本文整理汇总了C#中IronRuby.Runtime.Calls.MetaObjectBuilder.SetError方法的典型用法代码示例。如果您正苦于以下问题:C# MetaObjectBuilder.SetError方法的具体用法?C# MetaObjectBuilder.SetError怎么用?C# MetaObjectBuilder.SetError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronRuby.Runtime.Calls.MetaObjectBuilder
的用法示例。
在下文中一共展示了MetaObjectBuilder.SetError方法的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) {
// TODO: splat, rhs, ...
if (args.Signature.ArgumentCount == 0) {
if (args.Signature.HasBlock) {
metaBuilder.Result = Methods.HookupEvent.OpCall(
AstUtils.Constant(this),
args.TargetExpression,
Ast.Convert(args.GetBlockExpression(), typeof(Proc))
);
} else {
metaBuilder.Result = Methods.CreateEvent.OpCall(
AstUtils.Constant(this),
args.TargetExpression,
AstUtils.Constant(name)
);
}
} else {
metaBuilder.SetError(Methods.MakeWrongNumberOfArgumentsError.OpCall(Ast.Constant(args.Signature.ArgumentCount), Ast.Constant(0)));
}
}
示例3: BuildCallNoFlow
internal override void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
Expression expr = null;
Expression instance = _fieldInfo.IsStatic ? null : Ast.Convert(args.TargetExpression, _fieldInfo.DeclaringType);
if (_isSetter) {
// parameters should be: instance/type, value
if (args.SimpleArgumentCount == 0 && args.Signature.HasRhsArgument) {
expr = Ast.Assign(
Ast.Field(instance, _fieldInfo),
// TODO: remove
args.RubyContext.Binder.ConvertExpression(
args.GetRhsArgumentExpression(),
_fieldInfo.FieldType,
ConversionResultKind.ExplicitCast,
args.ScopeExpression
)
);
}
} else {
// parameter should be: instance/type
if (args.SimpleArgumentCount == 0) {
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)
expr = Ast.Constant(_fieldInfo.GetValue(null));
} else {
expr = Ast.Field(instance, _fieldInfo);
}
}
}
if (expr != null) {
metaBuilder.Result = expr;
} else {
metaBuilder.SetError(
Methods.MakeInvalidArgumentTypesError.OpCall(Ast.Constant(_isSetter ? name + "=" : name))
);
}
}
示例4: BuildCallNoFlow
/// <summary>
/// Resolves an library method overload and builds call expression.
/// The resulting expression on meta-builder doesn't handle block control flow yet.
/// </summary>
internal static void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name,
IList<MethodBase>/*!*/ overloads, bool includeSelf, bool selfIsInstance) {
var bindingTarget = ResolveOverload(name, overloads, args, includeSelf, selfIsInstance);
if (bindingTarget.Success) {
bool calleeHasBlockParam = HasBlockParameter(bindingTarget.Method);
// Allocates a variable holding BlockParam. At runtime the BlockParam is created with a new RFC instance that
// identifies the library method frame as a proc-converter target of a method unwinder triggered by break from a block.
//
// NOTE: We check for null block here -> test fore that fact is added in MakeActualArgs
if (metaBuilder.BfcVariable == null && args.Signature.HasBlock && args.GetBlock() != null && calleeHasBlockParam) {
metaBuilder.BfcVariable = metaBuilder.GetTemporary(typeof(BlockParam), "#bfc");
}
var actualArgs = MakeActualArgs(metaBuilder, args, includeSelf, selfIsInstance, calleeHasBlockParam, true);
var parameterBinder = new RubyParameterBinder(args.RubyContext.Binder, args.MetaContext.Expression, args.Signature.HasScope);
var targetExpression = bindingTarget.MakeExpression(parameterBinder, actualArgs);
metaBuilder.Result = targetExpression;
} else {
metaBuilder.SetError(
Methods.MakeInvalidArgumentTypesError.OpCall(Ast.Constant(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;
}
示例6: BuildCall
private void BuildCall(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name) {
var actualArgs = RubyOverloadResolver.NormalizeArguments(metaBuilder, args, 0, Int32.MaxValue);
if (metaBuilder.Error) {
return;
}
metaBuilder.AddRestriction(
Ast.Equal(
Ast.Property(Ast.Convert(args.TargetExpression, typeof(Win32API)), VersionProperty),
Ast.Constant(_version)
)
);
if (_function == IntPtr.Zero) {
metaBuilder.SetError(Ast.Throw(new Func<Exception>(UninitializedFunctionError).Method.OpCall(), typeof(object)));
return;
}
if (_signature.Length != actualArgs.Count) {
metaBuilder.SetError(Ast.Throw(new Func<int, int, Exception>(InvalidParameterCountError).Method.OpCall(
Ast.Constant(_signature.Length), Ast.Constant(actualArgs.Count)), typeof(object)
));
return;
}
var calliArgs = new AstExpressions();
calliArgs.Add(Ast.Property(Ast.Convert(args.TargetExpression, typeof(Win32API)), FunctionProperty));
for (int i = 0; i < actualArgs.Count; i++) {
calliArgs.Add(MarshalArgument(metaBuilder, actualArgs[i], _signature[i]));
}
metaBuilder.Result = Ast.Call(EmitCalliStub(), calliArgs);
// MRI returns 0 if void return type is given:
if (_returnType == ArgType.None) {
metaBuilder.Result = Ast.Block(metaBuilder.Result, AstUtils.Constant(0));
}
}
示例7: BuildCallNoFlow
/// <summary>
/// Resolves an library method overload and builds call expression.
/// The resulting expression on meta-builder doesn't handle block control flow yet.
/// </summary>
internal static void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name,
IList<OverloadInfo>/*!*/ overloads, SelfCallConvention callConvention, bool implicitProtocolConversions) {
RubyOverloadResolver resolver;
var bindingTarget = ResolveOverload(metaBuilder, args, name, overloads, callConvention, implicitProtocolConversions, out resolver);
if (bindingTarget.Success) {
// TODO: create a custom overload info:
if (ReferenceEquals(bindingTarget.Overload.ReflectionInfo, Methods.CreateDefaultInstance)) {
Debug.Assert(args.TargetClass.TypeTracker.Type.IsValueType);
metaBuilder.Result = Ast.New(args.TargetClass.TypeTracker.Type);
} else if (args.Signature.IsVirtualCall && bindingTarget.Overload.IsVirtual) {
// Virtual methods that have been detached from the CLR type and
// defined on the corresponding Ruby class or its subclass are not
// directly invoked from a dynamic virtual call to prevent recursion.
// Instead the base call is performed.
//
// Example:
// class C < ArrayList
// define_method(:Add, instance_method(:Add))
// end
//
// C.new.Add(1)
//
// C.new.Add dispatches to the virtual ArrayList::Add, which in turn dispatches to the auto-generated override C$1::Add.
// That gets here since the defined method is a Ruby method (a detached CLR method group). If we called it directly
// it would invoke the C$1::Add override again leading to a stack overflow. So we need to use a base call instead.
metaBuilder.Result = Ast.Field(null, Fields.ForwardToBase);
} else {
metaBuilder.Result = bindingTarget.MakeExpression();
}
} else {
metaBuilder.SetError(resolver.MakeInvalidParametersError(bindingTarget).Expression);
}
}
示例8: BuildCallNoFlow
/// <summary>
/// Resolves an library method overload and builds call expression.
/// The resulting expression on meta-builder doesn't handle block control flow yet.
/// </summary>
internal static void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name,
IList<MethodBase>/*!*/ overloads, SelfCallConvention callConvention) {
RubyOverloadResolver resolver;
var bindingTarget = ResolveOverload(metaBuilder, args, name, overloads, callConvention, out resolver);
if (bindingTarget.Success) {
metaBuilder.Result = bindingTarget.MakeExpression();
} else {
metaBuilder.SetError(resolver.MakeInvalidParametersError(bindingTarget).Expression);
}
}
示例9: BuildClrObjectConstruction
/// <summary>
/// Implements Class#clr_new feature.
/// </summary>
public void BuildClrObjectConstruction(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ methodName) {
OverloadInfo[] ctors;
if (TypeTracker == null) {
metaBuilder.SetError(Methods.MakeNotClrTypeError.OpCall(Ast.Convert(args.TargetExpression, typeof(RubyClass))));
} else if ((ctors = GetConstructors(TypeTracker.Type).ToArray()).Length == 0) {
metaBuilder.SetError(Methods.MakeConstructorUndefinedError.OpCall(Ast.Convert(args.TargetExpression, typeof(RubyClass))));
} else {
RubyMethodGroupInfo.BuildCallNoFlow(metaBuilder, args, methodName, ctors, SelfCallConvention.NoSelf, true);
}
}
示例10: BuildCallNoFlow
/// <summary>
/// Resolves an library method overload and builds call expression.
/// The resulting expression on meta-builder doesn't handle block control flow yet.
/// </summary>
internal static void BuildCallNoFlow(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ name,
IList<MethodBase>/*!*/ overloads, SelfCallConvention callConvention) {
var bindingTarget = ResolveOverload(name, overloads, args, callConvention);
bool calleeHasBlockParam = bindingTarget.Success && HasBlockParameter(bindingTarget.Method);
// Allocates a variable holding BlockParam. At runtime the BlockParam is created with a new RFC instance that
// identifies the library method frame as a proc-converter target of a method unwinder triggered by break from a block.
if (args.Signature.HasBlock) {
var metaBlock = args.GetMetaBlock();
if (metaBlock.Value != null && calleeHasBlockParam) {
if (metaBuilder.BfcVariable == null) {
metaBuilder.BfcVariable = metaBuilder.GetTemporary(typeof(BlockParam), "#bfc");
}
metaBuilder.ControlFlowBuilder = RuleControlFlowBuilder;
}
// Block test - we need to test for a block regardless of whether it is actually passed to the method or not
// since the information that the block is not null is used for overload resolution.
if (metaBlock.Value == null) {
metaBuilder.AddRestriction(Ast.Equal(metaBlock.Expression, AstUtils.Constant(null)));
} else {
// don't need to test the exact type of the Proc since the code is subclass agnostic:
metaBuilder.AddRestriction(Ast.NotEqual(metaBlock.Expression, AstUtils.Constant(null)));
}
}
var actualArgs = MakeActualArgs(metaBuilder, args, callConvention, calleeHasBlockParam, true);
if (bindingTarget.Success) {
var parameterBinder = new RubyParameterBinder(args.RubyContext.Binder, args.MetaContext.Expression, args.Signature.HasScope);
metaBuilder.Result = bindingTarget.MakeExpression(parameterBinder, actualArgs);
} else {
metaBuilder.SetError(args.RubyContext.RubyBinder.MakeInvalidParametersError(bindingTarget).Expression);
}
}
示例11: BuildConversion
internal static bool BuildConversion(MetaObjectBuilder/*!*/ metaBuilder, DynamicMetaObject/*!*/ target, Expression/*!*/ contextExpression,
Type/*!*/ toType, bool defaultFallback) {
Expression expr = TryImplicitConversion(target, toType);
if (expr != null) {
metaBuilder.Result = expr;
metaBuilder.AddObjectTypeRestriction(target.Value, target.Expression);
return true;
}
if (defaultFallback) {
metaBuilder.AddObjectTypeRestriction(target.Value, target.Expression);
metaBuilder.SetError(Methods.MakeTypeConversionError.OpCall(
contextExpression,
AstUtils.Convert(target.Expression, typeof(object)),
Ast.Constant(toType)
));
return true;
}
return false;
}
示例12: 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);
}
}
示例13: InteropBind
protected override DynamicMetaObject/*!*/ InteropBind(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args) {
metaBuilder.SetError(Ast.New(
typeof(NotSupportedException).GetConstructor(new[] { typeof(string) }),
Ast.Constant("Super call not supported on foreign meta-objects")
));
return metaBuilder.CreateMetaObject(this);
}
示例14: BindToMethodMissing
internal static bool BindToMethodMissing(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ methodName,
RubyMemberInfo methodMissing, RubyMethodVisibility incompatibleVisibility, bool isSuperCall, bool defaultFallback) {
// Assumption: args already contain method name.
// TODO: better check for builtin method
if (methodMissing == null ||
methodMissing.DeclaringModule == methodMissing.Context.KernelModule && methodMissing is RubyLibraryMethodInfo) {
if (isSuperCall) {
metaBuilder.SetError(Methods.MakeMissingSuperException.OpCall(AstUtils.Constant(methodName)));
} else if (incompatibleVisibility == RubyMethodVisibility.Private) {
metaBuilder.SetError(Methods.MakePrivateMethodCalledError.OpCall(
AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)), args.TargetExpression, AstUtils.Constant(methodName))
);
} else if (incompatibleVisibility == RubyMethodVisibility.Protected) {
metaBuilder.SetError(Methods.MakeProtectedMethodCalledError.OpCall(
AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)), args.TargetExpression, AstUtils.Constant(methodName))
);
} else if (defaultFallback) {
args.InsertMethodName(methodName);
methodMissing.BuildCall(metaBuilder, args, methodName);
} else {
return false;
}
} else {
args.InsertMethodName(methodName);
methodMissing.BuildCall(metaBuilder, args, methodName);
}
return true;
}
示例15: BuildMethodMissingAccess
// Returns true if the call was bound (with success or failure), false if fallback should be performed.
internal static bool BuildMethodMissingAccess(MetaObjectBuilder/*!*/ metaBuilder, CallArguments/*!*/ args, string/*!*/ methodName,
RubyMemberInfo methodMissing, RubyMethodVisibility incompatibleVisibility, bool isSuperCall, bool defaultFallback) {
switch (BindToKernelMethodMissing(metaBuilder, args, methodName, methodMissing, incompatibleVisibility, isSuperCall)) {
case MethodMissingBinding.Custom:
// we pretend we found the member and return a method that calls method_missing:
Debug.Assert(!metaBuilder.Error);
metaBuilder.Result = Methods.CreateBoundMissingMember.OpCall(
AstUtils.Convert(args.TargetExpression, typeof(object)),
Ast.Constant(methodMissing, typeof(RubyMemberInfo)),
Ast.Constant(methodName)
);
return true;
case MethodMissingBinding.Error:
// method_missing is defined in Kernel, error has been reported:
return true;
case MethodMissingBinding.Fallback:
// method_missing is defined in Kernel:
if (defaultFallback) {
metaBuilder.SetError(Methods.MakeMissingMemberError.OpCall(Ast.Constant(methodName)));
return true;
}
return false;
}
throw Assert.Unreachable;
}