protected sealed override SymbolKeyResolution Resolve( SymbolKeyReader reader, IMethodSymbol?contextualMethod, out string?failureReason) { var reducedFromResolution = reader.ReadSymbolKey(contextualMethod?.ReducedFrom, out var reducedFromFailureReason); var receiverTypeResolution = reader.ReadSymbolKey(contextualMethod?.ReceiverType, out var receiverTypeFailureReason); if (reducedFromFailureReason != null) { failureReason = $"({nameof(ReducedExtensionMethodSymbolKey)} {nameof(reducedFromResolution)} failed -> {reducedFromFailureReason})"; return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var reducedFromResolution = reader.ReadSymbolKey(); var receiverTypeResolution = reader.ReadSymbolKey(); var q = from m in reducedFromResolution.GetAllSymbols().OfType <IMethodSymbol>() from t in receiverTypeResolution.GetAllSymbols().OfType <ITypeSymbol>() let r = m.ReduceExtensionMethod(t) select r; return(CreateSymbolInfo(q)); }
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)); }
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 pointedAtTypeResolution = reader.ReadSymbolKey(); return(CreateSymbolInfo(GetAllSymbols <ITypeSymbol>(pointedAtTypeResolution) .Select(reader.Compilation.CreatePointerTypeSymbol))); }
private static IMethodSymbol Resolve( SymbolKeyReader reader, bool isPartialMethodImplementationPart, IMethodSymbol method) { var originalParameterTypeResolutions = reader.ReadSymbolKeyArray(); var returnType = GetFirstSymbol <ITypeSymbol>(reader.ReadSymbolKey()); var originalParameterTypes = originalParameterTypeResolutions.Select( r => GetFirstSymbol <ITypeSymbol>(r)).ToArray(); if (!originalParameterTypes.Any(s_typeIsNull)) { if (reader.ParameterTypesMatch(method.OriginalDefinition.Parameters, originalParameterTypes)) { if (returnType == null || reader.Comparer.Equals(returnType, method.ReturnType)) { if (isPartialMethodImplementationPart) { method = method.PartialImplementationPart ?? method; } Debug.Assert(method != null); return(method); } } } return(null); }
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) { var reducedFromResolution = reader.ReadSymbolKey(); var receiverTypeResolution = reader.ReadSymbolKey(); using var result = PooledArrayBuilder <IMethodSymbol> .GetInstance(); foreach (var reducedFrom in reducedFromResolution.OfType <IMethodSymbol>()) { foreach (var receiverType in receiverTypeResolution.OfType <ITypeSymbol>()) { result.AddIfNotNull(reducedFrom.ReduceExtensionMethod(receiverType)); } } return(CreateResolution(result)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var elementTypeResolution = reader.ReadSymbolKey(); var rank = reader.ReadInteger(); return(CreateSymbolInfo(GetAllSymbols <ITypeSymbol>(elementTypeResolution) .Select(s => reader.Compilation.CreateArrayTypeSymbol(s, rank)))); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var name = reader.ReadString(); var containingSymbolResolution = reader.ReadSymbolKey(); var arity = reader.ReadInteger(); using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>(); if (typeArguments.IsDefault) { return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var constructedFrom = reader.ReadSymbolKey(); using var typeArguments = reader.ReadSymbolKeyArray <ITypeSymbol>(); if (constructedFrom.SymbolCount == 0 || typeArguments.IsDefault) { return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var metadataName = reader.ReadString(); var containingSymbolResolution = reader.ReadSymbolKey(); var parameters = GetAllSymbols(containingSymbolResolution).SelectMany( s => Resolve(reader, s, metadataName)); return(CreateSymbolInfo(parameters)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var metadataName = reader.ReadString(); var containingTypeResolution = reader.ReadSymbolKey(); var events = GetAllSymbols <INamedTypeSymbol>(containingTypeResolution) .SelectMany(t => t.GetMembers(metadataName)).OfType <IEventSymbol>(); return(CreateSymbolInfo(events)); }
protected sealed override SymbolKeyResolution Resolve( SymbolKeyReader reader, IAliasSymbol?contextualSymbol, out string?failureReason) { var name = reader.ReadRequiredString(); var targetResolution = reader.ReadSymbolKey(contextualSymbol?.Target, out var targetFailureReason); var filePath = reader.ReadRequiredString(); if (targetFailureReason != null) { failureReason = $"({nameof(AliasSymbolKey)} {nameof(targetResolution)} failed -> {targetFailureReason})"; return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var containingSymbolResolution = reader.ReadSymbolKey(); // Don't check ModuleIds for equality because in practice, no-one uses them, // and there is no way to set netmodule name programmatically using Roslyn var modules = GetAllSymbols <IAssemblySymbol>(containingSymbolResolution) .SelectMany(a => a.Modules); return(CreateSymbolInfo(modules)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var constructedFromResolution = reader.ReadSymbolKey(); var typeArgumentResolutions = reader.ReadSymbolKeyArray(); Debug.Assert(!typeArgumentResolutions.IsDefault); var typeArguments = typeArgumentResolutions.Select( r => GetFirstSymbol <ITypeSymbol>(r)).ToArray(); if (typeArguments.Any(s_typeIsNull)) { return(default);
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);
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);
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)); }
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)); }
protected sealed override SymbolKeyResolution Resolve( SymbolKeyReader reader, IParameterSymbol?contextualSymbol, out string?failureReason) { var metadataName = reader.ReadRequiredString(); // Parameters are owned by members, and members are never resolved in a way where we have contextual // types to guide how the outer parts of the member may resolve. We can use contextual typing for the // *signature* portion of the member though. var containingSymbolResolution = reader.ReadSymbolKey( contextualSymbol?.ContainingSymbol, out var containingSymbolFailureReason); if (containingSymbolFailureReason != null) { failureReason = $"({nameof(ParameterSymbolKey)} {nameof(containingSymbolResolution)} failed -> {containingSymbolFailureReason})"; return(default);
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var underlyingTypeResolution = reader.ReadSymbolKey(); var tupleElementNames = reader.ReadStringArray(); try { var result = GetAllSymbols <INamedTypeSymbol>(underlyingTypeResolution).Select( t => reader.Compilation.CreateTupleTypeSymbol(t, tupleElementNames)); return(CreateSymbolInfo(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)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var metadataName = reader.ReadString(); var containingSymbolResolution = reader.ReadSymbolKey(); using var result = PooledArrayBuilder <IParameterSymbol> .GetInstance(); foreach (var container in containingSymbolResolution) { switch (container) { case IMethodSymbol method: Resolve(result, reader, metadataName, method.Parameters); break; case IPropertySymbol property: Resolve(result, reader, metadataName, property.Parameters); break; case IEventSymbol eventSymbol: // Parameters can be owned by events in VB. i.e. it's legal in VB to have: // // Public Event E(a As Integer, b As Integer); // // In this case it's equivalent to: // // Public Delegate UnutterableCompilerName(a As Integer, b As Integer) // public Event E As UnutterableCompilerName // // So, in this case, to resolve the parameter, we go have to map the event, // then find the delegate it returns, then find the parameter in the delegate's // 'Invoke' method. var delegateInvoke = (eventSymbol.Type as INamedTypeSymbol)?.DelegateInvokeMethod; if (delegateInvoke != null) { Resolve(result, reader, metadataName, delegateInvoke.Parameters); } break; } } return(CreateResolution(result)); }
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)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var constructedFromResolution = reader.ReadSymbolKey(); var typeArgumentResolutions = reader.ReadSymbolKeyArray(); Debug.Assert(!typeArgumentResolutions.IsDefault); var typeArguments = typeArgumentResolutions.Select( r => GetFirstSymbol <ITypeSymbol>(r)).ToArray(); if (typeArguments.Any(s_typeIsNull)) { return(default(SymbolKeyResolution)); } var result = constructedFromResolution.GetAllSymbols() .OfType <IMethodSymbol>() .Select(m => m.Construct(typeArguments)); return(CreateSymbolInfo(result)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var name = reader.ReadString(); var containingSymbolResolution = reader.ReadSymbolKey(); var arity = reader.ReadInteger(); var typeArgumentResolutions = reader.ReadSymbolKeyArray(); var errorTypes = ResolveErrorTypes(reader, containingSymbolResolution, name, arity); if (typeArgumentResolutions.IsDefault) { return(CreateSymbolInfo(errorTypes)); } var typeArguments = typeArgumentResolutions.Select( r => GetFirstSymbol <ITypeSymbol>(r)).ToArray(); if (typeArguments.Any(s_typeIsNull)) { return(default);
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);
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)); }
public static SymbolKeyResolution Resolve(SymbolKeyReader reader) { var localName = reader.ReadString(); var containingSymbolResolution = reader.ReadSymbolKey(); var ordinal = reader.ReadInteger(); var kind = (SymbolKind)reader.ReadInteger(); var containingSymbol = containingSymbolResolution.Symbol; if (containingSymbol != null) { foreach (var symbol in EnumerateSymbols( reader.Compilation, containingSymbol, kind, localName, reader.CancellationToken)) { if (symbol.ordinal == ordinal) { return(new SymbolKeyResolution(symbol.symbol)); } } } return(new SymbolKeyResolution()); }