Пример #1
0
        protected ObjectDef EmitMultiplicativeExpression(CParser.MultiplicativeExpressionContext multiplicativeExpression)
        {
            ObjectDef returnObjectDef = null;

            if (multiplicativeExpression.castExpression() != null)
            {
                returnObjectDef = EmitCastExpression(multiplicativeExpression.castExpression());
            }

            if (multiplicativeExpression.castExpression() != null &&
                multiplicativeExpression.multiplicativeExpression() != null)
            {
                var multiplicativeObj = EmitMultiplicativeExpression(multiplicativeExpression.multiplicativeExpression());

                multiplicativeObj.Load();
                returnObjectDef.Load();

                if (multiplicativeExpression.Star() != null)
                {
                    _generatorIL.Emit(OpCodes.Mul);
                }
                else if (multiplicativeExpression.Div() != null)
                {
                    _generatorIL.Emit(OpCodes.Div);
                }
                else if (multiplicativeExpression.Mod() != null)
                {
                    _generatorIL.Emit(OpCodes.Rem);
                }

                returnObjectDef = LocalObjectDef.AllocateLocal(typeof(int));
            }

            return(returnObjectDef);
        }
Пример #2
0
        public override void ExitMultiplicativeExpression(CParser.MultiplicativeExpressionContext context)
        {
            if (context.multiplicativeExpression() != null)
            {
                string operation = context.GetText().Substring(context.multiplicativeExpression().GetText().Length, 1);

                if (operation == "*")
                {
                    //multiplicativeExpression '*' castExpression
                    SafeCall(context, CExpression.MultiplicationOperator);
                }
                else if (operation == "/")
                {
                    //multiplicativeExpression '/' castExpression
                    SafeCall(context, CExpression.DivisionOperator);
                }
                else if (operation == "%")
                {
                    //multiplicativeExpression '%' castExpression
                    SafeCall(context, CExpression.ModuloOperator);
                }
            }
        }