public override int VisitFunction(CFunction node) { //1. Create Output File CFile parent = m_parents.Peek() as CFile; CodeContainer repDeclare = new CodeContainer(CodeBlockType.CB_FILE, parent); CCFunctionDefinition rep = new CCFunctionDefinition(CodeBlockType.CB_FUNCTIONDEFINITION, 2, parent); //2. Add Function Definition to the File in the appropriate context parent.AddCode(repDeclare, CFile.CB_GLOBALS); parent.AddCode(rep, CFile.CB_FUNDEFS); m_parents.Push(rep); m_parentContexts.Push(CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS); //3. Assemble the function header CIdentifier id = node.GetChild(CFunction.CT_FNAME, 0) as CIdentifier; m_translatedFile.DeclareFunction(id.M_Name); rep.AddCode("float " + id.M_Name + "(", CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS); repDeclare.AddCode("float " + id.M_Name + "(", CFile.CB_GLOBALS); string last = node.GetChildrenContext(CFunction.CT_FARGS).Last().M_GraphVizName; foreach (ASTElement s in node.GetChildrenContext(CFunction.CT_FARGS)) { repDeclare.AddCode("float " + s.M_Name, CFile.CB_GLOBALS); rep.AddCode("float " + s.M_Name, CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS); if (!s.M_GraphVizName.Equals(last)) { repDeclare.AddCode(", ", CFile.CB_GLOBALS); rep.AddCode(", ", CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS); } parent.DeclareLocalFunvtionVariable(id.M_Name, s.M_Name); } repDeclare.AddCode(");\n", CFile.CB_GLOBALS); rep.AddCode(")", CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS); m_parents.Pop(); m_parentContexts.Pop(); m_parents.Push(rep); m_parentContexts.Push(CCFunctionDefinition.CB_FUNCTIONDEFINITION_BODY); m_functionNames.Push(id.M_Name); foreach (ASTVisitableElement child in node.GetChildrenContext(CFunction.CT_BODY)) { Visit(child); } m_functionNames.Pop(); m_parents.Pop(); m_parentContexts.Pop(); return(0); }
public override int VisitFunction(CFunction node) { ExtractSubgraphs(node, CFunction.CT_FNAME, CFunction.ContextNames); ExtractSubgraphs(node, CFunction.CT_FARGS, CFunction.ContextNames); ExtractSubgraphs(node, CFunction.CT_BODY, CFunction.ContextNames); base.VisitFunction(node); m_ostream.WriteLine("{0}->{1}", currentParent.M_GraphVizName, node.M_GraphVizName); return(0); }
public virtual T VisitFunction(CFunction node) { return(VisitChildren(node)); }