public static UnrootedSymbolSet GetUnrootedSymbols(Compilation compilation) { var primaryAssembly = new WeakReference <IAssemblySymbol>(compilation.Assembly); // The dynamic type is also unrooted (i.e. doesn't point back at the compilation or source // assembly). So we have to keep track of it so we can get back from it to a project in case the // underlying compilation is GC'ed. var primaryDynamic = new WeakReference <ITypeSymbol?>( compilation.Language == LanguageNames.CSharp ? compilation.DynamicType : null); var secondarySymbols = new WeakSet <ISymbol>(); foreach (var reference in compilation.References) { var symbol = compilation.GetAssemblyOrModuleSymbol(reference); if (symbol == null) { continue; } secondarySymbols.Add(symbol); } return(new UnrootedSymbolSet(primaryAssembly, primaryDynamic, secondarySymbols)); }
public static WeakSet <ISymbol> GetUnrootedSymbols(Compilation compilation) { var result = new WeakSet <ISymbol>(); var compAssembly = compilation.Assembly; result.Add(compAssembly); // The dynamic type is also unrooted (i.e. doesn't point back at the compilation or source // assembly). So we have to keep track of it so we can get back from it to a project in case the // underlying compilation is GC'ed. if (compilation.Language == LanguageNames.CSharp) { result.Add(compilation.DynamicType); } foreach (var reference in compilation.References) { var symbol = compilation.GetAssemblyOrModuleSymbol(reference); if (symbol == null) { continue; } result.Add(symbol); } return(result); }
public static UnrootedSymbolSet GetUnrootedSymbols(Compilation compilation) { var primaryAssembly = new WeakReference <IAssemblySymbol>(compilation.Assembly); // The dynamic type is also unrooted (i.e. doesn't point back at the compilation or source // assembly). So we have to keep track of it so we can get back from it to a project in case the // underlying compilation is GC'ed. var primaryDynamic = new WeakReference <ITypeSymbol?>( compilation.Language == LanguageNames.CSharp ? compilation.DynamicType : null); // PERF: Preallocate this array so we don't have to resize it as we're adding assembly symbols. using var _ = ArrayBuilder <(int hashcode, WeakReference <ISymbol> symbol)> .GetInstance( compilation.ExternalReferences.Length + compilation.DirectiveReferences.Length, out var secondarySymbols); foreach (var reference in compilation.References) { var symbol = compilation.GetAssemblyOrModuleSymbol(reference); if (symbol == null) { continue; } secondarySymbols.Add((ReferenceEqualityComparer.GetHashCode(symbol), new WeakReference <ISymbol>(symbol))); } // Sort all the secondary symbols by their hash. This will allow us to easily binary search for // them afterwards. Note: it is fine for multiple symbols to have the same reference hash. The // search algorithm will account for that. secondarySymbols.Sort(WeakSymbolComparer.Instance); return(new UnrootedSymbolSet(primaryAssembly, primaryDynamic, secondarySymbols.ToImmutable())); }
private static IReadOnlyDictionary <string, INamedTypeSymbol[]> BuildLookup(Compilation compilation) { var refs = from metadataReference in compilation.References let assembly = compilation.GetAssemblyOrModuleSymbol(metadataReference) as IAssemblySymbol where assembly != null from type in assembly.GlobalNamespace.GetNamespaceTypes() group type by type.Name into names select new { names.Key, names }; return(refs.ToDictionary(k => k.Key, p => p.names.AsEnumerable().ToArray())); }
private bool HasMissingReferences(Compilation compilation, IReadOnlyList <MetadataReference> metadataReferences) { foreach (var reference in metadataReferences) { if (compilation.GetAssemblyOrModuleSymbol(reference) == null) { return(true); } } return(false); }
private IEnumerable <IAssemblySymbol> GetAssemblySymbols(Compilation compilation, bool ignoreAssemblyKey) { if (ignoreAssemblyKey || compilation.Assembly.Identity.Name == this.assemblyName) { yield return(compilation.Assembly); } foreach (var reference in compilation.References) { var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol; if (assembly != null && (ignoreAssemblyKey || assembly.Identity.Name == this.assemblyName)) { yield return(assembly); } } }
public static ConditionalWeakTable<ISymbol, object?> GetAssemblyAndModuleSet(Compilation compilation) { var result = new ConditionalWeakTable<ISymbol, object?>(); var compAssembly = compilation.Assembly; result.Add(compAssembly, null); foreach (var reference in compilation.References) { var symbol = compilation.GetAssemblyOrModuleSymbol(reference); if (symbol == null) continue; result.Add(symbol, null); } return result; }
private Compilation UpdateCompilationWithNewReferencesAndRecordAssemblySymbols(Compilation compilation, List <MetadataReference> newReferences, Dictionary <MetadataReference, ProjectId> metadataReferenceToProjectId) { if (!Enumerable.SequenceEqual(compilation.ExternalReferences, newReferences)) { compilation = compilation.WithReferences(newReferences); } // TODO: Record source assembly to project mapping // RecordSourceOfAssemblySymbol(compilation.Assembly, this.ProjectState.Id); foreach (var kvp in metadataReferenceToProjectId) { var metadataReference = kvp.Key; var projectId = kvp.Value; var symbol = compilation.GetAssemblyOrModuleSymbol(metadataReference); RecordSourceOfAssemblySymbol(symbol, projectId); } return(compilation); }