protected override DynamicMetaObject SetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type type, DynamicMetaObject value, DynamicMetaObject instance, DynamicMetaObject errorSuggestion) { return new DynamicMetaObject( Expression.Condition( Ast.Call( typeof(PythonOps).GetMethod("SlotTrySetValue"), ((PythonOverloadResolverFactory)factory)._codeContext, AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)), AstUtils.Convert( instance.Expression, typeof(object) ), AstUtils.Constant(DynamicHelpers.GetPythonTypeFromType(type)), value.Expression ), AstUtils.Convert(value.Expression, typeof(object)), errorSuggestion != null ? errorSuggestion.Expression : Expression.Throw( Expression.Call( typeof(PythonOps).GetMethod("AttributeErrorForMissingAttribute", new Type[] { typeof(object), typeof(string) }), instance.Expression, Expression.Constant(Name) ), typeof(object) ) ), BindingRestrictions.Empty ); }
public ParameterWrapper(ActionBinder binder, ParameterInfo info) : this(binder, info.ParameterType) { _name = SymbolTable.StringToId(info.Name ?? "<unknown>"); _isParams = info.IsDefined(typeof(ParamArrayAttribute), false); }
public ToyEngine(LanguageProvider provider, EngineOptions engineOptions) : base(provider, engineOptions) { IronPython.Runtime.Operations.Ops.Bool2Object(true); //awful initialization hack IronPython.Runtime.Operations.Ops.RegisterAssembly(typeof(ToyEngine).Assembly); _defaultContext = new ToyContext(this); _defaultBinder = new DefaultActionBinder(new CodeContext(null, _defaultContext)); }
/// <summary> /// Internal helper to produce the actual expression used for the error when emitting /// the error into a rule. /// </summary> public Statement MakeErrorForRule(StandardRule rule, ActionBinder binder) { if (_value != null) { rule.IsError = true; return rule.MakeReturn(binder, _value); } return rule.MakeError(_exception); }
public DefaultOverloadResolver(ActionBinder binder, IList<DynamicMetaObject> args, CallSignature signature, CallTypes callType) : base(binder) { ContractUtils.RequiresNotNullItems(args, "args"); Debug.Assert((callType == CallTypes.ImplicitInstance ? 1 : 0) + signature.ArgumentCount == args.Count); _args = args; _signature = signature; _callType = callType; }
public Expression GetBoundPythonValue(RuleBuilder builder, ActionBinder binder, PythonType accessing) { return Ast.Call( typeof(PythonOps).GetMethod("SlotGetValue"), builder.Context, Ast.Constant(GetSlot(), typeof(PythonTypeSlot)), Ast.Constant(null), Ast.Constant(accessing) ); }
public RubyParameterBinder(ActionBinder/*!*/ binder, Expression/*!*/ scopeOrContextExpression, bool isScope) : base(binder) { Assert.NotNull(binder, scopeOrContextExpression); if (isScope) { _scopeExpression = AstUtils.Convert(scopeOrContextExpression, typeof(RubyScope)); } else { _contextExpression = AstUtils.Convert(scopeOrContextExpression, typeof(RubyContext)); } }
protected override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance) { return Ast.Call( typeof(PythonOps).GetMethod("SlotGetValue"), context, Ast.Constant(GetSlot(), typeof(PythonTypeSlot)), AstUtils.Convert( instance, typeof(object) ), Ast.Constant(DynamicHelpers.GetPythonTypeFromType(type)) ); }
public ParameterWrapper(ActionBinder binder, ParameterInfo info, Type type, SymbolId name, bool prohibitNull, bool isParams, bool isParamsDict) { ContractUtils.RequiresNotNull(binder, "binder"); ContractUtils.RequiresNotNull(type, "type"); _type = type; _prohibitNull = prohibitNull; _binder = binder; _info = info; _name = name; _isParams = isParams; _isParamsDict = isParamsDict; }
public override ErrorInfo GetError(ActionBinder binder) { MethodInfo getter = ResolveGetter(binder.PrivateBinding); if (getter == null) { return binder.MakeMissingMemberErrorInfo(DeclaringType, Name); } if (getter.ContainsGenericParameters) { return binder.MakeGenericAccessError(this); } throw new InvalidOperationException(); }
public ParameterWrapper(ActionBinder binder, ParameterInfo info) : this(binder, info, info.ParameterType, SymbolId.Empty, false, false, false) { _prohibitNull = CompilerHelpers.ProhibitsNull(info); _isParams = CompilerHelpers.IsParamArray(info); _isParamsDict = BinderHelpers.IsParamDictionary(info); if (_isParams || _isParamsDict) { // params arrays & dictionaries don't allow assignment by keyword _name = SymbolTable.StringToId("<unknown>"); } else { _name = SymbolTable.StringToId(info.Name ?? "<unknown>"); } }
public MethodBinderContext(ActionBinder actionBinder #if FULL , StandardRule rule #endif ) { _actionBinder = actionBinder; #if FULL _rule = rule; #endif }
protected override DynamicMetaObject GetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type type, DynamicMetaObject instance) { return new DynamicMetaObject( Ast.Call( typeof(PythonOps).GetMethod("SlotGetValue"), ((PythonOverloadResolverFactory)factory)._codeContext, AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)), AstUtils.Convert( instance.Expression, typeof(object) ), AstUtils.Constant(DynamicHelpers.GetPythonTypeFromType(type)) ), BindingRestrictions.Empty ); }
public ParameterWrapper(ActionBinder binder, ParameterInfo info) : this(binder, info.ParameterType) { _name = SymbolTable.StringToId(info.Name ?? "<unknown>"); #if FULL _prohibitNull = info.IsDefined(typeof(NotNullAttribute), false); #endif _isParams = info.IsDefined(typeof(ParamArrayAttribute), false); #if FULL _isParamsDict = info.IsDefined(typeof(ParamDictionaryAttribute), false); #endif }
internal static void Initialize(IronSchemeLanguageProvider ironSchemeLanguageProvider) { lp = ironSchemeLanguageProvider; se = lp.GetEngine() as IronSchemeScriptEngine; scriptmodule = ScriptDomainManager.CurrentManager.Host.DefaultModule as ScriptModule; ModuleContext mc = new ModuleContext(scriptmodule); mc.CompilerContext = new CompilerContext(SourceUnit.CreateSnippet(se, "")); cc = new CodeContext(scriptmodule.Scope, se.GetLanguageContext(), mc); binder = new IronScheme.Actions.IronSchemeActionBinder(cc); Generator.initme = true; }
public static MSA.DynamicExpression/*!*/ MakeCallAction(string/*!*/ name, ActionBinder/*!*/ binder, RubyCallSignature signature, params MSA.Expression[]/*!*/ args) { RubyCallAction call = RubyCallAction.Make(name, signature); switch (args.Length) { case 0: return Ast.Dynamic(call, typeof(object), AstFactory.EmptyExpressions); case 1: return Ast.Dynamic(call, typeof(object), args[0]); case 2: return Ast.Dynamic(call, typeof(object), args[0], args[1]); case 3: return Ast.Dynamic(call, typeof(object), args[0], args[1], args[2]); case 4: return Ast.Dynamic(call, typeof(object), args[0], args[1], args[2], args[3]); default: return Ast.Dynamic( call, typeof(object), new ReadOnlyCollection<MSA.Expression>(args) ); } }
public override ErrorInfo GetBoundError(ActionBinder binder, DynamicMetaObject instance, Type instanceType) { MethodInfo getter = ResolveGetter(instanceType, binder.PrivateBinding); if (getter == null) { return binder.MakeMissingMemberErrorInfo(DeclaringType, Name); } if (getter.ContainsGenericParameters) { return binder.MakeGenericAccessError(this); } if (IsStatic) { return binder.MakeStaticPropertyInstanceAccessError(this, false, instance); } throw new InvalidOperationException(); }
public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type) { if (!IsStatic || GetIndexParameters().Length > 0) { // need to bind to a value or parameters to get the value. return binder.ReturnMemberTracker(type, this); } MethodInfo getter = ResolveGetter(binder.PrivateBinding); if (getter == null || getter.ContainsGenericParameters) { // no usable getter return null; } if (getter.IsPublic && getter.DeclaringType.IsPublic) { return binder.MakeCallExpression(resolverFactory, getter); } // private binding is just a call to the getter method... return MemberTracker.FromMemberInfo(getter).Call(resolverFactory, binder); }
private MethodBinder(ActionBinder binder, string name, IList<MethodBase> methods, BinderType binderType, SymbolId[] kwArgs) { _binder = binder; _name = name; _binderType = binderType; _kwArgs = kwArgs; foreach (MethodBase method in methods) { if (IsUnsupported(method)) continue; AddBasicMethodTargets(method); } if (_paramsCandidates != null) { foreach (MethodCandidate maker in _paramsCandidates) { foreach (int count in _targetSets.Keys) { MethodCandidate target = maker.MakeParamsExtended(binder, count, _kwArgs); if (target != null) AddTarget(target); } } } }
public ParameterWrapper(ActionBinder binder, Type type, bool prohibitNull, SymbolId name) : this(binder, type, prohibitNull) { _name = name; }
public ParameterWrapper(ActionBinder binder, Type type, SymbolId name) : this(binder, type) { _name = name; }
public override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { return(binder.ReturnMemberTracker(type, BindToInstance(instance))); }
public static OldDeleteMemberAction Make(ActionBinder binder, string name) { return(Make(binder, SymbolTable.StringToId(name))); }
internal override DynamicMetaObject Call(OverloadResolverFactory resolverFactory, ActionBinder binder, params DynamicMetaObject[] arguments) { if (Method.IsPublic && Method.DeclaringType.IsVisible()) { return(binder.MakeCallExpression(resolverFactory, Method, arguments)); } //methodInfo.Invoke(obj, object[] params) if (Method.IsStatic) { return(new DynamicMetaObject( Expression.Convert( Expression.Call( AstUtils.Constant(Method), typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }), AstUtils.Constant(null), AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(arguments, x => x.Expression)) ), Method.ReturnType ), BindingRestrictions.Empty ) ); } if (arguments.Length == 0) { throw Error.NoInstanceForCall(); } return(new DynamicMetaObject( Expression.Convert( Expression.Call( AstUtils.Constant(Method), typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }), arguments[0].Expression, AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(ArrayUtils.RemoveFirst(arguments), x => x.Expression)) ), Method.ReturnType ), BindingRestrictions.Empty )); }
protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { if (IsPublic && DeclaringType.IsVisible) { return(new DynamicMetaObject( AstUtils.Convert( Expression.Field( AstUtils.Convert(instance.Expression, Field.DeclaringType), Field ), typeof(object) ), BindingRestrictions.Empty )); } return(DefaultBinder.MakeError(((DefaultBinder)binder).MakeNonPublicMemberGetError(resolverFactory, this, type, instance), BindingRestrictions.Empty, typeof(object))); }
/// <summary> /// Gets an expression that assigns a value to the left hand side. /// /// Returns null if it's an error to assign to. The caller can then call GetErrorForSet to /// get the correct error Expression (or null if a default error should be provided). /// </summary> public virtual DynamicMetaObject SetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType, DynamicMetaObject value) { return(null); }
public static OldCallAction Make(ActionBinder binder, CallSignature signature) { ContractUtils.RequiresNotNull(binder, "binder"); return(new OldCallAction(binder, signature)); }
protected OldCallAction(ActionBinder binder, CallSignature callSignature) { _binder = binder; _signature = callSignature; }
/// <summary> /// Returns the error associated with getting the value. /// /// A null return value indicates that the default error message should be provided by the caller. /// </summary> public virtual ErrorInfo GetError(ActionBinder binder, Type instanceType) { return(null); }
public override DynamicMetaObject SetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject value) { return SetBoundValue(resolverFactory, binder, type, value, new DynamicMetaObject(AstUtils.Constant(null), BindingRestrictions.Empty)); }
public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type) { return new DynamicMetaObject(AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)), BindingRestrictions.Empty); }
protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { return binder.ReturnMemberTracker(type, BindToInstance(instance)); }
public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType) { return base.GetValue(resolverFactory, binder, instanceType); }
/// <summary> /// Helper for setting values that have been bound. Called from BoundMemberTracker. Custom member /// trackers can override this to provide their own behaviors when bound to an instance. /// </summary> public virtual DynamicMetaObject SetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType, DynamicMetaObject value, DynamicMetaObject instance) { return(SetValue(resolverFactory, binder, instanceType, instance)); }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Call")] // TODO: fix internal virtual DynamicMetaObject Call(OverloadResolverFactory resolverFactory, ActionBinder binder, params DynamicMetaObject[] arguments) { return(null); }
public static OldCallAction Make(ActionBinder binder, int argumentCount) { ContractUtils.Requires(argumentCount >= 0, "argumentCount"); ContractUtils.RequiresNotNull(binder, "binder"); return(new OldCallAction(binder, new CallSignature(argumentCount))); }
/// <summary> /// Helper for setting values that have been bound. Called from BoundMemberTracker. Custom member /// trackers can override this to provide their own behaviors when bound to an instance. /// </summary> protected internal virtual Expression SetBoundValue(Expression context, ActionBinder binder, Type type, Expression value, Expression instance) { return(SetValue(context, binder, type, instance)); }
protected internal override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance) { return binder.ReturnMemberTracker(type, BindToInstance(instance)); }
public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type) { if (Field.IsLiteral) { return(new DynamicMetaObject( AstUtils.Constant(Field.GetValue(null), typeof(object)), BindingRestrictions.Empty )); } if (!IsStatic) { // return the field tracker... return(binder.ReturnMemberTracker(type, this)); } if (Field.DeclaringType.ContainsGenericParameters) { return(null); } if (IsPublic && DeclaringType.IsPublic) { return(new DynamicMetaObject( Expression.Convert(Expression.Field(null, Field), typeof(object)), BindingRestrictions.Empty )); } return(new DynamicMetaObject( Expression.Call( AstUtils.Convert(AstUtils.Constant(Field), typeof(FieldInfo)), typeof(FieldInfo).GetMethod("GetValue"), AstUtils.Constant(null) ), BindingRestrictions.Empty )); }
internal override System.Linq.Expressions.Expression Call(Expression context, ActionBinder binder, params Expression[] arguments) { if (Method.IsPublic && Method.DeclaringType.IsVisible) { // TODO: Need to use MethodBinder in here to make this right. return binder.MakeCallExpression(context, Method, arguments); } //methodInfo.Invoke(obj, object[] params) if (Method.IsStatic) { return Ast.Convert( Ast.Call( Ast.Constant(Method), typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }), Ast.Constant(null), AstUtils.NewArrayHelper(typeof(object), arguments) ), Method.ReturnType); } if (arguments.Length == 0) throw Error.NoInstanceForCall(); return Ast.Convert( Ast.Call( Ast.Constant(Method), typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }), arguments[0], AstUtils.NewArrayHelper(typeof(object), ArrayUtils.RemoveFirst(arguments)) ), Method.ReturnType); }
private OldDeleteMemberAction(ActionBinder binder, SymbolId name) : base(binder, name) { }
protected internal override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance) { return(binder.ReturnMemberTracker(type, BindToInstance(instance))); }
public static OldDeleteMemberAction Make(ActionBinder binder, SymbolId name) { ContractUtils.RequiresNotNull(binder, "binder"); return(new OldDeleteMemberAction(binder, name)); }
public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType) { return(BoundTo.GetBoundValue(resolverFactory, binder, instanceType, Instance)); }
public ParameterWrapper(ActionBinder binder, Type type) { _type = type; _binder = binder; }
public override DynamicMetaObject SetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { return(BoundTo.SetBoundValue(resolverFactory, binder, instanceType, value, Instance, errorSuggestion)); }
public ParameterWrapper(ActionBinder binder, Type type, bool prohibitNull) { _type = type; _prohibitNull = prohibitNull; _binder = binder; }
// method call: public DefaultOverloadResolver(ActionBinder binder, IList <DynamicMetaObject> args, CallSignature signature) : this(binder, args, signature, CallTypes.None) { }
protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { if (instance != null && IsStatic) { return(null); } if (GetIndexParameters().Length > 0) { // need to bind to a value or parameters to get the value. return(binder.ReturnMemberTracker(type, BindToInstance(instance))); } MethodInfo getter = GetGetMethod(true); if (getter == null || getter.ContainsGenericParameters) { // no usable getter return(null); } // TODO (tomat): this used to use getter.ReflectedType, is it still correct? getter = CompilerHelpers.TryGetCallableMethod(instance.GetLimitType(), getter); var defaultBinder = (DefaultBinder)binder; if (binder.PrivateBinding || CompilerHelpers.IsVisible(getter)) { return(defaultBinder.MakeCallExpression(resolverFactory, getter, instance)); } // private binding is just a call to the getter method... return(DefaultBinder.MakeError(defaultBinder.MakeNonPublicMemberGetError(resolverFactory, this, type, instance), BindingRestrictions.Empty, typeof(object))); }
/// <summary> /// Returns the error associated with accessing this member via a bound instance. /// /// A null return value indicates that the default error message should be provided by the caller. /// </summary> public virtual ErrorInfo GetBoundError(ActionBinder binder, DynamicMetaObject instance, Type instanceType) { return(null); }
public override Expression GetValue(Expression context, ActionBinder binder, Type type) { return(base.GetValue(context, binder, type)); }
/// <summary> /// Gets the expression that creates the value. /// /// Returns null if it's an error to get the value. The caller can then call GetErrorForGet to get /// the correct error Expression (or null if they should provide a default). /// </summary> public virtual Expression GetValue(Expression context, ActionBinder binder, Type type) { return(binder.ReturnMemberTracker(type, this)); }
public override ErrorInfo GetError(ActionBinder binder, Type instanceType) { return(BoundTo.GetBoundError(binder, Instance, instanceType)); }
/// <summary> /// Gets an expression that assigns a value to the left hand side. /// /// Returns null if it's an error to assign to. The caller can then call GetErrorForSet to /// get the correct error Expression (or null if a default error should be provided). /// </summary> public virtual Expression SetValue(Expression context, ActionBinder binder, Type type, Expression value) { return(null); }
// instance method call: public DefaultOverloadResolver(ActionBinder binder, DynamicMetaObject instance, IList <DynamicMetaObject> args, CallSignature signature) : this(binder, ArrayUtils.Insert(instance, args), signature, CallTypes.ImplicitInstance) { }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Call")] // TODO: fix internal virtual Expression Call(Expression context, ActionBinder binder, params Expression[] arguments) { return(null); }
/// <summary> /// ParameterInfo is not available. /// </summary> public ParameterWrapper(ActionBinder binder, Type type, SymbolId name, bool prohibitNull) : this(binder, null, type, name, prohibitNull, false, false) { }
/// <summary> /// Returns the error associated with getting the value. /// /// A null return value indicates that the default error message should be provided by the caller. /// </summary> public virtual ErrorInfo GetError(ActionBinder binder) { return(null); }
public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type instanceType) { if (!IsStatic || GetIndexParameters().Length > 0) { // need to bind to a value or parameters to get the value. return(binder.ReturnMemberTracker(instanceType, this)); } MethodInfo getter = ResolveGetter(instanceType, binder.PrivateBinding); if (getter == null || getter.ContainsGenericParameters) { // no usable getter return(null); } if (getter.IsPublic && getter.DeclaringType.IsPublic()) { return(binder.MakeCallExpression(resolverFactory, getter)); } // private binding is just a call to the getter method... return(MemberTracker.FromMemberInfo(getter).Call(resolverFactory, binder)); }
/// <summary> /// Returns the error associated with accessing this member via a bound instance. /// /// A null return value indicates that the default error message should be provided by the caller. /// </summary> public virtual ErrorInfo GetBoundError(ActionBinder binder, Expression instance) { return(null); }