private static ErrorInfo MakeIncorrectArgumentCountError(BindingTarget target) { int minArgs = Int32.MaxValue; int maxArgs = Int32.MinValue; foreach (int argCnt in target.ExpectedArgumentCount) { minArgs = System.Math.Min(minArgs, argCnt); maxArgs = System.Math.Max(maxArgs, argCnt); } return(ErrorInfo.FromException( Ast.Call( typeof(BinderOps).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] { typeof(string), typeof(int), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(bool) }), Ast.Constant(target.Name, typeof(string)), // name Ast.Constant(minArgs), // min formal normal arg cnt Ast.Constant(maxArgs), // max formal normal arg cnt Ast.Constant(0), // default cnt Ast.Constant(target.ActualArgumentCount), // args provided Ast.Constant(false), // hasArgList Ast.Constant(false) // kwargs provided ) )); }
private ErrorInfo MakeAmbiguousCallError(BindingTarget target) { StringBuilder sb = new StringBuilder("Multiple targets could match: "); string outerComma = ""; foreach (MethodTarget mt in target.AmbiguousMatches) { Type[] types = mt.GetParameterTypes(); string innerComma = ""; sb.Append(outerComma); sb.Append(target.Name); sb.Append('('); foreach (Type t in types) { sb.Append(innerComma); sb.Append(GetTypeName(t)); innerComma = ", "; } sb.Append(')'); outerComma = ", "; } return(ErrorInfo.FromException( Ast.Call( typeof(BinderOps).GetMethod("SimpleTypeError"), Ast.Constant(sb.ToString(), typeof(string)) ) )); }
private ErrorInfo MakeInvalidSplatteeError(BindingTarget target) { return ErrorInfo.FromException( Ast.Call(typeof(BinderOps).GetMethod("InvalidSplatteeError"), AstUtils.Constant(target.Name), AstUtils.Constant(Binder.GetTypeName(_invalidSplattee.GetLimitType())) ) ); }
/// <summary> /// Provides a way for the binder to provide a custom error message when lookup fails. Just /// doing this for the time being until we get a more robust error return mechanism. /// /// Deprecated, use the non-generic version instead /// </summary> public virtual ErrorInfo MakeMissingMemberError(Type type, DynamicMetaObject self, string name) { return(ErrorInfo.FromException( Expression.New( typeof(MissingMemberException).GetConstructor(new[] { typeof(string) }), AstUtils.Constant(name) ) )); }
public virtual ErrorInfo MakeContainsGenericParametersError(MemberTracker tracker) { return(ErrorInfo.FromException( Expression.New( typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) }), AstUtils.Constant(Strings.InvalidOperation_ContainsGenericParameters(tracker.DeclaringType.Name, tracker.Name)) ) )); }
public virtual ErrorInfo MakeGenericAccessError(MemberTracker info) { return(ErrorInfo.FromException( Expression.New( typeof(MemberAccessException).GetConstructor(new[] { typeof(string) }), AstUtils.Constant(info.Name) ) )); }
public virtual ErrorInfo MakeMissingMemberErrorInfo(Type type, string name) { return(ErrorInfo.FromException( Ast.Ast.New( typeof(MissingMemberException).GetConstructor(new Type[] { typeof(string) }), Ast.Ast.Constant(name) ) )); }
/// <summary> /// Provides a way for the binder to provide a custom error message when lookup fails. Just /// doing this for the time being until we get a more robust error return mechanism. /// </summary> public virtual ErrorInfo MakeReadOnlyMemberError(Type type, string name) { return(ErrorInfo.FromException( Expression.New( typeof(MissingMemberException).GetConstructor(new Type[] { typeof(string) }), AstUtils.Constant(name) ) )); }
public virtual ErrorInfo MakeConversionError(Type toType, Expression value) { return(ErrorInfo.FromException( Expression.Call( new Func <Type, object, Exception>(ScriptingRuntimeHelpers.CannotConvertError).GetMethodInfo(), AstUtils.Constant(toType), AstUtils.Convert(value, typeof(object)) ) )); }
public virtual ErrorInfo MakeConversionError(Type toType, Expression value) { return(ErrorInfo.FromException( Ast.Ast.Call( typeof(RuntimeHelpers).GetMethod("CannotConvertError"), Ast.Ast.RuntimeConstant(toType), value ) )); }
public virtual ErrorInfo MakeInvalidParametersError(string name, int expectedParams, params Expression[] args) { return(ErrorInfo.FromException( Ast.Ast.Call( typeof(RuntimeHelpers).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] { typeof(string), typeof(int), typeof(int) }), Ast.Ast.Constant(name), Ast.Ast.Constant(args.Length), Ast.Ast.Constant(expectedParams) ) )); }
public virtual ErrorInfo MakeSetValueTypeFieldError(FieldTracker field, DynamicMetaObject instance, DynamicMetaObject value) { return(ErrorInfo.FromException( Expression.Throw( Expression.New( typeof(ArgumentException).GetConstructor(new[] { typeof(string) }), AstUtils.Constant("cannot assign to value types") ), typeof(object) ) )); }
private DynamicMetaObject MakeCannotCallRule(DynamicMetaObject self, Type type) { return MakeError( ErrorInfo.FromException( Expression.New( typeof(ArgumentTypeException).GetConstructor(new Type[] { typeof(string) }), AstUtils.Constant(GetTypeName(type) + " is not callable") ) ), self.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(self.Expression, type)), typeof(object) ); }
private MetaObject MakeCannotCallRule(MetaObject self, Type type) { return(MakeError( ErrorInfo.FromException( Ast.New( typeof(ArgumentTypeException).GetConstructor(new Type[] { typeof(string) }), Ast.Constant(type.Name + " is not callable") ) ), self.Restrictions.Merge(Restrictions.GetTypeRestriction(self.Expression, type)) )); }
public virtual ErrorInfo MakeConversionError(Type toType, Expression value) { return(ErrorInfo.FromException( Expression.Call( typeof(ScriptingRuntimeHelpers).GetMethod("CannotConvertError"), Expression.Constant(toType), Expression.Convert( value, typeof(object) ) ) )); }
/// <summary> /// Creates an ErrorInfo object when a static property is accessed from an instance member. The default behavior is throw /// an exception indicating that static members properties be accessed via an instance. Languages can override this to /// customize the exception, message, or to produce an ErrorInfo object which reads or writes to the property being accessed. /// </summary> /// <param name="tracker">The static property being accessed through an instance</param> /// <param name="isAssignment">True if the user is assigning to the property, false if the user is reading from the property</param> /// <param name="parameters">The parameters being used to access the property. This includes the instance as the first entry, any index parameters, and the /// value being assigned as the last entry if isAssignment is true.</param> /// <returns></returns> public virtual ErrorInfo MakeStaticPropertyInstanceAccessError(PropertyTracker tracker, bool isAssignment, IList <DynamicMetaObject> parameters) { ContractUtils.RequiresNotNull(tracker, "tracker"); ContractUtils.Requires(tracker.IsStatic, "tracker", Strings.ExpectedStaticProperty); ContractUtils.RequiresNotNull(parameters, "parameters"); ContractUtils.RequiresNotNullItems(parameters, "parameters"); string message = isAssignment ? Strings.StaticAssignmentFromInstanceError(tracker.Name, tracker.DeclaringType.Name) : Strings.StaticAccessFromInstanceError(tracker.Name, tracker.DeclaringType.Name); return(ErrorInfo.FromException( Expression.New( typeof(MissingMemberException).GetConstructor(new[] { typeof(string) }), AstUtils.Constant(message) ) )); }
private ErrorInfo MakeCallFailureError(BindingTarget target) { foreach (CallFailure cf in target.CallFailures) { switch (cf.Reason) { case CallFailureReason.ConversionFailure: foreach (ConversionResult cr in cf.ConversionResults) { if (cr.Failed) { return(ErrorInfo.FromException( Ast.Call( typeof(BinderOps).GetMethod("SimpleTypeError"), Ast.Constant(String.Format("expected {0}, got {1}", GetTypeName(cr.To), GetTypeName(cr.From))) ) )); } } break; case CallFailureReason.DuplicateKeyword: return(ErrorInfo.FromException( Ast.Call( typeof(BinderOps).GetMethod("TypeErrorForDuplicateKeywordArgument"), Ast.Constant(target.Name, typeof(string)), Ast.Constant(SymbolTable.IdToString(cf.KeywordArguments[0]), typeof(string)) // TODO: Report all bad arguments? ) )); case CallFailureReason.UnassignableKeyword: return(ErrorInfo.FromException( Ast.Call( typeof(BinderOps).GetMethod("TypeErrorForExtraKeywordArgument"), Ast.Constant(target.Name, typeof(string)), Ast.Constant(SymbolTable.IdToString(cf.KeywordArguments[0]), typeof(string)) // TODO: Report all bad arguments? ) )); default: throw new InvalidOperationException(); } } throw new InvalidOperationException(); }