using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols; internal sealed class SourceNamespaceSymbol : NamespaceSymbol { private sealed class AliasesAndUsings { private class ExternAliasesAndDiagnostics { public static readonly ExternAliasesAndDiagnostics Empty = new ExternAliasesAndDiagnostics { ExternAliases = ImmutableArray.Empty, Diagnostics = ImmutableArray.Empty }; public ImmutableArray ExternAliases { get; init; } public ImmutableArray Diagnostics { get; init; } } private class UsingsAndDiagnostics { public static readonly UsingsAndDiagnostics Empty = new UsingsAndDiagnostics { UsingAliases = ImmutableArray.Empty, UsingAliasesMap = null, UsingNamespacesOrTypes = ImmutableArray.Empty, Diagnostics = null }; public ImmutableArray UsingAliases { get; init; } public ImmutableDictionary? UsingAliasesMap { get; init; } public ImmutableArray UsingNamespacesOrTypes { get; init; } public DiagnosticBag? Diagnostics { get; init; } } private ExternAliasesAndDiagnostics? _lazyExternAliases; private UsingsAndDiagnostics? _lazyGlobalUsings; private UsingsAndDiagnostics? _lazyUsings; private Imports? _lazyImports; private SymbolCompletionState _state; internal ImmutableArray GetExternAliases(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax) { return GetExternAliasesAndDiagnostics(declaringSymbol, declarationSyntax).ExternAliases; } internal ImmutableArray GetExternAliases(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax) { return (_lazyExternAliases ?? GetExternAliasesAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(default(CancellationToken)))).ExternAliases; } private ExternAliasesAndDiagnostics GetExternAliasesAndDiagnostics(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) if (_lazyExternAliases == null) { SyntaxList externs; if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } externs = baseNamespaceDeclarationSyntax.Externs; } else { externs = compilationUnitSyntax.Externs; } if (!externs.Any()) { _lazyExternAliases = ExternAliasesAndDiagnostics.Empty; } else { DiagnosticBag instance = DiagnosticBag.GetInstance(); Interlocked.CompareExchange(ref _lazyExternAliases, new ExternAliasesAndDiagnostics { ExternAliases = buildExternAliases(externs, declaringSymbol, instance), Diagnostics = instance.ToReadOnlyAndFree() }, null); } } return _lazyExternAliases; static ImmutableArray buildExternAliases(SyntaxList syntaxList, SourceNamespaceSymbol sourceNamespaceSymbol, DiagnosticBag diagnostics) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) CSharpCompilation declaringCompilation = sourceNamespaceSymbol.DeclaringCompilation; ArrayBuilder instance2 = ArrayBuilder.GetInstance(); Enumerator enumerator = syntaxList.GetEnumerator(); while (enumerator.MoveNext()) { ExternAliasDirectiveSyntax current = enumerator.Current; declaringCompilation.RecordImport(current); bool skipInLookup = false; if (((Compilation)declaringCompilation).IsSubmission) { diagnostics.Add(ErrorCode.ERR_ExternAliasNotAllowed, ((SyntaxNode)current).Location); skipInLookup = true; } else { Enumerator enumerator2 = instance2.GetEnumerator(); SyntaxToken identifier; while (enumerator2.MoveNext()) { AliasAndExternAliasDirective current2 = enumerator2.Current; string name = current2.Alias.Name; identifier = current.Identifier; if (name == ((SyntaxToken)(ref identifier)).ValueText) { diagnostics.Add(ErrorCode.ERR_DuplicateAlias, current2.Alias.GetFirstLocation(), current2.Alias.Name); break; } } if (current.Identifier.ContextualKind() == SyntaxKind.GlobalKeyword) { identifier = current.Identifier; diagnostics.Add(ErrorCode.ERR_GlobalExternAlias, ((SyntaxToken)(ref identifier)).GetLocation()); } } instance2.Add(new AliasAndExternAliasDirective(new AliasSymbolFromSyntax(sourceNamespaceSymbol, current), current, skipInLookup)); } return instance2.ToImmutableAndFree(); } } internal ImmutableArray GetUsingAliases(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { return GetUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingAliases; } internal ImmutableArray GetGlobalUsingAliases(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { return GetGlobalUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingAliases; } internal ImmutableDictionary GetUsingAliasesMap(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { return GetUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingAliasesMap ?? ImmutableDictionary.Empty; } internal ImmutableDictionary GetGlobalUsingAliasesMap(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax, ConsList? basesBeingResolved) { return (_lazyGlobalUsings ?? GetGlobalUsingsAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(default(CancellationToken)), basesBeingResolved)).UsingAliasesMap ?? ImmutableDictionary.Empty; } internal ImmutableArray GetUsingNamespacesOrTypes(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { return GetUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingNamespacesOrTypes; } private UsingsAndDiagnostics GetUsingsAndDiagnostics(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { return GetUsingsAndDiagnostics(ref _lazyUsings, declaringSymbol, declarationSyntax, basesBeingResolved, onlyGlobal: false); } internal ImmutableArray GetGlobalUsingNamespacesOrTypes(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax, ConsList? basesBeingResolved) { return (_lazyGlobalUsings ?? GetGlobalUsingsAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(default(CancellationToken)), basesBeingResolved)).UsingNamespacesOrTypes; } private UsingsAndDiagnostics GetGlobalUsingsAndDiagnostics(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { return GetUsingsAndDiagnostics(ref _lazyGlobalUsings, declaringSymbol, declarationSyntax, basesBeingResolved, onlyGlobal: true); } private UsingsAndDiagnostics GetUsingsAndDiagnostics(ref UsingsAndDiagnostics? usings, SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved, bool onlyGlobal) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if (usings == null) { bool? flag; SyntaxList usings2; if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } flag = null; usings2 = baseNamespaceDeclarationSyntax.Usings; } else { flag = onlyGlobal; usings2 = compilationUnitSyntax.Usings; } UsingsAndDiagnostics value = (usings2.Any() ? buildUsings(usings2, declaringSymbol, declarationSyntax, flag, basesBeingResolved) : ((flag == false) ? new UsingsAndDiagnostics { UsingAliases = GetGlobalUsingAliases(declaringSymbol, declarationSyntax, basesBeingResolved), UsingAliasesMap = declaringSymbol.GetGlobalUsingAliasesMap(basesBeingResolved), UsingNamespacesOrTypes = declaringSymbol.GetGlobalUsingNamespacesOrTypes(basesBeingResolved), Diagnostics = null } : UsingsAndDiagnostics.Empty)); Interlocked.CompareExchange(ref usings, value, null); } return usings; UsingsAndDiagnostics buildUsings(SyntaxList usingDirectives, SourceNamespaceSymbol sourceNamespaceSymbol, CSharpSyntaxNode cSharpSyntaxNode, bool? applyIsGlobalFilter, ConsList? basesBeingResolved2) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Invalid comparison between Unknown and I4 //IL_0403: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Invalid comparison between Unknown and I4 //IL_033f: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0538: Unknown result type (might be due to invalid IL or missing references) //IL_053d: Unknown result type (might be due to invalid IL or missing references) //IL_053f: Unknown result type (might be due to invalid IL or missing references) //IL_0542: Invalid comparison between Unknown and I4 //IL_0411: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Unknown result type (might be due to invalid IL or missing references) //IL_041e: Unknown result type (might be due to invalid IL or missing references) //IL_0550: Unknown result type (might be due to invalid IL or missing references) //IL_0554: Invalid comparison between Unknown and I4 //IL_0544: Unknown result type (might be due to invalid IL or missing references) //IL_0547: Invalid comparison between Unknown and I4 //IL_045b: Unknown result type (might be due to invalid IL or missing references) //IL_0462: Unknown result type (might be due to invalid IL or missing references) //IL_0468: Unknown result type (might be due to invalid IL or missing references) //IL_0556: Unknown result type (might be due to invalid IL or missing references) //IL_055a: Invalid comparison between Unknown and I4 //IL_0549: Unknown result type (might be due to invalid IL or missing references) //IL_054c: Invalid comparison between Unknown and I4 //IL_059d: Unknown result type (might be due to invalid IL or missing references) //IL_05a3: Invalid comparison between Unknown and I4 ImmutableArray externAliases = GetExternAliases(sourceNamespaceSymbol, cSharpSyntaxNode); ImmutableDictionary immutableDictionary = ImmutableDictionary.Empty; ImmutableArray immutableArray = ImmutableArray.Empty; ImmutableArray immutableArray2 = ImmutableArray.Empty; if (applyIsGlobalFilter == false) { immutableDictionary = sourceNamespaceSymbol.GetGlobalUsingAliasesMap(basesBeingResolved2); immutableArray = sourceNamespaceSymbol.GetGlobalUsingNamespacesOrTypes(basesBeingResolved2); immutableArray2 = GetGlobalUsingAliases(sourceNamespaceSymbol, cSharpSyntaxNode, basesBeingResolved2); } DiagnosticBag val = new DiagnosticBag(); CSharpCompilation declaringCompilation = sourceNamespaceSymbol.DeclaringCompilation; ArrayBuilder usings3 = null; ImmutableDictionary.Builder builder = null; ArrayBuilder val2 = null; Binder binder = null; PooledHashSet uniqueUsings = null; PooledHashSet uniqueUsings2 = null; Enumerator enumerator = usingDirectives.GetEnumerator(); while (enumerator.MoveNext()) { UsingDirectiveSyntax current = enumerator.Current; if (applyIsGlobalFilter.HasValue && current.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword) != (applyIsGlobalFilter == true)) { continue; } declaringCompilation.RecordImport(current); SyntaxToken val3; if (current.Alias != null) { SyntaxToken identifier = current.Alias.Name.Identifier; Location location = ((SyntaxNode)current.Alias.Name).Location; if (identifier.ContextualKind() == SyntaxKind.GlobalKeyword) { val.Add(ErrorCode.WRN_GlobalAliasDefn, location); } SyntaxToken staticKeyword = current.StaticKeyword; val3 = default(SyntaxToken); if (staticKeyword != val3) { val.Add(ErrorCode.ERR_NoAliasHere, location); } SourceMemberContainerTypeSymbol.ReportReservedTypeName(((SyntaxToken)(ref identifier)).Text, declaringCompilation, val, location); string valueText = ((SyntaxToken)(ref identifier)).ValueText; bool flag2 = false; if (builder?.ContainsKey(valueText) ?? immutableDictionary.ContainsKey(valueText)) { flag2 = true; if (!((SyntaxNode)current.NamespaceOrType).IsMissing) { val.Add(ErrorCode.ERR_DuplicateAlias, location, valueText); } } else { ImmutableArray.Enumerator enumerator2 = externAliases.GetEnumerator(); while (enumerator2.MoveNext()) { if (enumerator2.Current.Alias.Name == valueText) { val.Add(ErrorCode.ERR_DuplicateAlias, ((SyntaxNode)current).Location, valueText); break; } } } AliasAndUsingDirective aliasAndUsingDirective = new AliasAndUsingDirective(new AliasSymbolFromSyntax(sourceNamespaceSymbol, current), current); if (val2 == null) { val2 = ArrayBuilder.GetInstance(); val2.AddRange(immutableArray2); } val2.Add(aliasAndUsingDirective); if (!flag2) { if (builder == null) { builder = immutableDictionary.ToBuilder(); } builder.Add(valueText, aliasAndUsingDirective); } continue; } if (((SyntaxNode)current.NamespaceOrType).IsMissing) { continue; } BinderFlags binderFlags = BinderFlags.SuppressConstraintChecks; SyntaxToken unsafeKeyword = current.UnsafeKeyword; val3 = default(SyntaxToken); if (unsafeKeyword != val3) { val3 = current.UnsafeKeyword; Location location2 = ((SyntaxToken)(ref val3)).GetLocation(); SyntaxToken staticKeyword2 = current.StaticKeyword; val3 = default(SyntaxToken); if (staticKeyword2 == val3) { val.Add(ErrorCode.ERR_BadUnsafeInUsingDirective, location2); } else { MessageID.IDS_FeatureUsingTypeAlias.CheckFeatureAvailability(val, (SyntaxNode)(object)current, location2); sourceNamespaceSymbol.CheckUnsafeModifier(DeclarationModifiers.Unsafe, location2, val); } binderFlags |= BinderFlags.UnsafeRegion; } else if (!declaringCompilation.IsFeatureEnabled(MessageID.IDS_FeatureUsingTypeAlias)) { binderFlags |= BinderFlags.UnsafeRegion; } BindingDiagnosticBag instance = BindingDiagnosticBag.GetInstance(); if (binder == null) { binder = declaringCompilation.GetBinderFactory(cSharpSyntaxNode.SyntaxTree).GetBinder((SyntaxNode)(object)current.NamespaceOrType).WithAdditionalFlags(binderFlags); } NamespaceOrTypeSymbol namespaceOrTypeSymbol = binder.BindNamespaceOrTypeSymbol(current.NamespaceOrType, instance, basesBeingResolved2).NamespaceOrTypeSymbol; bool flag3 = true; bool flag4; if ((int)namespaceOrTypeSymbol.Kind == 12) { SyntaxToken staticKeyword3 = current.StaticKeyword; val3 = default(SyntaxToken); if (staticKeyword3 != val3) { val.Add(ErrorCode.ERR_BadUsingType, ((SyntaxNode)current.NamespaceOrType).Location, namespaceOrTypeSymbol); } else if (!((HashSet)(object)getOrCreateUniqueUsings(ref uniqueUsings, immutableArray)).Add(namespaceOrTypeSymbol)) { val.Add((!immutableArray.IsEmpty && ((HashSet)(object)getOrCreateUniqueGlobalUsingsNotInTree(ref uniqueUsings2, immutableArray, cSharpSyntaxNode.SyntaxTree)).Contains(namespaceOrTypeSymbol)) ? ErrorCode.HDN_DuplicateWithGlobalUsing : ErrorCode.WRN_DuplicateUsing, ((SyntaxNode)current.NamespaceOrType).Location, namespaceOrTypeSymbol); } else { getOrCreateUsingsBuilder(ref usings3, immutableArray).Add(new NamespaceOrTypeAndUsingDirective(namespaceOrTypeSymbol, current, default(ImmutableArray))); } } else { if ((int)namespaceOrTypeSymbol.Kind != 11) { SymbolKind kind = namespaceOrTypeSymbol.Kind; if ((int)kind <= 3) { if ((int)kind == 1 || (int)kind == 3) { goto IL_055c; } } else if ((int)kind == 14 || (int)kind == 20) { goto IL_055c; } flag4 = false; goto IL_0564; } SyntaxToken staticKeyword4 = current.StaticKeyword; val3 = default(SyntaxToken); if (staticKeyword4 == val3) { val.Add(ErrorCode.ERR_BadUsingNamespace, ((SyntaxNode)current.NamespaceOrType).Location, namespaceOrTypeSymbol); } else { NamedTypeSymbol namedTypeSymbol = (NamedTypeSymbol)namespaceOrTypeSymbol; SyntaxToken globalKeyword = current.GlobalKeyword; val3 = default(SyntaxToken); if (globalKeyword != val3 && namedTypeSymbol.HasFileLocalTypes()) { val.Add(ErrorCode.ERR_GlobalUsingStaticFileType, ((SyntaxNode)current.NamespaceOrType).Location, namespaceOrTypeSymbol); } if (!((HashSet)(object)getOrCreateUniqueUsings(ref uniqueUsings, immutableArray)).Add((NamespaceOrTypeSymbol)namedTypeSymbol)) { val.Add((!immutableArray.IsEmpty && ((HashSet)(object)getOrCreateUniqueGlobalUsingsNotInTree(ref uniqueUsings2, immutableArray, cSharpSyntaxNode.SyntaxTree)).Contains(namespaceOrTypeSymbol)) ? ErrorCode.HDN_DuplicateWithGlobalUsing : ErrorCode.WRN_DuplicateUsing, ((SyntaxNode)current.NamespaceOrType).Location, namedTypeSymbol); } else { binder.ReportDiagnosticsIfObsolete(val, namedTypeSymbol, (SyntaxNode)(object)current.NamespaceOrType, hasBaseReceiver: false); getOrCreateUsingsBuilder(ref usings3, immutableArray).Add(new NamespaceOrTypeAndUsingDirective(namedTypeSymbol, current, ((BindingDiagnosticBag)(object)instance).DependenciesBag.ToImmutableArray())); } } } goto IL_05ec; IL_05ec: if (flag3) { val.AddRange(((BindingDiagnosticBag)instance).DiagnosticBag); } ((BindingDiagnosticBag)(object)instance).Free(); continue; IL_0564: if (flag4) { val.Add(ErrorCode.ERR_BadUsingStaticType, ((SyntaxNode)current.NamespaceOrType).Location, namespaceOrTypeSymbol.GetKindText()); flag3 = false; } else if ((int)namespaceOrTypeSymbol.Kind != 4) { val.Add(ErrorCode.ERR_BadSKknown, ((SyntaxNode)current.NamespaceOrType).Location, current.NamespaceOrType, namespaceOrTypeSymbol.GetKindText(), MessageID.IDS_SK_TYPE_OR_NAMESPACE.Localize()); } goto IL_05ec; IL_055c: flag4 = true; goto IL_0564; } uniqueUsings?.Free(); uniqueUsings2?.Free(); if (val.IsEmptyWithoutResolution) { val = null; } return new UsingsAndDiagnostics { UsingAliases = (val2?.ToImmutableAndFree() ?? immutableArray2), UsingAliasesMap = (builder?.ToImmutable() ?? immutableDictionary), UsingNamespacesOrTypes = (usings3?.ToImmutableAndFree() ?? immutableArray), Diagnostics = val }; } static PooledHashSet getOrCreateUniqueGlobalUsingsNotInTree(ref PooledHashSet? uniqueUsings, ImmutableArray globalUsingNamespacesOrTypes, SyntaxTree tree) { if (uniqueUsings == null) { uniqueUsings = SpecializedSymbolCollections.GetPooledSymbolHashSetInstance(); ISetExtensions.AddAll((ISet)uniqueUsings, from n in globalUsingNamespacesOrTypes.Where(delegate(NamespaceOrTypeAndUsingDirective n) { SyntaxReference? usingDirectiveReference = n.UsingDirectiveReference; return ((usingDirectiveReference != null) ? usingDirectiveReference.SyntaxTree : null) != tree; }) select n.NamespaceOrType); } return uniqueUsings; } static PooledHashSet getOrCreateUniqueUsings(ref PooledHashSet? uniqueUsings, ImmutableArray globalUsingNamespacesOrTypes) { if (uniqueUsings == null) { uniqueUsings = SpecializedSymbolCollections.GetPooledSymbolHashSetInstance(); ISetExtensions.AddAll((ISet)uniqueUsings, globalUsingNamespacesOrTypes.Select((NamespaceOrTypeAndUsingDirective n) => n.NamespaceOrType)); } return uniqueUsings; } static ArrayBuilder getOrCreateUsingsBuilder(ref ArrayBuilder? reference, ImmutableArray globalUsingNamespacesOrTypes) { if (reference == null) { reference = ArrayBuilder.GetInstance(); reference.AddRange(globalUsingNamespacesOrTypes); } return reference; } } internal Imports GetImports(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { if (_lazyImports == null) { Interlocked.CompareExchange(ref _lazyImports, Imports.Create(GetUsingAliasesMap(declaringSymbol, declarationSyntax, basesBeingResolved), GetUsingNamespacesOrTypes(declaringSymbol, declarationSyntax, basesBeingResolved), GetExternAliases(declaringSymbol, declarationSyntax)), null); } return _lazyImports; } internal void Complete(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax, CancellationToken cancellationToken) { ExternAliasesAndDiagnostics externAliasesAndDiagnostics = _lazyExternAliases ?? GetExternAliasesAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(cancellationToken)); cancellationToken.ThrowIfCancellationRequested(); UsingsAndDiagnostics usingsAndDiagnostics = _lazyGlobalUsings ?? (declaringSymbol.IsGlobalNamespace ? GetGlobalUsingsAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(cancellationToken), null) : UsingsAndDiagnostics.Empty); cancellationToken.ThrowIfCancellationRequested(); UsingsAndDiagnostics usingsAndDiagnostics2 = _lazyUsings ?? GetUsingsAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(cancellationToken), null); cancellationToken.ThrowIfCancellationRequested(); while (true) { cancellationToken.ThrowIfCancellationRequested(); CompletionPart nextIncompletePart = _state.NextIncompletePart; switch (nextIncompletePart) { case CompletionPart.StartBaseType: if (_state.NotePartComplete(CompletionPart.StartBaseType)) { Validate(declaringSymbol, declarationSyntax, externAliasesAndDiagnostics, usingsAndDiagnostics2, usingsAndDiagnostics.Diagnostics); _state.NotePartComplete(CompletionPart.FinishBaseType); } break; case CompletionPart.FinishBaseType: _state.SpinWaitComplete(CompletionPart.FinishBaseType, cancellationToken); break; case CompletionPart.None: return; default: _state.NotePartComplete(CompletionPart.MethodSymbolAll | CompletionPart.StartInterfaces | CompletionPart.FinishInterfaces | CompletionPart.EnumUnderlyingType | CompletionPart.TypeArguments | CompletionPart.FinishMemberChecks | CompletionPart.MembersCompletedChecksStarted | CompletionPart.MembersCompleted); break; } _state.SpinWaitComplete(nextIncompletePart, cancellationToken); } } private static void Validate(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax, ExternAliasesAndDiagnostics externAliasesAndDiagnostics, UsingsAndDiagnostics usingsAndDiagnostics, DiagnosticBag? globalUsingDiagnostics) { CSharpCompilation compilation = declaringSymbol.DeclaringCompilation; DiagnosticBag declarationDiagnostics = compilation.DeclarationDiagnostics; BindingDiagnosticBag diagnostics = BindingDiagnosticBag.GetInstance(); if (usingsAndDiagnostics.UsingAliasesMap != null) { string text = default(string); AliasAndUsingDirective aliasAndUsingDirective = default(AliasAndUsingDirective); foreach (KeyValuePair item in usingsAndDiagnostics.UsingAliasesMap) { KeyValuePairUtil.Deconstruct(item, ref text, ref aliasAndUsingDirective); AliasAndUsingDirective aliasAndUsingDirective2 = aliasAndUsingDirective; if (aliasAndUsingDirective2.UsingDirectiveReference.SyntaxTree == declarationSyntax.SyntaxTree) { NamespaceOrTypeSymbol aliasTarget = aliasAndUsingDirective2.Alias.GetAliasTarget(null); ((BindingDiagnosticBag)(object)diagnostics).Clear(); if (aliasAndUsingDirective2.Alias is AliasSymbolFromSyntax aliasSymbolFromSyntax) { ((BindingDiagnosticBag)(object)diagnostics).AddRange((BindingDiagnosticBag)(object)aliasSymbolFromSyntax.AliasTargetDiagnostics, false); } aliasAndUsingDirective2.Alias.CheckConstraints(diagnostics); declarationDiagnostics.AddRange(((BindingDiagnosticBag)diagnostics).DiagnosticBag); recordImportDependencies(aliasAndUsingDirective2.UsingDirective, aliasTarget); } } } TypeConversions typeConversions = compilation.SourceAssembly.CorLibrary.TypeConversions; ImmutableArray.Enumerator enumerator2 = usingsAndDiagnostics.UsingNamespacesOrTypes.GetEnumerator(); while (enumerator2.MoveNext()) { NamespaceOrTypeAndUsingDirective current = enumerator2.Current; if (current.UsingDirectiveReference.SyntaxTree == declarationSyntax.SyntaxTree) { ((BindingDiagnosticBag)(object)diagnostics).Clear(); ((BindingDiagnosticBag)(object)diagnostics).AddDependencies(current.Dependencies); NamespaceOrTypeSymbol namespaceOrType = current.NamespaceOrType; UsingDirectiveSyntax usingDirective = current.UsingDirective; if (namespaceOrType.IsType) { ((TypeSymbol)namespaceOrType).CheckAllConstraints(location: ((SyntaxNode)usingDirective.NamespaceOrType).Location, compilation: compilation, conversions: typeConversions, diagnostics: diagnostics); } declarationDiagnostics.AddRange(((BindingDiagnosticBag)diagnostics).DiagnosticBag); recordImportDependencies(usingDirective, namespaceOrType); } } ImmutableArray.Enumerator enumerator3 = externAliasesAndDiagnostics.ExternAliases.GetEnumerator(); while (enumerator3.MoveNext()) { AliasAndExternAliasDirective current2 = enumerator3.Current; if (!current2.SkipInLookup) { NamespaceSymbol ns = (NamespaceSymbol)current2.Alias.GetAliasTarget(null); if (current2.Alias is AliasSymbolFromSyntax aliasSymbolFromSyntax2) { declarationDiagnostics.AddRange(((BindingDiagnosticBag)aliasSymbolFromSyntax2.AliasTargetDiagnostics).DiagnosticBag); } if (!Compilation.ReportUnusedImportsInTree(current2.ExternAliasDirective.SyntaxTree)) { ((BindingDiagnosticBag)(object)diagnostics).Clear(); diagnostics.AddAssembliesUsedByNamespaceReference(ns); compilation.AddUsedAssemblies(((BindingDiagnosticBag)(object)diagnostics).DependenciesBag); } } } declarationDiagnostics.AddRange(externAliasesAndDiagnostics.Diagnostics); DiagnosticBag? diagnostics2 = usingsAndDiagnostics.Diagnostics; if (diagnostics2 != null && !diagnostics2.IsEmptyWithoutResolution) { declarationDiagnostics.AddRange(usingsAndDiagnostics.Diagnostics.AsEnumerable()); } if (globalUsingDiagnostics != null && !globalUsingDiagnostics.IsEmptyWithoutResolution) { declarationDiagnostics.AddRange(globalUsingDiagnostics.AsEnumerable()); } ((BindingDiagnosticBag)(object)diagnostics).Free(); void recordImportDependencies(UsingDirectiveSyntax usingDirectiveSyntax, NamespaceOrTypeSymbol target) { if (Compilation.ReportUnusedImportsInTree(usingDirectiveSyntax.SyntaxTree)) { compilation.RecordImportDependencies(usingDirectiveSyntax, ((BindingDiagnosticBag)(object)diagnostics).DependenciesBag.ToImmutableArray()); } else { if (target.IsNamespace) { diagnostics.AddAssembliesUsedByNamespaceReference((NamespaceSymbol)target); } compilation.AddUsedAssemblies(((BindingDiagnosticBag)(object)diagnostics).DependenciesBag); } } } } private class MergedGlobalAliasesAndUsings { private Imports? _lazyImports; private SymbolCompletionState _state; public static readonly MergedGlobalAliasesAndUsings Empty = new MergedGlobalAliasesAndUsings { UsingAliasesMap = ImmutableDictionary.Empty, UsingNamespacesOrTypes = ImmutableArray.Empty, Diagnostics = ImmutableArray.Empty, _lazyImports = Microsoft.CodeAnalysis.CSharp.Imports.Empty }; public ImmutableDictionary? UsingAliasesMap { get; init; } public ImmutableArray UsingNamespacesOrTypes { get; init; } public ImmutableArray Diagnostics { get; init; } public Imports Imports { get { if (_lazyImports == null) { Interlocked.CompareExchange(ref _lazyImports, Microsoft.CodeAnalysis.CSharp.Imports.Create(UsingAliasesMap ?? ImmutableDictionary.Empty, UsingNamespacesOrTypes, ImmutableArray.Empty), null); } return _lazyImports; } } internal void Complete(SourceNamespaceSymbol declaringSymbol, CancellationToken cancellationToken) { while (true) { cancellationToken.ThrowIfCancellationRequested(); CompletionPart nextIncompletePart = _state.NextIncompletePart; switch (nextIncompletePart) { case CompletionPart.StartBaseType: if (_state.NotePartComplete(CompletionPart.StartBaseType)) { if (!Diagnostics.IsDefaultOrEmpty) { declaringSymbol.DeclaringCompilation.DeclarationDiagnostics.AddRange(Diagnostics); } _state.NotePartComplete(CompletionPart.FinishBaseType); } break; case CompletionPart.FinishBaseType: _state.SpinWaitComplete(CompletionPart.FinishBaseType, cancellationToken); break; case CompletionPart.None: return; default: _state.NotePartComplete(CompletionPart.MethodSymbolAll | CompletionPart.StartInterfaces | CompletionPart.FinishInterfaces | CompletionPart.EnumUnderlyingType | CompletionPart.TypeArguments | CompletionPart.FinishMemberChecks | CompletionPart.MembersCompletedChecksStarted | CompletionPart.MembersCompleted); break; } _state.SpinWaitComplete(nextIncompletePart, cancellationToken); } } } private static readonly ImmutableDictionary s_emptyMap = ImmutableDictionary.Empty.WithComparers((IEqualityComparer?)ReferenceEqualityComparer.Instance); private readonly SourceModuleSymbol _module; private readonly Symbol _container; private readonly MergedNamespaceDeclaration _mergedDeclaration; private SymbolCompletionState _state; private ImmutableArray _locations; private Dictionary, ImmutableArray> _nameToMembersMap; private Dictionary, ImmutableArray> _nameToTypeMembersMap; private ImmutableArray _lazyAllMembers; private ImmutableArray _lazyTypeMembersUnordered; private ImmutableDictionary _aliasesAndUsings_doNotAccessDirectly = s_emptyMap; private MergedGlobalAliasesAndUsings _lazyMergedGlobalAliasesAndUsings; private const int LazyAllMembersIsSorted = 1; private int _flags; private LexicalSortKey _lazyLexicalSortKey = LexicalSortKey.NotInitialized; private static readonly Func s_declaringSyntaxReferencesSelector = (SingleNamespaceDeclaration d) => (SyntaxReference)(object)new NamespaceDeclarationSyntaxReference(d.SyntaxReference); internal MergedNamespaceDeclaration MergedDeclaration => _mergedDeclaration; public override Symbol ContainingSymbol => _container; public override AssemblySymbol ContainingAssembly => _module.ContainingAssembly; public override string Name => _mergedDeclaration.Name; public override ImmutableArray Locations { get { if (_locations.IsDefault) { ImmutableInterlocked.InterlockedCompareExchange(ref _locations, _mergedDeclaration.NameLocations, default(ImmutableArray)); } return _locations; } } public override ImmutableArray DeclaringSyntaxReferences => ComputeDeclaringReferencesCore(); internal override ModuleSymbol ContainingModule => _module; internal override NamespaceExtent Extent => new NamespaceExtent(_module); public Imports GetImports(CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } if (!baseNamespaceDeclarationSyntax.Externs.Any() && !baseNamespaceDeclarationSyntax.Usings.Any()) { return Imports.Empty; } } else if (!compilationUnitSyntax.Externs.Any() && !compilationUnitSyntax.Usings.Any()) { return GetGlobalUsingImports(basesBeingResolved); } return GetAliasesAndUsings(declarationSyntax).GetImports(this, declarationSyntax, basesBeingResolved); } private AliasesAndUsings GetAliasesAndUsings(CSharpSyntaxNode declarationSyntax) { return GetAliasesAndUsings(GetMatchingNamespaceDeclaration(declarationSyntax)); } private SingleNamespaceDeclaration GetMatchingNamespaceDeclaration(CSharpSyntaxNode declarationSyntax) { ImmutableArray.Enumerator enumerator = _mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { SingleNamespaceDeclaration current = enumerator.Current; SyntaxReference syntaxReference = current.SyntaxReference; if (syntaxReference.SyntaxTree == declarationSyntax.SyntaxTree && (object)syntaxReference.GetSyntax(default(CancellationToken)) == declarationSyntax) { return current; } } throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.AliasesAndUsings.cs", 85); } private static AliasesAndUsings GetOrCreateAliasAndUsings(ref ImmutableDictionary dictionary, SingleNamespaceDeclaration declaration) { return ImmutableInterlocked.GetOrAdd(ref dictionary, declaration, (SingleNamespaceDeclaration _) => new AliasesAndUsings()); } private AliasesAndUsings GetAliasesAndUsings(SingleNamespaceDeclaration declaration) { return GetOrCreateAliasAndUsings(ref _aliasesAndUsings_doNotAccessDirectly, declaration); } public ImmutableArray GetExternAliases(CSharpSyntaxNode declarationSyntax) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } if (!baseNamespaceDeclarationSyntax.Externs.Any()) { return ImmutableArray.Empty; } } else if (!compilationUnitSyntax.Externs.Any()) { return ImmutableArray.Empty; } return GetAliasesAndUsings(declarationSyntax).GetExternAliases(this, declarationSyntax); } public ImmutableArray GetUsingAliases(CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } if (!baseNamespaceDeclarationSyntax.Usings.Any()) { return ImmutableArray.Empty; } } else if (!compilationUnitSyntax.Usings.Any()) { return ImmutableArray.Empty; } return GetAliasesAndUsings(declarationSyntax).GetUsingAliases(this, declarationSyntax, basesBeingResolved); } public ImmutableDictionary GetUsingAliasesMap(CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } if (!baseNamespaceDeclarationSyntax.Usings.Any()) { return ImmutableDictionary.Empty; } } else if (!compilationUnitSyntax.Usings.Any()) { return GetGlobalUsingAliasesMap(basesBeingResolved); } return GetAliasesAndUsings(declarationSyntax).GetUsingAliasesMap(this, declarationSyntax, basesBeingResolved); } public ImmutableArray GetUsingNamespacesOrTypes(CSharpSyntaxNode declarationSyntax, ConsList? basesBeingResolved) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!(declarationSyntax is CompilationUnitSyntax compilationUnitSyntax)) { if (!(declarationSyntax is BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax)) { throw ExceptionUtilities.UnexpectedValue((object)declarationSyntax); } if (!baseNamespaceDeclarationSyntax.Usings.Any()) { return ImmutableArray.Empty; } } else if (!compilationUnitSyntax.Usings.Any()) { return GetGlobalUsingNamespacesOrTypes(basesBeingResolved); } return GetAliasesAndUsings(declarationSyntax).GetUsingNamespacesOrTypes(this, declarationSyntax, basesBeingResolved); } private Imports GetGlobalUsingImports(ConsList? basesBeingResolved) { return GetMergedGlobalAliasesAndUsings(basesBeingResolved).Imports; } private ImmutableDictionary GetGlobalUsingAliasesMap(ConsList? basesBeingResolved) { return GetMergedGlobalAliasesAndUsings(basesBeingResolved).UsingAliasesMap; } private ImmutableArray GetGlobalUsingNamespacesOrTypes(ConsList? basesBeingResolved) { return GetMergedGlobalAliasesAndUsings(basesBeingResolved).UsingNamespacesOrTypes; } private MergedGlobalAliasesAndUsings GetMergedGlobalAliasesAndUsings(ConsList? basesBeingResolved, CancellationToken cancellationToken = default(CancellationToken)) { if (_lazyMergedGlobalAliasesAndUsings == null) { if (!IsGlobalNamespace) { _lazyMergedGlobalAliasesAndUsings = MergedGlobalAliasesAndUsings.Empty; } else { ImmutableDictionary immutableDictionary = null; ArrayBuilder val = ArrayBuilder.GetInstance(); PooledHashSet pooledSymbolHashSetInstance = SpecializedSymbolCollections.GetPooledSymbolHashSetInstance(); DiagnosticBag val2 = DiagnosticBag.GetInstance(); try { bool flag = false; ImmutableArray.Enumerator enumerator = _mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { SingleNamespaceDeclaration current = enumerator.Current; if (current.HasExternAliases) { flag = true; } if (!current.HasGlobalUsings) { continue; } ImmutableDictionary globalUsingAliasesMap = GetAliasesAndUsings(current).GetGlobalUsingAliasesMap(this, current.SyntaxReference, basesBeingResolved); cancellationToken.ThrowIfCancellationRequested(); if (!globalUsingAliasesMap.IsEmpty) { if (immutableDictionary == null) { immutableDictionary = globalUsingAliasesMap; } else { ImmutableDictionary.Builder builder = immutableDictionary.ToBuilder(); bool flag2 = false; foreach (KeyValuePair item in globalUsingAliasesMap) { if (builder.ContainsKey(item.Key)) { val2.Add(ErrorCode.ERR_DuplicateAlias, item.Value.Alias.GetFirstLocation(), item.Key); } else { builder.Add(item); flag2 = true; } } if (flag2) { immutableDictionary = builder.ToImmutable(); } cancellationToken.ThrowIfCancellationRequested(); } } ImmutableArray globalUsingNamespacesOrTypes = GetAliasesAndUsings(current).GetGlobalUsingNamespacesOrTypes(this, current.SyntaxReference, basesBeingResolved); if (!globalUsingNamespacesOrTypes.IsEmpty) { if (val.Count == 0) { val.AddRange(globalUsingNamespacesOrTypes); ISetExtensions.AddAll((ISet)pooledSymbolHashSetInstance, globalUsingNamespacesOrTypes.Select((NamespaceOrTypeAndUsingDirective n) => n.NamespaceOrType)); } else { ImmutableArray.Enumerator enumerator3 = globalUsingNamespacesOrTypes.GetEnumerator(); while (enumerator3.MoveNext()) { NamespaceOrTypeAndUsingDirective current3 = enumerator3.Current; if (!((HashSet)(object)pooledSymbolHashSetInstance).Add(current3.NamespaceOrType)) { val2.Add(ErrorCode.HDN_DuplicateWithGlobalUsing, ((SyntaxNode)current3.UsingDirective.NamespaceOrType).Location, current3.NamespaceOrType); } else { val.Add(current3); } } } } cancellationToken.ThrowIfCancellationRequested(); } if (flag && immutableDictionary != null) { enumerator = _mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { SingleNamespaceDeclaration current4 = enumerator.Current; if (!current4.HasExternAliases) { continue; } ImmutableArray externAliases = GetAliasesAndUsings(current4).GetExternAliases(this, current4.SyntaxReference); ImmutableDictionary immutableDictionary2 = ImmutableDictionary.Empty; if (current4.HasGlobalUsings) { immutableDictionary2 = GetAliasesAndUsings(current4).GetGlobalUsingAliasesMap(this, current4.SyntaxReference, basesBeingResolved); } ImmutableArray.Enumerator enumerator4 = externAliases.GetEnumerator(); while (enumerator4.MoveNext()) { AliasAndExternAliasDirective current5 = enumerator4.Current; if (!current5.SkipInLookup && !immutableDictionary2.ContainsKey(current5.Alias.Name) && immutableDictionary.ContainsKey(current5.Alias.Name)) { val2.Add(ErrorCode.ERR_DuplicateAlias, current5.Alias.GetFirstLocation(), current5.Alias.Name); } } } } Interlocked.CompareExchange(ref _lazyMergedGlobalAliasesAndUsings, new MergedGlobalAliasesAndUsings { UsingAliasesMap = (immutableDictionary ?? ImmutableDictionary.Empty), UsingNamespacesOrTypes = val.ToImmutableAndFree(), Diagnostics = val2.ToReadOnlyAndFree() }, null); val = null; val2 = null; } finally { pooledSymbolHashSetInstance.Free(); val?.Free(); if (val2 != null) { val2.Free(); } } } } return _lazyMergedGlobalAliasesAndUsings; } internal SourceNamespaceSymbol(SourceModuleSymbol module, Symbol container, MergedNamespaceDeclaration mergedDeclaration, BindingDiagnosticBag diagnostics) { _module = module; _container = container; _mergedDeclaration = mergedDeclaration; ImmutableArray.Enumerator enumerator = mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { SingleNamespaceDeclaration current = enumerator.Current; ((BindingDiagnosticBag)diagnostics).AddRange(current.Diagnostics); } } internal override LexicalSortKey GetLexicalSortKey() { if (!_lazyLexicalSortKey.IsInitialized) { _lazyLexicalSortKey.SetFrom(_mergedDeclaration.GetLexicalSortKey(DeclaringCompilation)); } return _lazyLexicalSortKey; } public override Location TryGetFirstLocation() { return (Location)(object)_mergedDeclaration.Declarations[0].NameLocation; } public override bool HasLocationContainedWithin(SyntaxTree tree, TextSpan declarationSpan, out bool wasZeroWidthMatch) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) ImmutableArray.Enumerator enumerator = _mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { if (Symbol.IsLocationContainedWithin((Location)(object)enumerator.Current.NameLocation, tree, declarationSpan, out wasZeroWidthMatch)) { return true; } } wasZeroWidthMatch = false; return false; } private ImmutableArray ComputeDeclaringReferencesCore() { return ImmutableArrayExtensions.SelectAsArray(_mergedDeclaration.Declarations, s_declaringSyntaxReferencesSelector); } internal override ImmutableArray GetMembersUnordered() { ImmutableArray lazyAllMembers = _lazyAllMembers; if (lazyAllMembers.IsDefault) { ImmutableArray value = StaticCast.From(ImmutableArrayExtensions.Flatten, NamespaceOrTypeSymbol>(GetNameToMembersMap(), (IComparer)null)); ImmutableInterlocked.InterlockedInitialize(ref _lazyAllMembers, value); lazyAllMembers = _lazyAllMembers; } return ImmutableArrayExtensions.ConditionallyDeOrder(lazyAllMembers); } public override ImmutableArray GetMembers() { if ((_flags & 1) != 0) { return _lazyAllMembers; } ImmutableArray immutableArray = GetMembersUnordered(); if (immutableArray.Length >= 2) { immutableArray = immutableArray.Sort(LexicalOrderSymbolComparer.Instance); ImmutableInterlocked.InterlockedExchange(ref _lazyAllMembers, immutableArray); } ThreadSafeFlagOperations.Set(ref _flags, 1); return immutableArray; } public override ImmutableArray GetMembers(ReadOnlyMemory name) { if (!GetNameToMembersMap().TryGetValue(name, out var value)) { return ImmutableArray.Empty; } return ImmutableArrayExtensions.Cast(value); } internal override ImmutableArray GetTypeMembersUnordered() { if (_lazyTypeMembersUnordered.IsDefault) { ImmutableArray value = ImmutableArrayExtensions.Flatten, NamedTypeSymbol>(GetNameToTypeMembersMap(), (IComparer)null); ImmutableInterlocked.InterlockedInitialize(ref _lazyTypeMembersUnordered, value); } return _lazyTypeMembersUnordered; } public override ImmutableArray GetTypeMembers() { return ImmutableArrayExtensions.Flatten, NamedTypeSymbol>(GetNameToTypeMembersMap(), (IComparer)LexicalOrderSymbolComparer.Instance); } public override ImmutableArray GetTypeMembers(ReadOnlyMemory name) { if (!GetNameToTypeMembersMap().TryGetValue(name, out var value)) { return ImmutableArray.Empty; } return value; } public override ImmutableArray GetTypeMembers(ReadOnlyMemory name, int arity) { return ImmutableArrayExtensions.WhereAsArray(GetTypeMembers(name), (Func)((NamedTypeSymbol s, int num) => s.Arity == num), arity); } private Dictionary, ImmutableArray> GetNameToMembersMap() { if (_nameToMembersMap == null) { BindingDiagnosticBag instance = BindingDiagnosticBag.GetInstance(); if (Interlocked.CompareExchange(ref _nameToMembersMap, MakeNameToMembersMap(instance), null) == null) { AddDeclarationDiagnostics(instance); RegisterDeclaredCorTypes(); DeclaringCompilation.SymbolDeclaredEvent(this); _state.NotePartComplete(CompletionPart.Members); } ((BindingDiagnosticBag)(object)instance).Free(); } return _nameToMembersMap; } private Dictionary, ImmutableArray> GetNameToTypeMembersMap() { if (_nameToTypeMembersMap == null) { Interlocked.CompareExchange(ref _nameToTypeMembersMap, ImmutableArrayExtensions.GetTypesFromMemberMap, NamespaceOrTypeSymbol, NamedTypeSymbol>(GetNameToMembersMap(), (IEqualityComparer>)ReadOnlyMemoryOfCharComparer.Instance), null); } return _nameToTypeMembersMap; } private Dictionary, ImmutableArray> MakeNameToMembersMap(BindingDiagnosticBag diagnostics) { PooledDictionary, object> val = NamespaceOrTypeSymbol.s_nameToObjectPool.Allocate(); ImmutableArray.Enumerator enumerator = _mergedDeclaration.Children.GetEnumerator(); while (enumerator.MoveNext()) { MergedNamespaceOrTypeDeclaration current = enumerator.Current; NamespaceOrTypeSymbol namespaceOrTypeSymbol = BuildSymbol(current, diagnostics); ImmutableArrayExtensions.AddToMultiValueDictionaryBuilder, NamespaceOrTypeSymbol>((Dictionary, object>)(object)val, namespaceOrTypeSymbol.Name.AsMemory(), namespaceOrTypeSymbol); } Dictionary, ImmutableArray> dictionary = new Dictionary, ImmutableArray>(((Dictionary, object>)(object)val).Count, (IEqualityComparer>?)ReadOnlyMemoryOfCharComparer.Instance); ImmutableArrayExtensions.CreateNameToMembersMap, NamespaceOrTypeSymbol, NamedTypeSymbol, NamespaceSymbol>((Dictionary, object>)(object)val, dictionary); val.Free(); CheckMembers(this, dictionary, diagnostics); return dictionary; } private static void CheckMembers(NamespaceSymbol @namespace, Dictionary, ImmutableArray> result, BindingDiagnosticBag diagnostics) { //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Invalid comparison between Unknown and I4 //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Invalid comparison between Unknown and I4 Symbol[] array = new Symbol[10]; MergedNamespaceSymbol mergedNamespaceSymbol = null; if (@namespace.ContainingAssembly.Modules.Length > 1) { mergedNamespaceSymbol = @namespace.ContainingAssembly.GetAssemblyNamespace(@namespace) as MergedNamespaceSymbol; } foreach (ReadOnlyMemory key in result.Keys) { Array.Clear(array, 0, array.Length); ImmutableArray.Enumerator enumerator2 = result[key].GetEnumerator(); while (enumerator2.MoveNext()) { NamespaceOrTypeSymbol current2 = enumerator2.Current; SourceMemberContainerTypeSymbol sourceMemberContainerTypeSymbol = current2 as SourceMemberContainerTypeSymbol; int num = sourceMemberContainerTypeSymbol?.Arity ?? 0; if (num >= array.Length) { Array.Resize(ref array, num + 1); } Symbol symbol = array[num]; if ((object)symbol == null && (object)mergedNamespaceSymbol != null) { ImmutableArray.Enumerator enumerator3 = mergedNamespaceSymbol.ConstituentNamespaces.GetEnumerator(); while (enumerator3.MoveNext()) { NamespaceSymbol current3 = enumerator3.Current; if ((object)current3 != @namespace) { ImmutableArray typeMembers = current3.GetTypeMembers(current2.Name, num); if (typeMembers.Length > 0) { symbol = typeMembers[0]; break; } } } } SourceMemberContainerTypeSymbol sourceMemberContainerTypeSymbol2; if ((object)symbol != null) { (SourceMemberContainerTypeSymbol, Symbol) tuple = (sourceMemberContainerTypeSymbol, symbol); (sourceMemberContainerTypeSymbol2, _) = tuple; Symbol item; if ((object)sourceMemberContainerTypeSymbol2 == null) { item = tuple.Item2; if (item is SourceMemberContainerTypeSymbol { IsFileLocal: not false }) { goto IL_01fd; } goto IL_0246; } item = tuple.Item2; SourceMemberContainerTypeSymbol sourceMemberContainerTypeSymbol4 = item as SourceMemberContainerTypeSymbol; NamespaceOrTypeSymbol namespaceOrTypeSymbol; int num2; if ((object)sourceMemberContainerTypeSymbol4 != null) { SourceMemberContainerTypeSymbol otherSymbol = sourceMemberContainerTypeSymbol2; if (isFileLocalTypeInSeparateFileFrom(sourceMemberContainerTypeSymbol4, otherSymbol)) { goto IL_026a; } namespaceOrTypeSymbol = (NamespaceOrTypeSymbol)item; num2 = 1; } else { namespaceOrTypeSymbol = item as NamespaceOrTypeSymbol; if ((object)namespaceOrTypeSymbol == null) { goto IL_018b; } num2 = 2; } NamespaceOrTypeSymbol otherSymbol2 = namespaceOrTypeSymbol; if (!isFileLocalTypeInSeparateFileFrom(sourceMemberContainerTypeSymbol2, otherSymbol2)) { if (num2 == 1) { if (sourceMemberContainerTypeSymbol2.IsFileLocal || sourceMemberContainerTypeSymbol4.IsFileLocal) { goto IL_01fd; } if (!sourceMemberContainerTypeSymbol2.IsPartial || !sourceMemberContainerTypeSymbol4.IsPartial) { goto IL_0246; } diagnostics.Add(ErrorCode.ERR_PartialTypeKindConflict, current2.GetFirstLocationOrNone(), current2); } else if (num2 == 2) { goto IL_018b; } } } goto IL_026a; IL_018b: if (sourceMemberContainerTypeSymbol2.IsFileLocal) { goto IL_01fd; } goto IL_0246; IL_026a: array[num] = current2; if ((object)sourceMemberContainerTypeSymbol != null) { Accessibility declaredAccessibility = sourceMemberContainerTypeSymbol.DeclaredAccessibility; if ((int)declaredAccessibility != 6 && (int)declaredAccessibility != 4) { diagnostics.Add(ErrorCode.ERR_NoNamespacePrivate, current2.GetFirstLocationOrNone()); } } continue; IL_01fd: diagnostics.Add(ErrorCode.ERR_FileLocalDuplicateNameInNS, current2.GetFirstLocationOrNone(), current2.Name, @namespace); goto IL_026a; IL_0246: diagnostics.Add(ErrorCode.ERR_DuplicateNameInNS, current2.GetFirstLocationOrNone(), current2.Name, @namespace); goto IL_026a; } } static bool isFileLocalTypeInSeparateFileFrom(SourceMemberContainerTypeSymbol possibleFileLocalType, NamespaceOrTypeSymbol namespaceOrTypeSymbol2) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if (!possibleFileLocalType.IsFileLocal) { return false; } SyntaxTree sourceTree = ((Location)possibleFileLocalType.MergedDeclaration.Declarations[0].Location).SourceTree; if (namespaceOrTypeSymbol2 is SourceNamedTypeSymbol sourceNamedTypeSymbol) { MergedTypeDeclaration mergedDeclaration = sourceNamedTypeSymbol.MergedDeclaration; if (mergedDeclaration != null) { return !mergedDeclaration.NameLocations.Any((Func)((SourceLocation loc, SyntaxTree leftTree) => ((Location)loc).SourceTree == leftTree), sourceTree); } } if (namespaceOrTypeSymbol2 is SourceNamespaceSymbol { MergedDeclaration: { NameLocations: var nameLocations } }) { return !ImmutableArrayExtensions.Any(nameLocations, (Func)((Location loc, SyntaxTree leftTree) => loc.SourceTree == leftTree), sourceTree); } throw ExceptionUtilities.UnexpectedValue((object)namespaceOrTypeSymbol2); } } private NamespaceOrTypeSymbol BuildSymbol(MergedNamespaceOrTypeDeclaration declaration, BindingDiagnosticBag diagnostics) { switch (declaration.Kind) { case DeclarationKind.Namespace: return new SourceNamespaceSymbol(_module, this, (MergedNamespaceDeclaration)declaration, diagnostics); case DeclarationKind.Class: case DeclarationKind.Interface: case DeclarationKind.Struct: case DeclarationKind.Enum: case DeclarationKind.Delegate: case DeclarationKind.Record: case DeclarationKind.RecordStruct: return new SourceNamedTypeSymbol(this, (MergedTypeDeclaration)declaration, diagnostics); case DeclarationKind.Script: case DeclarationKind.Submission: case DeclarationKind.ImplicitClass: return new ImplicitNamedTypeSymbol(this, (MergedTypeDeclaration)declaration, diagnostics); default: throw ExceptionUtilities.UnexpectedValue((object)declaration.Kind); } } private void RegisterDeclaredCorTypes() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) AssemblySymbol containingAssembly = ContainingAssembly; if (!containingAssembly.KeepLookingForDeclaredSpecialTypes) { return; } foreach (ImmutableArray value in _nameToMembersMap.Values) { ImmutableArray.Enumerator enumerator2 = value.GetEnumerator(); while (enumerator2.MoveNext()) { if (enumerator2.Current is NamedTypeSymbol namedTypeSymbol && (int)namedTypeSymbol.SpecialType != 0) { containingAssembly.RegisterDeclaredSpecialType(namedTypeSymbol); if (!containingAssembly.KeepLookingForDeclaredSpecialTypes) { return; } } } } } public override bool IsDefinedInSourceTree(SyntaxTree tree, TextSpan? definedWithinSpan, CancellationToken cancellationToken = default(CancellationToken)) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) if (IsGlobalNamespace) { return true; } ImmutableArray.Enumerator enumerator = _mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { SingleNamespaceDeclaration current = enumerator.Current; cancellationToken.ThrowIfCancellationRequested(); SyntaxReference syntaxReference = current.SyntaxReference; if (syntaxReference.SyntaxTree == tree) { if (!definedWithinSpan.HasValue) { return true; } TextSpan fullSpan = NamespaceDeclarationSyntaxReference.GetSyntax(syntaxReference, cancellationToken).FullSpan; if (((TextSpan)(ref fullSpan)).IntersectsWith(definedWithinSpan.Value)) { return true; } } } return false; } internal override void ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken) { while (true) { cancellationToken.ThrowIfCancellationRequested(); CompletionPart nextIncompletePart = _state.NextIncompletePart; switch (nextIncompletePart) { case CompletionPart.Members: GetNameToMembersMap(); break; case CompletionPart.MembersCompleted: { SingleNamespaceDeclaration singleNamespaceDeclaration = null; ImmutableArray.Enumerator enumerator = _mergedDeclaration.Declarations.GetEnumerator(); while (enumerator.MoveNext()) { SingleNamespaceDeclaration current = enumerator.Current; if (((Location)(object)locationOpt == (Location)null || ((Location)locationOpt).SourceTree == current.SyntaxReference.SyntaxTree) && (current.HasGlobalUsings || current.HasUsings || current.HasExternAliases)) { singleNamespaceDeclaration = current; GetAliasesAndUsings(current).Complete(this, current.SyntaxReference, cancellationToken); } } if (IsGlobalNamespace && (locationOpt == null || singleNamespaceDeclaration != null)) { GetMergedGlobalAliasesAndUsings(null, cancellationToken).Complete(this, cancellationToken); } ImmutableArray members = GetMembers(); bool flag = true; if (((CompilationOptions)DeclaringCompilation.Options).ConcurrentBuild) { RoslynParallel.For(0, members.Length, UICultureUtilities.WithCurrentUICulture((Action)delegate(int i) { Symbol.ForceCompleteMemberByLocation(locationOpt, members[i], cancellationToken); }), cancellationToken); ImmutableArray.Enumerator enumerator2 = members.GetEnumerator(); while (enumerator2.MoveNext()) { if (!enumerator2.Current.HasComplete(CompletionPart.All)) { flag = false; break; } } } else { ImmutableArray.Enumerator enumerator2 = members.GetEnumerator(); while (enumerator2.MoveNext()) { Symbol current2 = enumerator2.Current; Symbol.ForceCompleteMemberByLocation(locationOpt, current2, cancellationToken); flag = flag && current2.HasComplete(CompletionPart.All); } } if (flag) { _state.NotePartComplete(CompletionPart.MembersCompleted); break; } CompletionPart part = (((Location)(object)locationOpt == (Location)null) ? CompletionPart.NamespaceSymbolAll : CompletionPart.Members); _state.SpinWaitComplete(part, cancellationToken); return; } case CompletionPart.None: return; default: _state.NotePartComplete(CompletionPart.PropertySymbolAll | CompletionPart.ReturnTypeAttributes | CompletionPart.Parameters | CompletionPart.Type | CompletionPart.TypeParameters | CompletionPart.TypeMembers | CompletionPart.SynthesizedExplicitImplementations | CompletionPart.StartMemberChecks | CompletionPart.FinishMemberChecks | CompletionPart.MembersCompletedChecksStarted); break; } _state.SpinWaitComplete(nextIncompletePart, cancellationToken); } } internal override bool HasComplete(CompletionPart part) { return _state.HasComplete(part); } }