Exemplo n.º 1
0
            private void AddUnsortedNodes(ArrayBuilder <BuilderNode> unsortedNodes,
                                          MultiDictionary <string, ExtensionMethodInfo> simpleBuilder,
                                          ArrayBuilder <ExtensionMethodInfo> complexBuilder,
                                          MetadataNode parentNode,
                                          int parentIndex,
                                          string fullyQualifiedContainerName)
            {
                foreach (var child in _parentToChildren[parentNode])
                {
                    var childNode  = new BuilderNode(child.Name, parentIndex, _extensionMethodToParameterTypeInfo[child]);
                    var childIndex = unsortedNodes.Count;
                    unsortedNodes.Add(childNode);

                    if (fullyQualifiedContainerName != null)
                    {
                        foreach (var parameterTypeInfo in _extensionMethodToParameterTypeInfo[child])
                        {
                            if (parameterTypeInfo.IsComplexType)
                            {
                                complexBuilder.Add(new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name));
                            }
                            else
                            {
                                simpleBuilder.Add(parameterTypeInfo.Name, new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name));
                            }
                        }
                    }

                    AddUnsortedNodes(unsortedNodes, simpleBuilder, complexBuilder, child, childIndex, Concat(fullyQualifiedContainerName, child.Name));
                }
Exemplo n.º 2
0
            private void GenerateMetadataNodes(
                MetadataNode parentNode,
                string nodeName,
                OrderPreservingMultiDictionary <string, MetadataDefinition> .ValueSet definitionsWithSameName)
            {
                if (!UnicodeCharacterUtilities.IsValidIdentifier(nodeName))
                {
                    return;
                }

                var childNode = MetadataNode.Allocate(nodeName);

                _parentToChildren.Add(parentNode, childNode);

                // Add all child members
                var definitionMap = OrderPreservingMultiDictionary <string, MetadataDefinition> .GetInstance();

                try
                {
                    foreach (var definition in definitionsWithSameName)
                    {
                        LookupMetadataDefinitions(definition, definitionMap);
                    }

                    foreach (var kvp in definitionMap)
                    {
                        GenerateMetadataNodes(childNode, kvp.Key, kvp.Value);
                    }
                }
                finally
                {
                    definitionMap.Free();
                }
            }
Exemplo n.º 3
0
            public MetadataInfoCreator(
                Workspace workspace,
                SolutionKey solutionKey,
                Checksum checksum,
                PortableExecutableReference reference
                )
            {
                _workspace                = workspace;
                _solutionKey              = solutionKey;
                _checksum                 = checksum;
                _reference                = reference;
                _metadataReader           = null;
                _allTypeDefinitions       = new List <MetadataDefinition>();
                _containsExtensionsMethod = false;

                _inheritanceMap = OrderPreservingMultiDictionary <string, string> .GetInstance();

                _parentToChildren = OrderPreservingMultiDictionary <
                    MetadataNode,
                    MetadataNode
                    > .GetInstance();

                _extensionMethodToParameterTypeInfo =
                    new MultiDictionary <MetadataNode, ParameterTypeInfo>();
                _rootNode = MetadataNode.Allocate(name: "");
            }
Exemplo n.º 4
0
            private void AddUnsortedNodes(ArrayBuilder <BuilderNode> unsortedNodes,
                                          MultiDictionary <string, ExtensionMethodInfo> receiverTypeNameToMethodMap,
                                          MetadataNode parentNode,
                                          int parentIndex,
                                          string fullyQualifiedContainerName)
            {
                foreach (var child in _parentToChildren[parentNode])
                {
                    var childNode  = new BuilderNode(child.Name, parentIndex, _extensionMethodToParameterTypeInfo[child]);
                    var childIndex = unsortedNodes.Count;
                    unsortedNodes.Add(childNode);

                    if (fullyQualifiedContainerName != null)
                    {
                        foreach (var parameterTypeInfo in _extensionMethodToParameterTypeInfo[child])
                        {
                            // We do not differentiate array of different kinds for simplicity.
                            // e.g. int[], int[][], int[,], etc. are all represented as int[] in the index.
                            // similar for complex receiver types, "[]" means it's an array type, "" otherwise.
                            var parameterTypeName = (parameterTypeInfo.IsComplexType, parameterTypeInfo.IsArray) switch
                            {
                                (true, true) => Extensions.ComplexArrayReceiverTypeName,                          // complex array type, e.g. "T[,]"
                                (true, false) => Extensions.ComplexReceiverTypeName,                              // complex non-array type, e.g. "T"
                                (false, true) => parameterTypeInfo.Name + Extensions.ArrayReceiverTypeNameSuffix, // simple array type, e.g. "int[][,]"
                                (false, false) => parameterTypeInfo.Name                                          // simple non-array type, e.g. "int"
                            };

                            receiverTypeNameToMethodMap.Add(parameterTypeName, new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name));
                        }
                    }

                    AddUnsortedNodes(unsortedNodes, receiverTypeNameToMethodMap, child, childIndex, Concat(fullyQualifiedContainerName, child.Name));
                }
Exemplo n.º 5
0
            private void AddUnsortedNodes(
                ArrayBuilder <BuilderNode> unsortedNodes, MetadataNode parentNode, int parentIndex)
            {
                foreach (var child in _parentToChildren[parentNode])
                {
                    var childNode  = new BuilderNode(child.Name, parentIndex);
                    var childIndex = unsortedNodes.Count;
                    unsortedNodes.Add(childNode);

                    AddUnsortedNodes(unsortedNodes, child, childIndex);
                }
            }
Exemplo n.º 6
0
            private void GenerateMetadataNodes(
                MetadataNode parentNode,
                string nodeName,
                OrderPreservingMultiDictionary <
                    string,
                    MetadataDefinition
                    > .ValueSet definitionsWithSameName
                )
            {
                if (!UnicodeCharacterUtilities.IsValidIdentifier(nodeName))
                {
                    return;
                }

                var childNode = MetadataNode.Allocate(nodeName);

                _parentToChildren.Add(parentNode, childNode);

                // Add all child members
                var definitionMap = OrderPreservingMultiDictionary <
                    string,
                    MetadataDefinition
                    > .GetInstance();

                try
                {
                    foreach (var definition in definitionsWithSameName)
                    {
                        if (definition.Kind == MetadataDefinitionKind.Member)
                        {
                            // We need to support having multiple methods with same name but different receiver type.
                            _extensionMethodToParameterTypeInfo.Add(
                                childNode,
                                definition.ReceiverTypeInfo
                                );
                        }

                        LookupMetadataDefinitions(definition, definitionMap);
                    }

                    foreach (var(name, definitions) in definitionMap)
                    {
                        GenerateMetadataNodes(childNode, name, definitions);
                    }
                }
                finally
                {
                    definitionMap.Free();
                }
            }
Exemplo n.º 7
0
            public MetadataInfoCreator(
                Solution solution, Checksum checksum, PortableExecutableReference reference, CancellationToken cancellationToken)
            {
                _solution           = solution;
                _checksum           = checksum;
                _reference          = reference;
                _cancellationToken  = cancellationToken;
                _metadataReader     = null;
                _allTypeDefinitions = new List <MetadataDefinition>();

                _inheritanceMap = OrderPreservingMultiDictionary <string, string> .GetInstance();

                _parentToChildren = OrderPreservingMultiDictionary <MetadataNode, MetadataNode> .GetInstance();

                _rootNode = MetadataNode.Allocate(name: "");
            }
Exemplo n.º 8
0
            public void Dispose()
            {
                // Return all the metadata nodes back to the pool so that they can be
                // used for the next PEReference we read.
                foreach (var(_, children) in _parentToChildren)
                {
                    foreach (var child in children)
                    {
                        MetadataNode.Free(child);
                    }
                }

                MetadataNode.Free(_rootNode);

                _parentToChildren.Free();
                _inheritanceMap.Free();
            }
Exemplo n.º 9
0
            private MetadataNode GetOrCreateChildNode(
                MetadataNode currentNode, string simpleName)
            {
                foreach (var childNode in _parentToChildren[currentNode])
                {
                    if (childNode.Name == simpleName)
                    {
                        // Found an existing child node.  Just return that and all
                        // future parts off of it.
                        return(childNode);
                    }
                }

                // Couldn't find a child node with this name.  Make a new node for
                // it and return that for all future parts to be added to.
                var newChildNode = MetadataNode.Allocate(simpleName);

                _parentToChildren.Add(currentNode, newChildNode);
                return(newChildNode);
            }
Exemplo n.º 10
0
 private MetadataNode GetOrCreateChildNode(
     MetadataNode currentNode, string simpleName)
 {
     if (_parentToChildren.TryGetValue(currentNode, static (childNode, simpleName) => childNode.Name == simpleName, simpleName, out var childNode))
Exemplo n.º 11
0
 public static void Free(MetadataNode node)
 {
     Debug.Assert(node.Name != null);
     node.Name = null;
     s_pool.Free(node);
 }
Exemplo n.º 12
0
 private MetadataNode GetOrCreateChildNode(MetadataNode currentNode, string simpleName)
 {
     if (
         _parentToChildren.TryGetValue(
             currentNode,