コード例 #1
0
        public override void ExitPostfixExpression(CParser.PostfixExpressionContext context)
        {
            if (context.expression() != null)
            {
                //postfixExpression '[' expression ']'
                SafeCall(context, CExpression.SubscriptOperator);
            }
            else if (context.postfixExpression() != null && context.GetText().EndsWith(")"))
            {
                //postfixExpression '(' argumentExpressionList? ')'
                int numArgs = GetArgumentListLength(context.argumentExpressionList());
                SafeCall(context, () => CExpression.FunctionCall(numArgs));
            }
            else if (context.Identifier() != null)
            {
                int objStringLength   = context.postfixExpression().GetText().Length;
                int idStringLength    = context.Identifier().GetText().Length;
                int contextStringSize = context.GetText().Length;

                int operationStringSize = contextStringSize - (objStringLength + idStringLength);

                string idString = context.Identifier().GetText();

                //'.'
                if (operationStringSize == 1)
                {
                    //postfixExpression '.' Identifier
                    SafeCall(context, () => CExpression.MemberAccess(idString));
                }
                //'->'
                else
                {
                    //postfixExpression '->' Identifier
                    SafeCall(context, () => CExpression.MemberAccessThroughPointer(idString));
                }
            }
            else if (context.GetText().EndsWith("++"))
            {
                //postfixExpression '++'
                SafeCall(context, CExpression.PostfixIncrementOperator);
            }
            else if (context.GetText().EndsWith("--"))
            {
                //postfixExpression '--'
                SafeCall(context, CExpression.PostfixDecrementOperator);
            }
            else if (context.initializerList() != null)
            {
                /*
                 *      '(' typeName ')' '{' initializerList '}'
                 |   '(' typeName ')' '{' initializerList ',' '}'
                 |   '__extension__' '(' typeName ')' '{' initializerList '}'
                 |   '__extension__' '(' typeName ')' '{' initializerList ',' '}'
                 */
                SematicError(context, "compound literals not supported");
            }
        }