示例#1
0
        public override ASTNode VisitTranslationUnit([NotNull] TranslationUnitContext ctx)
        {
            ASTNode decl = this.Visit(ctx.externalDeclaration());

            if (ctx.translationUnit() is null)
            {
                return(new SourceNode(decl));
            }

            SourceNode tu = this.Visit(ctx.translationUnit()).As <SourceNode>();

            decl.Parent = tu;
            return(new SourceNode(tu.Children.Concat(new[] { decl })));
        }
示例#2
0
        private void ParseTranslationUnit(TranslationUnitContext node)
        {
            TranslationUnitContext transUnit = node.translationUnit();

            ExternalDeclarationContext externalDeclaration = node.externalDeclaration();

            if (transUnit != null)
            {
                this.ParseTranslationUnit(transUnit);
            }

            if (externalDeclaration != null)
            {
                DeclarationContext[]        declarations = externalDeclaration.GetRuleContexts <DeclarationContext>();
                FunctionDefinitionContext[] functions    = externalDeclaration.GetRuleContexts <FunctionDefinitionContext>();

                foreach (DeclarationContext declaration in declarations)
                {
                    InitDeclaratorListContext initDeclaratorList = declaration.initDeclaratorList();

                    string name = initDeclaratorList.initDeclarator().declarator().directDeclarator().Identifier().GetText();

                    this.WriteKeyValue("Field", name);
                }

                foreach (FunctionDefinitionContext function in functions)
                {
                    DirectDeclaratorContext[] directDeclarators = function.declarator().GetRuleContexts <DirectDeclaratorContext>();

                    foreach (DirectDeclaratorContext directDeclarator in directDeclarators)
                    {
                        string name = directDeclarator.directDeclarator().Identifier().GetText();

                        this.WriteKeyValue("Function", name);
                    }
                }
            }
        }