public IParameterInfo[] GetParameters()
        {
            if (_params == null)
            {
                RemoteInterpreterProxy ri      = _remote;
                bool isInstanceExtensionMethod = ri != null?ri.IsInstanceExtensionMethod(_overload, _declaringType.Value) : false;

                ObjectIdentityHandle[] parameters = ri != null?ri.GetParametersNoCodeContext(_overload) : new ObjectIdentityHandle[0];

                var res = new List <IParameterInfo>(parameters.Length + 1);
                res.Add(new IronPythonNewClsParameterInfo(_declaringType));
                foreach (ObjectIdentityHandle param in parameters)
                {
                    if (res.Count == 0 && isInstanceExtensionMethod)
                    {
                        // skip instance parameter
                        isInstanceExtensionMethod = false;
                        continue;
                    }
                    else
                    {
                        res.Add(new IronPythonParameterInfo(_interpreter, param));
                    }
                }

                _params = res.ToArray();
            }
            return(_params);
        }
Example #2
0
 public PythonObject(IronPythonInterpreter interpreter, ObjectIdentityHandle obj)
 {
     _interpreter = interpreter;
     _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
     _remote = _interpreter.Remote;
     _obj    = obj;
 }
Example #3
0
        private void CreateNonClrAttrs()
        {
            if (!_checkedClrAttrs)
            {
                RemoteInterpreterProxy ri = RemoteInterpreter;
                foreach (var name in ri != null ? ri.DirHelper(_obj, false) : Enumerable.Empty <string>())
                {
                    if (!_attrs.ContainsKey(name))
                    {
                        _attrs[name] = new MemberInfo(IsClrOnly.No);
                    }
                    else
                    {
                        _attrs[name] = new MemberInfo(_attrs[name].Member, IsClrOnly.No);
                    }
                }

                foreach (var attr in _attrs.ToArray())
                {
                    if (attr.Value.ClrOnly == IsClrOnly.NotChecked)
                    {
                        _attrs[attr.Key] = new MemberInfo(attr.Value.Member, IsClrOnly.Yes);
                    }
                }
                _checkedClrAttrs = true;
            }
        }
 public IronPythonConstructorFunction(IronPythonInterpreter interpreter, ObjectIdentityHandle[] infos, IPythonType type) {
     _interpreter = interpreter;
     _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
     _remote = _interpreter.Remote;
     _infos = infos;
     _type = type;
 }
        private static readonly string _noDefaultValue = "<No Default Value>";          // sentinel value to mark when an object doesn't have a default value

        public IronPythonParameterInfo(IronPythonInterpreter interpreter, ObjectIdentityHandle parameterInfo)
        {
            _interpreter = interpreter;
            _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
            _remote        = _interpreter.Remote;
            _parameterInfo = parameterInfo;
        }
Example #6
0
 public IronPythonConstructorFunction(IronPythonInterpreter interpreter, ObjectIdentityHandle[] infos, IPythonType type)
 {
     _interpreter = interpreter;
     _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
     _remote = _interpreter.Remote;
     _infos  = infos;
     _type   = type;
 }
 public IronPythonConstructorFunctionTarget(IronPythonInterpreter interpreter, ObjectIdentityHandle overload, IronPythonType declType) {
     Debug.Assert(interpreter.Remote.TypeIs<MethodBase>(overload));
     _interpreter = interpreter;
     _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
     _remote = _interpreter.Remote;
     _overload = overload;
     _declaringType = declType;
 }
Example #8
0
        private void AddWpfReferences()
        {
            RemoteInterpreterProxy ri = RemoteInterpreter;

            if (ri != null && ri.LoadWpf())
            {
                Interpreter.RaiseModuleNamesChanged();
            }
        }
 public IronPythonConstructorFunctionTarget(IronPythonInterpreter interpreter, ObjectIdentityHandle overload, IronPythonType declType)
 {
     Debug.Assert(interpreter.Remote.TypeIs <MethodBase>(overload));
     _interpreter = interpreter;
     _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
     _remote        = _interpreter.Remote;
     _overload      = overload;
     _declaringType = declType;
 }
Example #10
0
        /// <summary>
        /// Returns the overloads for a normal .NET type
        /// </summary>
        private IPythonFunction GetClrOverloads()
        {
            RemoteInterpreterProxy ri = RemoteInterpreter;

            ObjectIdentityHandle[] ctors = ri != null?ri.GetPythonTypeConstructors(Value) : null;

            if (ctors != null)
            {
                return(new IronPythonConstructorFunction(Interpreter, ctors, this));
            }
            return(null);
        }
Example #11
0
        public IPythonType MakeGenericType(IPythonType[] indexTypes)
        {
            // Should we hash on the types here?
            ObjectIdentityHandle[] types = new ObjectIdentityHandle[indexTypes.Length];
            for (int i = 0; i < types.Length; i++)
            {
                types[i] = ((IronPythonType)indexTypes[i]).Value;
            }
            RemoteInterpreterProxy ri = RemoteInterpreter;

            return(ri != null?Interpreter.GetTypeFromType(ri.PythonTypeMakeGenericType(Value, types)) : null);
        }
Example #12
0
        private AppDomain CreateDomain(out RemoteInterpreterProxy remoteInterpreter)
        {
            // We create a sacrificial domain for loading all of our assemblies into.

            var            ironPythonAssemblyPath = Path.GetDirectoryName(_factory.Configuration.GetWindowsInterpreterPath());
            AppDomainSetup setup = new AppDomainSetup
            {
                ShadowCopyFiles = "true",
                // We are in ...\Extensions\Microsoft\IronPython Interpreter\2.0
                // We need to be able to load assemblies from:
                //      Python Tools for Visual Studio\2.0
                //      IronPython Interpreter\2.0
                //
                // So setup the application base to be Extensions\Microsoft\, and then add the other 2 dirs to the private bin path.
                ApplicationBase = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))),
                PrivateBinPath  = Path.GetDirectoryName(typeof(IronPythonInterpreter).Assembly.Location) + ";" +
                                  Path.GetDirectoryName(typeof(IPythonFunction).Assembly.Location) + ";" +
                                  Path.Combine(ironPythonAssemblyPath, "DLLs") + ";" +
                                  ironPythonAssemblyPath,

                PrivateBinPathProbe = ""
            };

            if (Directory.Exists(_factory.Configuration.GetPrefixPath()))
            {
                setup.AppDomainInitializer          = IronPythonResolver.Initialize;
                setup.AppDomainInitializerArguments = new[] { _factory.Configuration.GetPrefixPath() };
            }

            var domain = AppDomain.CreateDomain("IronPythonAnalysisDomain", null, setup);

            using (new RemoteAssemblyResolver(domain, ironPythonAssemblyPath))
            {
                remoteInterpreter = (RemoteInterpreterProxy)domain.CreateInstanceAndUnwrap(
                    typeof(RemoteInterpreterProxy).Assembly.FullName,
                    typeof(RemoteInterpreterProxy).FullName);
            }

#if DEBUG
            var assertListener = Debug.Listeners["Microsoft.PythonTools.AssertListener"];
            if (assertListener != null)
            {
                var init = (AssertListenerInitializer)domain.CreateInstanceAndUnwrap(
                    typeof(AssertListenerInitializer).Assembly.FullName,
                    typeof(AssertListenerInitializer).FullName
                    );
                init.Initialize(assertListener);
            }
#endif

            return(domain);
        }
Example #13
0
        /// <summary>
        /// Returns the overloads for a normal .NET type
        /// </summary>
        private IPythonFunction GetClrOverloads()
        {
            ObjectIdentityHandle   declType = default(ObjectIdentityHandle);
            RemoteInterpreterProxy ri       = RemoteInterpreter;

            ObjectIdentityHandle[] ctors = ri != null?ri.GetTypeGroupConstructors(Value, out declType) : null;

            if (ctors != null)
            {
                return(new IronPythonConstructorFunction(Interpreter, ctors, Interpreter.GetTypeFromType(declType)));
            }
            return(null);
        }
Example #14
0
        private IPythonType[] GetEventInvokeArgs()
        {
            RemoteInterpreterProxy ri = RemoteInterpreter;

            ObjectIdentityHandle[] types = ri != null?ri.GetEventInvokeArgs(Value) : new ObjectIdentityHandle[0];

            IPythonType[] args = new IPythonType[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                args[i] = Interpreter.GetTypeFromType(types[i]);
            }
            return(args);
        }
Example #15
0
        public IList <IPythonType> GetTypesPropagatedOnCall()
        {
            if (_propagateOnCall == null)
            {
                RemoteInterpreterProxy ri = RemoteInterpreter;
                if (ri != null && ri.IsDelegateType(Value))
                {
                    _propagateOnCall = GetEventInvokeArgs();
                }
                else
                {
                    _propagateOnCall = EmptyTypes;
                }
            }

            return(_propagateOnCall == EmptyTypes ? null : _propagateOnCall);
        }
Example #16
0
        public IList <IPythonType> GetEventParameterTypes()
        {
            if (_parameterTypes == null)
            {
                RemoteInterpreterProxy ri    = RemoteInterpreter;
                ObjectIdentityHandle[] types = ri != null?ri.GetEventParameterPythonTypes(Value) : new ObjectIdentityHandle[0];

                IPythonType[] paramTypes = new IPythonType[types.Length];
                for (int i = 0; i < paramTypes.Length; i++)
                {
                    paramTypes[i] = Interpreter.GetTypeFromType(types[i]);
                }

                _parameterTypes = paramTypes;
            }
            return(_parameterTypes);
        }
Example #17
0
        public IPythonFunction GetConstructors()
        {
            if (_ctors == null)
            {
                RemoteInterpreterProxy ri = RemoteInterpreter;
                if (ri != null && !ri.TypeGroupHasNewOrInitMethods(Value))
                {
                    _ctors = GetClrOverloads();
                }

                if (_ctors == null)
                {
                    _ctors = GetMember(null, "__new__") as IPythonFunction;
                }
            }
            return(_ctors);
        }
Example #18
0
        public IMember GetMember(IModuleContext context, string name)
        {
            if (_attrs == null)
            {
                Interlocked.CompareExchange(ref _attrs, new Dictionary <string, MemberInfo>(), null);
            }
            bool showClr = context == null || ((IronPythonModuleContext)context).ShowClr;

            if (!_attrs.TryGetValue(name, out MemberInfo member) || member.Member == null)
            {
                RemoteInterpreterProxy ri  = RemoteInterpreter;
                ObjectIdentityHandle   res = ri != null?ri.GetMember(Value, name) : default(ObjectIdentityHandle);

                if (!res.Equals(Value))
                {
                    _attrs[name] = member = new MemberInfo(_interpreter.MakeObject(res));
                }
            }

            if (!showClr)
            {
                if (!(this is IronPythonNamespace))
                {                   // namespaces always show all of their members...
                    switch (member.ClrOnly)
                    {
                    case IsClrOnly.NotChecked:
                        CreateNonClrAttrs();
                        if (_attrs.ContainsKey(name) &&
                            _attrs[name].ClrOnly == IsClrOnly.Yes)
                        {
                            return(null);
                        }
                        break;

                    case IsClrOnly.No:
                        break;

                    case IsClrOnly.Yes:
                        return(null);
                    }
                }
            }

            return(member.Member);
        }
Example #19
0
        public IList <IPythonType> GetTypesPropagatedOnCall()
        {
            if (_eventInvokeArgs == null)
            {
                RemoteInterpreterProxy ri    = RemoteInterpreter;
                ObjectIdentityHandle[] types = ri != null?ri.GetTypeGroupEventInvokeArgs(Value) : null;

                if (types == null)
                {
                    _eventInvokeArgs = IronPythonType.EmptyTypes;
                }
                else
                {
                    IPythonType[] args = new IPythonType[types.Length];
                    for (int i = 0; i < types.Length; i++)
                    {
                        args[i] = Interpreter.GetTypeFromType(types[i]);
                    }
                    _eventInvokeArgs = args;
                }
            }

            return(_eventInvokeArgs == IronPythonType.EmptyTypes ? null : _eventInvokeArgs);
        }
Example #20
0
 private void Interpreter_UnloadingDomain(object sender, EventArgs e)
 {
     _remote = null;
     _interpreter.UnloadingDomain -= Interpreter_UnloadingDomain;
 }
Example #21
0
        public IPythonType GetElementType()
        {
            RemoteInterpreterProxy ri = RemoteInterpreter;

            return(ri != null?Interpreter.GetTypeFromType(ri.GetPythonTypeElementType(Value)) : null);
        }
Example #22
0
 private void Interpreter_UnloadingDomain(object sender, EventArgs e) {
     _remote = null;
     _interpreter.UnloadingDomain -= Interpreter_UnloadingDomain;
 }
Example #23
0
        private static readonly string _noDefaultValue = "<No Default Value>";  // sentinel value to mark when an object doesn't have a default value

        public IronPythonParameterInfo(IronPythonInterpreter interpreter, ObjectIdentityHandle parameterInfo) {
            _interpreter = interpreter;
            _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
            _remote = _interpreter.Remote;
            _parameterInfo = parameterInfo;
        }
Example #24
0
        public IEnumerable <string> GetMemberNames(IModuleContext moduleContext)
        {
            RemoteInterpreterProxy ri = RemoteInterpreter;

            return(ri != null?ri.DirHelper(Value, ((IronPythonModuleContext)moduleContext).ShowClr) : Enumerable.Empty <string>());
        }
Example #25
0
        private AppDomain CreateDomain(out RemoteInterpreterProxy remoteInterpreter) {
            // We create a sacrificial domain for loading all of our assemblies into.  

            AppDomainSetup setup = new AppDomainSetup();
            setup.ShadowCopyFiles = "true";
            // We are in ...\Extensions\Microsoft\IronPython Interpreter\2.0
            // We need to be able to load assemblies from:
            //      Python Tools for Visual Studio\2.0
            //      IronPython Interpreter\2.0
            //
            // So setup the application base to be Extensions\Microsoft\, and then add the other 2 dirs to the private bin path.
            setup.ApplicationBase = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
            setup.PrivateBinPath = Path.GetDirectoryName(typeof(IronPythonInterpreter).Assembly.Location) + ";" +
                                   Path.GetDirectoryName(typeof(IPythonFunction).Assembly.Location);

            setup.PrivateBinPathProbe = "";

            var domain = AppDomain.CreateDomain("IronPythonAnalysisDomain", null, setup);
            domain.AssemblyResolve += IronPythonResolver.domain_AssemblyResolve;

            remoteInterpreter = (RemoteInterpreterProxy)domain.CreateInstanceAndUnwrap(
                typeof(RemoteInterpreterProxy).Assembly.FullName,
                typeof(RemoteInterpreterProxy).FullName);

#if DEBUG
            var assertListener = Debug.Listeners["Microsoft.PythonTools.AssertListener"];
            if (assertListener != null) {
                domain.DoCallBack(new AssertListenerInitializer(assertListener).Initialize);
            }
#endif

            return domain;
        }
Example #26
0
 public PythonObject(IronPythonInterpreter interpreter, ObjectIdentityHandle obj) {
     _interpreter = interpreter;
     _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
     _remote = _interpreter.Remote;
     _obj = obj;
 }
Example #27
0
        public IEnumerable <string> GetChildrenModules()
        {
            RemoteInterpreterProxy ri = RemoteInterpreter;

            return(ri != null?ri.GetNamespaceChildren(Value) : Enumerable.Empty <string>());
        }