예제 #1
0
        public static object Get__file__(NamespaceTracker self) {
            if (self.PackageAssemblies.Count == 1) {
                return self.PackageAssemblies[0].FullName;
            }

            List res = new List();
            for (int i = 0; i < self.PackageAssemblies.Count; i++) {
                res.append(self.PackageAssemblies[i].FullName);
            }
            return res;                        
        }
예제 #2
0
 public static PythonDictionary Get__dict__(CodeContext context, NamespaceTracker self) {
     PythonDictionary res = new PythonDictionary();
     foreach (var kvp in self) {
         if (kvp.Value is TypeGroup || kvp.Value is NamespaceTracker) {
             res[kvp.Key] = kvp.Value;
         } else {
             res[kvp.Key] = DynamicHelpers.GetPythonTypeFromType(((TypeTracker)kvp.Value).Type);
         }
     }
     return res;
 }
예제 #3
0
        private NamespaceTracker MakeChildPackage(string childName, Assembly assem)
        {
            // lock is held when this is called
            Assert.NotNull(childName, assem);
            NamespaceTracker rp = new NamespaceTracker(GetFullChildName(childName));

            rp.SetTopPackage(_topPackage);
            rp._packageAssemblies.Add(assem);

            _dict[childName] = rp;
            return(rp);
        }
예제 #4
0
        protected void UpdateId()
        {
            _id = Interlocked.Increment(ref _masterId);
            foreach (KeyValuePair <string, MemberTracker> kvp in _dict)
            {
                NamespaceTracker ns = kvp.Value as NamespaceTracker;
                if (ns == null)
                {
                    continue;
                }

                ns.UpdateId();
            }
        }
예제 #5
0
        protected void UpdateSubtreeIds()
        {
            // lock is held when this is called
            UpdateId();

            foreach (KeyValuePair <string, MemberTracker> kvp in _dict)
            {
                NamespaceTracker ns = kvp.Value as NamespaceTracker;
                if (ns != null)
                {
                    ns.UpdateSubtreeIds();
                }
            }
        }
예제 #6
0
        public static object Get__file__(NamespaceTracker self) {
            if (self.PackageAssemblies.Count == 1) {
                return self.PackageAssemblies[0].FullName;
            }

            StringBuilder res = new StringBuilder();
            for (int i = 0; i < self.PackageAssemblies.Count; i++) {
                if (i != 0) {
                    res.Append(", ");
                }
                res.Append(self.PackageAssemblies[i].FullName);
            }
            return res.ToString();
        }
예제 #7
0
        public static object GetCustomMember(CodeContext/*!*/ context, NamespaceTracker/*!*/ self, string name) {
            MemberTracker mt;
            if (self.TryGetValue(name, out mt)) {
                if (mt.MemberType == TrackerTypes.Namespace || mt.MemberType == TrackerTypes.TypeGroup) {
                    return mt;
                }

                PythonTypeSlot pts = PythonTypeOps.GetSlot(new MemberGroup(mt), name, PythonContext.GetContext(context).Binder.PrivateBinding);
                object value;
                if (pts != null && pts.TryGetValue(context, null, TypeCache.PythonType, out value)) {
                    return value;
                }
            }

            return OperationFailed.Value;
        }
예제 #8
0
        /// <summary>
        /// Populates the tree with nodes for each part of the namespace
        /// </summary>
        /// <param name="assem"></param>
        /// <param name="fullNamespace">Full namespace name. It can be null (for top-level types)</param>
        /// <returns></returns>
        private NamespaceTracker GetOrMakePackageHierarchy(Assembly assem, string fullNamespace)
        {
            if (fullNamespace == null)
            {
                // null is the top-level namespace
                return(this);
            }

            NamespaceTracker ret = this;

            string[] pieces = fullNamespace.Split(Type.Delimiter);
            for (int i = 0; i < pieces.Length; i++)
            {
                ret = ret.GetOrMakeChildPackage(pieces[i], assem);
            }

            return(ret);
        }
예제 #9
0
        protected void UpdateId()
        {
            _id = Interlocked.Increment(ref _masterId);
            foreach (KeyValuePair <string, MemberTracker> kvp in _dict)
            {
                NamespaceTracker ns = kvp.Value as NamespaceTracker;
                if (ns == null)
                {
                    continue;
                }

                lock (ns) {
                    // namespace trackers are trees so we always take this
                    // in order
                    ns.UpdateId();
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Populates the tree with nodes for each part of the namespace
        /// </summary>
        /// <param name="assem"></param>
        /// <param name="fullNamespace">Full namespace name. It can be null (for top-level types)</param>
        /// <returns></returns>
        private NamespaceTracker GetOrMakePackageHierarchy(Assembly assem, string fullNamespace)
        {
            // lock is held when this is called
            Assert.NotNull(assem);

            if (fullNamespace == null)
            {
                // null is the top-level namespace
                return(this);
            }

            NamespaceTracker ret = this;

            string[] pieces = fullNamespace.Split('.');
            for (int i = 0; i < pieces.Length; i++)
            {
                ret = ret.GetOrMakeChildPackage(pieces[i], assem);
            }

            return(ret);
        }
예제 #11
0
 public static string __repr__(NamespaceTracker self) {
     return __str__(self);
 }
예제 #12
0
        internal RubyModule(RubyContext/*!*/ context, string name, Action<RubyModule> methodsInitializer, Action<RubyModule> constantsInitializer,
            RubyModule/*!*/[] expandedMixins, NamespaceTracker namespaceTracker, TypeTracker typeTracker, ModuleRestrictions restrictions) {

            Assert.NotNull(context);
            Debug.Assert(namespaceTracker == null || typeTracker == null || typeTracker.Type == typeof(object));
            Debug.Assert(expandedMixins == null ||
                CollectionUtils.TrueForAll(expandedMixins, (m) => m != this && m != null && !m.IsClass && m.Context == context)
            );

            _context = context;
            _name = name;
            _methodsInitializer = methodsInitializer;
            _constantsInitializer = constantsInitializer;
            _namespaceTracker = namespaceTracker;
            _typeTracker = typeTracker;
            _mixins = expandedMixins ?? EmptyArray;
            _restrictions = restrictions;
            _weakSelf = new WeakReference(this);

            Version = new VersionHandle(Interlocked.Increment(ref _globalMethodVersion));
            Version.SetName(name);
            Id = Interlocked.Increment(ref _globalModuleId);
        }
        /// <summary>
        /// Recursively lookup a member in a given namespace.
        /// </summary>
        /// <param name="name">A name for a type, possibly delimited by periods.</param>
        /// <param name="n">The namespace</param>
        /// <returns>The type as an object</returns>
        public object LookupMember(string name, NamespaceTracker n)
        {
            object varOutput;

            var periodIndex = name.IndexOf('.');
            if (periodIndex == -1)
            {
                if (n.TryGetValue(name, out varOutput))
                {
                    return varOutput;
                }
                return null;
            }

            var currentName = name.Substring(0,periodIndex);
            var theRest = name.Substring(periodIndex+1);

            if (n.TryGetValue(currentName, out varOutput))
            {
                if (varOutput is NamespaceTracker)
                {
                    return LookupMember(theRest, varOutput as NamespaceTracker);
                }
            }
            return null;

        }
        /// <summary>
        /// List all of the members in a CLR Namespace
        /// </summary>
        /// <param name="ns">A reference to the module</param>
        /// <param name="name">The name of the module</param>
        /// <returns>A list of completion data for the namespace</returns>
        public List<IronPythonCompletionData> EnumerateMembers(NamespaceTracker ns, string name)
        {
            var items = new List<IronPythonCompletionData>();

            foreach (var member in ns)
            {
                if (member.Value is NamespaceTracker)
                {
                    items.Add(new IronPythonCompletionData(member.Key, name, false, IronPythonCompletionData.CompletionType.NAMESPACE, this));
                }
                else if (member.Value is FieldTracker)
                {
                    items.Add(new IronPythonCompletionData(member.Key, name, false, IronPythonCompletionData.CompletionType.FIELD, this));
                }
                else if (member.Value is Microsoft.Scripting.Actions.PropertyTracker)
                {
                    items.Add(new IronPythonCompletionData(member.Key, name, false, IronPythonCompletionData.CompletionType.PROPERTY, this));
                }
                else if (member.Value is Microsoft.Scripting.Actions.TypeTracker)
                {
                    items.Add(new IronPythonCompletionData(member.Key, name, false, IronPythonCompletionData.CompletionType.CLASS, this));
                }
            }
            return items;
        }
예제 #15
0
 public static string Get__name__(CodeContext context, NamespaceTracker self) {
     return Get__name__(self.Name);
 }
예제 #16
0
 public static RubyModule/*!*/ ConvertNamespaceToModule(RubyScope/*!*/ scope, NamespaceTracker/*!*/ tracker) {
     return scope.RubyContext.GetOrCreateModule(tracker);
 }
예제 #17
0
 public static string __str__(NamespaceTracker self) {
     if (self.PackageAssemblies.Count != 1) {
         return String.Format("<module '{0}' (CLS module, {1} assemblies loaded)>", Get__name__(self.Name), self.PackageAssemblies.Count);
     }
     return String.Format("<module '{0}' (CLS module from {1})>", Get__name__(self.Name), self.PackageAssemblies[0].FullName);
 }
예제 #18
0
        public static string/*!*/ GetQualifiedName(NamespaceTracker/*!*/ namespaceTracker) {
            ContractUtils.RequiresNotNull(namespaceTracker, "namespaceTracker");
            if (namespaceTracker.Name == null) return String.Empty;

            return namespaceTracker.Name.Replace(Type.Delimiter.ToString(), "::");
        }
예제 #19
0
        private NamespaceTracker MakeChildPackage(string childName, Assembly assem) {
            // lock is held when this is called
            Assert.NotNull(childName, assem);
            NamespaceTracker rp = new NamespaceTracker(GetFullChildName(childName));
            rp.SetTopPackage(_topPackage);
            rp._packageAssemblies.Add(assem);

            _dict[childName] = rp;
            return rp;
        }
예제 #20
0
        internal RubyModule(RubyContext/*!*/ context, string name, Action<RubyModule> methodsInitializer, Action<RubyModule> constantsInitializer,
            RubyModule/*!*/[] expandedMixins, NamespaceTracker namespaceTracker, TypeTracker typeTracker, ModuleRestrictions restrictions) {

            Assert.NotNull(context);
            Debug.Assert(namespaceTracker == null || typeTracker == null);
            Debug.Assert(expandedMixins == null ||
                CollectionUtils.TrueForAll(expandedMixins, (m) => m != this && m != null && !m.IsClass && m.Context == context)
            );

            _context = context;
            _name = name;
            _methodsInitializer = methodsInitializer;
            _constantsInitializer = constantsInitializer;
            _namespaceTracker = namespaceTracker;
            _typeTracker = typeTracker;
            _mixins = expandedMixins ?? EmptyArray;
            _restrictions = restrictions;
        }