本文整理汇总了C#中IronRuby.Runtime.Calls.MetaObjectBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MetaObjectBuilder类的具体用法?C# MetaObjectBuilder怎么用?C# MetaObjectBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetaObjectBuilder类属于IronRuby.Runtime.Calls命名空间,在下文中一共展示了MetaObjectBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
protected override bool Build(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, bool defaultFallback) {
if (TryImplicitConversion(metaBuilder, args)) {
metaBuilder.AddObjectTypeRestriction(args.Target, args.TargetExpression);
return true;
}
// TODO: this is our meta object, should we add IRubyMetaConvertible interface instead of using interop-binder?
if (args.Target is IDynamicMetaObjectProvider) {
metaBuilder.SetMetaResult(args.MetaTarget.BindConvert(new InteropBinder.Convert(args.RubyContext, _type, true)), false);
return true;
}
if (defaultFallback) {
metaBuilder.AddObjectTypeRestriction(args.Target, args.TargetExpression);
metaBuilder.SetError(Methods.MakeTypeConversionError.OpCall(
args.MetaContext.Expression,
AstUtils.Convert(args.TargetExpression, typeof(object)),
Ast.Constant(_type)
));
return true;
}
return false;
}
示例2: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
Expression instance = _fieldInfo.IsStatic ? null : Ast.Convert(args.TargetExpression, _fieldInfo.DeclaringType);
if (_isSetter) {
var actualArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 1, 1);
if (!metaBuilder.Error) {
metaBuilder.Result = Ast.Assign(
Ast.Field(instance, _fieldInfo),
Converter.ConvertExpression(
actualArgs[0].Expression,
_fieldInfo.FieldType,
args.RubyContext,
args.MetaContext.Expression,
true
)
);
}
} else {
RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, 0);
if (!metaBuilder.Error) {
if (_fieldInfo.IsLiteral) {
// TODO: seems like Compiler should correctly handle the literal field case
// (if you emit a read to a literal field, you get a NotSupportedExpception from
// FieldHandle when we try to emit)
metaBuilder.Result = AstUtils.Constant(_fieldInfo.GetValue(null));
} else {
metaBuilder.Result = Ast.Field(instance, _fieldInfo);
}
}
}
}
示例3: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
metaBuilder.Result = Methods.GetInstanceVariable.OpCall(
args.ScopeExpression,
AstFactory.Box(args.TargetExpression),
AstUtils.Constant(InstanceVariableName)
);
}
示例4: InteropBind
private DynamicMetaObject/*!*/ InteropBind(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
// TODO: argument count limit depends on the binder!
// TODO: pass block as the last (before RHS arg?) parameter/ignore block if args not accepting block:
var normalizedArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, Int32.MaxValue);
if (!metaBuilder.Error) {
MethodInfo postConverter;
var interopBinder = GetInteropBinder(args.RubyContext, normalizedArgs, out postConverter);
if (interopBinder != null) {
Type resultType;
var result = interopBinder.Bind(args.MetaTarget, ArrayUtils.MakeArray(normalizedArgs));
metaBuilder.SetMetaResult(result, args);
if (postConverter != null) {
// TODO: do better?
var paramType = postConverter.GetParameters()[0].ParameterType;
metaBuilder.Result = Ast.Call(null, postConverter, AstUtils.Convert(metaBuilder.Result, paramType));
resultType = postConverter.ReturnType;
} else {
resultType = ((IInteropBinder)interopBinder).ResultType;
}
return metaBuilder.CreateMetaObject(interopBinder, resultType);
} else {
metaBuilder.SetError(Ast.New(
typeof(NotSupportedException).GetConstructor(new[] { typeof(string) }),
Ast.Constant(String.Format("{0} not supported on foreign meta-objects", this))
));
}
}
return metaBuilder.CreateMetaObject(this);
}
示例5: TryBind
public static DynamicMetaObject TryBind(RubyContext/*!*/ context, GetMemberBinder/*!*/ binder, DynamicMetaObject/*!*/ target) {
Assert.NotNull(context, target);
var metaBuilder = new MetaObjectBuilder();
var contextExpression = AstUtils.Constant(context);
RubyClass targetClass = context.GetImmediateClassOf(target.Value);
MethodResolutionResult method;
RubyMemberInfo methodMissing = null;
using (targetClass.Context.ClassHierarchyLocker()) {
metaBuilder.AddTargetTypeTest(target.Value, targetClass, target.Expression, context, contextExpression);
method = targetClass.ResolveMethodForSiteNoLock(binder.Name, RubyClass.IgnoreVisibility);
if (method.Found) {
methodMissing = targetClass.ResolveMethodForSiteNoLock(Symbols.MethodMissing, RubyClass.IgnoreVisibility).Info;
}
}
if (method.Found) {
// we need to create a bound member:
metaBuilder.Result = AstUtils.Constant(new RubyMethod(target.Value, method.Info, binder.Name));
} else {
// TODO:
// We need to throw an exception if we don't find method_missing so that our version update optimization works:
// This limits interop with other languages.
//
// class B CLR type with method 'foo'
// class C < B Ruby class
// x = C.new
//
// 1. x.GET("foo") from Ruby
// No method found or CLR method found -> fallback to Python
// Python might see its method foo or might just fallback to .NET,
// in any case it will add rule [1] with restriction on type of C w/o Ruby version check.
// 2. B.define_method("foo")
// This doesn't update C due to the optimization (there is no overridden method foo in C).
// 3. x.GET("foo") from Ruby
// This will not invoke the binder since the rule [1] is still valid.
//
object symbol = SymbolTable.StringToId(binder.Name);
RubyCallAction.BindToMethodMissing(metaBuilder,
new CallArguments(
new DynamicMetaObject(contextExpression, BindingRestrictions.Empty, context),
new[] {
target,
new DynamicMetaObject(AstUtils.Constant(symbol), BindingRestrictions.Empty, symbol)
},
RubyCallSignature.Simple(1)
),
binder.Name,
methodMissing,
method.IncompatibleVisibility,
false
);
}
// TODO: we should return null if we fail, we need to throw exception for now:
return metaBuilder.CreateMetaObject(binder, DynamicMetaObject.EmptyMetaObjects);
}
示例6: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
Proc.BuildCall(
metaBuilder,
AstUtils.Constant(_lambda), // proc object
args.TargetExpression, // self
args
);
}
示例7: RubyOverloadResolver
internal RubyOverloadResolver(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, SelfCallConvention callConvention,
bool implicitProtocolConversions)
: base(args.RubyContext.Binder) {
_args = args;
_metaBuilder = metaBuilder;
_callConvention = callConvention;
_implicitProtocolConversions = implicitProtocolConversions;
}
示例8: Build
protected override bool Build(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, bool defaultFallback) {
// TODO: this is our meta object, should we add IRubyMetaConvertible interface instead of using interop-binder?
if (args.Target is IDynamicMetaObjectProvider) {
metaBuilder.SetMetaResult(args.MetaTarget.BindConvert(new InteropBinder.Convert(args.RubyContext, _type, true)), false);
return true;
}
return BuildConversion(metaBuilder, args.MetaTarget, args.MetaContext.Expression, _type, defaultFallback);
}
示例9: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
var visibleOverloads = GetVisibleOverloads(args, MethodBases, false);
if (visibleOverloads.Count == 0) {
metaBuilder.SetError(Methods.MakeClrProtectedMethodCalledError.OpCall(
args.MetaContext.Expression, args.MetaTarget.Expression, Ast.Constant(name)
));
} else {
BuildCallNoFlow(metaBuilder, args, name, visibleOverloads, CallConvention, ImplicitProtocolConversions);
}
}
示例10: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, 0);
if (!metaBuilder.Error) {
metaBuilder.Result = Methods.GetInstanceVariable.OpCall(
AstUtils.Convert(args.MetaScope.Expression, typeof(RubyScope)),
AstUtils.Box(args.TargetExpression),
AstUtils.Constant(InstanceVariableName)
);
}
}
示例11: 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;
}
示例12: Bind
public override DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ scopeOrContextOrTarget, DynamicMetaObject/*!*/[]/*!*/ args) {
var callArgs = new CallArguments(_context, scopeOrContextOrTarget, args, Signature);
var metaBuilder = new MetaObjectBuilder(this, args);
if (IsForeignMetaObject(callArgs.MetaTarget)) {
return InteropBind(metaBuilder, callArgs);
}
Build(metaBuilder, callArgs, true);
return metaBuilder.CreateMetaObject(this);
}
示例13: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
Debug.Assert(!args.Signature.HasBlock);
Proc.SetProcCallRule(
metaBuilder,
Ast.Constant(_lambda), // proc object
args.TargetExpression, // self
Ast.Constant(this), // this method for super and class_eval
args
);
}
示例14: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
if (args.Signature.HasBlock) {
metaBuilder.Result = Methods.HookupEvent.OpCall(
Ast.Convert(Ast.Constant(_eventInfo), typeof(EventInfo)),
args.TargetExpression,
Ast.Convert(args.GetBlockExpression(), typeof(Proc))
);
} else {
// TODO: make error
throw new NotImplementedError("no block given");
}
}
示例15: Bind
public override DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, DynamicMetaObject/*!*/[]/*!*/ args) {
var callArgs = new CallArguments(context, args, Signature);
// TODO: COM interop
if (IsForeignMetaObject(callArgs.MetaTarget)) {
return InteropBind(callArgs);
}
var metaBuilder = new MetaObjectBuilder();
Build(metaBuilder, callArgs);
return metaBuilder.CreateMetaObject(this);
}