Files
PURErat-crack-scode/decompiled/Libraries/microsoft.codeanalysis.csharp/Microsoft.CodeAnalysis.CSharp.Symbols/MethodToClassRewriter.cs
T

632 lines
26 KiB
C#
Raw Normal View History

2026-08-27 10:56:38 -06:00
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Cci;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Emit.NoPia;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
internal abstract class MethodToClassRewriter : BoundTreeRewriterWithStackGuard
{
private sealed class BaseMethodWrapperSymbol : SynthesizedMethodBaseSymbol
{
internal sealed override bool GenerateDebugInfo => false;
internal override bool SynthesizesLoweredBoundBody => true;
internal override ExecutableCodeBinder? TryGetBodyBinder(BinderFactory? binderFactoryOpt = null, bool ignoreAccessibility = false)
{
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.Lowered.cs", 311);
}
internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
{
SyntheticBoundNodeFactory syntheticBoundNodeFactory = new SyntheticBoundNodeFactory(this, (SyntaxNode)(object)this.GetNonNullSyntaxNode(), compilationState, diagnostics);
syntheticBoundNodeFactory.CurrentFunction = OriginalDefinition;
try
{
MethodSymbol methodSymbol = BaseMethod;
if (Arity > 0)
{
methodSymbol = methodSymbol.ConstructedFrom.Construct(StaticCast<TypeSymbol>.From<TypeParameterSymbol>(TypeParameters));
}
BoundBlock boundBlock = MethodBodySynthesizer.ConstructSingleInvocationMethodBody(syntheticBoundNodeFactory, methodSymbol, useBaseReference: true);
if (boundBlock.Kind != BoundKind.Block)
{
boundBlock = syntheticBoundNodeFactory.Block(boundBlock);
}
syntheticBoundNodeFactory.CompilationState.AddMethodWrapper(methodSymbol, this, boundBlock);
}
catch (SyntheticBoundNodeFactory.MissingPredefinedMember missingPredefinedMember)
{
((BindingDiagnosticBag)diagnostics).Add(missingPredefinedMember.Diagnostic);
}
}
internal BaseMethodWrapperSymbol(NamedTypeSymbol containingType, MethodSymbol methodBeingWrapped, SyntaxNode syntax, string name)
: base(containingType, methodBeingWrapped, syntax.SyntaxTree.GetReference(syntax), syntax.GetLocation(), name, DeclarationModifiers.Private, isIterator: false)
{
TypeMap typeMap = ((methodBeingWrapped.ContainingType is SubstitutedNamedTypeSymbol substitutedNamedTypeSymbol) ? substitutedNamedTypeSymbol.TypeSubstitution : TypeMap.Empty);
ImmutableArray<TypeParameterSymbol> newTypeParameters;
if (!methodBeingWrapped.IsGenericMethod)
{
newTypeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
typeMap = typeMap.WithAlphaRename(methodBeingWrapped, this, out newTypeParameters);
}
AssignTypeMapAndTypeParameters(typeMap, newTypeParameters);
}
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);
Symbol.AddSynthesizedAttribute(ref attributes, DeclaringCompilation.TrySynthesizeAttribute((WellKnownMember)70));
}
}
protected Dictionary<Symbol, CapturedSymbolReplacement> proxies = new Dictionary<Symbol, CapturedSymbolReplacement>();
protected readonly Dictionary<LocalSymbol, LocalSymbol> localMap = new Dictionary<LocalSymbol, LocalSymbol>();
protected readonly TypeCompilationState CompilationState;
protected readonly BindingDiagnosticBag Diagnostics;
protected readonly VariableSlotAllocator? slotAllocatorOpt;
private readonly Dictionary<BoundValuePlaceholderBase, BoundExpression> _placeholderMap;
protected abstract TypeMap TypeMap { get; }
protected abstract MethodSymbol CurrentMethod { get; }
protected abstract NamedTypeSymbol ContainingType { get; }
protected abstract BoundExpression FramePointer(SyntaxNode syntax, NamedTypeSymbol frameClass);
protected MethodToClassRewriter(VariableSlotAllocator? slotAllocatorOpt, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
{
CompilationState = compilationState;
Diagnostics = diagnostics;
this.slotAllocatorOpt = slotAllocatorOpt;
_placeholderMap = new Dictionary<BoundValuePlaceholderBase, BoundExpression>();
}
public override BoundNode DefaultVisit(BoundNode node)
{
return base.DefaultVisit(node);
}
protected abstract bool NeedsProxy(Symbol localOrParameter);
protected void RewriteLocals(ImmutableArray<LocalSymbol> locals, ArrayBuilder<LocalSymbol> newLocals)
{
ImmutableArray<LocalSymbol>.Enumerator enumerator = locals.GetEnumerator();
while (enumerator.MoveNext())
{
LocalSymbol current = enumerator.Current;
if (TryRewriteLocal(current, out LocalSymbol newLocal))
{
newLocals.Add(newLocal);
}
}
}
protected bool TryRewriteLocal(LocalSymbol local, [NotNullWhen(true)] out LocalSymbol? newLocal)
{
if (NeedsProxy(local))
{
newLocal = null;
return false;
}
if (localMap.TryGetValue(local, out newLocal))
{
return true;
}
TypeSymbol typeSymbol = VisitType(local.Type);
if (TypeSymbol.Equals(typeSymbol, local.Type, (TypeCompareKind)0))
{
newLocal = local;
}
else
{
newLocal = new TypeSubstitutedLocalSymbol(local, TypeWithAnnotations.Create(typeSymbol), CurrentMethod);
localMap.Add(local, newLocal);
}
return true;
}
private ImmutableArray<LocalSymbol> RewriteLocals(ImmutableArray<LocalSymbol> locals)
{
if (locals.IsEmpty)
{
return locals;
}
ArrayBuilder<LocalSymbol> instance = ArrayBuilder<LocalSymbol>.GetInstance();
RewriteLocals(locals, instance);
return instance.ToImmutableAndFree();
}
public override BoundNode VisitCatchBlock(BoundCatchBlock node)
{
if (!node.Locals.IsDefaultOrEmpty)
{
ImmutableArray<LocalSymbol> locals = RewriteLocals(node.Locals);
return node.Update(locals, (BoundExpression)Visit(node.ExceptionSourceOpt), VisitType(node.ExceptionTypeOpt), (BoundStatementList)Visit(node.ExceptionFilterPrologueOpt), (BoundExpression)Visit(node.ExceptionFilterOpt), (BoundBlock)Visit(node.Body), node.IsSynthesizedAsyncCatchAll);
}
return base.VisitCatchBlock(node);
}
public override BoundNode VisitBlock(BoundBlock node)
{
return VisitBlock(node, removeInstrumentation: false);
}
protected BoundBlock VisitBlock(BoundBlock node, bool removeInstrumentation)
{
ImmutableArray<LocalSymbol> locals = RewriteLocals(node.Locals);
ImmutableArray<LocalFunctionSymbol> localFunctions = node.LocalFunctions;
ImmutableArray<BoundStatement> statements = VisitList(node.Statements);
BoundBlockInstrumentation instrumentation = (removeInstrumentation ? null : ((BoundBlockInstrumentation)Visit(node.Instrumentation)));
return node.Update(locals, localFunctions, node.HasUnsafeModifier, instrumentation, statements);
}
public abstract override BoundNode VisitScope(BoundScope node);
public override BoundNode VisitSequence(BoundSequence node)
{
ImmutableArray<LocalSymbol> locals = RewriteLocals(node.Locals);
ImmutableArray<BoundExpression> sideEffects = VisitList(node.SideEffects);
BoundExpression value = (BoundExpression)Visit(node.Value);
TypeSymbol type = VisitType(node.Type);
return node.Update(locals, sideEffects, value, type);
}
public override BoundNode VisitForStatement(BoundForStatement node)
{
ImmutableArray<LocalSymbol> outerLocals = RewriteLocals(node.OuterLocals);
BoundStatement initializer = (BoundStatement)Visit(node.Initializer);
ImmutableArray<LocalSymbol> innerLocals = RewriteLocals(node.InnerLocals);
BoundExpression condition = (BoundExpression)Visit(node.Condition);
BoundStatement increment = (BoundStatement)Visit(node.Increment);
BoundStatement body = (BoundStatement)Visit(node.Body);
return node.Update(outerLocals, initializer, innerLocals, condition, increment, body, node.BreakLabel, node.ContinueLabel);
}
public override BoundNode VisitDoStatement(BoundDoStatement node)
{
ImmutableArray<LocalSymbol> locals = RewriteLocals(node.Locals);
BoundExpression condition = (BoundExpression)Visit(node.Condition);
BoundStatement body = (BoundStatement)Visit(node.Body);
return node.Update(locals, condition, body, node.BreakLabel, node.ContinueLabel);
}
public override BoundNode VisitWhileStatement(BoundWhileStatement node)
{
ImmutableArray<LocalSymbol> locals = RewriteLocals(node.Locals);
BoundExpression condition = (BoundExpression)Visit(node.Condition);
BoundStatement body = (BoundStatement)Visit(node.Body);
return node.Update(locals, condition, body, node.BreakLabel, node.ContinueLabel);
}
public override BoundNode VisitUsingStatement(BoundUsingStatement node)
{
ImmutableArray<LocalSymbol> locals = RewriteLocals(node.Locals);
BoundMultipleLocalDeclarations declarationsOpt = (BoundMultipleLocalDeclarations)Visit(node.DeclarationsOpt);
BoundExpression expressionOpt = (BoundExpression)Visit(node.ExpressionOpt);
BoundStatement body = (BoundStatement)Visit(node.Body);
return node.Update(locals, declarationsOpt, expressionOpt, body, node.AwaitOpt, node.PatternDisposeInfoOpt);
}
[return: NotNullIfNotNull("type")]
public sealed override TypeSymbol? VisitType(TypeSymbol? type)
{
return TypeMap.SubstituteType(type).Type;
}
public override BoundNode VisitMethodInfo(BoundMethodInfo node)
{
MethodSymbol method = VisitMethodSymbol(node.Method);
return node.Update(method, node.GetMethodFromHandle, node.Type);
}
public override BoundNode VisitPropertyAccess(BoundPropertyAccess node)
{
PropertySymbol propertySymbol = VisitPropertySymbol(node.PropertySymbol);
BoundExpression receiverOpt = (BoundExpression)Visit(node.ReceiverOpt);
return node.Update(receiverOpt, (ThreeState)0, propertySymbol, node.ResultKind, VisitType(node.Type));
}
public override BoundNode VisitCall(BoundCall node)
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
MethodSymbol methodSymbol = VisitMethodSymbol(node.Method);
BoundExpression boundExpression = (BoundExpression)Visit(node.ReceiverOpt);
ImmutableArray<BoundExpression> arguments = VisitList(node.Arguments);
TypeSymbol type = VisitType(node.Type);
if (BaseReferenceInReceiverWasRewritten(node.ReceiverOpt, boundExpression) && node.Method.IsMetadataVirtual())
{
methodSymbol = GetMethodWrapperForBaseNonVirtualCall(methodSymbol, node.Syntax);
}
return node.Update(boundExpression, (ThreeState)0, methodSymbol, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.IsDelegateCall, node.Expanded, node.InvokedAsExtensionMethod, node.ArgsToParamsOpt, node.DefaultArguments, node.ResultKind, type);
}
public override BoundNode VisitBinaryOperator(BoundBinaryOperator node)
{
return node.Update(node.OperatorKind, node.ConstantValueOpt, VisitMethodSymbol(node.Method), VisitType(node.ConstrainedToType), node.ResultKind, (BoundExpression)Visit(node.Left), (BoundExpression)Visit(node.Right), VisitType(node.Type));
}
public override BoundNode VisitUnaryOperator(BoundUnaryOperator node)
{
return node.Update(node.OperatorKind, (BoundExpression)Visit(node.Operand), node.ConstantValueOpt, VisitMethodSymbol(node.MethodOpt), VisitType(node.ConstrainedToTypeOpt), node.ResultKind, VisitType(node.Type));
}
public override BoundNode? VisitConversion(BoundConversion node)
{
Conversion conversion = node.Conversion;
if ((object)conversion.Method != null)
{
conversion = conversion.SetConversionMethod(VisitMethodSymbol(conversion.Method));
}
return node.Update((BoundExpression)Visit(node.Operand), conversion, node.IsBaseConversion, node.Checked, node.ExplicitCastInCode, node.ConstantValueOpt, node.ConversionGroupOpt, VisitType(node.Type));
}
public override BoundNode? VisitUserDefinedConditionalLogicalOperator(BoundUserDefinedConditionalLogicalOperator node)
{
return node.Update(node.OperatorKind, VisitMethodSymbol(node.LogicalOperator), VisitMethodSymbol(node.TrueOperator), VisitMethodSymbol(node.FalseOperator), VisitType(node.ConstrainedToTypeOpt), node.ResultKind, (BoundExpression)Visit(node.Left), (BoundExpression)Visit(node.Right), VisitType(node.Type));
}
private MethodSymbol GetMethodWrapperForBaseNonVirtualCall(MethodSymbol methodBeingCalled, SyntaxNode syntax)
{
MethodSymbol orCreateBaseFunctionWrapper = GetOrCreateBaseFunctionWrapper(methodBeingCalled, syntax);
if (!orCreateBaseFunctionWrapper.IsGenericMethod)
{
return orCreateBaseFunctionWrapper;
}
ImmutableArray<TypeWithAnnotations> typeArgumentsWithAnnotations = methodBeingCalled.TypeArgumentsWithAnnotations;
ArrayBuilder<TypeWithAnnotations> instance = ArrayBuilder<TypeWithAnnotations>.GetInstance(typeArgumentsWithAnnotations.Length);
ImmutableArray<TypeWithAnnotations>.Enumerator enumerator = typeArgumentsWithAnnotations.GetEnumerator();
while (enumerator.MoveNext())
{
TypeWithAnnotations current = enumerator.Current;
instance.Add(current.WithTypeAndModifiers(VisitType(current.Type), current.CustomModifiers));
}
return orCreateBaseFunctionWrapper.Construct(instance.ToImmutableAndFree());
}
private MethodSymbol GetOrCreateBaseFunctionWrapper(MethodSymbol methodBeingWrapped, SyntaxNode syntax)
{
methodBeingWrapped = methodBeingWrapped.ConstructedFrom;
MethodSymbol methodWrapper = CompilationState.GetMethodWrapper(methodBeingWrapped);
if ((object)methodWrapper != null)
{
return methodWrapper;
}
NamedTypeSymbol containingType = ContainingType;
string name = GeneratedNames.MakeBaseMethodWrapperName(CompilationState.NextWrapperMethodIndex);
methodWrapper = new BaseMethodWrapperSymbol(containingType, methodBeingWrapped, syntax, name);
if (CompilationState.Emitting)
{
((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)CompilationState.ModuleBuilderOpt).AddSynthesizedDefinition(containingType, (IMethodDefinition)(object)methodWrapper.GetCciAdapter());
}
methodWrapper.GenerateMethodBody(CompilationState, Diagnostics);
return methodWrapper;
}
private bool TryReplaceWithProxy(Symbol parameterOrLocal, SyntaxNode syntax, [NotNullWhen(true)] out BoundNode? replacement)
{
if (proxies.TryGetValue(parameterOrLocal, out CapturedSymbolReplacement value))
{
replacement = value.Replacement(syntax, (NamedTypeSymbol frameType) => FramePointer(syntax, frameType));
return true;
}
replacement = null;
return false;
}
public sealed override BoundNode VisitParameter(BoundParameter node)
{
if (TryReplaceWithProxy(node.ParameterSymbol, node.Syntax, out BoundNode replacement))
{
return replacement;
}
return VisitUnhoistedParameter(node);
}
protected virtual BoundNode VisitUnhoistedParameter(BoundParameter node)
{
return base.VisitParameter(node);
}
public sealed override BoundNode VisitLocal(BoundLocal node)
{
if (TryReplaceWithProxy(node.LocalSymbol, node.Syntax, out BoundNode replacement))
{
return replacement;
}
return VisitUnhoistedLocal(node);
}
public override BoundNode? VisitLocalId(BoundLocalId node)
{
if (!TryGetHoistedField(node.Local, out FieldSymbol field))
{
return base.VisitLocalId(node);
}
return node.Update(node.Local, field, node.Type);
}
public override BoundNode? VisitParameterId(BoundParameterId node)
{
if (!TryGetHoistedField(node.Parameter, out FieldSymbol field))
{
return base.VisitParameterId(node);
}
return node.Update(node.Parameter, field, node.Type);
}
private bool TryGetHoistedField(Symbol variable, [NotNullWhen(true)] out FieldSymbol? field)
{
if (proxies.TryGetValue(variable, out CapturedSymbolReplacement value))
{
FieldSymbol hoistedField;
if (!(value is CapturedToStateMachineFieldReplacement capturedToStateMachineFieldReplacement))
{
if (!(value is CapturedToFrameSymbolReplacement capturedToFrameSymbolReplacement))
{
throw ExceptionUtilities.UnexpectedValue((object)value);
}
hoistedField = capturedToFrameSymbolReplacement.HoistedField;
}
else
{
hoistedField = capturedToStateMachineFieldReplacement.HoistedField;
}
field = hoistedField;
return true;
}
field = null;
return false;
}
private BoundNode VisitUnhoistedLocal(BoundLocal node)
{
if (localMap.TryGetValue(node.LocalSymbol, out LocalSymbol value))
{
return new BoundLocal(node.Syntax, value, node.ConstantValueOpt, value.Type, node.HasErrors);
}
return base.VisitLocal(node);
}
public override BoundNode VisitAwaitableInfo(BoundAwaitableInfo node)
{
BoundAwaitableValuePlaceholder awaitableInstancePlaceholder = node.AwaitableInstancePlaceholder;
if (awaitableInstancePlaceholder == null)
{
return node;
}
BoundAwaitableValuePlaceholder boundAwaitableValuePlaceholder = awaitableInstancePlaceholder.Update(VisitType(awaitableInstancePlaceholder.Type));
_placeholderMap.Add(awaitableInstancePlaceholder, boundAwaitableValuePlaceholder);
BoundExpression getAwaiter = (BoundExpression)Visit(node.GetAwaiter);
PropertySymbol isCompleted = VisitPropertySymbol(node.IsCompleted);
MethodSymbol getResult = VisitMethodSymbol(node.GetResult);
_placeholderMap.Remove(awaitableInstancePlaceholder);
return node.Update(boundAwaitableValuePlaceholder, node.IsDynamic, getAwaiter, isCompleted, getResult);
}
public override BoundNode VisitAwaitableValuePlaceholder(BoundAwaitableValuePlaceholder node)
{
return _placeholderMap[node];
}
public override BoundNode VisitAssignmentOperator(BoundAssignmentOperator node)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
BoundExpression left = node.Left;
if (left.Kind != BoundKind.Local)
{
return base.VisitAssignmentOperator(node);
}
BoundLocal boundLocal = (BoundLocal)left;
BoundExpression right = node.Right;
if ((int)boundLocal.LocalSymbol.RefKind != 0 && node.IsRef && NeedsProxy(boundLocal.LocalSymbol))
{
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Lowering/MethodToClassRewriter.cs", 492);
}
if (NeedsProxy(boundLocal.LocalSymbol) && !proxies.ContainsKey(boundLocal.LocalSymbol))
{
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Lowering/MethodToClassRewriter.cs", 499);
}
BoundExpression boundExpression = (BoundExpression)Visit(boundLocal);
BoundExpression boundExpression2 = (BoundExpression)Visit(right);
TypeSymbol type = VisitType(node.Type);
if (boundExpression.Kind != BoundKind.Local && right.Kind == BoundKind.ConvertedStackAllocExpression)
{
BoundAssignmentOperator store;
BoundLocal boundLocal2 = new SyntheticBoundNodeFactory(CurrentMethod, boundExpression.Syntax, CompilationState, Diagnostics).StoreToTemp(boundExpression2, out store, (RefKind)0, (SynthesizedLocalKind)(-2));
BoundAssignmentOperator value = node.Update(boundExpression, boundLocal2, node.IsRef, type);
return new BoundSequence(node.Syntax, ImmutableArray.Create(boundLocal2.LocalSymbol), ImmutableArray.Create((BoundExpression)store), value, type);
}
return node.Update(boundExpression, boundExpression2, node.IsRef, type);
}
public override BoundNode VisitFieldInfo(BoundFieldInfo node)
{
FieldSymbol field = node.Field.OriginalDefinition.AsMember((NamedTypeSymbol)VisitType(node.Field.ContainingType));
return node.Update(field, node.GetFieldFromHandle, node.Type);
}
public override BoundNode VisitFieldAccess(BoundFieldAccess node)
{
BoundExpression receiver = (BoundExpression)Visit(node.ReceiverOpt);
TypeSymbol typeSymbol = VisitType(node.Type);
FieldSymbol fieldSymbol = node.FieldSymbol.OriginalDefinition.AsMember((NamedTypeSymbol)VisitType(node.FieldSymbol.ContainingType));
return node.Update(receiver, fieldSymbol, node.ConstantValueOpt, node.ResultKind, typeSymbol);
}
public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpression node)
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
BoundObjectCreationExpression boundObjectCreationExpression = (BoundObjectCreationExpression)base.VisitObjectCreationExpression(node);
if (!TypeSymbol.Equals(boundObjectCreationExpression.Type, node.Type, (TypeCompareKind)0) && (object)node.Constructor != null)
{
MethodSymbol constructor = VisitMethodSymbol(node.Constructor);
boundObjectCreationExpression = boundObjectCreationExpression.Update(constructor, boundObjectCreationExpression.Arguments, boundObjectCreationExpression.ArgumentNamesOpt, boundObjectCreationExpression.ArgumentRefKindsOpt, boundObjectCreationExpression.Expanded, boundObjectCreationExpression.ArgsToParamsOpt, boundObjectCreationExpression.DefaultArguments, boundObjectCreationExpression.ConstantValueOpt, boundObjectCreationExpression.InitializerExpressionOpt, boundObjectCreationExpression.Type);
}
return boundObjectCreationExpression;
}
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node)
{
BoundExpression argument = node.Argument;
BoundExpression boundExpression = (BoundExpression)Visit(argument);
MethodSymbol methodSymbol = node.MethodOpt;
if (BaseReferenceInReceiverWasRewritten(argument, boundExpression) && methodSymbol.IsMetadataVirtual())
{
methodSymbol = GetMethodWrapperForBaseNonVirtualCall(methodSymbol, argument.Syntax);
}
methodSymbol = VisitMethodSymbol(methodSymbol);
TypeSymbol type = VisitType(node.Type);
return node.Update(boundExpression, methodSymbol, node.IsExtensionMethod, node.WasTargetTyped, type);
}
public override BoundNode VisitFunctionPointerLoad(BoundFunctionPointerLoad node)
{
return node.Update(VisitMethodSymbol(node.TargetMethod), VisitType(node.ConstrainedToTypeOpt), VisitType(node.Type));
}
public override BoundNode VisitLoweredConditionalAccess(BoundLoweredConditionalAccess node)
{
BoundExpression receiver = (BoundExpression)Visit(node.Receiver);
BoundExpression whenNotNull = (BoundExpression)Visit(node.WhenNotNull);
BoundExpression whenNullOpt = (BoundExpression)Visit(node.WhenNullOpt);
TypeSymbol type = VisitType(node.Type);
return node.Update(receiver, VisitMethodSymbol(node.HasValueMethodOpt), whenNotNull, whenNullOpt, node.Id, node.ForceCopyOfNullableValueType, type);
}
[return: NotNullIfNotNull("method")]
protected MethodSymbol? VisitMethodSymbol(MethodSymbol? method)
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Invalid comparison between Unknown and I4
if ((object)method == null)
{
return null;
}
if ((object)method.ContainingType == null)
{
return method.OriginalDefinition.ConstructIfGeneric(TypeMap.SubstituteTypes(method.TypeArgumentsWithAnnotations));
}
if (method.ContainingType.IsAnonymousType)
{
NamedTypeSymbol namedTypeSymbol = (NamedTypeSymbol)TypeMap.SubstituteType(method.ContainingType).AsTypeSymbolOnly();
if ((object)namedTypeSymbol == method.ContainingType)
{
return method;
}
ImmutableArray<Symbol>.Enumerator enumerator = namedTypeSymbol.GetMembers(method.Name).GetEnumerator();
while (enumerator.MoveNext())
{
Symbol current = enumerator.Current;
if ((int)current.Kind == 9)
{
return (MethodSymbol)current;
}
}
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Lowering/MethodToClassRewriter.cs", 639);
}
return method.OriginalDefinition.AsMember((NamedTypeSymbol)TypeMap.SubstituteType(method.ContainingType).AsTypeSymbolOnly()).ConstructIfGeneric(TypeMap.SubstituteTypes(method.TypeArgumentsWithAnnotations));
}
[return: NotNullIfNotNull("property")]
private PropertySymbol? VisitPropertySymbol(PropertySymbol? property)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Invalid comparison between Unknown and I4
if ((object)property == null)
{
return null;
}
if (!property.ContainingType.IsAnonymousType)
{
return property.OriginalDefinition.AsMember((NamedTypeSymbol)TypeMap.SubstituteType(property.ContainingType).AsTypeSymbolOnly());
}
NamedTypeSymbol namedTypeSymbol = (NamedTypeSymbol)TypeMap.SubstituteType(property.ContainingType).AsTypeSymbolOnly();
if ((object)namedTypeSymbol == property.ContainingType)
{
return property;
}
ImmutableArray<Symbol>.Enumerator enumerator = namedTypeSymbol.GetMembers(property.Name).GetEnumerator();
while (enumerator.MoveNext())
{
Symbol current = enumerator.Current;
if ((int)current.Kind == 15)
{
return (PropertySymbol)current;
}
}
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Lowering/MethodToClassRewriter.cs", 682);
}
private FieldSymbol VisitFieldSymbol(FieldSymbol field)
{
return field.OriginalDefinition.AsMember((NamedTypeSymbol)TypeMap.SubstituteType(field.ContainingType).AsTypeSymbolOnly());
}
public override BoundNode VisitObjectInitializerMember(BoundObjectInitializerMember node)
{
//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)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Invalid comparison between Unknown and I4
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
ImmutableArray<BoundExpression> arguments = VisitList(node.Arguments);
TypeSymbol type = VisitType(node.Type);
TypeSymbol receiverType = VisitType(node.ReceiverType);
Symbol symbol = node.MemberSymbol;
SymbolKind kind = symbol.Kind;
if ((int)kind != 6)
{
if ((int)kind == 15)
{
symbol = VisitPropertySymbol((PropertySymbol)symbol);
}
}
else
{
symbol = VisitFieldSymbol((FieldSymbol)symbol);
}
return node.Update(symbol, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.DefaultArguments, node.ResultKind, receiverType, type);
}
public override BoundNode VisitReadOnlySpanFromArray(BoundReadOnlySpanFromArray node)
{
BoundExpression operand = (BoundExpression)Visit(node.Operand);
MethodSymbol conversionMethod = VisitMethodSymbol(node.ConversionMethod);
TypeSymbol type = VisitType(node.Type);
return node.Update(operand, conversionMethod, type);
}
private static bool BaseReferenceInReceiverWasRewritten([NotNullWhen(true)] BoundExpression? originalReceiver, [NotNullWhen(true)] BoundExpression? rewrittenReceiver)
{
if (originalReceiver != null && originalReceiver.Kind == BoundKind.BaseReference)
{
if (rewrittenReceiver != null)
{
return rewrittenReceiver.Kind != BoundKind.BaseReference;
}
return false;
}
return false;
}
}