示例#1
0
        public override object VisitDirectDeclarator(CParser.DirectDeclaratorContext context)
        {
            skipWhitespaces();
            var mark = Builder.Mark();

            VisitChildren(context);
            Builder.Done(mark, SpringCompositeNodeWithArgumentType.VAR_DECLARATION, context);
            return(null);
        }
        public SpringVariableDeclarationElement(CParser.DirectDeclaratorContext ctx)
        {
            context = ctx;
            var ctxIdentifier = ctx.Identifier();

            if (ctxIdentifier != null)
            {
                name = ctxIdentifier.GetText();
            }
            DeclaredElement = new CVariableDeclared(this);
        }
        public override void ExitDeclarator(CParser.DeclaratorContext context)
        {
            if (context.gccDeclaratorExtension().Count > 0)
            {
                throw new SemanticException("gcc Declarator Extensions not supported");
            }

            bool isPointer = context.pointer() != null;

            CParser.DirectDeclaratorContext directDecltor = context.directDeclarator();

            if (directDecltor.Identifier() != null)
            {
                CDeclaration.PushIdentifierDeclarator(isPointer, directDecltor.GetText());
            }
            else if (directDecltor.declarator() != null)
            {
                CDeclaration.NestedDeclarator(isPointer);
            }
            else if (directDecltor.GetText().EndsWith("*]"))
            {
                SematicError(context, "VLA not supported");
            }
            else
            {
                if (directDecltor.directDeclarator().Identifier() != null)
                {
                    CDeclaration.PushIdentifierDeclarator(false, directDecltor.directDeclarator().GetText());
                }

                if (directDecltor.GetText().EndsWith(")"))
                {
                    if (directDecltor.identifierList() != null)
                    {
                        SematicError(context, "old style (K&R) style functions not supported");
                    }
                    else if (directDecltor.parameterTypeList() != null)
                    {
                        CDeclaration.EndFunctionDeclarator(isPointer, GetParameterListCount(directDecltor.parameterTypeList().parameterList()));
                    }
                    else
                    {
                        CDeclaration.EndFunctionDeclarator(isPointer, 0);
                    }
                }
                else
                {
                    bool hasAssgnExpr      = directDecltor.assignmentExpression() != null;
                    int  numTypeQualifiers = GetTypeQualifierListCount(directDecltor.typeQualifierList());
                    CDeclaration.ArrayDeclarator(isPointer, numTypeQualifiers, hasAssgnExpr);
                }
            }
        }
        //declarators

        public override void EnterDeclarator(CParser.DeclaratorContext context)
        {
            //beginFunctionDeclarator
            CParser.DirectDeclaratorContext directDecltor = context.directDeclarator();

            if (directDecltor.GetText().EndsWith(")"))
            {
                if (directDecltor.identifierList() == null)
                {
                    CDeclaration.BeginFunctionDeclarator();
                }
            }
        }
示例#5
0
            public override Unit VisitDirectDeclarator(CParser.DirectDeclaratorContext context)
            {
                if (context.Identifier() != null)
                {
                    _builder.ResetCurrentLexeme(context.SourceInterval.a, context.SourceInterval.a);
                    var mark = _builder.Mark();
                    base.VisitChildren(context);
                    _builder.Done(mark, SpringDeclarationNodeElement.NODE_TYPE, context);
                }
                else
                {
                    VisitChildren(context);
                }

                return(Unit.Instance);
            }
示例#6
0
        public override void ExitDirectDeclarator([NotNull] CParser.DirectDeclaratorContext context)
        {
            var text  = context.GetText();
            var token = context.Start;

            //
            // directDeclarator is used for the routine name and individual parameters. Sometimes, a directDeclarator will be nested, if so then
            // we don't want this node
            //

            if (context.ChildCount == 1)
            {
                //
                // Determine if this is the routine name or a parameter name
                //

                if (in_params_list)
                {
                    cur_parameter.param_name = text;

                    Console.Write($" {text}");                              // Parameter name
                }
                else
                {
                    function_def.func_name = text;

                    Console.WriteLine($"{text}");                           // Routine name
                }
            }
            else
            {
                //
                // Look for an empty parameter list, e.g. bool rtn ();
                //

                if ((context.children [context.ChildCount - 1].GetText() == ")") && (context.children [context.ChildCount - 2].GetText() == "("))
                {
                    function_def.parameters.Clear();

                    Console.WriteLine("();\n");
                }
            }
        }                   // End ExitDirectDeclarator