Esempio n. 1
0
        private Expr GenerateBuiltInUnaryOperator(ExprUnaryOp expr)
        {
            Debug.Assert(expr != null);
            PREDEFMETH pdm;

            switch (expr.Kind)
            {
            case ExpressionKind.UnaryPlus:
                return(Visit(expr.Child));

            case ExpressionKind.BitwiseNot: pdm = PREDEFMETH.PM_EXPRESSION_NOT; break;

            case ExpressionKind.LogicalNot: pdm = PREDEFMETH.PM_EXPRESSION_NOT; break;

            case ExpressionKind.Negate:
                pdm = expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_NEGATECHECKED : PREDEFMETH.PM_EXPRESSION_NEGATE;
                break;

            default:
                throw Error.InternalCompilerError();
            }
            Expr origOp = expr.Child;

            // Such operations are always already casts on operations on casts.
            Debug.Assert(!(origOp.Type is NullableType nub) || !nub.UnderlyingType.isEnumType());
            return(GenerateCall(pdm, Visit(origOp)));
        }
Esempio n. 2
0
        public static ExprUnaryOp CreateNeg(EXPRFLAG flags, Expr operand)
        {
            Debug.Assert(operand != null);
            ExprUnaryOp unary = CreateUnaryOp(ExpressionKind.Negate, operand.Type, operand);

            unary.Flags |= flags;
            return(unary);
        }
Esempio n. 3
0
        public ExprUnaryOp CreateNeg(EXPRFLAG nFlags, Expr pOperand)
        {
            Debug.Assert(pOperand != null);
            ExprUnaryOp pUnaryOp = CreateUnaryOp(ExpressionKind.EK_NEG, pOperand.Type, pOperand);

            pUnaryOp.Flags |= nFlags;
            return(pUnaryOp);
        }
Esempio n. 4
0
        public ExprUnaryOp CreateUnaryOp(ExpressionKind exprKind, CType pType, Expr pOperand)
        {
            Debug.Assert(exprKind.IsUnaryOperator());
            Debug.Assert(pOperand != null);
            ExprUnaryOp rval = new ExprUnaryOp(exprKind, pType);

            rval.Child = pOperand;
            return(rval);
        }
Esempio n. 5
0
        private Expr GenerateUserDefinedUnaryOperator(ExprUnaryOp expr)
        {
            Debug.Assert(expr != null);
            PREDEFMETH pdm;
            Expr       arg  = expr.Child;
            ExprCall   call = (ExprCall)expr.OptionalUserDefinedCall;

            if (call != null)
            {
                // Use the actual argument of the call; it may contain user-defined
                // conversions or be a bound lambda, and that will not be in the original
                // argument stashed away in the left child of the operator.
                arg = call.OptionalArguments;
            }
            Debug.Assert(arg != null && arg.Kind != ExpressionKind.List);
            switch (expr.Kind)
            {
            case ExpressionKind.True:
            case ExpressionKind.False:
                return(Visit(call));

            case ExpressionKind.UnaryPlus:
                pdm = PREDEFMETH.PM_EXPRESSION_UNARYPLUS_USER_DEFINED;
                break;

            case ExpressionKind.BitwiseNot: pdm = PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED; break;

            case ExpressionKind.LogicalNot: pdm = PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED; break;

            case ExpressionKind.DecimalNegate:
            case ExpressionKind.Negate:
                pdm = expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_NEGATECHECKED_USER_DEFINED : PREDEFMETH.PM_EXPRESSION_NEGATE_USER_DEFINED;
                break;

            case ExpressionKind.Inc:
            case ExpressionKind.Dec:
            case ExpressionKind.DecimalInc:
            case ExpressionKind.DecimalDec:
                pdm = PREDEFMETH.PM_EXPRESSION_CALL;
                break;

            default:
                throw Error.InternalCompilerError();
            }
            Expr op         = Visit(arg);
            Expr methodInfo = GetExprFactory().CreateMethodInfo(expr.UserDefinedCallMethod);

            if (expr.Kind == ExpressionKind.Inc || expr.Kind == ExpressionKind.Dec ||
                expr.Kind == ExpressionKind.DecimalInc || expr.Kind == ExpressionKind.DecimalDec)
            {
                return(GenerateCall(pdm, null, methodInfo, GenerateParamsArray(op, PredefinedType.PT_EXPRESSION)));
            }
            return(GenerateCall(pdm, op, methodInfo));
        }
Esempio n. 6
0
 protected override Expr VisitUNARYOP(ExprUnaryOp pExpr)
 {
     Debug.Assert(pExpr != null);
     if (pExpr.UserDefinedCallMethod != null)
     {
         return(GenerateUserDefinedUnaryOperator(pExpr));
     }
     else
     {
         return(GenerateBuiltInUnaryOperator(pExpr));
     }
 }
Esempio n. 7
0
        public ExprUnaryOp CreateUnaryOp(ExpressionKind exprKind, CType pType, Expr pOperand)
        {
            Debug.Assert(exprKind.isUnaryOperator());
            Debug.Assert(pOperand != null);
            ExprUnaryOp rval = new ExprUnaryOp();

            rval.Kind  = exprKind;
            rval.Type  = pType;
            rval.Flags = 0;
            rval.Child = pOperand;
            rval.OptionalUserDefinedCall = null;
            rval.UserDefinedCallMethod   = null;
            Debug.Assert(rval != null);
            return(rval);
        }
Esempio n. 8
0
        public ExprUnaryOp CreateUserDefinedUnaryOperator(ExpressionKind exprKind, CType pType, Expr pOperand, ExprCall call, MethPropWithInst pmpwi)
        {
            Debug.Assert(pType != null);
            Debug.Assert(pOperand != null);
            Debug.Assert(call != null);
            Debug.Assert(pmpwi != null);
            ExprUnaryOp rval = new ExprUnaryOp(exprKind, pType);

            rval.Child = pOperand;
            // The call may be lifted, but we do not mark the outer binop as lifted.
            rval.OptionalUserDefinedCall = call;
            rval.UserDefinedCallMethod   = pmpwi;
            if (call.HasError)
            {
                rval.SetError();
            }
            return(rval);
        }
Esempio n. 9
0
 protected virtual Expr VisitDECIMALINC(ExprUnaryOp pExpr)
 {
     return(VisitUNARYOP(pExpr));
 }
Esempio n. 10
0
 protected virtual Expr VisitUPLUS(ExprUnaryOp pExpr)
 {
     return(VisitUNARYOP(pExpr));
 }