#include "dead_code_removal.h"
#include "free.h"
#include "dbug.h"
#include "node_basic.h"
#include "tree_basic.h"
#include "mymacros.h"

node* DCRfor(node* arg_node, info* arg_info)
{
    DBUG_ENTER("DCRfor");

    if (FOR_BLOCK(arg_node) == NULL)
    {
        FREEdoFreeTree(arg_node);
        DBUG_RETURN(NULL);
    }

    TO(FOR_VARINITVAL);
    TO(FOR_VARLIMVAL);
    TO(FOR_VARSTEPVAL);
    TO(FOR_BLOCK);

    DBUG_RETURN(arg_node);
}

node* DCRstmts(node* arg_node, info* arg_info)
{
    DBUG_ENTER("DCRstmts");

    TO(STMTS_NEXT);
    node* next = STMTS_NEXT(arg_node);
    if (STMTS_STMT(arg_node) == NULL)
    {
        STMTS_NEXT(arg_node) = NULL;
        FREEdoFreeTree(arg_node);
        DBUG_RETURN(next);
    }

    TO(STMTS_STMT);
    DBUG_RETURN(arg_node);
}

node* DCRdoRemoval(node* syntaxtree)
{
    DBUG_ENTER("DCRdoRemoval");

    TRAVpush(TR_dcr);
    syntaxtree = TRAVdo(syntaxtree, NULL);
    TRAVpop();

    TRAVpush(TR_dcr);
    syntaxtree = TRAVdo(syntaxtree, NULL);
    TRAVpop();

    DBUG_RETURN(syntaxtree);
}