コード例 #1
0
        protected ObjectDef EmitUnaryExpression(CParser.UnaryExpressionContext unaryExpression)
        {
            ObjectDef returnObjectDef = null;

            if (unaryExpression.postfixExpression() != null)
            {
                returnObjectDef = EmitPostfixExpression(unaryExpression.postfixExpression());
            }
            else
            {
                returnObjectDef = null; // Skip unary expressions
            }

            return(returnObjectDef);
        }
コード例 #2
0
        public override void ExitUnaryExpression(CParser.UnaryExpressionContext context)
        {
            if (context.unaryOperator() != null)
            {
                // unaryOperator castExpression

                /*
                 * unaryOperator
                 *  :   '&' | '*' | '+' | '-' | '~' | '!'
                 *  ;
                 */

                string operation = context.unaryOperator().GetText();

                if (operation == "&")
                {
                    SafeCall(context, CExpression.AddressOfOperator);
                }
                else if (operation == "*")
                {
                    SafeCall(context, CExpression.DereferenceOperator);
                }
                else if (operation == "+")
                {
                    SafeCall(context, CExpression.UnaryPlusOperator);
                }
                else if (operation == "-")
                {
                    SafeCall(context, CExpression.UnaryMinusOperator);
                }
                else if (operation == "~")
                {
                    SafeCall(context, CExpression.BitwiseNotOperator);
                }
                else if (operation == "!")
                {
                    SafeCall(context, CExpression.LogicalNotOperator);
                }
            }
            else if (context.GetText().StartsWith("++"))
            {
                //'++' unaryExpression
                SafeCall(context, CExpression.PrefixIncrementOperator);
            }
            else if (context.GetText().StartsWith("--"))
            {
                //'--' unaryExpression
                SafeCall(context, CExpression.PrefixDecrementOperator);
            }
            else if (context.GetText().StartsWith("sizeof"))
            {
                if (context.unaryExpression() != null)
                {
                    //'sizeof' unaryExpression
                    SafeCall(context, CExpression.SizeOf);
                }
                else
                {
                    //'sizeof' '(' typeName ')'
                    SafeCall(context, () => CExpression.SizeOf(context.typeName().GetText()));
                }
            }
            else if (context.Identifier() != null)
            {
                //'&&' Identifier
                SematicError(context, "GCC extension && not supported");
            }
            else if (context.GetText().StartsWith("_Alignof"))
            {
                //'_Alignof' '(' typeName ')'
                SematicError(context, "alignof not supported");
            }
        }