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; internal class CSharpDeclarationComputer : DeclarationComputer { public static void ComputeDeclarationsInSpan(SemanticModel model, TextSpan span, bool getSymbol, ArrayBuilder builder, CancellationToken cancellationToken) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) ComputeDeclarations(model, null, model.SyntaxTree.GetRoot(cancellationToken), delegate(SyntaxNode node, int? level) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) TextSpan span2 = node.Span; return !((TextSpan)(ref span2)).OverlapsWith(span) || InvalidLevel(level); }, getSymbol, builder, null, cancellationToken); } public static void ComputeDeclarationsInNode(SemanticModel model, ISymbol associatedSymbol, SyntaxNode node, bool getSymbol, ArrayBuilder builder, CancellationToken cancellationToken, int? levelsToCompute = null) { ComputeDeclarations(model, associatedSymbol, node, (SyntaxNode n, int? level) => InvalidLevel(level), getSymbol, builder, levelsToCompute, cancellationToken); } private static bool InvalidLevel(int? level) { if (level.HasValue) { return level.Value <= 0; } return false; } private static int? DecrementLevel(int? level) { if (!level.HasValue) { return level; } return level - 1; } private static void ComputeDeclarations(SemanticModel model, ISymbol associatedSymbol, SyntaxNode node, Func shouldSkip, bool getSymbol, ArrayBuilder builder, int? levelsToCompute, CancellationToken cancellationToken) { //IL_0618: Unknown result type (might be due to invalid IL or missing references) //IL_0631: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_042a: Unknown result type (might be due to invalid IL or missing references) //IL_042f: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_04b3: Unknown result type (might be due to invalid IL or missing references) //IL_04b8: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Unknown result type (might be due to invalid IL or missing references) //IL_04c1: Unknown result type (might be due to invalid IL or missing references) //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Unknown result type (might be due to invalid IL or missing references) //IL_055d: Unknown result type (might be due to invalid IL or missing references) //IL_0561: Unknown result type (might be due to invalid IL or missing references) //IL_0566: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Unknown result type (might be due to invalid IL or missing references) //IL_0730: Unknown result type (might be due to invalid IL or missing references) //IL_0734: Unknown result type (might be due to invalid IL or missing references) //IL_0739: Unknown result type (might be due to invalid IL or missing references) //IL_071e: Unknown result type (might be due to invalid IL or missing references) //IL_045c: Unknown result type (might be due to invalid IL or missing references) //IL_06ab: Unknown result type (might be due to invalid IL or missing references) //IL_050a: Unknown result type (might be due to invalid IL or missing references) //IL_0535: Unknown result type (might be due to invalid IL or missing references) //IL_05bd: Unknown result type (might be due to invalid IL or missing references) //IL_05de: Unknown result type (might be due to invalid IL or missing references) //IL_0490: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_06f0: 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_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_0762: Unknown result type (might be due to invalid IL or missing references) //IL_0767: Unknown result type (might be due to invalid IL or missing references) //IL_0774: Unknown result type (might be due to invalid IL or missing references) //IL_0789: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) cancellationToken.ThrowIfCancellationRequested(); if (shouldSkip(node, levelsToCompute)) { return; } int? levelsToCompute2 = DecrementLevel(levelsToCompute); switch (node.Kind()) { case SyntaxKind.NamespaceDeclaration: case SyntaxKind.FileScopedNamespaceDeclaration: { BaseNamespaceDeclarationSyntax baseNamespaceDeclarationSyntax = (BaseNamespaceDeclarationSyntax)(object)node; Enumerator enumerator = baseNamespaceDeclarationSyntax.Members.GetEnumerator(); while (enumerator.MoveNext()) { MemberDeclarationSyntax current6 = enumerator.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current6, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } DeclarationInfo declarationInfo = DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, cancellationToken); builder.Add(declarationInfo); NameSyntax nameSyntax = baseNamespaceDeclarationSyntax.Name; ISymbol declaredSymbol = ((DeclarationInfo)(ref declarationInfo)).DeclaredSymbol; INamespaceSymbol val = (INamespaceSymbol)(object)((declaredSymbol is INamespaceSymbol) ? declaredSymbol : null); while (nameSyntax.Kind() == SyntaxKind.QualifiedName) { nameSyntax = ((QualifiedNameSyntax)nameSyntax).Left; INamespaceSymbol val2 = (getSymbol ? ((val != null) ? ((ISymbol)val).ContainingNamespace : null) : null); builder.Add(new DeclarationInfo((SyntaxNode)(object)nameSyntax, ImmutableArray.Empty, (ISymbol)(object)val2)); val = val2; } break; } case SyntaxKind.ClassDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKind.RecordDeclaration: case SyntaxKind.RecordStructDeclaration: if (associatedSymbol is IMethodSymbol) { TypeDeclarationSyntax obj = (TypeDeclarationSyntax)(object)node; IEnumerable enumerable = GetParameterListInitializersAndAttributes(obj.ParameterList); if (obj.BaseList?.Types.FirstOrDefault() is PrimaryConstructorBaseTypeSyntax primaryConstructorBaseTypeSyntax) { enumerable = EnumerableExtensions.Concat(enumerable, (SyntaxNode)(object)primaryConstructorBaseTypeSyntax); } builder.Add(DeclarationComputer.GetDeclarationInfo(node, associatedSymbol, enumerable)); break; } goto case SyntaxKind.InterfaceDeclaration; case SyntaxKind.InterfaceDeclaration: { TypeDeclarationSyntax typeDeclarationSyntax = (TypeDeclarationSyntax)(object)node; Enumerator enumerator = typeDeclarationSyntax.Members.GetEnumerator(); while (enumerator.MoveNext()) { MemberDeclarationSyntax current5 = enumerator.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current5, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } IEnumerable enumerable4 = GetAttributes(typeDeclarationSyntax.AttributeLists).Concat(GetTypeParameterListAttributes(typeDeclarationSyntax.TypeParameterList)); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, enumerable4, cancellationToken)); break; } case SyntaxKind.EnumDeclaration: { EnumDeclarationSyntax enumDeclarationSyntax = (EnumDeclarationSyntax)(object)node; Enumerator enumerator3 = enumDeclarationSyntax.Members.GetEnumerator(); while (enumerator3.MoveNext()) { EnumMemberDeclarationSyntax current3 = enumerator3.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current3, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } IEnumerable attributes3 = GetAttributes(enumDeclarationSyntax.AttributeLists); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, attributes3, cancellationToken)); break; } case SyntaxKind.EnumMemberDeclaration: { EnumMemberDeclarationSyntax obj2 = (EnumMemberDeclarationSyntax)(object)node; IEnumerable enumerable2 = Enumerable.Concat(second: GetAttributes(obj2.AttributeLists), first: (IEnumerable)SpecializedCollections.SingletonEnumerable(obj2.EqualsValue)); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, enumerable2, cancellationToken)); break; } case SyntaxKind.DelegateDeclaration: { DelegateDeclarationSyntax delegateDeclarationSyntax = (DelegateDeclarationSyntax)(object)node; IEnumerable enumerable6 = GetAttributes(delegateDeclarationSyntax.AttributeLists).Concat(GetParameterListInitializersAndAttributes(delegateDeclarationSyntax.ParameterList)).Concat(GetTypeParameterListAttributes(delegateDeclarationSyntax.TypeParameterList)); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, enumerable6, cancellationToken)); break; } case SyntaxKind.EventDeclaration: { EventDeclarationSyntax eventDeclarationSyntax = (EventDeclarationSyntax)(object)node; if (eventDeclarationSyntax.AccessorList != null) { Enumerator enumerator2 = eventDeclarationSyntax.AccessorList.Accessors.GetEnumerator(); while (enumerator2.MoveNext()) { AccessorDeclarationSyntax current8 = enumerator2.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current8, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } } IEnumerable attributes6 = GetAttributes(eventDeclarationSyntax.AttributeLists); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, attributes6, cancellationToken)); break; } case SyntaxKind.FieldDeclaration: case SyntaxKind.EventFieldDeclaration: { BaseFieldDeclarationSyntax obj3 = (BaseFieldDeclarationSyntax)(object)node; IEnumerable attributes4 = GetAttributes(obj3.AttributeLists); Enumerator enumerator4 = obj3.Declaration.Variables.GetEnumerator(); while (enumerator4.MoveNext()) { VariableDeclaratorSyntax current4 = enumerator4.Current; IEnumerable enumerable3 = ((IEnumerable)SpecializedCollections.SingletonEnumerable(current4.Initializer)).Concat(attributes4); builder.Add(DeclarationComputer.GetDeclarationInfo(model, (SyntaxNode)(object)current4, getSymbol, enumerable3, cancellationToken)); } break; } case SyntaxKind.ArrowExpressionClause: if (node.Parent is BasePropertyDeclarationSyntax declarationWithExpressionBody) { builder.Add(GetExpressionBodyDeclarationInfo(declarationWithExpressionBody, (ArrowExpressionClauseSyntax)(object)node, model, getSymbol, cancellationToken)); } break; case SyntaxKind.PropertyDeclaration: { PropertyDeclarationSyntax propertyDeclarationSyntax = (PropertyDeclarationSyntax)(object)node; if (propertyDeclarationSyntax.AccessorList != null) { Enumerator enumerator2 = propertyDeclarationSyntax.AccessorList.Accessors.GetEnumerator(); while (enumerator2.MoveNext()) { AccessorDeclarationSyntax current7 = enumerator2.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current7, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } } if (propertyDeclarationSyntax.ExpressionBody != null) { ComputeDeclarations(model, null, (SyntaxNode)(object)propertyDeclarationSyntax.ExpressionBody, shouldSkip, getSymbol, builder, levelsToCompute, cancellationToken); } IEnumerable attributes5 = GetAttributes(propertyDeclarationSyntax.AttributeLists); IEnumerable enumerable5 = ((IEnumerable)SpecializedCollections.SingletonEnumerable(propertyDeclarationSyntax.Initializer)).Concat(attributes5); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, enumerable5, cancellationToken)); break; } case SyntaxKind.IndexerDeclaration: { IndexerDeclarationSyntax indexerDeclarationSyntax = (IndexerDeclarationSyntax)(object)node; if (indexerDeclarationSyntax.AccessorList != null) { Enumerator enumerator2 = indexerDeclarationSyntax.AccessorList.Accessors.GetEnumerator(); while (enumerator2.MoveNext()) { AccessorDeclarationSyntax current2 = enumerator2.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current2, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } } if (indexerDeclarationSyntax.ExpressionBody != null) { ComputeDeclarations(model, null, (SyntaxNode)(object)indexerDeclarationSyntax.ExpressionBody, shouldSkip, getSymbol, builder, levelsToCompute, cancellationToken); } IEnumerable parameterListInitializersAndAttributes = GetParameterListInitializersAndAttributes(indexerDeclarationSyntax.ParameterList); IEnumerable attributes2 = GetAttributes(indexerDeclarationSyntax.AttributeLists); parameterListInitializersAndAttributes = parameterListInitializersAndAttributes.Concat(attributes2); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, parameterListInitializersAndAttributes, cancellationToken)); break; } case SyntaxKind.GetAccessorDeclaration: case SyntaxKind.SetAccessorDeclaration: case SyntaxKind.AddAccessorDeclaration: case SyntaxKind.RemoveAccessorDeclaration: case SyntaxKind.InitAccessorDeclaration: { AccessorDeclarationSyntax accessorDeclarationSyntax = (AccessorDeclarationSyntax)(object)node; ArrayBuilder instance = ArrayBuilder.GetInstance(); ArrayBuilderExtensions.AddIfNotNull(instance, (SyntaxNode)(object)accessorDeclarationSyntax.Body); ArrayBuilderExtensions.AddIfNotNull(instance, (SyntaxNode)(object)accessorDeclarationSyntax.ExpressionBody); instance.AddRange(GetAttributes(accessorDeclarationSyntax.AttributeLists)); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, (IEnumerable)instance, cancellationToken)); instance.Free(); break; } case SyntaxKind.MethodDeclaration: case SyntaxKind.OperatorDeclaration: case SyntaxKind.ConversionOperatorDeclaration: case SyntaxKind.ConstructorDeclaration: case SyntaxKind.DestructorDeclaration: { BaseMethodDeclarationSyntax baseMethodDeclarationSyntax = (BaseMethodDeclarationSyntax)(object)node; IEnumerable parameterListInitializersAndAttributes2 = GetParameterListInitializersAndAttributes(baseMethodDeclarationSyntax.ParameterList); parameterListInitializersAndAttributes2 = EnumerableExtensions.Concat(parameterListInitializersAndAttributes2, (SyntaxNode)(object)baseMethodDeclarationSyntax.Body); if (baseMethodDeclarationSyntax is ConstructorDeclarationSyntax { Initializer: not null } constructorDeclarationSyntax) { parameterListInitializersAndAttributes2 = EnumerableExtensions.Concat(parameterListInitializersAndAttributes2, (SyntaxNode)(object)constructorDeclarationSyntax.Initializer); } ArrowExpressionClauseSyntax expressionBodySyntax = GetExpressionBodySyntax(baseMethodDeclarationSyntax); if (expressionBodySyntax != null) { parameterListInitializersAndAttributes2 = EnumerableExtensions.Concat(parameterListInitializersAndAttributes2, (SyntaxNode)(object)expressionBodySyntax); } parameterListInitializersAndAttributes2 = parameterListInitializersAndAttributes2.Concat(GetAttributes(baseMethodDeclarationSyntax.AttributeLists)); if (node is MethodDeclarationSyntax { TypeParameterList: not null } methodDeclarationSyntax) { parameterListInitializersAndAttributes2 = parameterListInitializersAndAttributes2.Concat(GetTypeParameterListAttributes(methodDeclarationSyntax.TypeParameterList)); } builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, parameterListInitializersAndAttributes2, cancellationToken)); break; } case SyntaxKind.CompilationUnit: { CompilationUnitSyntax compilationUnitSyntax = (CompilationUnitSyntax)(object)node; if (associatedSymbol is IMethodSymbol) { builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, getSymbol, (IEnumerable)(object)new CompilationUnitSyntax[1] { compilationUnitSyntax }, cancellationToken)); break; } Enumerator enumerator = compilationUnitSyntax.Members.GetEnumerator(); while (enumerator.MoveNext()) { MemberDeclarationSyntax current = enumerator.Current; ComputeDeclarations(model, null, (SyntaxNode)(object)current, shouldSkip, getSymbol, builder, levelsToCompute2, cancellationToken); } if (compilationUnitSyntax.AttributeLists.Any()) { IEnumerable attributes = GetAttributes(compilationUnitSyntax.AttributeLists); builder.Add(DeclarationComputer.GetDeclarationInfo(model, node, false, attributes, cancellationToken)); } break; } } } private static IEnumerable GetAttributes(SyntaxList attributeLists) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) Enumerator enumerator = attributeLists.GetEnumerator(); while (enumerator.MoveNext()) { AttributeListSyntax current = enumerator.Current; Enumerator enumerator2 = current.Attributes.GetEnumerator(); while (enumerator2.MoveNext()) { yield return (SyntaxNode)(object)enumerator2.Current; } } } private static IEnumerable GetParameterListInitializersAndAttributes(BaseParameterListSyntax parameterList) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (parameterList == null) { return SpecializedCollections.EmptyEnumerable(); } return ((IEnumerable)(object)parameterList.Parameters).SelectMany((ParameterSyntax p) => GetParameterInitializersAndAttributes(p)); } private static IEnumerable GetParameterInitializersAndAttributes(ParameterSyntax parameter) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return ((IEnumerable)SpecializedCollections.SingletonEnumerable(parameter.Default)).Concat(GetAttributes(parameter.AttributeLists)); } private static IEnumerable GetTypeParameterListAttributes(TypeParameterListSyntax typeParameterList) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (typeParameterList == null) { return SpecializedCollections.EmptyEnumerable(); } return ((IEnumerable)(object)typeParameterList.Parameters).SelectMany((TypeParameterSyntax p) => GetAttributes(p.AttributeLists)); } private static DeclarationInfo GetExpressionBodyDeclarationInfo(BasePropertyDeclarationSyntax declarationWithExpressionBody, ArrowExpressionClauseSyntax expressionBody, SemanticModel model, bool getSymbol, CancellationToken cancellationToken) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) object obj; if (!getSymbol) { obj = null; } else { ISymbol? declaredSymbol = model.GetDeclaredSymbol(declarationWithExpressionBody, cancellationToken); ISymbol? obj2 = ((declaredSymbol is IPropertySymbol) ? declaredSymbol : null); obj = ((obj2 != null) ? ((IPropertySymbol)obj2).GetMethod : null); } IMethodSymbol val = (IMethodSymbol)obj; return new DeclarationInfo((SyntaxNode)(object)expressionBody, ImmutableArray.Create((SyntaxNode)(object)expressionBody), (ISymbol)(object)val); } internal static ArrowExpressionClauseSyntax GetExpressionBodySyntax(CSharpSyntaxNode node) { ArrowExpressionClauseSyntax result = null; switch (node.Kind()) { case SyntaxKind.ArrowExpressionClause: result = (ArrowExpressionClauseSyntax)node; break; case SyntaxKind.MethodDeclaration: result = ((MethodDeclarationSyntax)node).ExpressionBody; break; case SyntaxKind.OperatorDeclaration: result = ((OperatorDeclarationSyntax)node).ExpressionBody; break; case SyntaxKind.ConversionOperatorDeclaration: result = ((ConversionOperatorDeclarationSyntax)node).ExpressionBody; break; case SyntaxKind.PropertyDeclaration: result = ((PropertyDeclarationSyntax)node).ExpressionBody; break; case SyntaxKind.IndexerDeclaration: result = ((IndexerDeclarationSyntax)node).ExpressionBody; break; case SyntaxKind.ConstructorDeclaration: result = ((ConstructorDeclarationSyntax)node).ExpressionBody; break; case SyntaxKind.DestructorDeclaration: result = ((DestructorDeclarationSyntax)node).ExpressionBody; break; default: ExceptionUtilities.UnexpectedValue((object)node.Kind()); break; } return result; } }