本文整理汇总了C#中ConditionalBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ConditionalBuilder类的具体用法?C# ConditionalBuilder怎么用?C# ConditionalBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConditionalBuilder类属于命名空间,在下文中一共展示了ConditionalBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCompareTest
private static void MakeCompareTest(string op, ConditionalBuilder/*!*/ bodyBuilder, Expression retCond, Expression/*!*/ expr, bool reverse) {
MakeCompareReturn(bodyBuilder, retCond, GetCompareTest(op, expr, reverse), reverse);
}
示例2: DoCoerce
/// <summary>
/// calls __coerce__ for old-style classes and performs the operation if the coercion is successful.
/// </summary>
private static void DoCoerce(PythonContext/*!*/ pyContext, ConditionalBuilder/*!*/ bodyBuilder, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse, Func<Expression, Expression> returnTransform) {
ParameterExpression coerceResult = Ast.Variable(typeof(object), "coerceResult");
ParameterExpression coerceTuple = Ast.Variable(typeof(PythonTuple), "coerceTuple");
// tmp = self.__coerce__(other)
// if tmp != null && tmp != NotImplemented && (tuple = PythonOps.ValidateCoerceResult(tmp)) != null:
// return operation(tuple[0], tuple[1])
SlotOrFunction slot = SlotOrFunction.GetSlotOrFunction(pyContext, "__coerce__", types);
if (slot.Success) {
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Not(
Ast.TypeIs(
Ast.Assign(
coerceResult,
slot.Target.Expression
),
typeof(OldInstance)
)
),
Ast.NotEqual(
Ast.Assign(
coerceTuple,
Ast.Call(
typeof(PythonOps).GetMethod("ValidateCoerceResult"),
coerceResult
)
),
AstUtils.Constant(null)
)
),
BindingHelpers.AddRecursionCheck(
pyContext,
returnTransform(
DynamicExpression.Dynamic(
pyContext.Operation(op | PythonOperationKind.DisableCoerce),
op == PythonOperationKind.Compare ? typeof(int) : typeof(object),
reverse ? CoerceTwo(coerceTuple) : CoerceOne(coerceTuple),
reverse ? CoerceOne(coerceTuple) : CoerceTwo(coerceTuple)
)
)
)
);
bodyBuilder.AddVariable(coerceResult);
bodyBuilder.AddVariable(coerceTuple);
}
}
示例3: MakeCompareReturn
private static void MakeCompareReturn(ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition, Expression/*!*/ retValue, bool isReverse, Type retType) {
if (retCondition != null) {
bodyBuilder.AddCondition(retCondition, retValue);
} else {
bodyBuilder.FinishCondition(retValue, retType);
}
}
示例4: MakeOneTarget
private static bool MakeOneTarget(PythonContext/*!*/ state, SlotOrFunction/*!*/ target, PythonTypeSlot slotTarget, ConditionalBuilder/*!*/ bodyBuilder, bool reverse, DynamicMetaObject/*!*/[]/*!*/ types) {
if (target == SlotOrFunction.Empty && slotTarget == null) return true;
if (slotTarget != null) {
MakeSlotCall(state, types, bodyBuilder, slotTarget, reverse);
return true;
} else if (target.MaybeNotImplemented) {
Debug.Assert(target.ReturnType == typeof(object));
ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
bodyBuilder.AddVariable(tmp);
bodyBuilder.AddCondition(
Ast.NotEqual(
Ast.Assign(
tmp,
target.Target.Expression
),
Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
),
tmp
);
return true;
} else {
bodyBuilder.FinishCondition(target.Target.Expression, typeof(object));
return false;
}
}
示例5: MakeCompareReverse
private static void MakeCompareReverse(ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition, Expression/*!*/ expr, bool reverse, Type retType) {
Expression res = expr;
if (reverse) {
res = ReverseCompareValue(expr);
}
MakeCompareReturn(bodyBuilder, retCondition, res, reverse, retType);
}
示例6: CompleteRuleTarget
public override DynamicMetaObject/*!*/ CompleteRuleTarget(DynamicMetaObjectBinder/*!*/ metaBinder, DynamicMetaObject/*!*/[]/*!*/ args, Func<DynamicMetaObject> customFailure) {
ConditionalBuilder cb = new ConditionalBuilder();
_slot.MakeGetExpression(
Binder,
AstUtils.Constant(PythonContext.SharedContext),
args[0],
new DynamicMetaObject(
Ast.Call(
typeof(DynamicHelpers).GetMethod("GetPythonType"),
AstUtils.Convert(args[0].Expression, typeof(object))
),
BindingRestrictions.Empty,
DynamicHelpers.GetPythonType(args[0].Value)
),
cb
);
if (!cb.IsFinal) {
cb.FinishCondition(metaBinder.Throw(Ast.New(typeof(InvalidOperationException))));
}
Expression callable = cb.GetMetaObject().Expression;
Expression[] exprArgs = new Expression[args.Length - 1];
for (int i = 1; i < args.Length; i++) {
exprArgs[i - 1] = args[i].Expression;
}
Expression retVal = DynamicExpression.Dynamic(
PythonContext.Invoke(
new CallSignature(exprArgs.Length)
),
typeof(object),
ArrayUtils.Insert(AstUtils.Constant(PythonContext.SharedContext), (Expression)callable, exprArgs)
);
if (IsSetter) {
retVal = Ast.Block(retVal, args[args.Length - 1].Expression);
}
return new DynamicMetaObject(
retVal,
BindingRestrictions.Combine(args)
);
}
示例7: Call
internal static DynamicMetaObject Call(DynamicMetaObjectBinder/*!*/ call, DynamicMetaObject target, DynamicMetaObject/*!*/[]/*!*/ args) {
Assert.NotNull(call, args);
Assert.NotNullItems(args);
if (target.NeedsDeferral()) {
return call.Defer(ArrayUtils.Insert(target, args));
}
foreach (DynamicMetaObject mo in args) {
if (mo.NeedsDeferral()) {
RestrictTypes(args);
return call.Defer(
ArrayUtils.Insert(target, args)
);
}
}
DynamicMetaObject self = target.Restrict(target.GetLimitType());
ValidationInfo valInfo = BindingHelpers.GetValidationInfo(target);
PythonType pt = DynamicHelpers.GetPythonType(target.Value);
BinderState state = BinderState.GetBinderState(call);
// look for __call__, if it's present dispatch to it. Otherwise fall back to the
// default binder
PythonTypeSlot callSlot;
if (!typeof(Delegate).IsAssignableFrom(target.GetLimitType()) &&
pt.TryResolveSlot(state.Context, Symbols.Call, out callSlot)) {
ConditionalBuilder cb = new ConditionalBuilder(call);
Expression body;
callSlot.MakeGetExpression(
state.Binder,
BinderState.GetCodeContext(call),
self.Expression,
GetPythonType(self),
cb
);
if (!cb.IsFinal) {
cb.FinishCondition(GetCallError(self));
}
Expression[] callArgs = ArrayUtils.Insert(
BinderState.GetCodeContext(call),
cb.GetMetaObject().Expression,
DynamicUtils.GetExpressions(args)
);
body = Ast.Dynamic(
BinderState.GetBinderState(call).Invoke(
BindingHelpers.GetCallSignature(call)
),
typeof(object),
callArgs
);
return BindingHelpers.AddDynamicTestAndDefer(
call,
new DynamicMetaObject(body, self.Restrictions.Merge(BindingRestrictions.Combine(args))),
args,
valInfo
);
}
return null;
}
示例8: MakeCompareToNegativeOne
private static void MakeCompareToNegativeOne(ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition, Expression/*!*/ expr, bool reverse, Type retType) {
MakeValueCheck(-1, expr, bodyBuilder, retCondition);
}
示例9: MakeGetExpression
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) {
if (!_info.IsPublic || _info.DeclaringType.ContainsGenericParameters) {
// fallback to reflection
base.MakeGetExpression(binder, codeContext, instance, owner, builder);
} else if (instance == null) {
if (_info.IsStatic) {
builder.FinishCondition(AstUtils.Convert(Ast.Field(null, _info), typeof(object)));
} else {
builder.FinishCondition(Ast.Constant(this));
}
} else {
builder.FinishCondition(
AstUtils.Convert(
Ast.Field(
binder.ConvertExpression(
instance.Expression,
_info.DeclaringType,
ConversionResultKind.ExplicitCast,
new PythonOverloadResolverFactory(binder, codeContext)
),
_info
),
typeof(object)
)
);
}
}
示例10: DoCoerce
/// <summary>
/// calls __coerce__ for old-style classes and performs the operation if the coercion is successful.
/// </summary>
private static void DoCoerce(PythonContext/*!*/ state, ConditionalBuilder/*!*/ bodyBuilder, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse, Func<Expression, Expression> returnTransform) {
ParameterExpression coerceResult = Ast.Variable(typeof(object), "coerceResult");
ParameterExpression coerceTuple = Ast.Variable(typeof(PythonTuple), "coerceTuple");
if (!bodyBuilder.TestCoercionRecursionCheck) {
// during coercion we need to enforce recursion limits if
// they're enabled and the rule's test needs to reflect this.
bodyBuilder.Restrictions = bodyBuilder.Restrictions.Merge(
BindingRestrictions.GetExpressionRestriction(
Ast.Equal(
Ast.Call(typeof(PythonOps).GetMethod("ShouldEnforceRecursion")),
AstUtils.Constant(PythonFunction.EnforceRecursion)
)
)
);
bodyBuilder.TestCoercionRecursionCheck = true;
}
// tmp = self.__coerce__(other)
// if tmp != null && tmp != NotImplemented && (tuple = PythonOps.ValidateCoerceResult(tmp)) != null:
// return operation(tuple[0], tuple[1])
SlotOrFunction slot = SlotOrFunction.GetSlotOrFunction(state, Symbols.Coerce, types);
if (slot.Success) {
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Not(
Ast.TypeIs(
Ast.Assign(
coerceResult,
slot.Target.Expression
),
typeof(OldInstance)
)
),
Ast.NotEqual(
Ast.Assign(
coerceTuple,
Ast.Call(
typeof(PythonOps).GetMethod("ValidateCoerceResult"),
coerceResult
)
),
AstUtils.Constant(null)
)
),
BindingHelpers.AddRecursionCheck(
returnTransform(
Ast.Dynamic(
state.Operation(op | PythonOperationKind.DisableCoerce),
op == PythonOperationKind.Compare ? typeof(int) : typeof(object),
reverse ? CoerceTwo(coerceTuple) : CoerceOne(coerceTuple),
reverse ? CoerceOne(coerceTuple) : CoerceTwo(coerceTuple)
)
)
)
);
bodyBuilder.AddVariable(coerceResult);
bodyBuilder.AddVariable(coerceTuple);
}
}
示例11: MakeCompareToZero
private static void MakeCompareToZero(ConditionalBuilder/*!*/ bodyBuilder, Expression retCondition, Expression/*!*/ expr, bool reverse) {
MakeValueCheck(0, expr, bodyBuilder, retCondition);
}
示例12: MakeComparisonOperation
private static DynamicMetaObject/*!*/ MakeComparisonOperation(DynamicMetaObject/*!*/[]/*!*/ types, DynamicMetaObjectBinder/*!*/ operation, PythonOperationKind opString) {
RestrictTypes(types);
PythonOperationKind op = NormalizeOperator(opString);
BinderState state = BinderState.GetBinderState(operation);
Debug.Assert(types.Length == 2);
DynamicMetaObject xType = types[0], yType = types[1];
SymbolId opSym = Symbols.OperatorToSymbol(op);
SymbolId ropSym = Symbols.OperatorToReversedSymbol(op);
// reverse
DynamicMetaObject[] rTypes = new DynamicMetaObject[] { types[1], types[0] };
SlotOrFunction fop, rop, cmp, rcmp;
fop = SlotOrFunction.GetSlotOrFunction(state, opSym, types);
rop = SlotOrFunction.GetSlotOrFunction(state, ropSym, rTypes);
cmp = SlotOrFunction.GetSlotOrFunction(state, Symbols.Cmp, types);
rcmp = SlotOrFunction.GetSlotOrFunction(state, Symbols.Cmp, rTypes);
ConditionalBuilder bodyBuilder = new ConditionalBuilder(operation);
SlotOrFunction.GetCombinedTargets(fop, rop, out fop, out rop);
SlotOrFunction.GetCombinedTargets(cmp, rcmp, out cmp, out rcmp);
// first try __op__ or __rop__ and return the value
if (MakeOneCompareGeneric(fop, false, types, MakeCompareReturn, bodyBuilder)) {
if (MakeOneCompareGeneric(rop, true, types, MakeCompareReturn, bodyBuilder)) {
// then try __cmp__ or __rcmp__ and compare the resulting int appropriaetly
if (ShouldCoerce(state, opString, xType, yType, true)) {
DoCoerce(state, bodyBuilder, PythonOperationKind.Compare, types, false, delegate(Expression e) {
return GetCompareTest(op, e, false);
});
}
if (MakeOneCompareGeneric(
cmp,
false,
types,
delegate(ConditionalBuilder builder, Expression retCond, Expression expr, bool reverse) {
MakeCompareTest(op, builder, retCond, expr, reverse);
},
bodyBuilder)) {
if (ShouldCoerce(state, opString, yType, xType, true)) {
DoCoerce(state, bodyBuilder, PythonOperationKind.Compare, rTypes, true, delegate(Expression e) {
return GetCompareTest(op, e, true);
});
}
if (MakeOneCompareGeneric(
rcmp,
true,
types,
delegate(ConditionalBuilder builder, Expression retCond, Expression expr, bool reverse) {
MakeCompareTest(op, builder, retCond, expr, reverse);
},
bodyBuilder)) {
bodyBuilder.FinishCondition(MakeFallbackCompare(op, types));
}
}
}
}
return bodyBuilder.GetMetaObject(types);
}
示例13: DoCoerce
private static void DoCoerce(OperationBinder/*!*/ operation, ConditionalBuilder/*!*/ bodyBuilder, string op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse) {
DoCoerce(operation, bodyBuilder, op, types, reverse, delegate(Expression e) {
return e;
});
}
示例14: MakeComparisonOperation
private static DynamicMetaObject/*!*/ MakeComparisonOperation(DynamicMetaObject/*!*/[]/*!*/ types, DynamicMetaObjectBinder/*!*/ operation, PythonOperationKind opString, DynamicMetaObject errorSuggestion) {
RestrictTypes(types);
PythonOperationKind op = NormalizeOperator(opString);
PythonContext state = PythonContext.GetPythonContext(operation);
Debug.Assert(types.Length == 2);
DynamicMetaObject xType = types[0], yType = types[1];
string opSym = Symbols.OperatorToSymbol(op);
string ropSym = Symbols.OperatorToReversedSymbol(op);
// reverse
DynamicMetaObject[] rTypes = new DynamicMetaObject[] { types[1], types[0] };
SlotOrFunction fop, rop, cmp, rcmp;
fop = SlotOrFunction.GetSlotOrFunction(state, opSym, types);
rop = SlotOrFunction.GetSlotOrFunction(state, ropSym, rTypes);
cmp = SlotOrFunction.GetSlotOrFunction(state, "__cmp__", types);
rcmp = SlotOrFunction.GetSlotOrFunction(state, "__cmp__", rTypes);
ConditionalBuilder bodyBuilder = new ConditionalBuilder(operation);
SlotOrFunction.GetCombinedTargets(fop, rop, out fop, out rop);
SlotOrFunction.GetCombinedTargets(cmp, rcmp, out cmp, out rcmp);
bool shouldWarn = false;
WarningInfo info = null;
// first try __op__ or __rop__ and return the value
shouldWarn = fop.ShouldWarn(state, out info);
if (MakeOneCompareGeneric(fop, false, types, MakeCompareReturn, bodyBuilder, typeof(object))) {
shouldWarn = shouldWarn || rop.ShouldWarn(state, out info);
if (MakeOneCompareGeneric(rop, true, types, MakeCompareReturn, bodyBuilder, typeof(object))) {
// then try __cmp__ or __rcmp__ and compare the resulting int appropriaetly
shouldWarn = shouldWarn || cmp.ShouldWarn(state, out info);
if (ShouldCoerce(state, opString, xType, yType, true)) {
DoCoerce(state, bodyBuilder, PythonOperationKind.Compare, types, false, delegate(Expression e) {
return GetCompareTest(op, e, false);
});
}
if (MakeOneCompareGeneric(
cmp,
false,
types,
delegate(ConditionalBuilder builder, Expression retCond, Expression expr, bool reverse, Type retType) {
MakeCompareTest(op, builder, retCond, expr, reverse, retType);
},
bodyBuilder,
typeof(object))) {
shouldWarn = shouldWarn || rcmp.ShouldWarn(state, out info);
if (ShouldCoerce(state, opString, yType, xType, true)) {
DoCoerce(state, bodyBuilder, PythonOperationKind.Compare, rTypes, true, delegate(Expression e) {
return GetCompareTest(op, e, true);
});
}
if (MakeOneCompareGeneric(
rcmp,
true,
types,
delegate(ConditionalBuilder builder, Expression retCond, Expression expr, bool reverse, Type retType) {
MakeCompareTest(op, builder, retCond, expr, reverse, retType);
},
bodyBuilder,
typeof(object))) {
if (errorSuggestion != null) {
bodyBuilder.FinishCondition(errorSuggestion.Expression, typeof(object));
} else {
bodyBuilder.FinishCondition(BindingHelpers.AddPythonBoxing(MakeFallbackCompare(operation, op, types)), typeof(object));
}
}
}
}
}
DynamicMetaObject res = bodyBuilder.GetMetaObject(types);
if (!shouldWarn || res == null) {
return res;
} else {
return info.AddWarning(Ast.Constant(state.SharedContext), res);
}
}
示例15: MemberBindingInfo
public MemberBindingInfo(DynamicMetaObject/*!*/[]/*!*/ args, ConditionalBuilder/*!*/ body, ValidationInfo/*!*/ validation) {
Body = body;
Validation = validation;
Args = args;
}