Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        internal void AddClrModules(NamespaceTreeNode treeNode)
        {
            foreach (var ns in treeNode.GetNamespaces())
            {
                if (_constants == null)
                {
                    // not initialized yet:

                    if (_clrModule == null)
                    {
                        // promote the Ruby module to a CLR namespace:
                    }
                    else
                    {
                        // TODO:
                        // if namespace => merge
                        // if type => ???
                    }
                }
                else
                {
                    // already initialized:
                    // TODO: MergeInitialized();
                }
            }

            foreach (var typeDef in treeNode.GetTypeDefs())
            {
            }
        }
Ejemplo n.º 3
0
        public IEnumerable <NamespaceTreeNode> GetNamespaces()
        {
            NamespaceTreeNode current = _firstChild;

            while (current != null)
            {
                yield return(current);

                current = current._nextSibling;
            }
        }
Ejemplo n.º 4
0
        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;
                }
            }
        }
Ejemplo n.º 5
0
        internal override void InitializeConstants(RubyContext context, Dictionary <string, object> constants)
        {
            foreach (TypeDef typeDef in _namespaceNode.GetTypeDefs())
            {
                constants[typeDef.Name.ToString()] = new RubyModule(context, new ClrTypeInfo(typeDef));
            }

            foreach (var ns in _namespaceNode.GetNamespaces())
            {
                constants[ns.Name.ToString()] = new RubyModule(context, new ClrNamespaceInfo(ns));
            }

            // TODO: resolve namespace/type conflicts (C# doesn't allow, but there could be some)

            _namespaceNode = null;
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
0
        private static void DumpNamespaceTree(int level, NamespaceTreeNode node)
        {
            string indent = new String(' ', level * 2);

            _output.WriteLine("{0}{1}: {2}/{3}",
                              indent,
                              node.Name,
                              node.GetTypeDefs().Count(),
                              (from def in node.GetTypeDefs() where (def.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public select def).Count()
                              );

            foreach (var typeDef in node.GetTypeDefs())
            {
                if ((typeDef.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public)
                {
                    _output.WriteLine("{0}  {1}", indent, typeDef.Name);
                }
            }

            foreach (var ns in node.GetNamespaces())
            {
                DumpNamespaceTree(level + 1, ns);
            }
        }
Ejemplo n.º 8
0
        internal void AddClrModules(NamespaceTreeNode treeNode)
        {
            foreach (var ns in treeNode.GetNamespaces()) {
                if (_constants == null) {
                    // not initialized yet:

                    if (_clrModule == null) {
                        // promote the Ruby module to a CLR namespace:

                    } else {
                        // TODO:
                        // if namespace => merge
                        // if type => ???
                    }
                } else {
                    // already initialized:
                    // TODO: MergeInitialized();
                }
            }

            foreach (var typeDef in treeNode.GetTypeDefs()) {

            }
        }
Ejemplo n.º 9
0
 internal ClrNamespaceInfo(NamespaceTreeNode namespaceNode)
 {
     _namespaceNode = namespaceNode;
 }
Ejemplo n.º 10
0
 private static void DumpNamespaceTree(NamespaceTreeNode node)
 {
     DumpNamespaceTree(0, node);
 }
Ejemplo n.º 11
0
        private static void DumpNamespaceTree(int level, NamespaceTreeNode node)
        {
            string indent = new String(' ', level * 2);
            _output.WriteLine("{0}{1}: {2}/{3}",
                indent,
                node.Name,
                node.GetTypeDefs().Count(),
                (from def in node.GetTypeDefs() where (def.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public select def).Count()
            );

            foreach (var typeDef in node.GetTypeDefs()) {
                if ((typeDef.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
                    _output.WriteLine("{0}  {1}", indent, typeDef.Name);
                }
            }

            foreach (var ns in node.GetNamespaces()) {
                DumpNamespaceTree(level + 1, ns);
            }
        }
Ejemplo n.º 12
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;
            }
        }
Ejemplo n.º 13
0
 public NamespaceTree()
 {
     _names = new Dictionary <MetadataNamePart, NamespaceTreeNode>();
     _names.Add(MetadataNamePart.Empty, Root = new NamespaceTreeNode(MetadataNamePart.Empty));
 }
Ejemplo n.º 14
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;
            }
        }
Ejemplo n.º 15
0
 internal ClrNamespaceInfo(NamespaceTreeNode namespaceNode)
 {
     _namespaceNode = namespaceNode;
 }
Ejemplo n.º 16
0
        internal override void InitializeConstants(RubyContext context, Dictionary<string, object> constants)
        {
            foreach (TypeDef typeDef in _namespaceNode.GetTypeDefs()) {
                constants[typeDef.Name.ToString()] = new RubyModule(context, new ClrTypeInfo(typeDef));
            }

            foreach (var ns in _namespaceNode.GetNamespaces()) {
                constants[ns.Name.ToString()] = new RubyModule(context, new ClrNamespaceInfo(ns));
            }

            // TODO: resolve namespace/type conflicts (C# doesn't allow, but there could be some)

            _namespaceNode = null;
        }
Ejemplo n.º 17
0
 private static void DumpNamespaceTree(NamespaceTreeNode node)
 {
     DumpNamespaceTree(0, node);
 }
Ejemplo n.º 18
0
        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;
                }
            }
        }
Ejemplo n.º 19
0
 public NamespaceTree()
 {
     _names = new Dictionary<MetadataNamePart, NamespaceTreeNode>();
     _names.Add(MetadataNamePart.Empty, _root = new NamespaceTreeNode(MetadataNamePart.Empty));
 }