Example #1
0
        /// <summary>
        /// Merges given node into this node. Removes the child nodes from the other node.
        /// </summary>
        public void Merge(NamespaceTreeNode other)
        {
            ContractUtils.Requires(other != null);

            if (other._typeDefs != null)
            {
                _typeDefs.AddRange(other._typeDefs);
                other._typeDefs = null;
            }

            if (other._firstChild != null)
            {
                ContractUtils.Assert(other._lastChild != null);
                if (_firstChild == null)
                {
                    // this namespace has no subnamespaces:
                    _firstChild = other._firstChild;
                    _lastChild  = other._lastChild;
                }
                else
                {
                    // concat the lists:
                    _lastChild._nextSibling = other._firstChild;
                    _lastChild = other._lastChild;
                }
                other._firstChild = other._lastChild = null;
            }
        }
Example #2
0
        public void Add(Module module)
        {
            ContractUtils.Requires(module != null);

            Type[] types;
            try {
                types = module.GetTypes();
            } catch (Exception) {
                Console.WriteLine(module.Assembly.Location);
                return;
            }

            foreach (Type type in types)
            {
                if (type.Attributes.IsNested())
                {
                    continue;
                }

                string             prefix = type.Namespace ?? "";
                RNamespaceTreeNode ns     = null;

                while (true)
                {
                    RNamespaceTreeNode existing;
                    if (_names.TryGetValue(prefix, out existing))
                    {
                        if (ns == null)
                        {
                            existing.AddType(type);
                        }
                        else
                        {
                            existing.AddNamespace(ns);
                        }
                        break;
                    }

                    ContractUtils.Assert(prefix.Length > 0);
                    int lastDot = prefix.LastIndexOf('.', prefix.Length - 1, prefix.Length);

                    string             name  = (lastDot >= 0) ? prefix.Substring(lastDot + 1) : prefix;
                    RNamespaceTreeNode newNs = new RNamespaceTreeNode(name);
                    if (ns == null)
                    {
                        newNs.AddType(type);
                    }
                    else
                    {
                        newNs.AddNamespace(ns);
                    }
                    ns = newNs;

                    _names.Add(prefix, ns);

                    prefix = (lastDot >= 0) ? prefix.Substring(0, lastDot) : "";
                }
            }
        }
        public void Add(MetadataTables tables)
        {
            ContractUtils.Requires(tables != null);

            foreach (TypeDef typeDef in tables.TypeDefs)
            {
                if (typeDef.IsGlobal || typeDef.Attributes.IsNested())
                {
                    continue;
                }

                MetadataNamePart  prefix = typeDef.Namespace.GetExtent();
                NamespaceTreeNode ns     = null;

                while (true)
                {
                    NamespaceTreeNode existing;
                    if (_names.TryGetValue(prefix, out existing))
                    {
                        if (ns == null)
                        {
                            existing.AddType(typeDef);
                        }
                        else
                        {
                            existing.AddNamespace(ns);
                        }
                        break;
                    }


                    ContractUtils.Assert(prefix.Length > 0);
                    int lastDot = prefix.LastIndexOf((byte)'.', prefix.Length - 1, prefix.Length);

                    MetadataNamePart  name  = (lastDot >= 0) ? prefix.GetPart(lastDot + 1) : prefix;
                    NamespaceTreeNode newNs = new NamespaceTreeNode(name);
                    if (ns == null)
                    {
                        newNs.AddType(typeDef);
                    }
                    else
                    {
                        newNs.AddNamespace(ns);
                    }
                    ns = newNs;

                    _names.Add(prefix, ns);

                    prefix = (lastDot >= 0) ? prefix.GetPart(0, lastDot) : MetadataNamePart.Empty;
                }
            }
        }
Example #4
0
            internal T this[int index] {
                get {
                    ContractUtils.Assert(index < _count);
                    switch (index)
                    {
                    case 0: return(_item1);

                    case 1: return(_item2);

                    case 2: return(_item3);

                    case 3: return(_item4);

                    case 4: return(_item5);

                    case 5: return(_item6);

                    case 6: return(_item7);

                    case 7: return(_item8);

                    default: return(default(T));
                    }
                }
                set {
                    ContractUtils.Assert(index < _count);
                    switch (index)
                    {
                    case 0: _item1 = value; return;

                    case 1: _item2 = value; return;

                    case 2: _item3 = value; return;

                    case 3: _item4 = value; return;

                    case 4: _item5 = value; return;

                    case 5: _item6 = value; return;

                    case 6: _item7 = value; return;

                    case 7: _item8 = value; return;
                    }
                }
            }
Example #5
0
        internal void AddNamespace(NamespaceTreeNode ns)
        {
            ContractUtils.Assert(ns != null && ns._nextSibling == null);
            ContractUtils.Assert((_firstChild == null) == (_lastChild == null));

            if (_firstChild == null)
            {
                // our first child:
                _firstChild = _lastChild = ns;
            }
            else
            {
                // add to the end of the children linked list:
                _lastChild._nextSibling = ns;
                _lastChild = ns;
            }
        }
Example #6
0
            public bool MoveNext()
            {
                if (_currentChunk == null)
                {
                    ContractUtils.Assert(_index == 0);
                    _currentChunk = _initialChunk;
                }

                if (_index == _currentChunk._count)
                {
                    if (_currentChunk._next == null)
                    {
                        return(false);
                    }
                    _currentChunk = _currentChunk._next;
                    _index        = 0;
                }
                else
                {
                    _index++;
                }
                return(true);
            }