1566 lines
69 KiB
C#
1566 lines
69 KiB
C#
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<AliasAndExternAliasDirective>.Empty,
|
|
Diagnostics = ImmutableArray<Diagnostic>.Empty
|
|
};
|
|
|
|
public ImmutableArray<AliasAndExternAliasDirective> ExternAliases { get; init; }
|
|
|
|
public ImmutableArray<Diagnostic> Diagnostics { get; init; }
|
|
}
|
|
|
|
private class UsingsAndDiagnostics
|
|
{
|
|
public static readonly UsingsAndDiagnostics Empty = new UsingsAndDiagnostics
|
|
{
|
|
UsingAliases = ImmutableArray<AliasAndUsingDirective>.Empty,
|
|
UsingAliasesMap = null,
|
|
UsingNamespacesOrTypes = ImmutableArray<NamespaceOrTypeAndUsingDirective>.Empty,
|
|
Diagnostics = null
|
|
};
|
|
|
|
public ImmutableArray<AliasAndUsingDirective> UsingAliases { get; init; }
|
|
|
|
public ImmutableDictionary<string, AliasAndUsingDirective>? UsingAliasesMap { get; init; }
|
|
|
|
public ImmutableArray<NamespaceOrTypeAndUsingDirective> 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<AliasAndExternAliasDirective> GetExternAliases(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax)
|
|
{
|
|
return GetExternAliasesAndDiagnostics(declaringSymbol, declarationSyntax).ExternAliases;
|
|
}
|
|
|
|
internal ImmutableArray<AliasAndExternAliasDirective> 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<ExternAliasDirectiveSyntax> 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<AliasAndExternAliasDirective> buildExternAliases(SyntaxList<ExternAliasDirectiveSyntax> 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<AliasAndExternAliasDirective> instance2 = ArrayBuilder<AliasAndExternAliasDirective>.GetInstance();
|
|
Enumerator<ExternAliasDirectiveSyntax> 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<AliasAndExternAliasDirective> 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<AliasAndUsingDirective> GetUsingAliases(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingAliases;
|
|
}
|
|
|
|
internal ImmutableArray<AliasAndUsingDirective> GetGlobalUsingAliases(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetGlobalUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingAliases;
|
|
}
|
|
|
|
internal ImmutableDictionary<string, AliasAndUsingDirective> GetUsingAliasesMap(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingAliasesMap ?? ImmutableDictionary<string, AliasAndUsingDirective>.Empty;
|
|
}
|
|
|
|
internal ImmutableDictionary<string, AliasAndUsingDirective> GetGlobalUsingAliasesMap(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return (_lazyGlobalUsings ?? GetGlobalUsingsAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(default(CancellationToken)), basesBeingResolved)).UsingAliasesMap ?? ImmutableDictionary<string, AliasAndUsingDirective>.Empty;
|
|
}
|
|
|
|
internal ImmutableArray<NamespaceOrTypeAndUsingDirective> GetUsingNamespacesOrTypes(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetUsingsAndDiagnostics(declaringSymbol, declarationSyntax, basesBeingResolved).UsingNamespacesOrTypes;
|
|
}
|
|
|
|
private UsingsAndDiagnostics GetUsingsAndDiagnostics(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetUsingsAndDiagnostics(ref _lazyUsings, declaringSymbol, declarationSyntax, basesBeingResolved, onlyGlobal: false);
|
|
}
|
|
|
|
internal ImmutableArray<NamespaceOrTypeAndUsingDirective> GetGlobalUsingNamespacesOrTypes(SourceNamespaceSymbol declaringSymbol, SyntaxReference declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return (_lazyGlobalUsings ?? GetGlobalUsingsAndDiagnostics(declaringSymbol, (CSharpSyntaxNode)(object)declarationSyntax.GetSyntax(default(CancellationToken)), basesBeingResolved)).UsingNamespacesOrTypes;
|
|
}
|
|
|
|
private UsingsAndDiagnostics GetGlobalUsingsAndDiagnostics(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetUsingsAndDiagnostics(ref _lazyGlobalUsings, declaringSymbol, declarationSyntax, basesBeingResolved, onlyGlobal: true);
|
|
}
|
|
|
|
private UsingsAndDiagnostics GetUsingsAndDiagnostics(ref UsingsAndDiagnostics? usings, SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? 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<UsingDirectiveSyntax> 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<UsingDirectiveSyntax> usingDirectives, SourceNamespaceSymbol sourceNamespaceSymbol, CSharpSyntaxNode cSharpSyntaxNode, bool? applyIsGlobalFilter, ConsList<TypeSymbol>? 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<AliasAndExternAliasDirective> externAliases = GetExternAliases(sourceNamespaceSymbol, cSharpSyntaxNode);
|
|
ImmutableDictionary<string, AliasAndUsingDirective> immutableDictionary = ImmutableDictionary<string, AliasAndUsingDirective>.Empty;
|
|
ImmutableArray<NamespaceOrTypeAndUsingDirective> immutableArray = ImmutableArray<NamespaceOrTypeAndUsingDirective>.Empty;
|
|
ImmutableArray<AliasAndUsingDirective> immutableArray2 = ImmutableArray<AliasAndUsingDirective>.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<NamespaceOrTypeAndUsingDirective> usings3 = null;
|
|
ImmutableDictionary<string, AliasAndUsingDirective>.Builder builder = null;
|
|
ArrayBuilder<AliasAndUsingDirective> val2 = null;
|
|
Binder binder = null;
|
|
PooledHashSet<NamespaceOrTypeSymbol> uniqueUsings = null;
|
|
PooledHashSet<NamespaceOrTypeSymbol> uniqueUsings2 = null;
|
|
Enumerator<UsingDirectiveSyntax> 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<AliasAndExternAliasDirective>.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<AliasAndUsingDirective>.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<NamespaceOrTypeSymbol>)(object)getOrCreateUniqueUsings(ref uniqueUsings, immutableArray)).Add(namespaceOrTypeSymbol))
|
|
{
|
|
val.Add((!immutableArray.IsEmpty && ((HashSet<NamespaceOrTypeSymbol>)(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<AssemblySymbol>)));
|
|
}
|
|
}
|
|
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<NamespaceOrTypeSymbol>)(object)getOrCreateUniqueUsings(ref uniqueUsings, immutableArray)).Add((NamespaceOrTypeSymbol)namedTypeSymbol))
|
|
{
|
|
val.Add((!immutableArray.IsEmpty && ((HashSet<NamespaceOrTypeSymbol>)(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<AssemblySymbol>)(object)instance).DependenciesBag.ToImmutableArray()));
|
|
}
|
|
}
|
|
}
|
|
goto IL_05ec;
|
|
IL_05ec:
|
|
if (flag3)
|
|
{
|
|
val.AddRange(((BindingDiagnosticBag)instance).DiagnosticBag);
|
|
}
|
|
((BindingDiagnosticBag<AssemblySymbol>)(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<NamespaceOrTypeSymbol> getOrCreateUniqueGlobalUsingsNotInTree(ref PooledHashSet<NamespaceOrTypeSymbol>? uniqueUsings, ImmutableArray<NamespaceOrTypeAndUsingDirective> globalUsingNamespacesOrTypes, SyntaxTree tree)
|
|
{
|
|
if (uniqueUsings == null)
|
|
{
|
|
uniqueUsings = SpecializedSymbolCollections.GetPooledSymbolHashSetInstance<NamespaceOrTypeSymbol>();
|
|
ISetExtensions.AddAll<NamespaceOrTypeSymbol>((ISet<NamespaceOrTypeSymbol>)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<NamespaceOrTypeSymbol> getOrCreateUniqueUsings(ref PooledHashSet<NamespaceOrTypeSymbol>? uniqueUsings, ImmutableArray<NamespaceOrTypeAndUsingDirective> globalUsingNamespacesOrTypes)
|
|
{
|
|
if (uniqueUsings == null)
|
|
{
|
|
uniqueUsings = SpecializedSymbolCollections.GetPooledSymbolHashSetInstance<NamespaceOrTypeSymbol>();
|
|
ISetExtensions.AddAll<NamespaceOrTypeSymbol>((ISet<NamespaceOrTypeSymbol>)uniqueUsings, globalUsingNamespacesOrTypes.Select((NamespaceOrTypeAndUsingDirective n) => n.NamespaceOrType));
|
|
}
|
|
return uniqueUsings;
|
|
}
|
|
static ArrayBuilder<NamespaceOrTypeAndUsingDirective> getOrCreateUsingsBuilder(ref ArrayBuilder<NamespaceOrTypeAndUsingDirective>? reference, ImmutableArray<NamespaceOrTypeAndUsingDirective> globalUsingNamespacesOrTypes)
|
|
{
|
|
if (reference == null)
|
|
{
|
|
reference = ArrayBuilder<NamespaceOrTypeAndUsingDirective>.GetInstance();
|
|
reference.AddRange(globalUsingNamespacesOrTypes);
|
|
}
|
|
return reference;
|
|
}
|
|
}
|
|
|
|
internal Imports GetImports(SourceNamespaceSymbol declaringSymbol, CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? 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<string, AliasAndUsingDirective> item in usingsAndDiagnostics.UsingAliasesMap)
|
|
{
|
|
KeyValuePairUtil.Deconstruct<string, AliasAndUsingDirective>(item, ref text, ref aliasAndUsingDirective);
|
|
AliasAndUsingDirective aliasAndUsingDirective2 = aliasAndUsingDirective;
|
|
if (aliasAndUsingDirective2.UsingDirectiveReference.SyntaxTree == declarationSyntax.SyntaxTree)
|
|
{
|
|
NamespaceOrTypeSymbol aliasTarget = aliasAndUsingDirective2.Alias.GetAliasTarget(null);
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).Clear();
|
|
if (aliasAndUsingDirective2.Alias is AliasSymbolFromSyntax aliasSymbolFromSyntax)
|
|
{
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).AddRange((BindingDiagnosticBag<AssemblySymbol>)(object)aliasSymbolFromSyntax.AliasTargetDiagnostics, false);
|
|
}
|
|
aliasAndUsingDirective2.Alias.CheckConstraints(diagnostics);
|
|
declarationDiagnostics.AddRange(((BindingDiagnosticBag)diagnostics).DiagnosticBag);
|
|
recordImportDependencies(aliasAndUsingDirective2.UsingDirective, aliasTarget);
|
|
}
|
|
}
|
|
}
|
|
TypeConversions typeConversions = compilation.SourceAssembly.CorLibrary.TypeConversions;
|
|
ImmutableArray<NamespaceOrTypeAndUsingDirective>.Enumerator enumerator2 = usingsAndDiagnostics.UsingNamespacesOrTypes.GetEnumerator();
|
|
while (enumerator2.MoveNext())
|
|
{
|
|
NamespaceOrTypeAndUsingDirective current = enumerator2.Current;
|
|
if (current.UsingDirectiveReference.SyntaxTree == declarationSyntax.SyntaxTree)
|
|
{
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).Clear();
|
|
((BindingDiagnosticBag<AssemblySymbol>)(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<AliasAndExternAliasDirective>.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<AssemblySymbol>)(object)diagnostics).Clear();
|
|
diagnostics.AddAssembliesUsedByNamespaceReference(ns);
|
|
compilation.AddUsedAssemblies(((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).DependenciesBag);
|
|
}
|
|
}
|
|
}
|
|
declarationDiagnostics.AddRange<Diagnostic>(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<AssemblySymbol>)(object)diagnostics).Free();
|
|
void recordImportDependencies(UsingDirectiveSyntax usingDirectiveSyntax, NamespaceOrTypeSymbol target)
|
|
{
|
|
if (Compilation.ReportUnusedImportsInTree(usingDirectiveSyntax.SyntaxTree))
|
|
{
|
|
compilation.RecordImportDependencies(usingDirectiveSyntax, ((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).DependenciesBag.ToImmutableArray());
|
|
}
|
|
else
|
|
{
|
|
if (target.IsNamespace)
|
|
{
|
|
diagnostics.AddAssembliesUsedByNamespaceReference((NamespaceSymbol)target);
|
|
}
|
|
compilation.AddUsedAssemblies(((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).DependenciesBag);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private class MergedGlobalAliasesAndUsings
|
|
{
|
|
private Imports? _lazyImports;
|
|
|
|
private SymbolCompletionState _state;
|
|
|
|
public static readonly MergedGlobalAliasesAndUsings Empty = new MergedGlobalAliasesAndUsings
|
|
{
|
|
UsingAliasesMap = ImmutableDictionary<string, AliasAndUsingDirective>.Empty,
|
|
UsingNamespacesOrTypes = ImmutableArray<NamespaceOrTypeAndUsingDirective>.Empty,
|
|
Diagnostics = ImmutableArray<Diagnostic>.Empty,
|
|
_lazyImports = Microsoft.CodeAnalysis.CSharp.Imports.Empty
|
|
};
|
|
|
|
public ImmutableDictionary<string, AliasAndUsingDirective>? UsingAliasesMap { get; init; }
|
|
|
|
public ImmutableArray<NamespaceOrTypeAndUsingDirective> UsingNamespacesOrTypes { get; init; }
|
|
|
|
public ImmutableArray<Diagnostic> Diagnostics { get; init; }
|
|
|
|
public Imports Imports
|
|
{
|
|
get
|
|
{
|
|
if (_lazyImports == null)
|
|
{
|
|
Interlocked.CompareExchange(ref _lazyImports, Microsoft.CodeAnalysis.CSharp.Imports.Create(UsingAliasesMap ?? ImmutableDictionary<string, AliasAndUsingDirective>.Empty, UsingNamespacesOrTypes, ImmutableArray<AliasAndExternAliasDirective>.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<Diagnostic>(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<SingleNamespaceDeclaration, AliasesAndUsings> s_emptyMap = ImmutableDictionary<SingleNamespaceDeclaration, AliasesAndUsings>.Empty.WithComparers((IEqualityComparer<SingleNamespaceDeclaration>?)ReferenceEqualityComparer.Instance);
|
|
|
|
private readonly SourceModuleSymbol _module;
|
|
|
|
private readonly Symbol _container;
|
|
|
|
private readonly MergedNamespaceDeclaration _mergedDeclaration;
|
|
|
|
private SymbolCompletionState _state;
|
|
|
|
private ImmutableArray<Location> _locations;
|
|
|
|
private Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamespaceOrTypeSymbol>> _nameToMembersMap;
|
|
|
|
private Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamedTypeSymbol>> _nameToTypeMembersMap;
|
|
|
|
private ImmutableArray<Symbol> _lazyAllMembers;
|
|
|
|
private ImmutableArray<NamedTypeSymbol> _lazyTypeMembersUnordered;
|
|
|
|
private ImmutableDictionary<SingleNamespaceDeclaration, AliasesAndUsings> _aliasesAndUsings_doNotAccessDirectly = s_emptyMap;
|
|
|
|
private MergedGlobalAliasesAndUsings _lazyMergedGlobalAliasesAndUsings;
|
|
|
|
private const int LazyAllMembersIsSorted = 1;
|
|
|
|
private int _flags;
|
|
|
|
private LexicalSortKey _lazyLexicalSortKey = LexicalSortKey.NotInitialized;
|
|
|
|
private static readonly Func<SingleNamespaceDeclaration, SyntaxReference> 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<Location> Locations
|
|
{
|
|
get
|
|
{
|
|
if (_locations.IsDefault)
|
|
{
|
|
ImmutableInterlocked.InterlockedCompareExchange(ref _locations, _mergedDeclaration.NameLocations, default(ImmutableArray<Location>));
|
|
}
|
|
return _locations;
|
|
}
|
|
}
|
|
|
|
public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences => ComputeDeclaringReferencesCore();
|
|
|
|
internal override ModuleSymbol ContainingModule => _module;
|
|
|
|
internal override NamespaceExtent Extent => new NamespaceExtent(_module);
|
|
|
|
public Imports GetImports(CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? 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<SingleNamespaceDeclaration>.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<SingleNamespaceDeclaration, AliasesAndUsings> 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<AliasAndExternAliasDirective> 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<AliasAndExternAliasDirective>.Empty;
|
|
}
|
|
}
|
|
else if (!compilationUnitSyntax.Externs.Any())
|
|
{
|
|
return ImmutableArray<AliasAndExternAliasDirective>.Empty;
|
|
}
|
|
return GetAliasesAndUsings(declarationSyntax).GetExternAliases(this, declarationSyntax);
|
|
}
|
|
|
|
public ImmutableArray<AliasAndUsingDirective> GetUsingAliases(CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? 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<AliasAndUsingDirective>.Empty;
|
|
}
|
|
}
|
|
else if (!compilationUnitSyntax.Usings.Any())
|
|
{
|
|
return ImmutableArray<AliasAndUsingDirective>.Empty;
|
|
}
|
|
return GetAliasesAndUsings(declarationSyntax).GetUsingAliases(this, declarationSyntax, basesBeingResolved);
|
|
}
|
|
|
|
public ImmutableDictionary<string, AliasAndUsingDirective> GetUsingAliasesMap(CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? 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<string, AliasAndUsingDirective>.Empty;
|
|
}
|
|
}
|
|
else if (!compilationUnitSyntax.Usings.Any())
|
|
{
|
|
return GetGlobalUsingAliasesMap(basesBeingResolved);
|
|
}
|
|
return GetAliasesAndUsings(declarationSyntax).GetUsingAliasesMap(this, declarationSyntax, basesBeingResolved);
|
|
}
|
|
|
|
public ImmutableArray<NamespaceOrTypeAndUsingDirective> GetUsingNamespacesOrTypes(CSharpSyntaxNode declarationSyntax, ConsList<TypeSymbol>? 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<NamespaceOrTypeAndUsingDirective>.Empty;
|
|
}
|
|
}
|
|
else if (!compilationUnitSyntax.Usings.Any())
|
|
{
|
|
return GetGlobalUsingNamespacesOrTypes(basesBeingResolved);
|
|
}
|
|
return GetAliasesAndUsings(declarationSyntax).GetUsingNamespacesOrTypes(this, declarationSyntax, basesBeingResolved);
|
|
}
|
|
|
|
private Imports GetGlobalUsingImports(ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetMergedGlobalAliasesAndUsings(basesBeingResolved).Imports;
|
|
}
|
|
|
|
private ImmutableDictionary<string, AliasAndUsingDirective> GetGlobalUsingAliasesMap(ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetMergedGlobalAliasesAndUsings(basesBeingResolved).UsingAliasesMap;
|
|
}
|
|
|
|
private ImmutableArray<NamespaceOrTypeAndUsingDirective> GetGlobalUsingNamespacesOrTypes(ConsList<TypeSymbol>? basesBeingResolved)
|
|
{
|
|
return GetMergedGlobalAliasesAndUsings(basesBeingResolved).UsingNamespacesOrTypes;
|
|
}
|
|
|
|
private MergedGlobalAliasesAndUsings GetMergedGlobalAliasesAndUsings(ConsList<TypeSymbol>? basesBeingResolved, CancellationToken cancellationToken = default(CancellationToken))
|
|
{
|
|
if (_lazyMergedGlobalAliasesAndUsings == null)
|
|
{
|
|
if (!IsGlobalNamespace)
|
|
{
|
|
_lazyMergedGlobalAliasesAndUsings = MergedGlobalAliasesAndUsings.Empty;
|
|
}
|
|
else
|
|
{
|
|
ImmutableDictionary<string, AliasAndUsingDirective> immutableDictionary = null;
|
|
ArrayBuilder<NamespaceOrTypeAndUsingDirective> val = ArrayBuilder<NamespaceOrTypeAndUsingDirective>.GetInstance();
|
|
PooledHashSet<NamespaceOrTypeSymbol> pooledSymbolHashSetInstance = SpecializedSymbolCollections.GetPooledSymbolHashSetInstance<NamespaceOrTypeSymbol>();
|
|
DiagnosticBag val2 = DiagnosticBag.GetInstance();
|
|
try
|
|
{
|
|
bool flag = false;
|
|
ImmutableArray<SingleNamespaceDeclaration>.Enumerator enumerator = _mergedDeclaration.Declarations.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
SingleNamespaceDeclaration current = enumerator.Current;
|
|
if (current.HasExternAliases)
|
|
{
|
|
flag = true;
|
|
}
|
|
if (!current.HasGlobalUsings)
|
|
{
|
|
continue;
|
|
}
|
|
ImmutableDictionary<string, AliasAndUsingDirective> globalUsingAliasesMap = GetAliasesAndUsings(current).GetGlobalUsingAliasesMap(this, current.SyntaxReference, basesBeingResolved);
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
if (!globalUsingAliasesMap.IsEmpty)
|
|
{
|
|
if (immutableDictionary == null)
|
|
{
|
|
immutableDictionary = globalUsingAliasesMap;
|
|
}
|
|
else
|
|
{
|
|
ImmutableDictionary<string, AliasAndUsingDirective>.Builder builder = immutableDictionary.ToBuilder();
|
|
bool flag2 = false;
|
|
foreach (KeyValuePair<string, AliasAndUsingDirective> 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<NamespaceOrTypeAndUsingDirective> globalUsingNamespacesOrTypes = GetAliasesAndUsings(current).GetGlobalUsingNamespacesOrTypes(this, current.SyntaxReference, basesBeingResolved);
|
|
if (!globalUsingNamespacesOrTypes.IsEmpty)
|
|
{
|
|
if (val.Count == 0)
|
|
{
|
|
val.AddRange(globalUsingNamespacesOrTypes);
|
|
ISetExtensions.AddAll<NamespaceOrTypeSymbol>((ISet<NamespaceOrTypeSymbol>)pooledSymbolHashSetInstance, globalUsingNamespacesOrTypes.Select((NamespaceOrTypeAndUsingDirective n) => n.NamespaceOrType));
|
|
}
|
|
else
|
|
{
|
|
ImmutableArray<NamespaceOrTypeAndUsingDirective>.Enumerator enumerator3 = globalUsingNamespacesOrTypes.GetEnumerator();
|
|
while (enumerator3.MoveNext())
|
|
{
|
|
NamespaceOrTypeAndUsingDirective current3 = enumerator3.Current;
|
|
if (!((HashSet<NamespaceOrTypeSymbol>)(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<AliasAndExternAliasDirective> externAliases = GetAliasesAndUsings(current4).GetExternAliases(this, current4.SyntaxReference);
|
|
ImmutableDictionary<string, AliasAndUsingDirective> immutableDictionary2 = ImmutableDictionary<string, AliasAndUsingDirective>.Empty;
|
|
if (current4.HasGlobalUsings)
|
|
{
|
|
immutableDictionary2 = GetAliasesAndUsings(current4).GetGlobalUsingAliasesMap(this, current4.SyntaxReference, basesBeingResolved);
|
|
}
|
|
ImmutableArray<AliasAndExternAliasDirective>.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<string, AliasAndUsingDirective>.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<SingleNamespaceDeclaration>.Enumerator enumerator = mergedDeclaration.Declarations.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
SingleNamespaceDeclaration current = enumerator.Current;
|
|
((BindingDiagnosticBag)diagnostics).AddRange<Diagnostic>(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<SingleNamespaceDeclaration>.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<SyntaxReference> ComputeDeclaringReferencesCore()
|
|
{
|
|
return ImmutableArrayExtensions.SelectAsArray<SingleNamespaceDeclaration, SyntaxReference>(_mergedDeclaration.Declarations, s_declaringSyntaxReferencesSelector);
|
|
}
|
|
|
|
internal override ImmutableArray<Symbol> GetMembersUnordered()
|
|
{
|
|
ImmutableArray<Symbol> lazyAllMembers = _lazyAllMembers;
|
|
if (lazyAllMembers.IsDefault)
|
|
{
|
|
ImmutableArray<Symbol> value = StaticCast<Symbol>.From<NamespaceOrTypeSymbol>(ImmutableArrayExtensions.Flatten<ReadOnlyMemory<char>, NamespaceOrTypeSymbol>(GetNameToMembersMap(), (IComparer<NamespaceOrTypeSymbol>)null));
|
|
ImmutableInterlocked.InterlockedInitialize(ref _lazyAllMembers, value);
|
|
lazyAllMembers = _lazyAllMembers;
|
|
}
|
|
return ImmutableArrayExtensions.ConditionallyDeOrder<Symbol>(lazyAllMembers);
|
|
}
|
|
|
|
public override ImmutableArray<Symbol> GetMembers()
|
|
{
|
|
if ((_flags & 1) != 0)
|
|
{
|
|
return _lazyAllMembers;
|
|
}
|
|
ImmutableArray<Symbol> 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<Symbol> GetMembers(ReadOnlyMemory<char> name)
|
|
{
|
|
if (!GetNameToMembersMap().TryGetValue(name, out var value))
|
|
{
|
|
return ImmutableArray<Symbol>.Empty;
|
|
}
|
|
return ImmutableArrayExtensions.Cast<NamespaceOrTypeSymbol, Symbol>(value);
|
|
}
|
|
|
|
internal override ImmutableArray<NamedTypeSymbol> GetTypeMembersUnordered()
|
|
{
|
|
if (_lazyTypeMembersUnordered.IsDefault)
|
|
{
|
|
ImmutableArray<NamedTypeSymbol> value = ImmutableArrayExtensions.Flatten<ReadOnlyMemory<char>, NamedTypeSymbol>(GetNameToTypeMembersMap(), (IComparer<NamedTypeSymbol>)null);
|
|
ImmutableInterlocked.InterlockedInitialize(ref _lazyTypeMembersUnordered, value);
|
|
}
|
|
return _lazyTypeMembersUnordered;
|
|
}
|
|
|
|
public override ImmutableArray<NamedTypeSymbol> GetTypeMembers()
|
|
{
|
|
return ImmutableArrayExtensions.Flatten<ReadOnlyMemory<char>, NamedTypeSymbol>(GetNameToTypeMembersMap(), (IComparer<NamedTypeSymbol>)LexicalOrderSymbolComparer.Instance);
|
|
}
|
|
|
|
public override ImmutableArray<NamedTypeSymbol> GetTypeMembers(ReadOnlyMemory<char> name)
|
|
{
|
|
if (!GetNameToTypeMembersMap().TryGetValue(name, out var value))
|
|
{
|
|
return ImmutableArray<NamedTypeSymbol>.Empty;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public override ImmutableArray<NamedTypeSymbol> GetTypeMembers(ReadOnlyMemory<char> name, int arity)
|
|
{
|
|
return ImmutableArrayExtensions.WhereAsArray<NamedTypeSymbol, int>(GetTypeMembers(name), (Func<NamedTypeSymbol, int, bool>)((NamedTypeSymbol s, int num) => s.Arity == num), arity);
|
|
}
|
|
|
|
private Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamespaceOrTypeSymbol>> 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<AssemblySymbol>)(object)instance).Free();
|
|
}
|
|
return _nameToMembersMap;
|
|
}
|
|
|
|
private Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamedTypeSymbol>> GetNameToTypeMembersMap()
|
|
{
|
|
if (_nameToTypeMembersMap == null)
|
|
{
|
|
Interlocked.CompareExchange(ref _nameToTypeMembersMap, ImmutableArrayExtensions.GetTypesFromMemberMap<ReadOnlyMemory<char>, NamespaceOrTypeSymbol, NamedTypeSymbol>(GetNameToMembersMap(), (IEqualityComparer<ReadOnlyMemory<char>>)ReadOnlyMemoryOfCharComparer.Instance), null);
|
|
}
|
|
return _nameToTypeMembersMap;
|
|
}
|
|
|
|
private Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamespaceOrTypeSymbol>> MakeNameToMembersMap(BindingDiagnosticBag diagnostics)
|
|
{
|
|
PooledDictionary<ReadOnlyMemory<char>, object> val = NamespaceOrTypeSymbol.s_nameToObjectPool.Allocate();
|
|
ImmutableArray<MergedNamespaceOrTypeDeclaration>.Enumerator enumerator = _mergedDeclaration.Children.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
MergedNamespaceOrTypeDeclaration current = enumerator.Current;
|
|
NamespaceOrTypeSymbol namespaceOrTypeSymbol = BuildSymbol(current, diagnostics);
|
|
ImmutableArrayExtensions.AddToMultiValueDictionaryBuilder<ReadOnlyMemory<char>, NamespaceOrTypeSymbol>((Dictionary<ReadOnlyMemory<char>, object>)(object)val, namespaceOrTypeSymbol.Name.AsMemory(), namespaceOrTypeSymbol);
|
|
}
|
|
Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamespaceOrTypeSymbol>> dictionary = new Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamespaceOrTypeSymbol>>(((Dictionary<ReadOnlyMemory<char>, object>)(object)val).Count, (IEqualityComparer<ReadOnlyMemory<char>>?)ReadOnlyMemoryOfCharComparer.Instance);
|
|
ImmutableArrayExtensions.CreateNameToMembersMap<ReadOnlyMemory<char>, NamespaceOrTypeSymbol, NamedTypeSymbol, NamespaceSymbol>((Dictionary<ReadOnlyMemory<char>, object>)(object)val, dictionary);
|
|
val.Free();
|
|
CheckMembers(this, dictionary, diagnostics);
|
|
return dictionary;
|
|
}
|
|
|
|
private static void CheckMembers(NamespaceSymbol @namespace, Dictionary<ReadOnlyMemory<char>, ImmutableArray<NamespaceOrTypeSymbol>> 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<char> key in result.Keys)
|
|
{
|
|
Array.Clear(array, 0, array.Length);
|
|
ImmutableArray<NamespaceOrTypeSymbol>.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<NamespaceSymbol>.Enumerator enumerator3 = mergedNamespaceSymbol.ConstituentNamespaces.GetEnumerator();
|
|
while (enumerator3.MoveNext())
|
|
{
|
|
NamespaceSymbol current3 = enumerator3.Current;
|
|
if ((object)current3 != @namespace)
|
|
{
|
|
ImmutableArray<NamedTypeSymbol> 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<SyntaxTree>((Func<SourceLocation, SyntaxTree, bool>)((SourceLocation loc, SyntaxTree leftTree) => ((Location)loc).SourceTree == leftTree), sourceTree);
|
|
}
|
|
}
|
|
if (namespaceOrTypeSymbol2 is SourceNamespaceSymbol { MergedDeclaration: { NameLocations: var nameLocations } })
|
|
{
|
|
return !ImmutableArrayExtensions.Any<Location, SyntaxTree>(nameLocations, (Func<Location, SyntaxTree, bool>)((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<NamespaceOrTypeSymbol> value in _nameToMembersMap.Values)
|
|
{
|
|
ImmutableArray<NamespaceOrTypeSymbol>.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<SingleNamespaceDeclaration>.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<SingleNamespaceDeclaration>.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<Symbol> members = GetMembers();
|
|
bool flag = true;
|
|
if (((CompilationOptions)DeclaringCompilation.Options).ConcurrentBuild)
|
|
{
|
|
RoslynParallel.For(0, members.Length, UICultureUtilities.WithCurrentUICulture<int>((Action<int>)delegate(int i)
|
|
{
|
|
Symbol.ForceCompleteMemberByLocation(locationOpt, members[i], cancellationToken);
|
|
}), cancellationToken);
|
|
ImmutableArray<Symbol>.Enumerator enumerator2 = members.GetEnumerator();
|
|
while (enumerator2.MoveNext())
|
|
{
|
|
if (!enumerator2.Current.HasComplete(CompletionPart.All))
|
|
{
|
|
flag = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ImmutableArray<Symbol>.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);
|
|
}
|
|
}
|