static MethodDeclarationNode GenerateDestructor(ClassDeclarationNode classDeclarationNode) //Generates destruction method from variable list in class { foreach (MethodDeclarationNode method in classDeclarationNode.MethodDeclarations) //check if method already given { if (method.isDestruction) { return(method); } } MethodDeclarationNode destructor = new MethodDeclarationNode(true); foreach (VariableDeclarationNode declaration in classDeclarationNode.VariableDeclarations) //for every variable collect a destruction function { CallNode call = new CallNode(); call.SetCallerName(declaration.name); string className = declaration.expression.call.CalleeNames[0]; foreach (ClassDeclarationNode classDeclaration in _rootNode.ClassDeclarations) { if (classDeclaration.name == className) { call.AddCallee(GenerateDestructor(classDeclaration).name, new List <ExpressionNode>()); } } destructor.AddBodyNode(call); //Add destruction call to method } return(destructor); }