protected virtual EXPR GenerateUserDefinedUnaryOperator(EXPRUNARYOP expr) { Debug.Assert(expr != null); Debug.Assert(alwaysRewrite || currentAnonMeth != null); PREDEFMETH pdm; EXPR arg = expr.Child; EXPRCALL call = expr.OptionalUserDefinedCall.asCALL(); 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.GetOptionalArguments(); } Debug.Assert(arg != null && arg.kind != ExpressionKind.EK_LIST); switch (expr.kind) { case ExpressionKind.EK_TRUE: case ExpressionKind.EK_FALSE: return Visit(call); case ExpressionKind.EK_UPLUS: pdm = PREDEFMETH.PM_EXPRESSION_UNARYPLUS_USER_DEFINED; break; case ExpressionKind.EK_BITNOT: pdm = PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED; break; case ExpressionKind.EK_LOGNOT: pdm = PREDEFMETH.PM_EXPRESSION_NOT_USER_DEFINED; break; case ExpressionKind.EK_DECIMALNEG: case ExpressionKind.EK_NEG: pdm = expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_NEGATECHECKED_USER_DEFINED : PREDEFMETH.PM_EXPRESSION_NEGATE_USER_DEFINED; break; case ExpressionKind.EK_INC: case ExpressionKind.EK_DEC: case ExpressionKind.EK_DECIMALINC: case ExpressionKind.EK_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.EK_INC || expr.kind == ExpressionKind.EK_DEC || expr.kind == ExpressionKind.EK_DECIMALINC || expr.kind == ExpressionKind.EK_DECIMALDEC) { return GenerateCall(pdm, null, methodInfo, GenerateParamsArray(op, PredefinedType.PT_EXPRESSION)); } return GenerateCall(pdm, op, methodInfo); }
protected virtual EXPR GenerateBuiltInUnaryOperator(EXPRUNARYOP expr) { Debug.Assert(expr != null); Debug.Assert(alwaysRewrite || currentAnonMeth != null); PREDEFMETH pdm; switch (expr.kind) { case ExpressionKind.EK_UPLUS: return Visit(expr.Child); case ExpressionKind.EK_BITNOT: pdm = PREDEFMETH.PM_EXPRESSION_NOT; break; case ExpressionKind.EK_LOGNOT: pdm = PREDEFMETH.PM_EXPRESSION_NOT; break; case ExpressionKind.EK_NEG: pdm = expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_NEGATECHECKED : PREDEFMETH.PM_EXPRESSION_NEGATE; break; default: throw Error.InternalCompilerError(); } EXPR origOp = expr.Child; return GenerateBuiltInUnaryOperator(pdm, origOp, expr); }