public int addLine(string codeLine, CFGNode node) { m_CodeLine.Add(codeLine); if (node != null) { m_nodeToLine.Add(node, m_CodeLine.Count - 1); } return(m_CodeLine.Count - 1); }
public Graph GetNextFunctionAsGLEEGraph() { Graph g = new Graph("Next"); foreach (CFGNode Node in ListOfCfgNodes) { Node n = (Node)g.AddNode(Node.GetHashCode().ToString()); n.Attr.Label = Node.ToString(); } foreach (CFGNode Node in ListOfCfgNodes) { if (Node is CFGNodeStatement) { CFGNodeStatement StmtNode = (CFGNodeStatement)Node; CFGNode NextNode = StmtNode.Next; g.AddEdge(Node.GetHashCode().ToString(), NextNode.GetHashCode().ToString()); } } return(g); }
private void BuildNextFunction() { foreach (CFGNode node in ListOfCfgNodes) { if (node is CFGNodeStatement) { CFGNodeStatement stmt = (CFGNodeStatement)node; CFGNode NextNode = null; CommonAST ASTwalker = stmt.GetAST(); ASTParentByASTNode.TryGetValue(ASTwalker, out ASTwalker); bool done = false; while (!done && ASTwalker != null) { #region STMT or LSTMT if (ASTwalker.Type == BoolParserTokenTypes.LITERAL_while) { done = true; ASTParentByASTNode.TryGetValue(ASTwalker, out ASTwalker); if (AstToCfgMapping.TryGetValue(ASTwalker, out NextNode)) { stmt.Next = NextNode; } else { stmt.Next = null; } } else if ((ASTwalker.Type == BoolParserTokenTypes.STMT || ASTwalker.Type == BoolParserTokenTypes.LSTMT) && (ASTwalker.getNextSibling() != null)) { CommonAST ASTwalkerSibling = (CommonAST)ASTwalker.getNextSibling(); if (ASTwalkerSibling.Type == BoolParserTokenTypes.STMT || ASTwalkerSibling.Type == BoolParserTokenTypes.LSTMT) { done = true; if (AstToCfgMapping.TryGetValue(ASTwalkerSibling, out NextNode)) { stmt.Next = NextNode; } else { stmt.Next = null; } } } #endregion #region PROC if (ASTwalker.Type == BoolParserTokenTypes.PROC) { done = true; if (AstToCfgMapping.TryGetValue(ASTwalker, out NextNode)) { stmt.Next = NextNode; } else { stmt.Next = null; } } #endregion if (!done) { ASTParentByASTNode.TryGetValue(ASTwalker, out ASTwalker); } } if (stmt is CFGNodeStmtProcCall) { if (NextNode is CFGNodeStmtSkip) { (NextNode as CFGNodeStmtSkip).setPreviousProcCall(stmt as CFGNodeStmtProcCall); } } } else //We use this pass trough the CFG nodes to build "First Statement Of Procedure" function if (node is CFGNodeProcedure) { CFGNodeProcedure proc = (CFGNodeProcedure)node; CommonAST ASTwalker = proc.GetAST(); ASTwalker = (CommonAST)ASTwalker.getFirstChild(); while (ASTwalker.Type != BoolParserTokenTypes.SSEQ) { ASTwalker = (CommonAST)ASTwalker.getNextSibling(); } ASTwalker = (CommonAST)ASTwalker.getFirstChild(); CFGNode FirstOf; if (AstToCfgMapping.TryGetValue(ASTwalker, out FirstOf)) { proc.FirstStmtOf = FirstOf; } } } }
internal override void AddSuccesor(CFGNode SuccNode) { m_Succesor.Add(SuccNode); SuccNode.AddPredecessor(this); }
internal void AddPredecessor(CFGNode PreNode) { m_Predecessor.Add(PreNode); }
internal virtual void AddSuccesor(CFGNode SuccNode) { //Succesors.Add(SuccNode); m_Succesor = SuccNode; SuccNode.AddPredecessor(this); }