Exemplo n.º 1
0
        public void Visit(FuncDefNode n)
        {
            var funcBody = (FuncBodyNode)n.GetChildren().Last();

            funcBody.SymTable = n.Table;
            funcBody.Accept(this);
        }
Exemplo n.º 2
0
        public void Visit(FuncDefNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }
        }
Exemplo n.º 3
0
 public void Visit(FuncDefNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Exemplo n.º 4
0
        public Arbor(Parser _parser)
        {
            parser  = _parser;
            options = parser.options;

            symbolTable  = new SymbolTable();
            curModule    = null;
            curFunc      = null;
            blockStack   = new List <Block>();
            curBlock     = null;
            curParamList = null;

            defineBaseTypes();
        }
Exemplo n.º 5
0
        public void FunctionDefenitionDifferenceTest4()
        {
            ASTNode ast1 = new FuncDefNode(
                1,
                new DeclSpecsNode(2, "public static", "void"),
                new FuncDeclNode(
                    2,
                    new IdNode(2, "f"),
                    new FuncParamsNode(
                        2,
                        new FuncParamNode(
                            3,
                            new DeclSpecsNode(3, "", "time_t"),
                            new ArrDeclNode(3, new IdNode(3, "arr"))
                            )
                        )
                    ),
                new BlockStatNode(3, new JumpStatNode(4, new LitExprNode(4, "2", "u")))
                );
            ASTNode ast2 = new FuncDefNode(
                1,
                new DeclSpecsNode(3, "public static", "void"),
                new FuncDeclNode(
                    3,
                    new IdNode(4, "f"),
                    new FuncParamsNode(
                        4,
                        new FuncParamNode(
                            4,
                            new DeclSpecsNode(5, "const", "time_t"),
                            new ArrDeclNode(6, new IdNode(6, "arr"))
                            )
                        )
                    ),
                new BlockStatNode(7, new JumpStatNode(8, new LitExprNode(8, "2", "u")), new EmptyStatNode(10))
                );

            AssertNodes(ast1, ast2, eq: false);
        }
Exemplo n.º 6
0
        public void startFuncDef(DeclSpecNode declarspecs, DeclaratorNode declarator)
        {
            FuncDefNode func = new FuncDefNode();

            func.returnType = declarspecs.baseType;
            DeclaratorNode dnode = declarator;

            while (dnode != null)
            {
                if (dnode is IdentDeclaratorNode)
                {
                    func.name = ((IdentDeclaratorNode)dnode).ident;
                }
                if (dnode is ParamListNode)
                {
                    func.paramList = ((ParamListNode)dnode).paramList;
                }
                dnode = dnode.next;
            }
            symbolTable.addSymbol(func.name, func);     //add func def to global symbol tbl
            curModule.funcs.Add(func);                  //add func to module's func list
            curFunc = func;
            enterBlock();                               //enter function "super" block
        }
Exemplo n.º 7
0
 public virtual TResult Visit(FuncDefNode node) => this.VisitChildren(node);
Exemplo n.º 8
0
        public void Visit(FuncDefNode n)
        {
            var children = n.GetChildren();

            var tableEntry = new FunctionSymbolTableEntry();
            List <ASTNodeBase> funcParamList;
            List <ASTNodeBase> localScope;

            bool hasScopeSpec = children[1] is IdentifierNode;

            if (hasScopeSpec)
            {
                tableEntry.ScopeSpec  = children[0].Token.Lexeme;
                tableEntry.Name       = children[1].Token.Lexeme;
                funcParamList         = children[2].GetChildren();
                tableEntry.ReturnType = children[3].Token;
                localScope            = children.GetCast <FuncBodyNode>(4).GetChildren().First().GetChildren().SelectMany(x => x.GetChildren()).ToList();
            }
            else
            {
                tableEntry.Name       = children[0].Token.Lexeme;
                funcParamList         = children[1].GetChildren();
                tableEntry.ReturnType = children[2].Token;
                localScope            = children.GetCast <FuncBodyNode>(3).GetChildren().First().GetChildren().SelectMany(x => x.GetChildren()).ToList();
            }

            for (int i = 0; i < funcParamList.Count; i += 3)
            {
                var paramType = funcParamList[i + 0].Token;
                var paramName = funcParamList[i + 1].Token.Lexeme;
                var arrayDims = NodeUtils.ExtractArrayDimListNode(funcParamList.GetCast <ArrayDimListNode>(i + 2));

                var entry = new FunctionSymbolTableEntryParam()
                {
                    TypeToken = paramType,
                    Name      = paramName,
                    ArrayDims = arrayDims,
                };

                tableEntry.AddParamEntry(entry);
            }

            for (int i = 0; i < localScope.Count; i += 3)
            {
                var paramType = localScope[i + 0].Token;
                var paramName = localScope[i + 1].Token.Lexeme;
                var arrayDims = NodeUtils.ExtractArrayDimListNode(localScope.GetCast <ArrayDimListNode>(i + 2));

                if (!CheckTypeExists(paramType.Lexeme))
                {
                    _errorStream.WriteLine($"Use of undeclared class, \"{paramType.Lexeme}\"({paramType.StartLine}:{paramType.StartColumn})");
                    Console.WriteLine($"Error: Use of undeclared class, \"{paramType.Lexeme}\"({paramType.StartLine}:{paramType.StartColumn})");
                }

                var entry = new FunctionSymbolTableEntryLocalScope()
                {
                    Type      = paramType,
                    Name      = paramName,
                    ArrayDims = arrayDims,
                };

                tableEntry.AddLocalScopeEntry(entry);
            }

            n.Table = tableEntry;
            GlobalSymbolTable.FunctionSymbolTable.AddEntry(tableEntry);
        }
Exemplo n.º 9
0
 public CGFuncDefNode(FuncDefNode _funcdef)
 {
     funcdef        = _funcdef;
     funcdef.cgnode = this;
 }