本文整理汇总了C#中IronRuby.Runtime.Calls.CallArguments.SetTarget方法的典型用法代码示例。如果您正苦于以下问题:C# CallArguments.SetTarget方法的具体用法?C# CallArguments.SetTarget怎么用?C# CallArguments.SetTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronRuby.Runtime.Calls.CallArguments
的用法示例。
在下文中一共展示了CallArguments.SetTarget方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
protected override bool Build(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, bool defaultFallback) {
RubyModule currentDeclaringModule;
string currentMethodName;
var scope = args.Scope;
object target;
scope.GetSuperCallTarget(out currentDeclaringModule, out currentMethodName, out target);
var targetExpression = metaBuilder.GetTemporary(typeof(object), "#super-self");
metaBuilder.AddCondition(
Methods.IsSuperCallTarget.OpCall(
AstUtils.Convert(args.MetaScope.Expression, typeof(RubyScope)),
AstUtils.Constant(currentDeclaringModule),
AstUtils.Constant(currentMethodName),
targetExpression
)
);
args.SetTarget(targetExpression, target);
Debug.Assert(currentDeclaringModule != null);
RubyMemberInfo method;
RubyMemberInfo methodMissing = null;
// we need to lock the hierarchy of the target class:
var targetClass = scope.RubyContext.GetImmediateClassOf(target);
using (targetClass.Context.ClassHierarchyLocker()) {
// initialize all methods in ancestors:
targetClass.InitializeMethodsNoLock();
// target is stored in a local, therefore it cannot be part of the restrictions:
metaBuilder.TreatRestrictionsAsConditions = true;
metaBuilder.AddTargetTypeTest(target, targetClass, targetExpression, args.MetaContext,
new[] { Symbols.MethodMissing } // currentMethodName is resolved for super, which cannot be an instance singleton
);
metaBuilder.TreatRestrictionsAsConditions = false;
method = targetClass.ResolveSuperMethodNoLock(currentMethodName, currentDeclaringModule).InvalidateSitesOnOverride().Info;
if (method == null) {
// MRI: method_missing is called for the targetClass, not for the super:
methodMissing = targetClass.ResolveMethodMissingForSite(currentMethodName, RubyMethodVisibility.None);
}
}
if (method != null) {
method.BuildSuperCall(metaBuilder, args, currentMethodName, currentDeclaringModule);
} else {
return RubyCallAction.BuildMethodMissingCall(metaBuilder, args, currentMethodName, methodMissing, RubyMethodVisibility.None, true, defaultFallback);
}
return true;
}
示例2: BuildInvoke
internal void BuildInvoke(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
Assert.NotNull(metaBuilder, args);
Debug.Assert(args.Target == this);
// TODO: we could compare infos here:
// first argument must be this method:
metaBuilder.AddRestriction(Ast.Equal(args.TargetExpression, AstUtils.Constant(this)));
// set the target (becomes self in the called method):
args.SetTarget(AstUtils.Constant(_target), _target);
_info.BuildCall(metaBuilder, args, _name);
}
示例3: BuildOverriddenInitializerCall
private static void BuildOverriddenInitializerCall(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, RubyMemberInfo/*!*/ initializer) {
var instanceExpr = metaBuilder.Result;
metaBuilder.Result = null;
var instanceVariable = metaBuilder.GetTemporary(instanceExpr.Type, "#instance");
// We know an exact type of the new instance and that there is no singleton for that instance.
// We also have the exact method we need to call ("initialize" is a RubyMethodInfo/RubyLambdaMethodInfo).
// => no tests are necessary:
args.SetTarget(instanceVariable, null);
if (initializer is RubyMethodInfo || initializer is RubyLambdaMethodInfo) {
initializer.BuildCallNoFlow(metaBuilder, args, Symbols.Initialize);
} else {
// TODO: we need more refactoring of RubyMethodGroupInfo.BuildCall to be able to inline this:
metaBuilder.Result = AstUtils.LightDynamic(
RubyCallAction.Make(args.RubyContext, "initialize",
new RubyCallSignature(
args.Signature.ArgumentCount,
(args.Signature.Flags & ~RubyCallFlags.IsInteropCall) | RubyCallFlags.HasImplicitSelf
)
),
args.GetCallSiteArguments(instanceVariable)
);
}
if (!metaBuilder.Error) {
// PropagateRetrySingleton(instance = new <type>(), instance.initialize(<args>))
metaBuilder.Result = Methods.PropagateRetrySingleton.OpCall(
Ast.Assign(instanceVariable, instanceExpr),
metaBuilder.Result
);
// we need to handle break, which unwinds to a proc-converter that could be this method's frame:
if (args.Signature.HasBlock) {
metaBuilder.ControlFlowBuilder = RubyMethodInfo.RuleControlFlowBuilder;
}
}
}
示例4: BuildInvoke
internal virtual void BuildInvoke(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
Assert.NotNull(metaBuilder, args);
Debug.Assert(args.Target == this);
// first argument must be this method:
metaBuilder.AddRestriction(Ast.Equal(args.TargetExpression, AstUtils.Constant(this)));
// set the target (becomes self in the called method):
args.SetTarget(AstUtils.Constant(_target, CompilerHelpers.GetVisibleType(_target)), _target);
_info.BuildCall(metaBuilder, args, _name);
}
示例5: Build
protected override bool Build(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, bool defaultFallback)
{
RubyModule currentDeclaringModule;
string currentMethodName;
var scope = args.Scope;
var scopeExpr = AstUtils.Convert(args.MetaScope.Expression, typeof(RubyScope));
RubyScope targetScope;
int scopeNesting = scope.GetSuperCallTarget(out currentDeclaringModule, out currentMethodName, out targetScope);
if (scopeNesting == -1) {
metaBuilder.AddCondition(Methods.IsSuperOutOfMethodScope.OpCall(scopeExpr));
metaBuilder.SetError(Methods.MakeTopLevelSuperException.OpCall());
return true;
}
object target = targetScope.SelfObject;
var targetExpression = metaBuilder.GetTemporary(typeof(object), "#super-self");
var assignTarget = Ast.Assign(
targetExpression,
Methods.GetSuperCallTarget.OpCall(scopeExpr, AstUtils.Constant(scopeNesting))
);
if (_signature.HasImplicitArguments && targetScope.Kind == ScopeKind.BlockMethod) {
metaBuilder.AddCondition(Ast.NotEqual(assignTarget, Ast.Field(null, Fields.NeedsUpdate)));
metaBuilder.SetError(Methods.MakeImplicitSuperInBlockMethodError.OpCall());
return true;
}
// If we need to update we return RubyOps.NeedsUpdate instance that will cause the subsequent conditions to fail:
metaBuilder.AddInitialization(assignTarget);
args.SetTarget(targetExpression, target);
Debug.Assert(currentDeclaringModule != null);
RubyMemberInfo method;
RubyMemberInfo methodMissing = null;
// MRI bug: Uses currentDeclaringModule for method look-up so we can end up with an instance method of class C
// called on a target of another class. See http://redmine.ruby-lang.org/issues/show/2419.
// we need to lock the hierarchy of the target class:
var targetClass = scope.RubyContext.GetImmediateClassOf(target);
using (targetClass.Context.ClassHierarchyLocker()) {
// initialize all methods in ancestors:
targetClass.InitializeMethodsNoLock();
// target is stored in a local, therefore it cannot be part of the restrictions:
metaBuilder.TreatRestrictionsAsConditions = true;
metaBuilder.AddTargetTypeTest(target, targetClass, targetExpression, args.MetaContext,
new[] { Symbols.MethodMissing } // currentMethodName is resolved for super, which cannot be an instance singleton
);
metaBuilder.TreatRestrictionsAsConditions = false;
method = targetClass.ResolveSuperMethodNoLock(currentMethodName, currentDeclaringModule).InvalidateSitesOnOverride().Info;
if (_signature.ResolveOnly) {
metaBuilder.Result = AstUtils.Constant(method != null);
return true;
}
if (method == null) {
// MRI: method_missing is called for the targetClass, not for the super:
methodMissing = targetClass.ResolveMethodMissingForSite(currentMethodName, RubyMethodVisibility.None);
}
}
if (method != null) {
method.BuildSuperCall(metaBuilder, args, currentMethodName, currentDeclaringModule);
} else {
return RubyCallAction.BuildMethodMissingCall(metaBuilder, args, currentMethodName, methodMissing, RubyMethodVisibility.None, true, defaultFallback);
}
return true;
}