private void BuildTransferFunctions() { foreach (CFGNode node in ProgramCFG.CfgNodes) { if (node is CFGNodeStatement) { if ((node is CFGNodeStmtSkip) || (node is CFGNodeStmtPrint) || (node is CFGNodeStmtGoto) || (node is CFGNodeStmtReturn)) { (node as CFGNodeStatement).Transfer = HelperFunctions.BuildIdentityTransfer(m_BddManager, (node as CFGNodeStatement).ProcOf.LocalVariables.VariablesToId, ProgramCFG.GlobalVariables.VariablesToId); } else if (node is CFGNodeStmtAssignment) { (node as CFGNodeStmtAssignment).Transfer = CFGNodeStmtAssignment.BuildAssignmentTransfer(node.GetAST(), m_BddManager, (node as CFGNodeStatement).ProcOf.LocalVariables.VariablesToId, ProgramCFG.GlobalVariables.VariablesToId); } else if (node is CFGNodeStmtConditional) { Bdd TransferTrue, TransferFalse; CommonAST decider = node.GetAST().getFirstChild() as CommonAST; HelperFunctions.BuildDeciderTransfers(decider, m_BddManager, (node as CFGNodeStatement).ProcOf.LocalVariables.VariablesToId, ProgramCFG.GlobalVariables.VariablesToId, out TransferTrue, out TransferFalse); (node as CFGNodeStmtConditional).TransferTrue = TransferTrue; (node as CFGNodeStmtConditional).TransferFalse = TransferFalse; } else if (node is CFGNodeStmtProcCall) { CFGNodeProcedure procedureCalled; if (!(ProgramCFG.ProcedureNameToNode().TryGetValue( node.GetAST().getFirstChild().getText(), out procedureCalled))) { System.Diagnostics.Debug.Assert(false); } (node as CFGNodeStmtProcCall).Transfer = CFGNodeStmtProcCall.buildProcCallTransfer(node.GetAST(), procedureCalled, m_BddManager, (node as CFGNodeStatement).ProcOf.LocalVariables.VariablesToId, ProgramCFG.GlobalVariables.VariablesToId); } } } }
public static void Main(string[] args) { // Create the tree nodes ASTFactory factory = new ASTFactory(); CommonAST r = (CommonAST)factory.create(0, "ROOT"); r.addChild((CommonAST)factory.create(0, "C1")); r.addChild((CommonAST)factory.create(0, "C2")); r.addChild((CommonAST)factory.create(0, "C3")); ASTFrame frame = new ASTFrame("AST JTree Example", r); Application.Run(frame); }
public static void Main(string[] args) { try { LangLexer lexer = new LangLexer(new CharBuffer(Console.In)); LangParser parser = new LangParser(lexer); parser.block(); CommonAST a = (CommonAST)parser.getAST(); Console.Out.WriteLine(a.ToStringList()); LangWalker walker = new LangWalker(); walker.block(a); // walk tree Console.Out.WriteLine("done walking"); } catch (Exception e) { Console.Error.WriteLine("exception: " + e); } }
override public string ToString() { string StatementString = NodeASTSubTree.getText(); CommonAST ASTChild = (CommonAST)NodeASTSubTree.getFirstChild(); while (ASTChild != null) { StatementString += " " + ASTChild.getText(); ASTChild = (CommonAST)ASTChild.getNextSibling(); } return(StatementString); }
private Bdd Lift(CFGNodeStmtProcCall procCallNode, CFGNodeProcedure exitNode) { int i = 0; int id; Bdd[] bddArrayFormalsNot = new Bdd[2 * exitNode.LocalVariables.Length - exitNode.FormalParameters.Length]; //Bdd[] bddArrayFormals = new Bdd[2 * exitNode.FormalParameters.Length]; Bdd[] bddArrayForSubstitution = new Bdd[2 * exitNode.FormalParameters.Length]; Bdd tempBdd, tempBddAnd, tempBddXnor, tempBddReplace; Bdd var, exp, identity; CommonAST walkerVar = exitNode.GetAST().getFirstChild() as CommonAST; CommonAST walkerExp = procCallNode.GetAST().getFirstChild().getFirstChild() as CommonAST; foreach (string varName in exitNode.LocalVariables.VariablesToId.Keys) { exitNode.LocalVariables.VariablesToId.TryGetValue(varName, out id); if (exitNode.FormalParameters.VariablesToId.ContainsKey(varName) == false) { bddArrayFormalsNot[i++] = m_BddManager.GetBddVariableWithID(id); bddArrayFormalsNot[i++] = m_BddManager.GetBddVariableWithID(id + 2); } else { bddArrayFormalsNot[i++] = m_BddManager.GetBddVariableWithID(id + 2); } } PathEdges tempPath; m_PathEdges.TryGetValue(exitNode, out tempPath); tempBdd = tempPath.GetJointPaths(m_BddManager); tempBdd = tempBdd.Exists(bddArrayFormalsNot); i = 0; while (walkerVar.Type == BoolParserTokenTypes.ID) { exitNode.LocalVariables.VariablesToId.TryGetValue(walkerVar.getText(), out id); exp = HelperFunctions.ExprToBdd(walkerExp, m_BddManager, procCallNode.ProcOf.LocalVariables.VariablesToId, ProgramCFG.GlobalVariables.VariablesToId); var = m_BddManager.GetBddVariableWithID(id); bddArrayForSubstitution[i++] = var; bddArrayForSubstitution[i++] = exp; /* * tempBddXnor = m_BddManager.LogicalXnor(exp, var); * tempBddAnd = m_BddManager.LogicalAnd(tempBddXnor, tempBdd); * * tempBdd.FreeBdd(); * exp.FreeBdd(); * tempBdd = tempBddAnd; */ walkerExp = walkerExp.getNextSibling() as CommonAST; walkerVar = walkerVar.getNextSibling() as CommonAST; } i = 0; /* * foreach (int bddId in exitNode.FormalParameters.VariablesToId.Values) * { * bddArrayFormals[i++] = m_BddManager.GetBddVariableWithID(bddId); * bddArrayFormals[i++] = m_BddManager.GetBddVariableWithID(bddId + 2); * }*/ tempBddReplace = tempBdd.Replace(bddArrayForSubstitution); tempBdd.FreeBdd(); tempBdd = tempBddReplace; identity = HelperFunctions.BuildIdentityTransfer(m_BddManager, procCallNode.ProcOf.LocalVariables.VariablesToId, null); tempBddAnd = m_BddManager.LogicalAnd(tempBdd, identity); tempBdd.FreeBdd(); identity.FreeBdd(); tempBdd = tempBddAnd; return(tempBdd); }
public CFGNodeStatement(CommonAST StatementAST) { NodeASTSubTree = StatementAST; m_ProcOf = null; }