Ejemplo n.º 1
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isCref = reader.ReadBoolean();

                if (isCref)
                {
                    var location   = reader.ReadLocation();
                    var resolution = reader.ResolveLocation(location);
                    return(resolution.GetValueOrDefault());
                }
                else
                {
                    var metadataName = reader.ReadString();
                    var containingSymbolResolution = reader.ReadSymbolKey();

                    using var result = PooledArrayBuilder <ITypeParameterSymbol> .GetInstance();

                    foreach (var containingSymbol in containingSymbolResolution)
                    {
                        foreach (var typeParam in containingSymbol.GetTypeParameters())
                        {
                            if (typeParam.MetadataName == metadataName)
                            {
                                result.AddIfNotNull(typeParam);
                            }
                        }
                    }

                    return(CreateResolution(result));
                }
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isAnonymousDelegateType = reader.ReadBoolean();
                var location = reader.ReadLocation();

                var syntaxTree = location.SourceTree;

                if (syntaxTree == null)
                {
                    return(default(SymbolKeyResolution));
                }

                var semanticModel = reader.Compilation.GetSemanticModel(syntaxTree);
                var root          = syntaxTree.GetRoot(reader.CancellationToken);
                var node          = root.FindNode(location.SourceSpan, getInnermostNodeForTie: true);

                var symbol = semanticModel.GetSymbolInfo(node, reader.CancellationToken)
                             .GetAnySymbol();

                // If this was a key for an anonymous delegate type, then go find the
                // associated delegate for this lambda and return that instead of the
                // lambda function symbol itself.
                if (isAnonymousDelegateType)
                {
                    var anonymousDelegate = (symbol as IMethodSymbol).AssociatedAnonymousDelegate;
                    symbol = anonymousDelegate;
                }

                return(new SymbolKeyResolution(symbol));
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var isIndexer = reader.ReadBoolean();
                var refKinds  = reader.ReadRefKindArray();
                var originalParameterTypes = reader.ReadSymbolKeyArray().Select(
                    r => GetFirstSymbol <ITypeSymbol>(r)).ToArray();

                if (originalParameterTypes.Any(s_typeIsNull))
                {
                    return(default(SymbolKeyResolution));
                }

                var properties = containingSymbolResolution.GetAllSymbols().OfType <INamedTypeSymbol>()
                                 .SelectMany(t => t.GetMembers())
                                 .OfType <IPropertySymbol>()
                                 .Where(p => p.Parameters.Length == refKinds.Length &&
                                        p.MetadataName == metadataName &&
                                        p.IsIndexer == isIndexer);
                var matchingProperties = properties.Where(p =>
                                                          ParameterRefKindsMatch(p.OriginalDefinition.Parameters, refKinds) &&
                                                          reader.ParameterTypesMatch(p.OriginalDefinition.Parameters, originalParameterTypes));

                return(CreateSymbolInfo(matchingProperties));
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var isAnonymousDelegateType = reader.ReadBoolean();
                var location = reader.ReadLocation(out var locationFailureReason) !;

                if (locationFailureReason != null)
                {
                    failureReason = $"({nameof(AnonymousFunctionOrDelegateSymbolKey)} {nameof(location)} failed -> {locationFailureReason})";
                    return(default);
Ejemplo n.º 5
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var metadataName = reader.ReadString() !;
                var isCompilationGlobalNamespace = reader.ReadBoolean();
                var containingSymbolResolution   = reader.ReadSymbolKey(out var containingSymbolFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(EventSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
                    return(default);
Ejemplo n.º 6
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isAnonymousDelegateType = reader.ReadBoolean();
                var location = reader.ReadLocation();

                var syntaxTree = location.SourceTree;

                if (syntaxTree == null)
                {
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var isCref = reader.ReadBoolean();

                if (isCref)
                {
                    var location = reader.ReadLocation(out var locationFailureReason) !;
                    if (locationFailureReason != null)
                    {
                        failureReason = $"({nameof(TypeParameterSymbolKey)} {nameof(location)} failed -> {locationFailureReason})";
                        return(default);
Ejemplo n.º 8
0
            public static SymbolKeyResolution Resolve(
                SymbolKeyReader reader,
                out string?failureReason
                )
            {
                var isError = reader.ReadBoolean();

                return(isError
                  ? ResolveErrorTuple(reader, out failureReason)
                  : ResolveNormalTuple(reader, out failureReason));
            }
Ejemplo n.º 9
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var isIndexer = reader.ReadBoolean();
                var refKinds  = reader.ReadRefKindArray();
                var originalParameterTypes = reader.ReadSymbolKeyArray().Select(
                    r => GetFirstSymbol <ITypeSymbol>(r)).ToArray();

                if (originalParameterTypes.Any(s_typeIsNull))
                {
                    return(default);
Ejemplo n.º 10
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName             = reader.ReadString();
                var containingTypeResolution = reader.ReadSymbolKey();
                var isIndexer = reader.ReadBoolean();

                using var refKinds       = reader.ReadRefKindArray();
                using var parameterTypes = reader.ReadSymbolKeyArray <ITypeSymbol>();

                if (parameterTypes.IsDefault)
                {
                    return(default);
Ejemplo n.º 11
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity = reader.ReadInteger();
                var isUnboundGenericType = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>();

                if (typeArguments.IsDefault)
                {
                    return(default);
Ejemplo n.º 12
0
            protected sealed override SymbolKeyResolution Resolve(
                SymbolKeyReader reader, ITypeParameterSymbol?contextualSymbol, out string?failureReason)
            {
                var isCref = reader.ReadBoolean();

                if (isCref)
                {
                    var location = reader.ReadLocation(out var locationFailureReason) !;
                    if (locationFailureReason != null)
                    {
                        failureReason = $"({nameof(TypeParameterSymbolKey)} {nameof(location)} failed -> {locationFailureReason})";
                        return(default);
Ejemplo n.º 13
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity = reader.ReadInteger();
                var isPartialMethodImplementationPart = reader.ReadBoolean();
                var parameterRefKinds = reader.ReadRefKindArray();

                // For each method that we look at, we'll have to resolve the parameter list and
                // return type in the context of that method.  i.e. if we have Foo<T>(IList<T> list)
                // then we'll need to have marked that we're on the Foo<T> method so that we know
                // 'T' in IList<T> resolves to.
                //
                // Because of this, we keep track of where we are in the reader.  Before resolving
                // every parameter list, we'll mark which method we're on and we'll rewind to this
                // point.
                var beforeParametersPosition = reader.Position;

                var result = new List <IMethodSymbol>();

                var namedTypes = containingSymbolResolution.GetAllSymbols().OfType <INamedTypeSymbol>();

                foreach (var namedType in namedTypes)
                {
                    var method = Resolve(reader, metadataName, arity, isPartialMethodImplementationPart,
                                         parameterRefKinds, beforeParametersPosition, namedType);

                    // Note: after finding the first method that matches we stop.  That's necessary
                    // as we cache results while searching.  We don't want to override these positive
                    // matches with a negative ones if we were to continue searching.
                    if (method != null)
                    {
                        result.Add(method);
                        break;
                    }
                }

                if (reader.Position == beforeParametersPosition)
                {
                    // We didn't find any candidates.  We still need to stream through this
                    // method signature so the reader is in a proper position.

                    // Push an null-method to our stack so that any method-type-parameters
                    // can at least be read (if not resolved) properly.
                    reader.PushMethod(methodOpt: null);
                    var parameterTypeResolutions = reader.ReadSymbolKeyArray();
                    var returnType = GetFirstSymbol <ITypeSymbol>(reader.ReadSymbolKey());
                    reader.PopMethod(methodOpt: null);
                }

                return(CreateSymbolInfo(result));
            }
Ejemplo n.º 14
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var name = reader.ReadString() !;
                var containingSymbolResolution = ResolveContainer(reader, out var containingSymbolFailureReason);
                var arity         = reader.ReadInteger();
                var isConstructed = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>(out var typeArgumentsFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(ErrorTypeSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string?failureReason)
            {
                var metadataName = reader.ReadString() !;
                var containingSymbolResolution = reader.ReadSymbolKey(out var containingSymbolFailureReason);
                var arity = reader.ReadInteger();
                var isUnboundGenericType = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>(out var typeArgumentsFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(NamedTypeSymbolKey)} {nameof(containingSymbolFailureReason)} failed -> {containingSymbolFailureReason})";
                    return(default);
Ejemplo n.º 16
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var arity                = reader.ReadInteger();
                var typeKind             = (TypeKind)reader.ReadInteger();
                var isUnboundGenericType = reader.ReadBoolean();
                var typeArgumentsOpt     = reader.ReadSymbolKeyArray();

                var types = GetAllSymbols <INamespaceOrTypeSymbol>(containingSymbolResolution).SelectMany(
                    s => Resolve(reader, s, metadataName, arity, typeKind, isUnboundGenericType, typeArgumentsOpt));

                return(CreateSymbolInfo(types));
            }
Ejemplo n.º 17
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isError = reader.ReadBoolean();

                if (isError)
                {
                    using var elementTypes = reader.ReadSymbolKeyArray <ITypeSymbol>();
                    using var elementNames = reader.ReadStringArray();
                    var elementLocations = ReadElementLocations(reader);

                    if (!elementTypes.IsDefault)
                    {
                        try
                        {
                            var result = reader.Compilation.CreateTupleTypeSymbol(
                                elementTypes.ToImmutable(), elementNames.ToImmutable(), elementLocations);
                            return(new SymbolKeyResolution(result));
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                }
                else
                {
                    var underlyingTypeResolution = reader.ReadSymbolKey();
                    using var elementNamesBuilder = reader.ReadStringArray();
                    var elementLocations = ReadElementLocations(reader);

                    try
                    {
                        using var result = PooledArrayBuilder <INamedTypeSymbol> .GetInstance();

                        var elementNames = elementNamesBuilder.ToImmutable();
                        foreach (var namedType in underlyingTypeResolution.OfType <INamedTypeSymbol>())
                        {
                            result.AddIfNotNull(reader.Compilation.CreateTupleTypeSymbol(
                                                    namedType, elementNames, elementLocations));
                        }

                        return(CreateResolution(result));
                    }
                    catch (ArgumentException)
                    {
                    }
                }

                return(new SymbolKeyResolution(reader.Compilation.ObjectType));
            }
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var isCompilationGlobalNamespace = reader.ReadBoolean();
                var containingSymbolResolution   = reader.ReadSymbolKey();

                if (isCompilationGlobalNamespace)
                {
                    return(new SymbolKeyResolution(reader.Compilation.GlobalNamespace));
                }

                var namespaces = GetAllSymbols(containingSymbolResolution).SelectMany(
                    s => Resolve(s, metadataName));

                return(CreateSymbolInfo(namespaces));
            }
Ejemplo n.º 19
0
            protected sealed override SymbolKeyResolution Resolve(
                SymbolKeyReader reader, INamedTypeSymbol?contextualType, out string?failureReason)
            {
                var name = reader.ReadRequiredString();
                var containingSymbolResolution = ResolveContainer(reader, contextualType, out var containingSymbolFailureReason);
                var arity         = reader.ReadInteger();
                var isConstructed = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <INamedTypeSymbol, ITypeSymbol>(
                          contextualType,
                          getContextualSymbol: static (contextualType, i) => SafeGet(contextualType.TypeArguments, i),
                          out var typeArgumentsFailureReason);

                if (containingSymbolFailureReason != null)
                {
                    failureReason = $"({nameof(ErrorTypeSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})";
                    return(default);
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isError = reader.ReadBoolean();

                if (isError)
                {
                    var elementTypes     = reader.ReadSymbolKeyArray().SelectAsArray(r => r.GetAnySymbol() as ITypeSymbol);
                    var elementNames     = reader.ReadStringArray();
                    var elementLocations = ReadElementLocations(reader);

                    if (!elementTypes.Any(t => t == null))
                    {
                        try
                        {
                            var result = reader.Compilation.CreateTupleTypeSymbol(
                                elementTypes, elementNames, elementLocations);
                            return(new SymbolKeyResolution(result));
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                }
                else
                {
                    var underlyingTypeResolution = reader.ReadSymbolKey();
                    var elementNames             = reader.ReadStringArray();
                    var elementLocations         = ReadElementLocations(reader);

                    try
                    {
                        var result = GetAllSymbols <INamedTypeSymbol>(underlyingTypeResolution).Select(
                            t => reader.Compilation.CreateTupleTypeSymbol(t, elementNames, elementLocations));
                        return(CreateSymbolInfo(result));
                    }
                    catch (ArgumentException)
                    {
                    }
                }

                return(new SymbolKeyResolution(reader.Compilation.ObjectType));
            }
Ejemplo n.º 21
0
            protected sealed override SymbolKeyResolution Resolve(
                SymbolKeyReader reader, INamedTypeSymbol?contextualSymbol, out string?failureReason)
            {
                var containingSymbolResolution = reader.ReadSymbolKey(contextualSymbol?.ContainingSymbol, out var containingSymbolFailureReason);
                var name                 = reader.ReadRequiredString();
                var arity                = reader.ReadInteger();
                var filePath             = reader.ReadString();
                var isUnboundGenericType = reader.ReadBoolean();

                using var typeArguments = reader.ReadSymbolKeyArray <INamedTypeSymbol, ITypeSymbol>(
                          contextualSymbol,
                          getContextualSymbol: static (contextualType, i) => SafeGet(contextualType.TypeArguments, i),
                          out var typeArgumentsFailureReason);

                if (typeArgumentsFailureReason != null)
                {
                    Contract.ThrowIfFalse(typeArguments.IsDefault);

                    failureReason = $"({nameof(NamedTypeSymbolKey)} {nameof(typeArguments)} failed -> {typeArgumentsFailureReason})";
                    return(default);
Ejemplo n.º 22
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var metadataName = reader.ReadString();
                var isCompilationGlobalNamespace = reader.ReadBoolean();
                var containingSymbolResolution   = reader.ReadSymbolKey();

                if (isCompilationGlobalNamespace)
                {
                    return(new SymbolKeyResolution(reader.Compilation.GlobalNamespace));
                }

                using var result = PooledArrayBuilder <INamespaceSymbol> .GetInstance();

                foreach (var container in containingSymbolResolution)
                {
                    switch (container)
                    {
                    case IAssemblySymbol assembly:
                        Debug.Assert(metadataName == string.Empty);
                        result.AddIfNotNull(assembly.GlobalNamespace);
                        break;

                    case IModuleSymbol module:
                        Debug.Assert(metadataName == string.Empty);
                        result.AddIfNotNull(module.GlobalNamespace);
                        break;

                    case INamespaceSymbol namespaceSymbol:
                        foreach (var member in namespaceSymbol.GetMembers(metadataName))
                        {
                            if (member is INamespaceSymbol childNamespace)
                            {
                                result.AddIfNotNull(childNamespace);
                            }
                        }
                        break;
                    }
                }

                return(CreateResolution(result));
            }