本文整理汇总了C#中Microsoft.Scripting.Actions.Calls.OverloadResolver.GetTemporary方法的典型用法代码示例。如果您正苦于以下问题:C# OverloadResolver.GetTemporary方法的具体用法?C# OverloadResolver.GetTemporary怎么用?C# OverloadResolver.GetTemporary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Scripting.Actions.Calls.OverloadResolver
的用法示例。
在下文中一共展示了OverloadResolver.GetTemporary方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToExpression
internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
if (_tmp == null) {
_tmp = resolver.GetTemporary(_elementType, "outParam");
}
Debug.Assert(!hasBeenUsed[Index]);
hasBeenUsed[Index] = true;
Expression arg = args.GetObject(Index).Expression;
return Expression.Condition(
Expression.TypeIs(arg, Type),
Expression.Assign(
_tmp,
Expression.Field(
AstUtils.Convert(arg, Type),
Type.GetField("Value")
)
),
Expression.Throw(
Expression.Call(
new Func<Type, object, Exception>(RuntimeHelpers.MakeIncorrectBoxTypeError).Method,
AstUtils.Constant(_elementType),
AstUtils.Convert(arg, typeof(object))
),
_elementType
)
);
}
示例2: ToExpression
internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
if (_tmp == null) {
_tmp = resolver.GetTemporary(_elementType, "outParam");
}
Debug.Assert(!hasBeenUsed[Index]);
hasBeenUsed[Index] = true;
Type boxType = typeof(StrongBox<>).MakeGenericType(_elementType);
Expression arg = args.GetObject(Index).Expression;
return Expression.Condition(
Expression.TypeIs(arg, Type),
Expression.Assign(
_tmp,
Expression.Field(
AstUtils.Convert(arg, boxType),
boxType.GetField("Value")
)
),
Expression.Call(
typeof(RuntimeHelpers).GetMethod("IncorrectBoxType").MakeGenericMethod(_elementType),
AstUtils.Convert(arg, typeof(object))
)
);
}
示例3: ToExpression
internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
if (_tmp == null) {
_tmp = resolver.GetTemporary(Type, "outParam");
}
return Ast.Block(Ast.Assign(_tmp, base.ToExpression(resolver, args, hasBeenUsed)), _tmp);
}
示例4: ToExpression
internal protected override Expression ToExpression(OverloadResolver resolver, IList<Expression> parameters, bool[] hasBeenUsed) {
if (_tmp == null) {
_tmp = resolver.GetTemporary(Type, "outParam");
}
return Ast.Block(Ast.Assign(_tmp, base.ToExpression(resolver, parameters, hasBeenUsed)), _tmp);
}
示例5: ToExpression
internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
if (_isRef) {
if (_tmp == null) {
_tmp = resolver.GetTemporary(_parameterType, "outParam");
}
return _tmp;
}
return GetDefaultValue();
}
示例6: ToExpression
internal override Expression ToExpression(OverloadResolver resolver, IList<ArgBuilder> builders, RestrictedArguments args, Expression ret) {
List<Expression> sets = new List<Expression>();
ParameterExpression tmp = resolver.GetTemporary(ret.Type, "val");
sets.Add(
Ast.Assign(tmp, ret)
);
for (int i = 0; i < _indexesUsed.Length; i++) {
Expression value = args.GetObject(args.Length - _kwArgCount + _indexesUsed[i]).Expression;
switch(_membersSet[i].MemberType) {
case MemberTypes.Field:
FieldInfo fi = (FieldInfo)_membersSet[i];
if (!fi.IsLiteral && !fi.IsInitOnly) {
sets.Add(
Ast.Assign(
Ast.Field(tmp, fi),
ConvertToHelper(resolver, value, fi.FieldType)
)
);
} else {
// call a helper which throws the error but "returns object"
sets.Add(
Ast.Convert(
Ast.Call(
typeof(ScriptingRuntimeHelpers).GetMethod("ReadOnlyAssignError"),
AstUtils.Constant(true),
AstUtils.Constant(fi.Name)
),
fi.FieldType
)
);
}
break;
case MemberTypes.Property:
PropertyInfo pi = (PropertyInfo)_membersSet[i];
if (pi.GetSetMethod(_privateBinding) != null) {
sets.Add(
Ast.Assign(
Ast.Property(tmp, pi),
ConvertToHelper(resolver, value, pi.PropertyType)
)
);
} else {
// call a helper which throws the error but "returns object"
sets.Add(
Ast.Convert(
Ast.Call(
typeof(ScriptingRuntimeHelpers).GetMethod("ReadOnlyAssignError"),
AstUtils.Constant(false),
AstUtils.Constant(pi.Name)
),
pi.PropertyType
)
);
}
break;
}
}
sets.Add(
tmp
);
Expression newCall = Ast.Block(
sets.ToArray()
);
return _builder.ToExpression(resolver, builders, args, newCall);
}
示例7: ToExpression
internal protected override Expression ToExpression(OverloadResolver resolver, RestrictedArguments args, bool[] hasBeenUsed) {
var actualArgs = resolver.GetActualArguments();
int splatIndex = actualArgs.SplatIndex;
int collapsedCount = actualArgs.CollapsedCount;
int firstSplatted = actualArgs.FirstSplattedArg;
var result = new Expression[2 + _expandedCount + (collapsedCount > 0 ? 2 : 0)];
var arrayVariable = resolver.GetTemporary(_elementType.MakeArrayType(), "a");
int e = 0;
result[e++] = Ast.Assign(arrayVariable, Ast.NewArrayBounds(_elementType, Ast.Constant(_expandedCount + collapsedCount)));
int itemIndex = 0;
int i = _start;
while (true) {
// inject loop copying collapsed items:
if (i == splatIndex) {
var indexVariable = resolver.GetTemporary(typeof(int), "t");
// for (int t = 0; t <= {collapsedCount}; t++) {
// a[{itemIndex} + t] = CONVERT<ElementType>(list.get_Item({splatIndex - firstSplatted} + t))
// }
result[e++] = Ast.Assign(indexVariable, AstUtils.Constant(0));
result[e++] = AstUtils.Loop(
Ast.LessThan(indexVariable, Ast.Constant(collapsedCount)),
// TODO: not implemented in the old interpreter
// Ast.PostIncrementAssign(indexVariable),
Ast.Assign(indexVariable, Ast.Add(indexVariable, AstUtils.Constant(1))),
Ast.Assign(
Ast.ArrayAccess(arrayVariable, Ast.Add(AstUtils.Constant(itemIndex), indexVariable)),
resolver.Convert(
new DynamicMetaObject(
resolver.GetSplattedItemExpression(Ast.Add(AstUtils.Constant(splatIndex - firstSplatted), indexVariable)),
BindingRestrictions.Empty
),
null,
ParameterInfo,
_elementType
)
),
null
);
itemIndex += collapsedCount;
}
if (i >= _start + _expandedCount) {
break;
}
Debug.Assert(!hasBeenUsed[i]);
hasBeenUsed[i] = true;
result[e++] = Ast.Assign(
Ast.ArrayAccess(arrayVariable, AstUtils.Constant(itemIndex++)),
resolver.Convert(args.GetObject(i), args.GetType(i), ParameterInfo, _elementType)
);
i++;
}
result[e++] = arrayVariable;
Debug.Assert(e == result.Length);
return Ast.Block(result);
}