void AST_FreeNode(tAST_Node *Node)
{
tAST_Node *node;
+
+ if(!Node) return ;
+
switch(Node->Type)
{
// Block of code
}
break;
+ // If node
+ case NODETYPE_IF:
+ AST_FreeNode(Node->If.Condition);
+ AST_FreeNode(Node->If.True);
+ AST_FreeNode(Node->If.False);
+ break;
+
+ // Looping Construct (For loop node)
+ case NODETYPE_LOOP:
+ AST_FreeNode(Node->For.Init);
+ AST_FreeNode(Node->For.Condition);
+ AST_FreeNode(Node->For.Increment);
+ AST_FreeNode(Node->For.Code);
+ break;
+
// Asignment
case NODETYPE_ASSIGN:
AST_FreeNode(Node->Assign.Dest);
}
}
+tAST_Node *AST_NewIf(tAST_Node *Condition, tAST_Node *True, tAST_Node *False)
+{
+ tAST_Node *ret = malloc( sizeof(tAST_Node) );
+ ret->NextSibling = NULL;
+ ret->Type = NODETYPE_IF;
+ ret->If.Condition = Condition;
+ ret->If.True = True;
+ ret->If.False = False;
+ return ret;
+}
+
+tAST_Node *AST_NewLoop(tAST_Node *Init, int bPostCheck, tAST_Node *Condition, tAST_Node *Increment, tAST_Node *Code)
+{
+ tAST_Node *ret = malloc( sizeof(tAST_Node) );
+ ret->NextSibling = NULL;
+ ret->Type = NODETYPE_LOOP;
+ ret->For.Init = Init;
+ ret->For.bCheckAfter = !!bPostCheck;
+ ret->For.Condition = Condition;
+ ret->For.Increment = Increment;
+ ret->For.Code = Code;
+ return ret;
+}
+
tAST_Node *AST_NewAssign(int Operation, tAST_Node *Dest, tAST_Node *Value)
{
tAST_Node *ret = malloc( sizeof(tAST_Node) );