/// <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; } }
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()) { } }
public IEnumerable <NamespaceTreeNode> GetNamespaces() { NamespaceTreeNode current = _firstChild; while (current != null) { yield return(current); current = current._nextSibling; } }
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; } } }
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; }
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; } }
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); } }
internal ClrNamespaceInfo(NamespaceTreeNode namespaceNode) { _namespaceNode = namespaceNode; }
private static void DumpNamespaceTree(NamespaceTreeNode node) { DumpNamespaceTree(0, node); }
public NamespaceTree() { _names = new Dictionary <MetadataNamePart, NamespaceTreeNode>(); _names.Add(MetadataNamePart.Empty, Root = new NamespaceTreeNode(MetadataNamePart.Empty)); }
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; }
public NamespaceTree() { _names = new Dictionary<MetadataNamePart, NamespaceTreeNode>(); _names.Add(MetadataNamePart.Empty, _root = new NamespaceTreeNode(MetadataNamePart.Empty)); }