Exemple #1
0
        public static void TryToCastUnaryArithExpression(UnaryArithExpression unaryArith, InnerType toType)
        {
            SyntaxTreeNode parent      = unaryArith;
            InnerType      operandType = TypeResolver.ResolveExpressionType(unaryArith.Operand);

            if (CanCast(operandType, toType, false))
            {
                CastCase   castCase   = DefineCastCase(operandType, toType);
                Expression castMethod = CreateCastMethod(parent, toType, new ParameterDeclaration[] { new ParameterDeclaration(unaryArith.Operand) }, castCase);
                Replace(parent, unaryArith.Operand, castMethod);
            }
        }
Exemple #2
0
        private static void EmitUnaryArithExpression(UnaryArithExpression unaryArith, ILGenerator methodIL)
        {
            switch (unaryArith.OperatorKind)
            {
            case UnaryExpression.UnaryOperator.UnaryMinus:
                //simply mult by -1
                EmitExpression(unaryArith.Operand, methodIL);
                methodIL.Emit(OpCodes.Ldc_I4, -1);
                methodIL.Emit(OpCodes.Mul);
                break;

            default:
                throw new Exception();
            }
        }
Exemple #3
0
        public static InnerType ResolveUnaryArithExpressionType(UnaryArithExpression unaryArithExpression)
        {
            InnerType OperandType = ResolveExpressionType(unaryArithExpression.Operand);

            //try to cast
            switch (unaryArithExpression.OperatorKind)
            {
            case UnaryArithExpression.UnaryOperator.UnaryMinus:
                if (OperandType is NumericType)
                {
                    return(OperandType);
                }
                ReportErrorInArithExpression(new SemanticErrorMessage($"Operator of unary minus must be located before numeric operand", unaryArithExpression.SourceContext));
                return(OperandType);

            default:
                return(new Undefined());
            }
        }