예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        //declarators

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

            if (directDecltor.GetText().EndsWith(")"))
            {
                if (directDecltor.identifierList() == null)
                {
                    CDeclaration.BeginFunctionDeclarator();
                }
            }
        }