// instance method call: public PythonOverloadResolver(PythonBinder binder, DynamicMetaObject instance, IList<DynamicMetaObject> args, CallSignature signature, Expression codeContext) : base(binder, instance, args, signature) { Assert.NotNull(codeContext); _context = codeContext; }
public override DynamicMetaObject /*!*/ GetExpression(PythonBinder /*!*/ binder) { PythonOverloadResolver resolve; if (_creating.IsSystemType || _creating.HasSystemCtor) { resolve = new PythonOverloadResolver( binder, Arguments.Arguments, Arguments.Signature, CodeContext ); } else { resolve = new PythonOverloadResolver( binder, ArrayUtils.Insert(Arguments.Self, Arguments.Arguments), GetDynamicNewSignature(), CodeContext ); } return(binder.CallMethod( resolve, _creating.UnderlyingSystemType.GetConstructors(), Arguments.Self.Restrictions, _creating.Name )); }
/// <summary> /// Gets an expression which is used for accessing this slot. If the slot lookup fails the error expression /// is used again. /// /// The default implementation just calls the TryGetValue method. Subtypes of PythonTypeSlot can override /// this and provide a more optimal implementation. /// </summary> internal virtual Expression/*!*/ MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, Expression/*!*/ error) { ParameterExpression tmp = Ast.Variable(typeof(object), "slotTmp"); Expression call = Ast.Call( typeof(PythonOps).GetMethod("SlotTryGetValue"), codeContext, AstUtils.Convert(AstUtils.WeakConstant(this), typeof(PythonTypeSlot)), instance ?? AstUtils.Constant(null), owner, tmp ); if (!GetAlwaysSucceeds) { call = Ast.Condition( call, tmp, AstUtils.Convert(error, typeof(object)) ); } else { call = Ast.Block(call, tmp); } return Ast.Block( new ParameterExpression[] { tmp }, call ); }
// instance method call: public PythonOverloadResolver(PythonBinder binder, DynamicMetaObject instance, IList <DynamicMetaObject> args, CallSignature signature, Expression codeContext) : base(binder, instance, args, signature) { Assert.NotNull(codeContext); _context = codeContext; }
public static bool ShouldWarn(PythonBinder/*!*/ binder, MethodBase/*!*/ method, out WarningInfo info) { Assert.NotNull(method); ObsoleteAttribute[] os = (ObsoleteAttribute[])method.GetCustomAttributes(typeof(ObsoleteAttribute), true); if (os.Length > 0) { info = new WarningInfo( PythonExceptions.DeprecationWarning, String.Format("{0}.{1} has been obsoleted. {2}", NameConverter.GetTypeName(method.DeclaringType), method.Name, os[0].Message ) ); return true; } if (binder.WarnOnPython3000) { Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.GetCustomAttributes(typeof(Python3WarningAttribute), true); if (py3kwarnings.Length > 0) { info = new WarningInfo( PythonExceptions.DeprecationWarning, py3kwarnings[0].Message ); return true; } } #if !SILVERLIGHT // no apartment states on Silverlight if (method.DeclaringType == typeof(Thread)) { if (method.Name == "Sleep") { info = new WarningInfo( PythonExceptions.RuntimeWarning, "Calling Thread.Sleep on an STA thread doesn't pump messages. Use Thread.CurrentThread.Join instead.", Expression.Equal( Expression.Call( Expression.Property( null, typeof(Thread).GetProperty("CurrentThread") ), typeof(Thread).GetMethod("GetApartmentState") ), AstUtils.Constant(ApartmentState.STA) ), () => Thread.CurrentThread.GetApartmentState() == ApartmentState.STA ); return true; } } #endif info = null; return false; }
internal override Expression/*!*/ MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, Expression/*!*/ error) { if (instance != null) { return Ast.Call( typeof(PythonOps).GetMethod("MakeBoundBuiltinFunction"), Ast.Constant(_template), instance ); } return Ast.Constant(this); }
public override DynamicMetaObject /*!*/ MakeInitCall(PythonBinder /*!*/ binder, DynamicMetaObject /*!*/ createExpr) { Expression init = Ast.Call( typeof(PythonOps).GetMethod("GetMixedMember"), CodeContext, Ast.Convert(Arguments.Self.Expression, typeof(PythonType)), AstUtils.Convert(createExpr.Expression, typeof(object)), AstUtils.Constant("__init__") ); return(MakeDefaultInit(binder, createExpr, init)); }
public virtual DynamicMetaObject /*!*/ GetExpression(PythonBinder /*!*/ binder) { return(MakeDefaultNew( binder, Ast.Call( typeof(PythonOps).GetMethod(nameof(PythonOps.PythonTypeGetMember)), CodeContext, AstUtils.Convert(Arguments.Self.Expression, typeof(PythonType)), AstUtils.Constant(null), AstUtils.Constant("__new__") ) )); }
public override DynamicMetaObject /*!*/ GetExpression(PythonBinder /*!*/ binder) { return(binder.CallMethod( new PythonOverloadResolver( binder, ArrayUtils.Insert(Arguments.Self, Arguments.Arguments), Arguments.Signature.InsertArgument(new Argument(ArgumentType.Simple)), CodeContext ), _ctor.Targets, _creating.Name )); }
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, ConditionalBuilder/*!*/ builder) { if (instance != null) { builder.FinishCondition( Ast.Call( typeof(PythonOps).GetMethod("MakeBoundBuiltinFunction"), AstUtils.Constant(_template), instance ) ); } else { builder.FinishCondition(AstUtils.Constant(this)); } }
public override DynamicMetaObject /*!*/ GetExpression(PythonBinder /*!*/ binder) { return(MakeDefaultNew( binder, Ast.Call( typeof(PythonOps).GetMethod("GetMixedMember"), CodeContext, Arguments.Self.Expression, AstUtils.Constant(null), AstUtils.Constant("__new__") ) )); }
internal static DynamicMetaObject FallbackWorker(PythonContext context, DynamicMetaObject /*!*/ self, DynamicMetaObject /*!*/ codeContext, string name, GetMemberOptions options, DynamicMetaObjectBinder action, DynamicMetaObject errorSuggestion) { if (self.NeedsDeferral()) { return(action.Defer(self)); } PythonOverloadResolverFactory resolverFactory = new PythonOverloadResolverFactory(context.Binder, codeContext.Expression); PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "FallbackGet"); bool isNoThrow = ((options & GetMemberOptions.IsNoThrow) != 0) ? true : false; Type limitType = self.GetLimitType(); if (limitType == typeof(DynamicNull) || PythonBinder.IsPythonType(limitType)) { // look up in the PythonType so that we can // get our custom method names (e.g. string.startswith) PythonType argType = DynamicHelpers.GetPythonTypeFromType(limitType); // if the name is defined in the CLS context but not the normal context then // we will hide it. if (argType.IsHiddenMember(name)) { DynamicMetaObject baseRes = PythonContext.GetPythonContext(action).Binder.GetMember( name, self, resolverFactory, isNoThrow, errorSuggestion ); Expression failure = GetFailureExpression(limitType, self, name, isNoThrow, action); return(BindingHelpers.FilterShowCls(codeContext, action, baseRes, failure)); } } var res = PythonContext.GetPythonContext(action).Binder.GetMember(name, self, resolverFactory, isNoThrow, errorSuggestion); // Default binder can return something typed to boolean or int. // If that happens, we need to apply Python's boxing rules. if (res.Expression.Type.IsValueType) { res = new DynamicMetaObject( AstUtils.Convert(res.Expression, typeof(object)), res.Restrictions ); } return(res); }
public override DynamicMetaObject /*!*/ GetExpression(PythonBinder /*!*/ binder) { PythonOverloadResolver resolver; if (_creating.IsSystemType || _creating.HasSystemCtor) { resolver = new PythonOverloadResolver(binder, DynamicMetaObject.EmptyMetaObjects, new CallSignature(0), CodeContext); } else { resolver = new PythonOverloadResolver(binder, new[] { Arguments.Self }, new CallSignature(1), CodeContext); } return(binder.CallMethod(resolver, _creating.UnderlyingSystemType.GetConstructors(), BindingRestrictions.Empty, _creating.Name)); }
public override DynamicMetaObject /*!*/ MakeInitCall(PythonBinder /*!*/ binder, DynamicMetaObject /*!*/ createExpr) { if (_method == InstanceOps.Init.Template) { // we have a default __init__, don't call it. return(createExpr); } return(binder.CallMethod( new PythonOverloadResolver( binder, createExpr, Arguments.Arguments, Arguments.Signature, CodeContext ), _method.Targets, Arguments.Self.Restrictions )); }
protected DynamicMetaObject /*!*/ MakeDefaultInit(PythonBinder /*!*/ binder, DynamicMetaObject /*!*/ createExpr, Expression /*!*/ init) { List <Expression> args = new List <Expression>(); args.Add(CodeContext); args.Add(Expression.Convert(createExpr.Expression, typeof(object))); foreach (DynamicMetaObject mo in Arguments.Arguments) { args.Add(mo.Expression); } return(new DynamicMetaObject( Expression.Dynamic( ((PythonType)Arguments.Self.Value).GetLateBoundInitBinder(Arguments.Signature), typeof(object), args.ToArray() ), Arguments.Self.Restrictions.Merge(createExpr.Restrictions) )); }
/// <summary> /// Gets an expression which is used for accessing this slot. If the slot lookup fails the error expression /// is used again. /// /// The default implementation just calls the TryGetValue method. Subtypes of PythonTypeSlot can override /// this and provide a more optimal implementation. /// </summary> internal virtual void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) { ParameterExpression tmp = Ast.Variable(typeof(object), "slotTmp"); Expression call = Ast.Call( typeof(PythonOps).GetMethod("SlotTryGetValue"), codeContext, AstUtils.Convert(AstUtils.WeakConstant(this), typeof(PythonTypeSlot)), instance != null ? instance.Expression : AstUtils.Constant(null), owner.Expression, tmp ); builder.AddVariable(tmp); if (!GetAlwaysSucceeds) { builder.AddCondition( call, tmp ); } else { builder.FinishCondition(Ast.Block(call, tmp)); } }
public PythonExtensionBinder(PythonBinder binder, ExtensionMethodSet extensionMethods) : base(binder) { _extMethodSet = extensionMethods; }
internal override Expression/*!*/ MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, Expression/*!*/ error) { if (!_info.IsPublic || _info.DeclaringType.ContainsGenericParameters) { // fallback to reflection return base.MakeGetExpression(binder, codeContext, instance, owner, error); } if (instance == null) { if (_info.IsStatic) { return Ast.Field(null, _info); } else { return AstUtils.Constant(this); } } else { return Ast.Field( binder.ConvertExpression( instance, _info.DeclaringType, ConversionResultKind.ExplicitCast, codeContext ), _info ); } }
public PythonOverloadResolverFactory(PythonBinder/*!*/ binder, Expression/*!*/ codeContext) { Assert.NotNull(binder, codeContext); _binder = binder; _codeContext = codeContext; }
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) { if (!_info.IsPublic || _info.DeclaringType.ContainsGenericParameters) { // fallback to reflection base.MakeGetExpression(binder, codeContext, instance, owner, builder); } else if (instance == null) { if (_info.IsStatic) { builder.FinishCondition(AstUtils.Convert(Ast.Field(null, _info), typeof(object))); } else { builder.FinishCondition(Ast.Constant(this)); } } else { builder.FinishCondition( AstUtils.Convert( Ast.Field( binder.ConvertExpression( instance.Expression, _info.DeclaringType, ConversionResultKind.ExplicitCast, new PythonOverloadResolverFactory(binder, codeContext) ), _info ), typeof(object) ) ); } }
// method call: public PythonOverloadResolver(PythonBinder binder, IList<DynamicMetaObject> args, CallSignature signature, Expression codeContext) : this(binder, args, signature, CallTypes.None, codeContext) { }
internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) { if (Getter.Length != 0 && !Getter[0].IsPublic) { // fallback to runtime call base.MakeGetExpression(binder, codeContext, instance, owner, builder); } else if (NeedToReturnProperty(instance, Getter)) { builder.FinishCondition(AstUtils.Constant(this)); } else if (Getter[0].ContainsGenericParameters) { builder.FinishCondition( DefaultBinder.MakeError( binder.MakeContainsGenericParametersError( MemberTracker.FromMemberInfo(_info) ), typeof(object) ).Expression ); } else if (instance != null) { builder.FinishCondition( AstUtils.Convert( binder.MakeCallExpression( new PythonOverloadResolverFactory(binder, codeContext), Getter[0], instance ).Expression, typeof(object) ) ); } else { builder.FinishCondition( AstUtils.Convert( binder.MakeCallExpression( new PythonOverloadResolverFactory(binder, codeContext), Getter[0] ).Expression, typeof(object) ) ); } }
public override DynamicMetaObject /*!*/ MakeInitCall(PythonBinder /*!*/ binder, DynamicMetaObject /*!*/ createExpr) { // default init, we can just return the value from __new__ return(createExpr); }
public override DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) { PythonOverloadResolver resolve; if (_creating.IsSystemType || _creating.HasSystemCtor) { resolve = new PythonOverloadResolver( binder, Arguments.Arguments, Arguments.Signature, CodeContext ); } else { resolve = new PythonOverloadResolver( binder, ArrayUtils.Insert(Arguments.Self, Arguments.Arguments), GetDynamicNewSignature(), CodeContext ); } return binder.CallMethod( resolve, _creating.UnderlyingSystemType.GetConstructors(), Arguments.Self.Restrictions, _creating.Name ); }
/// <summary> /// Gets the statically known member from the type with the specific name. Searches only the specified type to find the member. /// </summary> public static MemberGroup/*!*/ GetMember(PythonBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type, string/*!*/ name) { Assert.NotNull(binder, action, type, name); PerfTrack.NoteEvent(PerfTrack.Categories.ReflectedTypes, String.Format("LookupMember: {0} {1}", type.Name, name)); return GetMemberGroup(new LookupBinder(binder), action, type, name); }
public abstract DynamicMetaObject /*!*/ MakeInitCall(PythonBinder /*!*/ binder, DynamicMetaObject /*!*/ createExpr);
public ResolveBinder(PythonBinder/*!*/ binder) : base(binder) { }
// method call: public PythonOverloadResolver(PythonBinder binder, IList <DynamicMetaObject> args, CallSignature signature, Expression codeContext) : this(binder, args, signature, CallTypes.None, codeContext) { }
public PythonOverloadResolverFactory(PythonBinder /*!*/ binder, Expression /*!*/ codeContext) { Assert.NotNull(binder, codeContext); _binder = binder; _codeContext = codeContext; }
public virtual DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) { return MakeDefaultNew( binder, Ast.Call( typeof(PythonOps).GetMethod("PythonTypeGetMember"), CodeContext, AstUtils.Convert(Arguments.Self.Expression, typeof(PythonType)), AstUtils.Constant(null), AstUtils.Constant("__new__") ) ); }
public override DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) { return binder.CallMethod( new PythonOverloadResolver( binder, ArrayUtils.Insert(Arguments.Self, Arguments.Arguments), Arguments.Signature.InsertArgument(new Argument(ArgumentType.Simple)), CodeContext ), _ctor.Targets, _creating.Name ); }
/// <summary> /// Gets the statically known member from the type with the specific name. Searches the entire type hierarchy to find the specified member. /// </summary> public static MemberGroup/*!*/ GetMemberAll(PythonBinder/*!*/ binder, MemberRequestKind/*!*/ action, Type/*!*/ type, string/*!*/ name) { Assert.NotNull(binder, action, type, name); PerfTrack.NoteEvent(PerfTrack.Categories.ReflectedTypes, String.Format("ResolveMember: {0} {1}", type.Name, name)); return GetMemberGroup(new ResolveBinder(binder), action, type, name); }
/// <summary> /// Gets all the statically known members from the specified type. Searches the entire type hierarchy to get all possible members. /// /// The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing. /// </summary> public static IList<ResolvedMember/*!*/>/*!*/ GetMembersAll(PythonBinder/*!*/ binder, MemberRequestKind/*!*/ action, Type/*!*/ type) { Assert.NotNull(binder, action, type); return GetResolvedMembers(new ResolveBinder(binder), action, type); }
public override DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) { return MakeDefaultNew( binder, Ast.Call( typeof(PythonOps).GetMethod("GetMixedMember"), CodeContext, Arguments.Self.Expression, AstUtils.Constant(null), AstUtils.Constant("__new__") ) ); }
public override DynamicMetaObject/*!*/ GetExpression(PythonBinder/*!*/ binder) { PythonOverloadResolver resolver; if (_creating.IsSystemType || _creating.HasSystemCtor) { resolver = new PythonOverloadResolver(binder, DynamicMetaObject.EmptyMetaObjects, new CallSignature(0), CodeContext); } else { resolver = new PythonOverloadResolver(binder, new[] { Arguments.Self }, new CallSignature(1), CodeContext); } return binder.CallMethod(resolver, _creating.UnderlyingSystemType.GetConstructors(), BindingRestrictions.Empty, _creating.Name); }
public abstract DynamicMetaObject/*!*/ MakeInitCall(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr);
protected DynamicMetaObject/*!*/ MakeDefaultInit(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr, Expression/*!*/ init) { List<Expression> args = new List<Expression>(); args.Add(CodeContext); args.Add(Expression.Convert(createExpr.Expression, typeof(object))); foreach (DynamicMetaObject mo in Arguments.Arguments) { args.Add(mo.Expression); } return new DynamicMetaObject( DynamicExpression.Dynamic( ((PythonType)Arguments.Self.Value).GetLateBoundInitBinder(Arguments.Signature), typeof(object), args.ToArray() ), Arguments.Self.Restrictions.Merge(createExpr.Restrictions) ); }
public override DynamicMetaObject/*!*/ MakeInitCall(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr) { // default init, we can just return the value from __new__ return createExpr; }
public MemberBinder(PythonBinder/*!*/ binder) { Debug.Assert(binder != null); _binder = binder; }
public override DynamicMetaObject/*!*/ MakeInitCall(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr) { if (_method == InstanceOps.Init.Template) { // we have a default __init__, don't call it. return createExpr; } return binder.CallMethod( new PythonOverloadResolver( binder, createExpr, Arguments.Arguments, Arguments.Signature, CodeContext ), _method.Targets, Arguments.Self.Restrictions ); }
public LookupBinder(PythonBinder/*!*/ binder) : base(binder) { }
public override DynamicMetaObject/*!*/ MakeInitCall(PythonBinder/*!*/ binder, DynamicMetaObject/*!*/ createExpr) { Expression init = Ast.Call( typeof(PythonOps).GetMethod("GetMixedMember"), CodeContext, Ast.Convert(Arguments.Self.Expression, typeof(PythonType)), AstUtils.Convert(createExpr.Expression, typeof(object)), AstUtils.Constant("__init__") ); return MakeDefaultInit(binder, createExpr, init); }
/// <summary> /// Gets all the statically known members from the specified type. Searches only the specified type to find the members. /// /// The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing. /// </summary> public static IList<ResolvedMember/*!*/>/*!*/ GetMembers(PythonBinder/*!*/ binder, OldDynamicAction/*!*/ action, Type/*!*/ type) { Assert.NotNull(binder, action, type); return GetResolvedMembers(new LookupBinder(binder), action, type); }
internal override Expression/*!*/ MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, Expression instance, Expression/*!*/ owner, Expression/*!*/ error) { if (Getter.Length != 0 && !Getter[0].IsPublic) { // fallback to runtime call return base.MakeGetExpression(binder, codeContext, instance, owner, error); } else if (NeedToReturnProperty(instance, Getter)) { return AstUtils.Constant(this); } else if (Getter[0].ContainsGenericParameters) { return DefaultBinder.MakeError( binder.MakeContainsGenericParametersError( MemberTracker.FromMemberInfo(_info) ) ); } Expression res; if (instance != null) { res = binder.MakeCallExpression( codeContext, Getter[0], instance ); } else { res = binder.MakeCallExpression( codeContext, Getter[0] ); } Debug.Assert(res != null); return res; }