本文整理汇总了C#中ConditionalBuilder.AddVariable方法的典型用法代码示例。如果您正苦于以下问题:C# ConditionalBuilder.AddVariable方法的具体用法?C# ConditionalBuilder.AddVariable怎么用?C# ConditionalBuilder.AddVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConditionalBuilder
的用法示例。
在下文中一共展示了ConditionalBuilder.AddVariable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: MakeOneCompareGeneric
/// <summary>
/// Helper to handle a comparison operator call. Checks to see if the call can
/// return NotImplemented and allows the caller to modify the expression that
/// is ultimately returned (e.g. to turn __cmp__ into a bool after a comparison)
/// </summary>
private static bool MakeOneCompareGeneric(SlotOrFunction/*!*/ target, bool reverse, DynamicMetaObject/*!*/[]/*!*/ types, ComparisonHelper returner, ConditionalBuilder/*!*/ bodyBuilder, Type retType) {
if (target == SlotOrFunction.Empty || !target.Success) return true;
ParameterExpression tmp;
if (target.ReturnType == typeof(bool)) {
tmp = bodyBuilder.CompareRetBool;
} else {
tmp = Ast.Variable(target.ReturnType, "compareRetValue");
bodyBuilder.AddVariable(tmp);
}
if (target.MaybeNotImplemented) {
Expression call = target.Target.Expression;
Expression assign = Ast.Assign(tmp, call);
returner(
bodyBuilder,
Ast.NotEqual(
assign,
AstUtils.Constant(PythonOps.NotImplemented)
),
tmp,
reverse,
retType);
return true;
} else {
returner(
bodyBuilder,
null,
target.Target.Expression,
reverse,
retType
);
return false;
}
}
示例3: MakeSlotCallWorker
private static void MakeSlotCallWorker(PythonContext/*!*/ state, PythonTypeSlot/*!*/ slotTarget, Expression/*!*/ self, ConditionalBuilder/*!*/ bodyBuilder, params Expression/*!*/[]/*!*/ args) {
// Generate:
//
// SlotTryGetValue(context, slot, selfType, out callable) && (tmp=callable(args)) != NotImplemented) ?
// tmp :
// RestOfOperation
//
ParameterExpression callable = Ast.Variable(typeof(object), "slot");
ParameterExpression tmp = Ast.Variable(typeof(object), "slot");
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Call(
typeof(PythonOps).GetMethod("SlotTryGetValue"),
AstUtils.Constant(state.SharedContext),
AstUtils.Convert(Utils.WeakConstant(slotTarget), typeof(PythonTypeSlot)),
AstUtils.Convert(self, typeof(object)),
Ast.Call(
typeof(DynamicHelpers).GetMethod("GetPythonType"),
AstUtils.Convert(self, typeof(object))
),
callable
),
Ast.NotEqual(
Ast.Assign(
tmp,
DynamicExpression.Dynamic(
state.Invoke(
new CallSignature(args.Length)
),
typeof(object),
ArrayUtils.Insert(AstUtils.Constant(state.SharedContext), (Expression)callable, args)
)
),
Ast.Property(null, typeof(PythonOps).GetProperty("NotImplemented"))
)
),
tmp
);
bodyBuilder.AddVariable(callable);
bodyBuilder.AddVariable(tmp);
}
示例4: 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);
}
}
示例5: 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);
}
}