From b338bae88aab6e300a81cc1dfce2e5bdb0188ff1 Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Fri, 9 Jun 2017 05:06:17 -0700 Subject: [PATCH] made operation factory an instance factory and semantic model owns the factory. --- .../Compilation/MemberSemanticModel.cs | 10 +- .../LocalRewriter/LocalRewriter_Call.cs | 106 ++++++------ .../Operations/CSharpOperationFactory.cs | 163 +++++++++--------- .../CSharpOperationFactory_Methods.cs | 65 +++---- .../Core/Portable/CodeAnalysis.csproj | 1 + .../Portable/Operations/OperationCache.cs | 25 +++ .../Portable/Binding/MemberSemanticModel.vb | 6 +- .../Operations/VisualBasicOperationFactory.vb | 163 +++++++++--------- .../VisualBasicOperationFactory_Methods.vb | 114 +++++------- 9 files changed, 323 insertions(+), 330 deletions(-) create mode 100644 src/Compilers/Core/Portable/Operations/OperationCache.cs diff --git a/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs b/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs index 7c6060f3aac..3639aff5ef6 100644 --- a/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs +++ b/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs @@ -34,6 +34,8 @@ internal abstract partial class MemberSemanticModel : CSharpSemanticModel private readonly SyntaxTreeSemanticModel _parentSemanticModelOpt; private readonly int _speculatedPosition; + private readonly CSharpOperationFactory _operationFactory; + protected MemberSemanticModel(CSharpCompilation compilation, CSharpSyntaxNode root, Symbol memberSymbol, Binder rootBinder, SyntaxTreeSemanticModel parentSemanticModelOpt, int speculatedPosition) { Debug.Assert(compilation != null); @@ -48,6 +50,8 @@ protected MemberSemanticModel(CSharpCompilation compilation, CSharpSyntaxNode ro this.RootBinder = rootBinder.WithAdditionalFlags(GetSemanticModelBinderFlags()); _parentSemanticModelOpt = parentSemanticModelOpt; _speculatedPosition = speculatedPosition; + + _operationFactory = new CSharpOperationFactory(); } public override CSharpCompilation Compilation @@ -979,7 +983,7 @@ internal override IOperation GetOperationWorker(CSharpSyntaxNode node, GetOperat break; } - return CSharpOperationFactory.Create(result); + return _operationFactory.Create(result); } internal override SymbolInfo GetSymbolInfoWorker(CSharpSyntaxNode node, SymbolInfoOptions options, CancellationToken cancellationToken = default(CancellationToken)) @@ -1542,7 +1546,7 @@ private static Binder GetQueryEnclosingBinder(int position, CSharpSyntaxNode sta } while (node != null); -done: + done: return GetEnclosingBinderInternalWithinRoot(AdjustStartingNodeAccordingToNewRoot(startingNode, queryClause.Syntax), position, queryClause.Binder, queryClause.Syntax); } @@ -1936,7 +1940,7 @@ public override BoundStatement BindStatement(StatementSyntax node, DiagnosticBag // _lazyGuardedSynthesizedStatementsMap if (statement.WasCompilerGenerated) { - _semanticModel.GuardedAddSynthesizedStatementToMap(node, statement); + _semanticModel.GuardedAddSynthesizedStatementToMap(node, statement); } return statement; diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs index aa8551255ec..3998c0d8cd0 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs @@ -492,6 +492,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind } internal static ImmutableArray MakeArgumentsInEvaluationOrder( + CSharpOperationFactory operationFactory, Binder binder, SyntaxNode syntax, ImmutableArray arguments, @@ -517,19 +518,21 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind if (CanSkipRewriting(arguments, methodOrIndexer, expanded, argsToParamsOpt, invokedAsExtensionMethod, out var isComReceiver)) - { + { // In this case, the invocation is not in expanded form and there's no named argument provided. // So we just return list of arguments as is. - return arguments.ZipAsArray(methodOrIndexer.GetParameters(), (a, p) => CSharpOperationFactory.CreateArgumentOperation(ArgumentKind.Explicit, p, CSharpOperationFactory.Create(a))); - } + return arguments.ZipAsArray(methodOrIndexer.GetParameters(), (a, p) => CSharpOperationFactory.CreateArgumentOperation(ArgumentKind.Explicit, p, operationFactory.Create(a))); + } - return BuildArgumentsInEvaluationOrder(syntax, + return BuildArgumentsInEvaluationOrder( + operationFactory, + syntax, methodOrIndexer, optionalParametersMethod, - expanded, - argsToParamsOpt, - arguments, - binder); + expanded, + argsToParamsOpt, + arguments, + binder); } // temporariesBuilder will be null when factory is null. @@ -558,7 +561,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind ((MethodSymbol)methodOrIndexer).Parameters[0].Type as NamedTypeSymbol : methodOrIndexer.ContainingType; - isComReceiver = (object)receiverNamedType != null && receiverNamedType.IsComImport; + isComReceiver = (object)receiverNamedType != null && receiverNamedType.IsComImport; return rewrittenArguments.Length == methodOrIndexer.GetParameterCount() && argsToParamsOpt.IsDefault && @@ -619,8 +622,8 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r // then we need to create a temporary as usual. The step that // produces the parameter array will need to deal with that // eventuality. - - if (IsBeginningOfParamArray(p, a, expanded, arguments.Length, rewrittenArguments, argsToParamsOpt, out int paramArrayArgumentCount) + + if (IsBeginningOfParamArray(p, a, expanded, arguments.Length, rewrittenArguments, argsToParamsOpt, out int paramArrayArgumentCount) && a + paramArrayArgumentCount == rewrittenArguments.Length) { return; @@ -643,6 +646,7 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r // This fills in the arguments and parameters arrays in evaluation order. private static ImmutableArray BuildArgumentsInEvaluationOrder( + CSharpOperationFactory operationFactory, SyntaxNode syntax, Symbol methodOrIndexer, MethodSymbol optionalParametersMethod, @@ -690,8 +694,8 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r argument = CreateParamArrayArgument(syntax, parameter.Type, paramArray.ToImmutableAndFree(), null, binder); } - argumentsInEvaluationBuilder.Add(CSharpOperationFactory.CreateArgumentOperation(kind, parameter, CSharpOperationFactory.Create(argument))); - } + argumentsInEvaluationBuilder.Add(CSharpOperationFactory.CreateArgumentOperation(kind, parameter, operationFactory.Create(argument))); + } // Collect parameters with missing arguments. ArrayBuilder missingParametersBuilder = ArrayBuilder.GetInstance(parameters.Length); @@ -706,7 +710,7 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r processedParameters.Free(); // Finally, append default value as arguments. - AppendMissingOptionalArguments(syntax, methodOrIndexer, optionalParametersMethod, expanded, binder, missingParametersBuilder, argumentsInEvaluationBuilder); + AppendMissingOptionalArguments(operationFactory, syntax, methodOrIndexer, optionalParametersMethod, expanded, binder, missingParametersBuilder, argumentsInEvaluationBuilder); missingParametersBuilder.Free(); @@ -729,13 +733,13 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r numberOfParamArrayArguments = 0; if (expanded && parameterIndex == parameterCount - 1) - { + { int remainingArgument = argumentIndex + 1; for (; remainingArgument < arguments.Length; ++remainingArgument) { int remainingParameter = (!argsToParamsOpt.IsDefault) ? argsToParamsOpt[remainingArgument] : remainingArgument; if (remainingParameter != parameterCount - 1) - { + { break; } } @@ -816,15 +820,15 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r } private static BoundExpression CreateParamArrayArgument(SyntaxNode syntax, - TypeSymbol paramArrayType, - ImmutableArray arrayArgs, + TypeSymbol paramArrayType, + ImmutableArray arrayArgs, LocalRewriter localRewriter, Binder binder) { - Debug.Assert(localRewriter == null ^ binder == null); - + Debug.Assert(localRewriter == null ^ binder == null); + TypeSymbol int32Type = (localRewriter != null ? localRewriter._compilation : binder.Compilation).GetSpecialType(SpecialType.System_Int32); - BoundExpression arraySize = MakeLiteral(syntax, ConstantValue.Create(arrayArgs.Length), int32Type, localRewriter); + BoundExpression arraySize = MakeLiteral(syntax, ConstantValue.Create(arrayArgs.Length), int32Type, localRewriter); return new BoundArrayCreation( syntax, @@ -994,16 +998,18 @@ private static BoundExpression MakeLiteral(SyntaxNode syntax, ConstantValue cons } } - private static void AppendMissingOptionalArguments(SyntaxNode syntax, + private static void AppendMissingOptionalArguments( + CSharpOperationFactory operationFactory, + SyntaxNode syntax, Symbol methodOrIndexer, MethodSymbol optionalParametersMethod, - bool expanded, + bool expanded, Binder binder, ArrayBuilder missingParameters, ArrayBuilder argumentsBuilder) { ImmutableArray parameters = methodOrIndexer.GetParameters(); - ImmutableArray parametersOfOptionalParametersMethod = optionalParametersMethod.Parameters; + ImmutableArray parametersOfOptionalParametersMethod = optionalParametersMethod.Parameters; foreach (ParameterSymbol parameter in missingParameters) { @@ -1021,7 +1027,7 @@ private static BoundExpression MakeLiteral(SyntaxNode syntax, ConstantValue cons // Create an empty array for omitted param array argument. argument = CreateParamArrayArgument(syntax, parameterOfOptionalParametersMethod.Type, ImmutableArray.Empty, null, binder); - kind = ArgumentKind.ParamArray; + kind = ArgumentKind.ParamArray; } else { @@ -1030,18 +1036,18 @@ private static BoundExpression MakeLiteral(SyntaxNode syntax, ConstantValue cons var unusedDiagnostics = DiagnosticBag.GetInstance(); argument = GetDefaultParameterValue(syntax, - parameterOfOptionalParametersMethod, - enableCallerInfo: ThreeState.Unknown, - localRewriter: null, - binder: binder, + parameterOfOptionalParametersMethod, + enableCallerInfo: ThreeState.Unknown, + localRewriter: null, + binder: binder, diagnostics: unusedDiagnostics); kind = ArgumentKind.DefaultValue; - unusedDiagnostics.Free(); - } + unusedDiagnostics.Free(); + } - argumentsBuilder.Add(CSharpOperationFactory.CreateArgumentOperation(kind, parameter, CSharpOperationFactory.Create(argument))); - } + argumentsBuilder.Add(CSharpOperationFactory.CreateArgumentOperation(kind, parameter, operationFactory.Create(argument))); + } } private static SourceLocation GetCallerLocation(SyntaxNode syntax, ThreeState enableCallerInfo) @@ -1115,7 +1121,7 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym /// must be passed in, where 'callerMemberName' must not be null if 'parameter.IsCallerMemberName' is 'true'. /// private static BoundExpression GetDefaultParameterValue( - SyntaxNode syntax, + SyntaxNode syntax, ParameterSymbol parameter, ThreeState enableCallerInfo, LocalRewriter localRewriter, @@ -1125,8 +1131,8 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym Debug.Assert(localRewriter == null ^ binder == null); Debug.Assert(diagnostics != null); - bool isLowering; - CSharpCompilation compilation; + bool isLowering; + CSharpCompilation compilation; if (localRewriter != null) { @@ -1135,8 +1141,8 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym } else { - isLowering = false; - compilation = binder.Compilation; + isLowering = false; + compilation = binder.Compilation; } // TODO: Ideally, the enableCallerInfo parameter would be of just bool type with only 'true' and 'false' values, and all callers @@ -1161,7 +1167,7 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym if (parameter.IsCallerLineNumber && ((callerSourceLocation = GetCallerLocation(syntax, enableCallerInfo)) != null)) { int line = callerSourceLocation.SourceTree.GetDisplayLineNumber(callerSourceLocation.SourceSpan); - + BoundExpression lineLiteral = MakeLiteral(syntax, ConstantValue.Create(line), compilation.GetSpecialType(SpecialType.System_Int32), localRewriter); if (parameterType.IsNullableType()) @@ -1179,7 +1185,7 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym else { defaultValue = MakeConversionNode(lineLiteral, parameterType, @checked: false); - } + } } else if (parameter.IsCallerFilePath && ((callerSourceLocation = GetCallerLocation(syntax, enableCallerInfo)) != null)) { @@ -1246,20 +1252,20 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym } } else - { - memberName = binder.ContainingMember().GetMemberCallerName(); + { + memberName = binder.ContainingMember().GetMemberCallerName(); } BoundExpression memberNameLiteral = MakeLiteral(syntax, ConstantValue.Create(memberName), compilation.GetSpecialType(SpecialType.System_String), localRewriter); defaultValue = MakeConversionNode(memberNameLiteral, parameterType, @checked: false); } else if (defaultConstantValue == ConstantValue.NotAvailable) - { + { // There is no constant value given for the parameter in source/metadata. if (parameterType.IsDynamic() || parameterType.SpecialType == SpecialType.System_Object) { // We have something like M([Optional] object x). We have special handling for such situations. - defaultValue = isLowering + defaultValue = isLowering ? localRewriter.GetDefaultParameterSpecial(syntax, parameter) : GetDefaultParameterSpecialForIOperation(syntax, parameter, compilation, diagnostics); } @@ -1293,7 +1299,7 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym syntax, UnsafeGetNullableMethod(syntax, parameterType, SpecialMember.System_Nullable_T__ctor, compilation, diagnostics), null, - defaultValue); + defaultValue); } else if (defaultConstantValue.IsNull || defaultConstantValue.IsBad) { @@ -1314,19 +1320,19 @@ private BoundExpression GetDefaultParameterValue(SyntaxNode syntax, ParameterSym BoundExpression MakeConversionNode(BoundExpression operand, TypeSymbol type, bool @checked, bool acceptFailingConversion = false) { if (isLowering) - { + { return localRewriter.MakeConversionNode(operand, type, @checked, acceptFailingConversion); } else - { + { return MakeConversionForIOperation(operand, type, syntax, compilation, diagnostics, @checked, acceptFailingConversion); } } - } + } private BoundExpression GetDefaultParameterSpecial(SyntaxNode syntax, ParameterSymbol parameter) { - BoundExpression defaultValue = GetDefaultParameterSpecialNoConversion(syntax, parameter, this._compilation); + BoundExpression defaultValue = GetDefaultParameterSpecialNoConversion(syntax, parameter, this._compilation); return MakeConversionNode(defaultValue, parameter.Type, @checked: false); } @@ -1375,7 +1381,7 @@ private static BoundExpression GetDefaultParameterSpecialNoConversion(SyntaxNode // Type.Missing var fieldSymbol = (FieldSymbol)compilation.GetWellKnownTypeMember(WellKnownMember.System_Type__Missing); defaultValue = new BoundFieldAccess(syntax, null, fieldSymbol, ConstantValue.NotAvailable); - } + } return defaultValue; } diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs index 823facd6a3f..2cee5ba7d60 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs @@ -2,30 +2,27 @@ using System; using System.Collections.Immutable; -using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Symbols; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Semantics { - internal static partial class CSharpOperationFactory + internal partial class CSharpOperationFactory { - private static readonly ConditionalWeakTable s_cache = new ConditionalWeakTable(); + private readonly OperationCache _cache = new OperationCache(); - public static IOperation Create(BoundNode boundNode) + public IOperation Create(BoundNode boundNode) { if (boundNode == null) { return null; } - return s_cache.GetValue(boundNode, n => CreateInternal(n)); + return _cache.GetValue(boundNode, n => CreateInternal(n)); } - private static IOperation CreateInternal(BoundNode boundNode) + private IOperation CreateInternal(BoundNode boundNode) { switch (boundNode.Kind) { @@ -177,7 +174,7 @@ private static IOperation CreateInternal(BoundNode boundNode) } } - private static ImmutableArray GetIOperationChildren(BoundNode boundNode) + private ImmutableArray GetIOperationChildren(BoundNode boundNode) { var boundNodeWithChildren = (IBoundNodeWithIOperationChildren)boundNode; if (boundNodeWithChildren.Children.IsDefaultOrEmpty) @@ -195,7 +192,7 @@ private static ImmutableArray GetIOperationChildren(BoundNode boundN return builder.ToImmutableAndFree(); } - private static IPlaceholderExpression CreateBoundDeconstructValuePlaceholderOperation(BoundDeconstructValuePlaceholder boundDeconstructValuePlaceholder) + private IPlaceholderExpression CreateBoundDeconstructValuePlaceholderOperation(BoundDeconstructValuePlaceholder boundDeconstructValuePlaceholder) { bool isInvalid = boundDeconstructValuePlaceholder.HasErrors; SyntaxNode syntax = boundDeconstructValuePlaceholder.Syntax; @@ -204,7 +201,7 @@ private static IPlaceholderExpression CreateBoundDeconstructValuePlaceholderOper return new PlaceholderExpression(isInvalid, syntax, type, constantValue); } - private static IInvocationExpression CreateBoundCallOperation(BoundCall boundCall) + private IInvocationExpression CreateBoundCallOperation(BoundCall boundCall) { IMethodSymbol targetMethod = boundCall.Method; Lazy instance = new Lazy(() => Create(((object)boundCall.Method == null || boundCall.Method.IsStatic) ? null : boundCall.ReceiverOpt)); @@ -220,7 +217,7 @@ private static IInvocationExpression CreateBoundCallOperation(BoundCall boundCal return new LazyInvocationExpression(targetMethod, instance, isVirtual, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue); } - private static ILocalReferenceExpression CreateBoundLocalOperation(BoundLocal boundLocal) + private ILocalReferenceExpression CreateBoundLocalOperation(BoundLocal boundLocal) { ILocalSymbol local = boundLocal.LocalSymbol; bool isInvalid = boundLocal.HasErrors; @@ -230,7 +227,7 @@ private static ILocalReferenceExpression CreateBoundLocalOperation(BoundLocal bo return new LocalReferenceExpression(local, isInvalid, syntax, type, constantValue); } - private static IFieldReferenceExpression CreateBoundFieldAccessOperation(BoundFieldAccess boundFieldAccess) + private IFieldReferenceExpression CreateBoundFieldAccessOperation(BoundFieldAccess boundFieldAccess) { IFieldSymbol field = boundFieldAccess.FieldSymbol; Lazy instance = new Lazy(() => Create(boundFieldAccess.FieldSymbol.IsStatic ? null : boundFieldAccess.ReceiverOpt)); @@ -242,7 +239,7 @@ private static IFieldReferenceExpression CreateBoundFieldAccessOperation(BoundFi return new LazyFieldReferenceExpression(field, instance, member, isInvalid, syntax, type, constantValue); } - private static IPropertyReferenceExpression CreateBoundPropertyAccessOperation(BoundPropertyAccess boundPropertyAccess) + private IPropertyReferenceExpression CreateBoundPropertyAccessOperation(BoundPropertyAccess boundPropertyAccess) { IPropertySymbol property = boundPropertyAccess.PropertySymbol; Lazy instance = new Lazy(() => Create(boundPropertyAccess.PropertySymbol.IsStatic ? null : boundPropertyAccess.ReceiverOpt)); @@ -254,7 +251,7 @@ private static IPropertyReferenceExpression CreateBoundPropertyAccessOperation(B return new LazyPropertyReferenceExpression(property, instance, member, isInvalid, syntax, type, constantValue); } - private static IIndexedPropertyReferenceExpression CreateBoundIndexerAccessOperation(BoundIndexerAccess boundIndexerAccess) + private IIndexedPropertyReferenceExpression CreateBoundIndexerAccessOperation(BoundIndexerAccess boundIndexerAccess) { IPropertySymbol property = boundIndexerAccess.Indexer; Lazy instance = new Lazy(() => Create(boundIndexerAccess.Indexer.IsStatic ? null : boundIndexerAccess.ReceiverOpt)); @@ -286,7 +283,7 @@ private static IIndexedPropertyReferenceExpression CreateBoundIndexerAccessOpera return new LazyIndexedPropertyReferenceExpression(property, instance, member, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue); } - private static IEventReferenceExpression CreateBoundEventAccessOperation(BoundEventAccess boundEventAccess) + private IEventReferenceExpression CreateBoundEventAccessOperation(BoundEventAccess boundEventAccess) { IEventSymbol @event = boundEventAccess.EventSymbol; Lazy instance = new Lazy(() => Create(boundEventAccess.EventSymbol.IsStatic ? null : boundEventAccess.ReceiverOpt)); @@ -298,7 +295,7 @@ private static IEventReferenceExpression CreateBoundEventAccessOperation(BoundEv return new LazyEventReferenceExpression(@event, instance, member, isInvalid, syntax, type, constantValue); } - private static IEventAssignmentExpression CreateBoundEventAssignmentOperatorOperation(BoundEventAssignmentOperator boundEventAssignmentOperator) + private IEventAssignmentExpression CreateBoundEventAssignmentOperatorOperation(BoundEventAssignmentOperator boundEventAssignmentOperator) { IEventSymbol @event = boundEventAssignmentOperator.Event; Lazy eventInstance = new Lazy(() => Create(boundEventAssignmentOperator.Event.IsStatic ? null : boundEventAssignmentOperator.ReceiverOpt)); @@ -311,7 +308,7 @@ private static IEventAssignmentExpression CreateBoundEventAssignmentOperatorOper return new LazyEventAssignmentExpression(@event, eventInstance, handlerValue, adds, isInvalid, syntax, type, constantValue); } - private static IParameterReferenceExpression CreateBoundParameterOperation(BoundParameter boundParameter) + private IParameterReferenceExpression CreateBoundParameterOperation(BoundParameter boundParameter) { IParameterSymbol parameter = boundParameter.ParameterSymbol; bool isInvalid = boundParameter.HasErrors; @@ -321,7 +318,7 @@ private static IParameterReferenceExpression CreateBoundParameterOperation(Bound return new ParameterReferenceExpression(parameter, isInvalid, syntax, type, constantValue); } - private static ILiteralExpression CreateBoundLiteralOperation(BoundLiteral boundLiteral) + private ILiteralExpression CreateBoundLiteralOperation(BoundLiteral boundLiteral) { string text = boundLiteral.Syntax.ToString(); bool isInvalid = boundLiteral.HasErrors; @@ -331,7 +328,7 @@ private static ILiteralExpression CreateBoundLiteralOperation(BoundLiteral bound return new LiteralExpression(text, isInvalid, syntax, type, constantValue); } - private static IObjectCreationExpression CreateBoundObjectCreationExpressionOperation(BoundObjectCreationExpression boundObjectCreationExpression) + private IObjectCreationExpression CreateBoundObjectCreationExpressionOperation(BoundObjectCreationExpression boundObjectCreationExpression) { IMethodSymbol constructor = boundObjectCreationExpression.Constructor; Lazy> memberInitializers = new Lazy>(() => GetObjectCreationInitializers(boundObjectCreationExpression)); @@ -354,7 +351,7 @@ private static IObjectCreationExpression CreateBoundObjectCreationExpressionOper return new LazyObjectCreationExpression(constructor, memberInitializers, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue); } - private static IUnboundLambdaExpression CreateUnboundLambdaOperation(UnboundLambda unboundLambda) + private IUnboundLambdaExpression CreateUnboundLambdaOperation(UnboundLambda unboundLambda) { bool isInvalid = unboundLambda.HasErrors; SyntaxNode syntax = unboundLambda.Syntax; @@ -367,7 +364,7 @@ private static IUnboundLambdaExpression CreateUnboundLambdaOperation(UnboundLamb return new UnboundLambdaExpression(isInvalid, syntax, type, constantValue); } - private static ILambdaExpression CreateBoundLambdaOperation(BoundLambda boundLambda) + private ILambdaExpression CreateBoundLambdaOperation(BoundLambda boundLambda) { IMethodSymbol signature = boundLambda.Symbol; Lazy body = new Lazy(() => (IBlockStatement)Create(boundLambda.Body)); @@ -382,7 +379,7 @@ private static ILambdaExpression CreateBoundLambdaOperation(BoundLambda boundLam return new LazyLambdaExpression(signature, body, isInvalid, syntax, type, constantValue); } - private static IOperation CreateBoundConversionOperation(BoundConversion boundConversion) + private IOperation CreateBoundConversionOperation(BoundConversion boundConversion) { ConversionKind conversionKind = GetConversionKind(boundConversion.ConversionKind); if (boundConversion.ConversionKind == CSharp.ConversionKind.MethodGroup) @@ -411,7 +408,7 @@ private static IOperation CreateBoundConversionOperation(BoundConversion boundCo } } - private static IConversionExpression CreateBoundAsOperatorOperation(BoundAsOperator boundAsOperator) + private IConversionExpression CreateBoundAsOperatorOperation(BoundAsOperator boundAsOperator) { Lazy operand = new Lazy(() => Create(boundAsOperator.Operand)); ConversionKind conversionKind = Semantics.ConversionKind.TryCast; @@ -425,7 +422,7 @@ private static IConversionExpression CreateBoundAsOperatorOperation(BoundAsOpera return new LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue); } - private static IIsTypeExpression CreateBoundIsOperatorOperation(BoundIsOperator boundIsOperator) + private IIsTypeExpression CreateBoundIsOperatorOperation(BoundIsOperator boundIsOperator) { Lazy operand = new Lazy(() => Create(boundIsOperator.Operand)); ITypeSymbol isType = boundIsOperator.TargetType.Type; @@ -436,7 +433,7 @@ private static IIsTypeExpression CreateBoundIsOperatorOperation(BoundIsOperator return new LazyIsTypeExpression(operand, isType, isInvalid, syntax, type, constantValue); } - private static ISizeOfExpression CreateBoundSizeOfOperatorOperation(BoundSizeOfOperator boundSizeOfOperator) + private ISizeOfExpression CreateBoundSizeOfOperatorOperation(BoundSizeOfOperator boundSizeOfOperator) { ITypeSymbol typeOperand = boundSizeOfOperator.SourceType.Type; bool isInvalid = boundSizeOfOperator.HasErrors; @@ -446,7 +443,7 @@ private static ISizeOfExpression CreateBoundSizeOfOperatorOperation(BoundSizeOfO return new SizeOfExpression(typeOperand, isInvalid, syntax, type, constantValue); } - private static ITypeOfExpression CreateBoundTypeOfOperatorOperation(BoundTypeOfOperator boundTypeOfOperator) + private ITypeOfExpression CreateBoundTypeOfOperatorOperation(BoundTypeOfOperator boundTypeOfOperator) { ITypeSymbol typeOperand = boundTypeOfOperator.SourceType.Type; bool isInvalid = boundTypeOfOperator.HasErrors; @@ -456,7 +453,7 @@ private static ITypeOfExpression CreateBoundTypeOfOperatorOperation(BoundTypeOfO return new TypeOfExpression(typeOperand, isInvalid, syntax, type, constantValue); } - private static IArrayCreationExpression CreateBoundArrayCreationOperation(BoundArrayCreation boundArrayCreation) + private IArrayCreationExpression CreateBoundArrayCreationOperation(BoundArrayCreation boundArrayCreation) { ITypeSymbol elementType = GetArrayCreationElementType(boundArrayCreation); Lazy> dimensionSizes = new Lazy>(() => boundArrayCreation.Bounds.SelectAsArray(n => Create(n))); @@ -468,7 +465,7 @@ private static IArrayCreationExpression CreateBoundArrayCreationOperation(BoundA return new LazyArrayCreationExpression(elementType, dimensionSizes, initializer, isInvalid, syntax, type, constantValue); } - private static IArrayInitializer CreateBoundArrayInitializationOperation(BoundArrayInitialization boundArrayInitialization) + private IArrayInitializer CreateBoundArrayInitializationOperation(BoundArrayInitialization boundArrayInitialization) { Lazy> elementValues = new Lazy>(() => boundArrayInitialization.Initializers.SelectAsArray(n => Create(n))); bool isInvalid = boundArrayInitialization.HasErrors; @@ -478,7 +475,7 @@ private static IArrayInitializer CreateBoundArrayInitializationOperation(BoundAr return new LazyArrayInitializer(elementValues, isInvalid, syntax, type, constantValue); } - private static IDefaultValueExpression CreateBoundDefaultExpressionOperation(BoundDefaultExpression boundDefaultExpression) + private IDefaultValueExpression CreateBoundDefaultExpressionOperation(BoundDefaultExpression boundDefaultExpression) { bool isInvalid = boundDefaultExpression.HasErrors; SyntaxNode syntax = boundDefaultExpression.Syntax; @@ -487,7 +484,7 @@ private static IDefaultValueExpression CreateBoundDefaultExpressionOperation(Bou return new DefaultValueExpression(isInvalid, syntax, type, constantValue); } - private static IInstanceReferenceExpression CreateBoundBaseReferenceOperation(BoundBaseReference boundBaseReference) + private IInstanceReferenceExpression CreateBoundBaseReferenceOperation(BoundBaseReference boundBaseReference) { InstanceReferenceKind instanceReferenceKind = InstanceReferenceKind.BaseClass; bool isInvalid = boundBaseReference.HasErrors; @@ -497,7 +494,7 @@ private static IInstanceReferenceExpression CreateBoundBaseReferenceOperation(Bo return new InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue); } - private static IInstanceReferenceExpression CreateBoundThisReferenceOperation(BoundThisReference boundThisReference) + private IInstanceReferenceExpression CreateBoundThisReferenceOperation(BoundThisReference boundThisReference) { InstanceReferenceKind instanceReferenceKind = boundThisReference.Syntax.Kind() == SyntaxKind.ThisExpression ? InstanceReferenceKind.Explicit : InstanceReferenceKind.Implicit; bool isInvalid = boundThisReference.HasErrors; @@ -507,7 +504,7 @@ private static IInstanceReferenceExpression CreateBoundThisReferenceOperation(Bo return new InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue); } - private static IAssignmentExpression CreateBoundAssignmentOperatorOperation(BoundAssignmentOperator boundAssignmentOperator) + private IAssignmentExpression CreateBoundAssignmentOperatorOperation(BoundAssignmentOperator boundAssignmentOperator) { Lazy target = new Lazy(() => Create(boundAssignmentOperator.Left)); Lazy value = new Lazy(() => Create(boundAssignmentOperator.Right)); @@ -518,7 +515,7 @@ private static IAssignmentExpression CreateBoundAssignmentOperatorOperation(Boun return new LazyAssignmentExpression(target, value, isInvalid, syntax, type, constantValue); } - private static ICompoundAssignmentExpression CreateBoundCompoundAssignmentOperatorOperation(BoundCompoundAssignmentOperator boundCompoundAssignmentOperator) + private ICompoundAssignmentExpression CreateBoundCompoundAssignmentOperatorOperation(BoundCompoundAssignmentOperator boundCompoundAssignmentOperator) { BinaryOperationKind binaryOperationKind = Helper.DeriveBinaryOperationKind(boundCompoundAssignmentOperator.Operator.Kind); Lazy target = new Lazy(() => Create(boundCompoundAssignmentOperator.Left)); @@ -532,7 +529,7 @@ private static ICompoundAssignmentExpression CreateBoundCompoundAssignmentOperat return new LazyCompoundAssignmentExpression(binaryOperationKind, target, value, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue); } - private static IIncrementExpression CreateBoundIncrementOperatorOperation(BoundIncrementOperator boundIncrementOperator) + private IIncrementExpression CreateBoundIncrementOperatorOperation(BoundIncrementOperator boundIncrementOperator) { UnaryOperationKind incrementOperationKind = Helper.DeriveUnaryOperationKind(boundIncrementOperator.OperatorKind); BinaryOperationKind binaryOperationKind = Helper.DeriveBinaryOperationKind(incrementOperationKind); @@ -547,7 +544,7 @@ private static IIncrementExpression CreateBoundIncrementOperatorOperation(BoundI return new LazyIncrementExpression(incrementOperationKind, binaryOperationKind, target, value, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue); } - private static IInvalidExpression CreateBoundBadExpressionOperation(BoundBadExpression boundBadExpression) + private IInvalidExpression CreateBoundBadExpressionOperation(BoundBadExpression boundBadExpression) { Lazy> children = new Lazy>(() => boundBadExpression.ChildBoundNodes.SelectAsArray(n => Create(n))); bool isInvalid = boundBadExpression.HasErrors; @@ -557,7 +554,7 @@ private static IInvalidExpression CreateBoundBadExpressionOperation(BoundBadExpr return new LazyInvalidExpression(children, isInvalid, syntax, type, constantValue); } - private static ITypeParameterObjectCreationExpression CreateBoundNewTOperation(BoundNewT boundNewT) + private ITypeParameterObjectCreationExpression CreateBoundNewTOperation(BoundNewT boundNewT) { bool isInvalid = boundNewT.HasErrors; SyntaxNode syntax = boundNewT.Syntax; @@ -566,7 +563,7 @@ private static ITypeParameterObjectCreationExpression CreateBoundNewTOperation(B return new TypeParameterObjectCreationExpression(isInvalid, syntax, type, constantValue); } - private static IUnaryOperatorExpression CreateBoundUnaryOperatorOperation(BoundUnaryOperator boundUnaryOperator) + private IUnaryOperatorExpression CreateBoundUnaryOperatorOperation(BoundUnaryOperator boundUnaryOperator) { UnaryOperationKind unaryOperationKind = Helper.DeriveUnaryOperationKind(boundUnaryOperator.OperatorKind); Lazy operand = new Lazy(() => Create(boundUnaryOperator.Operand)); @@ -579,7 +576,7 @@ private static IUnaryOperatorExpression CreateBoundUnaryOperatorOperation(BoundU return new LazyUnaryOperatorExpression(unaryOperationKind, operand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue); } - private static IBinaryOperatorExpression CreateBoundBinaryOperatorOperation(BoundBinaryOperator boundBinaryOperator) + private IBinaryOperatorExpression CreateBoundBinaryOperatorOperation(BoundBinaryOperator boundBinaryOperator) { BinaryOperationKind binaryOperationKind = Helper.DeriveBinaryOperationKind(boundBinaryOperator.OperatorKind); Lazy leftOperand = new Lazy(() => Create(boundBinaryOperator.Left)); @@ -593,7 +590,7 @@ private static IBinaryOperatorExpression CreateBoundBinaryOperatorOperation(Boun return new LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue); } - private static IConditionalChoiceExpression CreateBoundConditionalOperatorOperation(BoundConditionalOperator boundConditionalOperator) + private IConditionalChoiceExpression CreateBoundConditionalOperatorOperation(BoundConditionalOperator boundConditionalOperator) { Lazy condition = new Lazy(() => Create(boundConditionalOperator.Condition)); Lazy ifTrueValue = new Lazy(() => Create(boundConditionalOperator.Consequence)); @@ -605,7 +602,7 @@ private static IConditionalChoiceExpression CreateBoundConditionalOperatorOperat return new LazyConditionalChoiceExpression(condition, ifTrueValue, ifFalseValue, isInvalid, syntax, type, constantValue); } - private static INullCoalescingExpression CreateBoundNullCoalescingOperatorOperation(BoundNullCoalescingOperator boundNullCoalescingOperator) + private INullCoalescingExpression CreateBoundNullCoalescingOperatorOperation(BoundNullCoalescingOperator boundNullCoalescingOperator) { Lazy primaryOperand = new Lazy(() => Create(boundNullCoalescingOperator.LeftOperand)); Lazy secondaryOperand = new Lazy(() => Create(boundNullCoalescingOperator.RightOperand)); @@ -616,7 +613,7 @@ private static INullCoalescingExpression CreateBoundNullCoalescingOperatorOperat return new LazyNullCoalescingExpression(primaryOperand, secondaryOperand, isInvalid, syntax, type, constantValue); } - private static IAwaitExpression CreateBoundAwaitExpressionOperation(BoundAwaitExpression boundAwaitExpression) + private IAwaitExpression CreateBoundAwaitExpressionOperation(BoundAwaitExpression boundAwaitExpression) { Lazy awaitedValue = new Lazy(() => Create(boundAwaitExpression.Expression)); bool isInvalid = boundAwaitExpression.HasErrors; @@ -626,7 +623,7 @@ private static IAwaitExpression CreateBoundAwaitExpressionOperation(BoundAwaitEx return new LazyAwaitExpression(awaitedValue, isInvalid, syntax, type, constantValue); } - private static IArrayElementReferenceExpression CreateBoundArrayAccessOperation(BoundArrayAccess boundArrayAccess) + private IArrayElementReferenceExpression CreateBoundArrayAccessOperation(BoundArrayAccess boundArrayAccess) { Lazy arrayReference = new Lazy(() => Create(boundArrayAccess.Expression)); Lazy> indices = new Lazy>(() => boundArrayAccess.Indices.SelectAsArray(n => Create(n))); @@ -637,7 +634,7 @@ private static IArrayElementReferenceExpression CreateBoundArrayAccessOperation( return new LazyArrayElementReferenceExpression(arrayReference, indices, isInvalid, syntax, type, constantValue); } - private static IPointerIndirectionReferenceExpression CreateBoundPointerIndirectionOperatorOperation(BoundPointerIndirectionOperator boundPointerIndirectionOperator) + private IPointerIndirectionReferenceExpression CreateBoundPointerIndirectionOperatorOperation(BoundPointerIndirectionOperator boundPointerIndirectionOperator) { Lazy pointer = new Lazy(() => Create(boundPointerIndirectionOperator.Operand)); bool isInvalid = boundPointerIndirectionOperator.HasErrors; @@ -647,7 +644,7 @@ private static IPointerIndirectionReferenceExpression CreateBoundPointerIndirect return new LazyPointerIndirectionReferenceExpression(pointer, isInvalid, syntax, type, constantValue); } - private static IAddressOfExpression CreateBoundAddressOfOperatorOperation(BoundAddressOfOperator boundAddressOfOperator) + private IAddressOfExpression CreateBoundAddressOfOperatorOperation(BoundAddressOfOperator boundAddressOfOperator) { Lazy reference = new Lazy(() => Create(boundAddressOfOperator.Operand)); bool isInvalid = boundAddressOfOperator.HasErrors; @@ -657,7 +654,7 @@ private static IAddressOfExpression CreateBoundAddressOfOperatorOperation(BoundA return new LazyAddressOfExpression(reference, isInvalid, syntax, type, constantValue); } - private static IInstanceReferenceExpression CreateBoundImplicitReceiverOperation(BoundImplicitReceiver boundImplicitReceiver) + private IInstanceReferenceExpression CreateBoundImplicitReceiverOperation(BoundImplicitReceiver boundImplicitReceiver) { InstanceReferenceKind instanceReferenceKind = InstanceReferenceKind.Implicit; bool isInvalid = boundImplicitReceiver.HasErrors; @@ -667,7 +664,7 @@ private static IInstanceReferenceExpression CreateBoundImplicitReceiverOperation return new InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue); } - private static IConditionalAccessExpression CreateBoundConditionalAccessOperation(BoundConditionalAccess boundConditionalAccess) + private IConditionalAccessExpression CreateBoundConditionalAccessOperation(BoundConditionalAccess boundConditionalAccess) { Lazy conditionalValue = new Lazy(() => Create(boundConditionalAccess.AccessExpression)); Lazy conditionalInstance = new Lazy(() => Create(boundConditionalAccess.Receiver)); @@ -678,7 +675,7 @@ private static IConditionalAccessExpression CreateBoundConditionalAccessOperatio return new LazyConditionalAccessExpression(conditionalValue, conditionalInstance, isInvalid, syntax, type, constantValue); } - private static IConditionalAccessInstanceExpression CreateBoundConditionalReceiverOperation(BoundConditionalReceiver boundConditionalReceiver) + private IConditionalAccessInstanceExpression CreateBoundConditionalReceiverOperation(BoundConditionalReceiver boundConditionalReceiver) { bool isInvalid = boundConditionalReceiver.HasErrors; SyntaxNode syntax = boundConditionalReceiver.Syntax; @@ -687,7 +684,7 @@ private static IConditionalAccessInstanceExpression CreateBoundConditionalReceiv return new ConditionalAccessInstanceExpression(isInvalid, syntax, type, constantValue); } - private static IFieldInitializer CreateBoundFieldEqualsValueOperation(BoundFieldEqualsValue boundFieldEqualsValue) + private IFieldInitializer CreateBoundFieldEqualsValueOperation(BoundFieldEqualsValue boundFieldEqualsValue) { ImmutableArray initializedFields = ImmutableArray.Create(boundFieldEqualsValue.Field); Lazy value = new Lazy(() => Create(boundFieldEqualsValue.Value)); @@ -699,7 +696,7 @@ private static IFieldInitializer CreateBoundFieldEqualsValueOperation(BoundField return new LazyFieldInitializer(initializedFields, value, kind, isInvalid, syntax, type, constantValue); } - private static IPropertyInitializer CreateBoundPropertyEqualsValueOperation(BoundPropertyEqualsValue boundPropertyEqualsValue) + private IPropertyInitializer CreateBoundPropertyEqualsValueOperation(BoundPropertyEqualsValue boundPropertyEqualsValue) { IPropertySymbol initializedProperty = boundPropertyEqualsValue.Property; Lazy value = new Lazy(() => Create(boundPropertyEqualsValue.Value)); @@ -711,7 +708,7 @@ private static IPropertyInitializer CreateBoundPropertyEqualsValueOperation(Boun return new LazyPropertyInitializer(initializedProperty, value, kind, isInvalid, syntax, type, constantValue); } - private static IParameterInitializer CreateBoundParameterEqualsValueOperation(BoundParameterEqualsValue boundParameterEqualsValue) + private IParameterInitializer CreateBoundParameterEqualsValueOperation(BoundParameterEqualsValue boundParameterEqualsValue) { IParameterSymbol parameter = boundParameterEqualsValue.Parameter; Lazy value = new Lazy(() => Create(boundParameterEqualsValue.Value)); @@ -723,7 +720,7 @@ private static IParameterInitializer CreateBoundParameterEqualsValueOperation(Bo return new LazyParameterInitializer(parameter, value, kind, isInvalid, syntax, type, constantValue); } - private static IBlockStatement CreateBoundBlockOperation(BoundBlock boundBlock) + private IBlockStatement CreateBoundBlockOperation(BoundBlock boundBlock) { Lazy> statements = new Lazy>(() => GetBlockStatement(boundBlock)); ImmutableArray locals = boundBlock.Locals.As(); @@ -734,7 +731,7 @@ private static IBlockStatement CreateBoundBlockOperation(BoundBlock boundBlock) return new LazyBlockStatement(statements, locals, isInvalid, syntax, type, constantValue); } - private static IBranchStatement CreateBoundContinueStatementOperation(BoundContinueStatement boundContinueStatement) + private IBranchStatement CreateBoundContinueStatementOperation(BoundContinueStatement boundContinueStatement) { ILabelSymbol target = boundContinueStatement.Label; BranchKind branchKind = BranchKind.Continue; @@ -745,7 +742,7 @@ private static IBranchStatement CreateBoundContinueStatementOperation(BoundConti return new BranchStatement(target, branchKind, isInvalid, syntax, type, constantValue); } - private static IBranchStatement CreateBoundBreakStatementOperation(BoundBreakStatement boundBreakStatement) + private IBranchStatement CreateBoundBreakStatementOperation(BoundBreakStatement boundBreakStatement) { ILabelSymbol target = boundBreakStatement.Label; BranchKind branchKind = BranchKind.Break; @@ -756,7 +753,7 @@ private static IBranchStatement CreateBoundBreakStatementOperation(BoundBreakSta return new BranchStatement(target, branchKind, isInvalid, syntax, type, constantValue); } - private static IReturnStatement CreateBoundYieldBreakStatementOperation(BoundYieldBreakStatement boundYieldBreakStatement) + private IReturnStatement CreateBoundYieldBreakStatementOperation(BoundYieldBreakStatement boundYieldBreakStatement) { Lazy returnedValue = new Lazy(() => Create(null)); bool isInvalid = boundYieldBreakStatement.HasErrors; @@ -766,7 +763,7 @@ private static IReturnStatement CreateBoundYieldBreakStatementOperation(BoundYie return new LazyReturnStatement(returnedValue, isInvalid, syntax, type, constantValue); } - private static IBranchStatement CreateBoundGotoStatementOperation(BoundGotoStatement boundGotoStatement) + private IBranchStatement CreateBoundGotoStatementOperation(BoundGotoStatement boundGotoStatement) { ILabelSymbol target = boundGotoStatement.Label; BranchKind branchKind = BranchKind.GoTo; @@ -777,7 +774,7 @@ private static IBranchStatement CreateBoundGotoStatementOperation(BoundGotoState return new BranchStatement(target, branchKind, isInvalid, syntax, type, constantValue); } - private static IEmptyStatement CreateBoundNoOpStatementOperation(BoundNoOpStatement boundNoOpStatement) + private IEmptyStatement CreateBoundNoOpStatementOperation(BoundNoOpStatement boundNoOpStatement) { bool isInvalid = boundNoOpStatement.HasErrors; SyntaxNode syntax = boundNoOpStatement.Syntax; @@ -786,7 +783,7 @@ private static IEmptyStatement CreateBoundNoOpStatementOperation(BoundNoOpStatem return new EmptyStatement(isInvalid, syntax, type, constantValue); } - private static IIfStatement CreateBoundIfStatementOperation(BoundIfStatement boundIfStatement) + private IIfStatement CreateBoundIfStatementOperation(BoundIfStatement boundIfStatement) { Lazy condition = new Lazy(() => Create(boundIfStatement.Condition)); Lazy ifTrueStatement = new Lazy(() => Create(boundIfStatement.Consequence)); @@ -798,7 +795,7 @@ private static IIfStatement CreateBoundIfStatementOperation(BoundIfStatement bou return new LazyIfStatement(condition, ifTrueStatement, ifFalseStatement, isInvalid, syntax, type, constantValue); } - private static IWhileUntilLoopStatement CreateBoundWhileStatementOperation(BoundWhileStatement boundWhileStatement) + private IWhileUntilLoopStatement CreateBoundWhileStatementOperation(BoundWhileStatement boundWhileStatement) { bool isTopTest = true; bool isWhile = true; @@ -812,7 +809,7 @@ private static IWhileUntilLoopStatement CreateBoundWhileStatementOperation(Bound return new LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, loopKind, body, isInvalid, syntax, type, constantValue); } - private static IWhileUntilLoopStatement CreateBoundDoStatementOperation(BoundDoStatement boundDoStatement) + private IWhileUntilLoopStatement CreateBoundDoStatementOperation(BoundDoStatement boundDoStatement) { bool isTopTest = false; bool isWhile = true; @@ -826,7 +823,7 @@ private static IWhileUntilLoopStatement CreateBoundDoStatementOperation(BoundDoS return new LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, loopKind, body, isInvalid, syntax, type, constantValue); } - private static IForLoopStatement CreateBoundForStatementOperation(BoundForStatement boundForStatement) + private IForLoopStatement CreateBoundForStatementOperation(BoundForStatement boundForStatement) { Lazy> before = new Lazy>(() => ToStatements(boundForStatement.Initializer)); Lazy> atLoopBottom = new Lazy>(() => ToStatements(boundForStatement.Increment)); @@ -841,7 +838,7 @@ private static IForLoopStatement CreateBoundForStatementOperation(BoundForStatem return new LazyForLoopStatement(before, atLoopBottom, locals, condition, loopKind, body, isInvalid, syntax, type, constantValue); } - private static IForEachLoopStatement CreateBoundForEachStatementOperation(BoundForEachStatement boundForEachStatement) + private IForEachLoopStatement CreateBoundForEachStatementOperation(BoundForEachStatement boundForEachStatement) { ILocalSymbol iterationVariable = boundForEachStatement.IterationVariables.Length == 1 ? boundForEachStatement.IterationVariables.FirstOrDefault() : @@ -856,7 +853,7 @@ private static IForEachLoopStatement CreateBoundForEachStatementOperation(BoundF return new LazyForEachLoopStatement(iterationVariable, collection, loopKind, body, isInvalid, syntax, type, constantValue); } - private static ISwitchStatement CreateBoundSwitchStatementOperation(BoundSwitchStatement boundSwitchStatement) + private ISwitchStatement CreateBoundSwitchStatementOperation(BoundSwitchStatement boundSwitchStatement) { Lazy value = new Lazy(() => Create(boundSwitchStatement.Expression)); Lazy> cases = new Lazy>(() => GetSwitchStatementCases(boundSwitchStatement)); @@ -867,7 +864,7 @@ private static ISwitchStatement CreateBoundSwitchStatementOperation(BoundSwitchS return new LazySwitchStatement(value, cases, isInvalid, syntax, type, constantValue); } - private static ISingleValueCaseClause CreateBoundSwitchLabelOperation(BoundSwitchLabel boundSwitchLabel) + private ISingleValueCaseClause CreateBoundSwitchLabelOperation(BoundSwitchLabel boundSwitchLabel) { Lazy value = new Lazy(() => Create(boundSwitchLabel.ExpressionOpt)); BinaryOperationKind equality = GetLabelEqualityKind(boundSwitchLabel); @@ -879,7 +876,7 @@ private static ISingleValueCaseClause CreateBoundSwitchLabelOperation(BoundSwitc return new LazySingleValueCaseClause(value, equality, caseKind, isInvalid, syntax, type, constantValue); } - private static ITryStatement CreateBoundTryStatementOperation(BoundTryStatement boundTryStatement) + private ITryStatement CreateBoundTryStatementOperation(BoundTryStatement boundTryStatement) { Lazy body = new Lazy(() => (IBlockStatement)Create(boundTryStatement.TryBlock)); Lazy> catches = new Lazy>(() => boundTryStatement.CatchBlocks.SelectAsArray(n => (ICatchClause)Create(n))); @@ -891,7 +888,7 @@ private static ITryStatement CreateBoundTryStatementOperation(BoundTryStatement return new LazyTryStatement(body, catches, finallyHandler, isInvalid, syntax, type, constantValue); } - private static ICatchClause CreateBoundCatchBlockOperation(BoundCatchBlock boundCatchBlock) + private ICatchClause CreateBoundCatchBlockOperation(BoundCatchBlock boundCatchBlock) { Lazy handler = new Lazy(() => (IBlockStatement)Create(boundCatchBlock.Body)); ITypeSymbol caughtType = boundCatchBlock.ExceptionTypeOpt; @@ -904,7 +901,7 @@ private static ICatchClause CreateBoundCatchBlockOperation(BoundCatchBlock bound return new LazyCatchClause(handler, caughtType, filter, exceptionLocal, isInvalid, syntax, type, constantValue); } - private static IFixedStatement CreateBoundFixedStatementOperation(BoundFixedStatement boundFixedStatement) + private IFixedStatement CreateBoundFixedStatementOperation(BoundFixedStatement boundFixedStatement) { Lazy variables = new Lazy(() => (IVariableDeclarationStatement)Create(boundFixedStatement.Declarations)); Lazy body = new Lazy(() => Create(boundFixedStatement.Body)); @@ -915,7 +912,7 @@ private static IFixedStatement CreateBoundFixedStatementOperation(BoundFixedStat return new LazyFixedStatement(variables, body, isInvalid, syntax, type, constantValue); } - private static IUsingStatement CreateBoundUsingStatementOperation(BoundUsingStatement boundUsingStatement) + private IUsingStatement CreateBoundUsingStatementOperation(BoundUsingStatement boundUsingStatement) { Lazy body = new Lazy(() => Create(boundUsingStatement.Body)); Lazy declaration = new Lazy(() => (IVariableDeclarationStatement)Create(boundUsingStatement.DeclarationsOpt)); @@ -927,7 +924,7 @@ private static IUsingStatement CreateBoundUsingStatementOperation(BoundUsingStat return new LazyUsingStatement(body, declaration, value, isInvalid, syntax, type, constantValue); } - private static IThrowStatement CreateBoundThrowStatementOperation(BoundThrowStatement boundThrowStatement) + private IThrowStatement CreateBoundThrowStatementOperation(BoundThrowStatement boundThrowStatement) { Lazy thrownObject = new Lazy(() => Create(boundThrowStatement.ExpressionOpt)); bool isInvalid = boundThrowStatement.HasErrors; @@ -937,7 +934,7 @@ private static IThrowStatement CreateBoundThrowStatementOperation(BoundThrowStat return new LazyThrowStatement(thrownObject, isInvalid, syntax, type, constantValue); } - private static IReturnStatement CreateBoundReturnStatementOperation(BoundReturnStatement boundReturnStatement) + private IReturnStatement CreateBoundReturnStatementOperation(BoundReturnStatement boundReturnStatement) { Lazy returnedValue = new Lazy(() => Create(boundReturnStatement.ExpressionOpt)); bool isInvalid = boundReturnStatement.HasErrors; @@ -947,7 +944,7 @@ private static IReturnStatement CreateBoundReturnStatementOperation(BoundReturnS return new LazyReturnStatement(returnedValue, isInvalid, syntax, type, constantValue); } - private static IReturnStatement CreateBoundYieldReturnStatementOperation(BoundYieldReturnStatement boundYieldReturnStatement) + private IReturnStatement CreateBoundYieldReturnStatementOperation(BoundYieldReturnStatement boundYieldReturnStatement) { Lazy returnedValue = new Lazy(() => Create(boundYieldReturnStatement.Expression)); bool isInvalid = boundYieldReturnStatement.HasErrors; @@ -957,7 +954,7 @@ private static IReturnStatement CreateBoundYieldReturnStatementOperation(BoundYi return new LazyReturnStatement(returnedValue, isInvalid, syntax, type, constantValue); } - private static ILockStatement CreateBoundLockStatementOperation(BoundLockStatement boundLockStatement) + private ILockStatement CreateBoundLockStatementOperation(BoundLockStatement boundLockStatement) { Lazy lockedObject = new Lazy(() => Create(boundLockStatement.Argument)); Lazy body = new Lazy(() => Create(boundLockStatement.Body)); @@ -968,7 +965,7 @@ private static ILockStatement CreateBoundLockStatementOperation(BoundLockStateme return new LazyLockStatement(lockedObject, body, isInvalid, syntax, type, constantValue); } - private static IInvalidStatement CreateBoundBadStatementOperation(BoundBadStatement boundBadStatement) + private IInvalidStatement CreateBoundBadStatementOperation(BoundBadStatement boundBadStatement) { Lazy> children = new Lazy>(() => boundBadStatement.ChildBoundNodes.SelectAsArray(n => Create(n))); bool isInvalid = boundBadStatement.HasErrors; @@ -978,7 +975,7 @@ private static IInvalidStatement CreateBoundBadStatementOperation(BoundBadStatem return new LazyInvalidStatement(children, isInvalid, syntax, type, constantValue); } - private static IVariableDeclarationStatement CreateBoundLocalDeclarationOperation(BoundLocalDeclaration boundLocalDeclaration) + private IVariableDeclarationStatement CreateBoundLocalDeclarationOperation(BoundLocalDeclaration boundLocalDeclaration) { Lazy> declarations = new Lazy>(() => GetVariableDeclarationStatementVariables(boundLocalDeclaration)); bool isInvalid = boundLocalDeclaration.HasErrors; @@ -988,9 +985,9 @@ private static IVariableDeclarationStatement CreateBoundLocalDeclarationOperatio return new LazyVariableDeclarationStatement(declarations, isInvalid, syntax, type, constantValue); } - private static IVariableDeclarationStatement CreateBoundMultipleLocalDeclarationsOperation(BoundMultipleLocalDeclarations boundMultipleLocalDeclarations) + private IVariableDeclarationStatement CreateBoundMultipleLocalDeclarationsOperation(BoundMultipleLocalDeclarations boundMultipleLocalDeclarations) { - Lazy> declarations = new Lazy>(() => GetVariableDeclarationStatementVariables(boundMultipleLocalDeclarations)); + Lazy> declarations = new Lazy>(() => GetVariableMultipleDeclarationStatementVariables(boundMultipleLocalDeclarations)); bool isInvalid = boundMultipleLocalDeclarations.HasErrors; SyntaxNode syntax = boundMultipleLocalDeclarations.Syntax; ITypeSymbol type = null; @@ -998,7 +995,7 @@ private static IVariableDeclarationStatement CreateBoundMultipleLocalDeclaration return new LazyVariableDeclarationStatement(declarations, isInvalid, syntax, type, constantValue); } - private static ILabelStatement CreateBoundLabelStatementOperation(BoundLabelStatement boundLabelStatement) + private ILabelStatement CreateBoundLabelStatementOperation(BoundLabelStatement boundLabelStatement) { ILabelSymbol label = boundLabelStatement.Label; Lazy labeledStatement = new Lazy(() => Create(null)); @@ -1009,7 +1006,7 @@ private static ILabelStatement CreateBoundLabelStatementOperation(BoundLabelStat return new LazyLabelStatement(label, labeledStatement, isInvalid, syntax, type, constantValue); } - private static ILabelStatement CreateBoundLabeledStatementOperation(BoundLabeledStatement boundLabeledStatement) + private ILabelStatement CreateBoundLabeledStatementOperation(BoundLabeledStatement boundLabeledStatement) { ILabelSymbol label = boundLabeledStatement.Label; Lazy labeledStatement = new Lazy(() => Create(boundLabeledStatement.Body)); @@ -1020,7 +1017,7 @@ private static ILabelStatement CreateBoundLabeledStatementOperation(BoundLabeled return new LazyLabelStatement(label, labeledStatement, isInvalid, syntax, type, constantValue); } - private static IExpressionStatement CreateBoundExpressionStatementOperation(BoundExpressionStatement boundExpressionStatement) + private IExpressionStatement CreateBoundExpressionStatementOperation(BoundExpressionStatement boundExpressionStatement) { Lazy expression = new Lazy(() => Create(boundExpressionStatement.Expression)); bool isInvalid = boundExpressionStatement.HasErrors; @@ -1030,7 +1027,7 @@ private static IExpressionStatement CreateBoundExpressionStatementOperation(Boun return new LazyExpressionStatement(expression, isInvalid, syntax, type, constantValue); } - private static IInterpolatedStringExpression CreateBoundInterpolatedStringExpressionOperation(BoundInterpolatedString boundInterpolatedString) + private IInterpolatedStringExpression CreateBoundInterpolatedStringExpressionOperation(BoundInterpolatedString boundInterpolatedString) { Lazy> parts = new Lazy>(() => GetInterpolatedStringExpressionParts(boundInterpolatedString)); bool isInvalid = boundInterpolatedString.HasErrors; @@ -1040,7 +1037,7 @@ private static IInterpolatedStringExpression CreateBoundInterpolatedStringExpres return new LazyInterpolatedStringExpression(parts, isInvalid, syntax, type, constantValue); } - private static IInterpolatedStringContent CreateBoundInterpolatedStringContentOperation(BoundNode boundNode) + private IInterpolatedStringContent CreateBoundInterpolatedStringContentOperation(BoundNode boundNode) { if (boundNode.Kind == BoundKind.StringInsert) { @@ -1052,7 +1049,7 @@ private static IInterpolatedStringContent CreateBoundInterpolatedStringContentOp } } - private static IInterpolation CreateBoundInterpolationOperation(BoundStringInsert boundStringInsert) + private IInterpolation CreateBoundInterpolationOperation(BoundStringInsert boundStringInsert) { Lazy expression = new Lazy(() => Create(boundStringInsert.Value)); Lazy alignment = new Lazy(() => Create(boundStringInsert.Alignment)); @@ -1064,7 +1061,7 @@ private static IInterpolation CreateBoundInterpolationOperation(BoundStringInser return new LazyInterpolation(expression, alignment, format, isInvalid, syntax, type, constantValue); } - private static IInterpolatedStringText CreateBoundInterpolatedStringTextOperation(BoundNode boundNode) + private IInterpolatedStringText CreateBoundInterpolatedStringTextOperation(BoundNode boundNode) { Lazy text = new Lazy(() => Create(boundNode)); bool isInvalid = boundNode.HasErrors; diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs index 7400e73c850..d9351fc9693 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs @@ -1,24 +1,22 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using System.Runtime.CompilerServices; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Symbols; namespace Microsoft.CodeAnalysis.Semantics { - internal static partial class CSharpOperationFactory + internal partial class CSharpOperationFactory { private static Optional ConvertToOptional(ConstantValue value) { return value != null ? new Optional(value.Value) : default(Optional); } - private static ImmutableArray ToStatements(BoundStatement statement) + private ImmutableArray ToStatements(BoundStatement statement) { - BoundStatementList statementList = statement as BoundStatementList; + var statementList = statement as BoundStatementList; if (statementList != null) { return statementList.Statements.SelectAsArray(n => Create(n)); @@ -31,11 +29,9 @@ private static ImmutableArray ToStatements(BoundStatement statement) return ImmutableArray.Create(Create(statement)); } - private static readonly ConditionalWeakTable s_incrementValueMappings = new ConditionalWeakTable(); - - private static ILiteralExpression CreateIncrementOneLiteralExpression(BoundIncrementOperator boundIncrementOperator) + private ILiteralExpression CreateIncrementOneLiteralExpression(BoundIncrementOperator boundIncrementOperator) { - return s_incrementValueMappings.GetValue(boundIncrementOperator, (increment) => + return _cache.GetValue(boundIncrementOperator, nameof(CreateIncrementOneLiteralExpression), (increment) => { string text = increment.Syntax.ToString(); bool isInvalid = false; @@ -46,9 +42,6 @@ private static ILiteralExpression CreateIncrementOneLiteralExpression(BoundIncre }); } - private static readonly ConditionalWeakTable> s_callToArgumentsMappings - = new ConditionalWeakTable>(); - internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterSymbol parameter, IOperation value) { return new Argument(kind, @@ -59,10 +52,10 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS isInvalid: parameter == null || value.IsInvalid, syntax: value.Syntax, type: value.Type, - constantValue: default(Optional)); + constantValue: default); } - private static ImmutableArray DeriveArguments( + private ImmutableArray DeriveArguments( BoundExpression boundNode, Binder binder, Symbol methodOrIndexer, @@ -84,8 +77,8 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS return ImmutableArray.Empty; } - return (ImmutableArray)s_callToArgumentsMappings.GetValue( - boundNode, + return _cache.GetValue( + boundNode, nameof(DeriveArguments), (n) => { //TODO: https://github.com/dotnet/roslyn/issues/18722 @@ -99,6 +92,7 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS } return LocalRewriter.MakeArgumentsInEvaluationOrder( + operationFactory: this, binder: binder, syntax: invocationSyntax, arguments: boundArguments, @@ -110,7 +104,7 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS }); } - private static ImmutableArray GetObjectCreationInitializers(BoundObjectCreationExpression expression) + private ImmutableArray GetObjectCreationInitializers(BoundObjectCreationExpression expression) { return BoundObjectCreationExpression.GetChildInitializers(expression.InitializerExpressionOpt).SelectAsArray(n => Create(n)); } @@ -170,25 +164,19 @@ private static ITypeSymbol GetArrayCreationElementType(BoundArrayCreation creati return null; } - private static readonly ConditionalWeakTable s_blockStatementsMappings = - new ConditionalWeakTable(); - - private static ImmutableArray GetBlockStatement(BoundBlock block) + private ImmutableArray GetBlockStatement(BoundBlock block) { // This is to filter out operations of kind None. - return (ImmutableArray)s_blockStatementsMappings.GetValue(block, + return _cache.GetValue(block, nameof(GetBlockStatement), blockStatement => { return blockStatement.Statements.Select(s => Create(s)).Where(s => s.Kind != OperationKind.None).ToImmutableArray(); }); } - private static readonly ConditionalWeakTable s_switchSectionsMappings = - new ConditionalWeakTable(); - - private static ImmutableArray GetSwitchStatementCases(BoundSwitchStatement statement) + private ImmutableArray GetSwitchStatementCases(BoundSwitchStatement statement) { - return (ImmutableArray)s_switchSectionsMappings.GetValue(statement, + return _cache.GetValue(statement, nameof(GetSwitchStatementCases), switchStatement => { return switchStatement.SwitchSections.SelectAsArray(switchSection => @@ -238,33 +226,24 @@ private static BinaryOperationKind GetLabelEqualityKind(BoundSwitchLabel label) return BinaryOperationKind.None; } - private static readonly ConditionalWeakTable s_variablesMappings = - new ConditionalWeakTable(); - - private static ImmutableArray GetVariableDeclarationStatementVariables(BoundLocalDeclaration decl) + private ImmutableArray GetVariableDeclarationStatementVariables(BoundLocalDeclaration decl) { - return (ImmutableArray)s_variablesMappings.GetValue(decl, - declaration => ImmutableArray.Create( + return _cache.GetValue(decl, nameof(GetVariableDeclarationStatementVariables), + declaration => ImmutableArray.Create( OperationFactory.CreateVariableDeclaration(declaration.LocalSymbol, Create(declaration.InitializerOpt), declaration.Syntax))); } - private static readonly ConditionalWeakTable s_multiVariablesMappings = - new ConditionalWeakTable(); - - private static ImmutableArray GetVariableDeclarationStatementVariables(BoundMultipleLocalDeclarations decl) + private ImmutableArray GetVariableMultipleDeclarationStatementVariables(BoundMultipleLocalDeclarations decl) { - return (ImmutableArray)s_multiVariablesMappings.GetValue(decl, + return _cache.GetValue(decl, nameof(GetVariableMultipleDeclarationStatementVariables), multipleDeclarations => multipleDeclarations.LocalDeclarations.SelectAsArray(declaration => OperationFactory.CreateVariableDeclaration(declaration.LocalSymbol, Create(declaration.InitializerOpt), declaration.Syntax))); } - private static readonly ConditionalWeakTable s_interpolatedStringExpressionMappings = - new ConditionalWeakTable(); - - private static ImmutableArray GetInterpolatedStringExpressionParts(BoundInterpolatedString boundInterpolatedString) + private ImmutableArray GetInterpolatedStringExpressionParts(BoundInterpolatedString boundInterpolatedString) { - return (ImmutableArray)s_interpolatedStringExpressionMappings.GetValue(boundInterpolatedString, + return _cache.GetValue(boundInterpolatedString, nameof(GetInterpolatedStringExpressionParts), interpolatedString => interpolatedString.Parts.SelectAsArray(interpolatedStringContent => CreateBoundInterpolatedStringContentOperation(interpolatedStringContent))); } diff --git a/src/Compilers/Core/Portable/CodeAnalysis.csproj b/src/Compilers/Core/Portable/CodeAnalysis.csproj index c40ddb2c020..fd1f929c5c9 100644 --- a/src/Compilers/Core/Portable/CodeAnalysis.csproj +++ b/src/Compilers/Core/Portable/CodeAnalysis.csproj @@ -100,6 +100,7 @@ + diff --git a/src/Compilers/Core/Portable/Operations/OperationCache.cs b/src/Compilers/Core/Portable/Operations/OperationCache.cs new file mode 100644 index 00000000000..b19365b4297 --- /dev/null +++ b/src/Compilers/Core/Portable/Operations/OperationCache.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; + +namespace Microsoft.CodeAnalysis +{ + internal class OperationCache + { + private readonly ConcurrentDictionary<(TBoundNode key, string kind), object> _cache = + new ConcurrentDictionary<(TBoundNode key, string kind), object>(concurrencyLevel: 2, capacity: 10); + + public TRet GetValue(TNode key, Func creator) + where TNode : TBoundNode + { + return GetValue(key, "Root", creator); + } + + public TRet GetValue(TNode key, string kind, Func creator) + where TNode : TBoundNode + { + return (TRet)_cache.GetOrAdd((key, kind), kv => creator((TNode)kv.key)); + } + } +} diff --git a/src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb b/src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb index 9f8f47bf8ad..9c274fc501c 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb @@ -25,6 +25,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Private ReadOnly _speculatedPosition As Integer Private ReadOnly _ignoresAccessibility As Boolean + Private ReadOnly _operationFactory As VisualBasicOperationFactory + Friend Sub New(root As SyntaxNode, rootBinder As Binder, parentSemanticModelOpt As SyntaxTreeSemanticModel, speculatedPosition As Integer, Optional ignoreAccessibility As Boolean = False) Debug.Assert(parentSemanticModelOpt Is Nothing OrElse Not parentSemanticModelOpt.IsSpeculativeSemanticModel, VBResources.ChainingSpeculativeModelIsNotSupported) @@ -33,6 +35,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic _rootBinder = SemanticModelBinder.Mark(rootBinder, ignoreAccessibility) _parentSemanticModelOpt = parentSemanticModelOpt _speculatedPosition = speculatedPosition + + _operationFactory = New VisualBasicOperationFactory() End Sub Friend ReadOnly Property RootBinder As Binder @@ -800,7 +804,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic result = summary.LowestBoundNode End Select - Return VisualBasicOperationFactory.Create(result) + Return _operationFactory.Create(result) End Function Friend Overrides Function GetExpressionTypeInfo(node As ExpressionSyntax, Optional cancellationToken As CancellationToken = Nothing) As VisualBasicTypeInfo diff --git a/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb b/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb index e4d98f3e765..d6a33c35e02 100644 --- a/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb +++ b/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb @@ -1,23 +1,22 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Collections.Immutable -Imports System.Runtime.CompilerServices Imports Microsoft.CodeAnalysis.VisualBasic Namespace Microsoft.CodeAnalysis.Semantics - Partial Friend NotInheritable Class VisualBasicOperationFactory + Partial Friend Class VisualBasicOperationFactory - Private Shared ReadOnly s_cache As New ConditionalWeakTable(Of BoundNode, IOperation) + Private ReadOnly _cache As New OperationCache(Of BoundNode) - Public Shared Function Create(boundNode As BoundNode) As IOperation + Public Function Create(boundNode As BoundNode) As IOperation If boundNode Is Nothing Then Return Nothing End If - Return s_cache.GetValue(boundNode, Function(n) CreateInternal(n)) + Return _cache.GetValue(boundNode, Function(n) CreateInternal(n)) End Function - Private Shared Function CreateInternal(boundNode As BoundNode) As IOperation + Private Function CreateInternal(boundNode As BoundNode) As IOperation Select Case boundNode.Kind Case BoundKind.AssignmentOperator Return CreateBoundAssignmentOperatorOperation(DirectCast(boundNode, BoundAssignmentOperator)) @@ -171,7 +170,7 @@ Namespace Microsoft.CodeAnalysis.Semantics End Select End Function - Private Shared Function GetIOperationChildren(boundNode As BoundNode) As ImmutableArray(Of IOperation) + Private Function GetIOperationChildren(boundNode As BoundNode) As ImmutableArray(Of IOperation) Dim boundNodeWithChildren = DirectCast(boundNode, IBoundNodeWithIOperationChildren) If boundNodeWithChildren.Children.IsDefaultOrEmpty Then Return ImmutableArray(Of IOperation).Empty @@ -186,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return builder.ToImmutableAndFree() End Function - Private Shared Function CreateBoundAssignmentOperatorOperation(boundAssignmentOperator As BoundAssignmentOperator) As IOperation + Private Function CreateBoundAssignmentOperatorOperation(boundAssignmentOperator As BoundAssignmentOperator) As IOperation Dim kind = GetAssignmentKind(boundAssignmentOperator) If kind = OperationKind.CompoundAssignmentExpression Then Dim binaryOperationKind As BinaryOperationKind = DirectCast(Create(boundAssignmentOperator.Right), IBinaryOperatorExpression).BinaryOperationKind @@ -210,7 +209,7 @@ Namespace Microsoft.CodeAnalysis.Semantics End If End Function - Private Shared Function CreateBoundMeReferenceOperation(boundMeReference As BoundMeReference) As IInstanceReferenceExpression + Private Function CreateBoundMeReferenceOperation(boundMeReference As BoundMeReference) As IInstanceReferenceExpression Dim instanceReferenceKind As InstanceReferenceKind = If(boundMeReference.WasCompilerGenerated, InstanceReferenceKind.Implicit, InstanceReferenceKind.Explicit) Dim isInvalid As Boolean = boundMeReference.HasErrors Dim syntax As SyntaxNode = boundMeReference.Syntax @@ -219,7 +218,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundMyBaseReferenceOperation(boundMyBaseReference As BoundMyBaseReference) As IInstanceReferenceExpression + Private Function CreateBoundMyBaseReferenceOperation(boundMyBaseReference As BoundMyBaseReference) As IInstanceReferenceExpression Dim instanceReferenceKind As InstanceReferenceKind = InstanceReferenceKind.BaseClass Dim isInvalid As Boolean = boundMyBaseReference.HasErrors Dim syntax As SyntaxNode = boundMyBaseReference.Syntax @@ -228,7 +227,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundMyClassReferenceOperation(boundMyClassReference As BoundMyClassReference) As IInstanceReferenceExpression + Private Function CreateBoundMyClassReferenceOperation(boundMyClassReference As BoundMyClassReference) As IInstanceReferenceExpression Dim instanceReferenceKind As InstanceReferenceKind = InstanceReferenceKind.ThisClass Dim isInvalid As Boolean = boundMyClassReference.HasErrors Dim syntax As SyntaxNode = boundMyClassReference.Syntax @@ -237,7 +236,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New InstanceReferenceExpression(instanceReferenceKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundLiteralOperation(boundLiteral As BoundLiteral) As ILiteralExpression + Private Function CreateBoundLiteralOperation(boundLiteral As BoundLiteral) As ILiteralExpression Dim text As String = boundLiteral.Syntax.ToString() Dim isInvalid As Boolean = boundLiteral.HasErrors Dim syntax As SyntaxNode = boundLiteral.Syntax @@ -246,7 +245,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LiteralExpression(text, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundAwaitOperatorOperation(boundAwaitOperator As BoundAwaitOperator) As IAwaitExpression + Private Function CreateBoundAwaitOperatorOperation(boundAwaitOperator As BoundAwaitOperator) As IAwaitExpression Dim awaitedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundAwaitOperator.Operand)) Dim isInvalid As Boolean = boundAwaitOperator.HasErrors Dim syntax As SyntaxNode = boundAwaitOperator.Syntax @@ -255,7 +254,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyAwaitExpression(awaitedValue, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundLambdaOperation(boundLambda As BoundLambda) As ILambdaExpression + Private Function CreateBoundLambdaOperation(boundLambda As BoundLambda) As ILambdaExpression Dim signature As IMethodSymbol = boundLambda.LambdaSymbol Dim body As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundLambda.Body), IBlockStatement)) Dim isInvalid As Boolean = boundLambda.HasErrors @@ -265,7 +264,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyLambdaExpression(signature, body, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundCallOperation(boundCall As BoundCall) As IInvocationExpression + Private Function CreateBoundCallOperation(boundCall As BoundCall) As IInvocationExpression Dim targetMethod As IMethodSymbol = boundCall.Method Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() If(boundCall.Method.IsShared, Nothing, Create(boundCall.ReceiverOpt))) @@ -281,7 +280,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyInvocationExpression(targetMethod, instance, isVirtual, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundOmittedArgumentOperation(boundOmittedArgument As BoundOmittedArgument) As IOmittedArgumentExpression + Private Function CreateBoundOmittedArgumentOperation(boundOmittedArgument As BoundOmittedArgument) As IOmittedArgumentExpression Dim isInvalid As Boolean = boundOmittedArgument.HasErrors Dim syntax As SyntaxNode = boundOmittedArgument.Syntax Dim type As ITypeSymbol = boundOmittedArgument.Type @@ -289,7 +288,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New OmittedArgumentExpression(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundParenthesizedOperation(boundParenthesized As BoundParenthesized) As IParenthesizedExpression + Private Function CreateBoundParenthesizedOperation(boundParenthesized As BoundParenthesized) As IParenthesizedExpression Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundParenthesized.Expression)) Dim isInvalid As Boolean = boundParenthesized.HasErrors Dim syntax As SyntaxNode = boundParenthesized.Syntax @@ -298,7 +297,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyParenthesizedExpression(operand, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundArrayAccessOperation(boundArrayAccess As BoundArrayAccess) As IArrayElementReferenceExpression + Private Function CreateBoundArrayAccessOperation(boundArrayAccess As BoundArrayAccess) As IArrayElementReferenceExpression Dim arrayReference As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundArrayAccess.Expression)) Dim indices As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundArrayAccess.Indices.SelectAsArray(Function(n) DirectCast(Create(n), IOperation))) Dim isInvalid As Boolean = boundArrayAccess.HasErrors @@ -308,7 +307,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyArrayElementReferenceExpression(arrayReference, indices, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundUnaryOperatorOperation(boundUnaryOperator As BoundUnaryOperator) As IUnaryOperatorExpression + Private Function CreateBoundUnaryOperatorOperation(boundUnaryOperator As BoundUnaryOperator) As IUnaryOperatorExpression Dim unaryOperationKind As UnaryOperationKind = Helper.DeriveUnaryOperationKind(boundUnaryOperator.OperatorKind, boundUnaryOperator.Operand) Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUnaryOperator.Operand)) Dim usesOperatorMethod As Boolean = False @@ -320,7 +319,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyUnaryOperatorExpression(unaryOperationKind, operand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundUserDefinedUnaryOperatorOperation(boundUserDefinedUnaryOperator As BoundUserDefinedUnaryOperator) As IUnaryOperatorExpression + Private Function CreateBoundUserDefinedUnaryOperatorOperation(boundUserDefinedUnaryOperator As BoundUserDefinedUnaryOperator) As IUnaryOperatorExpression Dim unaryOperationKind As UnaryOperationKind = Helper.DeriveUnaryOperationKind(boundUserDefinedUnaryOperator.OperatorKind) Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() If boundUserDefinedUnaryOperator.UnderlyingExpression.Kind = BoundKind.Call Then @@ -338,7 +337,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyUnaryOperatorExpression(unaryOperationKind, operand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundBinaryOperatorOperation(boundBinaryOperator As BoundBinaryOperator) As IBinaryOperatorExpression + Private Function CreateBoundBinaryOperatorOperation(boundBinaryOperator As BoundBinaryOperator) As IBinaryOperatorExpression Dim binaryOperationKind As BinaryOperationKind = Helper.DeriveBinaryOperationKind(boundBinaryOperator.OperatorKind, boundBinaryOperator.Left) Dim leftOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryOperator.Left)) Dim rightOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryOperator.Right)) @@ -351,7 +350,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundUserDefinedBinaryOperatorOperation(boundUserDefinedBinaryOperator As BoundUserDefinedBinaryOperator) As IBinaryOperatorExpression + Private Function CreateBoundUserDefinedBinaryOperatorOperation(boundUserDefinedBinaryOperator As BoundUserDefinedBinaryOperator) As IBinaryOperatorExpression Dim binaryOperationKind As BinaryOperationKind = Helper.DeriveBinaryOperationKind(boundUserDefinedBinaryOperator.OperatorKind) Dim leftOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetUserDefinedBinaryOperatorChild(boundUserDefinedBinaryOperator, 0)) Dim rightOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetUserDefinedBinaryOperatorChild(boundUserDefinedBinaryOperator, 1)) @@ -364,7 +363,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundBinaryConditionalExpressionOperation(boundBinaryConditionalExpression As BoundBinaryConditionalExpression) As INullCoalescingExpression + Private Function CreateBoundBinaryConditionalExpressionOperation(boundBinaryConditionalExpression As BoundBinaryConditionalExpression) As INullCoalescingExpression Dim primaryOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryConditionalExpression.TestExpression)) Dim secondaryOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundBinaryConditionalExpression.ElseExpression)) Dim isInvalid As Boolean = boundBinaryConditionalExpression.HasErrors @@ -374,7 +373,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyNullCoalescingExpression(primaryOperand, secondaryOperand, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundUserDefinedShortCircuitingOperatorOperation(boundUserDefinedShortCircuitingOperator As BoundUserDefinedShortCircuitingOperator) As IBinaryOperatorExpression + Private Function CreateBoundUserDefinedShortCircuitingOperatorOperation(boundUserDefinedShortCircuitingOperator As BoundUserDefinedShortCircuitingOperator) As IBinaryOperatorExpression Dim binaryOperationKind As BinaryOperationKind = If((boundUserDefinedShortCircuitingOperator.BitwiseOperator.OperatorKind And BinaryOperatorKind.And) <> 0, BinaryOperationKind.OperatorMethodConditionalAnd, BinaryOperationKind.OperatorMethodConditionalOr) Dim leftOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUserDefinedShortCircuitingOperator.LeftOperand)) Dim rightOperand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUserDefinedShortCircuitingOperator.BitwiseOperator.Right)) @@ -387,7 +386,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyBinaryOperatorExpression(binaryOperationKind, leftOperand, rightOperand, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundBadExpressionOperation(boundBadExpression As BoundBadExpression) As IInvalidExpression + Private Function CreateBoundBadExpressionOperation(boundBadExpression As BoundBadExpression) As IInvalidExpression Dim children As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundBadExpression.ChildBoundNodes.SelectAsArray(Function(n) Create(n))) Dim isInvalid As Boolean = boundBadExpression.HasErrors Dim syntax As SyntaxNode = boundBadExpression.Syntax @@ -396,7 +395,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyInvalidExpression(children, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundTryCastOperation(boundTryCast As BoundTryCast) As IConversionExpression + Private Function CreateBoundTryCastOperation(boundTryCast As BoundTryCast) As IConversionExpression Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTryCast.Operand)) Dim conversionKind As ConversionKind = Semantics.ConversionKind.TryCast Dim isExplicit As Boolean = True @@ -409,7 +408,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundDirectCastOperation(boundDirectCast As BoundDirectCast) As IConversionExpression + Private Function CreateBoundDirectCastOperation(boundDirectCast As BoundDirectCast) As IConversionExpression Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDirectCast.Operand)) Dim conversionKind As ConversionKind = Semantics.ConversionKind.Cast Dim isExplicit As Boolean = True @@ -422,7 +421,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundConversionOperation(boundConversion As BoundConversion) As IConversionExpression + Private Function CreateBoundConversionOperation(boundConversion As BoundConversion) As IConversionExpression Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConversion.Operand)) Dim conversionKind As ConversionKind = Semantics.ConversionKind.Basic Dim isExplicit As Boolean = boundConversion.ExplicitCastInCode @@ -435,7 +434,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundUserDefinedConversionOperation(boundUserDefinedConversion As BoundUserDefinedConversion) As IConversionExpression + Private Function CreateBoundUserDefinedConversionOperation(boundUserDefinedConversion As BoundUserDefinedConversion) As IConversionExpression Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUserDefinedConversion.Operand)) Dim conversionKind As ConversionKind = Semantics.ConversionKind.OperatorMethod Dim isExplicit As Boolean = Not boundUserDefinedConversion.WasCompilerGenerated @@ -448,7 +447,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyConversionExpression(operand, conversionKind, isExplicit, usesOperatorMethod, operatorMethod, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundTernaryConditionalExpressionOperation(boundTernaryConditionalExpression As BoundTernaryConditionalExpression) As IConditionalChoiceExpression + Private Function CreateBoundTernaryConditionalExpressionOperation(boundTernaryConditionalExpression As BoundTernaryConditionalExpression) As IConditionalChoiceExpression Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.Condition)) Dim ifTrueValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.WhenTrue)) Dim ifFalseValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTernaryConditionalExpression.WhenFalse)) @@ -459,7 +458,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyConditionalChoiceExpression(condition, ifTrueValue, ifFalseValue, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundTypeOfOperation(boundTypeOf As BoundTypeOf) As IIsTypeExpression + Private Function CreateBoundTypeOfOperation(boundTypeOf As BoundTypeOf) As IIsTypeExpression Dim operand As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundTypeOf.Operand)) Dim isType As ITypeSymbol = boundTypeOf.TargetType Dim isInvalid As Boolean = boundTypeOf.HasErrors @@ -469,7 +468,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyIsTypeExpression(operand, isType, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundObjectCreationExpressionOperation(boundObjectCreationExpression As BoundObjectCreationExpression) As IObjectCreationExpression + Private Function CreateBoundObjectCreationExpressionOperation(boundObjectCreationExpression As BoundObjectCreationExpression) As IObjectCreationExpression Dim constructor As IMethodSymbol = boundObjectCreationExpression.ConstructorOpt Dim memberInitializers As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))( Function() @@ -491,7 +490,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyObjectCreationExpression(constructor, memberInitializers, argumentsInEvaluationOrder, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundNewTOperation(boundNewT As BoundNewT) As ITypeParameterObjectCreationExpression + Private Function CreateBoundNewTOperation(boundNewT As BoundNewT) As ITypeParameterObjectCreationExpression Dim isInvalid As Boolean = boundNewT.HasErrors Dim syntax As SyntaxNode = boundNewT.Syntax Dim type As ITypeSymbol = boundNewT.Type @@ -499,7 +498,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New TypeParameterObjectCreationExpression(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundArrayCreationOperation(boundArrayCreation As BoundArrayCreation) As IArrayCreationExpression + Private Function CreateBoundArrayCreationOperation(boundArrayCreation As BoundArrayCreation) As IArrayCreationExpression Dim elementType As ITypeSymbol = TryCast(boundArrayCreation.Type, IArrayTypeSymbol)?.ElementType Dim dimensionSizes As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundArrayCreation.Bounds.SelectAsArray(Function(n) Create(n))) Dim initializer As Lazy(Of IArrayInitializer) = New Lazy(Of IArrayInitializer)(Function() DirectCast(Create(boundArrayCreation.InitializerOpt), IArrayInitializer)) @@ -510,7 +509,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyArrayCreationExpression(elementType, dimensionSizes, initializer, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundArrayInitializationOperation(boundArrayInitialization As BoundArrayInitialization) As IArrayInitializer + Private Function CreateBoundArrayInitializationOperation(boundArrayInitialization As BoundArrayInitialization) As IArrayInitializer Dim elementValues As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() boundArrayInitialization.Initializers.SelectAsArray(Function(n) Create(n))) Dim isInvalid As Boolean = boundArrayInitialization.HasErrors Dim syntax As SyntaxNode = boundArrayInitialization.Syntax @@ -519,7 +518,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyArrayInitializer(elementValues, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundPropertyAccessOperation(boundPropertyAccess As BoundPropertyAccess) As IPropertyReferenceExpression + Private Function CreateBoundPropertyAccessOperation(boundPropertyAccess As BoundPropertyAccess) As IPropertyReferenceExpression Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)( Function() If boundPropertyAccess.PropertySymbol.IsShared Then @@ -541,7 +540,7 @@ Namespace Microsoft.CodeAnalysis.Semantics New LazyPropertyReferenceExpression([property], instance, member, isInvalid, syntax, type, constantValue)) End Function - Private Shared Function CreateBoundEventAccessOperation(boundEventAccess As BoundEventAccess) As IEventReferenceExpression + Private Function CreateBoundEventAccessOperation(boundEventAccess As BoundEventAccess) As IEventReferenceExpression Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)( Function() If boundEventAccess.EventSymbol.IsShared Then @@ -560,7 +559,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyEventReferenceExpression([event], instance, member, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundFieldAccessOperation(boundFieldAccess As BoundFieldAccess) As IFieldReferenceExpression + Private Function CreateBoundFieldAccessOperation(boundFieldAccess As BoundFieldAccess) As IFieldReferenceExpression Dim field As IFieldSymbol = boundFieldAccess.FieldSymbol Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)( Function() @@ -579,7 +578,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyFieldReferenceExpression(field, instance, member, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundConditionalAccessOperation(boundConditionalAccess As BoundConditionalAccess) As IConditionalAccessExpression + Private Function CreateBoundConditionalAccessOperation(boundConditionalAccess As BoundConditionalAccess) As IConditionalAccessExpression Dim conditionalValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConditionalAccess.AccessExpression)) Dim conditionalInstance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundConditionalAccess.Receiver)) Dim isInvalid As Boolean = boundConditionalAccess.HasErrors @@ -589,7 +588,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyConditionalAccessExpression(conditionalValue, conditionalInstance, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundConditionalAccessReceiverPlaceholderOperation(boundConditionalAccessReceiverPlaceholder As BoundConditionalAccessReceiverPlaceholder) As IConditionalAccessInstanceExpression + Private Function CreateBoundConditionalAccessReceiverPlaceholderOperation(boundConditionalAccessReceiverPlaceholder As BoundConditionalAccessReceiverPlaceholder) As IConditionalAccessInstanceExpression Dim isInvalid As Boolean = boundConditionalAccessReceiverPlaceholder.HasErrors Dim syntax As SyntaxNode = boundConditionalAccessReceiverPlaceholder.Syntax Dim type As ITypeSymbol = boundConditionalAccessReceiverPlaceholder.Type @@ -597,7 +596,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New ConditionalAccessInstanceExpression(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundParameterOperation(boundParameter As BoundParameter) As IParameterReferenceExpression + Private Function CreateBoundParameterOperation(boundParameter As BoundParameter) As IParameterReferenceExpression Dim parameter As IParameterSymbol = boundParameter.ParameterSymbol Dim isInvalid As Boolean = boundParameter.HasErrors Dim syntax As SyntaxNode = boundParameter.Syntax @@ -606,7 +605,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New ParameterReferenceExpression(parameter, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundLocalOperation(boundLocal As BoundLocal) As ILocalReferenceExpression + Private Function CreateBoundLocalOperation(boundLocal As BoundLocal) As ILocalReferenceExpression Dim local As ILocalSymbol = boundLocal.LocalSymbol Dim isInvalid As Boolean = boundLocal.HasErrors Dim syntax As SyntaxNode = boundLocal.Syntax @@ -615,7 +614,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LocalReferenceExpression(local, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundLateMemberAccessOperation(boundLateMemberAccess As BoundLateMemberAccess) As ILateBoundMemberReferenceExpression + Private Function CreateBoundLateMemberAccessOperation(boundLateMemberAccess As BoundLateMemberAccess) As ILateBoundMemberReferenceExpression Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundLateMemberAccess.ReceiverOpt)) Dim memberName As String = boundLateMemberAccess.NameOpt Dim isInvalid As Boolean = boundLateMemberAccess.HasErrors @@ -625,7 +624,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyLateBoundMemberReferenceExpression(instance, memberName, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundFieldInitializerOperation(boundFieldInitializer As BoundFieldInitializer) As IFieldInitializer + Private Function CreateBoundFieldInitializerOperation(boundFieldInitializer As BoundFieldInitializer) As IFieldInitializer Dim initializedFields As ImmutableArray(Of IFieldSymbol) = ImmutableArray(Of IFieldSymbol).CastUp(boundFieldInitializer.InitializedFields) Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundFieldInitializer.InitialValue)) Dim kind As OperationKind = OperationKind.FieldInitializerAtDeclaration @@ -636,7 +635,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyFieldInitializer(initializedFields, value, kind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundPropertyInitializerOperation(boundPropertyInitializer As BoundPropertyInitializer) As IPropertyInitializer + Private Function CreateBoundPropertyInitializerOperation(boundPropertyInitializer As BoundPropertyInitializer) As IPropertyInitializer Dim initializedProperty As IPropertySymbol = boundPropertyInitializer.InitializedProperties.FirstOrDefault() Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundPropertyInitializer.InitialValue)) Dim kind As OperationKind = OperationKind.PropertyInitializerAtDeclaration @@ -647,7 +646,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyPropertyInitializer(initializedProperty, value, kind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundParameterEqualsValueOperation(boundParameterEqualsValue As BoundParameterEqualsValue) As IParameterInitializer + Private Function CreateBoundParameterEqualsValueOperation(boundParameterEqualsValue As BoundParameterEqualsValue) As IParameterInitializer Dim parameter As IParameterSymbol = boundParameterEqualsValue.Parameter Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundParameterEqualsValue.Value)) Dim kind As OperationKind = OperationKind.ParameterInitializerAtDeclaration @@ -658,7 +657,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyParameterInitializer(parameter, value, kind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundRValuePlaceholderOperation(boundRValuePlaceholder As BoundRValuePlaceholder) As IPlaceholderExpression + Private Function CreateBoundRValuePlaceholderOperation(boundRValuePlaceholder As BoundRValuePlaceholder) As IPlaceholderExpression Dim isInvalid As Boolean = boundRValuePlaceholder.HasErrors Dim syntax As SyntaxNode = boundRValuePlaceholder.Syntax Dim type As ITypeSymbol = boundRValuePlaceholder.Type @@ -666,7 +665,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New PlaceholderExpression(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundIfStatementOperation(boundIfStatement As BoundIfStatement) As IIfStatement + Private Function CreateBoundIfStatementOperation(boundIfStatement As BoundIfStatement) As IIfStatement Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundIfStatement.Condition)) Dim ifTrueStatement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundIfStatement.Consequence)) Dim ifFalseStatement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundIfStatement.AlternativeOpt)) @@ -677,7 +676,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyIfStatement(condition, ifTrueStatement, ifFalseStatement, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundSelectStatementOperation(boundSelectStatement As BoundSelectStatement) As ISwitchStatement + Private Function CreateBoundSelectStatementOperation(boundSelectStatement As BoundSelectStatement) As ISwitchStatement Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSelectStatement.ExpressionStatement.Expression)) Dim cases As Lazy(Of ImmutableArray(Of ISwitchCase)) = New Lazy(Of ImmutableArray(Of ISwitchCase))(Function() GetSwitchStatementCases(boundSelectStatement)) Dim isInvalid As Boolean = boundSelectStatement.HasErrors @@ -687,7 +686,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazySwitchStatement(value, cases, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundSimpleCaseClauseOperation(boundSimpleCaseClause As BoundSimpleCaseClause) As ISingleValueCaseClause + Private Function CreateBoundSimpleCaseClauseOperation(boundSimpleCaseClause As BoundSimpleCaseClause) As ISingleValueCaseClause Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(GetSingleValueCaseClauseValue(boundSimpleCaseClause))) Dim equality As BinaryOperationKind = GetSingleValueCaseClauseEquality(boundSimpleCaseClause) Dim caseKind As CaseKind = CaseKind.SingleValue @@ -698,7 +697,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazySingleValueCaseClause(value, equality, caseKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundRangeCaseClauseOperation(boundRangeCaseClause As BoundRangeCaseClause) As IRangeCaseClause + Private Function CreateBoundRangeCaseClauseOperation(boundRangeCaseClause As BoundRangeCaseClause) As IRangeCaseClause Dim minimumValue As Lazy(Of IOperation) = New Lazy(Of IOperation)( Function() If boundRangeCaseClause.LowerBoundOpt IsNot Nothing Then @@ -737,7 +736,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyRangeCaseClause(minimumValue, maximumValue, caseKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundRelationalCaseClauseOperation(boundRelationalCaseClause As BoundRelationalCaseClause) As IRelationalCaseClause + Private Function CreateBoundRelationalCaseClauseOperation(boundRelationalCaseClause As BoundRelationalCaseClause) As IRelationalCaseClause Dim valueExpression = GetRelationalCaseClauseValue(boundRelationalCaseClause) Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(valueExpression)) Dim relation As BinaryOperationKind = If(valueExpression IsNot Nothing, Helper.DeriveBinaryOperationKind(boundRelationalCaseClause.OperatorKind, valueExpression), BinaryOperationKind.Invalid) @@ -749,7 +748,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyRelationalCaseClause(value, relation, caseKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundDoLoopStatementOperation(boundDoLoopStatement As BoundDoLoopStatement) As IWhileUntilLoopStatement + Private Function CreateBoundDoLoopStatementOperation(boundDoLoopStatement As BoundDoLoopStatement) As IWhileUntilLoopStatement Dim isTopTest As Boolean = boundDoLoopStatement.ConditionIsTop Dim isWhile As Boolean = Not boundDoLoopStatement.ConditionIsUntil Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.ConditionOpt)) @@ -762,7 +761,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, loopKind, body, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundForToStatementOperation(boundForToStatement As BoundForToStatement) As IForLoopStatement + Private Function CreateBoundForToStatementOperation(boundForToStatement As BoundForToStatement) As IForLoopStatement Dim before As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() GetForLoopStatementBefore(boundForToStatement)) Dim atLoopBottom As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() GetForLoopStatementAtLoopBottom(boundForToStatement)) Dim locals As ImmutableArray(Of ILocalSymbol) = ImmutableArray(Of ILocalSymbol).Empty @@ -776,7 +775,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyForLoopStatement(before, atLoopBottom, locals, condition, loopKind, body, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundForEachStatementOperation(boundForEachStatement As BoundForEachStatement) As IForEachLoopStatement + Private Function CreateBoundForEachStatementOperation(boundForEachStatement As BoundForEachStatement) As IForEachLoopStatement Dim iterationVariable As ILocalSymbol = Nothing ' Manual Dim collection As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundForEachStatement.Collection)) Dim loopKind As LoopKind = LoopKind.ForEach @@ -788,7 +787,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyForEachLoopStatement(iterationVariable, collection, loopKind, body, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundTryStatementOperation(boundTryStatement As BoundTryStatement) As ITryStatement + Private Function CreateBoundTryStatementOperation(boundTryStatement As BoundTryStatement) As ITryStatement Dim body As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundTryStatement.TryBlock), IBlockStatement)) Dim catches As Lazy(Of ImmutableArray(Of ICatchClause)) = New Lazy(Of ImmutableArray(Of ICatchClause))(Function() boundTryStatement.CatchBlocks.As(Of ICatchClause)()) Dim finallyHandler As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundTryStatement.FinallyBlockOpt), IBlockStatement)) @@ -799,7 +798,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyTryStatement(body, catches, finallyHandler, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundCatchBlockOperation(boundCatchBlock As BoundCatchBlock) As ICatchClause + Private Function CreateBoundCatchBlockOperation(boundCatchBlock As BoundCatchBlock) As ICatchClause Dim handler As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundCatchBlock.Body), IBlockStatement)) Dim caughtType As ITypeSymbol = Nothing ' Manual Dim filter As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundCatchBlock.ExceptionFilterOpt)) @@ -811,7 +810,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyCatchClause(handler, caughtType, filter, exceptionLocal, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundBlockOperation(boundBlock As BoundBlock) As IBlockStatement + Private Function CreateBoundBlockOperation(boundBlock As BoundBlock) As IBlockStatement Dim statements As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))(Function() GetBlockStatementStatements(boundBlock)) Dim locals As ImmutableArray(Of ILocalSymbol) = boundBlock.Locals.As(Of ILocalSymbol)() Dim isInvalid As Boolean = boundBlock.HasErrors @@ -821,7 +820,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyBlockStatement(statements, locals, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundBadStatementOperation(boundBadStatement As BoundBadStatement) As IInvalidStatement + Private Function CreateBoundBadStatementOperation(boundBadStatement As BoundBadStatement) As IInvalidStatement Dim children As Lazy(Of ImmutableArray(Of IOperation)) = New Lazy(Of ImmutableArray(Of IOperation))( Function() Dim builder As ArrayBuilder(Of IOperation) = ArrayBuilder(Of IOperation).GetInstance(boundBadStatement.ChildBoundNodes.Length) @@ -841,7 +840,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyInvalidStatement(children, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundReturnStatementOperation(boundReturnStatement As BoundReturnStatement) As IReturnStatement + Private Function CreateBoundReturnStatementOperation(boundReturnStatement As BoundReturnStatement) As IReturnStatement Dim returnedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundReturnStatement.ExpressionOpt)) Dim isInvalid As Boolean = boundReturnStatement.HasErrors Dim syntax As SyntaxNode = boundReturnStatement.Syntax @@ -850,7 +849,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyReturnStatement(returnedValue, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundThrowStatementOperation(boundThrowStatement As BoundThrowStatement) As IThrowStatement + Private Function CreateBoundThrowStatementOperation(boundThrowStatement As BoundThrowStatement) As IThrowStatement Dim thrownObject As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundThrowStatement.ExpressionOpt)) Dim isInvalid As Boolean = boundThrowStatement.HasErrors Dim syntax As SyntaxNode = boundThrowStatement.Syntax @@ -859,7 +858,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyThrowStatement(thrownObject, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundWhileStatementOperation(boundWhileStatement As BoundWhileStatement) As IWhileUntilLoopStatement + Private Function CreateBoundWhileStatementOperation(boundWhileStatement As BoundWhileStatement) As IWhileUntilLoopStatement Dim isTopTest As Boolean = True Dim isWhile As Boolean = True Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Condition)) @@ -872,7 +871,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyWhileUntilLoopStatement(isTopTest, isWhile, condition, loopKind, body, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundDimStatementOperation(boundDimStatement As BoundDimStatement) As IVariableDeclarationStatement + Private Function CreateBoundDimStatementOperation(boundDimStatement As BoundDimStatement) As IVariableDeclarationStatement Dim declarations As Lazy(Of ImmutableArray(Of IVariableDeclaration)) = New Lazy(Of ImmutableArray(Of IVariableDeclaration))(Function() GetVariableDeclarationStatementVariables(boundDimStatement)) Dim isInvalid As Boolean = boundDimStatement.HasErrors Dim syntax As SyntaxNode = boundDimStatement.Syntax @@ -881,7 +880,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyVariableDeclarationStatement(declarations, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundYieldStatementOperation(boundYieldStatement As BoundYieldStatement) As IReturnStatement + Private Function CreateBoundYieldStatementOperation(boundYieldStatement As BoundYieldStatement) As IReturnStatement Dim returnedValue As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundYieldStatement.Expression)) Dim isInvalid As Boolean = boundYieldStatement.HasErrors Dim syntax As SyntaxNode = boundYieldStatement.Syntax @@ -890,7 +889,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyReturnStatement(returnedValue, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundLabelStatementOperation(boundLabelStatement As BoundLabelStatement) As ILabelStatement + Private Function CreateBoundLabelStatementOperation(boundLabelStatement As BoundLabelStatement) As ILabelStatement Dim label As ILabelSymbol = boundLabelStatement.Label Dim labeledStatement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(Nothing)) Dim isInvalid As Boolean = boundLabelStatement.HasErrors @@ -900,7 +899,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyLabelStatement(label, labeledStatement, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundGotoStatementOperation(boundGotoStatement As BoundGotoStatement) As IBranchStatement + Private Function CreateBoundGotoStatementOperation(boundGotoStatement As BoundGotoStatement) As IBranchStatement Dim target As ILabelSymbol = boundGotoStatement.Label Dim branchKind As BranchKind = BranchKind.GoTo Dim isInvalid As Boolean = boundGotoStatement.HasErrors @@ -910,7 +909,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New BranchStatement(target, branchKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundContinueStatementOperation(boundContinueStatement As BoundContinueStatement) As IBranchStatement + Private Function CreateBoundContinueStatementOperation(boundContinueStatement As BoundContinueStatement) As IBranchStatement Dim target As ILabelSymbol = boundContinueStatement.Label Dim branchKind As BranchKind = BranchKind.Continue Dim isInvalid As Boolean = boundContinueStatement.HasErrors @@ -920,7 +919,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New BranchStatement(target, branchKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundExitStatementOperation(boundExitStatement As BoundExitStatement) As IBranchStatement + Private Function CreateBoundExitStatementOperation(boundExitStatement As BoundExitStatement) As IBranchStatement Dim target As ILabelSymbol = boundExitStatement.Label Dim branchKind As BranchKind = BranchKind.Break Dim isInvalid As Boolean = boundExitStatement.HasErrors @@ -930,7 +929,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New BranchStatement(target, branchKind, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundSyncLockStatementOperation(boundSyncLockStatement As BoundSyncLockStatement) As ILockStatement + Private Function CreateBoundSyncLockStatementOperation(boundSyncLockStatement As BoundSyncLockStatement) As ILockStatement Dim lockedObject As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSyncLockStatement.LockExpression)) Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundSyncLockStatement.Body)) Dim isInvalid As Boolean = boundSyncLockStatement.HasErrors @@ -940,7 +939,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyLockStatement(lockedObject, body, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundNoOpStatementOperation(boundNoOpStatement As BoundNoOpStatement) As IEmptyStatement + Private Function CreateBoundNoOpStatementOperation(boundNoOpStatement As BoundNoOpStatement) As IEmptyStatement Dim isInvalid As Boolean = boundNoOpStatement.HasErrors Dim syntax As SyntaxNode = boundNoOpStatement.Syntax Dim type As ITypeSymbol = Nothing @@ -948,7 +947,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New EmptyStatement(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundStopStatementOperation(boundStopStatement As BoundStopStatement) As IStopStatement + Private Function CreateBoundStopStatementOperation(boundStopStatement As BoundStopStatement) As IStopStatement Dim isInvalid As Boolean = boundStopStatement.HasErrors Dim syntax As SyntaxNode = boundStopStatement.Syntax Dim type As ITypeSymbol = Nothing @@ -956,7 +955,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New StopStatement(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundEndStatementOperation(boundEndStatement As BoundEndStatement) As IEndStatement + Private Function CreateBoundEndStatementOperation(boundEndStatement As BoundEndStatement) As IEndStatement Dim isInvalid As Boolean = boundEndStatement.HasErrors Dim syntax As SyntaxNode = boundEndStatement.Syntax Dim type As ITypeSymbol = Nothing @@ -964,7 +963,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New EndStatement(isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundWithStatementOperation(boundWithStatement As BoundWithStatement) As IWithStatement + Private Function CreateBoundWithStatementOperation(boundWithStatement As BoundWithStatement) As IWithStatement Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWithStatement.Body)) Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWithStatement.OriginalExpression)) Dim isInvalid As Boolean = boundWithStatement.HasErrors @@ -974,7 +973,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyWithStatement(body, value, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundUsingStatementOperation(boundUsingStatement As BoundUsingStatement) As IUsingStatement + Private Function CreateBoundUsingStatementOperation(boundUsingStatement As BoundUsingStatement) As IUsingStatement Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUsingStatement.Body)) Dim declaration As Lazy(Of IVariableDeclarationStatement) = New Lazy(Of IVariableDeclarationStatement)(Function() GetUsingStatementDeclaration(boundUsingStatement)) Dim value As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundUsingStatement.ResourceExpressionOpt)) @@ -985,7 +984,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyUsingStatement(body, declaration, value, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundExpressionStatementOperation(boundExpressionStatement As BoundExpressionStatement) As IExpressionStatement + Private Function CreateBoundExpressionStatementOperation(boundExpressionStatement As BoundExpressionStatement) As IExpressionStatement Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundExpressionStatement.Expression)) Dim isInvalid As Boolean = boundExpressionStatement.HasErrors Dim syntax As SyntaxNode = boundExpressionStatement.Syntax @@ -994,7 +993,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyExpressionStatement(expression, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundRaiseEventStatementOperation(boundRaiseEventStatement As BoundRaiseEventStatement) As IExpressionStatement + Private Function CreateBoundRaiseEventStatementOperation(boundRaiseEventStatement As BoundRaiseEventStatement) As IExpressionStatement Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundRaiseEventStatement.EventInvocation)) Dim isInvalid As Boolean = boundRaiseEventStatement.HasErrors Dim syntax As SyntaxNode = boundRaiseEventStatement.Syntax @@ -1003,7 +1002,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyExpressionStatement(expression, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundAddHandlerStatementOperation(boundAddHandlerStatement As BoundAddHandlerStatement) As IExpressionStatement + Private Function CreateBoundAddHandlerStatementOperation(boundAddHandlerStatement As BoundAddHandlerStatement) As IExpressionStatement Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetAddHandlerStatementExpression(boundAddHandlerStatement)) Dim isInvalid As Boolean = boundAddHandlerStatement.HasErrors Dim syntax As SyntaxNode = boundAddHandlerStatement.Syntax @@ -1012,7 +1011,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyExpressionStatement(expression, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundRemoveHandlerStatementOperation(boundRemoveHandlerStatement As BoundRemoveHandlerStatement) As IExpressionStatement + Private Function CreateBoundRemoveHandlerStatementOperation(boundRemoveHandlerStatement As BoundRemoveHandlerStatement) As IExpressionStatement Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() GetRemoveStatementExpression(boundRemoveHandlerStatement)) Dim isInvalid As Boolean = boundRemoveHandlerStatement.HasErrors Dim syntax As SyntaxNode = boundRemoveHandlerStatement.Syntax @@ -1021,7 +1020,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyExpressionStatement(expression, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundInterpolatedStringExpressionOperation(boundInterpolatedString As BoundInterpolatedStringExpression) As IInterpolatedStringExpression + Private Function CreateBoundInterpolatedStringExpressionOperation(boundInterpolatedString As BoundInterpolatedStringExpression) As IInterpolatedStringExpression Dim parts As New Lazy(Of ImmutableArray(Of IInterpolatedStringContent))(Function() GetInterpolatedStringExpressionParts(boundInterpolatedString)) Dim isInvalid As Boolean = boundInterpolatedString.HasErrors Dim syntax As SyntaxNode = boundInterpolatedString.Syntax @@ -1030,7 +1029,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyInterpolatedStringExpression(parts, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundInterpolatedStringContentOperation(boundNode As BoundNode) As IInterpolatedStringContent + Private Function CreateBoundInterpolatedStringContentOperation(boundNode As BoundNode) As IInterpolatedStringContent If boundNode.Kind = BoundKind.Interpolation Then Return DirectCast(Create(boundNode), IInterpolatedStringContent) Else @@ -1038,7 +1037,7 @@ Namespace Microsoft.CodeAnalysis.Semantics End If End Function - Private Shared Function CreateBoundInterpolationOperation(boundInterpolation As BoundInterpolation) As IInterpolation + Private Function CreateBoundInterpolationOperation(boundInterpolation As BoundInterpolation) As IInterpolation Dim expression As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundInterpolation.Expression)) Dim alignment As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundInterpolation.AlignmentOpt)) Dim format As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundInterpolation.FormatStringOpt)) @@ -1049,7 +1048,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return New LazyInterpolation(expression, alignment, format, isInvalid, syntax, type, constantValue) End Function - Private Shared Function CreateBoundInterpolatedStringTextOperation(boundNode As BoundNode) As IInterpolatedStringText + Private Function CreateBoundInterpolatedStringTextOperation(boundNode As BoundNode) As IInterpolatedStringText Dim text As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundNode)) Dim isInvalid As Boolean = boundNode.HasErrors Dim syntax As SyntaxNode = boundNode.Syntax diff --git a/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb b/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb index 2048492a057..789b079d8d9 100644 --- a/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb +++ b/src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb @@ -5,7 +5,7 @@ Imports System.Runtime.CompilerServices Imports Microsoft.CodeAnalysis.VisualBasic Namespace Microsoft.CodeAnalysis.Semantics - Partial Friend NotInheritable Class VisualBasicOperationFactory + Partial Friend Class VisualBasicOperationFactory Private Shared Function ConvertToOptional(value As ConstantValue) As [Optional](Of Object) Return If(value Is Nothing, New [Optional](Of Object)(), New [Optional](Of Object)(value.Value)) End Function @@ -34,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return OperationKind.AssignmentExpression End Function - Private Shared Function GetUserDefinedBinaryOperatorChild([operator] As BoundUserDefinedBinaryOperator, index As Integer) As IOperation + Private Function GetUserDefinedBinaryOperatorChild([operator] As BoundUserDefinedBinaryOperator, index As Integer) As IOperation Dim child = Create(GetUserDefinedBinaryOperatorChildBoundNode([operator], index)) If child IsNot Nothing Then Return child @@ -57,7 +57,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return GetChildOfBadExpressionBoundNode([operator].UnderlyingExpression, index) End Function - Friend Shared Function DeriveArguments(boundArguments As ImmutableArray(Of BoundExpression), parameters As ImmutableArray(Of VisualBasic.Symbols.ParameterSymbol)) As ImmutableArray(Of IArgument) + Friend Function DeriveArguments(boundArguments As ImmutableArray(Of BoundExpression), parameters As ImmutableArray(Of VisualBasic.Symbols.ParameterSymbol)) As ImmutableArray(Of IArgument) Dim argumentsLength As Integer = boundArguments.Length Debug.Assert(argumentsLength = parameters.Length) @@ -69,13 +69,11 @@ Namespace Microsoft.CodeAnalysis.Semantics Return arguments.ToImmutableAndFree() End Function - Private Shared ReadOnly s_argumentMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundExpression, IArgument) - - Private Shared Function DeriveArgument(index As Integer, argument As BoundExpression, parameters As ImmutableArray(Of VisualBasic.Symbols.ParameterSymbol)) As IArgument + Private Function DeriveArgument(index As Integer, argument As BoundExpression, parameters As ImmutableArray(Of VisualBasic.Symbols.ParameterSymbol)) As IArgument Select Case argument.Kind Case BoundKind.ByRefArgumentWithCopyBack - Return s_argumentMappings.GetValue( - argument, + Return _cache.GetValue( + argument, NameOf(DeriveArgument), Function(argumentValue) Dim byRefArgument = DirectCast(argumentValue, BoundByRefArgumentWithCopyBack) Dim parameter = parameters(index) @@ -92,8 +90,8 @@ Namespace Microsoft.CodeAnalysis.Semantics constantValue:=Nothing) End Function) Case Else - Return s_argumentMappings.GetValue( - argument, + Return _cache.GetValue( + argument, NameOf(DeriveArgument), Function(argumentValue) Dim lastParameterIndex = parameters.Length - 1 If index = lastParameterIndex AndAlso ParameterIsParamArray(parameters(lastParameterIndex)) Then @@ -143,7 +141,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return If(parameter.IsParamArray AndAlso parameter.Type.Kind = SymbolKind.ArrayType, DirectCast(parameter.Type, VisualBasic.Symbols.ArrayTypeSymbol).IsSZArray, False) End Function - Private Shared Function GetChildOfBadExpression(parent As BoundNode, index As Integer) As IOperation + Private Function GetChildOfBadExpression(parent As BoundNode, index As Integer) As IOperation Dim child = Create(GetChildOfBadExpressionBoundNode(parent, index)) If child IsNot Nothing Then Return child @@ -164,14 +162,12 @@ Namespace Microsoft.CodeAnalysis.Semantics Return Nothing End Function - Private Shared Function GetObjectCreationInitializers(expression As BoundObjectCreationExpression) As ImmutableArray(Of IOperation) + Private Function GetObjectCreationInitializers(expression As BoundObjectCreationExpression) As ImmutableArray(Of IOperation) Return If(expression.InitializerOpt IsNot Nothing, expression.InitializerOpt.Initializers.SelectAsArray(Function(n) Create(n)), ImmutableArray(Of IOperation).Empty) End Function - Private Shared ReadOnly s_caseBlocksMappings As New ConditionalWeakTable(Of BoundSelectStatement, Object) - - Private Shared Function GetSwitchStatementCases(statement As BoundSelectStatement) As ImmutableArray(Of ISwitchCase) - Dim cases = s_caseBlocksMappings.GetValue(statement, + Private Function GetSwitchStatementCases(statement As BoundSelectStatement) As ImmutableArray(Of ISwitchCase) + Dim cases = _cache.GetValue(statement, NameOf(GetSwitchStatementCases), Function(boundSelect) Return boundSelect.CaseBlocks.SelectAsArray( Function(boundCaseBlock) @@ -199,7 +195,7 @@ Namespace Microsoft.CodeAnalysis.Semantics Return DirectCast(New SwitchCase(clauses, body, isInvalid, syntax, type:=Nothing, constantValue:=Nothing), ISwitchCase) End Function) End Function) - Return DirectCast(cases, ImmutableArray(Of ISwitchCase)) + Return cases End Function Private Shared Function GetSingleValueCaseClauseValue(clause As BoundSimpleCaseClause) As BoundExpression @@ -252,11 +248,9 @@ Namespace Microsoft.CodeAnalysis.Semantics Return Nothing End Function - Private Shared ReadOnly s_loopTopMappings As New ConditionalWeakTable(Of BoundForToStatement, Object) - - Private Shared Function GetForLoopStatementBefore(boundForToStatement As BoundForToStatement) As ImmutableArray(Of IOperation) - Dim result = s_loopTopMappings.GetValue( - boundForToStatement, + Private Function GetForLoopStatementBefore(boundForToStatement As BoundForToStatement) As ImmutableArray(Of IOperation) + Dim result = _cache.GetValue( + boundForToStatement, NameOf(GetForLoopStatementBefore), Function(boundFor) Dim statements As ArrayBuilder(Of IOperation) = ArrayBuilder(Of IOperation).GetInstance() @@ -297,14 +291,12 @@ Namespace Microsoft.CodeAnalysis.Semantics Return statements.ToImmutableAndFree() End Function) - Return DirectCast(result, ImmutableArray(Of IOperation)) + Return result End Function - Private Shared ReadOnly s_loopBottomMappings As New ConditionalWeakTable(Of BoundForToStatement, Object) - - Private Shared Function GetForLoopStatementAtLoopBottom(boundForToStatement As BoundForToStatement) As ImmutableArray(Of IOperation) - Dim result = s_loopBottomMappings.GetValue( - boundForToStatement, + Private Function GetForLoopStatementAtLoopBottom(boundForToStatement As BoundForToStatement) As ImmutableArray(Of IOperation) + Dim result = _cache.GetValue( + boundForToStatement, NameOf(GetForLoopStatementAtLoopBottom), Function(boundFor) Dim statements As ArrayBuilder(Of IOperation) = ArrayBuilder(Of IOperation).GetInstance() Dim operators As BoundForToUserDefinedOperators = boundFor.OperatorsOpt @@ -338,15 +330,13 @@ Namespace Microsoft.CodeAnalysis.Semantics Return statements.ToImmutableAndFree() End Function) - Return DirectCast(result, ImmutableArray(Of IOperation)) + Return result End Function - Private Shared ReadOnly s_loopConditionMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundForToStatement, IOperation) - - Private Shared Function GetForWhileUntilLoopStatmentCondition(boundForToStatement As BoundForToStatement) As IOperation - Return s_loopConditionMappings.GetValue( - boundForToStatement, - Function(boundFor) + Private Function GetForWhileUntilLoopStatmentCondition(boundForToStatement As BoundForToStatement) As IOperation + Return _cache.GetValue( + boundForToStatement, NameOf(GetForWhileUntilLoopStatmentCondition), + Function(boundFor) As IOperation Dim operationValue = Create(boundFor.LimitValue) Dim limitValue As IOperation = If(boundFor.LimitValue.IsConstant, @@ -405,23 +395,19 @@ Namespace Microsoft.CodeAnalysis.Semantics End Function) End Function - Private Shared ReadOnly s_blockStatementsMappings As New System.Runtime.CompilerServices.ConditionalWeakTable(Of BoundBlock, Object) - - Private Shared Function GetBlockStatementStatements(block As BoundBlock) As ImmutableArray(Of IOperation) + Private Function GetBlockStatementStatements(block As BoundBlock) As ImmutableArray(Of IOperation) ' This is to filter out operations of kind None. - Dim statements = s_blockStatementsMappings.GetValue( - block, + Dim statements = _cache.GetValue( + block, NameOf(GetBlockStatementStatements), Function(boundBlock) Return boundBlock.Statements.Select(Function(n) Create(n)).Where(Function(s) s.Kind <> OperationKind.None).ToImmutableArray() End Function) - Return DirectCast(statements, ImmutableArray(Of IOperation)) + Return statements End Function - Private Shared ReadOnly s_variablesMappings As New ConditionalWeakTable(Of BoundDimStatement, Object) - - Private Shared Function GetVariableDeclarationStatementVariables(statement As BoundDimStatement) As ImmutableArray(Of IVariableDeclaration) - Dim variables = s_variablesMappings.GetValue( - statement, + Private Function GetVariableDeclarationStatementVariables(statement As BoundDimStatement) As ImmutableArray(Of IVariableDeclaration) + Dim variables = _cache.GetValue( + statement, NameOf(GetVariableDeclarationStatementVariables), Function(dimStatement) Dim builder = ArrayBuilder(Of IVariableDeclaration).GetInstance() For Each base In dimStatement.LocalDeclarations @@ -437,14 +423,12 @@ Namespace Microsoft.CodeAnalysis.Semantics Return builder.ToImmutableAndFree() End Function ) - Return DirectCast(variables, ImmutableArray(Of IVariableDeclaration)) + Return variables End Function - Private Shared ReadOnly s_variablesDeclMappings As New ConditionalWeakTable(Of BoundUsingStatement, VariableDeclarationStatement) - - Private Shared Function GetUsingStatementDeclaration(boundUsingStatement As BoundUsingStatement) As IVariableDeclarationStatement - Return s_variablesDeclMappings.GetValue( - boundUsingStatement, + Private Function GetUsingStatementDeclaration(boundUsingStatement As BoundUsingStatement) As IVariableDeclarationStatement + Return _cache.GetValue( + boundUsingStatement, NameOf(GetUsingStatementDeclaration), Function(boundUsing) Dim declaration = If(boundUsing.ResourceList.IsDefaultOrEmpty, ImmutableArray(Of IVariableDeclaration).Empty, @@ -458,12 +442,9 @@ Namespace Microsoft.CodeAnalysis.Semantics End Function) End Function - Private Shared ReadOnly s_expressionsMappings As New ConditionalWeakTable(Of BoundAddRemoveHandlerStatement, IEventAssignmentExpression) - - - Private Shared Function GetAddHandlerStatementExpression(handlerStatement As BoundAddHandlerStatement) As IOperation - Return s_expressionsMappings.GetValue( - handlerStatement, + Private Function GetAddHandlerStatementExpression(handlerStatement As BoundAddHandlerStatement) As IOperation + Return _cache.GetValue( + handlerStatement, NameOf(GetAddHandlerStatementExpression), Function(statement) Dim eventAccess As BoundEventAccess = TryCast(statement.EventAccess, BoundEventAccess) Dim [event] As IEventSymbol = eventAccess?.EventSymbol @@ -474,10 +455,9 @@ Namespace Microsoft.CodeAnalysis.Semantics End Function) End Function - - Private Shared Function GetRemoveStatementExpression(handlerStatement As BoundRemoveHandlerStatement) As IOperation - Return s_expressionsMappings.GetValue( - handlerStatement, + Private Function GetRemoveStatementExpression(handlerStatement As BoundRemoveHandlerStatement) As IOperation + Return _cache.GetValue( + handlerStatement, NameOf(GetRemoveStatementExpression), Function(statement) Dim eventAccess As BoundEventAccess = TryCast(statement.EventAccess, BoundEventAccess) Dim [event] As IEventSymbol = eventAccess?.EventSymbol @@ -489,14 +469,12 @@ Namespace Microsoft.CodeAnalysis.Semantics End Function) End Function - Private Shared ReadOnly s_interpolatedStringExpressionMappings As New ConditionalWeakTable(Of BoundInterpolatedStringExpression, Object)() - - Private Shared Function GetInterpolatedStringExpressionParts(boundInterpolatedString As BoundInterpolatedStringExpression) As ImmutableArray(Of IInterpolatedStringContent) - Return DirectCast(s_interpolatedStringExpressionMappings.GetValue( - boundInterpolatedString, + Private Function GetInterpolatedStringExpressionParts(boundInterpolatedString As BoundInterpolatedStringExpression) As ImmutableArray(Of IInterpolatedStringContent) + Return _cache.GetValue( + boundInterpolatedString, NameOf(GetInterpolatedStringExpressionParts), Function(interpolatedString) Return interpolatedString.Contents.SelectAsArray(Function(interpolatedStringContent) CreateBoundInterpolatedStringContentOperation(interpolatedStringContent)) - End Function), ImmutableArray(Of IInterpolatedStringContent)) + End Function) End Function Friend Class Helper -- GitLab