diff --git a/pkg/dart2bytecode/lib/bytecode_generator.dart b/pkg/dart2bytecode/lib/bytecode_generator.dart index 24252bc9a30..7ba96aed5f4 100644 --- a/pkg/dart2bytecode/lib/bytecode_generator.dart +++ b/pkg/dart2bytecode/lib/bytecode_generator.dart @@ -1675,7 +1675,7 @@ class BytecodeGenerator extends RecursiveVisitor { } void _genPushContextForVariable( - Variable variable, { + VariableDeclaration variable, { int? currentContextLevel, }) { currentContextLevel ??= locals.currentContextLevel; @@ -1690,13 +1690,13 @@ class BytecodeGenerator extends RecursiveVisitor { } } - void _genPushContextIfCaptured(Variable variable) { + void _genPushContextIfCaptured(VariableDeclaration variable) { if (locals.isCaptured(variable)) { _genPushContextForVariable(variable); } } - void _genLoadVar(Variable v, {int? currentContextLevel}) { + void _genLoadVar(VariableDeclaration v, {int? currentContextLevel}) { if (locals.isCaptured(v)) { _genPushContextForVariable(v, currentContextLevel: currentContextLevel); asm.emitLoadContextVar( @@ -1716,7 +1716,7 @@ class BytecodeGenerator extends RecursiveVisitor { // Stores value into variable. // If variable is captured, context should be pushed before value. - void _genStoreVar(Variable variable) { + void _genStoreVar(VariableDeclaration variable) { if (locals.isCaptured(variable)) { asm.emitStoreContextVar( locals.getVarContextId(variable), @@ -2420,7 +2420,10 @@ class BytecodeGenerator extends RecursiveVisitor { } } - void _declareLocalVariable(Variable variable, int initializedPosition) { + void _declareLocalVariable( + VariableDeclaration variable, + int initializedPosition, + ) { bool isCaptured = locals.isCaptured(variable); asm.localVariableTable.declareVariable( asm.offset, @@ -4139,7 +4142,7 @@ class BytecodeGenerator extends RecursiveVisitor { @override void visitVariableGet(VariableGet node) { - final v = node.expressionVariable; + final v = node.variable; if (v.isConst) { _genPushConstExpr(v.initializer!); } else if (v.isLate) { @@ -4203,7 +4206,7 @@ class BytecodeGenerator extends RecursiveVisitor { @override void visitVariableSet(VariableSet node) { - final v = node.expressionVariable; + final v = node.variable; _genPushContextIfCaptured(v); _generateNode(node.value); @@ -4778,14 +4781,14 @@ class BytecodeGenerator extends RecursiveVisitor { _enterScope(catchClause); - final exceptionVar = catchClause.exceptionCatchVariable; + final exceptionVar = catchClause.exception; if (exceptionVar != null) { _genPushContextIfCaptured(exceptionVar); asm.emitPush(exception); _genStoreVar(exceptionVar); } - final stackTraceVar = catchClause.stackTraceCatchVariable; + final stackTraceVar = catchClause.stackTrace; if (stackTraceVar != null) { tryBlock.needsStackTrace = true; _genPushContextIfCaptured(stackTraceVar); @@ -4854,7 +4857,10 @@ class BytecodeGenerator extends RecursiveVisitor { finallyBlocks.remove(node); } - bool _skipVariableInitialization(VariableInitialization v, bool isCaptured) { + bool _skipVariableInitialization( + VariableInitializationBase v, + bool isCaptured, + ) { // We can skip variable initialization if the variable is supposed to be // initialized to null and it's captured. This is because all the slots in // the capture context are implicitly initialized to null. @@ -4877,11 +4883,11 @@ class BytecodeGenerator extends RecursiveVisitor { } @override - void visitVariableInitialization(VariableInitialization node) { + void visitVariableInitialization(VariableInitializationBase node) { _handleVariableInitialization(node); } - void _handleVariableInitialization(VariableInitialization node) { + void _handleVariableInitialization(VariableInitializationBase node) { if (!node.isConst) { final bool isCaptured = locals.isCaptured(node.variable); final initializer = node.initializer; diff --git a/pkg/dart2bytecode/lib/local_vars.dart b/pkg/dart2bytecode/lib/local_vars.dart index fe5ddb4f972..dd78b20367e 100644 --- a/pkg/dart2bytecode/lib/local_vars.dart +++ b/pkg/dart2bytecode/lib/local_vars.dart @@ -12,7 +12,7 @@ import 'options.dart' show BytecodeOptions; class LocalVariables { final _scopes = new Map(); - final _vars = new Map(); + final _vars = new Map(); Map>? _temps; Map? _capturedSavedContextVars; Map? _capturedExceptionVars; @@ -27,11 +27,11 @@ class LocalVariables { Frame? _currentFrameInternal; Frame get _currentFrame => _currentFrameInternal!; - VarDesc _getVarDesc(Variable variable) => + VarDesc _getVarDesc(VariableDeclaration variable) => _vars[variable] ?? (throw 'Variable descriptor is not created for $variable'); - int _getVarIndex(Variable variable, bool isCaptured) { + int _getVarIndex(VariableDeclaration variable, bool isCaptured) { final v = _getVarDesc(variable); if (v.isCaptured != isCaptured) { throw 'Mismatch in captured state of $variable'; @@ -39,11 +39,14 @@ class LocalVariables { return v.index ?? (throw 'Variable $variable is not allocated'); } - bool isCaptured(Variable variable) => _getVarDesc(variable).isCaptured; + bool isCaptured(VariableDeclaration variable) => + _getVarDesc(variable).isCaptured; - int getVarIndexInFrame(Variable variable) => _getVarIndex(variable, false); + int getVarIndexInFrame(VariableDeclaration variable) => + _getVarIndex(variable, false); - int getVarIndexInContext(Variable variable) => _getVarIndex(variable, true); + int getVarIndexInContext(VariableDeclaration variable) => + _getVarIndex(variable, true); int getOriginalParamSlotIndex(VariableDeclaration variable) => _getVarDesc(variable).originalParamSlotIndex ?? @@ -69,13 +72,13 @@ class LocalVariables { _currentFrame.contextLevelAtEntry ?? (throw "Current frame is top level and it doesn't have a context at entry"); - int getContextLevelOfVar(Variable variable) { + int getContextLevelOfVar(VariableDeclaration variable) { final v = _getVarDesc(variable); assert(v.isCaptured); return v.scope.contextLevel!; } - int getVarContextId(Variable variable) { + int getVarContextId(VariableDeclaration variable) { final v = _getVarDesc(variable); assert(v.isCaptured); return v.scope.contextId!; @@ -123,13 +126,13 @@ class LocalVariables { bool get hasFactoryTypeArgsVar => _currentFrame.factoryTypeArgsVar != null; - Variable get receiverVar => + VariableDeclaration get receiverVar => _currentFrame.receiverVar ?? (throw 'Receiver variable is not declared in ${_currentFrame.function}'); bool get hasCapturedReceiverVar => _currentFrame.capturedReceiverVar != null; - Variable get capturedReceiverVar => + VariableDeclaration get capturedReceiverVar => _currentFrame.capturedReceiverVar ?? (throw 'Captured receiver variable is not declared in ${_currentFrame.function}'); @@ -195,7 +198,7 @@ class LocalVariables { } class VarDesc { - final Variable declaration; + final VariableDeclaration declaration; Scope scope; bool isCaptured = false; int? index; @@ -237,8 +240,8 @@ class Frame { bool hasOptionalParameters = false; bool hasCapturedParameters = false; bool hasClosures = false; - Variable? receiverVar; - Variable? capturedReceiverVar; + VariableDeclaration? receiverVar; + VariableDeclaration? capturedReceiverVar; VariableDeclaration? functionTypeArgsVar; VariableDeclaration? factoryTypeArgsVar; VariableDeclaration? closureVar; @@ -477,7 +480,7 @@ class _ScopeBuilder extends RecursiveVisitor { _currentScopeInternal = _currentScope.parent; } - void _declareVariable(Variable variable, [Scope? scope]) { + void _declareVariable(VariableDeclaration variable, [Scope? scope]) { if (scope == null) { scope = _currentScope; } @@ -489,7 +492,7 @@ class _ScopeBuilder extends RecursiveVisitor { locals._vars[variable] = v; } - void _useVariable(Variable variable) { + void _useVariable(VariableDeclaration variable) { final VarDesc? v = locals._vars[variable]; if (v == null) { throw 'Variable $variable is used before declared'; @@ -550,11 +553,11 @@ class _ScopeBuilder extends RecursiveVisitor { } @override - void visitVariableInitialization(VariableInitialization node) { + void visitVariableInitialization(VariableInitializationBase node) { _handleVariableInitialization(node); } - void _handleVariableInitialization(VariableInitialization node) { + void _handleVariableInitialization(VariableInitializationBase node) { _declareVariable(node.variable); node.visitChildren(this); } @@ -582,15 +585,15 @@ class _ScopeBuilder extends RecursiveVisitor { @override void visitVariableGet(VariableGet node) { - _useVariable(node.expressionVariable); - if (node.expressionVariable.isLate) { - node.expressionVariable.initializer?.accept(this); + _useVariable(node.variable); + if (node.variable.isLate) { + node.variable.initializer?.accept(this); } } @override void visitVariableSet(VariableSet node) { - _useVariable(node.expressionVariable); + _useVariable(node.variable); node.visitChildren(this); } @@ -671,7 +674,7 @@ class _ScopeBuilder extends RecursiveVisitor { node.iterable.accept(this); ++_loopDepth; _enterScope(node); - node.expressionVariable.accept(this); + node.variable.accept(this); node.body.accept(this); _leaveScope(); --_loopDepth; @@ -889,7 +892,7 @@ class _Allocator extends RecursiveVisitor { ); } - void _allocateVariable(Variable variable, {int? paramSlotIndex}) { + void _allocateVariable(VariableDeclaration variable, {int? paramSlotIndex}) { final VarDesc v = locals._getVarDesc(variable); assert(!v.isAllocated); @@ -921,7 +924,7 @@ class _Allocator extends RecursiveVisitor { _updateFrameSize(); } - void _ensureVariableAllocated(Variable? variable) { + void _ensureVariableAllocated(VariableDeclaration? variable) { if (variable != null) { final VarDesc v = locals._getVarDesc(variable); if (!v.isAllocated) { @@ -930,7 +933,7 @@ class _Allocator extends RecursiveVisitor { } } - void _allocateParameter(Variable node, int i) { + void _allocateParameter(VariableDeclaration node, int i) { final numParameters = _currentFrame.numParameters; assert(0 <= i && i < numParameters); assert( @@ -1112,11 +1115,11 @@ class _Allocator extends RecursiveVisitor { } @override - void visitVariableInitialization(VariableInitialization node) { + void visitVariableInitialization(VariableInitializationBase node) { _handleVariableInitialization(node); } - void _handleVariableInitialization(VariableInitialization node) { + void _handleVariableInitialization(VariableInitializationBase node) { _allocateVariable(node.variable); node.visitChildren(this); } @@ -1172,7 +1175,7 @@ class _Allocator extends RecursiveVisitor { node.iterable.accept(this); _enterScope(node); - node.expressionVariable.accept(this); + node.variable.accept(this); node.body.accept(this); _leaveScope(); @@ -1276,14 +1279,13 @@ class _Allocator extends RecursiveVisitor { @override void visitVariableGet(VariableGet node) { - _visit(node, temps: node.expressionVariable.isLate ? 1 : 0); + _visit(node, temps: node.variable.isLate ? 1 : 0); } @override void visitVariableSet(VariableSet node) { final bool needsTemp = - node.parent is! ExpressionStatement && - locals.isCaptured(node.expressionVariable); + node.parent is! ExpressionStatement && locals.isCaptured(node.variable); _visit(node, temps: needsTemp ? 1 : 0); } diff --git a/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart b/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart index 0e5292fe723..412e43e4190 100644 --- a/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart +++ b/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart @@ -701,7 +701,7 @@ String extractLocalNameFromLateLoweredSetter(String name) { /// int Extension|method(int #this) => #this; /// /// where '#this' is the synthetic "extension this" parameter. -bool isExtensionThis(Variable node) { +bool isExtensionThis(VariableDeclaration node) { assert( node.isLowered || node.cosmeticName == null || diff --git a/pkg/front_end/lib/src/base/crash.dart b/pkg/front_end/lib/src/base/crash.dart index 6a729695e18..35e5a6dced2 100644 --- a/pkg/front_end/lib/src/base/crash.dart +++ b/pkg/front_end/lib/src/base/crash.dart @@ -70,9 +70,11 @@ Future reportCrash( } if (hasCrashed) { + // Coverage-ignore-block(suite): Not run. return new Future.error(error, trace); } if (error is Crash) { + // Coverage-ignore-block(suite): Not run. trace = error.trace ?? trace; uri = error.uri ?? uri; charOffset = error.charOffset ?? charOffset; @@ -145,7 +147,9 @@ Future withCrashReporting( } on DebugAbort { rethrow; } catch (e, s) { - if (e is Crash && e._hasBeenReported) { + if (e is Crash && + // Coverage-ignore(suite): Not run. + e._hasBeenReported) { rethrow; } UriOffset? uriOffset = currentUriOffset(); diff --git a/pkg/front_end/lib/src/base/incremental_compiler.dart b/pkg/front_end/lib/src/base/incremental_compiler.dart index 19402b4af70..cb84c6ae0de 100644 --- a/pkg/front_end/lib/src/base/incremental_compiler.dart +++ b/pkg/front_end/lib/src/base/incremental_compiler.dart @@ -35,7 +35,6 @@ import 'package:kernel/kernel.dart' DartType, DynamicType, Expression, - Variable, ExtensionType, Field, FunctionNode, @@ -1212,7 +1211,6 @@ class IncrementalCompiler implements IncrementalKernelGenerator { experimentalFeatures: experimentalFeatures, ); if (before == null) { - // Coverage-ignore-block(suite): Not run. recorderForTesting?.recordAdvancedInvalidationResult( AdvancedInvalidationResult.noPreviousOutline, ); @@ -2559,10 +2557,10 @@ class ExpressionEvaluationHelperImpl implements ExpressionEvaluationHelper { CompilerContext compilerContext, Uri fileUri, ) { - if (knownButUnavailable.contains(node.expressionVariable)) { + if (knownButUnavailable.contains(node.variable)) { return _returnKnownVariableUnavailable( node, - node.expressionVariable, + node.variable, problemReporting, compilerContext, fileUri, @@ -2579,10 +2577,10 @@ class ExpressionEvaluationHelperImpl implements ExpressionEvaluationHelper { CompilerContext compilerContext, Uri fileUri, ) { - if (knownButUnavailable.contains(node.expressionVariable)) { + if (knownButUnavailable.contains(node.variable)) { return _returnKnownVariableUnavailable( node, - node.expressionVariable, + node.variable, problemReporting, compilerContext, fileUri, @@ -2593,7 +2591,7 @@ class ExpressionEvaluationHelperImpl implements ExpressionEvaluationHelper { ExpressionInferenceResult _returnKnownVariableUnavailable( Expression node, - Variable variable, + VariableDeclaration variable, ProblemReporting problemReporting, CompilerContext compilerContext, Uri fileUri, diff --git a/pkg/front_end/lib/src/base/modifiers.dart b/pkg/front_end/lib/src/base/modifiers.dart index d96ffba217b..e1c0ad51f58 100644 --- a/pkg/front_end/lib/src/base/modifiers.dart +++ b/pkg/front_end/lib/src/base/modifiers.dart @@ -181,11 +181,7 @@ extension type const Modifiers(int _mask) implements Object { Token? varFinalOrConst, }) { assert(abstractToken == null || abstractToken.type == Keyword.ABSTRACT); - assert( - augmentToken == null || - // Coverage-ignore(suite): Not run. - augmentToken.type == Keyword.AUGMENT, - ); + assert(augmentToken == null || augmentToken.type == Keyword.AUGMENT); assert(baseToken == null || baseToken.type == Keyword.BASE); assert(covariantToken == null || covariantToken.type == Keyword.COVARIANT); assert(constToken == null || constToken.type == Keyword.CONST); diff --git a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart index a8399f6f1bc..1e1870bf10e 100644 --- a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart +++ b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart @@ -15,7 +15,6 @@ import 'package:kernel/ast.dart' NamedParameter, NullLiteral, PositionalParameter, - VariableBase, VariableDeclaration; import 'package:kernel/class_hierarchy.dart'; @@ -29,6 +28,7 @@ import '../kernel/internal_ast.dart' InternalCatchVariable, InternalNamedParameter, InternalPositionalParameter, + InternalVariable, VariableDeclarationImpl; import '../kernel/resolver.dart'; import '../kernel/wildcard_lowering.dart'; @@ -68,7 +68,7 @@ abstract class ParameterBuilder { int get fileOffset; - VariableBase build(SourceLibraryBuilder library); + VariableDeclaration build(SourceLibraryBuilder library); } abstract class ParameterVariableBuilder @@ -292,11 +292,11 @@ class FormalParameterBuilder extends NamedBuilderImpl )..fileOffset = fileOffset; } } - return _variable!; + return _variable!.asExpressionVariable; } @override - VariableDeclaration get variable => _variable!; + VariableDeclaration get variable => _variable!.asExpressionVariable; @override void onInferredType(DartType type) { @@ -492,7 +492,7 @@ class FunctionTypeParameterBuilder implements ParameterBuilder { } @override - VariableBase build(SourceLibraryBuilder library) { + VariableDeclaration build(SourceLibraryBuilder library) { throw new UnsupportedError("${this.runtimeType}.build"); } } @@ -516,7 +516,7 @@ class CatchParameterBuilder extends NamedBuilderImpl final Uri fileUri; /// The variable declaration created for this catch parameter. - CatchVariable? _variable; + InternalVariable? _variable; /// If this is a wildcard variable, this holds the index used to create a /// uniquely named kernel variable for it. @@ -592,10 +592,10 @@ class CatchParameterBuilder extends NamedBuilderImpl String get fullNameForErrors => name; @override - CatchVariable get variable => _variable!; + VariableDeclaration get variable => _variable!.asExpressionVariable; @override - CatchVariable build(SourceLibraryBuilder library) { + VariableDeclaration build(SourceLibraryBuilder library) { if (_variable == null) { bool isTypeOmitted = type is OmittedTypeBuilder; DartType? builtType = type.build(library, TypeUse.parameterType); @@ -630,7 +630,7 @@ class CatchParameterBuilder extends NamedBuilderImpl )..fileOffset = fileOffset; } } - return _variable!; + return _variable!.asExpressionVariable; } @override diff --git a/pkg/front_end/lib/src/builder/variable_builder.dart b/pkg/front_end/lib/src/builder/variable_builder.dart index 1c5e2b8c4af..679bb08ad7c 100644 --- a/pkg/front_end/lib/src/builder/variable_builder.dart +++ b/pkg/front_end/lib/src/builder/variable_builder.dart @@ -2,13 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:kernel/ast.dart' show Variable; +import 'package:kernel/ast.dart' show VariableDeclaration; import '../base/lookup_result.dart'; import '../builder/builder.dart'; abstract class VariableBuilder implements Builder, LookupResult { - Variable get variable; + VariableDeclaration get variable; bool get isConst; diff --git a/pkg/front_end/lib/src/kernel/assigned_variables_impl.dart b/pkg/front_end/lib/src/kernel/assigned_variables_impl.dart index 5bb25792601..82e73e70469 100644 --- a/pkg/front_end/lib/src/kernel/assigned_variables_impl.dart +++ b/pkg/front_end/lib/src/kernel/assigned_variables_impl.dart @@ -6,10 +6,11 @@ import 'package:_fe_analyzer_shared/src/type_inference/assigned_variables.dart'; import 'package:_fe_analyzer_shared/src/type_inference/promotion_key_store.dart'; import 'package:kernel/ast.dart'; -class AssignedVariablesImpl implements AssignedVariables { - final AssignedVariables _delegate; - final AssignedVariables? _insideAsserts; - final AssignedVariables? _outsideAsserts; +class AssignedVariablesImpl + implements AssignedVariables { + final AssignedVariables _delegate; + final AssignedVariables? _insideAsserts; + final AssignedVariables? _outsideAsserts; int _assertDepth = 0; final Map? _deferredInsideAssertsByDeferredDelegate; @@ -20,10 +21,10 @@ class AssignedVariablesImpl implements AssignedVariables { this._delegate, { required bool isClosureContextLoweringEnabled, }) : _insideAsserts = isClosureContextLoweringEnabled - ? new AssignedVariables() + ? new AssignedVariables() : null, _outsideAsserts = isClosureContextLoweringEnabled - ? new AssignedVariables() + ? new AssignedVariables() : null, _deferredInsideAssertsByDeferredDelegate = isClosureContextLoweringEnabled @@ -71,7 +72,7 @@ class AssignedVariablesImpl implements AssignedVariables { } @override - void declare(Variable variable, {bool ignoreDuplicates = false}) { + void declare(VariableDeclaration variable, {bool ignoreDuplicates = false}) { _delegate.declare(variable, ignoreDuplicates: ignoreDuplicates); _insideAsserts?.declare(variable, ignoreDuplicates: ignoreDuplicates); _outsideAsserts?.declare(variable, ignoreDuplicates: ignoreDuplicates); @@ -152,7 +153,7 @@ class AssignedVariablesImpl implements AssignedVariables { } @override - PromotionKeyStore get promotionKeyStore { + PromotionKeyStore get promotionKeyStore { return _delegate.promotionKeyStore; } @@ -164,7 +165,7 @@ class AssignedVariablesImpl implements AssignedVariables { } @override - void read(Variable variable) { + void read(VariableDeclaration variable) { _delegate.read(variable); if (_isInsideAssert) { _insideAsserts?.read(variable); @@ -202,7 +203,7 @@ class AssignedVariablesImpl implements AssignedVariables { } @override - void write(Variable variable) { + void write(VariableDeclaration variable) { _delegate.write(variable); if (_isInsideAssert) { // Coverage-ignore-block(suite): Not run. diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart index 426a377d887..55fbd63de2b 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -170,7 +170,7 @@ abstract class BodyBuilder { BuildSingleExpressionResult buildSingleExpression({ required Token token, - required List extraKnownVariables, + required List extraKnownVariables, required List? typeParameterBuilders, required List? formals, required int fileOffset, @@ -341,7 +341,7 @@ class BodyBuilderImpl extends StackListenerImpl final LocalStack _localScopes; - Set? declaredInCurrentGuard; + Set? declaredInCurrentGuard; JumpTarget? breakTarget; @@ -628,11 +628,11 @@ class BodyBuilderImpl extends StackListenerImpl } @override - void registerVariableAssignment(Variable variable) { + void registerVariableAssignment(VariableDeclaration variable) { // TODO(cstefantsova): Always pass [variable] to [assignedVariables.write] // when [InferenceVisitorBase.flowAnalysis] will use // [InternalExpressionVariable] instead of [ExpressionVariable] (that is, - // pass it for the `Variable` type parameter of [FlowAnalysis]). + // pass it for the `VariableDeclaration` type parameter of [FlowAnalysis]). if (variable case InternalVariable variable) { assignedVariables.write(variable.astVariable); } else { @@ -826,7 +826,7 @@ class BodyBuilderImpl extends StackListenerImpl } void wrapVariableInitializerInError( - Variable variable, + VariableDeclaration variable, List context, ) { String name = variable.cosmeticName!; @@ -850,7 +850,7 @@ class BodyBuilderImpl extends StackListenerImpl } } - void declareVariable(Variable variable, LocalScope scope) { + void declareVariable(VariableDeclaration variable, LocalScope scope) { String name = variable.cosmeticName!; Builder? existing = scope.lookupLocalVariable(name); if (existing != null) { @@ -2502,7 +2502,7 @@ class BodyBuilderImpl extends StackListenerImpl } @override - void registerVariableRead(Variable variable) { + void registerVariableRead(VariableDeclaration variable) { if (variable case InternalVariable variable) { if (!variable.isLocalFunction && !variable.isWildcard) { assignedVariables.read(variable.astVariable); @@ -2518,7 +2518,7 @@ class BodyBuilderImpl extends StackListenerImpl /// Helper method to create a [VariableGet] of the [variable] using /// [charOffset] as the file offset. @override - VariableGet createVariableGet(Variable variable, int charOffset) { + VariableGet createVariableGet(VariableDeclaration variable, int charOffset) { registerVariableRead(variable); return new VariableGet(variable)..fileOffset = charOffset; } @@ -2527,7 +2527,7 @@ class BodyBuilderImpl extends StackListenerImpl /// using [token] and [charOffset] for offset information and [name] /// for `ExpressionGenerator._plainNameForRead`. ReadOnlyAccessGenerator _createReadOnlyVariableAccess( - Variable variable, + VariableDeclaration variable, Token token, int charOffset, String? name, @@ -2543,7 +2543,7 @@ class BodyBuilderImpl extends StackListenerImpl } @override - bool isDeclaredInEnclosingCase(Variable variable) { + bool isDeclaredInEnclosingCase(VariableDeclaration variable) { return declaredInCurrentGuard?.contains(variable) ?? false; } @@ -2678,7 +2678,7 @@ class BodyBuilderImpl extends StackListenerImpl diag.notAConstantExpression, ); } - Variable variable = getable.variable; + VariableDeclaration variable = getable.variable; if (forStatementScope && getable.isAssignable && getable.isLate && @@ -3331,7 +3331,7 @@ class BodyBuilderImpl extends StackListenerImpl } pushNewLocalVariable(initializer, equalsToken: assignmentOperator); if (isLate) { - VariableInitialization node = peek() as VariableInitialization; + VariableInitializationBase node = peek() as VariableInitializationBase; // This is matched by the call to [beginNode] in // [beginVariableInitializer]. @@ -3390,7 +3390,7 @@ class BodyBuilderImpl extends StackListenerImpl name = createWildcardVariableName(wildcardVariableIndex); wildcardVariableIndex++; } - VariableInitialization variableInitialization; + VariableInitializationBase variableInitialization; InternalVariable internalVariable; if (isClosureContextLoweringEnabled) { internalVariable = new InternalLocalVariable( @@ -3405,7 +3405,7 @@ class BodyBuilderImpl extends StackListenerImpl forSyntheticToken: identifier.token.isSynthetic, isImplicitlyTyped: currentLocalVariableType == null, ); - variableInitialization = new VariableInitialization( + variableInitialization = new VariableInitializationBase( variable: internalVariable.asExpressionVariable, initializer: initializer, hasDeclaredInitializer: initializer != null, @@ -3499,8 +3499,8 @@ class BodyBuilderImpl extends StackListenerImpl push(node); return; } - VariableInitialization variableInitialization = - node as VariableInitialization; + VariableInitializationBase variableInitialization = + node as VariableInitializationBase; variableInitialization.fileOffset = nameToken.charOffset; push(variableInitialization); @@ -3556,8 +3556,8 @@ class BodyBuilderImpl extends StackListenerImpl push(node); return; } - VariableInitialization variableInitialization = - node as VariableInitialization; + VariableInitializationBase variableInitialization = + node as VariableInitializationBase; if (annotations != null) { for (int i = 0; i < annotations.length; i++) { variableInitialization.addAnnotation(annotations[i]); @@ -3693,7 +3693,7 @@ class BodyBuilderImpl extends StackListenerImpl } } - List? _buildForLoopVariableDeclarations( + List? _buildForLoopVariableDeclarations( variableOrExpression, ) { // TODO(ahe): This can be simplified now that we have the events @@ -3701,40 +3701,41 @@ class BodyBuilderImpl extends StackListenerImpl if (variableOrExpression is Generator) { variableOrExpression = variableOrExpression.buildForEffect(); } - if (variableOrExpression is VariableInitialization) { + if (variableOrExpression is VariableInitializationBase) { // Late for loop variables are not supported. An error has already been // reported by the parser. variableOrExpression.isLate = false; - return [variableOrExpression]; + return [variableOrExpression]; } else if (variableOrExpression is Expression) { - VariableDeclaration variable = new VariableDeclarationImpl.forEffect( - variableOrExpression, - ); - return [variable]; + VariableInitializationBase variable = + new VariableDeclarationImpl.forEffect(variableOrExpression); + return [variable]; } else if (variableOrExpression is ExpressionStatement) { // Coverage-ignore-block(suite): Not run. - VariableDeclaration variable = new VariableDeclarationImpl.forEffect( - variableOrExpression.expression, - ); - return [variable]; + VariableInitializationBase variable = + new VariableDeclarationImpl.forEffect( + variableOrExpression.expression, + ); + return [variable]; } else if (intern.isVariablesDeclaration(variableOrExpression)) { return intern.variablesDeclarationExtractDeclarations( variableOrExpression, ); } else if (variableOrExpression is List) { // Coverage-ignore-block(suite): Not run. - List variables = []; + List variables = + []; for (Object v in variableOrExpression) { variables.addAll(_buildForLoopVariableDeclarations(v)!); } return variables; } else if (variableOrExpression is PatternVariableDeclaration) { // Coverage-ignore-block(suite): Not run. - return []; + return []; } else if (variableOrExpression is ParserRecovery) { - return []; + return []; } else if (variableOrExpression == null) { - return []; + return []; } return null; } @@ -3934,7 +3935,7 @@ class BodyBuilderImpl extends StackListenerImpl .popNode(); Object? variableOrExpression = pop(); - List? variables; + List? variables; List? intermediateVariables; if (variableOrExpression is PatternVariableDeclaration) { variables = pop() as List; // Internal variables. @@ -4053,7 +4054,7 @@ class BodyBuilderImpl extends StackListenerImpl .deferNode(); Object? variableOrExpression = pop(); - List? variables; + List? variables; List? intermediateVariables; if (variableOrExpression is PatternVariableDeclaration) { variables = pop() as List; @@ -5449,7 +5450,7 @@ class BodyBuilderImpl extends StackListenerImpl } } - Variable functionParameter; + VariableDeclaration functionParameter; if (memberKind == MemberKind.Catch) { functionParameter = (parameter as CatchParameterBuilder).build( libraryBuilder, @@ -5480,9 +5481,7 @@ class BodyBuilderImpl extends StackListenerImpl ..parent = functionParameter; } if (annotations != null) { - if (functionParameter is VariableDeclaration) { - functionParameter.clearAnnotations(); - } + functionParameter.clearAnnotations(); for (Expression annotation in annotations) { functionParameter.addAnnotation(annotation); } @@ -8065,7 +8064,8 @@ class BodyBuilderImpl extends StackListenerImpl ValueKinds.Expression, ValueKinds.Generator, ValueKinds.Pattern, - ValueKinds.Statement, // Variable for non-pattern for-in loop. + ValueKinds + .Statement, // VariableDeclaration for non-pattern for-in loop. ValueKinds.ParserRecovery, ]), ]), @@ -8134,7 +8134,7 @@ class BodyBuilderImpl extends StackListenerImpl null, ); assignedVariables.pushNode(assignedVariablesNodeInfo); - Variable variable = elements.variable; + VariableDeclaration variable = elements.variable; Expression? problem = elements.expressionProblem; if (entry is MapLiteralEntry) { ForInMapEntry result = intern.createForInMapEntry( @@ -8188,7 +8188,7 @@ class BodyBuilderImpl extends StackListenerImpl // constant evaluator further in the pipeline. lvalue.isConst = false; } - } else if (lvalue is VariableInitialization) { + } else if (lvalue is VariableInitializationBase) { // Late for-in variables are not supported. An error has already been // reported by the parser. lvalue.isLate = false; @@ -8205,7 +8205,7 @@ class BodyBuilderImpl extends StackListenerImpl // constant evaluator further in the pipeline. lvalue.isConst = false; } - } else if (lvalue is Variable) { + } else if (lvalue is VariableDeclaration) { // Coverage-ignore-block(suite): Not run. // Late for-in variables are not supported. An error has already been // reported by the parser. @@ -8223,8 +8223,8 @@ class BodyBuilderImpl extends StackListenerImpl lvalue.isConst = false; } } else { - Variable astVariable; - Variable variable; + VariableDeclaration astVariable; + VariableDeclaration variable; if (isClosureContextLoweringEnabled) { SyntheticVariable syntheticAstVariable = new SyntheticVariable( type: const DynamicType(), @@ -8387,7 +8387,7 @@ class BodyBuilderImpl extends StackListenerImpl lvalue, body, ); - Variable variable = elements.variable; + VariableDeclaration variable = elements.variable; Expression? problem = elements.expressionProblem; Statement forInStatement; if (elements.explicitVariableDeclaration != null) { @@ -11465,7 +11465,7 @@ class BodyBuilderImpl extends StackListenerImpl // Coverage-ignore(suite): Not run. BuildSingleExpressionResult buildSingleExpression({ required Token token, - required List extraKnownVariables, + required List extraKnownVariables, required List? typeParameterBuilders, required List? formals, required int fileOffset, @@ -11502,7 +11502,7 @@ class BodyBuilderImpl extends StackListenerImpl kind: LocalScopeKind.ifElement, ); enterLocalScope(extraKnownVariablesScope); - for (Variable extraVariable in extraKnownVariables) { + for (VariableDeclaration extraVariable in extraKnownVariables) { declareVariable(extraVariable, _localScope); assignedVariables.declare(extraVariable); } diff --git a/pkg/front_end/lib/src/kernel/body_builder_helpers.dart b/pkg/front_end/lib/src/kernel/body_builder_helpers.dart index 56e15de8323..3a3f32992cc 100644 --- a/pkg/front_end/lib/src/kernel/body_builder_helpers.dart +++ b/pkg/front_end/lib/src/kernel/body_builder_helpers.dart @@ -417,13 +417,13 @@ class Label { } class ForInElements { - Variable? explicitVariableDeclaration; - Variable? syntheticVariableDeclaration; + VariableDeclaration? explicitVariableDeclaration; + VariableDeclaration? syntheticVariableDeclaration; Expression? syntheticAssignment; Expression? expressionProblem; Statement? expressionEffects; - Variable get variable => + VariableDeclaration get variable => (explicitVariableDeclaration ?? syntheticVariableDeclaration)!; } diff --git a/pkg/front_end/lib/src/kernel/collections.dart b/pkg/front_end/lib/src/kernel/collections.dart index 33646069d1f..30b3be467a7 100644 --- a/pkg/front_end/lib/src/kernel/collections.dart +++ b/pkg/front_end/lib/src/kernel/collections.dart @@ -272,7 +272,7 @@ class ForElement extends ControlFlowElement implements ForElementBase { // May be empty, but not null. @override - final List variableInitializations; + final List variableInitializations; @override // Coverage-ignore(suite): Not run. @@ -386,10 +386,8 @@ class ForElement extends ControlFlowElement /// A 'for-in' element in a list or set literal. class ForInElement extends ControlFlowElement with ControlFlowElementMixin { - Variable expressionVariable; - // Coverage-ignore(suite): Not run. // Has no initializer. - VariableDeclaration get variable => expressionVariable as VariableDeclaration; + VariableDeclaration variable; Expression iterable; Expression? syntheticAssignment; // May be null. Statement? expressionEffects; // May be null. @@ -404,7 +402,7 @@ class ForInElement extends ControlFlowElement with ControlFlowElementMixin { Scope? scope; ForInElement( - this.expressionVariable, + this.variable, this.iterable, this.syntheticAssignment, this.expressionEffects, @@ -412,7 +410,7 @@ class ForInElement extends ControlFlowElement with ControlFlowElementMixin { this.problem, { this.isAsync = false, }) { - expressionVariable.parent = this; + variable.parent = this; iterable.parent = this; syntheticAssignment?.parent = this; expressionEffects?.parent = this; @@ -431,7 +429,7 @@ class ForInElement extends ControlFlowElement with ControlFlowElementMixin { @override // Coverage-ignore(suite): Not run. void visitChildren(Visitor v) { - expressionVariable.accept(v); + variable.accept(v); iterable.accept(v); syntheticAssignment?.accept(v); expressionEffects?.accept(v); @@ -442,8 +440,8 @@ class ForInElement extends ControlFlowElement with ControlFlowElementMixin { @override // Coverage-ignore(suite): Not run. void transformChildren(Transformer v) { - expressionVariable = v.transform(expressionVariable); - expressionVariable.parent = this; + variable = v.transform(variable); + variable.parent = this; iterable = v.transform(iterable); iterable.parent = this; if (syntheticAssignment != null) { @@ -465,8 +463,8 @@ class ForInElement extends ControlFlowElement with ControlFlowElementMixin { @override // Coverage-ignore(suite): Not run. void transformOrRemoveChildren(RemovingTransformer v) { - expressionVariable = v.transform(expressionVariable); - expressionVariable.parent = this; + variable = v.transform(variable); + variable.parent = this; iterable = v.transform(iterable); iterable.parent = this; if (syntheticAssignment != null) { @@ -496,7 +494,7 @@ class ForInElement extends ControlFlowElement with ControlFlowElementMixin { } if (bodyEntry == null) return null; ForInMapEntry result = new ForInMapEntry( - expressionVariable, + variable, iterable, syntheticAssignment, expressionEffects, @@ -612,7 +610,7 @@ class IfCaseElement extends ControlFlowElementImpl } abstract interface class ForElementBase implements AuxiliaryExpression { - List get variableInitializations; + List get variableInitializations; List get variables; @@ -631,7 +629,7 @@ class PatternForElement extends ControlFlowElementImpl // May be empty, but not null. @override - final List variableInitializations; + final List variableInitializations; @override // Coverage-ignore(suite): Not run. @@ -649,7 +647,7 @@ class PatternForElement extends ControlFlowElementImpl PatternForElement({ required this.patternVariableDeclaration, required this.intermediateVariables, - required List variables, + required List variables, required this.condition, required this.updates, required this.body, @@ -919,7 +917,7 @@ class IfMapEntry extends TreeNode } abstract interface class ForMapEntryBase implements TreeNode, MapLiteralEntry { - List get variableInitializations; + List get variableInitializations; List get variables; @@ -936,7 +934,7 @@ class ForMapEntry extends TreeNode implements ForMapEntryBase, ControlFlowMapEntry { // May be empty, but not null. @override - final List variableInitializations; + final List variableInitializations; @override // Coverage-ignore(suite): Not run. @@ -1034,7 +1032,7 @@ class PatternForMapEntry extends TreeNode List intermediateVariables; @override - final List variableInitializations; + final List variableInitializations; @override // Coverage-ignore(suite): Not run. @@ -1052,7 +1050,7 @@ class PatternForMapEntry extends TreeNode PatternForMapEntry({ required this.patternVariableDeclaration, required this.intermediateVariables, - required List variables, + required List variables, required this.condition, required this.updates, required this.body, @@ -1092,10 +1090,8 @@ class PatternForMapEntry extends TreeNode class ForInMapEntry extends TreeNode with ControlFlowMapEntryMixin implements ControlFlowMapEntry { - Variable expressionVariable; - // Coverage-ignore(suite): Not run. // Has no initializer. - VariableDeclaration get variable => expressionVariable as VariableDeclaration; + VariableDeclaration variable; Expression iterable; Expression? syntheticAssignment; // May be null. Statement? expressionEffects; // May be null. @@ -1110,7 +1106,7 @@ class ForInMapEntry extends TreeNode Scope? scope; ForInMapEntry( - this.expressionVariable, + this.variable, this.iterable, this.syntheticAssignment, this.expressionEffects, @@ -1118,7 +1114,7 @@ class ForInMapEntry extends TreeNode this.problem, { required this.isAsync, }) { - expressionVariable.parent = this; + variable.parent = this; iterable.parent = this; syntheticAssignment?.parent = this; expressionEffects?.parent = this; @@ -1137,7 +1133,7 @@ class ForInMapEntry extends TreeNode @override // Coverage-ignore(suite): Not run. void visitChildren(Visitor v) { - expressionVariable.accept(v); + variable.accept(v); iterable.accept(v); syntheticAssignment?.accept(v); expressionEffects?.accept(v); @@ -1148,8 +1144,8 @@ class ForInMapEntry extends TreeNode @override // Coverage-ignore(suite): Not run. void transformChildren(Transformer v) { - expressionVariable = v.transform(expressionVariable); - expressionVariable.parent = this; + variable = v.transform(variable); + variable.parent = this; iterable = v.transform(iterable); iterable.parent = this; if (syntheticAssignment != null) { @@ -1171,8 +1167,8 @@ class ForInMapEntry extends TreeNode @override // Coverage-ignore(suite): Not run. void transformOrRemoveChildren(RemovingTransformer v) { - expressionVariable = v.transform(expressionVariable); - expressionVariable.parent = this; + variable = v.transform(variable); + variable.parent = this; iterable = v.transform(iterable); iterable.parent = this; if (syntheticAssignment != null) { @@ -1396,7 +1392,7 @@ MapLiteralEntry convertToMapEntry( case ForInElement(): ForInMapEntry result = new ForInMapEntry( - element.expressionVariable, + element.variable, element.iterable, element.syntheticAssignment, element.expressionEffects, diff --git a/pkg/front_end/lib/src/kernel/const_conditional_simplifier.dart b/pkg/front_end/lib/src/kernel/const_conditional_simplifier.dart index e9918695631..bae47e1fe55 100644 --- a/pkg/front_end/lib/src/kernel/const_conditional_simplifier.dart +++ b/pkg/front_end/lib/src/kernel/const_conditional_simplifier.dart @@ -128,7 +128,7 @@ class _ConstantEvaluator extends TryConstantEvaluator { // TODO(fishythefish): Do caches need to be invalidated when the static type // context changes? /// Cache for local variables in the current method. - Map _variableCache = {}; + Map _variableCache = {}; final Map _staticFieldCache = {}; final Map _functionCache = {}; final Map _localFunctionCache = {}; @@ -168,7 +168,7 @@ class _ConstantEvaluator extends TryConstantEvaluator { return _evaluate(expression); } - Constant? _evaluateVariableGet(Variable variable) { + Constant? _evaluateVariableGet(VariableDeclaration variable) { // A function parameter can be declared final with an initializer, but // doesn't necessarily have the initializer's value. if (variable.parent is FunctionNode) return null; @@ -179,15 +179,12 @@ class _ConstantEvaluator extends TryConstantEvaluator { return _evaluate(initializer); } - Constant? _lookupVariableGet(Variable variable) => _variableCache.putIfAbsent( - variable, - () => _evaluateVariableGet(variable), - ); + Constant? _lookupVariableGet(VariableDeclaration variable) => _variableCache + .putIfAbsent(variable, () => _evaluateVariableGet(variable)); @override Constant visitVariableGet(VariableGet node) => - _lookupVariableGet(node.expressionVariable) ?? - super.visitVariableGet(node); + _lookupVariableGet(node.variable) ?? super.visitVariableGet(node); // Coverage-ignore(suite): Not run. Constant? _evaluateStaticFieldGet(Field field) { @@ -261,7 +258,7 @@ class _ConstantEvaluator extends TryConstantEvaluator { // // This can occur when calling const extension type constructors since these // are lowered into top level functions. - Map oldCache = _variableCache; + Map oldCache = _variableCache; _variableCache = {}; Constant result = _lookupStaticInvocation(node.target) ?? diff --git a/pkg/front_end/lib/src/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/kernel/constant_evaluator.dart index b773ae7f2f0..3ba80aeac10 100644 --- a/pkg/front_end/lib/src/kernel/constant_evaluator.dart +++ b/pkg/front_end/lib/src/kernel/constant_evaluator.dart @@ -587,12 +587,11 @@ class ConstantsTransformer extends RemovingTransformer { if (expression is StaticGet && expression.target.isConst) { // Handle [StaticGet] of constant fields also when these are not inlined. expression = (expression.target as Field).initializer!; - } else if (expression is VariableGet && - expression.expressionVariable.isConst) { + } else if (expression is VariableGet && expression.variable.isConst) { // Coverage-ignore-block(suite): Not run. // Handle [VariableGet] of constant locals also when these are not // inlined. - expression = expression.expressionVariable.initializer!; + expression = expression.variable.initializer!; } if (expression is ConstantExpression) { if (result.typeArguments.every(isInstantiated)) { @@ -2191,7 +2190,7 @@ class ConstantsTransformer extends RemovingTransformer { @override TreeNode visitVariableGet(VariableGet node, TreeNode? removalSentinel) { - final Variable variable = node.expressionVariable; + final VariableDeclaration variable = node.variable; if (variable.isConst) { variable.initializer = evaluateAndTransformWithContext( variable, @@ -4793,7 +4792,7 @@ class ConstantEvaluator // // TODO(kustermann): The heuristic of allowing all [VariableGet]s on [Let] // variables might allow more than it should. - final Variable variable = node.expressionVariable; + final VariableDeclaration variable = node.variable; if (enableConstFunctions || inExtensionTypeConstConstructor) { return env.lookupVariable(variable) ?? // Coverage-ignore(suite): Not run. @@ -4807,7 +4806,7 @@ class ConstantEvaluator if (variable.parent is Let || variable.parent is LocalInitializer || _isFormalParameter(variable)) { - return env.lookupVariable(node.expressionVariable) ?? + return env.lookupVariable(node.variable) ?? createEvaluationErrorConstant( node, diag.constEvalNonConstantVariableGet.withArguments( @@ -4830,7 +4829,7 @@ class ConstantEvaluator @override Constant visitVariableSet(VariableSet node) { if (enableConstFunctions || inExtensionTypeConstConstructor) { - final Variable variable = node.expressionVariable; + final VariableDeclaration variable = node.variable; Constant value = _evaluateSubexpression(node.value); if (value is AbortConstant) return value; Constant? result = env.updateVariableValue(variable, value); @@ -4841,7 +4840,7 @@ class ConstantEvaluator return createEvaluationErrorConstant( node, diag.constEvalError.withArguments( - message: 'Variable set of an unknown value.', + message: 'VariableDeclaration set of an unknown value.', ), ); } @@ -6108,7 +6107,7 @@ class StatementConstantEvaluator @override ExecutionStatus visitForStatement(ForStatement node) { - for (VariableInitialization variable in node.variableInitializations) { + for (VariableInitializationBase variable in node.variableInitializations) { final ExecutionStatus status = variable.accept(this); if (status is! ProceedStatus) return status; } @@ -6229,11 +6228,11 @@ class StatementConstantEvaluator ) || catchClause.guard == defaultType) { return exprEvaluator.withNewEnvironment(() { - if (catchClause.exceptionCatchVariable != null) { + if (catchClause.exception != null) { // TODO(kallentu): Store non-constant exceptions. if (throwValue is Constant) { exprEvaluator.env.addVariableValue( - catchClause.exceptionCatchVariable!, + catchClause.exception!, throwValue, ); } @@ -6424,14 +6423,15 @@ class EvaluationEnvironment { {}; /// The references to values of the parameters/variables in scope. - final Map _variables = - {}; + final Map _variables = + {}; /// The variables that hold unevaluated constants. /// /// Variables are removed from this set when looked up, leaving only the /// unread variables at the end. - final Set _unreadUnevaluatedVariables = new Set(); + final Set _unreadUnevaluatedVariables = + new Set(); final EvaluationEnvironment? _parent; @@ -6452,14 +6452,14 @@ class EvaluationEnvironment { _typeParameters[parameter] = value; } - void addVariableValue(Variable variable, Constant value) { + void addVariableValue(VariableDeclaration variable, Constant value) { _variables[variable] = new EvaluationReference(value); if (value is UnevaluatedConstant) { _unreadUnevaluatedVariables.add(variable); } } - Constant? updateVariableValue(Variable variable, Constant value) { + Constant? updateVariableValue(VariableDeclaration variable, Constant value) { EvaluationReference? reference = _variables[variable]; if (reference != null) { reference.value = value; @@ -6468,7 +6468,7 @@ class EvaluationEnvironment { return _parent?.updateVariableValue(variable, value); } - Constant? lookupVariable(Variable variable) { + Constant? lookupVariable(VariableDeclaration variable) { Constant? value = _variables[variable]?.value; if (value is UnevaluatedConstant) { _unreadUnevaluatedVariables.remove(variable); @@ -6483,7 +6483,8 @@ class EvaluationEnvironment { if (_unreadUnevaluatedVariables.isEmpty) return const []; // Coverage-ignore(suite): Not run. return _unreadUnevaluatedVariables.map( - (Variable variable) => _variables[variable]!.value as UnevaluatedConstant, + (VariableDeclaration variable) => + _variables[variable]!.value as UnevaluatedConstant, ); } @@ -6776,7 +6777,7 @@ class HasUninstantiatedVisitor extends FindTypeVisitor { } } -bool _isFormalParameter(Variable variable) { +bool _isFormalParameter(VariableDeclaration variable) { final TreeNode? parent = variable.parent; if (variable is FunctionParameter) { return true; diff --git a/pkg/front_end/lib/src/kernel/expression_generator.dart b/pkg/front_end/lib/src/kernel/expression_generator.dart index eedea40deb4..4b592178cfa 100644 --- a/pkg/front_end/lib/src/kernel/expression_generator.dart +++ b/pkg/front_end/lib/src/kernel/expression_generator.dart @@ -438,7 +438,7 @@ abstract class Generator { /// If the variable is final or read-only (like a parameter in a catch clause) a /// [ReadOnlyAccessGenerator] is created instead. class VariableUseGenerator extends Generator { - final Variable variable; + final VariableDeclaration variable; VariableUseGenerator( ExpressionGeneratorHelper helper, @@ -646,7 +646,7 @@ class ForInLateFinalVariableUseGenerator extends VariableUseGenerator { ForInLateFinalVariableUseGenerator( ExpressionGeneratorHelper helper, Token token, - Variable variable, + VariableDeclaration variable, ) : super(helper, token, variable); @override diff --git a/pkg/front_end/lib/src/kernel/expression_generator_helper.dart b/pkg/front_end/lib/src/kernel/expression_generator_helper.dart index 5921dbc2886..94c0eb9f649 100644 --- a/pkg/front_end/lib/src/kernel/expression_generator_helper.dart +++ b/pkg/front_end/lib/src/kernel/expression_generator_helper.dart @@ -82,7 +82,7 @@ abstract class ExpressionGeneratorHelper { LibraryFeatures get libraryFeatures; - bool isDeclaredInEnclosingCase(Variable variable); + bool isDeclaredInEnclosingCase(VariableDeclaration variable); Generator processLookupResult({ required LookupResult? lookupResult, @@ -225,17 +225,17 @@ abstract class ExpressionGeneratorHelper { /// Creates a [VariableGet] of the [variable] using [charOffset] as the file /// offset of the created node. - Expression createVariableGet(Variable variable, int charOffset); + Expression createVariableGet(VariableDeclaration variable, int charOffset); /// Registers that [variable] is read from. /// /// This is needed for type promotion. - void registerVariableRead(Variable variable); + void registerVariableRead(VariableDeclaration variable); /// Registers that [variable] is assigned to. /// /// This is needed for type promotion. - void registerVariableAssignment(Variable variable); + void registerVariableAssignment(VariableDeclaration variable); TypeEnvironment get typeEnvironment; diff --git a/pkg/front_end/lib/src/kernel/external_ast_helper.dart b/pkg/front_end/lib/src/kernel/external_ast_helper.dart index 42444521b99..11eea361bdc 100644 --- a/pkg/front_end/lib/src/kernel/external_ast_helper.dart +++ b/pkg/front_end/lib/src/kernel/external_ast_helper.dart @@ -169,7 +169,7 @@ VariableGet createVariableGet( /// Creates a [VariableSet] of [variable] with the [value]. Expression createVariableSet( - Variable variable, + VariableDeclaration variable, Expression value, { bool allowFinalAssignment = false, required int fileOffset, diff --git a/pkg/front_end/lib/src/kernel/internal_ast.dart b/pkg/front_end/lib/src/kernel/internal_ast.dart index f4b58d49d03..e2aa85e5758 100644 --- a/pkg/front_end/lib/src/kernel/internal_ast.dart +++ b/pkg/front_end/lib/src/kernel/internal_ast.dart @@ -33,7 +33,7 @@ import '../type_inference/inference_results.dart'; import '../type_inference/inference_visitor.dart'; typedef SharedMatchContext = - shared.MatchContext; + shared.MatchContext; mixin InternalTreeNode implements TreeNode { @override @@ -99,7 +99,7 @@ abstract class InternalStatement extends AuxiliaryStatement { } class ForInStatementWithSynthesizedVariable extends InternalStatement { - Variable? variable; + VariableDeclaration? variable; Expression iterable; Expression? syntheticAssignment; Statement? expressionEffects; @@ -927,7 +927,7 @@ class VariableDeclarationImpl extends VariableStatement with InternalVariableMixin implements InternalVariable { @override - Variable get astVariable => this; + VariableDeclaration get astVariable => this; @override final bool forSyntheticToken; @@ -1040,6 +1040,15 @@ class InternalLocalVariable extends TreeNode this.isLocalFunction = false, }); + @override + // Coverage-ignore(suite): Not run. + R accept(StatementVisitor v) => v.visitLocalVariable(astVariable); + + @override + // Coverage-ignore(suite): Not run. + R accept1(StatementVisitor1 v, A arg) => + v.visitLocalVariable(astVariable, arg); + @override String toString() { return "InternalLocalVariable(${toStringInternal()})"; @@ -1058,6 +1067,37 @@ class InternalLocalVariable extends TreeNode printer.write("[${modifiers.join(",")}]"); } } + + @override + int binaryOffsetNoTag = -1; + + @override + List? get contexts { + throw new UnsupportedError("${this.runtimeType}.contexts"); + } + + @override + void set contexts(List? value) { + throw new UnsupportedError("${this.runtimeType}.contexts="); + } + + @override + int fileEqualsOffset = TreeNode.noOffset; + + @override + // Coverage-ignore(suite): Not run. + VariableDeclaration get variable => this; + + @override + void set variable(VariableDeclaration variable) { + throw new UnsupportedError("${this.runtimeType}.variable="); + } + + @override + // Coverage-ignore(suite): Not run. + void clearAnnotations() { + annotations.clear(); + } } class InternalPositionalParameter extends TreeNode @@ -1083,23 +1123,17 @@ class InternalPositionalParameter extends TreeNode }); @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. List? get contexts { throw new UnsupportedError("${this.runtimeType}.contexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. void set contexts(List? value) { throw new UnsupportedError("${this.runtimeType}.contexts="); } - @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. - String get catchVariableName { - throw new UnsupportedError("${this.runtimeType}.catchVariableName"); - } - @override R accept(StatementVisitor v) => v.visitPositionalParameter(astVariable); @@ -1161,10 +1195,10 @@ class InternalPositionalParameter extends TreeNode @override // Coverage-ignore(suite): Not run. - Variable get variable => this; + VariableDeclaration get variable => this; @override - void set variable(Variable value) { + void set variable(VariableDeclaration value) { throw new UnsupportedError("${this.runtimeType}"); } } @@ -1192,23 +1226,17 @@ class InternalNamedParameter extends TreeNode }); @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. List? get contexts { throw new UnsupportedError("${this.runtimeType}.contexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. void set contexts(List? value) { throw new UnsupportedError("${this.runtimeType}.contexts="); } - @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. - String get catchVariableName { - throw new UnsupportedError("${this.runtimeType}.catchVariableName"); - } - @override R accept(StatementVisitor v) => v.visitNamedParameter(astVariable); @@ -1280,10 +1308,10 @@ class InternalNamedParameter extends TreeNode @override // Coverage-ignore(suite): Not run. - Variable get variable => this; + VariableDeclaration get variable => this; @override - void set variable(Variable value) { + void set variable(VariableDeclaration value) { throw new UnsupportedError("${this.runtimeType}"); } } @@ -1559,11 +1587,11 @@ mixin DelegatingVariableMixin on InternalVariableMixin @override // Coverage-ignore(suite): Not run. - VariableInitialization? get variableInitialization => + VariableInitializationBase? get variableInitialization => astVariable.variableInitialization; @override - void set variableInitialization(VariableInitialization? value) { + void set variableInitialization(VariableInitializationBase? value) { astVariable.variableInitialization = value; } @@ -1635,12 +1663,12 @@ mixin DelegatingVariableMixin on InternalVariableMixin @override // Coverage-ignore(suite): Not run. - R accept(TreeVisitor v) { + R accept(StatementVisitor v) { return astVariable.accept(v); } @override - R accept1(TreeVisitor1 v, A arg) { + R accept1(StatementVisitor1 v, A arg) { return astVariable.accept1(v, arg); } @@ -1716,6 +1744,52 @@ mixin DelegatingVariableMixin on InternalVariableMixin void visitChildren(Visitor v) { throw new UnsupportedError("${this.runtimeType}"); } + + @override + // Coverage-ignore(suite): Not run. + int get binaryOffsetNoTag => astVariable.binaryOffsetNoTag; + + @override + // Coverage-ignore(suite): Not run. + void set binaryOffsetNoTag(int value) { + astVariable.binaryOffsetNoTag = value; + } + + @override + // Coverage-ignore(suite): Not run. + List? get contexts => astVariable.contexts; + + @override + // Coverage-ignore(suite): Not run. + void set contexts(List? value) { + astVariable.contexts = value; + } + + @override + // Coverage-ignore(suite): Not run. + int get fileEqualsOffset => astVariable.fileEqualsOffset; + + @override + // Coverage-ignore(suite): Not run. + void set fileEqualsOffset(int value) { + astVariable.fileEqualsOffset = value; + } + + @override + // Coverage-ignore(suite): Not run. + VariableDeclaration get variable => astVariable.variable; + + @override + // Coverage-ignore(suite): Not run. + void set variable(VariableDeclaration value) { + astVariable.variable = value; + } + + @override + // Coverage-ignore(suite): Not run. + void clearAnnotations() { + astVariable.clearAnnotations(); + } } abstract interface class InternalVariable implements IVariable, Annotatable { @@ -1729,7 +1803,7 @@ abstract interface class InternalVariable implements IVariable, Annotatable { /// * using [astVariable] as a part of the generated AST, /// * checking semantic properties of an AST node, such as [isExtensionThis] /// in `lowering_predicates.dart`. - Variable get astVariable; + VariableDeclaration get astVariable; bool get forSyntheticToken; @@ -1813,7 +1887,7 @@ mixin InternalVariableMixin on TreeNode implements InternalVariable { String? lateName; @override - Variable get asExpressionVariable => this as Variable; + VariableDeclaration get asExpressionVariable => this as VariableDeclaration; } /// Front end specific implementation of [LoadLibrary]. @@ -4800,7 +4874,7 @@ bool isPureExpression(Expression node) { if (node is ThisExpression) { return true; } else if (node is VariableGet) { - return node.expressionVariable.isFinal && !node.expressionVariable.isLate; + return node.variable.isFinal && !node.variable.isLate; } return false; } @@ -4813,11 +4887,11 @@ Expression clonePureExpression(Expression node) { return new ThisExpression()..fileOffset = node.fileOffset; } else if (node is VariableGet) { assert( - node.expressionVariable.isFinal && !node.variable.isLate, + node.variable.isFinal && !node.variable.isLate, "Trying to clone VariableGet of non-final variable" - " ${node.expressionVariable}.", + " ${node.variable}.", ); - return new VariableGet(node.expressionVariable, node.promotedType) + return new VariableGet(node.variable, node.promotedType) ..fileOffset = node.fileOffset; } // Coverage-ignore-block(suite): Not run. diff --git a/pkg/front_end/lib/src/kernel/internal_ast_helper.dart b/pkg/front_end/lib/src/kernel/internal_ast_helper.dart index 2f3b0527861..46cc9340cf6 100644 --- a/pkg/front_end/lib/src/kernel/internal_ast_helper.dart +++ b/pkg/front_end/lib/src/kernel/internal_ast_helper.dart @@ -281,7 +281,7 @@ MapLiteralEntry createIfCaseMapEntry( ForElement createForElement( int fileOffset, - List variables, + List variables, Expression? condition, List updates, Expression body, @@ -294,7 +294,7 @@ PatternForElement createPatternForElement( int fileOffset, { required PatternVariableDeclaration patternVariableDeclaration, required List intermediateVariables, - required List variables, + required List variables, required Expression? condition, required List updates, required Expression body, @@ -311,7 +311,7 @@ PatternForElement createPatternForElement( ForMapEntry createForMapEntry( int fileOffset, - List variables, + List variables, Expression? condition, List updates, MapLiteralEntry body, @@ -324,7 +324,7 @@ PatternForMapEntry createPatternForMapEntry( int fileOffset, { required PatternVariableDeclaration patternVariableDeclaration, required List intermediateVariables, - required List variableInitializations, + required List variableInitializations, required Expression? condition, required List updates, required MapLiteralEntry body, @@ -341,7 +341,7 @@ PatternForMapEntry createPatternForMapEntry( ForInElement createForInElement( int fileOffset, - Variable variable, + VariableDeclaration variable, Expression iterable, Expression? synthesizedAssignment, Statement? expressionEffects, @@ -362,7 +362,7 @@ ForInElement createForInElement( ForInMapEntry createForInMapEntry( int fileOffset, - Variable variable, + VariableDeclaration variable, Expression iterable, Expression? synthesizedAssignment, Statement? expressionEffects, @@ -444,8 +444,8 @@ Statement createBreakStatement(int fileOffset, Object? label) { Catch createCatch( int fileOffset, DartType exceptionType, - CatchVariable? exceptionParameter, - CatchVariable? stackTraceParameter, + VariableDeclaration? exceptionParameter, + VariableDeclaration? stackTraceParameter, DartType stackTraceType, Statement body, ) { @@ -504,7 +504,7 @@ Statement createEmptyStatement(int fileOffset) { /// Return a representation of a for statement. Statement createForStatement( int fileOffset, - List? variables, + List? variables, Expression? condition, List updaters, Statement body, @@ -939,7 +939,7 @@ AndPattern createAndPattern(int fileOffset, Pattern left, Pattern right) { AssignedVariablePattern createAssignedVariablePattern( int fileOffset, - Variable variable, + VariableDeclaration variable, ) { return new AssignedVariablePattern(variable)..fileOffset = fileOffset; } diff --git a/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart b/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart index 9fc126f0cc4..bbaedda26e1 100644 --- a/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart +++ b/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:kernel/ast.dart' show Variable; +import 'package:kernel/ast.dart' show VariableDeclaration; import '../base/lookup_result.dart'; import '../builder/builder.dart'; @@ -18,7 +18,7 @@ class VariableBuilderImpl extends NamedBuilderImpl final Uri fileUri; @override - final Variable variable; + final VariableDeclaration variable; VariableBuilderImpl(this.name, this.variable, this.fileUri); diff --git a/pkg/front_end/lib/src/kernel/resolver.dart b/pkg/front_end/lib/src/kernel/resolver.dart index 32795be9e6b..c16c0cc5254 100644 --- a/pkg/front_end/lib/src/kernel/resolver.dart +++ b/pkg/front_end/lib/src/kernel/resolver.dart @@ -418,7 +418,9 @@ class Resolver { forPrimaryConstructor: false, ); context.performBacklog(result.annotations); - } on DebugAbort { + } + // Coverage-ignore(suite): Not run. + on DebugAbort { rethrow; } catch (e, s) { throw new Crash(fileUri, token.charOffset, e, s); @@ -840,7 +842,7 @@ class Resolver { required LookupScope scope, required Token token, required Procedure procedure, - required List extraKnownVariables, + required List extraKnownVariables, required ExpressionEvaluationHelper expressionEvaluationHelper, required VariableDeclaration? extensionThis, }) { @@ -937,7 +939,7 @@ class Resolver { ); } } - for (Variable extraVariable in extraKnownVariables) { + for (VariableDeclaration extraVariable in extraKnownVariables) { context.typeInferrer.flowAnalysis.declare( extraVariable, new SharedTypeView(extraVariable.type), diff --git a/pkg/front_end/lib/src/source/builder_factory.dart b/pkg/front_end/lib/src/source/builder_factory.dart index f476949490f..cab914b05ad 100644 --- a/pkg/front_end/lib/src/source/builder_factory.dart +++ b/pkg/front_end/lib/src/source/builder_factory.dart @@ -100,9 +100,7 @@ void _checkAugmentation( ? diag.unmatchedPatchDeclaration.withArguments( declarationName: declaration.displayName, ) - : - // Coverage-ignore(suite): Not run. - diag.unmatchedAugmentationDeclaration.withArguments( + : diag.unmatchedAugmentationDeclaration.withArguments( declarationName: declaration.displayName, ); } diff --git a/pkg/front_end/lib/src/source/source_function_builder.dart b/pkg/front_end/lib/src/source/source_function_builder.dart index c606545e62a..17da84b2dd0 100644 --- a/pkg/front_end/lib/src/source/source_function_builder.dart +++ b/pkg/front_end/lib/src/source/source_function_builder.dart @@ -61,8 +61,7 @@ void buildTypeParametersAndFormals( for (int i = 0; i < declaredFormals.length; i++) { FormalParameterBuilder formal = declaredFormals[i]; VariableDeclaration parameter = - (formal.build(libraryBuilder) as InternalVariable).astVariable - as VariableDeclaration; + (formal.build(libraryBuilder) as InternalVariable).astVariable; if (needsCheckVisitor != null) { if (parameter.type.accept(needsCheckVisitor)) { parameter.isCovariantByClass = true; diff --git a/pkg/front_end/lib/src/testing/id_extractor.dart b/pkg/front_end/lib/src/testing/id_extractor.dart index f2e2e3e11f4..6ea2b2eb229 100644 --- a/pkg/front_end/lib/src/testing/id_extractor.dart +++ b/pkg/front_end/lib/src/testing/id_extractor.dart @@ -284,8 +284,7 @@ abstract class DataExtractor extends VisitorDefault @override void visitEqualsNull(EqualsNull node) { Expression receiver = node.expression; - if (receiver is VariableGet && - receiver.expressionVariable.cosmeticName == null) { + if (receiver is VariableGet && receiver.variable.cosmeticName == null) { // This is a desugared `?.`. } else { _visitInvocation(node, Name.equalsName); @@ -373,8 +372,8 @@ abstract class DataExtractor extends VisitorDefault @override void visitVariableGet(VariableGet node) { - if (node.expressionVariable.cosmeticName != null && - !node.expressionVariable.isInitializingFormal) { + if (node.variable.cosmeticName != null && + !node.variable.isInitializingFormal) { // Skip use of synthetic variables. computeForNode( node, @@ -402,7 +401,7 @@ abstract class DataExtractor extends VisitorDefault @override void visitVariableSet(VariableSet node) { - if (node.expressionVariable.cosmeticName != null) { + if (node.variable.cosmeticName != null) { // Skip use of synthetic variables. computeForNode(node, createUpdateId(node)); } diff --git a/pkg/front_end/lib/src/type_inference/context_allocation_strategy.dart b/pkg/front_end/lib/src/type_inference/context_allocation_strategy.dart index 6b255f540bd..40ec4788e45 100644 --- a/pkg/front_end/lib/src/type_inference/context_allocation_strategy.dart +++ b/pkg/front_end/lib/src/type_inference/context_allocation_strategy.dart @@ -145,7 +145,7 @@ abstract class ContextAllocationStrategy { } void handleDeclarationOfVariable( - Variable variable, { + VariableDeclaration variable, { required CaptureKind captureKind, }); @@ -181,7 +181,7 @@ class TrivialContextAllocationStrategy extends ContextAllocationStrategy { @override void handleDeclarationOfVariable( - Variable variable, { + VariableDeclaration variable, { required CaptureKind captureKind, }) { assert(_currentScopeProviderInfo != null); @@ -256,7 +256,7 @@ class LoopDepthAllocationStrategy @override void handleDeclarationOfVariable( - Variable variable, { + VariableDeclaration variable, { required CaptureKind captureKind, }) { CollectorScopeProviderInfo currentScope = _currentScopeProviderInfo!; diff --git a/pkg/front_end/lib/src/type_inference/delayed_expressions.dart b/pkg/front_end/lib/src/type_inference/delayed_expressions.dart index 1956c2466ec..05251e85971 100644 --- a/pkg/front_end/lib/src/type_inference/delayed_expressions.dart +++ b/pkg/front_end/lib/src/type_inference/delayed_expressions.dart @@ -611,7 +611,7 @@ class EffectExpression implements DelayedExpression { /// to [_target]. class DelayedAssignment extends DelayedExpression { final MatchingCache _cache; - final Variable _target; + final VariableDeclaration _target; final DartType _type; final DelayedExpression _value; final bool hasEffect; diff --git a/pkg/front_end/lib/src/type_inference/for_in.dart b/pkg/front_end/lib/src/type_inference/for_in.dart index 9bee3fdf54c..f23026a4304 100644 --- a/pkg/front_end/lib/src/type_inference/for_in.dart +++ b/pkg/front_end/lib/src/type_inference/for_in.dart @@ -15,7 +15,7 @@ import 'object_access_target.dart'; import 'type_schema.dart' show UnknownType; class ForInResult { - final Variable variable; + final VariableDeclaration variable; final Expression iterable; final Expression? syntheticAssignment; final Statement? expressionSideEffects; @@ -49,7 +49,7 @@ class LocalForInVariable implements ForInVariable { @override DartType computeElementType(InferenceVisitorBase visitor) { - Variable variable = variableSet.expressionVariable; + VariableDeclaration variable = variableSet.variable; DartType? promotedType = visitor.flowAnalysis .promotedType(variable) // Coverage-ignore(suite): Not run. @@ -60,7 +60,7 @@ class LocalForInVariable implements ForInVariable { @override Expression inferAssignment(InferenceVisitorBase visitor, DartType rhsType) { DartType variableType = visitor.computeGreatestClosure( - variableSet.expressionVariable.type, + variableSet.variable.type, ); Expression rhs = visitor.ensureAssignable( variableType, @@ -75,7 +75,7 @@ class LocalForInVariable implements ForInVariable { variableSet, visitor.flowAnalysis.write( variableSet, - variableSet.expressionVariable, + variableSet.variable, new SharedTypeView(rhsType), null, ), @@ -93,7 +93,7 @@ class PatternVariableDeclarationForInVariable implements ForInVariable { // Coverage-ignore(suite): Not run. DartType computeElementType(InferenceVisitorBase visitor) { return (patternVariableDeclaration.initializer as VariableGet) - .expressionVariable + .variable .type; } diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor.dart b/pkg/front_end/lib/src/type_inference/inference_visitor.dart index 69c1029f863..bb2877402de 100644 --- a/pkg/front_end/lib/src/type_inference/inference_visitor.dart +++ b/pkg/front_end/lib/src/type_inference/inference_visitor.dart @@ -111,13 +111,13 @@ class InferenceVisitorImpl extends InferenceVisitorBase TreeNode, Statement, Expression, - Variable, + VariableDeclaration, Pattern, InvalidExpression, TypeDeclarationType, TypeDeclaration >, - NullShortingMixin, + NullShortingMixin, StackChecker, ExpressionVisitor1ExperimentExclusionMixin< ExpressionInferenceResult, @@ -204,7 +204,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase ) : _contextAllocationStrategy = new LoopDepthAllocationStrategy(); @override - // Coverage-ignore(suite): Not run. ThisVariable get internalThisVariable => _contextAllocationStrategy.thisVariable; @@ -1398,7 +1397,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase PropertyTarget computePropertyTarget(Expression target) { if (_enclosingCascade case Cascade( :var variable, - ) when target is VariableGet && target.expressionVariable == variable) { + ) when target is VariableGet && target.variable == variable) { // `target` is an implicit reference to the target of a cascade // expression; flow analysis uses `CascadePropertyTarget` to represent // this situation. @@ -3193,14 +3192,14 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInResult handleForInDeclaringVariable( TreeNode node, - Variable variable, + VariableDeclaration variable, Expression iterable, Statement? expressionEffects, { bool isAsync = false, }) { DartType elementType; bool isVariableTypeNeeded = false; - Variable astVariable; + VariableDeclaration astVariable; if (variable case InternalVariable variable) { if (variable.isImplicitlyTyped) { isVariableTypeNeeded = true; @@ -3253,13 +3252,13 @@ class InferenceVisitorImpl extends InferenceVisitorBase ); Statement? expressionEffect; if (!identical(implicitDowncast, variableGet)) { - if (variable is VariableDeclaration) { + if (!isClosureContextLoweringEnabled) { variable.initializer = implicitDowncast..parent = variable; expressionEffect = variable; variable = tempVariable; } else { // Coverage-ignore-block(suite): Not run. - expressionEffect = new VariableInitialization( + expressionEffect = new VariableInitializationBase( variable: variable, initializer: implicitDowncast, ); @@ -3362,7 +3361,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInResult _handleForInWithoutVariable( TreeNode node, - Variable variable, + VariableDeclaration variable, Expression iterable, Expression? syntheticAssignment, Statement? expressionEffects, { @@ -3412,7 +3411,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInResult _handlePatternForIn( TreeNode node, - Variable variable, + VariableDeclaration variable, Expression iterable, Expression? syntheticAssignment, PatternVariableDeclaration patternVariableDeclaration, { @@ -3497,7 +3496,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInResult handleForInWithoutVariable( TreeNode node, - Variable variable, + VariableDeclaration variable, Expression iterable, Expression? syntheticAssignment, Statement? expressionEffects, { @@ -3535,18 +3534,18 @@ class InferenceVisitorImpl extends InferenceVisitorBase scopeProviderInfoKind: ScopeProviderInfoKind.Loop, ); } - assert(node.expressionVariable.cosmeticName != null); + assert(node.variable.cosmeticName != null); ForInResult result = handleForInDeclaringVariable( node, - node.expressionVariable, + node.variable, node.iterable, null, isAsync: node.isAsync, ); - Variable astVariable = result.variable is InternalVariable + VariableDeclaration astVariable = result.variable is InternalVariable ? (result.variable as InternalVariable).astVariable : result.variable; - node.expressionVariable = astVariable..parent = node; + node.variable = astVariable..parent = node; if (isClosureContextLoweringEnabled) { _contextAllocationStrategy.handleDeclarationOfVariable( astVariable, @@ -3637,9 +3636,9 @@ class InferenceVisitorImpl extends InferenceVisitorBase scopeProviderInfoKind: ScopeProviderInfoKind.Loop, ); } - List? variables; + List? variables; for (int index = 0; index < node.variableInitializations.length; index++) { - VariableInitialization variable = node.variableInitializations[index]; + VariableInitializationBase variable = node.variableInitializations[index]; if (variable.name == null) { if (variable.initializer != null) { ExpressionInferenceResult result = inferExpression( @@ -3655,7 +3654,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (variableResult.hasChanged) { // Coverage-ignore-block(suite): Not run. if (variables == null) { - variables = []; + variables = []; variables.addAll(node.variableInitializations.sublist(0, index)); } if (variableResult.statementCount == 1) { @@ -3813,7 +3812,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase for (VariableDeclaration parameter in parameters) { // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - Variable parameterAstVariable = + VariableDeclaration parameterAstVariable = (parameter as InternalVariable).astVariable; _contextAllocationStrategy.handleDeclarationOfVariable( parameterAstVariable, @@ -4570,13 +4569,14 @@ class InferenceVisitorImpl extends InferenceVisitorBase Map inferredConditionTypes, ) { // TODO(johnniwinther): Use _visitStatements instead. - List? variables; + List? variables; for ( int index = 0; index < element.variableInitializations.length; index++ ) { - VariableInitialization variable = element.variableInitializations[index]; + VariableInitializationBase variable = + element.variableInitializations[index]; if (variable.name == null) { if (variable.initializer != null) { ExpressionInferenceResult initializerResult = inferExpression( @@ -4673,10 +4673,10 @@ class InferenceVisitorImpl extends InferenceVisitorBase ); } ForInResult result; - if (element.expressionVariable.cosmeticName == null) { + if (element.variable.cosmeticName == null) { result = handleForInWithoutVariable( element, - element.expressionVariable, + element.variable, element.iterable, element.syntheticAssignment, element.expressionEffects, @@ -4686,16 +4686,16 @@ class InferenceVisitorImpl extends InferenceVisitorBase } else { result = handleForInDeclaringVariable( element, - element.expressionVariable, + element.variable, element.iterable, element.expressionEffects, isAsync: element.isAsync, ); } - Variable astVariable = result.variable is InternalVariable + VariableDeclaration astVariable = result.variable is InternalVariable ? (result.variable as InternalVariable).astVariable : result.variable; - element.expressionVariable = astVariable..parent = element; + element.variable = astVariable..parent = element; if (isClosureContextLoweringEnabled) { _contextAllocationStrategy.handleDeclarationOfVariable( astVariable, @@ -5546,7 +5546,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } ForInStatement loop = _createForInStatement( element.fileOffset, - element.expressionVariable, + element.variable, element.iterable, loopBody, isAsync: element.isAsync, @@ -6147,7 +6147,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } ForInStatement loop = _createForInStatement( entry.fileOffset, - entry.expressionVariable, + entry.variable, entry.iterable, loopBody, isAsync: entry.isAsync, @@ -7063,7 +7063,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForStatement _createForStatement( int fileOffset, - List variables, + List variables, Expression? condition, List updates, Statement body, @@ -7075,7 +7075,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInStatement _createForInStatement( int fileOffset, - Variable variable, + VariableDeclaration variable, Expression iterable, Statement body, { bool isAsync = false, @@ -7732,9 +7732,10 @@ class InferenceVisitorImpl extends InferenceVisitorBase _MapLiteralEntryOffsets offsets, ) { // TODO(johnniwinther): Use _visitStatements instead. - List? variables; + List? variables; for (int index = 0; index < entry.variableInitializations.length; index++) { - VariableInitialization variable = entry.variableInitializations[index]; + VariableInitializationBase variable = + entry.variableInitializations[index]; if (variable.name == null) { if (variable.initializer != null) { ExpressionInferenceResult result = inferExpression( @@ -7843,10 +7844,10 @@ class InferenceVisitorImpl extends InferenceVisitorBase ); } ForInResult result; - if (entry.expressionVariable.cosmeticName == null) { + if (entry.variable.cosmeticName == null) { result = handleForInWithoutVariable( entry, - entry.expressionVariable, + entry.variable, entry.iterable, entry.syntheticAssignment, entry.expressionEffects, @@ -7856,18 +7857,18 @@ class InferenceVisitorImpl extends InferenceVisitorBase } else { result = handleForInDeclaringVariable( entry, - entry.expressionVariable, + entry.variable, entry.iterable, entry.expressionEffects, isAsync: entry.isAsync, ); } - Variable astVariable = result.variable is InternalVariable + VariableDeclaration astVariable = result.variable is InternalVariable ? (result.variable as InternalVariable).astVariable : // Coverage-ignore(suite): Not run. result.variable; - entry.expressionVariable = astVariable..parent = entry; + entry.variable = astVariable..parent = entry; if (isClosureContextLoweringEnabled) { _contextAllocationStrategy.handleDeclarationOfVariable( astVariable, @@ -8564,7 +8565,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase return result; case ForInMapEntry(): ForInElement result = new ForInElement( - entry.expressionVariable, + entry.variable, entry.iterable, entry.syntheticAssignment, entry.expressionEffects, @@ -13232,7 +13233,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase DartType typeContext, ) { if (isClosureContextLoweringEnabled) { - // Coverage-ignore-block(suite): Not run. node.receiver = new VariableGet(internalThisVariable) ..fileOffset = node.fileOffset; } @@ -13288,7 +13288,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); if (isClosureContextLoweringEnabled) { - // Coverage-ignore-block(suite): Not run. node.receiver = new VariableGet(internalThisVariable) ..fileOffset = node.fileOffset; } @@ -13660,8 +13659,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase scopeProviderInfo = _contextAllocationStrategy.enterScopeProvider( scopeProviderInfoKind: ScopeProviderInfoKind.Catch, ); - if (node.exceptionCatchVariable - case CatchVariable exceptionCatchVariable?) { + if (node.exception case CatchVariable exceptionCatchVariable?) { // TODO(62401): Remove the casts when the flow analysis uses // [InternalExpressionVariable]s. exceptionCatchVariable = @@ -13672,8 +13670,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase captureKind: _captureKindForVariable(exceptionCatchVariable), ); } - if (node.stackTraceCatchVariable - case CatchVariable stackTraceCatchVariable?) { + if (node.stackTrace case CatchVariable stackTraceCatchVariable?) { // TODO(62401): Remove the casts when the flow analysis uses // [InternalExpressionVariable]s. stackTraceCatchVariable = @@ -13715,9 +13712,8 @@ class InferenceVisitorImpl extends InferenceVisitorBase // TODO(62401): Remove the casts when the flow analysis uses // [InternalExpressionVariable]s. flowAnalysis.tryCatchStatement_catchBegin( - (catchBlock.exceptionCatchVariable as InternalVariable?)?.astVariable, - (catchBlock.stackTraceCatchVariable as InternalVariable?) - ?.astVariable, + (catchBlock.exception as InternalVariable?)?.astVariable, + (catchBlock.stackTrace as InternalVariable?)?.astVariable, ); visitCatch(catchBlock); flowAnalysis.tryCatchStatement_catchEnd(); @@ -13788,7 +13784,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase return result; } } - InternalVariable variable = node.expressionVariable as InternalVariable; + InternalVariable variable = node.variable as InternalVariable; var (DartType variableType, DartType writeContext) = computeVariableSetTypeAndWriteContext(variable); ExpressionInferenceResult rhsResult = inferExpression( @@ -13873,7 +13869,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } } return inferVariableGet( - variable: node.expressionVariable as InternalVariable, + variable: node.variable as InternalVariable, typeContext: typeContext, nameOffset: node.fileOffset, node: node, @@ -14705,7 +14701,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } @override - FlowAnalysis get flow => + FlowAnalysis get flow => flowAnalysis; @override @@ -14897,7 +14893,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase void handleCase_afterCaseHeads( Statement node, int caseIndex, - Iterable variables, + Iterable variables, ) {} @override @@ -14973,7 +14969,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } @override - void setVariableType(Variable variable, SharedTypeView type) { + void setVariableType(VariableDeclaration variable, SharedTypeView type) { variable.type = type.unwrapTypeView(); } @@ -16512,7 +16508,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase @override void finishJoinedPatternVariable( - Variable variable, { + VariableDeclaration variable, { required JoinedPatternVariableLocation location, required JoinedPatternVariableInconsistency inconsistency, required bool isFinal, @@ -17139,7 +17135,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase return node is DotShorthand; } - CaptureKind _captureKindForVariable(Variable variable) { + CaptureKind _captureKindForVariable(VariableDeclaration variable) { int variableKey = assignedVariables.promotionKeyStore.keyForVariable( variable, ); @@ -17173,7 +17169,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase @override StatementInferenceResult visitVariableInitialization( - VariableInitialization node, + VariableInitializationBase node, ) { InternalVariable nodeVariable = node.variable as InternalVariable; StatementInferenceResult statementInferenceResult = @@ -17189,7 +17185,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } StatementInferenceResult _inferInternalExpressionVariableDeclaration( - VariableInitialization node, + VariableInitializationBase node, InternalVariable nodeVariable, ) { DartType declaredType = nodeVariable.isImplicitlyTyped @@ -17221,7 +17217,8 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (node.isLate && node.hasDeclaredInitializer) { // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - Variable variable = (node.variable as InternalVariable).astVariable; + VariableDeclaration variable = + (node.variable as InternalVariable).astVariable; if (isClosureContextLoweringEnabled) { _contextAllocationStrategy.handleVariablesCapturedByNode( node, diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart b/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart index 5d85c02a7d9..058678a0026 100644 --- a/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart +++ b/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart @@ -148,8 +148,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor { InferenceDataForTesting? get dataForTesting => _inferrer.dataForTesting; - FlowAnalysis get flowAnalysis => - _inferrer.flowAnalysis; + FlowAnalysis + get flowAnalysis => _inferrer.flowAnalysis; /// Provides access to the [OperationsCfe] object. This is needed by /// [isAssignable] and for caching types. @@ -252,13 +252,13 @@ abstract class InferenceVisitorBase implements InferenceVisitor { } TreeNode origNode = node; while (origNode is VariableGet && - origNode.expressionVariable.cosmeticName == null && - origNode.expressionVariable.initializer != null) { + origNode.variable.cosmeticName == null && + origNode.variable.initializer != null) { // This is a read of a synthetic variable, presumably from a "let". // Find the original expression. // TODO(johnniwinther): add a general solution for getting the // original node for testing. - origNode = origNode.expressionVariable.initializer!; + origNode = origNode.variable.initializer!; } dataForTesting!.flowAnalysisResult.nonPromotionReasons[origNode] = nonPromotionReasonText; @@ -2366,7 +2366,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { VariableDeclaration parameter = positionalParameters[i]; // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - Variable parameterAstVariable = + VariableDeclaration parameterAstVariable = (parameter as InternalVariable).astVariable; flowAnalysis.declare( parameterAstVariable, @@ -2386,7 +2386,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { for (VariableDeclaration parameter in function.namedParameters) { // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - Variable parameterAstVariable = + VariableDeclaration parameterAstVariable = (parameter as InternalVariable).astVariable; flowAnalysis.declare( parameterAstVariable, @@ -2877,7 +2877,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { functionType: null, )..fileOffset = fileOffset; } else if (receiver is VariableGet) { - Variable variable = receiver.expressionVariable; + VariableDeclaration variable = receiver.variable; TreeNode? parent = variable.parent; if (parent is FunctionDeclaration) { assert( @@ -2886,7 +2886,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { ); localName = variable.cosmeticName!; expression = new LocalFunctionInvocation( - variable as VariableDeclaration, + variable, createArgumentsFromInternalNode( result.typeArguments, result.positional, @@ -4033,9 +4033,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { result.applyResult( createSuperMethodInvocation( isClosureContextLoweringEnabled - ? - // Coverage-ignore(suite): Not run. - (new VariableGet(internalThisVariable)..fileOffset = fileOffset) + ? (new VariableGet(internalThisVariable)..fileOffset = fileOffset) : (new ThisExpression()..fileOffset = fileOffset), name, procedure, @@ -4079,9 +4077,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { // supported by backends. new SuperPropertyGet( isClosureContextLoweringEnabled - ? - // Coverage-ignore(suite): Not run. - (new VariableGet(internalThisVariable)..fileOffset = nameOffset) + ? (new VariableGet(internalThisVariable)..fileOffset = nameOffset) : (new ThisExpression()..fileOffset = nameOffset), name, member, @@ -4153,9 +4149,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { assert(node == null, "Unexpected node for super property set $node."); node = new SuperPropertySet( isClosureContextLoweringEnabled - ? - // Coverage-ignore(suite): Not run. - (new VariableGet(internalThisVariable)..fileOffset = nameOffset) + ? (new VariableGet(internalThisVariable)..fileOffset = nameOffset) : (new ThisExpression()..fileOffset = nameOffset), name, rhs, @@ -4272,7 +4266,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { flowAnalysis.getExpressionInfo(node), ); } else { - resultExpression = node..expressionVariable = variable.astVariable; + resultExpression = node..variable = variable.astVariable; } bool isUnassigned = !flowAnalysis.isAssigned(variable.astVariable); @@ -4324,11 +4318,11 @@ abstract class InferenceVisitorBase implements InferenceVisitor { compilerContext: compilerContext, expression: resultExpression, message: diag.finalNotAssignedError.withArguments( - variableName: node.expressionVariable.cosmeticName!, + variableName: node.variable.cosmeticName!, ), fileUri: fileUri, fileOffset: node.fileOffset, - length: node.expressionVariable.cosmeticName!.length, + length: node.variable.cosmeticName!.length, ), ); } else if (declaredOrInferredType.isPotentiallyNonNullable) { @@ -4338,11 +4332,11 @@ abstract class InferenceVisitorBase implements InferenceVisitor { compilerContext: compilerContext, expression: resultExpression, message: diag.nonNullableNotAssignedError.withArguments( - variableName: node.expressionVariable.cosmeticName!, + variableName: node.variable.cosmeticName!, ), fileUri: fileUri, fileOffset: node.fileOffset, - length: node.expressionVariable.cosmeticName!.length, + length: node.variable.cosmeticName!.length, ), ); } @@ -4416,7 +4410,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { ); } else { node.value = rhs..parent = node; - resultExpression = node..expressionVariable = variable.astVariable; + resultExpression = node..variable = variable.astVariable; } // Synthetic variables, local functions, and variables with // invalid types aren't checked. @@ -4432,11 +4426,11 @@ abstract class InferenceVisitorBase implements InferenceVisitor { compilerContext: compilerContext, expression: resultExpression, message: diag.lateDefinitelyAssignedError.withArguments( - variableName: node.expressionVariable.cosmeticName!, + variableName: node.variable.cosmeticName!, ), fileUri: fileUri, fileOffset: node.fileOffset, - length: node.expressionVariable.cosmeticName!.length, + length: node.variable.cosmeticName!.length, ), ); } @@ -4448,11 +4442,11 @@ abstract class InferenceVisitorBase implements InferenceVisitor { compilerContext: compilerContext, expression: resultExpression, message: diag.finalPossiblyAssignedError.withArguments( - variableName: node.expressionVariable.cosmeticName!, + variableName: node.variable.cosmeticName!, ), fileUri: fileUri, fileOffset: node.fileOffset, - length: node.expressionVariable.cosmeticName!.length, + length: node.variable.cosmeticName!.length, ), ); } @@ -4796,7 +4790,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Expression? initializer = first.initializer; if (initializer is! StaticInvocation) return false; if (initializer.target != engine.setFactory) return false; - return value.expressionVariable == first; + return value.variable == first; } /// Determines if the given [expression]'s type is precisely known at compile @@ -4847,7 +4841,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { } } if (expression is VariableGet) { - Variable variable = expression.expressionVariable; + VariableDeclaration variable = expression.variable; if (variable is VariableDeclarationImpl && variable.isLocalFunction) { return diag.invalidCastLocalFunction; } @@ -5599,7 +5593,12 @@ FunctionType replaceReturnType(FunctionType functionType, DartType returnType) { } class _WhyNotPromotedVisitor - implements NonPromotionReasonVisitor, Node, Variable> { + implements + NonPromotionReasonVisitor< + List, + Node, + VariableDeclaration + > { final InferenceVisitorBase inferrer; Member? propertyReference; @@ -5608,7 +5607,7 @@ class _WhyNotPromotedVisitor @override List visitDemoteViaExplicitWrite( - DemoteViaExplicitWrite reason, + DemoteViaExplicitWrite reason, ) { TreeNode node = reason.node as TreeNode; if (inferrer.dataForTesting != null) { diff --git a/pkg/front_end/lib/src/type_inference/type_constraint_gatherer.dart b/pkg/front_end/lib/src/type_inference/type_constraint_gatherer.dart index 88881246dca..03aab4202d1 100644 --- a/pkg/front_end/lib/src/type_inference/type_constraint_gatherer.dart +++ b/pkg/front_end/lib/src/type_inference/type_constraint_gatherer.dart @@ -21,14 +21,14 @@ import 'type_schema_environment.dart'; class TypeConstraintGatherer extends shared.TypeConstraintGenerator< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode > with shared.TypeConstraintGeneratorMixin< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode diff --git a/pkg/front_end/lib/src/type_inference/type_inference_engine.dart b/pkg/front_end/lib/src/type_inference/type_inference_engine.dart index 9326d319082..9c96f79ecc5 100644 --- a/pkg/front_end/lib/src/type_inference/type_inference_engine.dart +++ b/pkg/front_end/lib/src/type_inference/type_inference_engine.dart @@ -385,14 +385,14 @@ class TypeInferenceEngineImpl extends TypeInferenceEngine { if (dataForTesting != null) { // Coverage-ignore-block(suite): Not run. dataForTesting.flowAnalysisResult.assignedVariables = - new AssignedVariablesForTesting(); + new AssignedVariablesForTesting(); assignedVariables = new AssignedVariablesImpl( dataForTesting.flowAnalysisResult.assignedVariables!, isClosureContextLoweringEnabled: isClosureContextLoweringEnabled, ); } else { assignedVariables = new AssignedVariablesImpl( - new AssignedVariables(), + new AssignedVariables(), isClosureContextLoweringEnabled: isClosureContextLoweringEnabled, ); } @@ -456,7 +456,7 @@ class FlowAnalysisResult { final List definitelyUnassignedNodes = []; /// The assigned variables information that computed for the member. - AssignedVariablesForTesting? assignedVariables; + AssignedVariablesForTesting? assignedVariables; /// For each expression that led to an error because it was not promoted, a /// string describing the reason it was not promoted. @@ -471,14 +471,14 @@ class FlowAnalysisResult { class OperationsCfe with TypeAnalyzerOperationsMixin< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode > implements TypeAnalyzerOperations< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode @@ -605,7 +605,7 @@ class OperationsCfe bool isExtensionTypeInternal(DartType type) => type is ExtensionType; @override - bool isFinal(Variable variable) { + bool isFinal(VariableDeclaration variable) { return variable.isFinal; } @@ -693,7 +693,7 @@ class OperationsCfe } @override - SharedTypeView variableType(Variable variable) { + SharedTypeView variableType(VariableDeclaration variable) { // When late variables get lowered, their type is changed, but the // original type is stored in `VariableDeclarationImpl.lateType`, so we // use that if it exists. @@ -782,7 +782,7 @@ class OperationsCfe } @override - bool isVariableFinal(Variable node) { + bool isVariableFinal(VariableDeclaration node) { return node.isFinal; } @@ -1107,7 +1107,7 @@ class OperationsCfe @override TypeConstraintGenerator< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode @@ -1194,7 +1194,11 @@ class OperationsCfe /// Type inference results used for testing. class TypeInferenceResultForTesting - extends shared.TypeConstraintGenerationDataForTesting { + extends + shared.TypeConstraintGenerationDataForTesting< + VariableDeclaration, + TreeNode + > { final Map> inferredTypeArguments = {}; final Map inferredVariableTypes = {}; } diff --git a/pkg/front_end/lib/src/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/type_inference/type_inferrer.dart index f29d21f11f1..d00b5b1549c 100644 --- a/pkg/front_end/lib/src/type_inference/type_inferrer.dart +++ b/pkg/front_end/lib/src/type_inference/type_inferrer.dart @@ -39,7 +39,8 @@ abstract class TypeInferrer { ExtensionScope get extensionScope; /// Returns the [FlowAnalysis] used during inference. - FlowAnalysis get flowAnalysis; + FlowAnalysis + get flowAnalysis; AssignedVariablesImpl get assignedVariables; @@ -114,7 +115,7 @@ class TypeInferrerImpl implements TypeInferrer { TypeAnalyzerOptions typeAnalyzerOptions; @override - late final FlowAnalysis + late final FlowAnalysis flowAnalysis = new FlowAnalysis( operations, assignedVariables, @@ -435,8 +436,8 @@ class TypeInferrerImplBenchmarked implements TypeInferrer { AssignedVariablesImpl get assignedVariables => impl.assignedVariables; @override - FlowAnalysis get flowAnalysis => - impl.flowAnalysis; + FlowAnalysis + get flowAnalysis => impl.flowAnalysis; @override TypeSchemaEnvironment get typeSchemaEnvironment => impl.typeSchemaEnvironment; diff --git a/pkg/front_end/lib/src/type_inference/type_schema_environment.dart b/pkg/front_end/lib/src/type_inference/type_schema_environment.dart index e5ea75fac2b..fb64e0f5508 100644 --- a/pkg/front_end/lib/src/type_inference/type_schema_environment.dart +++ b/pkg/front_end/lib/src/type_inference/type_schema_environment.dart @@ -20,11 +20,12 @@ import 'type_inference_engine.dart'; import 'type_demotion.dart'; import 'type_schema.dart' show UnknownType; -typedef GeneratedTypeConstraint = shared.GeneratedTypeConstraint; +typedef GeneratedTypeConstraint = + shared.GeneratedTypeConstraint; typedef MergedTypeConstraint = shared.MergedTypeConstraint< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode @@ -32,7 +33,7 @@ typedef MergedTypeConstraint = typedef UnknownTypeConstraintOrigin = shared.UnknownTypeConstraintOrigin< - Variable, + VariableDeclaration, TypeDeclarationType, TypeDeclaration, TreeNode diff --git a/pkg/front_end/lib/src/util/textual_outline.dart b/pkg/front_end/lib/src/util/textual_outline.dart index fdc271d89e8..72c570455c4 100644 --- a/pkg/front_end/lib/src/util/textual_outline.dart +++ b/pkg/front_end/lib/src/util/textual_outline.dart @@ -1153,7 +1153,6 @@ class TextualOutlineListener extends Listener { if (message.code == diag.nativeClauseShouldBeAnnotation) { return; } - // Coverage-ignore-block(suite): Not run. gotError = true; } } diff --git a/pkg/front_end/test/id_tests/assigned_variables_test.dart b/pkg/front_end/test/id_tests/assigned_variables_test.dart index 130650ab366..f9c4f1a10e9 100644 --- a/pkg/front_end/test/id_tests/assigned_variables_test.dart +++ b/pkg/front_end/test/id_tests/assigned_variables_test.dart @@ -53,12 +53,12 @@ class AssignedVariablesDataComputer extends CfeDataComputer<_Data> { SourceMemberBuilder memberBuilder = lookupMemberBuilder(testResultData.compilerResult, member) as SourceMemberBuilder; - AssignedVariablesForTesting? assignedVariables = - memberBuilder - .dataForTesting! - .inferenceData - .flowAnalysisResult - .assignedVariables; + AssignedVariablesForTesting? + assignedVariables = memberBuilder + .dataForTesting! + .inferenceData + .flowAnalysisResult + .assignedVariables; if (assignedVariables == null) return; member.accept( new AssignedVariablesDataExtractor( @@ -72,7 +72,8 @@ class AssignedVariablesDataComputer extends CfeDataComputer<_Data> { class AssignedVariablesDataExtractor extends CfeDataExtractor<_Data> { final SourceLoaderDataForTesting _sourceLoaderDataForTesting; - final AssignedVariablesForTesting _assignedVariables; + final AssignedVariablesForTesting + _assignedVariables; AssignedVariablesDataExtractor( InternalCompilerResult compilerResult, diff --git a/pkg/front_end/test/id_tests/nullability_test.dart b/pkg/front_end/test/id_tests/nullability_test.dart index 9f8369f4598..78d9fe434e1 100644 --- a/pkg/front_end/test/id_tests/nullability_test.dart +++ b/pkg/front_end/test/id_tests/nullability_test.dart @@ -55,7 +55,7 @@ class NullabilityDataExtractor extends CfeDataExtractor { @override String? computeNodeValue(Id id, TreeNode node) { if (node is VariableGet && node.promotedType != null) { - if (node.expressionVariable.type.nullability != Nullability.nonNullable && + if (node.variable.type.nullability != Nullability.nonNullable && node.promotedType!.nullability == Nullability.nonNullable) { return 'nonNullable'; } diff --git a/pkg/front_end/test/static_types/type_arguments_test.dart b/pkg/front_end/test/static_types/type_arguments_test.dart index bab290e07f8..3a802461e3e 100644 --- a/pkg/front_end/test/static_types/type_arguments_test.dart +++ b/pkg/front_end/test/static_types/type_arguments_test.dart @@ -70,7 +70,7 @@ class TypeArgumentsVisitor extends VerifyingAnalysis { uri: astUri, ); InterfaceType variableInitializationType = interface - .createInterfaceType('VariableInitialization', uri: astUri); + .createInterfaceType('VariableInitializationBase', uri: astUri); DartType typeArgument = receiver.arguments.types.single; if (interface.isSubtypeOf(typeArgument, expressionType) && typeArgument != expressionType) { diff --git a/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.expect b/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.expect index e805f7dbd9f..1509358f2d2 100644 --- a/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.expect +++ b/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.expect @@ -12,178 +12,178 @@ class A extends core::Object { ; method method() → dynamic/* scope=[ #ctx1: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ {} method call() → core::Object?/* scope=[ #ctx2: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ return null; operator [](positional-parameter index) → core::Object?/* scope=[ #ctx3: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; positional-parameter index; ]), ] */ return null; operator []=(positional-parameter index, positional-parameter value) → void/* scope=[ #ctx4: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; positional-parameter index; positional-parameter value; ]), ] */ {} operator +(positional-parameter other) → self::A/* scope=[ #ctx5: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; positional-parameter other; ]), ] */ return this-variable; operator unary-() → self::A/* scope=[ #ctx6: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ return this-variable; method notCapturedMethodCall() → dynamic/* scope=[ #ctx7: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::method}(){() → dynamic}; } method notCapturedExpression() → dynamic/* scope=[ #ctx8: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable; } method notCapturedPropertyGet() → dynamic/* scope=[ #ctx9: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::field}{core::Object?}; } method notCapturedPropertySet() → dynamic/* scope=[ #ctx10: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::field} = null; } method notCapturedCall() → dynamic/* scope=[ #ctx11: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::call}(){() → core::Object?}; } method notCapturedIndexGet() → dynamic/* scope=[ #ctx12: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::[]}(0){(core::int) → core::Object?}; } method notCapturedIndexSet() → dynamic/* scope=[ #ctx13: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::[]=}(0, null){(core::int, core::Object?) → void}; } method notCapturedUnary() → dynamic/* scope=[ #ctx14: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::unary-}(){() → self::A}; } method notCapturedBinary() → dynamic/* scope=[ #ctx15: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::+}(this-variable){(self::A) → self::A}; } method notCapturedPropertyCall() → dynamic/* scope=[ #ctx16: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a}{self::A}.{self::A::call}(){() → core::Object?}; } method notCapturedPropertyPrefix() → dynamic/* scope=[ #ctx17: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::n} = this-variable.{self::A::n}{core::int}.{core::num::+}(1){(core::num) → core::int}; } method notCapturedPropertyPostfix() → dynamic/* scope=[ #ctx18: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::n} = this-variable.{self::A::n}{core::int}.{core::num::+}(1){(core::num) → core::int}; } method notCapturedPropertyIndexGet() → dynamic/* scope=[ #ctx19: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a}{self::A}.{self::A::[]}(0){(core::int) → core::Object?}; } method notCapturedPropertyIndexSet() → dynamic/* scope=[ #ctx20: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a}{self::A}.{self::A::[]=}(0, null){(core::int, core::Object?) → void}; } method notCapturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx21: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::aNull}{self::A?} == null ?{self::A?} this-variable.{self::A::aNull} = new self::A::•() : null; } method notCapturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx22: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a} = this-variable.{self::A::a}{self::A}.{self::A::+}(new self::A::•()){(self::A) → self::A}; } method capturedMethodCall() → dynamic/* scope=[ #ctx23: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx23 */ → dynamic => this-variable.{self::A::method}(){() → dynamic}; } method capturedExpression() → dynamic/* scope=[ #ctx24: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx24 */ → self::A => this-variable; } method capturedPropertyGet() → dynamic/* scope=[ #ctx25: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx25 */ → core::Object? => this-variable.{self::A::field}{core::Object?}; } method capturedPropertySet() → dynamic/* scope=[ #ctx26: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx26 */ → Null { @@ -192,21 +192,21 @@ class A extends core::Object { } method capturedCall() → dynamic/* scope=[ #ctx27: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx27 */ → core::Object? => this-variable.{self::A::call}(){() → core::Object?}; } method capturedIndexGet() → dynamic/* scope=[ #ctx28: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx28 */ → core::Object? => this-variable.{self::A::[]}(0){(core::int) → core::Object?}; } method capturedIndexSet() → dynamic/* scope=[ #ctx29: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx29 */ → Null { @@ -215,63 +215,63 @@ class A extends core::Object { } method capturedUnary() → dynamic/* scope=[ #ctx30: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx30 */ → self::A => this-variable.{self::A::unary-}(){() → self::A}; } method capturedBinary() → dynamic/* scope=[ #ctx31: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx31 */ → self::A => this-variable.{self::A::+}(this-variable){(self::A) → self::A}; } method capturedPropertyCall() → dynamic/* scope=[ #ctx32: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx32 */ → core::Object? => this-variable.{self::A::a}{self::A}.{self::A::call}(){() → core::Object?}; } method capturedPropertyPrefix() → dynamic/* scope=[ #ctx33: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx33 */ → core::int => this-variable.{self::A::n} = this-variable.{self::A::n}{core::int}.{core::num::+}(1){(core::num) → core::int}; } method capturedPropertyPostfix() → dynamic/* scope=[ #ctx34: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx34 */ → core::int => let final core::int #t1 = this-variable.{self::A::n}{core::int} in let final void #t2 = this-variable.{self::A::n} = #t1.{core::num::+}(1){(core::num) → core::int} in #t1; } method capturedPropertyIndexGet() → dynamic/* scope=[ #ctx35: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx35 */ → core::Object? => this-variable.{self::A::a}{self::A}.{self::A::[]}(0){(core::int) → core::Object?}; } method capturedPropertyIndexSet() → dynamic/* scope=[ #ctx36: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx36 */ → Null => let final self::A #t3 = this-variable.{self::A::a}{self::A} in let final core::int #t4 = 0 in let final has-declared-initializer Null #t5 = null in let final void #t6 = #t3.{self::A::[]=}(#t4, #t5){(core::int, core::Object?) → void} in #t5; } method capturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx37: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx37 */ → self::A => let final self::A? #t7 = this-variable.{self::A::aNull}{self::A?} in #t7 == null ?{self::A} this-variable.{self::A::aNull} = new self::A::•() : #t7{self::A}; } method capturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx38: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx38 */ → self::A => this-variable.{self::A::a} = this-variable.{self::A::a}{self::A}.{self::A::+}(new self::A::•()){(self::A) → self::A}; @@ -284,7 +284,7 @@ class B extends self::A { @#C1 method notCapturedMethodCall() → dynamic/* scope=[ #ctx39: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::method}(); @@ -292,7 +292,7 @@ class B extends self::A { @#C1 method notCapturedPropertyGet() → dynamic/* scope=[ #ctx40: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::field}; @@ -300,7 +300,7 @@ class B extends self::A { @#C1 method notCapturedPropertySet() → dynamic/* scope=[ #ctx41: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::field} = null; @@ -308,7 +308,7 @@ class B extends self::A { @#C1 method notCapturedCall() → dynamic/* scope=[ #ctx42: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::call}(); @@ -316,7 +316,7 @@ class B extends self::A { @#C1 method notCapturedIndexGet() → dynamic/* scope=[ #ctx43: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::[]}(0); @@ -324,7 +324,7 @@ class B extends self::A { @#C1 method notCapturedIndexSet() → dynamic/* scope=[ #ctx44: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::[]=}(0, null); @@ -332,7 +332,7 @@ class B extends self::A { @#C1 method notCapturedUnary() → dynamic/* scope=[ #ctx45: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::unary-}(); @@ -340,7 +340,7 @@ class B extends self::A { @#C1 method notCapturedBinary() → dynamic/* scope=[ #ctx46: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::+}(this-variable); @@ -348,7 +348,7 @@ class B extends self::A { @#C1 method notCapturedPropertyCall() → dynamic/* scope=[ #ctx47: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a}.{self::A::call}(){() → core::Object?}; @@ -356,7 +356,7 @@ class B extends self::A { @#C1 method notCapturedPropertyPrefix() → dynamic/* scope=[ #ctx48: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::n} = super{this-variable}.{self::A::n}.{core::num::+}(1){(core::num) → core::int}; @@ -364,7 +364,7 @@ class B extends self::A { @#C1 method notCapturedPropertyPostfix() → dynamic/* scope=[ #ctx49: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::n} = super{this-variable}.{self::A::n}.{core::num::+}(1){(core::num) → core::int}; @@ -372,7 +372,7 @@ class B extends self::A { @#C1 method notCapturedPropertyIndexGet() → dynamic/* scope=[ #ctx50: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a}.{self::A::[]}(0){(core::int) → core::Object?}; @@ -380,7 +380,7 @@ class B extends self::A { @#C1 method notCapturedPropertyIndexSet() → dynamic/* scope=[ #ctx51: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a}.{self::A::[]=}(0, null){(core::int, core::Object?) → void}; @@ -388,7 +388,7 @@ class B extends self::A { @#C1 method notCapturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx52: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::aNull} == null ?{self::A?} super{this-variable}.{self::A::aNull} = new self::A::•() : null; @@ -396,7 +396,7 @@ class B extends self::A { @#C1 method notCapturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx53: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a} = super{this-variable}.{self::A::a}.{self::A::+}(new self::A::•()){(self::A) → self::A}; @@ -404,7 +404,7 @@ class B extends self::A { @#C1 method capturedMethodCall() → dynamic/* scope=[ #ctx54: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx54 */ → dynamic => super{this-variable}.{self::A::method}(); @@ -412,7 +412,7 @@ class B extends self::A { @#C1 method capturedPropertyGet() → dynamic/* scope=[ #ctx55: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx55 */ → core::Object? => super{this-variable}.{self::A::field}; @@ -420,7 +420,7 @@ class B extends self::A { @#C1 method capturedPropertySet() → dynamic/* scope=[ #ctx56: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx56 */ → Null { @@ -430,7 +430,7 @@ class B extends self::A { @#C1 method capturedCall() → dynamic/* scope=[ #ctx57: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx57 */ → core::Object? => super{this-variable}.{self::A::call}(); @@ -438,7 +438,7 @@ class B extends self::A { @#C1 method capturedIndexGet() → dynamic/* scope=[ #ctx58: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx58 */ → core::Object? => super{this-variable}.{self::A::[]}(0); @@ -446,7 +446,7 @@ class B extends self::A { @#C1 method capturedIndexSet() → dynamic/* scope=[ #ctx59: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx59 */ → Null { @@ -456,7 +456,7 @@ class B extends self::A { @#C1 method capturedUnary() → dynamic/* scope=[ #ctx60: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx60 */ → self::A => super{this-variable}.{self::A::unary-}(); @@ -464,7 +464,7 @@ class B extends self::A { @#C1 method capturedBinary() → dynamic/* scope=[ #ctx61: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx61 */ → self::A => super{this-variable}.{self::A::+}(this-variable); @@ -472,7 +472,7 @@ class B extends self::A { @#C1 method capturedPropertyCall() → dynamic/* scope=[ #ctx62: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx62 */ → core::Object? => super{this-variable}.{self::A::a}.{self::A::call}(){() → core::Object?}; @@ -480,7 +480,7 @@ class B extends self::A { @#C1 method capturedPropertyPrefix() → dynamic/* scope=[ #ctx63: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx63 */ → core::int => super{this-variable}.{self::A::n} = super{this-variable}.{self::A::n}.{core::num::+}(1){(core::num) → core::int}; @@ -488,7 +488,7 @@ class B extends self::A { @#C1 method capturedPropertyPostfix() → dynamic/* scope=[ #ctx64: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx64 */ → core::int => let final core::int #t8 = super{this-variable}.{self::A::n} in let final void #t9 = super{this-variable}.{self::A::n} = #t8.{core::num::+}(1){(core::num) → core::int} in #t8; @@ -496,7 +496,7 @@ class B extends self::A { @#C1 method capturedPropertyIndexGet() → dynamic/* scope=[ #ctx65: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx65 */ → core::Object? => super{this-variable}.{self::A::a}.{self::A::[]}(0){(core::int) → core::Object?}; @@ -504,7 +504,7 @@ class B extends self::A { @#C1 method capturedPropertyIndexSet() → dynamic/* scope=[ #ctx66: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx66 */ → Null => let final self::A #t10 = super{this-variable}.{self::A::a} in let final core::int #t11 = 0 in let final has-declared-initializer Null #t12 = null in let final void #t13 = #t10.{self::A::[]=}(#t11, #t12){(core::int, core::Object?) → void} in #t12; @@ -512,7 +512,7 @@ class B extends self::A { @#C1 method capturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx67: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx67 */ → self::A => let final self::A? #t14 = super{this-variable}.{self::A::aNull} in #t14 == null ?{self::A} super{this-variable}.{self::A::aNull} = new self::A::•() : #t14{self::A}; @@ -520,7 +520,7 @@ class B extends self::A { @#C1 method capturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx68: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx68 */ → self::A => super{this-variable}.{self::A::a} = super{this-variable}.{self::A::a}.{self::A::+}(new self::A::•()){(self::A) → self::A}; diff --git a/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.modular.expect b/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.modular.expect index e805f7dbd9f..1509358f2d2 100644 --- a/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.modular.expect +++ b/pkg/front_end/testcases/closure_context_lowering/this_variable.dart.strong.modular.expect @@ -12,178 +12,178 @@ class A extends core::Object { ; method method() → dynamic/* scope=[ #ctx1: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ {} method call() → core::Object?/* scope=[ #ctx2: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ return null; operator [](positional-parameter index) → core::Object?/* scope=[ #ctx3: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; positional-parameter index; ]), ] */ return null; operator []=(positional-parameter index, positional-parameter value) → void/* scope=[ #ctx4: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; positional-parameter index; positional-parameter value; ]), ] */ {} operator +(positional-parameter other) → self::A/* scope=[ #ctx5: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; positional-parameter other; ]), ] */ return this-variable; operator unary-() → self::A/* scope=[ #ctx6: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ return this-variable; method notCapturedMethodCall() → dynamic/* scope=[ #ctx7: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::method}(){() → dynamic}; } method notCapturedExpression() → dynamic/* scope=[ #ctx8: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable; } method notCapturedPropertyGet() → dynamic/* scope=[ #ctx9: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::field}{core::Object?}; } method notCapturedPropertySet() → dynamic/* scope=[ #ctx10: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::field} = null; } method notCapturedCall() → dynamic/* scope=[ #ctx11: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::call}(){() → core::Object?}; } method notCapturedIndexGet() → dynamic/* scope=[ #ctx12: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::[]}(0){(core::int) → core::Object?}; } method notCapturedIndexSet() → dynamic/* scope=[ #ctx13: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::[]=}(0, null){(core::int, core::Object?) → void}; } method notCapturedUnary() → dynamic/* scope=[ #ctx14: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::unary-}(){() → self::A}; } method notCapturedBinary() → dynamic/* scope=[ #ctx15: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::+}(this-variable){(self::A) → self::A}; } method notCapturedPropertyCall() → dynamic/* scope=[ #ctx16: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a}{self::A}.{self::A::call}(){() → core::Object?}; } method notCapturedPropertyPrefix() → dynamic/* scope=[ #ctx17: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::n} = this-variable.{self::A::n}{core::int}.{core::num::+}(1){(core::num) → core::int}; } method notCapturedPropertyPostfix() → dynamic/* scope=[ #ctx18: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::n} = this-variable.{self::A::n}{core::int}.{core::num::+}(1){(core::num) → core::int}; } method notCapturedPropertyIndexGet() → dynamic/* scope=[ #ctx19: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a}{self::A}.{self::A::[]}(0){(core::int) → core::Object?}; } method notCapturedPropertyIndexSet() → dynamic/* scope=[ #ctx20: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a}{self::A}.{self::A::[]=}(0, null){(core::int, core::Object?) → void}; } method notCapturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx21: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::aNull}{self::A?} == null ?{self::A?} this-variable.{self::A::aNull} = new self::A::•() : null; } method notCapturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx22: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { this-variable.{self::A::a} = this-variable.{self::A::a}{self::A}.{self::A::+}(new self::A::•()){(self::A) → self::A}; } method capturedMethodCall() → dynamic/* scope=[ #ctx23: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx23 */ → dynamic => this-variable.{self::A::method}(){() → dynamic}; } method capturedExpression() → dynamic/* scope=[ #ctx24: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx24 */ → self::A => this-variable; } method capturedPropertyGet() → dynamic/* scope=[ #ctx25: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx25 */ → core::Object? => this-variable.{self::A::field}{core::Object?}; } method capturedPropertySet() → dynamic/* scope=[ #ctx26: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx26 */ → Null { @@ -192,21 +192,21 @@ class A extends core::Object { } method capturedCall() → dynamic/* scope=[ #ctx27: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx27 */ → core::Object? => this-variable.{self::A::call}(){() → core::Object?}; } method capturedIndexGet() → dynamic/* scope=[ #ctx28: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx28 */ → core::Object? => this-variable.{self::A::[]}(0){(core::int) → core::Object?}; } method capturedIndexSet() → dynamic/* scope=[ #ctx29: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx29 */ → Null { @@ -215,63 +215,63 @@ class A extends core::Object { } method capturedUnary() → dynamic/* scope=[ #ctx30: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx30 */ → self::A => this-variable.{self::A::unary-}(){() → self::A}; } method capturedBinary() → dynamic/* scope=[ #ctx31: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx31 */ → self::A => this-variable.{self::A::+}(this-variable){(self::A) → self::A}; } method capturedPropertyCall() → dynamic/* scope=[ #ctx32: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx32 */ → core::Object? => this-variable.{self::A::a}{self::A}.{self::A::call}(){() → core::Object?}; } method capturedPropertyPrefix() → dynamic/* scope=[ #ctx33: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx33 */ → core::int => this-variable.{self::A::n} = this-variable.{self::A::n}{core::int}.{core::num::+}(1){(core::num) → core::int}; } method capturedPropertyPostfix() → dynamic/* scope=[ #ctx34: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx34 */ → core::int => let final core::int #t1 = this-variable.{self::A::n}{core::int} in let final void #t2 = this-variable.{self::A::n} = #t1.{core::num::+}(1){(core::num) → core::int} in #t1; } method capturedPropertyIndexGet() → dynamic/* scope=[ #ctx35: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx35 */ → core::Object? => this-variable.{self::A::a}{self::A}.{self::A::[]}(0){(core::int) → core::Object?}; } method capturedPropertyIndexSet() → dynamic/* scope=[ #ctx36: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx36 */ → Null => let final self::A #t3 = this-variable.{self::A::a}{self::A} in let final core::int #t4 = 0 in let final has-declared-initializer Null #t5 = null in let final void #t6 = #t3.{self::A::[]=}(#t4, #t5){(core::int, core::Object?) → void} in #t5; } method capturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx37: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx37 */ → self::A => let final self::A? #t7 = this-variable.{self::A::aNull}{self::A?} in #t7 == null ?{self::A} this-variable.{self::A::aNull} = new self::A::•() : #t7{self::A}; } method capturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx38: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx38 */ → self::A => this-variable.{self::A::a} = this-variable.{self::A::a}{self::A}.{self::A::+}(new self::A::•()){(self::A) → self::A}; @@ -284,7 +284,7 @@ class B extends self::A { @#C1 method notCapturedMethodCall() → dynamic/* scope=[ #ctx39: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::method}(); @@ -292,7 +292,7 @@ class B extends self::A { @#C1 method notCapturedPropertyGet() → dynamic/* scope=[ #ctx40: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::field}; @@ -300,7 +300,7 @@ class B extends self::A { @#C1 method notCapturedPropertySet() → dynamic/* scope=[ #ctx41: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::field} = null; @@ -308,7 +308,7 @@ class B extends self::A { @#C1 method notCapturedCall() → dynamic/* scope=[ #ctx42: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::call}(); @@ -316,7 +316,7 @@ class B extends self::A { @#C1 method notCapturedIndexGet() → dynamic/* scope=[ #ctx43: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::[]}(0); @@ -324,7 +324,7 @@ class B extends self::A { @#C1 method notCapturedIndexSet() → dynamic/* scope=[ #ctx44: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::[]=}(0, null); @@ -332,7 +332,7 @@ class B extends self::A { @#C1 method notCapturedUnary() → dynamic/* scope=[ #ctx45: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::unary-}(); @@ -340,7 +340,7 @@ class B extends self::A { @#C1 method notCapturedBinary() → dynamic/* scope=[ #ctx46: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::+}(this-variable); @@ -348,7 +348,7 @@ class B extends self::A { @#C1 method notCapturedPropertyCall() → dynamic/* scope=[ #ctx47: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a}.{self::A::call}(){() → core::Object?}; @@ -356,7 +356,7 @@ class B extends self::A { @#C1 method notCapturedPropertyPrefix() → dynamic/* scope=[ #ctx48: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::n} = super{this-variable}.{self::A::n}.{core::num::+}(1){(core::num) → core::int}; @@ -364,7 +364,7 @@ class B extends self::A { @#C1 method notCapturedPropertyPostfix() → dynamic/* scope=[ #ctx49: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::n} = super{this-variable}.{self::A::n}.{core::num::+}(1){(core::num) → core::int}; @@ -372,7 +372,7 @@ class B extends self::A { @#C1 method notCapturedPropertyIndexGet() → dynamic/* scope=[ #ctx50: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a}.{self::A::[]}(0){(core::int) → core::Object?}; @@ -380,7 +380,7 @@ class B extends self::A { @#C1 method notCapturedPropertyIndexSet() → dynamic/* scope=[ #ctx51: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a}.{self::A::[]=}(0, null){(core::int, core::Object?) → void}; @@ -388,7 +388,7 @@ class B extends self::A { @#C1 method notCapturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx52: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::aNull} == null ?{self::A?} super{this-variable}.{self::A::aNull} = new self::A::•() : null; @@ -396,7 +396,7 @@ class B extends self::A { @#C1 method notCapturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx53: not-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { super{this-variable}.{self::A::a} = super{this-variable}.{self::A::a}.{self::A::+}(new self::A::•()){(self::A) → self::A}; @@ -404,7 +404,7 @@ class B extends self::A { @#C1 method capturedMethodCall() → dynamic/* scope=[ #ctx54: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx54 */ → dynamic => super{this-variable}.{self::A::method}(); @@ -412,7 +412,7 @@ class B extends self::A { @#C1 method capturedPropertyGet() → dynamic/* scope=[ #ctx55: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx55 */ → core::Object? => super{this-variable}.{self::A::field}; @@ -420,7 +420,7 @@ class B extends self::A { @#C1 method capturedPropertySet() → dynamic/* scope=[ #ctx56: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx56 */ → Null { @@ -430,7 +430,7 @@ class B extends self::A { @#C1 method capturedCall() → dynamic/* scope=[ #ctx57: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx57 */ → core::Object? => super{this-variable}.{self::A::call}(); @@ -438,7 +438,7 @@ class B extends self::A { @#C1 method capturedIndexGet() → dynamic/* scope=[ #ctx58: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx58 */ → core::Object? => super{this-variable}.{self::A::[]}(0); @@ -446,7 +446,7 @@ class B extends self::A { @#C1 method capturedIndexSet() → dynamic/* scope=[ #ctx59: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx59 */ → Null { @@ -456,7 +456,7 @@ class B extends self::A { @#C1 method capturedUnary() → dynamic/* scope=[ #ctx60: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx60 */ → self::A => super{this-variable}.{self::A::unary-}(); @@ -464,7 +464,7 @@ class B extends self::A { @#C1 method capturedBinary() → dynamic/* scope=[ #ctx61: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx61 */ → self::A => super{this-variable}.{self::A::+}(this-variable); @@ -472,7 +472,7 @@ class B extends self::A { @#C1 method capturedPropertyCall() → dynamic/* scope=[ #ctx62: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx62 */ → core::Object? => super{this-variable}.{self::A::a}.{self::A::call}(){() → core::Object?}; @@ -480,7 +480,7 @@ class B extends self::A { @#C1 method capturedPropertyPrefix() → dynamic/* scope=[ #ctx63: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx63 */ → core::int => super{this-variable}.{self::A::n} = super{this-variable}.{self::A::n}.{core::num::+}(1){(core::num) → core::int}; @@ -488,7 +488,7 @@ class B extends self::A { @#C1 method capturedPropertyPostfix() → dynamic/* scope=[ #ctx64: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx64 */ → core::int => let final core::int #t8 = super{this-variable}.{self::A::n} in let final void #t9 = super{this-variable}.{self::A::n} = #t8.{core::num::+}(1){(core::num) → core::int} in #t8; @@ -496,7 +496,7 @@ class B extends self::A { @#C1 method capturedPropertyIndexGet() → dynamic/* scope=[ #ctx65: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx65 */ → core::Object? => super{this-variable}.{self::A::a}.{self::A::[]}(0){(core::int) → core::Object?}; @@ -504,7 +504,7 @@ class B extends self::A { @#C1 method capturedPropertyIndexSet() → dynamic/* scope=[ #ctx66: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx66 */ → Null => let final self::A #t10 = super{this-variable}.{self::A::a} in let final core::int #t11 = 0 in let final has-declared-initializer Null #t12 = null in let final void #t13 = #t10.{self::A::[]=}(#t11, #t12){(core::int, core::Object?) → void} in #t12; @@ -512,7 +512,7 @@ class B extends self::A { @#C1 method capturedPropertyIfNullAssignment() → dynamic/* scope=[ #ctx67: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx67 */ → self::A => let final self::A? #t14 = super{this-variable}.{self::A::aNull} in #t14 == null ?{self::A} super{this-variable}.{self::A::aNull} = new self::A::•() : #t14{self::A}; @@ -520,7 +520,7 @@ class B extends self::A { @#C1 method capturedPropertyCompoundAssignment() → dynamic/* scope=[ #ctx68: direct-captured VariableContext([ - this-variable this-variable; + this-variable final this-variable; ]), ] */ { return () /* #ctx68 */ → self::A => super{this-variable}.{self::A::a} = super{this-variable}.{self::A::a}.{self::A::+}(new self::A::•()){(self::A) → self::A}; diff --git a/pkg/front_end/tool/ast_model.dart b/pkg/front_end/tool/ast_model.dart index 718b259da5e..71ed7612c8b 100644 --- a/pkg/front_end/tool/ast_model.dart +++ b/pkg/front_end/tool/ast_model.dart @@ -31,7 +31,7 @@ Uri computePackageConfig(Uri repoDir) => /// nominality. For instance the name of a variable declaration is taking as /// defining its identity. const Map _declarativeClassesNames = const { - 'VariableDeclaration': 'name', + 'LegacyVariableDeclaration': 'name', 'TypeParameter': 'name', 'StructuralParameter': 'name', 'LabeledStatement': null, @@ -63,6 +63,7 @@ const Set _interchangeableClasses = const { 'DartType', 'Initializer', 'Pattern', + 'VariableDeclaration', }; /// Names of subclasses of [NamedNode] that do _not_ have a `visitXReference` @@ -124,8 +125,8 @@ const Map> _fieldRuleMap = { 'TypedefTearOffConstant': {'parameters': FieldRule(isDeclaration: true)}, 'LocalInitializer': {'variable': FieldRule(isDeclaration: true)}, 'Let': {'variable': FieldRule(isDeclaration: true)}, - 'VariableGet': {'expressionVariable': FieldRule(isDeclaration: false)}, - 'VariableSet': {'expressionVariable': FieldRule(isDeclaration: false)}, + 'VariableGet': {'variable': FieldRule(isDeclaration: false)}, + 'VariableSet': {'variable': FieldRule(isDeclaration: false)}, 'LocalFunctionInvocation': {'variable': FieldRule(isDeclaration: false)}, 'LocalVariable': {'variableInitialization': FieldRule(isDeclaration: false)}, 'BreakStatement': {'target': FieldRule(isDeclaration: false)}, @@ -134,8 +135,8 @@ const Map> _fieldRuleMap = { 'SwitchStatement': {'cases': FieldRule(isDeclaration: true)}, 'ContinueSwitchStatement': {'target': FieldRule(isDeclaration: false)}, 'Catch': { - 'exceptionCatchVariable': FieldRule(isDeclaration: true), - 'stackTraceCatchVariable': FieldRule(isDeclaration: true), + 'exception': FieldRule(isDeclaration: true), + 'stackTrace': FieldRule(isDeclaration: true), }, 'LocalFunctionIdGenerator': {'_counter': null}, 'FunctionExpression': {'id': null}, @@ -159,8 +160,12 @@ const Map> _fieldRuleMap = { 'PatternSwitchCase': {'jointVariables': FieldRule(isDeclaration: true)}, 'PatternSwitchStatement': {'cases': FieldRule(isDeclaration: true)}, 'TypeVariable': {'parameter': FieldRule(isDeclaration: false)}, - 'ClassTypeParameterType': {'parameter': FieldRule(isDeclaration: false)}, + 'ClassTypeParameterType': { + 'parameter': FieldRule(isDeclaration: false), + 'thisVariable': FieldRule(isDeclaration: false), + }, 'NominalParameter': {'_variance': FieldRule(name: 'variance')}, + 'VariableInitialization': {'variable': FieldRule(isDeclaration: false)}, }; /// Data that determines exceptions to how fields are used. diff --git a/pkg/front_end/tool/generate_ast_coverage.dart b/pkg/front_end/tool/generate_ast_coverage.dart index 8bbf607ed39..e64214e08a9 100644 --- a/pkg/front_end/tool/generate_ast_coverage.dart +++ b/pkg/front_end/tool/generate_ast_coverage.dart @@ -126,7 +126,7 @@ Set missingNodes($visitorName visitor) { nestedClassNames.forEach((String innerName, Set classNames) { if (innerName == 'Node') return; sb.writeln(''' -/// Returns the set of [${innerName}Kind]s that were not visited by [visitor]. +/// Returns the set of [${innerName}Kind]s not visited by [visitor]. Set<${innerName}Kind> missing${innerName}s($visitorName visitor) { Set<${innerName}Kind> all = new Set<${innerName}Kind>.of(${innerName}Kind.values); diff --git a/pkg/front_end/tool/unreachable_if_finder.dart b/pkg/front_end/tool/unreachable_if_finder.dart index 972b974d5b9..f7b0a4db103 100644 --- a/pkg/front_end/tool/unreachable_if_finder.dart +++ b/pkg/front_end/tool/unreachable_if_finder.dart @@ -54,7 +54,7 @@ class UnreachableIfFinder extends RecursiveVisitor { List warnings = []; - Map knownValues = {}; + Map knownValues = {}; @override void visitIfStatement(IfStatement node) { @@ -75,7 +75,7 @@ class UnreachableIfFinder extends RecursiveVisitor { // TODO(jensj): We could make the visit return a bool? instead and use that // from the condition instead of doing special casing on `Not` and // `VariableGet`. - Variable? newKnownValueHere; + VariableDeclaration? newKnownValueHere; bool conditionNegated = false; if (condition is Not) { @@ -84,7 +84,7 @@ class UnreachableIfFinder extends RecursiveVisitor { } if (condition is VariableGet) { - bool? knownValue = knownValues[condition.expressionVariable]; + bool? knownValue = knownValues[condition.variable]; if (knownValue != null) { if (conditionNegated) knownValue = !knownValue; String? hint; @@ -102,9 +102,9 @@ class UnreachableIfFinder extends RecursiveVisitor { ), ); } else { - if (condition.expressionVariable.isFinal || - unwritten.contains(condition.expressionVariable)) { - newKnownValueHere = condition.expressionVariable; + if (condition.variable.isFinal || + unwritten.contains(condition.variable)) { + newKnownValueHere = condition.variable; } } } @@ -135,7 +135,7 @@ class EffectivelyFinal extends RecursiveVisitor { @override void visitVariableSet(VariableSet node) { - unwritten.remove(node.expressionVariable); + unwritten.remove(node.variable); super.visitVariableSet(node); } } diff --git a/pkg/kernel/lib/clone.dart b/pkg/kernel/lib/clone.dart index 0fb87755502..92f76d39e8f 100644 --- a/pkg/kernel/lib/clone.dart +++ b/pkg/kernel/lib/clone.dart @@ -607,7 +607,7 @@ class CloneVisitorNotMembers @override TreeNode visitForStatement(ForStatement node) { - List variables = node.variableInitializations + List variables = node.variableInitializations .map(clone) .toList(); return new ForStatement( @@ -620,7 +620,7 @@ class CloneVisitorNotMembers @override TreeNode visitForInStatement(ForInStatement node) { - Variable newVariable = clone(node.expressionVariable); + VariableDeclaration newVariable = clone(node.expressionVariable); return new ForInStatement( newVariable, clone(node.iterable), diff --git a/pkg/kernel/lib/src/ast/expressions.dart b/pkg/kernel/lib/src/ast/expressions.dart index 7b7720a188b..a78149fee16 100644 --- a/pkg/kernel/lib/src/ast/expressions.dart +++ b/pkg/kernel/lib/src/ast/expressions.dart @@ -202,15 +202,12 @@ class InvalidExpression extends Expression { class VariableGet extends Expression { /// The target variable. - Variable expressionVariable; + VariableDeclaration variable; /// Null if not promoted. DartType? promotedType; - VariableGet(this.expressionVariable, [this.promotedType]); - - /// The target variable as [VariableDeclaration]. - VariableDeclaration get variable => expressionVariable as VariableDeclaration; + VariableGet(this.variable, [this.promotedType]); @override DartType getStaticType(StaticTypeContext context) => @@ -218,7 +215,7 @@ class VariableGet extends Expression { @override DartType getStaticTypeInternal(StaticTypeContext context) { - return promotedType ?? expressionVariable.type; + return promotedType ?? variable.type; } @override @@ -259,7 +256,7 @@ class VariableGet extends Expression { @override void toTextInternal(AstPrinter printer) { - printer.write(printer.getVariableName(expressionVariable)); + printer.write(printer.getVariableName(variable)); if (promotedType != null) { printer.write('{'); printer.writeType(promotedType!); @@ -272,15 +269,12 @@ class VariableGet extends Expression { /// /// Evaluates to the value of [value]. class VariableSet extends Expression { - /// The target variable as [VariableDeclaration]. - VariableDeclaration get variable => expressionVariable as VariableDeclaration; - /// The target variable. - Variable expressionVariable; + VariableDeclaration variable; Expression value; - VariableSet(this.expressionVariable, this.value) { + VariableSet(this.variable, this.value) { value.parent = this; } @@ -323,7 +317,7 @@ class VariableSet extends Expression { @override void toTextInternal(AstPrinter printer) { - printer.write(printer.getVariableName(expressionVariable)); + printer.write(printer.getVariableName(variable)); printer.write(' = '); printer.writeExpression(value); } @@ -5567,112 +5561,3 @@ class TypedefTearOff extends Expression { printer.write(")"); } } - -/// [VariableRead] nodes are the replacement for the VariableGet nodes. -/// -/// Despite of the name, [VariableRead] can't read [TypeVariable]s, -/// which are also [VariableBase]s. -class VariableRead extends Expression { - final Variable variable; - - VariableRead({required this.variable}); - - @override - R accept(ExpressionVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); - } - - @override - R accept1(ExpressionVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); - } - - @override - DartType getStaticTypeInternal(StaticTypeContext context) { - // TODO(cstefantsova): Implement getStaticTypeInternal. - throw UnimplementedError(); - } - - @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. - } - - @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. - } - - @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. - } - - @override - String toString() { - return "VariableRead(${toStringInternal()})"; - } - - @override - void toTextInternal(AstPrinter printer) { - printer.write(printer.getVariableName(variable)); - } -} - -/// [VariableWrite] nodes are the replacement for the VariableSet nodes. -/// -/// Despite of the name, [VariableWrite] can't write into -/// [TypeVariable]s, which are also [VariableBase]s. -class VariableWrite extends Expression { - final Variable variable; - final Expression value; - - VariableWrite({required this.variable, required this.value}); - - @override - R accept(ExpressionVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); - } - - @override - R accept1(ExpressionVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); - } - - @override - DartType getStaticTypeInternal(StaticTypeContext context) { - // TODO(cstefantsova): Implement getStaticTypeInternal. - throw UnimplementedError(); - } - - @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. - } - - @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. - } - - @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. - } - - @override - String toString() { - return "VariableWrite(${toStringInternal()})"; - } - - @override - void toTextInternal(AstPrinter printer) { - printer.write(printer.getVariableName(variable)); - printer.write(' = '); - printer.writeExpression(value); - } -} diff --git a/pkg/kernel/lib/src/ast/helpers.dart b/pkg/kernel/lib/src/ast/helpers.dart index b34eb8860b9..87073d838c0 100644 --- a/pkg/kernel/lib/src/ast/helpers.dart +++ b/pkg/kernel/lib/src/ast/helpers.dart @@ -314,6 +314,5 @@ List getAsTypeArguments( bool isThisExpression(Expression expression) { return expression is ThisExpression || - expression is VariableGet && - expression.expressionVariable is ThisVariable; + expression is VariableGet && expression.variable is ThisVariable; } diff --git a/pkg/kernel/lib/src/ast/patterns.dart b/pkg/kernel/lib/src/ast/patterns.dart index 13fe5fe6caa..54ef35826a4 100644 --- a/pkg/kernel/lib/src/ast/patterns.dart +++ b/pkg/kernel/lib/src/ast/patterns.dart @@ -884,9 +884,9 @@ class WildcardPattern extends Pattern { } class AssignedVariablePattern extends Pattern { - VariableDeclaration get variable => expressionVariable as VariableDeclaration; + VariableDeclaration get variable => expressionVariable; - final Variable expressionVariable; + final VariableDeclaration expressionVariable; /// The type of the expression against which this pattern is matched. /// diff --git a/pkg/kernel/lib/src/ast/statements.dart b/pkg/kernel/lib/src/ast/statements.dart index 7ec6c0beb4b..eeeb3fc76da 100644 --- a/pkg/kernel/lib/src/ast/statements.dart +++ b/pkg/kernel/lib/src/ast/statements.dart @@ -539,7 +539,7 @@ class DoStatement extends Statement implements LoopStatement { class ForStatement extends Statement implements LoopStatement, ScopeProvider { // May be empty, but not null. - final List variableInitializations; + final List variableInitializations; List get variables => variableInitializations.cast(); Expression? condition; // May be null. @@ -640,10 +640,10 @@ class ForInStatement extends Statement implements LoopStatement, ScopeProvider { @override List? get fileOffsetsIfMultiple => [fileOffset, bodyOffset]; - Variable expressionVariable; + VariableDeclaration expressionVariable; // Has no initializer. - VariableDeclaration get variable => expressionVariable as VariableDeclaration; + VariableDeclaration get variable => expressionVariable; void set variable(VariableDeclaration value) { expressionVariable = value; @@ -1234,38 +1234,24 @@ class TryCatch extends Statement { class Catch extends TreeNode implements ScopeProvider { DartType guard; // Not null, defaults to dynamic. - CatchVariable? exceptionCatchVariable; - CatchVariable? stackTraceCatchVariable; + VariableDeclaration? exception; + VariableDeclaration? stackTrace; Statement body; @override Scope? scope; Catch( - this.exceptionCatchVariable, + this.exception, this.body, { this.guard = const DynamicType(), - CatchVariable? stackTrace, - }) : stackTraceCatchVariable = stackTrace { - exceptionCatchVariable?.parent = this; - stackTraceCatchVariable?.parent = this; + this.stackTrace, + }) { + exception?.parent = this; + stackTrace?.parent = this; body.parent = this; } - VariableDeclaration? get exception => - exceptionCatchVariable as VariableDeclaration?; - - void set exception(VariableDeclaration? value) { - exceptionCatchVariable = value; - } - - VariableDeclaration? get stackTrace => - stackTraceCatchVariable as VariableDeclaration?; - - void set stackTrace(VariableDeclaration? value) { - stackTraceCatchVariable = value; - } - @override R accept(TreeVisitor v) => v.visitCatch(this); @@ -1275,21 +1261,21 @@ class Catch extends TreeNode implements ScopeProvider { @override void visitChildren(Visitor v) { guard.accept(v); - exceptionCatchVariable?.accept(v); - stackTraceCatchVariable?.accept(v); + exception?.accept(v); + stackTrace?.accept(v); body.accept(v); } @override void transformChildren(Transformer v) { guard = v.visitDartType(guard); - if (exceptionCatchVariable != null) { - exceptionCatchVariable = v.transform(exceptionCatchVariable!); - exceptionCatchVariable?.parent = this; + if (exception != null) { + exception = v.transform(exception!); + exception?.parent = this; } - if (stackTraceCatchVariable != null) { - stackTraceCatchVariable = v.transform(stackTraceCatchVariable!); - stackTraceCatchVariable?.parent = this; + if (stackTrace != null) { + stackTrace = v.transform(stackTrace!); + stackTrace?.parent = this; } body = v.transform(body); body.parent = this; @@ -1298,17 +1284,13 @@ class Catch extends TreeNode implements ScopeProvider { @override void transformOrRemoveChildren(RemovingTransformer v) { guard = v.visitDartType(guard, cannotRemoveSentinel); - if (exceptionCatchVariable != null) { - exceptionCatchVariable = v.transformOrRemoveCatchVariable( - exceptionCatchVariable!, - ); - exceptionCatchVariable?.parent = this; + if (exception != null) { + exception = v.transformOrRemoveVariableDeclaration(exception!); + exception?.parent = this; } - if (stackTraceCatchVariable != null) { - stackTraceCatchVariable = v.transformOrRemoveCatchVariable( - stackTraceCatchVariable!, - ); - stackTraceCatchVariable?.parent = this; + if (stackTrace != null) { + stackTrace = v.transformOrRemoveVariableDeclaration(stackTrace!); + stackTrace?.parent = this; } body = v.transform(body); body.parent = this; @@ -1485,13 +1467,12 @@ class YieldStatement extends Statement { } } -abstract interface class VariableDeclaration +abstract interface class LegacyVariableDeclaration implements Annotatable, Statement, - Variable, - VariableInitialization, - CatchVariable { + VariableDeclaration, + VariableInitializationBase { /// The name of the variable as provided in the source code. /// /// The name of a variable can only be omitted if the variable is synthesized. @@ -1517,7 +1498,7 @@ abstract interface class VariableDeclaration @override abstract bool isCovariantByDeclaration; - /// If this [VariableDeclaration] is a parameter of a method, indicates + /// If this [LegacyVariableDeclaration] is a parameter of a method, indicates /// whether the method implementation needs to contain a runtime type check to /// deal with generic covariance. /// @@ -1636,7 +1617,7 @@ abstract interface class VariableDeclaration @override void clearAnnotations(); - factory VariableDeclaration( + factory LegacyVariableDeclaration( String? name, { Expression? initializer, DartType type, @@ -1655,7 +1636,7 @@ abstract interface class VariableDeclaration bool isWildcard, }) = VariableStatement; - factory VariableDeclaration.forValue( + factory LegacyVariableDeclaration.forValue( Expression? initializer, { bool isFinal, bool isConst, @@ -1676,7 +1657,7 @@ abstract interface class VariableDeclaration /// When this occurs as a statement, it must be a direct child of a [Block]. // // DESIGN TODO: Should we remove the 'final' modifier from variables? -class VariableStatement extends Statement implements VariableDeclaration { +class VariableStatement extends Statement implements LegacyVariableDeclaration { @override int fileEqualsOffset = TreeNode.noOffset; @@ -1782,23 +1763,17 @@ class VariableStatement extends Statement implements VariableDeclaration { } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. List? get contexts { throw new UnsupportedError("${this.runtimeType}.contexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. void set contexts(List? value) { throw new UnsupportedError("${this.runtimeType}.contexts="); } - @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. - String get catchVariableName { - throw new UnsupportedError("${this.runtimeType}.catchVariableName"); - } - static const int FlagFinal = 1 << 0; // Must match serialized bit positions. static const int FlagConst = 1 << 1; static const int FlagHasDeclaredInitializer = 1 << 2; @@ -2030,12 +2005,12 @@ class VariableStatement extends Statement implements VariableDeclaration { } @override - VariableInitialization? get variableInitialization { + VariableInitializationBase? get variableInitialization { throw new UnsupportedError("${this.runtimeType}"); } @override - void set variableInitialization(VariableInitialization? value) { + void set variableInitialization(VariableInitializationBase? value) { throw new UnsupportedError("${this.runtimeType}"); } @@ -2045,13 +2020,13 @@ class VariableStatement extends Statement implements VariableDeclaration { } @override - Variable get asExpressionVariable => this; + VariableDeclaration get asExpressionVariable => this; @override - Variable get variable => this; + VariableDeclaration get variable => this; @override - void set variable(Variable value) { + void set variable(VariableDeclaration value) { throw new UnsupportedError("${this.runtimeType}"); } @@ -2164,10 +2139,50 @@ class FunctionDeclaration extends Statement implements LocalFunction { /// The statement that marks the declaration of the variable in the source Dart /// program. If the [initializer] is `null`, the variable was declared without /// an initializer. -class VariableInitialization extends Statement - implements Annotatable, ContextConsumer { - Variable variable; +abstract class VariableInitializationBase + implements Statement, Annotatable, ContextConsumer { + abstract VariableDeclaration variable; + abstract Expression? initializer; + abstract bool hasDeclaredInitializer; + abstract int flags; + abstract bool isErroneouslyInitialized; + abstract bool isConst; + abstract bool isCovariantByClass; + abstract bool isCovariantByDeclaration; + abstract bool isFinal; + abstract bool isHoisted; + abstract bool isInitializingFormal; + abstract bool isLate; + abstract bool isLowered; + abstract bool isRequired; + abstract bool isSuperInitializingFormal; + abstract bool isSynthesized; + abstract bool isWildcard; + abstract int binaryOffsetNoTag; + abstract int fileEqualsOffset; + abstract String? name; + abstract DartType type; + abstract String? cosmeticName; + abstract VariableInitializationBase? variableInitialization; + factory VariableInitializationBase({ + required VariableDeclaration variable, + required Expression? initializer, + bool hasDeclaredInitializer, + }) = VariableInitialization; + + void clearAnnotations(); + bool get isAssignable; + VariableContext get context; + VariableDeclaration get asExpressionVariable; +} + +class VariableInitialization extends Statement + implements VariableInitializationBase { + @override + VariableDeclaration variable; + + @override Expression? initializer; @override @@ -2185,92 +2200,121 @@ class VariableInitialization extends Statement static const int FlagHasDeclaredInitializer = 1 << 0; static const int FlagErroneouslyInitialized = 1 << 1; + @override int flags = 0; + @override bool get hasDeclaredInitializer => flags & FlagHasDeclaredInitializer != 0; + @override void set hasDeclaredInitializer(bool value) { flags = value ? (flags | FlagHasDeclaredInitializer) : (flags & ~FlagHasDeclaredInitializer); } + @override bool get isErroneouslyInitialized => flags & FlagErroneouslyInitialized != 0; + @override void set isErroneouslyInitialized(bool value) { flags = value ? (flags | FlagErroneouslyInitialized) : (flags & ~FlagErroneouslyInitialized); } + @override bool get isConst => variable.isConst; + @override void set isConst(bool value) { variable.isConst = value; } + @override bool get isCovariantByClass => variable.isCovariantByClass; + @override void set isCovariantByClass(bool value) { variable.isCovariantByClass = value; } + @override bool get isCovariantByDeclaration => variable.isCovariantByDeclaration; + @override void set isCovariantByDeclaration(bool value) { variable.isCovariantByDeclaration = value; } + @override bool get isFinal => variable.isFinal; + @override void set isFinal(bool value) { variable.isFinal = value; } + @override bool get isHoisted => variable.isHoisted; + @override void set isHoisted(bool value) { variable.isHoisted = value; } + @override bool get isInitializingFormal => variable.isInitializingFormal; + @override void set isInitializingFormal(bool value) { variable.isInitializingFormal = value; } + @override bool get isLate => variable.isLate; + @override void set isLate(bool value) { variable.isLate = value; } + @override bool get isLowered => variable.isLowered; + @override void set isLowered(bool value) { variable.isLowered = value; } + @override bool get isRequired => variable.isRequired; + @override void set isRequired(bool value) { variable.isRequired = value; } + @override bool get isSuperInitializingFormal => variable.isSuperInitializingFormal; + @override void set isSuperInitializingFormal(bool value) { variable.isSuperInitializingFormal = value; } + @override bool get isSynthesized => variable.isSynthesized; + @override void set isSynthesized(bool value) { variable.isSynthesized = value; } + @override bool get isWildcard => variable.isWildcard; + @override void set isWildcard(bool value) { variable.isWildcard = value; } @@ -2330,18 +2374,24 @@ class VariableInitialization extends Statement @override List annotations = const []; + @override int binaryOffsetNoTag = TreeNode.noOffset; + @override int fileEqualsOffset = TreeNode.noOffset; + @override String? get name => variable.cosmeticName; + @override void set name(String? value) { variable.cosmeticName = value; } + @override DartType get type => variable.type; + @override void set type(DartType value) { variable.type = value; } @@ -2354,25 +2404,33 @@ class VariableInitialization extends Statement annotations.add(node..parent = this); } + @override void clearAnnotations() { annotations = const []; } + @override bool get isAssignable => variable.isAssignable; + @override String? get cosmeticName => variable.cosmeticName; + @override void set cosmeticName(String? value) { variable.cosmeticName = value; } - VariableInitialization? get variableInitialization => this; + @override + VariableInitializationBase? get variableInitialization => this; - void set variableInitialization(VariableInitialization? value) { + @override + void set variableInitialization(VariableInitializationBase? value) { throw new UnsupportedError("${this.runtimeType}"); } + @override VariableContext get context => variable.context; - Variable get asExpressionVariable => variable; + @override + VariableDeclaration get asExpressionVariable => variable; } diff --git a/pkg/kernel/lib/src/ast/variables.dart b/pkg/kernel/lib/src/ast/variables.dart index c19d7589972..e17c1b3085e 100644 --- a/pkg/kernel/lib/src/ast/variables.dart +++ b/pkg/kernel/lib/src/ast/variables.dart @@ -22,13 +22,13 @@ sealed class VariableBase extends TreeNode implements Annotatable { } /// This is a helper class to enable mixing a mixin into concrete -/// implementations of the sealed class [Variable]. It's not supposed +/// implementations of the sealed class [VariableDeclaration]. It's not supposed /// to be used as a type annotation, but purely for declaring the class /// hierarchy. abstract interface class IVariable implements TreeNode { abstract DartType type; abstract String? cosmeticName; - abstract VariableInitialization? variableInitialization; + abstract VariableInitializationBase? variableInitialization; abstract Expression? initializer; abstract bool isFinal; abstract bool isConst; @@ -44,6 +44,15 @@ abstract interface class IVariable implements TreeNode { abstract bool isWildcard; abstract bool isSuperInitializingFormal; abstract bool isErroneouslyInitialized; + + // The following is due to [VariableDeclaration] implementing + // [VariableInitialization]. + abstract int binaryOffsetNoTag; + abstract List? contexts; + abstract int fileEqualsOffset; + abstract VariableDeclaration variable; + void clearAnnotations(); + bool get isAssignable; bool get hasIsFinal; bool get hasIsConst; @@ -59,18 +68,19 @@ abstract interface class IVariable implements TreeNode { bool get hasIsWildcard; bool get hasIsSuperInitializingFormal; bool get hasIsErroneouslyInitialized; - Variable get asExpressionVariable; + VariableDeclaration get asExpressionVariable; } /// The root of the sealed hierarchy of non-type variables. -sealed class Variable extends VariableBase implements IVariable { +sealed class VariableDeclaration extends VariableBase + implements IVariable, Statement, VariableInitializationBase { /// Static type of the variable. @override abstract DartType type; /// Initialization node for the variable, if available. @override - abstract VariableInitialization? variableInitialization; + abstract VariableInitializationBase? variableInitialization; /// Derived from [variableInitialization], if available. @override @@ -107,6 +117,40 @@ sealed class Variable extends VariableBase implements IVariable { abstract bool isSuperInitializingFormal; @override abstract bool isErroneouslyInitialized; + + factory VariableDeclaration( + String? name, { + Expression? initializer, + DartType type, + int flags, + bool isFinal, + bool isConst, + bool isInitializingFormal, + bool isSuperInitializingFormal, + bool isCovariantByDeclaration, + bool isLate, + bool isRequired, + bool isLowered, + bool isSynthesized, + bool isHoisted, + bool hasDeclaredInitializer, + bool isWildcard, + }) = VariableStatement; + + factory VariableDeclaration.forValue( + Expression? initializer, { + bool isFinal, + bool isConst, + bool isInitializingFormal, + bool isSuperInitializingFormal, + bool isLate, + bool isRequired, + bool isLowered, + DartType type, + }) = VariableStatement.forValue; + + VariableDeclaration.empty(); + @override bool get hasIsFinal; @override @@ -140,14 +184,17 @@ sealed class Variable extends VariableBase implements IVariable { bool get isAssignable; @override - Variable get asExpressionVariable => this; + VariableDeclaration get asExpressionVariable => this; + + @override + String? get name; } /// Local variables. They aren't Statements. A [LocalVariable] is "declared" in -/// the [VariableContext] it appears in. [VariableInitialization] +/// the [VariableContext] it appears in. [VariableInitializationBase] /// (which is a [Statement]) marks the spot of the original variable declaration /// in the Dart program. -class LocalVariable extends Variable { +class LocalVariable extends VariableDeclaration { @override String? cosmeticName; @@ -155,7 +202,7 @@ class LocalVariable extends Variable { DartType type; @override - VariableInitialization? variableInitialization; + VariableInitializationBase? variableInitialization; @override List annotations = const []; @@ -167,7 +214,8 @@ class LocalVariable extends Variable { bool isConst = false, bool isLate = false, bool isWildcard = false, - }) : type = type ?? const DynamicType() { + }) : type = type ?? const DynamicType(), + super.empty() { this.isFinal = isFinal; this.isConst = isConst; this.isLate = isLate; @@ -326,10 +374,10 @@ class LocalVariable extends Variable { } @override - R accept(TreeVisitor v) => v.visitLocalVariable(this); + R accept(StatementVisitor v) => v.visitLocalVariable(this); @override - R accept1(TreeVisitor1 v, A arg) => + R accept1(StatementVisitor1 v, A arg) => v.visitLocalVariable(this, arg); @override @@ -365,6 +413,7 @@ class LocalVariable extends Variable { variableInitialization!.initializer = value; } + @override String? get name => cosmeticName; @override @@ -408,6 +457,40 @@ class LocalVariable extends Variable { @override bool get hasIsErroneouslyInitialized => false; + + @override + int binaryOffsetNoTag = -1; + + @override + List? get contexts { + throw new UnsupportedError("${this.runtimeType}.contexts"); + } + + @override + void set contexts(List? value) { + throw new UnsupportedError("${this.runtimeType}.contexts="); + } + + @override + int fileEqualsOffset = TreeNode.noOffset; + + @override + VariableDeclaration get variable => this; + + @override + void set variable(VariableDeclaration variable) { + throw new UnsupportedError("${this.runtimeType}.variable="); + } + + @override + void clearAnnotations() { + annotations.clear(); + } + + @override + set name(String? value) { + cosmeticName = value; + } } /// Since the `catch` block isn't invoked by the user code, but is redirected to @@ -421,7 +504,7 @@ class LocalVariable extends Variable { /// } catch (e, s) { /// bar(); /// } -class CatchVariable extends Variable { +class CatchVariable extends VariableDeclaration { final String catchVariableName; @override @@ -435,7 +518,8 @@ class CatchVariable extends Variable { required DartType? type, bool isWildcard = false, }) : catchVariableName = name, - type = type ?? const DynamicType() { + type = type ?? const DynamicType(), + super.empty() { this.isWildcard = isWildcard; } @@ -448,12 +532,12 @@ class CatchVariable extends Variable { } @override - VariableInitialization? get variableInitialization { + VariableInitializationBase? get variableInitialization { throw new UnsupportedError("${this.runtimeType}.variableInitialization"); } @override - void set variableInitialization(VariableInitialization? value) { + void set variableInitialization(VariableInitializationBase? value) { throw new UnsupportedError("${this.runtimeType}.variableInitialization="); } @@ -603,10 +687,10 @@ class CatchVariable extends Variable { bool get isAssignable => false; @override - R accept(TreeVisitor v) => v.visitCatchVariable(this); + R accept(StatementVisitor v) => v.visitCatchVariable(this); @override - R accept1(TreeVisitor1 v, A arg) => + R accept1(StatementVisitor1 v, A arg) => v.visitCatchVariable(this, arg); @override @@ -679,10 +763,47 @@ class CatchVariable extends Variable { @override bool get hasIsErroneouslyInitialized => false; + + @override + int binaryOffsetNoTag = -1; + + @override + List? get contexts { + throw new UnsupportedError("${this.runtimeType}.contexts"); + } + + @override + void set contexts(List? value) { + throw new UnsupportedError("${this.runtimeType}.contexts="); + } + + @override + int fileEqualsOffset = TreeNode.noOffset; + + @override + VariableDeclaration get variable => this; + + @override + void set variable(VariableDeclaration variable) { + throw new UnsupportedError("${this.runtimeType}.variable="); + } + + @override + void clearAnnotations() { + annotations.clear(); + } + + @override + String? get name => cosmeticName; + + @override + set name(String? value) { + cosmeticName = value; + } } /// Abstract parameter class, the parent for positional and named parameters. -sealed class FunctionParameter extends Variable implements VariableDeclaration { +sealed class FunctionParameter extends VariableDeclaration { Expression? defaultValue; FunctionParameter({ @@ -696,7 +817,7 @@ sealed class FunctionParameter extends Variable implements VariableDeclaration { required bool isLowered, required bool isSynthesized, required bool isWildcard, - }) { + }) : super.empty() { this.isCovariantByDeclaration = isCovariantByDeclaration; this.isRequired = isRequired; this.isInitializingFormal = isInitializingFormal; @@ -715,10 +836,10 @@ sealed class FunctionParameter extends Variable implements VariableDeclaration { /// Function parameters don't have initializers, only default values. @override - VariableInitialization? get variableInitialization => null; + VariableInitializationBase? get variableInitialization => null; @override - void set variableInitialization(VariableInitialization? value) {} + void set variableInitialization(VariableInitializationBase? value) {} @override Expression? get initializer => defaultValue; @@ -907,23 +1028,17 @@ class PositionalParameter extends FunctionParameter { }); @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. List? get contexts { throw new UnsupportedError("${this.runtimeType}.contexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. void set contexts(List? value) { throw new UnsupportedError("${this.runtimeType}.contexts="); } - @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. - String get catchVariableName { - throw new UnsupportedError("${this.runtimeType}.catchVariableName"); - } - @override void addAnnotation(Expression annotation) { if (annotations.isEmpty) { @@ -1015,10 +1130,10 @@ class PositionalParameter extends FunctionParameter { int fileEqualsOffset = TreeNode.noOffset; @override - Variable get variable => this; + VariableDeclaration get variable => this; @override - void set variable(Variable value) { + void set variable(VariableDeclaration value) { throw new UnsupportedError("${this.runtimeType}"); } } @@ -1057,23 +1172,17 @@ class NamedParameter extends FunctionParameter { }); @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. List? get contexts { throw new UnsupportedError("${this.runtimeType}.contexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [VariableInitialization] interface. Remove this. void set contexts(List? value) { throw new UnsupportedError("${this.runtimeType}.contexts="); } - @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. - String get catchVariableName { - throw new UnsupportedError("${this.runtimeType}.catchVariableName"); - } - @override void addAnnotation(Expression annotation) { if (annotations.isEmpty) { @@ -1165,16 +1274,16 @@ class NamedParameter extends FunctionParameter { } @override - Variable get variable => this; + VariableDeclaration get variable => this; @override - void set variable(Variable value) { + void set variable(VariableDeclaration value) { throw new UnsupportedError("${this.runtimeType}"); } } /// The variable storage for `this`. -class ThisVariable extends Variable { +class ThisVariable extends VariableDeclaration { @override String get cosmeticName => "this-variable"; @@ -1182,10 +1291,10 @@ class ThisVariable extends Variable { void set cosmeticName(String? value) {} @override - VariableInitialization? get variableInitialization => null; + VariableInitializationBase? get variableInitialization => null; @override - void set variableInitialization(VariableInitialization? value) {} + void set variableInitialization(VariableInitializationBase? value) {} @override DartType type; @@ -1194,7 +1303,7 @@ class ThisVariable extends Variable { @override List annotations = const []; - ThisVariable({required this.type}); + ThisVariable({required this.type}) : super.empty(); // TODO(cstefantsova): Consider a throwing implementation instead. @override @@ -1340,10 +1449,10 @@ class ThisVariable extends Variable { } @override - R accept(TreeVisitor v) => v.visitThisVariable(this); + R accept(StatementVisitor v) => v.visitThisVariable(this); @override - R accept1(TreeVisitor1 v, A arg) => + R accept1(StatementVisitor1 v, A arg) => v.visitThisVariable(this, arg); @override @@ -1373,6 +1482,7 @@ class ThisVariable extends Variable { throw new UnsupportedError("${this.runtimeType}"); } + @override String? get name => cosmeticName; @override @@ -1416,11 +1526,45 @@ class ThisVariable extends Variable { @override bool get hasIsErroneouslyInitialized => false; + + @override + int binaryOffsetNoTag = -1; + + @override + List? get contexts { + throw new UnsupportedError("${this.runtimeType}.contexts"); + } + + @override + void set contexts(List? value) { + throw new UnsupportedError("${this.runtimeType}.contexts="); + } + + @override + int fileEqualsOffset = TreeNode.noOffset; + + @override + VariableDeclaration get variable => this; + + @override + void set variable(VariableDeclaration variable) { + throw new UnsupportedError("${this.runtimeType}.variable="); + } + + @override + void clearAnnotations() { + annotations.clear(); + } + + @override + set name(String? value) { + cosmeticName = value; + } } /// A variable introduced during desugaring. Such variables don't correspond to /// any variable declared by the programmer. -class SyntheticVariable extends Variable { +class SyntheticVariable extends VariableDeclaration { @override String? cosmeticName; @@ -1428,13 +1572,13 @@ class SyntheticVariable extends Variable { DartType type; @override - VariableInitialization? variableInitialization; + VariableInitializationBase? variableInitialization; // TODO(cstefantsova): Consider a throwing implementation instead. @override List annotations = const []; - SyntheticVariable({this.cosmeticName, required this.type}); + SyntheticVariable({this.cosmeticName, required this.type}) : super.empty(); // TODO(cstefantsova): Consider a throwing implementation instead. @override @@ -1578,10 +1722,10 @@ class SyntheticVariable extends Variable { } @override - R accept(TreeVisitor v) => v.visitSyntheticVariable(this); + R accept(StatementVisitor v) => v.visitSyntheticVariable(this); @override - R accept1(TreeVisitor1 v, A arg) => + R accept1(StatementVisitor1 v, A arg) => v.visitSyntheticVariable(this, arg); @override @@ -1615,6 +1759,7 @@ class SyntheticVariable extends Variable { variableInitialization!.initializer = value; } + @override String? get name => cosmeticName; @override @@ -1658,6 +1803,40 @@ class SyntheticVariable extends Variable { @override bool get hasIsErroneouslyInitialized => false; + + @override + int binaryOffsetNoTag = -1; + + @override + List? get contexts { + throw new UnsupportedError("${this.runtimeType}.contexts"); + } + + @override + void set contexts(List? value) { + throw new UnsupportedError("${this.runtimeType}.contexts="); + } + + @override + int fileEqualsOffset = TreeNode.noOffset; + + @override + VariableDeclaration get variable => this; + + @override + void set variable(VariableDeclaration variable) { + throw new UnsupportedError("${this.runtimeType}.variable="); + } + + @override + void clearAnnotations() { + annotations.clear(); + } + + @override + set name(String? value) { + cosmeticName = value; + } } /// The enum reflecting the kind of a variable context. A context is diff --git a/pkg/kernel/lib/src/coverage.dart b/pkg/kernel/lib/src/coverage.dart index 5ea2d1fb66d..7078f937193 100644 --- a/pkg/kernel/lib/src/coverage.dart +++ b/pkg/kernel/lib/src/coverage.dart @@ -593,18 +593,6 @@ class CoverageVisitor implements Visitor { node.visitChildren(this); } - @override - void visitVariableRead(VariableRead node) { - visited.add(ExpressionKind.VariableRead); - node.visitChildren(this); - } - - @override - void visitVariableWrite(VariableWrite node) { - visited.add(ExpressionKind.VariableWrite); - node.visitChildren(this); - } - @override void visitSwitchExpression(SwitchExpression node) { visited.add(ExpressionKind.SwitchExpression); @@ -967,12 +955,6 @@ class CoverageVisitor implements Visitor { node.visitChildren(this); } - @override - void visitVariableInitialization(VariableInitialization node) { - visited.add(StatementKind.VariableInitialization); - node.visitChildren(this); - } - @override void visitVariableStatement(VariableStatement node) { visited.add(StatementKind.VariableStatement); @@ -985,6 +967,12 @@ class CoverageVisitor implements Visitor { node.visitChildren(this); } + @override + void visitVariableInitialization(VariableInitialization node) { + visited.add(StatementKind.VariableInitialization); + node.visitChildren(this); + } + @override void visitSwitchExpressionCase(SwitchExpressionCase node) { visited.add(NodeKind.SwitchExpressionCase); @@ -998,38 +986,38 @@ class CoverageVisitor implements Visitor { } @override - void visitCatchVariable(CatchVariable node) { - visited.add(NodeKind.CatchVariable); + void visitLocalVariable(LocalVariable node) { + visited.add(VariableDeclarationKind.LocalVariable); node.visitChildren(this); } @override - void visitLocalVariable(LocalVariable node) { - visited.add(NodeKind.LocalVariable); + void visitCatchVariable(CatchVariable node) { + visited.add(VariableDeclarationKind.CatchVariable); node.visitChildren(this); } @override void visitPositionalParameter(PositionalParameter node) { - visited.add(NodeKind.PositionalParameter); + visited.add(VariableDeclarationKind.PositionalParameter); node.visitChildren(this); } @override void visitNamedParameter(NamedParameter node) { - visited.add(NodeKind.NamedParameter); + visited.add(VariableDeclarationKind.NamedParameter); node.visitChildren(this); } @override void visitThisVariable(ThisVariable node) { - visited.add(NodeKind.ThisVariable); + visited.add(VariableDeclarationKind.ThisVariable); node.visitChildren(this); } @override void visitSyntheticVariable(SyntheticVariable node) { - visited.add(NodeKind.SyntheticVariable); + visited.add(VariableDeclarationKind.SyntheticVariable); node.visitChildren(this); } @@ -1342,7 +1330,6 @@ enum ConstantKind { enum NodeKind { Arguments, Catch, - CatchVariable, Class, Combinator, Component, @@ -1352,25 +1339,20 @@ enum NodeKind { Library, LibraryDependency, LibraryPart, - LocalVariable, MapLiteralEntry, MapPatternEntry, MapPatternRestEntry, Name, NamedExpression, - NamedParameter, NamedType, NominalParameter, PatternGuard, PatternSwitchCase, - PositionalParameter, Scope, StructuralParameter, Supertype, SwitchCase, SwitchExpressionCase, - SyntheticVariable, - ThisVariable, TypeVariable, Typedef, VariableContext, @@ -1447,9 +1429,7 @@ enum ExpressionKind { TypeLiteral, TypedefTearOff, VariableGet, - VariableRead, VariableSet, - VariableWrite, } enum InitializerKind { @@ -1508,6 +1488,15 @@ enum StatementKind { YieldStatement, } +enum VariableDeclarationKind { + CatchVariable, + LocalVariable, + NamedParameter, + PositionalParameter, + SyntheticVariable, + ThisVariable, +} + enum DartTypeKind { ClassTypeParameterType, DynamicType, @@ -1537,34 +1526,35 @@ Set missingNodes(CoverageVisitor visitor) { ...InitializerKind.values, ...PatternKind.values, ...StatementKind.values, + ...VariableDeclarationKind.values, ...DartTypeKind.values, }; all.removeAll(visitor.visited); return all; } -/// Returns the set of [ConstantKind]s that were not visited by [visitor]. +/// Returns the set of [ConstantKind]s not visited by [visitor]. Set missingConstants(CoverageVisitor visitor) { Set all = new Set.of(ConstantKind.values); all.removeAll(visitor.visited); return all; } -/// Returns the set of [MemberKind]s that were not visited by [visitor]. +/// Returns the set of [MemberKind]s not visited by [visitor]. Set missingMembers(CoverageVisitor visitor) { Set all = new Set.of(MemberKind.values); all.removeAll(visitor.visited); return all; } -/// Returns the set of [ExpressionKind]s that were not visited by [visitor]. +/// Returns the set of [ExpressionKind]s not visited by [visitor]. Set missingExpressions(CoverageVisitor visitor) { Set all = new Set.of(ExpressionKind.values); all.removeAll(visitor.visited); return all; } -/// Returns the set of [InitializerKind]s that were not visited by [visitor]. +/// Returns the set of [InitializerKind]s not visited by [visitor]. Set missingInitializers(CoverageVisitor visitor) { Set all = new Set.of( InitializerKind.values, @@ -1573,21 +1563,32 @@ Set missingInitializers(CoverageVisitor visitor) { return all; } -/// Returns the set of [PatternKind]s that were not visited by [visitor]. +/// Returns the set of [PatternKind]s not visited by [visitor]. Set missingPatterns(CoverageVisitor visitor) { Set all = new Set.of(PatternKind.values); all.removeAll(visitor.visited); return all; } -/// Returns the set of [StatementKind]s that were not visited by [visitor]. +/// Returns the set of [StatementKind]s not visited by [visitor]. Set missingStatements(CoverageVisitor visitor) { Set all = new Set.of(StatementKind.values); all.removeAll(visitor.visited); return all; } -/// Returns the set of [DartTypeKind]s that were not visited by [visitor]. +/// Returns the set of [VariableDeclarationKind]s not visited by [visitor]. +Set missingVariableDeclarations( + CoverageVisitor visitor, +) { + Set all = new Set.of( + VariableDeclarationKind.values, + ); + all.removeAll(visitor.visited); + return all; +} + +/// Returns the set of [DartTypeKind]s not visited by [visitor]. Set missingDartTypes(CoverageVisitor visitor) { Set all = new Set.of(DartTypeKind.values); all.removeAll(visitor.visited); diff --git a/pkg/kernel/lib/src/equivalence.dart b/pkg/kernel/lib/src/equivalence.dart index 5ec65fccfe5..857cc3c2d5f 100644 --- a/pkg/kernel/lib/src/equivalence.dart +++ b/pkg/kernel/lib/src/equivalence.dart @@ -532,16 +532,6 @@ class EquivalenceVisitor implements Visitor1 { return strategy.checkTypedefTearOff(this, node, other); } - @override - bool visitVariableRead(VariableRead node, Node other) { - return strategy.checkVariableRead(this, node, other); - } - - @override - bool visitVariableWrite(VariableWrite node, Node other) { - return strategy.checkVariableWrite(this, node, other); - } - @override bool visitSwitchExpression(SwitchExpression node, Node other) { return strategy.checkSwitchExpression(this, node, other); @@ -845,11 +835,6 @@ class EquivalenceVisitor implements Visitor1 { return strategy.checkYieldStatement(this, node, other); } - @override - bool visitVariableInitialization(VariableInitialization node, Node other) { - return strategy.checkVariableInitialization(this, node, other); - } - @override bool visitVariableStatement(VariableStatement node, Node other) { return strategy.checkVariableStatement(this, node, other); @@ -860,6 +845,11 @@ class EquivalenceVisitor implements Visitor1 { return strategy.checkFunctionDeclaration(this, node, other); } + @override + bool visitVariableInitialization(VariableInitialization node, Node other) { + return strategy.checkVariableInitialization(this, node, other); + } + @override bool visitSwitchExpressionCase(SwitchExpressionCase node, Node other) { return strategy.checkSwitchExpressionCase(this, node, other); @@ -871,13 +861,13 @@ class EquivalenceVisitor implements Visitor1 { } @override - bool visitCatchVariable(CatchVariable node, Node other) { - return strategy.checkCatchVariable(this, node, other); + bool visitLocalVariable(LocalVariable node, Node other) { + return strategy.checkLocalVariable(this, node, other); } @override - bool visitLocalVariable(LocalVariable node, Node other) { - return strategy.checkLocalVariable(this, node, other); + bool visitCatchVariable(CatchVariable node, Node other) { + return strategy.checkCatchVariable(this, node, other); } @override @@ -2570,7 +2560,7 @@ class EquivalenceStrategy { if (other is! VariableGet) return false; visitor.pushNodeState(node, other); bool result = true; - if (!checkVariableGet_expressionVariable(visitor, node, other)) { + if (!checkVariableGet_variable(visitor, node, other)) { result = visitor.resultOnInequivalence; } if (!checkVariableGet_promotedType(visitor, node, other)) { @@ -2593,7 +2583,7 @@ class EquivalenceStrategy { if (other is! VariableSet) return false; visitor.pushNodeState(node, other); bool result = true; - if (!checkVariableSet_expressionVariable(visitor, node, other)) { + if (!checkVariableSet_variable(visitor, node, other)) { result = visitor.resultOnInequivalence; } if (!checkVariableSet_value(visitor, node, other)) { @@ -4198,49 +4188,6 @@ class EquivalenceStrategy { return result; } - bool checkVariableRead( - EquivalenceVisitor visitor, - VariableRead? node, - Object? other, - ) { - if (identical(node, other)) return true; - if (node is! VariableRead) return false; - if (other is! VariableRead) return false; - visitor.pushNodeState(node, other); - bool result = true; - if (!checkVariableRead_variable(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableRead_fileOffset(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - visitor.popState(); - return result; - } - - bool checkVariableWrite( - EquivalenceVisitor visitor, - VariableWrite? node, - Object? other, - ) { - if (identical(node, other)) return true; - if (node is! VariableWrite) return false; - if (other is! VariableWrite) return false; - visitor.pushNodeState(node, other); - bool result = true; - if (!checkVariableWrite_variable(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableWrite_value(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableWrite_fileOffset(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - visitor.popState(); - return result; - } - bool checkSwitchExpression( EquivalenceVisitor visitor, SwitchExpression? node, @@ -5933,44 +5880,6 @@ class EquivalenceStrategy { return result; } - bool checkVariableInitialization( - EquivalenceVisitor visitor, - VariableInitialization? node, - Object? other, - ) { - if (identical(node, other)) return true; - if (node is! VariableInitialization) return false; - if (other is! VariableInitialization) return false; - visitor.pushNodeState(node, other); - bool result = true; - if (!checkVariableInitialization_variable(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_initializer(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_contexts(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_flags(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_annotations(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_binaryOffsetNoTag(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_fileEqualsOffset(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkVariableInitialization_fileOffset(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - visitor.popState(); - return result; - } - bool checkVariableStatement( EquivalenceVisitor visitor, VariableStatement? node, @@ -6032,6 +5941,44 @@ class EquivalenceStrategy { return result; } + bool checkVariableInitialization( + EquivalenceVisitor visitor, + VariableInitialization? node, + Object? other, + ) { + if (identical(node, other)) return true; + if (node is! VariableInitialization) return false; + if (other is! VariableInitialization) return false; + visitor.pushNodeState(node, other); + bool result = true; + if (!checkVariableInitialization_variable(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_initializer(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_contexts(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_annotations(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_binaryOffsetNoTag(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_fileEqualsOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_fileOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + visitor.popState(); + return result; + } + bool checkSwitchExpressionCase( EquivalenceVisitor visitor, SwitchExpressionCase? node, @@ -6064,10 +6011,10 @@ class EquivalenceStrategy { if (!checkCatch_guard(visitor, node, other)) { result = visitor.resultOnInequivalence; } - if (!checkCatch_exceptionCatchVariable(visitor, node, other)) { + if (!checkCatch_exception(visitor, node, other)) { result = visitor.resultOnInequivalence; } - if (!checkCatch_stackTraceCatchVariable(visitor, node, other)) { + if (!checkCatch_stackTrace(visitor, node, other)) { result = visitor.resultOnInequivalence; } if (!checkCatch_body(visitor, node, other)) { @@ -6083,35 +6030,6 @@ class EquivalenceStrategy { return result; } - bool checkCatchVariable( - EquivalenceVisitor visitor, - CatchVariable? node, - Object? other, - ) { - if (identical(node, other)) return true; - if (node is! CatchVariable) return false; - if (other is! CatchVariable) return false; - visitor.pushNodeState(node, other); - bool result = true; - if (!checkCatchVariable_catchVariableName(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkCatchVariable_type(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkCatchVariable_annotations(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkCatchVariable_flags(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - if (!checkCatchVariable_fileOffset(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } - visitor.popState(); - return result; - } - bool checkLocalVariable( EquivalenceVisitor visitor, LocalVariable? node, @@ -6134,6 +6052,12 @@ class EquivalenceStrategy { if (!checkLocalVariable_annotations(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkLocalVariable_binaryOffsetNoTag(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkLocalVariable_fileEqualsOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkLocalVariable_flags(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -6144,6 +6068,41 @@ class EquivalenceStrategy { return result; } + bool checkCatchVariable( + EquivalenceVisitor visitor, + CatchVariable? node, + Object? other, + ) { + if (identical(node, other)) return true; + if (node is! CatchVariable) return false; + if (other is! CatchVariable) return false; + visitor.pushNodeState(node, other); + bool result = true; + if (!checkCatchVariable_catchVariableName(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkCatchVariable_type(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkCatchVariable_annotations(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkCatchVariable_binaryOffsetNoTag(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkCatchVariable_fileEqualsOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkCatchVariable_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkCatchVariable_fileOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + visitor.popState(); + return result; + } + bool checkPositionalParameter( EquivalenceVisitor visitor, PositionalParameter? node, @@ -6236,6 +6195,12 @@ class EquivalenceStrategy { if (!checkThisVariable_annotations(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkThisVariable_binaryOffsetNoTag(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkThisVariable_fileEqualsOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkThisVariable_flags(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -6268,6 +6233,12 @@ class EquivalenceStrategy { if (!checkSyntheticVariable_annotations(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkSyntheticVariable_binaryOffsetNoTag(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkSyntheticVariable_fileEqualsOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkSyntheticVariable_flags(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -8504,16 +8475,12 @@ class EquivalenceStrategy { return checkExpression_fileOffset(visitor, node, other); } - bool checkVariableGet_expressionVariable( + bool checkVariableGet_variable( EquivalenceVisitor visitor, VariableGet node, VariableGet other, ) { - return visitor.checkNodes( - node.expressionVariable, - other.expressionVariable, - 'expressionVariable', - ); + return visitor.checkNodes(node.variable, other.variable, 'variable'); } bool checkVariableGet_promotedType( @@ -8536,16 +8503,12 @@ class EquivalenceStrategy { return checkExpression_fileOffset(visitor, node, other); } - bool checkVariableSet_expressionVariable( + bool checkVariableSet_variable( EquivalenceVisitor visitor, VariableSet node, VariableSet other, ) { - return visitor.checkNodes( - node.expressionVariable, - other.expressionVariable, - 'expressionVariable', - ); + return visitor.checkNodes(node.variable, other.variable, 'variable'); } bool checkVariableSet_value( @@ -9365,7 +9328,7 @@ class EquivalenceStrategy { LocalFunctionInvocation node, LocalFunctionInvocation other, ) { - return visitor.checkDeclarations(node.variable, other.variable, 'variable'); + return visitor.checkNodes(node.variable, other.variable, 'variable'); } bool checkLocalFunctionInvocation_arguments( @@ -10606,46 +10569,6 @@ class EquivalenceStrategy { return checkExpression_fileOffset(visitor, node, other); } - bool checkVariableRead_variable( - EquivalenceVisitor visitor, - VariableRead node, - VariableRead other, - ) { - return visitor.checkNodes(node.variable, other.variable, 'variable'); - } - - bool checkVariableRead_fileOffset( - EquivalenceVisitor visitor, - VariableRead node, - VariableRead other, - ) { - return checkExpression_fileOffset(visitor, node, other); - } - - bool checkVariableWrite_variable( - EquivalenceVisitor visitor, - VariableWrite node, - VariableWrite other, - ) { - return visitor.checkNodes(node.variable, other.variable, 'variable'); - } - - bool checkVariableWrite_value( - EquivalenceVisitor visitor, - VariableWrite node, - VariableWrite other, - ) { - return visitor.checkNodes(node.value, other.value, 'value'); - } - - bool checkVariableWrite_fileOffset( - EquivalenceVisitor visitor, - VariableWrite node, - VariableWrite other, - ) { - return checkExpression_fileOffset(visitor, node, other); - } - bool checkSwitchExpression_expression( EquivalenceVisitor visitor, SwitchExpression node, @@ -11444,7 +11367,7 @@ class EquivalenceStrategy { return visitor.checkLists( node.orPatternJointVariables, other.orPatternJointVariables, - visitor.checkDeclarations, + visitor.checkNodes, 'orPatternJointVariables', ); } @@ -13274,92 +13197,6 @@ class EquivalenceStrategy { return checkStatement_fileOffset(visitor, node, other); } - bool checkVariableInitialization_variable( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkNodes(node.variable, other.variable, 'variable'); - } - - bool checkVariableInitialization_initializer( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkNodes( - node.initializer, - other.initializer, - 'initializer', - ); - } - - bool checkVariableInitialization_contexts( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkLists( - node.contexts, - other.contexts, - visitor.checkNodes, - 'contexts', - ); - } - - bool checkVariableInitialization_flags( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkValues(node.flags, other.flags, 'flags'); - } - - bool checkVariableInitialization_annotations( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkLists( - node.annotations, - other.annotations, - visitor.checkNodes, - 'annotations', - ); - } - - bool checkVariableInitialization_binaryOffsetNoTag( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkValues( - node.binaryOffsetNoTag, - other.binaryOffsetNoTag, - 'binaryOffsetNoTag', - ); - } - - bool checkVariableInitialization_fileEqualsOffset( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return visitor.checkValues( - node.fileEqualsOffset, - other.fileEqualsOffset, - 'fileEqualsOffset', - ); - } - - bool checkVariableInitialization_fileOffset( - EquivalenceVisitor visitor, - VariableInitialization node, - VariableInitialization other, - ) { - return checkStatement_fileOffset(visitor, node, other); - } - bool checkVariableStatement_fileEqualsOffset( EquivalenceVisitor visitor, VariableStatement node, @@ -13465,6 +13302,92 @@ class EquivalenceStrategy { return checkStatement_fileOffset(visitor, node, other); } + bool checkVariableInitialization_variable( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkNodes(node.variable, other.variable, 'variable'); + } + + bool checkVariableInitialization_initializer( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkNodes( + node.initializer, + other.initializer, + 'initializer', + ); + } + + bool checkVariableInitialization_contexts( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkLists( + node.contexts, + other.contexts, + visitor.checkNodes, + 'contexts', + ); + } + + bool checkVariableInitialization_flags( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkValues(node.flags, other.flags, 'flags'); + } + + bool checkVariableInitialization_annotations( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkLists( + node.annotations, + other.annotations, + visitor.checkNodes, + 'annotations', + ); + } + + bool checkVariableInitialization_binaryOffsetNoTag( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkValues( + node.binaryOffsetNoTag, + other.binaryOffsetNoTag, + 'binaryOffsetNoTag', + ); + } + + bool checkVariableInitialization_fileEqualsOffset( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return visitor.checkValues( + node.fileEqualsOffset, + other.fileEqualsOffset, + 'fileEqualsOffset', + ); + } + + bool checkVariableInitialization_fileOffset( + EquivalenceVisitor visitor, + VariableInitialization node, + VariableInitialization other, + ) { + return checkStatement_fileOffset(visitor, node, other); + } + bool checkSwitchExpressionCase_patternGuard( EquivalenceVisitor visitor, SwitchExpressionCase node, @@ -13497,28 +13420,20 @@ class EquivalenceStrategy { return visitor.checkNodes(node.guard, other.guard, 'guard'); } - bool checkCatch_exceptionCatchVariable( + bool checkCatch_exception( EquivalenceVisitor visitor, Catch node, Catch other, ) { - return visitor.checkNodes( - node.exceptionCatchVariable, - other.exceptionCatchVariable, - 'exceptionCatchVariable', - ); + return visitor.checkNodes(node.exception, other.exception, 'exception'); } - bool checkCatch_stackTraceCatchVariable( + bool checkCatch_stackTrace( EquivalenceVisitor visitor, Catch node, Catch other, ) { - return visitor.checkNodes( - node.stackTraceCatchVariable, - other.stackTraceCatchVariable, - 'stackTraceCatchVariable', - ); + return visitor.checkNodes(node.stackTrace, other.stackTrace, 'stackTrace'); } bool checkCatch_body(EquivalenceVisitor visitor, Catch node, Catch other) { @@ -13537,87 +13452,6 @@ class EquivalenceStrategy { return checkTreeNode_fileOffset(visitor, node, other); } - bool checkCatchVariable_catchVariableName( - EquivalenceVisitor visitor, - CatchVariable node, - CatchVariable other, - ) { - return visitor.checkValues( - node.catchVariableName, - other.catchVariableName, - 'catchVariableName', - ); - } - - bool checkCatchVariable_type( - EquivalenceVisitor visitor, - CatchVariable node, - CatchVariable other, - ) { - return visitor.checkNodes(node.type, other.type, 'type'); - } - - bool checkCatchVariable_annotations( - EquivalenceVisitor visitor, - CatchVariable node, - CatchVariable other, - ) { - return visitor.checkLists( - node.annotations, - other.annotations, - visitor.checkNodes, - 'annotations', - ); - } - - bool checkVariableBase_flags( - EquivalenceVisitor visitor, - VariableBase node, - VariableBase other, - ) { - return visitor.checkValues(node.flags, other.flags, 'flags'); - } - - bool checkVariable_flags( - EquivalenceVisitor visitor, - Variable node, - Variable other, - ) { - return checkVariableBase_flags(visitor, node, other); - } - - bool checkCatchVariable_flags( - EquivalenceVisitor visitor, - CatchVariable node, - CatchVariable other, - ) { - return checkVariable_flags(visitor, node, other); - } - - bool checkVariableBase_fileOffset( - EquivalenceVisitor visitor, - VariableBase node, - VariableBase other, - ) { - return checkTreeNode_fileOffset(visitor, node, other); - } - - bool checkVariable_fileOffset( - EquivalenceVisitor visitor, - Variable node, - Variable other, - ) { - return checkVariableBase_fileOffset(visitor, node, other); - } - - bool checkCatchVariable_fileOffset( - EquivalenceVisitor visitor, - CatchVariable node, - CatchVariable other, - ) { - return checkVariable_fileOffset(visitor, node, other); - } - bool checkLocalVariable_cosmeticName( EquivalenceVisitor visitor, LocalVariable node, @@ -13663,12 +13497,68 @@ class EquivalenceStrategy { ); } + bool checkLocalVariable_binaryOffsetNoTag( + EquivalenceVisitor visitor, + LocalVariable node, + LocalVariable other, + ) { + return visitor.checkValues( + node.binaryOffsetNoTag, + other.binaryOffsetNoTag, + 'binaryOffsetNoTag', + ); + } + + bool checkLocalVariable_fileEqualsOffset( + EquivalenceVisitor visitor, + LocalVariable node, + LocalVariable other, + ) { + return visitor.checkValues( + node.fileEqualsOffset, + other.fileEqualsOffset, + 'fileEqualsOffset', + ); + } + + bool checkVariableBase_flags( + EquivalenceVisitor visitor, + VariableBase node, + VariableBase other, + ) { + return visitor.checkValues(node.flags, other.flags, 'flags'); + } + + bool checkVariableDeclaration_flags( + EquivalenceVisitor visitor, + VariableDeclaration node, + VariableDeclaration other, + ) { + return checkVariableBase_flags(visitor, node, other); + } + bool checkLocalVariable_flags( EquivalenceVisitor visitor, LocalVariable node, LocalVariable other, ) { - return checkVariable_flags(visitor, node, other); + return checkVariableDeclaration_flags(visitor, node, other); + } + + bool checkVariableBase_fileOffset( + EquivalenceVisitor visitor, + VariableBase node, + VariableBase other, + ) { + return checkTreeNode_fileOffset(visitor, node, other); + } + + bool checkVariableDeclaration_fileOffset( + EquivalenceVisitor visitor, + VariableDeclaration node, + VariableDeclaration other, + ) { + return checkVariableBase_fileOffset(visitor, node, other); } bool checkLocalVariable_fileOffset( @@ -13676,7 +13566,80 @@ class EquivalenceStrategy { LocalVariable node, LocalVariable other, ) { - return checkVariable_fileOffset(visitor, node, other); + return checkVariableDeclaration_fileOffset(visitor, node, other); + } + + bool checkCatchVariable_catchVariableName( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return visitor.checkValues( + node.catchVariableName, + other.catchVariableName, + 'catchVariableName', + ); + } + + bool checkCatchVariable_type( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return visitor.checkNodes(node.type, other.type, 'type'); + } + + bool checkCatchVariable_annotations( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return visitor.checkLists( + node.annotations, + other.annotations, + visitor.checkNodes, + 'annotations', + ); + } + + bool checkCatchVariable_binaryOffsetNoTag( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return visitor.checkValues( + node.binaryOffsetNoTag, + other.binaryOffsetNoTag, + 'binaryOffsetNoTag', + ); + } + + bool checkCatchVariable_fileEqualsOffset( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return visitor.checkValues( + node.fileEqualsOffset, + other.fileEqualsOffset, + 'fileEqualsOffset', + ); + } + + bool checkCatchVariable_flags( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return checkVariableDeclaration_flags(visitor, node, other); + } + + bool checkCatchVariable_fileOffset( + EquivalenceVisitor visitor, + CatchVariable node, + CatchVariable other, + ) { + return checkVariableDeclaration_fileOffset(visitor, node, other); } bool checkPositionalParameter_cosmeticName( @@ -13761,7 +13724,7 @@ class EquivalenceStrategy { FunctionParameter node, FunctionParameter other, ) { - return checkVariable_flags(visitor, node, other); + return checkVariableDeclaration_flags(visitor, node, other); } bool checkPositionalParameter_flags( @@ -13777,7 +13740,7 @@ class EquivalenceStrategy { FunctionParameter node, FunctionParameter other, ) { - return checkVariable_fileOffset(visitor, node, other); + return checkVariableDeclaration_fileOffset(visitor, node, other); } bool checkPositionalParameter_fileOffset( @@ -13890,12 +13853,36 @@ class EquivalenceStrategy { ); } + bool checkThisVariable_binaryOffsetNoTag( + EquivalenceVisitor visitor, + ThisVariable node, + ThisVariable other, + ) { + return visitor.checkValues( + node.binaryOffsetNoTag, + other.binaryOffsetNoTag, + 'binaryOffsetNoTag', + ); + } + + bool checkThisVariable_fileEqualsOffset( + EquivalenceVisitor visitor, + ThisVariable node, + ThisVariable other, + ) { + return visitor.checkValues( + node.fileEqualsOffset, + other.fileEqualsOffset, + 'fileEqualsOffset', + ); + } + bool checkThisVariable_flags( EquivalenceVisitor visitor, ThisVariable node, ThisVariable other, ) { - return checkVariable_flags(visitor, node, other); + return checkVariableDeclaration_flags(visitor, node, other); } bool checkThisVariable_fileOffset( @@ -13903,7 +13890,7 @@ class EquivalenceStrategy { ThisVariable node, ThisVariable other, ) { - return checkVariable_fileOffset(visitor, node, other); + return checkVariableDeclaration_fileOffset(visitor, node, other); } bool checkSyntheticVariable_cosmeticName( @@ -13951,12 +13938,36 @@ class EquivalenceStrategy { ); } + bool checkSyntheticVariable_binaryOffsetNoTag( + EquivalenceVisitor visitor, + SyntheticVariable node, + SyntheticVariable other, + ) { + return visitor.checkValues( + node.binaryOffsetNoTag, + other.binaryOffsetNoTag, + 'binaryOffsetNoTag', + ); + } + + bool checkSyntheticVariable_fileEqualsOffset( + EquivalenceVisitor visitor, + SyntheticVariable node, + SyntheticVariable other, + ) { + return visitor.checkValues( + node.fileEqualsOffset, + other.fileEqualsOffset, + 'fileEqualsOffset', + ); + } + bool checkSyntheticVariable_flags( EquivalenceVisitor visitor, SyntheticVariable node, SyntheticVariable other, ) { - return checkVariable_flags(visitor, node, other); + return checkVariableDeclaration_flags(visitor, node, other); } bool checkSyntheticVariable_fileOffset( @@ -13964,7 +13975,7 @@ class EquivalenceStrategy { SyntheticVariable node, SyntheticVariable other, ) { - return checkVariable_fileOffset(visitor, node, other); + return checkVariableDeclaration_fileOffset(visitor, node, other); } bool checkTypeVariable_cosmeticName( diff --git a/pkg/kernel/lib/src/node_creator.dart b/pkg/kernel/lib/src/node_creator.dart index 6b4e07e29c0..e64f4fe2744 100644 --- a/pkg/kernel/lib/src/node_creator.dart +++ b/pkg/kernel/lib/src/node_creator.dart @@ -40,6 +40,7 @@ class NodeCreator { final Map _pendingInitializers; final Map _pendingMembers; final Map _pendingNodes; + final Map _pendingVariableDeclarations; /// The set of all kinds of nodes created by this node creator. final Set _createdKinds = {}; @@ -78,11 +79,10 @@ class NodeCreator { Iterable patterns = PatternKind.values, Iterable initializers = InitializerKind.values, Iterable members = MemberKind.values, + Iterable variableDeclarations = + VariableDeclarationKind.values, Iterable nodes = NodeKind.values, - }) : _pendingExpressions = _createPending(expressions, { - ExpressionKind.VariableRead, - ExpressionKind.VariableWrite, - }), + }) : _pendingExpressions = _createPending(expressions, {}), _pendingStatements = _createPending(statements, { StatementKind.VariableInitialization, }), @@ -94,12 +94,16 @@ class NodeCreator { _pendingPatterns = _createPending(patterns), _pendingInitializers = _createPending(initializers), _pendingMembers = _createPending(members), + _pendingVariableDeclarations = + _createPending(variableDeclarations, { + VariableDeclarationKind.CatchVariable, + VariableDeclarationKind.LocalVariable, + VariableDeclarationKind.PositionalParameter, + VariableDeclarationKind.NamedParameter, + VariableDeclarationKind.SyntheticVariable, + VariableDeclarationKind.ThisVariable, + }), _pendingNodes = _createPending(nodes, { - NodeKind.LocalVariable, - NodeKind.PositionalParameter, - NodeKind.NamedParameter, - NodeKind.SyntheticVariable, - NodeKind.ThisVariable, NodeKind.TypeVariable, NodeKind.VariableContext, NodeKind.Scope, @@ -110,6 +114,7 @@ class NodeCreator { _createdKinds.addAll(_pendingDartTypes.keys); _createdKinds.addAll(_pendingInitializers.keys); _createdKinds.addAll(_pendingMembers.keys); + _createdKinds.addAll(_pendingVariableDeclarations.keys); _createdKinds.addAll(_pendingNodes.keys); } @@ -383,12 +388,6 @@ class NodeCreator { case NodeKind.PatternGuard: case NodeKind.PatternSwitchCase: case NodeKind.SwitchExpressionCase: - case NodeKind.LocalVariable: - case NodeKind.CatchVariable: - case NodeKind.PositionalParameter: - case NodeKind.NamedParameter: - case NodeKind.SyntheticVariable: - case NodeKind.ThisVariable: case NodeKind.TypeVariable: case NodeKind.Scope: case NodeKind.VariableContext: @@ -1276,9 +1275,6 @@ class NodeCreator { _createExpressionFromKind(ExpressionKind.ConstructorInvocation) as InvocationExpression, ); - case ExpressionKind.VariableRead: - case ExpressionKind.VariableWrite: - throw new UnimplementedError("Unimplemented support for ${kind}."); } } @@ -2138,12 +2134,6 @@ class NodeCreator { _createNodeFromKind(NodeKind.PatternGuard) as PatternGuard, _createExpression(), )..fileOffset = _needFileOffset(); - case NodeKind.LocalVariable: - case NodeKind.CatchVariable: - case NodeKind.PositionalParameter: - case NodeKind.NamedParameter: - case NodeKind.SyntheticVariable: - case NodeKind.ThisVariable: case NodeKind.TypeVariable: case NodeKind.Scope: case NodeKind.VariableContext: diff --git a/pkg/kernel/lib/src/printer.dart b/pkg/kernel/lib/src/printer.dart index a2ac211c571..454c8df1f65 100644 --- a/pkg/kernel/lib/src/printer.dart +++ b/pkg/kernel/lib/src/printer.dart @@ -258,15 +258,15 @@ class AstPrinter { case LocalVariable(cosmeticName: null): case SyntheticVariable(): return _variableNames[node] ??= '#${_variableNames.length}'; - case VariableDeclaration(): + case CatchVariable(catchVariableName: var name): + return name; + case LegacyVariableDeclaration(): String? name = node.name; if (name != null) { return name; } return _variableDeclarationNames[node] ??= '#${_variableDeclarationNames.length}'; - case CatchVariable(catchVariableName: var name): - return name; } } @@ -519,7 +519,7 @@ class AstPrinter { /// If [isLate] and [type] are provided, these values are used instead of /// the corresponding properties on [node]. void writeVariableInitialization( - VariableInitialization node, { + VariableInitializationBase node, { bool includeModifiersAndType = true, bool? isLate, DartType? type, @@ -557,7 +557,7 @@ class AstPrinter { /// If [isLate] and [type] are provided, these values are used instead of /// the corresponding properties on [node]. void writeExpressionVariable( - Variable node, { + VariableDeclaration node, { bool includeModifiersAndType = true, bool? isLate, DartType? type, diff --git a/pkg/kernel/lib/text/ast_to_text.dart b/pkg/kernel/lib/text/ast_to_text.dart index 1d8b312f07f..aeef9718656 100644 --- a/pkg/kernel/lib/text/ast_to_text.dart +++ b/pkg/kernel/lib/text/ast_to_text.dart @@ -146,7 +146,8 @@ String componentToString(Component node) { } class NameSystem { - final Namer variables = new NormalNamer('#t'); + final Namer variables = + new NormalNamer('#t'); final Namer libraries = new NormalNamer('#lib'); final Namer typeParameters = new NormalNamer( '#T', @@ -161,7 +162,7 @@ class NameSystem { final Disambiguator prefixes = new Disambiguator(); - String nameVariable(Variable node) => variables.getName(node); + String nameVariable(VariableDeclaration node) => variables.getName(node); String nameLibrary(Reference node) => libraries.getName(node); String nameTypeParameter(TypeParameter node) => typeParameters.getName(node); String nameStructuralParameter(StructuralParameter node) => @@ -242,7 +243,7 @@ class NameSystem { } abstract class Annotator { - String annotateVariable(Printer printer, VariableInitialization node); + String annotateVariable(Printer printer, VariableInitializationBase node); String annotateReturn(Printer printer, FunctionNode node); String annotateField(Printer printer, Field node); } @@ -368,11 +369,11 @@ class Printer extends VisitorDefault with VisitorVoidMixin { } } - String getVariableName(Variable node) { + String getVariableName(VariableDeclaration node) { return node.cosmeticName ?? syntheticNames.nameVariable(node); } - String getVariableReference(Variable node) { + String getVariableReference(VariableDeclaration node) { return getVariableName(node); } @@ -1111,7 +1112,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { writeWord(getTypedefReference(typedefNode)); } - void writeVariableReference(Variable variable) { + void writeVariableReference(VariableDeclaration variable) { final bool highlight = shouldHighlight(variable); if (highlight) { startHighlight(variable); @@ -1247,8 +1248,8 @@ class Printer extends VisitorDefault with VisitorVoidMixin { endLine(';'); } - void writeExpressionVariable(Variable node) { - if (node is VariableDeclaration && node is! FunctionParameter) { + void writeExpressionVariable(VariableDeclaration node) { + if (node is LegacyVariableDeclaration && node is! FunctionParameter) { writeVariableDeclaration(node); } else { if (showOffsets) writeWord("[${node.fileOffset}]"); @@ -1265,7 +1266,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { writeWord('this-variable'); case SyntheticVariable(): writeWord('synthetic-variable'); - case VariableDeclaration(): + case LegacyVariableDeclaration(): writeWord('variable-declaration'); case CatchVariable(): writeWord('catch-variable'); @@ -2282,7 +2283,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { @override void visitVariableGet(VariableGet node) { - writeVariableReference(node.expressionVariable); + writeVariableReference(node.variable); DartType? promotedType = node.promotedType; if (promotedType != null) { writeSymbol('{'); @@ -2294,7 +2295,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { @override void visitVariableSet(VariableSet node) { - writeVariableReference(node.expressionVariable); + writeVariableReference(node.variable); writeSpaced('='); writeExpression(node.value); } @@ -2596,10 +2597,10 @@ class Printer extends VisitorDefault with VisitorVoidMixin { ensureSpace(); } writeSymbol('('); - if (node.expressionVariable case VariableDeclaration variable) { + if (node.variable case LegacyVariableDeclaration variable) { writeVariableDeclaration(variable, useVarKeyword: true); } else { - writeExpressionVariable(node.expressionVariable); + writeExpressionVariable(node.variable); } writeSpaced('in'); writeExpression(node.iterable); @@ -2702,13 +2703,13 @@ class Printer extends VisitorDefault with VisitorVoidMixin { writeSpace(); writeWord('catch'); writeSymbol('('); - CatchVariable? exception = node.exceptionCatchVariable; + VariableDeclaration? exception = node.exception; if (exception != null) { writeExpressionVariable(exception); } else { writeWord('no-exception-var'); } - CatchVariable? stackTrace = node.stackTraceCatchVariable; + VariableDeclaration? stackTrace = node.stackTrace; if (stackTrace != null) { writeComma(); writeExpressionVariable(stackTrace); @@ -2750,7 +2751,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { } @override - void visitVariableInitialization(VariableInitialization node) { + void visitVariableInitialization(VariableInitializationBase node) { writeIndentation(); writeVariableInitialization(node); _writeContexts(node); @@ -2813,7 +2814,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { } } - void writeVariableInitialization(VariableInitialization node) { + void writeVariableInitialization(VariableInitializationBase node) { if (node is VariableDeclaration) { writeVariableDeclaration(node); } else { @@ -3641,12 +3642,6 @@ class Precedence implements ExpressionVisitor { @override int visitPatternAssignment(PatternAssignment node) => EXPRESSION; - - @override - int visitVariableRead(VariableRead node) => PRIMARY; - - @override - int visitVariableWrite(VariableWrite node) => EXPRESSION; } String procedureKindToString(ProcedureKind kind) { diff --git a/pkg/kernel/lib/type_checker.dart b/pkg/kernel/lib/type_checker.dart index 051097c16d7..0e6531d24e6 100644 --- a/pkg/kernel/lib/type_checker.dart +++ b/pkg/kernel/lib/type_checker.dart @@ -1265,7 +1265,7 @@ class TypeCheckingVisitor } @override - void visitVariableInitialization(VariableInitialization node) { + void visitVariableInitialization(VariableInitializationBase node) { if (node.initializer != null) { node.initializer = checkExpressionAndAssignability( node.initializer!, @@ -1558,22 +1558,6 @@ class TypeCheckingVisitor // TODO(johnniwinther): Implement this. } - @override - DartType visitVariableRead(VariableRead node) { - // TODO(cstefantsova): Implement visitVariableRead. - throw new UnimplementedError( - "Unimplemented support for $node (${node.runtimeType}).", - ); - } - - @override - DartType visitVariableWrite(VariableWrite node) { - // TODO(cstefantsova): Implement visitVariableWrite. - throw new UnimplementedError( - "Unimplemented support for $node (${node.runtimeType}).", - ); - } - @override DartType visitRedirectingFactoryInvocation( RedirectingFactoryInvocation node, diff --git a/pkg/kernel/lib/verifier.dart b/pkg/kernel/lib/verifier.dart index 602e12e0bdc..3294bd9e832 100644 --- a/pkg/kernel/lib/verifier.dart +++ b/pkg/kernel/lib/verifier.dart @@ -143,8 +143,9 @@ class VerifyingVisitor extends RecursiveResultVisitor { Set typeParametersInScope = new Set(); Set structuralParametersInScope = new Set(); - Set variableDeclarationsInScope = new Set(); - final List variableStack = []; + Set variableDeclarationsInScope = + new Set(); + final List variableStack = []; final Map typedefState = {}; final Set seenConstants = {}; @@ -269,7 +270,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { // TODO(cstefantsova): Remove this method when the new variable model is // supported. bool _isNewModelVariable(TreeNode node) { - return node is Variable && node is! VariableDeclaration || + return node is VariableDeclaration && node is! LegacyVariableDeclaration || node is FunctionParameter; } @@ -321,7 +322,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { exitTreeNode(node); } - void declareVariable(Variable variable) { + void declareVariable(VariableDeclaration variable) { if (variableDeclarationsInScope.contains(variable)) { problem(variable, "Variable '$variable' declared more than once."); } @@ -329,7 +330,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { variableStack.add(variable); } - void undeclareVariable(Variable variable) { + void undeclareVariable(VariableDeclaration variable) { variableDeclarationsInScope.remove(variable); } @@ -389,7 +390,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { structuralParametersInScope.removeAll(parameters); } - void checkVariableInScope(Variable variable, TreeNode where) { + void checkVariableInScope(VariableDeclaration variable, TreeNode where) { if (!variableDeclarationsInScope.contains(variable)) { problem(where, "Variable '$variable' used out of scope."); } @@ -1141,11 +1142,11 @@ class VerifyingVisitor extends RecursiveResultVisitor { } @override - void visitVariableInitialization(VariableInitialization node) { + void visitVariableInitialization(VariableInitializationBase node) { return _verifyVariableInitialization(node); } - void _verifyVariableInitialization(VariableInitialization node) { + void _verifyVariableInitialization(VariableInitializationBase node) { enterTreeNode(node); TreeNode? parent = node.parent; if (parent is! Block && @@ -1187,20 +1188,17 @@ class VerifyingVisitor extends RecursiveResultVisitor { @override void visitVariableGet(VariableGet node) { // TODO(cstefantsova): Support new variable model. - if (_isNewModelVariable(node.expressionVariable)) { + if (_isNewModelVariable(node.variable)) { return; } enterTreeNode(node); - checkVariableInScope(node.expressionVariable, node); + checkVariableInScope(node.variable, node); visitChildren(node); if (constantsAreAlwaysInlined && afterConst && - node.expressionVariable.isConst && + node.variable.isConst && !inUnevaluatedConstant) { - problem( - node, - "VariableGet of const variable '${node.expressionVariable}'.", - ); + problem(node, "VariableGet of const variable '${node.variable}'."); } exitTreeNode(node); } @@ -1208,11 +1206,11 @@ class VerifyingVisitor extends RecursiveResultVisitor { @override void visitVariableSet(VariableSet node) { // TODO(cstefantsova): Support new variable model. - if (_isNewModelVariable(node.expressionVariable)) { + if (_isNewModelVariable(node.variable)) { return; } enterTreeNode(node); - checkVariableInScope(node.expressionVariable, node); + checkVariableInScope(node.variable, node); visitChildren(node); exitTreeNode(node); } diff --git a/pkg/kernel/lib/visitor.dart b/pkg/kernel/lib/visitor.dart index 31236071743..8038364fd40 100644 --- a/pkg/kernel/lib/visitor.dart +++ b/pkg/kernel/lib/visitor.dart @@ -81,8 +81,6 @@ abstract class ExpressionVisitor { R visitRecordNameGet(RecordNameGet node); R visitSwitchExpression(SwitchExpression node); R visitPatternAssignment(PatternAssignment node); - R visitVariableRead(VariableRead node); - R visitVariableWrite(VariableWrite node); } /// Helper mixin for [ExpressionVisitor] that implements visit methods by @@ -244,10 +242,6 @@ mixin ExpressionVisitorDefaultMixin implements ExpressionVisitor { R visitSwitchExpression(SwitchExpression node) => defaultExpression(node); @override R visitPatternAssignment(PatternAssignment node) => defaultExpression(node); - @override - R visitVariableRead(VariableRead node) => defaultExpression(node); - @override - R visitVariableWrite(VariableWrite node) => defaultExpression(node); } abstract class PatternVisitor { @@ -534,6 +528,10 @@ abstract class StatementVisitor { R visitVariableStatement(VariableStatement node); R visitPositionalParameter(PositionalParameter node); R visitNamedParameter(NamedParameter node); + R visitLocalVariable(LocalVariable node); + R visitCatchVariable(CatchVariable node); + R visitThisVariable(ThisVariable node); + R visitSyntheticVariable(SyntheticVariable node); } /// Helper mixin for [StatementVisitor] that implements visit methods by @@ -605,6 +603,14 @@ mixin StatementVisitorDefaultMixin implements StatementVisitor { defaultStatement(node); @override R visitNamedParameter(NamedParameter node) => defaultStatement(node); + @override + R visitLocalVariable(LocalVariable node) => defaultStatement(node); + @override + R visitCatchVariable(CatchVariable node) => defaultStatement(node); + @override + R visitThisVariable(ThisVariable node) => defaultStatement(node); + @override + R visitSyntheticVariable(SyntheticVariable node) => defaultStatement(node); } abstract class MemberVisitor { @@ -759,10 +765,6 @@ abstract class TreeVisitor R visitPatternGuard(PatternGuard node); R visitComponent(Component node); R visitTypeVariable(TypeVariable node); - R visitLocalVariable(LocalVariable node); - R visitCatchVariable(CatchVariable node); - R visitThisVariable(ThisVariable node); - R visitSyntheticVariable(SyntheticVariable node); R visitVariableContext(VariableContext node); R visitScope(Scope node); R visitNominalParameter(NominalParameter node); @@ -822,14 +824,6 @@ mixin TreeVisitorDefaultMixin implements TreeVisitor { @override R visitTypeVariable(TypeVariable node) => defaultTreeNode(node); @override - R visitLocalVariable(LocalVariable node) => defaultTreeNode(node); - @override - R visitCatchVariable(CatchVariable node) => defaultTreeNode(node); - @override - R visitThisVariable(ThisVariable node) => defaultTreeNode(node); - @override - R visitSyntheticVariable(SyntheticVariable node) => defaultTreeNode(node); - @override R visitVariableContext(VariableContext node) => defaultTreeNode(node); @override R visitScope(Scope node) => defaultTreeNode(node); @@ -896,10 +890,6 @@ abstract class TreeVisitor1 R visitPatternGuard(PatternGuard node, A arg); R visitComponent(Component node, A arg); R visitTypeVariable(TypeVariable node, A arg); - R visitLocalVariable(LocalVariable node, A arg); - R visitCatchVariable(CatchVariable node, A arg); - R visitThisVariable(ThisVariable node, A arg); - R visitSyntheticVariable(SyntheticVariable node, A arg); R visitVariableContext(VariableContext node, A arg); R visitScope(Scope node, A arg); R visitNominalParameter(NominalParameter node, A arg); @@ -965,15 +955,6 @@ mixin TreeVisitor1DefaultMixin implements TreeVisitor1 { @override R visitTypeVariable(TypeVariable node, A arg) => defaultTreeNode(node, arg); @override - R visitLocalVariable(LocalVariable node, A arg) => defaultTreeNode(node, arg); - @override - R visitCatchVariable(CatchVariable node, A arg) => defaultTreeNode(node, arg); - @override - R visitThisVariable(ThisVariable node, A arg) => defaultTreeNode(node, arg); - @override - R visitSyntheticVariable(SyntheticVariable node, A arg) => - defaultTreeNode(node, arg); - @override R visitVariableContext(VariableContext node, A arg) => defaultTreeNode(node, arg); @override @@ -2214,19 +2195,6 @@ class RemovingTransformer extends TreeVisitor1Default { return transformOrRemove(node, dummyVariableDeclaration); } - /// Visits [node], returning the transformation result. Removal of [node] is - /// supported with `null` as the result. - /// - /// This is convenience method for calling [transformOrRemove] with removal - /// sentinel for [VariableDeclaration] nodes. - CatchVariable? transformOrRemoveCatchVariable(CatchVariable node) { - if (node is VariableDeclaration) { - return transformOrRemoveVariableDeclaration(node); - } else { - return transformOrRemove(node, dummyCatchVariable); - } - } - /// Visits [node] using [removalSentinel] as the removal sentinel. /// /// If [removalSentinel] is the result of visiting [node], `null` is returned. @@ -2457,13 +2425,13 @@ class RemovingTransformer extends TreeVisitor1Default { transformList(nodes, parent, dummyVariableDeclaration); } - /// Transforms or removes [VariableInitialization] nodes in [nodes] as + /// Transforms or removes [VariableInitializationBase] nodes in [nodes] as /// children of [parent]. /// /// This is convenience method for calling [transformList] with removal - /// sentinel for [VariableInitialization] nodes. + /// sentinel for [VariableInitializationBase] nodes. void transformVariableInitializationList( - List nodes, + List nodes, TreeNode parent, ) { transformList(nodes, parent, dummyVariableDeclaration); @@ -2583,8 +2551,6 @@ abstract class ExpressionVisitor1 { R visitRecordLiteral(RecordLiteral node, A arg); R visitSwitchExpression(SwitchExpression node, A arg); R visitPatternAssignment(PatternAssignment node, A arg); - R visitVariableRead(VariableRead node, A arg); - R visitVariableWrite(VariableWrite node, A arg); } /// Helper mixin for [ExpressionVisitor1] that implements visit methods by @@ -2784,11 +2750,6 @@ mixin ExpressionVisitor1DefaultMixin implements ExpressionVisitor1 { @override R visitPatternAssignment(PatternAssignment node, A arg) => defaultExpression(node, arg); - @override - R visitVariableRead(VariableRead node, A arg) => defaultExpression(node, arg); - @override - R visitVariableWrite(VariableWrite node, A arg) => - defaultExpression(node, arg); } abstract class PatternVisitor1 { @@ -2889,6 +2850,10 @@ abstract class StatementVisitor1 { R visitVariableStatement(VariableStatement node, A arg); R visitPositionalParameter(PositionalParameter node, A arg); R visitNamedParameter(NamedParameter node, A arg); + R visitLocalVariable(LocalVariable node, A arg); + R visitCatchVariable(CatchVariable node, A arg); + R visitThisVariable(ThisVariable node, A arg); + R visitSyntheticVariable(SyntheticVariable node, A arg); } /// Helper mixin for [StatementVisitor1] that implements visit methods by @@ -2972,6 +2937,17 @@ mixin StatementVisitor1DefaultMixin implements StatementVisitor1 { @override R visitNamedParameter(NamedParameter node, A arg) => defaultStatement(node, arg); + @override + R visitLocalVariable(LocalVariable node, A arg) => + defaultStatement(node, arg); + @override + R visitCatchVariable(CatchVariable node, A arg) => + defaultStatement(node, arg); + @override + R visitThisVariable(ThisVariable node, A arg) => defaultStatement(node, arg); + @override + R visitSyntheticVariable(SyntheticVariable node, A arg) => + defaultStatement(node, arg); } /// [DartTypeVisitorExperimentExclusionMixin] is intended to reduce the effects @@ -3132,17 +3108,7 @@ mixin ExpressionVisitor1InternalNodeMixin /// nodes. The methods throw an exception signaling that the experimental nodes /// aren't supported. mixin ExpressionVisitorExperimentExclusionMixin - implements ExpressionVisitor { - @override - R visitVariableRead(VariableRead node) { - throw StateError("${runtimeType}.visitVariableRead isn't supported."); - } - - @override - R visitVariableWrite(VariableWrite node) { - throw StateError("${runtimeType}.visitVariableWrite isn't supported."); - } -} + implements ExpressionVisitor {} /// [ExpressionVisitor1ExperimentExclusionMixin] is intended to reduce the /// effects of CFE experiments on the backends. @@ -3151,17 +3117,7 @@ mixin ExpressionVisitorExperimentExclusionMixin /// nodes. The methods throw an exception signaling that the experimental nodes /// aren't supported. mixin ExpressionVisitor1ExperimentExclusionMixin - implements ExpressionVisitor1 { - @override - R visitVariableRead(VariableRead node, A arg) { - throw StateError("${runtimeType}.visitVariableRead isn't supported."); - } - - @override - R visitVariableWrite(VariableWrite node, A arg) { - throw StateError("${runtimeType}.visitVariableWrite isn't supported."); - } -} + implements ExpressionVisitor1 {} /// [StatementVisitorInternalNodeMixin] is intended to reduce the effects of /// CFE internal nodes on the backends. @@ -3262,6 +3218,26 @@ mixin StatementVisitorExperimentExclusionMixin R visitNamedParameter(NamedParameter node) { throw StateError("${runtimeType}.visitNamedParameter isn't supported."); } + + @override + R visitLocalVariable(LocalVariable node) { + throw StateError("${runtimeType}.visitLocalVariable isn't supported."); + } + + @override + R visitCatchVariable(CatchVariable node) { + throw StateError("${runtimeType}.visitCatchVariable isn't supported."); + } + + @override + R visitThisVariable(ThisVariable node) { + throw StateError("${runtimeType}.visitThisVariable isn't supported."); + } + + @override + R visitSyntheticVariable(SyntheticVariable node) { + throw StateError("${runtimeType}.visitSyntheticVariable isn't supported."); + } } /// [StatementVisitor1ExperimentExclusionMixin] is intended to reduce the @@ -3306,6 +3282,26 @@ mixin StatementVisitor1ExperimentExclusionMixin R visitNamedParameter(NamedParameter node, A arg) { throw StateError("${runtimeType}.visitNamedParameter isn't supported."); } + + @override + R visitLocalVariable(LocalVariable node, A arg) { + throw StateError("${runtimeType}.visitLocalVariable isn't supported."); + } + + @override + R visitCatchVariable(CatchVariable node, A arg) { + throw StateError("${runtimeType}.visitCatchVariable isn't supported."); + } + + @override + R visitThisVariable(ThisVariable node, A arg) { + throw StateError("${runtimeType}.visitThisVariable isn't supported."); + } + + @override + R visitSyntheticVariable(SyntheticVariable node, A arg) { + throw StateError("${runtimeType}.visitSyntheticVariable isn't supported."); + } } /// [TreeVisitorInternalNodeMixin] is intended to reduce the effects of @@ -3372,26 +3368,6 @@ mixin TreeVisitorExperimentExclusionMixin implements TreeVisitor { throw StateError("${runtimeType}.visitTypeVariable isn't supported."); } - @override - R visitLocalVariable(LocalVariable node) { - throw StateError("${runtimeType}.visitLocalVariable isn't supported."); - } - - @override - R visitCatchVariable(CatchVariable node) { - throw StateError("${runtimeType}.visitCatchVariable isn't supported."); - } - - @override - R visitThisVariable(ThisVariable node) { - throw StateError("${runtimeType}.visitThisVariable isn't supported."); - } - - @override - R visitSyntheticVariable(SyntheticVariable node) { - throw StateError("${runtimeType}.visitSyntheticVariable isn't supported."); - } - @override R visitVariableContext(VariableContext node) { throw StateError("${runtimeType}.visitVariableContext isn't supported."); @@ -3430,26 +3406,6 @@ mixin TreeVisitor1ExperimentExclusionMixin implements TreeVisitor1 { throw StateError("${runtimeType}.visitTypeVariable isn't supported."); } - @override - R visitLocalVariable(LocalVariable node, A arg) { - throw StateError("${runtimeType}.visitLocalVariable isn't supported."); - } - - @override - R visitCatchVariable(CatchVariable node, A arg) { - throw StateError("${runtimeType}.visitCatchVariable isn't supported."); - } - - @override - R visitThisVariable(ThisVariable node, A arg) { - throw StateError("${runtimeType}.visitThisVariable isn't supported."); - } - - @override - R visitSyntheticVariable(SyntheticVariable node, A arg) { - throw StateError("${runtimeType}.visitSyntheticVariable isn't supported."); - } - @override R visitVariableContext(VariableContext node, A arg) { throw StateError("${runtimeType}.visitVariableContext isn't supported."); diff --git a/pkg/vm/lib/modular/transformations/for_in_lowering.dart b/pkg/vm/lib/modular/transformations/for_in_lowering.dart index 1c1bfe62cd6..99c06eb402a 100644 --- a/pkg/vm/lib/modular/transformations/for_in_lowering.dart +++ b/pkg/vm/lib/modular/transformations/for_in_lowering.dart @@ -279,7 +279,7 @@ class ForInLowering { return Block([syncForIteratorVariableInitialization, forStatement]); } - (Variable, VariableInitialization) + (VariableDeclaration, VariableInitializationBase) _createSyncForIteratorVariableAndInitialization({ required Expression initializer, required DartType type, @@ -290,7 +290,7 @@ class ForInLowering { cosmeticName: ForInVariables.syncForIterator, type: type, ); - final initialization = VariableInitialization( + final initialization = VariableInitializationBase( variable: variable, initializer: initializer, ); @@ -306,18 +306,16 @@ class ForInLowering { } } - VariableInitialization _ensureSyncForLoopVariableInitialization({ - required Variable variable, + VariableInitializationBase _ensureSyncForLoopVariableInitialization({ + required VariableDeclaration variable, required Expression initializer, }) { if (isClosureContextLoweringEnabled) { - return VariableInitialization( + return VariableInitializationBase( variable: variable, initializer: initializer, ); } else { - assert(variable is VariableDeclaration); - variable as VariableDeclaration; initializer.parent = variable; return variable..initializer = initializer; }