From 80c9d57250e259b94cf4d15d00daf724a19873de Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Thu, 21 May 2026 01:51:10 -0700 Subject: [PATCH] [kernel][Contexts] Rename VariableDeclaration to Variable This is a step towards split variables from their declarations as part of encoding variables and their usage more precisely. TEST=existing Change-Id: I4a0eeb2947bdebce3667afda4e6cfbfdf5d7de18 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504201 Reviewed-by: Alexander Markov Reviewed-by: Nicholas Shahan Reviewed-by: Chloe Stefantsova Reviewed-by: Martin Kustermann SLSA-Policy-Verified: SLSA Policy Verification Service --- .../shared_interop_transformer.dart | 10 +- pkg/cfg/lib/front_end/ast_to_ir.dart | 22 +- pkg/cfg/lib/front_end/computed_scopes.dart | 5 +- pkg/cfg/lib/front_end/scopes.dart | 2 +- pkg/cfg/lib/ir/field.dart | 2 +- pkg/cfg/lib/ir/flow_graph_builder.dart | 4 +- pkg/cfg/lib/ir/functions.dart | 2 +- pkg/cfg/lib/ir/local_variable.dart | 4 +- pkg/cfg/test/ir/functions_test.dart | 2 +- .../src/deferred_load/entity_data_info.dart | 2 +- pkg/compiler/lib/src/inferrer/builder.dart | 25 +- pkg/compiler/lib/src/ir/closure.dart | 16 +- pkg/compiler/lib/src/ir/impact_data.dart | 6 +- pkg/compiler/lib/src/ir/protobuf_impacts.dart | 2 +- .../lib/src/ir/runtime_type_analysis.dart | 8 +- pkg/compiler/lib/src/ir/scope.dart | 24 +- pkg/compiler/lib/src/ir/scope_visitor.dart | 35 +- pkg/compiler/lib/src/ir/util.dart | 4 +- .../lib/src/js_backend/field_analysis.dart | 2 +- pkg/compiler/lib/src/js_model/closure.dart | 81 ++- .../lib/src/js_model/element_map.dart | 16 +- .../lib/src/js_model/element_map_impl.dart | 35 +- pkg/compiler/lib/src/js_model/env.dart | 7 +- .../lib/src/js_model/js_world_builder.dart | 2 +- pkg/compiler/lib/src/js_model/locals.dart | 10 +- .../lib/src/kernel/element_map_impl.dart | 16 +- pkg/compiler/lib/src/kernel/env.dart | 5 +- .../src/kernel/no_such_method_resolver.dart | 3 +- .../global/constant_transformer.dart | 2 +- .../modular/late_lowering.dart | 54 +- .../modular/list_factory_specializer.dart | 28 +- .../transformations/modular/transform.dart | 2 +- .../lib/src/serialization/node_indexer.dart | 4 +- pkg/compiler/lib/src/serialization/sink.dart | 3 +- pkg/compiler/lib/src/ssa/builder.dart | 64 ++- pkg/compiler/test/closure/closure_test.dart | 2 +- .../test/inference/inference_test_helper.dart | 2 +- pkg/dart2bytecode/lib/bytecode_generator.dart | 51 +- pkg/dart2bytecode/lib/local_vars.dart | 130 +++-- pkg/dart2bytecode/lib/object_table.dart | 5 +- pkg/dart2wasm/lib/async.dart | 2 +- pkg/dart2wasm/lib/await_transformer.dart | 41 +- pkg/dart2wasm/lib/closures.dart | 23 +- pkg/dart2wasm/lib/code_generator.dart | 33 +- pkg/dart2wasm/lib/constructor_info.dart | 16 +- .../lib/deferred_load/dependencies.dart | 3 +- pkg/dart2wasm/lib/dispatch_table.dart | 2 +- pkg/dart2wasm/lib/ffi_native_transformer.dart | 4 +- pkg/dart2wasm/lib/functions.dart | 2 +- .../lib/js/callback_specializer.dart | 28 +- pkg/dart2wasm/lib/js/inline_expander.dart | 4 +- pkg/dart2wasm/lib/js/interop_specializer.dart | 24 +- pkg/dart2wasm/lib/js/util.dart | 24 +- pkg/dart2wasm/lib/param_info.dart | 6 +- pkg/dart2wasm/lib/record_class_generator.dart | 13 +- pkg/dart2wasm/lib/state_machine.dart | 24 +- pkg/dart2wasm/lib/transformers.dart | 40 +- pkg/dart2wasm/lib/translator.dart | 38 +- pkg/dev_compiler/lib/src/command/command.dart | 2 +- pkg/dev_compiler/lib/src/kernel/compiler.dart | 57 +-- .../lib/src/kernel/compiler_new.dart | 59 +-- .../lib/src/kernel/kernel_helpers.dart | 6 +- .../src/kernel/module_symbols_collector.dart | 6 +- .../lib/src/kernel/nullable_inference.dart | 13 +- pkg/dev_compiler/lib/src/kernel/target.dart | 2 +- .../api_prototype/lowering_predicates.dart | 16 +- .../lib/src/base/incremental_compiler.dart | 11 +- .../src/builder/formal_parameter_builder.dart | 25 +- .../lib/src/builder/function_signature.dart | 4 +- .../lib/src/builder/variable_builder.dart | 4 +- .../lib/src/fragment/constructor.dart | 2 +- .../constructor/body_builder_context.dart | 4 +- .../src/fragment/constructor/declaration.dart | 14 +- .../src/fragment/constructor/encoding.dart | 26 +- pkg/front_end/lib/src/fragment/factory.dart | 2 +- .../factory/body_builder_context.dart | 2 +- .../lib/src/fragment/factory/declaration.dart | 8 +- .../lib/src/fragment/factory/encoding.dart | 4 +- .../lib/src/fragment/field/encoding.dart | 18 +- pkg/front_end/lib/src/fragment/function.dart | 2 +- pkg/front_end/lib/src/fragment/getter.dart | 2 +- .../fragment/getter/body_builder_context.dart | 2 +- .../lib/src/fragment/getter/declaration.dart | 8 +- .../lib/src/fragment/getter/encoding.dart | 12 +- pkg/front_end/lib/src/fragment/method.dart | 2 +- .../fragment/method/body_builder_context.dart | 2 +- .../lib/src/fragment/method/declaration.dart | 12 +- .../lib/src/fragment/method/encoding.dart | 44 +- .../lib/src/fragment/primary_constructor.dart | 2 +- pkg/front_end/lib/src/fragment/setter.dart | 2 +- .../fragment/setter/body_builder_context.dart | 2 +- .../lib/src/fragment/setter/declaration.dart | 8 +- .../lib/src/fragment/setter/encoding.dart | 18 +- .../src/kernel/assigned_variables_impl.dart | 21 +- .../lib/src/kernel/body_builder.dart | 181 ++++--- .../lib/src/kernel/body_builder_context.dart | 6 +- .../lib/src/kernel/body_builder_helpers.dart | 8 +- pkg/front_end/lib/src/kernel/collections.dart | 8 +- .../src/kernel/combined_member_signature.dart | 24 +- .../kernel/const_conditional_simplifier.dart | 12 +- .../lib/src/kernel/constant_evaluator.dart | 159 +++--- .../kernel/constructor_tearoff_lowering.dart | 19 +- .../lib/src/kernel/dart_scope_calculator.dart | 83 ++-- .../lib/src/kernel/expression_generator.dart | 10 +- .../kernel/expression_generator_helper.dart | 10 +- .../lib/src/kernel/external_ast_helper.dart | 48 +- .../lib/src/kernel/forwarding_node.dart | 21 +- .../src/kernel/hierarchy/members_builder.dart | 2 +- .../src/kernel/hierarchy/members_node.dart | 6 +- .../lib/src/kernel/internal_ast.dart | 111 +++-- .../lib/src/kernel/internal_ast_helper.dart | 36 +- .../lib/src/kernel/kernel_helper.dart | 40 +- .../lib/src/kernel/kernel_target.dart | 21 +- .../src/kernel/kernel_variable_builder.dart | 4 +- .../lib/src/kernel/late_lowering.dart | 22 +- .../lib/src/kernel/member_covariance.dart | 11 +- pkg/front_end/lib/src/kernel/resolver.dart | 39 +- .../lib/src/kernel/resolver_helpers.dart | 12 +- .../lib/src/source/check_helper.dart | 2 +- .../lib/src/source/source_class_builder.dart | 35 +- .../src/source/source_function_builder.dart | 4 +- .../src/source/source_library_builder.dart | 15 +- .../lib/src/source/source_loader.dart | 2 +- pkg/front_end/lib/src/source/value_kinds.dart | 2 +- .../lib/src/testing/id_extractor.dart | 2 +- .../context_allocation_strategy.dart | 8 +- .../type_inference/delayed_expressions.dart | 6 +- .../src/type_inference/inference_results.dart | 22 +- .../src/type_inference/inference_visitor.dart | 462 +++++++----------- .../inference_visitor_base.dart | 97 ++-- .../src/type_inference/matching_cache.dart | 49 +- .../type_inference/matching_expressions.dart | 4 +- .../type_inference/shared_type_analyzer.dart | 8 +- .../type_constraint_gatherer.dart | 4 +- .../type_inference/type_inference_engine.dart | 30 +- .../lib/src/type_inference/type_inferrer.dart | 32 +- .../type_schema_environment.dart | 7 +- .../comments_on_certain_arguments_tool.dart | 4 +- pkg/front_end/test/compiler_test_helper.dart | 2 +- .../test/dart_scope_calculator_test.dart | 18 +- pkg/front_end/test/expression_suite.dart | 4 +- .../test/generator_to_string_test.dart | 13 +- .../id_tests/assigned_variables_test.dart | 15 +- .../inferred_variable_types_test.dart | 2 +- .../test/member_covariance_test.dart | 24 +- .../test/predicates/predicate_test.dart | 4 +- .../test/static_types/static_type_test.dart | 2 +- .../static_types/type_arguments_test.dart | 2 +- ...internal_ast_text_representation_test.dart | 35 +- .../text_representation_test.dart | 9 +- pkg/front_end/tool/ast_model.dart | 8 +- pkg/front_end/tool/unreachable_if_finder.dart | 12 +- pkg/kernel/lib/binary/ast_from_binary.dart | 70 ++- pkg/kernel/lib/binary/ast_to_binary.dart | 20 +- pkg/kernel/lib/clone.dart | 38 +- pkg/kernel/lib/naive_type_checker.dart | 15 +- pkg/kernel/lib/src/ast/dummies.dart | 6 +- pkg/kernel/lib/src/ast/expressions.dart | 8 +- pkg/kernel/lib/src/ast/functions.dart | 27 +- pkg/kernel/lib/src/ast/initializers.dart | 2 +- pkg/kernel/lib/src/ast/patterns.dart | 46 +- pkg/kernel/lib/src/ast/statements.dart | 26 +- pkg/kernel/lib/src/ast/typedefs.dart | 4 +- pkg/kernel/lib/src/ast/variables.dart | 50 +- pkg/kernel/lib/src/coverage.dart | 26 +- pkg/kernel/lib/src/equivalence.dart | 32 +- pkg/kernel/lib/src/node_creator.dart | 109 ++--- pkg/kernel/lib/src/printer.dart | 8 +- pkg/kernel/lib/target/targets.dart | 4 +- pkg/kernel/lib/text/ast_to_text.dart | 32 +- pkg/kernel/lib/text/debug_printer.dart | 2 +- .../track_widget_constructor_locations.dart | 30 +- pkg/kernel/lib/type_checker.dart | 8 +- pkg/kernel/lib/verifier.dart | 23 +- pkg/kernel/lib/visitor.dart | 92 ++-- pkg/kernel/test/class_hierarchy_test.dart | 2 +- .../convert_field_to_setter_getter_test.dart | 2 +- .../test/generalized_tracking_test.dart | 8 +- pkg/kernel/test/verify_test.dart | 17 +- pkg/vm/lib/embedder/shims.dart | 2 +- .../transformations/call_site_annotator.dart | 4 +- .../transformations/ffi/definitions.dart | 12 +- .../transformations/ffi/finalizable.dart | 43 +- .../modular/transformations/ffi/native.dart | 16 +- .../transformations/ffi/native_type_cfe.dart | 16 +- .../transformations/ffi/use_sites.dart | 53 +- .../transformations/for_in_lowering.dart | 13 +- .../late_var_init_transformer.dart | 2 +- .../mixin_full_resolution.dart | 3 +- .../transformations/type_casts_optimizer.dart | 2 +- .../transformations/type_flow/analysis.dart | 12 +- .../type_flow/signature_shaking.dart | 43 +- .../transformations/type_flow/summary.dart | 18 +- .../type_flow/summary_collector.dart | 45 +- .../type_flow/transformer.dart | 24 +- .../lib/transformations/type_flow/types.dart | 6 +- .../lib/transformations/type_flow/utils.dart | 2 +- .../type_flow/summary_collector_test.dart | 4 +- 198 files changed, 1947 insertions(+), 2368 deletions(-) diff --git a/pkg/_js_interop_checks/lib/src/transformations/shared_interop_transformer.dart b/pkg/_js_interop_checks/lib/src/transformations/shared_interop_transformer.dart index f00b095379d..748b75b84b6 100644 --- a/pkg/_js_interop_checks/lib/src/transformations/shared_interop_transformer.dart +++ b/pkg/_js_interop_checks/lib/src/transformations/shared_interop_transformer.dart @@ -365,7 +365,7 @@ class SharedInteropTransformer extends Transformer { // already a variable for both these declarations. // TODO(srujzs): Change these to `VariableDeclaration.forValue` once // https://github.com/dart-lang/sdk/issues/54734 is resolved. - var dartInstance = VariableDeclaration( + var dartInstance = Variable( '#dartInstance', initializer: invocation.arguments.positional[0], type: dartType, @@ -375,7 +375,7 @@ class SharedInteropTransformer extends Transformer { VariableStatement(dartInstance)..fileOffset = invocation.fileOffset, ); - var jsExporter = VariableDeclaration( + var jsExporter = Variable( '#jsExporter', initializer: getLiteral(proto), type: ExtensionType(_jsObject, Nullability.nonNullable), @@ -456,7 +456,7 @@ class SharedInteropTransformer extends Transformer { // // A new map VariableDeclaration is created and added to the block of // statements for each export name. - var getSetMap = VariableDeclaration( + var getSetMap = Variable( // Don't use the exportName here because it might not be a valid JS // identifier. '#${exportNameIdentifierCounter++}Mapping', @@ -503,7 +503,7 @@ class SharedInteropTransformer extends Transformer { ); } if (setter != null) { - var setterParameter = VariableDeclaration( + var setterParameter = Variable( '#val', type: _staticInteropMockValidator.typeParameterResolver.resolve( setter.setterType, @@ -599,7 +599,7 @@ class SharedInteropTransformer extends Transformer { final receiverVar = receiver is VariableGet ? receiver.variable // Synthesize declaration to avoid re-evaluating expressions. - : (VariableDeclaration.forValue( + : (Variable.forValue( receiver, type: receiverIsJSType ? ExtensionType(_jsAny, Nullability.nullable) diff --git a/pkg/cfg/lib/front_end/ast_to_ir.dart b/pkg/cfg/lib/front_end/ast_to_ir.dart index b6bfe0f79ec..a232c8c71dd 100644 --- a/pkg/cfg/lib/front_end/ast_to_ir.dart +++ b/pkg/cfg/lib/front_end/ast_to_ir.dart @@ -819,10 +819,10 @@ class AstToIr extends ast.RecursiveVisitor { bool _isCapturedContext(Context context) => context.isCaptured(enableAsserts: enableAsserts); - bool _isCaptured(ast.VariableDeclaration v) => + bool _isCaptured(ast.Variable v) => _isCapturedContext(scopes.getVariableContext(v)); - void _readVariable(ast.VariableDeclaration v) { + void _readVariable(ast.Variable v) { if (_isCaptured(v)) { builder.push(localVarIndexer.contextDef(scopes.getVariableContext(v))); builder.addLoadInstanceField(localVarIndexer.contextField(v)); @@ -831,7 +831,7 @@ class AstToIr extends ast.RecursiveVisitor { } } - void _writeVariable(ast.VariableDeclaration v) { + void _writeVariable(ast.Variable v) { if (_isCaptured(v)) { final value = builder.pop(); builder.push(localVarIndexer.contextDef(scopes.getVariableContext(v))); @@ -900,7 +900,7 @@ class AstToIr extends ast.RecursiveVisitor { } @override - void defaultVariableDeclaration(ast.VariableDeclaration node) { + void defaultVariable(ast.Variable node) { final variable = node.variable; if (node.isConst) return; if (node.isLate) { @@ -925,12 +925,12 @@ class AstToIr extends ast.RecursiveVisitor { @override void visitLegacyVariableStatement(ast.LegacyVariableStatement node) { - defaultVariableDeclaration(node.variable); + defaultVariable(node.variable); } @override void visitVariableInitialization(ast.VariableInitialization node) { - defaultVariableDeclaration(node.variable); + defaultVariable(node.variable); } @override @@ -2132,17 +2132,17 @@ class LocalVariableIndexer { final CoreTypes coreTypes; final AstToIrTypes typeTranslator; final Scopes scopes; - final Map _declaredVariables = {}; + final Map _declaredVariables = {}; final Map _exceptionVariables = {}; final Map _stackTraceVariables = {}; final Map _contexts = {}; - final Map _contextFields = {}; + final Map _contextFields = {}; final List parameters = []; late final LocalVariable functionTypeParameters; late final LocalVariable receiver; late final LocalVariable closure; - late final ast.VariableDeclaration? receiverDeclaration; + late final ast.Variable? receiverDeclaration; LocalVariableIndexer( this.builder, @@ -2200,7 +2200,7 @@ class LocalVariableIndexer { assert(parameters.length == function.numberOfParameters); } - LocalVariable variableForDeclaration(ast.VariableDeclaration declaration) => + LocalVariable variableForDeclaration(ast.Variable declaration) => _declaredVariables[declaration] ??= builder.declareLocalVariable( declaration.name ?? '#temp', declaration, @@ -2234,7 +2234,7 @@ class LocalVariableIndexer { Definition contextDef(Context ctx) => _contexts[ctx]!; // TODO: share context fields between functions. - CField contextField(ast.VariableDeclaration variable) => + CField contextField(ast.Variable variable) => _contextFields[variable] ??= CField( ContextField( variable, diff --git a/pkg/cfg/lib/front_end/computed_scopes.dart b/pkg/cfg/lib/front_end/computed_scopes.dart index 8037d1b3b9d..68debcfb30b 100644 --- a/pkg/cfg/lib/front_end/computed_scopes.dart +++ b/pkg/cfg/lib/front_end/computed_scopes.dart @@ -22,8 +22,7 @@ final class ComputedScopes implements Scopes { .nonNullable, ); thisVariable = - member.function?.thisVariable ?? - ast.VariableDeclaration('this', type: type); + member.function?.thisVariable ?? ast.Variable('this', type: type); } final builder = _ScopeBuilder(this); member.accept(builder); @@ -310,7 +309,7 @@ class _ScopeBuilder extends ast.RecursiveVisitor { } @override - void defaultVariableDeclaration(ast.VariableDeclaration node) { + void defaultVariable(ast.Variable node) { _declareVariable(node.variable); node.visitChildren(this); } diff --git a/pkg/cfg/lib/front_end/scopes.dart b/pkg/cfg/lib/front_end/scopes.dart index cbdf82594a3..89e133f6733 100644 --- a/pkg/cfg/lib/front_end/scopes.dart +++ b/pkg/cfg/lib/front_end/scopes.dart @@ -4,7 +4,7 @@ import 'package:kernel/ast.dart' as ast; -typedef Variable = ast.VariableDeclaration; +typedef Variable = ast.Variable; /// A unit of capturing. Contains variables and belongs to a certain [Scope]. abstract class Context { diff --git a/pkg/cfg/lib/ir/field.dart b/pkg/cfg/lib/ir/field.dart index 7b348ea506f..2e52a43defd 100644 --- a/pkg/cfg/lib/ir/field.dart +++ b/pkg/cfg/lib/ir/field.dart @@ -32,7 +32,7 @@ sealed class SyntheticField extends ast.Field { /// Field of the context object. /// Context fields hold values of captured variables. final class ContextField extends SyntheticField { - final ast.VariableDeclaration variable; + final ast.Variable variable; final int index; ContextField(this.variable, this.index) diff --git a/pkg/cfg/lib/ir/flow_graph_builder.dart b/pkg/cfg/lib/ir/flow_graph_builder.dart index 7801127da03..96049a13aec 100644 --- a/pkg/cfg/lib/ir/flow_graph_builder.dart +++ b/pkg/cfg/lib/ir/flow_graph_builder.dart @@ -12,7 +12,7 @@ import 'package:cfg/ir/source_position.dart'; import 'package:cfg/ir/types.dart'; import 'package:kernel/ast.dart' as ast - show DartType, Name, TypeLiteralConstant, VariableDeclaration; + show DartType, Name, TypeLiteralConstant, Variable; /// Helper class to create IR instructions and populate [FlowGraph]. /// @@ -290,7 +290,7 @@ class FlowGraphBuilder { /// Add [LocalVariable] to the graph. LocalVariable declareLocalVariable( String name, - ast.VariableDeclaration? declaration, + ast.Variable? declaration, CType type, ) { final v = LocalVariable( diff --git a/pkg/cfg/lib/ir/functions.dart b/pkg/cfg/lib/ir/functions.dart index 7f9c01d38ab..f7cdb1f0a23 100644 --- a/pkg/cfg/lib/ir/functions.dart +++ b/pkg/cfg/lib/ir/functions.dart @@ -71,7 +71,7 @@ sealed class CFunction { bool get hasNamedParameters => functionNode?.namedParameters.isNotEmpty ?? false; - ast.VariableDeclaration _getOptionalOrNamedParameter(int index) => + ast.Variable _getOptionalOrNamedParameter(int index) => hasOptionalPositionalParameters ? functionNode!.positionalParameters[index - numberOfImplicitParameters] : functionNode!.namedParameters[index - diff --git a/pkg/cfg/lib/ir/local_variable.dart b/pkg/cfg/lib/ir/local_variable.dart index 52e5434f5c1..0ee5c3af8ba 100644 --- a/pkg/cfg/lib/ir/local_variable.dart +++ b/pkg/cfg/lib/ir/local_variable.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' as ast show VariableDeclaration; +import 'package:kernel/ast.dart' as ast show Variable; import 'package:cfg/ir/types.dart'; /// Local variable or a function parameter. @@ -14,7 +14,7 @@ class LocalVariable { final String name; /// Declaration of the variable in the AST, if any. - final ast.VariableDeclaration? declaration; + final ast.Variable? declaration; /// Index of the variable in the [FlowGraph.localVariables]. final int index; diff --git a/pkg/cfg/test/ir/functions_test.dart b/pkg/cfg/test/ir/functions_test.dart index b54a552e3a2..a4923e7e27c 100644 --- a/pkg/cfg/test/ir/functions_test.dart +++ b/pkg/cfg/test/ir/functions_test.dart @@ -165,7 +165,7 @@ void main() { test('local function', () { final member = coreTypes.futureValueFactory; final localFunction = ast.FunctionDeclaration( - ast.VariableDeclaration('foo'), + ast.Variable('foo'), ast.FunctionNode( ast.Block([]), returnType: coreTypes.boolNonNullableRawType, diff --git a/pkg/compiler/lib/src/deferred_load/entity_data_info.dart b/pkg/compiler/lib/src/deferred_load/entity_data_info.dart index cb1d6c04b64..7c1cd561faf 100644 --- a/pkg/compiler/lib/src/deferred_load/entity_data_info.dart +++ b/pkg/compiler/lib/src/deferred_load/entity_data_info.dart @@ -578,7 +578,7 @@ class ConstantCollector extends ir.RecursiveVisitor { } @override - void defaultVariableDeclaration(ir.VariableDeclaration node) { + void defaultVariable(ir.Variable node) { // We avoid visiting metadata on the parameter declaration by only visiting // the initializer. The type cannot hold constants so can kan skip that // as well. diff --git a/pkg/compiler/lib/src/inferrer/builder.dart b/pkg/compiler/lib/src/inferrer/builder.dart index 1f637771396..315cb9c9ede 100644 --- a/pkg/compiler/lib/src/inferrer/builder.dart +++ b/pkg/compiler/lib/src/inferrer/builder.dart @@ -280,10 +280,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault return result; } - void handleParameter( - ir.VariableDeclaration node, { - required bool isOptional, - }) { + void handleParameter(ir.Variable node, {required bool isOptional}) { Local local = _localsMap.getLocalVariable(node); final parameterType = _inferrer.typeOfParameter(local); _state.setLocal(_inferrer, _capturedAndBoxed, local, parameterType); @@ -426,14 +423,14 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault void handleParameters(ir.FunctionNode node) { int position = 0; - for (ir.VariableDeclaration parameter in node.positionalParameters) { + for (ir.Variable parameter in node.positionalParameters) { handleParameter( parameter, isOptional: position >= node.requiredParameterCount, ); position++; } - for (ir.VariableDeclaration parameter in node.namedParameters) { + for (ir.Variable parameter in node.namedParameters) { handleParameter(parameter, isOptional: true); } } @@ -942,11 +939,11 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault TypeInformation? visitLegacyVariableStatement( ir.LegacyVariableStatement node, ) { - return defaultVariableDeclaration(node.variable); + return defaultVariable(node.variable); } @override - TypeInformation? defaultVariableDeclaration(ir.VariableDeclaration node) { + TypeInformation? defaultVariable(ir.Variable node) { assert( node.parent is! ir.FunctionNode, "Unexpected parameter declaration.", @@ -1256,7 +1253,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault ); } - ir.VariableDeclaration? _getVariableDeclaration(ir.Expression node) { + ir.Variable? _getVariableDeclaration(ir.Expression node) { return node is ir.VariableGet ? node.variable : null; } @@ -1267,7 +1264,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault AbstractValue? mask, TypeInformation receiverType, ArgumentsTypes? arguments, - ir.VariableDeclaration? variable, + ir.Variable? variable, ) { if (_types.selectorNeedsUpdate(receiverType, mask)) { mask = receiverType == _types.dynamicType @@ -1317,7 +1314,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault Selector selector, AbstractValue? mask, TypeInformation receiverType, - ir.VariableDeclaration? variable, + ir.Variable? variable, ) { return _handleDynamic( CallType.access, @@ -1336,7 +1333,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault AbstractValue? mask, TypeInformation receiverType, TypeInformation rhsType, - ir.VariableDeclaration? variable, + ir.Variable? variable, ) { ArgumentsTypes arguments = ArgumentsTypes([rhsType], null); return _handleDynamic( @@ -1357,7 +1354,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault AbstractValue? mask, TypeInformation receiverType, ArgumentsTypes arguments, - ir.VariableDeclaration? variable, + ir.Variable? variable, ) { return _handleDynamic( callType, @@ -2356,7 +2353,7 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault TypeInformation handleLocalFunction( ir.LocalFunction node, ir.FunctionNode functionNode, [ - ir.VariableDeclaration? variable, + ir.Variable? variable, ]) { // We loose track of [this] in closures (see issue 20840). To be on // the safe side, we mark [this] as exposed here. We could do better by diff --git a/pkg/compiler/lib/src/ir/closure.dart b/pkg/compiler/lib/src/ir/closure.dart index f4dac1ff992..fb62241fd0f 100644 --- a/pkg/compiler/lib/src/ir/closure.dart +++ b/pkg/compiler/lib/src/ir/closure.dart @@ -27,9 +27,9 @@ class ClosureScopeModel { } class KernelScopeInfo { - final Set localsUsedInTryOrSync; + final Set localsUsedInTryOrSync; final bool hasThisLocal; - final Set boxedVariables; + final Set boxedVariables; // If boxedVariables is empty, this will be null, because no variables will // need to be boxed. final NodeBox? capturedVariablesAccessor; @@ -61,8 +61,8 @@ class KernelScopeInfo { Set thisUsedAsFreeVariableIfNeedsRti = {}; KernelScopeInfo(this.hasThisLocal) - : localsUsedInTryOrSync = {}, - boxedVariables = {}, + : localsUsedInTryOrSync = {}, + boxedVariables = {}, capturedVariablesAccessor = null; KernelScopeInfo.from(this.hasThisLocal, KernelScopeInfo info) @@ -125,19 +125,19 @@ class KernelCapturedScope extends KernelScopeInfo { ); // Silly hack because we don't have const sets. - static final Set _empty = {}; + static final Set _empty = {}; bool get requiresContextBox => boxedVariables.isNotEmpty; } class KernelCapturedLoopScope extends KernelCapturedScope { - final List boxedLoopVariables; + final List boxedLoopVariables; KernelCapturedLoopScope( - Set boxedVariables, + Set boxedVariables, NodeBox? capturedVariablesAccessor, this.boxedLoopVariables, - Set localsUsedInTryOrSync, + Set localsUsedInTryOrSync, Set freeVariables, Map> freeVariablesForRti, diff --git a/pkg/compiler/lib/src/ir/impact_data.dart b/pkg/compiler/lib/src/ir/impact_data.dart index 20324dee283..a2dfea47368 100644 --- a/pkg/compiler/lib/src/ir/impact_data.dart +++ b/pkg/compiler/lib/src/ir/impact_data.dart @@ -284,7 +284,7 @@ class ImpactBuilder extends ir.RecursiveVisitor implements ImpactRegistry { } @override - void defaultVariableDeclaration(ir.VariableDeclaration node) { + void defaultVariable(ir.Variable node) { if (node.initializer == null) { registerLocalWithoutInitializer(); } @@ -426,11 +426,11 @@ class ImpactBuilder extends ir.RecursiveVisitor implements ImpactRegistry { for (ir.TypeParameter parameter in node.typeParameters) { registerParameterCheck(parameter.bound); } - for (ir.VariableDeclaration parameter in node.positionalParameters) { + for (ir.Variable parameter in node.positionalParameters) { registerParameterCheck(parameter.type); parameter.initializer?.accept(this); } - for (ir.VariableDeclaration parameter in node.namedParameters) { + for (ir.Variable parameter in node.namedParameters) { registerParameterCheck(parameter.type); parameter.initializer?.accept(this); } diff --git a/pkg/compiler/lib/src/ir/protobuf_impacts.dart b/pkg/compiler/lib/src/ir/protobuf_impacts.dart index 52e3b9b354a..7768900eccc 100644 --- a/pkg/compiler/lib/src/ir/protobuf_impacts.dart +++ b/pkg/compiler/lib/src/ir/protobuf_impacts.dart @@ -282,7 +282,7 @@ class ProtobufImpactHandler implements ConditionalImpactHandler { /// declaration is not in scope. class _CloneVisitorLenientVariables extends ir.CloneVisitorNotMembers { @override - ir.VariableDeclaration getVariableClone(ir.VariableDeclaration variable) { + ir.Variable getVariableClone(ir.Variable variable) { return super.getVariableClone(variable) ?? variable; } } diff --git a/pkg/compiler/lib/src/ir/runtime_type_analysis.dart b/pkg/compiler/lib/src/ir/runtime_type_analysis.dart index 6bc1ff19ed0..fbabe3ab3b3 100644 --- a/pkg/compiler/lib/src/ir/runtime_type_analysis.dart +++ b/pkg/compiler/lib/src/ir/runtime_type_analysis.dart @@ -110,8 +110,7 @@ RuntimeTypeUseData computeRuntimeTypeUse( final nullAwareParent = nullAware.parent; final nullAwareParentParent = nullAwareParent.parent; - if (nullAwareParent is ir.VariableDeclaration && - nullAwareParentParent is ir.Let) { + if (nullAwareParent is ir.Variable && nullAwareParentParent is ir.Let) { _NullAwareExpression? outer = _getNullAwareExpression( nullAwareParentParent, ); @@ -268,8 +267,7 @@ RuntimeTypeUseData computeRuntimeTypeUse( receiverGet = node; } } - } else if (nodeParent is ir.VariableDeclaration && - nodeParentParent is ir.Let) { + } else if (nodeParent is ir.Variable && nodeParentParent is ir.Let) { _NullAwareExpression? nullAware = _getNullAwareExpression(nodeParentParent); if (nullAware != null && _isInvokeToString(nullAware.expression)) { // Detected @@ -449,7 +447,7 @@ ir.InstanceGet? _extractGetRuntimeType(ir.TreeNode node) => /// expression. [let] returns the let node created for the encoding. class _NullAwareExpression { final ir.Let let; - final ir.VariableDeclaration syntheticVariable; + final ir.Variable syntheticVariable; final ir.Expression expression; _NullAwareExpression(this.let, this.syntheticVariable, this.expression); diff --git a/pkg/compiler/lib/src/ir/scope.dart b/pkg/compiler/lib/src/ir/scope.dart index 1d82bfcc740..9d3d6a6f418 100644 --- a/pkg/compiler/lib/src/ir/scope.dart +++ b/pkg/compiler/lib/src/ir/scope.dart @@ -28,18 +28,18 @@ class ScopeModel { abstract class VariableScopeModel { VariableScope getScopeFor(ir.TreeNode node); - Iterable get assignedVariables; + Iterable get assignedVariables; } class VariableScopeModelImpl implements VariableScopeModel { final Map _scopeMap = {}; - Set? _assignedVariables; + Set? _assignedVariables; VariableScopeImpl createScopeFor(ir.TreeNode node) { return _scopeMap[node] ??= VariableScopeImpl(); } - void registerAssignedVariable(ir.VariableDeclaration node) { + void registerAssignedVariable(ir.Variable node) { (_assignedVariables ??= {}).add(node); } @@ -49,15 +49,15 @@ class VariableScopeModelImpl implements VariableScopeModel { } @override - Iterable get assignedVariables => - _assignedVariables ?? []; + Iterable get assignedVariables => + _assignedVariables ?? []; } /// Variable information for a scope. abstract class VariableScope { - /// Returns the set of [ir.VariableDeclaration]s that have been assigned to in + /// Returns the set of [ir.Variable]s that have been assigned to in /// this scope. - Iterable get assignedVariables; + Iterable get assignedVariables; /// Returns `true` if this scope has a [ir.ContinueSwitchStatement]. bool get hasContinueSwitch; @@ -65,7 +65,7 @@ abstract class VariableScope { class VariableScopeImpl implements VariableScope { List? _subScopes; - Set? _assignedVariables; + Set? _assignedVariables; @override bool hasContinueSwitch = false; @@ -74,13 +74,13 @@ class VariableScopeImpl implements VariableScope { _subScopes!.add(scope); } - void registerAssignedVariable(ir.VariableDeclaration variable) { - _assignedVariables ??= {}; + void registerAssignedVariable(ir.Variable variable) { + _assignedVariables ??= {}; _assignedVariables!.add(variable); } @override - Iterable get assignedVariables sync* { + Iterable get assignedVariables sync* { if (_assignedVariables != null) { yield* _assignedVariables!; } @@ -106,7 +106,7 @@ mixin VariableCollectorMixin { currentVariableScope = oldScope; } - void registerAssignedVariable(ir.VariableDeclaration node) { + void registerAssignedVariable(ir.Variable node) { currentVariableScope?.registerAssignedVariable(node); variableScopeModel.registerAssignedVariable(node); } diff --git a/pkg/compiler/lib/src/ir/scope_visitor.dart b/pkg/compiler/lib/src/ir/scope_visitor.dart index 577eb13b029..5489e92ebbd 100644 --- a/pkg/compiler/lib/src/ir/scope_visitor.dart +++ b/pkg/compiler/lib/src/ir/scope_visitor.dart @@ -53,7 +53,7 @@ class ScopeModelBuilder extends ir.VisitorDefault /// Keep track of the mutated local variables so that we don't need to box /// non-mutated variables. We know these are only VariableDeclarations because /// type variable types and `this` types can't be mutated! - final Set _mutatedVariables = {}; + final Set _mutatedVariables = {}; /// The set of variables that are accessed in some form, whether they are /// mutated or not. @@ -187,12 +187,11 @@ class ScopeModelBuilder extends ir.VisitorDefault /// Update the [CapturedScope] object corresponding to /// this node if any variables are captured. void attachCapturedScopeVariables(ir.TreeNode node) { - Set capturedVariablesForScope = - {}; + Set capturedVariablesForScope = {}; for (ir.Node variable in _scopeVariables) { // No need to box non-assignable elements. - if (variable is ir.VariableDeclaration) { + if (variable is ir.Variable) { if (variable.isConst) continue; if (!_mutatedVariables.contains(variable)) continue; if (_capturedVariables.contains(variable)) { @@ -307,10 +306,7 @@ class ScopeModelBuilder extends ir.VisitorDefault return const EvaluationComplexity.lazy(); } - void _handleVariableDeclaration( - ir.VariableDeclaration node, - VariableUse usage, - ) { + void _handleVariableDeclaration(ir.Variable node, VariableUse usage) { if (!node.isInitializingFormal) { _scopeVariables.add(node); } @@ -325,11 +321,11 @@ class ScopeModelBuilder extends ir.VisitorDefault EvaluationComplexity visitLegacyVariableStatement( ir.LegacyVariableStatement node, ) { - return defaultVariableDeclaration(node.variable); + return defaultVariable(node.variable); } @override - EvaluationComplexity defaultVariableDeclaration(ir.VariableDeclaration node) { + EvaluationComplexity defaultVariable(ir.Variable node) { _handleVariableDeclaration(node.variable, SimpleVariableUse.localType); return const EvaluationComplexity.lazy(); } @@ -343,10 +339,7 @@ class ScopeModelBuilder extends ir.VisitorDefault ir.Node /* VariableDeclaration | TypeParameterTypeWithContext */ variable, VariableUse usage, ) { - assert( - variable is ir.VariableDeclaration || - variable is TypeVariableTypeWithContext, - ); + assert(variable is ir.Variable || variable is TypeVariableTypeWithContext); if (_isInsideClosure && !_inCurrentContext(variable)) { // If the element is not declared in the current function and the element // is not the closure itself we need to mark the element as free variable. @@ -365,7 +358,7 @@ class ScopeModelBuilder extends ir.VisitorDefault .add(usage); } } - if (_inTry && variable is ir.VariableDeclaration) { + if (_inTry && variable is ir.Variable) { _currentScopeInfo.localsUsedInTryOrSync.add(variable); } } @@ -500,8 +493,7 @@ class ScopeModelBuilder extends ir.VisitorDefault @override EvaluationComplexity visitForStatement(ir.ForStatement node) { - List boxedLoopVariables = - []; + List boxedLoopVariables = []; enterNewScope(node, () { // First visit initialized variables and update steps so we can easily // check if a loop variable was captured in one of these subexpressions. @@ -648,10 +640,7 @@ class ScopeModelBuilder extends ir.VisitorDefault /// Return true if [variable]'s context is the same as the current executable /// context. bool _inCurrentContext(ir.Node variable) { - assert( - variable is ir.VariableDeclaration || - variable is TypeVariableTypeWithContext, - ); + assert(variable is ir.Variable || variable is TypeVariableTypeWithContext); if (variable is TypeVariableTypeWithContext) { return variable.context == _executableContext; } @@ -877,10 +866,10 @@ class ScopeModelBuilder extends ir.VisitorDefault ? MemberParameterVariableUse(parent) : LocalParameterVariableUse(parent as ir.LocalFunction); visitNodesInContext(node.typeParameters, parameterUsage); - for (ir.VariableDeclaration declaration in node.positionalParameters) { + for (ir.Variable declaration in node.positionalParameters) { _handleVariableDeclaration(declaration, parameterUsage); } - for (ir.VariableDeclaration declaration in node.namedParameters) { + for (ir.Variable declaration in node.namedParameters) { _handleVariableDeclaration(declaration, parameterUsage); } visitInContext( diff --git a/pkg/compiler/lib/src/ir/util.dart b/pkg/compiler/lib/src/ir/util.dart index f3b76c1ec3e..5e4eac64335 100644 --- a/pkg/compiler/lib/src/ir/util.dart +++ b/pkg/compiler/lib/src/ir/util.dart @@ -21,12 +21,12 @@ String nodeToDebugString(ir.Node node, [int textLength = 40]) { /// Comparator for the canonical order for named parameters. // TODO(johnniwinther): Remove this when named parameters are sorted in dill. -int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { +int namedOrdering(ir.Variable a, ir.Variable b) { return a.name!.compareTo(b.name!); } /// Comparator for the declaration order of parameters. -int nativeOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { +int nativeOrdering(ir.Variable a, ir.Variable b) { return a.fileOffset.compareTo(b.fileOffset); } diff --git a/pkg/compiler/lib/src/js_backend/field_analysis.dart b/pkg/compiler/lib/src/js_backend/field_analysis.dart index 87e3e72808a..bac30f27517 100644 --- a/pkg/compiler/lib/src/js_backend/field_analysis.dart +++ b/pkg/compiler/lib/src/js_backend/field_analysis.dart @@ -98,7 +98,7 @@ class KFieldAnalysis { if (constantValue != null && constantValue.isConstant) { initializerValue = Initializer.direct(constantValue); } else if (value is ir.VariableGet) { - ir.VariableDeclaration parameter = value.variable; + ir.Variable parameter = value.variable; int position = constructor.function.positionalParameters.indexOf( parameter, ); diff --git a/pkg/compiler/lib/src/js_model/closure.dart b/pkg/compiler/lib/src/js_model/closure.dart index 6dbebc65f83..9e42c21596e 100644 --- a/pkg/compiler/lib/src/js_model/closure.dart +++ b/pkg/compiler/lib/src/js_model/closure.dart @@ -413,7 +413,7 @@ class ClosureDataBuilder { List callMethods, ) { void processModel(MemberEntity member, ClosureScopeModel model) { - Map allBoxedVariables = _elementMap + Map allBoxedVariables = _elementMap .makeContextContainer(model.scopeInfo!, member); _scopeMap[member] = JsScopeInfo.from( allBoxedVariables, @@ -425,7 +425,7 @@ class ClosureDataBuilder { ir.Node node, KernelCapturedScope scope, ) { - Map boxedVariables = _elementMap + Map boxedVariables = _elementMap .makeContextContainer(scope, member); _updateScopeBasedOnRtiNeed(scope, rtiNeed, member); @@ -516,7 +516,7 @@ class ClosureDataBuilder { MemberEntity member, ir.FunctionNode node, KernelScopeInfo info, - Map boxedVariables, + Map boxedVariables, ClosureRtiNeed rtiNeed, { required bool createSignatureMethod, }) { @@ -552,14 +552,14 @@ class JsScopeInfo extends ScopeInfo { /// debugging data stream. static const String tag = 'scope-info'; - final Iterable _localsUsedInTryOrSync; + final Iterable _localsUsedInTryOrSync; Set? _localsUsedInTryOrSyncCache; @override final Local? thisLocal; - final Map _boxedVariables; + final Map _boxedVariables; Map? _boxedVariablesCache; @@ -582,10 +582,7 @@ class JsScopeInfo extends ScopeInfo { _boxedVariablesCache = const {}; } else { final cache = {}; - _boxedVariables.forEach(( - ir.VariableDeclaration node, - JContextField field, - ) { + _boxedVariables.forEach((ir.Variable node, JContextField field) { cache[localsMap.getLocalVariable(node)] = field; }); _boxedVariablesCache = cache; @@ -609,7 +606,7 @@ class JsScopeInfo extends ScopeInfo { _localsUsedInTryOrSyncCache = const {}; } else { _localsUsedInTryOrSyncCache = {}; - for (ir.VariableDeclaration node in _localsUsedInTryOrSync) { + for (ir.Variable node in _localsUsedInTryOrSync) { _localsUsedInTryOrSyncCache!.add(localsMap.getLocalVariable(node)); } } @@ -633,11 +630,11 @@ class JsScopeInfo extends ScopeInfo { factory JsScopeInfo.readFromDataSource(DataSourceReader source) { source.begin(tag); - Iterable localsUsedInTryOrSync = source - .readTreeNodes(); + Iterable localsUsedInTryOrSync = source + .readTreeNodes(); Local? thisLocal = source.readLocalOrNull(); - Map boxedVariables = source - .readTreeNodeMap( + Map boxedVariables = source + .readTreeNodeMap( () => source.readMember() as JContextField, ); source.end(tag); @@ -689,11 +686,11 @@ class JsCapturedScope extends JsScopeInfo implements CapturedScope { factory JsCapturedScope.readFromDataSource(DataSourceReader source) { source.begin(tag); - Iterable localsUsedInTryOrSync = source - .readTreeNodes(); + Iterable localsUsedInTryOrSync = source + .readTreeNodes(); Local? thisLocal = source.readLocalOrNull(); - Map boxedVariables = source - .readTreeNodeMap( + Map boxedVariables = source + .readTreeNodeMap( () => source.readMember() as JContextField, ); Local? context = source.readLocalOrNull(); @@ -723,7 +720,7 @@ class JsCapturedLoopScope extends JsCapturedScope implements CapturedLoopScope { /// debugging data stream. static const String tag = 'captured-loop-scope'; - final List _boxedLoopVariables; + final List _boxedLoopVariables; JsCapturedLoopScope.internal( super.localsUsedInTryOrSync, @@ -745,16 +742,15 @@ class JsCapturedLoopScope extends JsCapturedScope implements CapturedLoopScope { factory JsCapturedLoopScope.readFromDataSource(DataSourceReader source) { source.begin(tag); - Iterable localsUsedInTryOrSync = source - .readTreeNodes(); + Iterable localsUsedInTryOrSync = source + .readTreeNodes(); Local? thisLocal = source.readLocalOrNull(); - Map boxedVariables = source - .readTreeNodeMap( + Map boxedVariables = source + .readTreeNodeMap( () => source.readMember() as JContextField, ); Local? context = source.readLocalOrNull(); - List boxedLoopVariables = source - .readTreeNodes(); + List boxedLoopVariables = source.readTreeNodes(); source.end(tag); return JsCapturedLoopScope.internal( localsUsedInTryOrSync, @@ -780,7 +776,7 @@ class JsCapturedLoopScope extends JsCapturedScope implements CapturedLoopScope { @override List getBoxedLoopVariables(KernelToLocalsMap localsMap) { List locals = []; - for (ir.VariableDeclaration boxedLoopVariable in _boxedLoopVariables) { + for (ir.Variable boxedLoopVariable in _boxedLoopVariables) { locals.add(localsMap.getLocalVariable(boxedLoopVariable)); } return locals; @@ -806,12 +802,12 @@ class JsClosureClassInfo extends JsScopeInfo /// The local variable that defines this closure, if it is a local function /// declaration. - final ir.VariableDeclaration? _closureEntityVariable; + final ir.Variable? _closureEntityVariable; @override final JClass closureClassEntity; - final Map _variableToFieldMap; + final Map _variableToFieldMap; final Map _typeVariableToFieldMap; final Map _localToFieldMap; Map? _fieldToLocalsMap; @@ -833,7 +829,7 @@ class JsClosureClassInfo extends JsScopeInfo JsClosureClassInfo.fromScopeInfo( this.closureClassEntity, ir.FunctionNode closureSourceNode, - Map boxedVariables, + Map boxedVariables, KernelScopeInfo info, ClassEntity? enclosingClass, this._closureEntity, @@ -845,22 +841,22 @@ class JsClosureClassInfo extends JsScopeInfo factory JsClosureClassInfo.readFromDataSource(DataSourceReader source) { source.begin(tag); - Iterable localsUsedInTryOrSync = source - .readTreeNodes(); + Iterable localsUsedInTryOrSync = source + .readTreeNodes(); Local? thisLocal = source.readLocalOrNull(); - Map boxedVariables = source - .readTreeNodeMap( + Map boxedVariables = source + .readTreeNodeMap( () => source.readMember() as JContextField, ); JFunction callMethod = source.readMember() as JFunction; JSignatureMethod? signatureMethod = source.readMemberOrNull() as JSignatureMethod?; Local? closureEntity = source.readLocalOrNull(); - ir.VariableDeclaration? closureEntityVariable = - source.readTreeNodeOrNull() as ir.VariableDeclaration?; + ir.Variable? closureEntityVariable = + source.readTreeNodeOrNull() as ir.Variable?; JClass closureClassEntity = source.readClass() as JClass; - Map localToFieldMap = source - .readTreeNodeMap( + Map localToFieldMap = source + .readTreeNodeMap( () => source.readMember() as JField, ); Map typeVariableToFieldMap = source @@ -913,7 +909,7 @@ class JsClosureClassInfo extends JsScopeInfo _localToFieldMap[local] = field; } - void registerFieldForVariable(ir.VariableDeclaration node, JField field) { + void registerFieldForVariable(ir.Variable node, JField field) { assert(_fieldToLocalsMap == null); _variableToFieldMap[node] = field; } @@ -926,10 +922,7 @@ class JsClosureClassInfo extends JsScopeInfo _typeVariableToFieldMap[typeVariable] = field; } - void registerFieldForBoxedVariable( - ir.VariableDeclaration node, - JField field, - ) { + void registerFieldForBoxedVariable(ir.Variable node, JField field) { assert(_boxedVariablesCache == null); _boxedVariables[node] = field as JContextField; } @@ -937,7 +930,7 @@ class JsClosureClassInfo extends JsScopeInfo void _ensureFieldToLocalsMap(KernelToLocalsMap localsMap) { if (_fieldToLocalsMap == null) { _fieldToLocalsMap = {}; - _variableToFieldMap.forEach((ir.VariableDeclaration node, JField field) { + _variableToFieldMap.forEach((ir.Variable node, JField field) { _fieldToLocalsMap![field] = localsMap.getLocalVariable(node); }); _typeVariableToFieldMap.forEach(( @@ -1452,7 +1445,7 @@ class ClosureFieldData extends ClosureMemberData implements JFieldData { elementMap.coreTypes, sourceNode.enclosingLibrary.nonNullable, ); - } else if (sourceNode is ir.VariableDeclaration) { + } else if (sourceNode is ir.Variable) { type = sourceNode.type; } else if (sourceNode is ir.Field) { type = sourceNode.type; diff --git a/pkg/compiler/lib/src/js_model/element_map.dart b/pkg/compiler/lib/src/js_model/element_map.dart index 1258e9ed7d2..10ad66aa574 100644 --- a/pkg/compiler/lib/src/js_model/element_map.dart +++ b/pkg/compiler/lib/src/js_model/element_map.dart @@ -153,7 +153,7 @@ abstract class JsToElementMap { /// Make a mapping from closed-over variables to the context fields where they /// are stored. - Map makeContextContainer( + Map makeContextContainer( KernelScopeInfo info, MemberEntity member, ); @@ -291,7 +291,7 @@ abstract class KernelToLocalsMap { MemberEntity get currentMember; /// Returns the [Local] for [node]. - Local getLocalVariable(ir.VariableDeclaration node); + Local getLocalVariable(ir.Variable node); /// Returns the [Local] for the [typeVariable]. Local getLocalTypeVariableEntity(TypeVariableEntity typeVariable); @@ -599,7 +599,7 @@ void forEachOrderedParameterByFunctionNode( ir.FunctionNode node, ParameterStructure parameterStructure, void Function( - ir.VariableDeclaration parameter, { + ir.Variable parameter, { required bool isOptional, required bool isElided, }) @@ -611,7 +611,7 @@ void forEachOrderedParameterByFunctionNode( position < node.positionalParameters.length; position++ ) { - ir.VariableDeclaration variable = node.positionalParameters[position]; + ir.Variable variable = node.positionalParameters[position]; f( variable, isOptional: position >= parameterStructure.requiredPositionalParameters, @@ -623,13 +623,13 @@ void forEachOrderedParameterByFunctionNode( return; } - List namedParameters = node.namedParameters.toList(); + List namedParameters = node.namedParameters.toList(); if (useNativeOrdering) { namedParameters.sort(nativeOrdering); } else { namedParameters.sort(namedOrdering); } - for (ir.VariableDeclaration variable in namedParameters) { + for (ir.Variable variable in namedParameters) { f( variable, isOptional: true, @@ -641,12 +641,12 @@ void forEachOrderedParameterByFunctionNode( void forEachOrderedParameter( JsToElementMap elementMap, FunctionEntity function, - void Function(ir.VariableDeclaration parameter, {required bool isElided}) f, + void Function(ir.Variable parameter, {required bool isElided}) f, ) { ParameterStructure parameterStructure = function.parameterStructure; void handleParameter( - ir.VariableDeclaration parameter, { + ir.Variable parameter, { required bool isOptional, required bool isElided, }) { diff --git a/pkg/compiler/lib/src/js_model/element_map_impl.dart b/pkg/compiler/lib/src/js_model/element_map_impl.dart index ea03ebfefb9..1cd05262505 100644 --- a/pkg/compiler/lib/src/js_model/element_map_impl.dart +++ b/pkg/compiler/lib/src/js_model/element_map_impl.dart @@ -872,7 +872,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { List parameterTypes = []; List optionalParameterTypes = []; - DartType getParameterType(ir.VariableDeclaration variable) { + DartType getParameterType(ir.Variable variable) { // isCovariant implies this FunctionNode is a class Procedure. var isCovariant = variable.isCovariantByDeclaration || variable.isCovariantByClass; @@ -882,7 +882,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { ); } - for (ir.VariableDeclaration variable in node.positionalParameters) { + for (ir.Variable variable in node.positionalParameters) { if (parameterTypes.length == node.requiredParameterCount) { optionalParameterTypes.add(getParameterType(variable)); } else { @@ -892,10 +892,9 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { var namedParameters = []; var requiredNamedParameters = {}; List namedParameterTypes = []; - List sortedNamedParameters = - node.namedParameters.toList() - ..sort((a, b) => a.name!.compareTo(b.name!)); - for (ir.VariableDeclaration variable in sortedNamedParameters) { + List sortedNamedParameters = node.namedParameters.toList() + ..sort((a, b) => a.name!.compareTo(b.name!)); + for (ir.Variable variable in sortedNamedParameters) { namedParameters.add(variable.name!); namedParameterTypes.add(getParameterType(variable)); if (variable.isRequired) { @@ -1714,7 +1713,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { JContextField _constructContextFieldEntry( InterfaceType? memberThisType, - ir.VariableDeclaration variable, + ir.Variable variable, BoxLocal boxLocal, Map memberMap, ) { @@ -1743,11 +1742,11 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { /// are accessed in different scopes. This function creates the container /// and returns a map of locals to the corresponding records created. @override - Map makeContextContainer( + Map makeContextContainer( KernelScopeInfo info, MemberEntity member, ) { - Map boxedFields = {}; + Map boxedFields = {}; if (info.boxedVariables.isNotEmpty) { NodeBox box = info.capturedVariablesAccessor!; @@ -1772,7 +1771,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { InterfaceType? memberThisType = member.enclosingClass != null ? elementEnvironment.getThisType(member.enclosingClass!) : null; - for (ir.VariableDeclaration variable in info.boxedVariables) { + for (ir.Variable variable in info.boxedVariables) { boxedFields[variable] = _constructContextFieldEntry( memberThisType, variable, @@ -1813,7 +1812,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { MemberEntity member, ir.FunctionNode node, JLibrary enclosingLibrary, - Map contextFieldsVisibleInScope, + Map contextFieldsVisibleInScope, KernelScopeInfo info, InterfaceType supertype, { required bool createSignatureMethod, @@ -1852,7 +1851,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { classes.register(classEntity, closureData, ClosureClassEnv(memberMap)); Local? closureEntity; - ir.VariableDeclaration? closureEntityNode; + ir.Variable? closureEntityNode; if (node.parent is ir.FunctionDeclaration) { final parent = node.parent as ir.FunctionDeclaration; closureEntityNode = parent.variable; @@ -1881,7 +1880,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { JsClosureClassInfo closureClassInfo = JsClosureClassInfo.fromScopeInfo( classEntity, node, - {}, + {}, info, member.enclosingClass, closureEntity, @@ -1928,7 +1927,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { MemberEntity member, InterfaceType? memberThisType, KernelScopeInfo info, - Map contextFieldsVisibleInScope, + Map contextFieldsVisibleInScope, Map memberMap, ) { // TODO(efortuna): Limit field number usage to when we need to distinguish @@ -1942,7 +1941,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { // TODO(redemption): Merge this loop and the following. for (ir.Node variable in info.freeVariables) { - if (variable is ir.VariableDeclaration) { + if (variable is ir.Variable) { if (contextFieldsVisibleInScope.containsKey(variable)) { bool constructedField = _constructClosureFieldForRecord( variable, @@ -1979,7 +1978,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { for (ir.Node variable in info.freeVariables) { // Make a corresponding field entity in this closure class for the // free variables in the KernelScopeInfo.freeVariable. - if (variable is ir.VariableDeclaration) { + if (variable is ir.Variable) { if (!contextFieldsVisibleInScope.containsKey(variable)) { closureClassInfo.registerFieldForVariable( variable, @@ -2036,12 +2035,12 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { /// locals they contain may be). Returns `true` if we constructed a new field /// in the closure class. bool _constructClosureFieldForRecord( - ir.VariableDeclaration capturedLocal, + ir.Variable capturedLocal, JsClosureClassInfo closureClassInfo, InterfaceType? memberThisType, Map memberMap, ir.TreeNode sourceNode, - Map contextFieldsVisibleInScope, + Map contextFieldsVisibleInScope, int fieldNumber, ) { JContextField contextField = contextFieldsVisibleInScope[capturedLocal]!; diff --git a/pkg/compiler/lib/src/js_model/env.dart b/pkg/compiler/lib/src/js_model/env.dart index 0f082b451ee..826878e9a3d 100644 --- a/pkg/compiler/lib/src/js_model/env.dart +++ b/pkg/compiler/lib/src/js_model/env.dart @@ -744,10 +744,7 @@ mixin FunctionDataForEachParameterMixin implements FunctionData { void Function(DartType type, String? name, ConstantValue? defaultValue) f, { bool isNative = false, }) { - void handleParameter( - ir.VariableDeclaration parameter, { - bool isOptional = true, - }) { + void handleParameter(ir.Variable parameter, {bool isOptional = true}) { DartType type = elementMap.getDartType(parameter.type); String? name = parameter.name; ConstantValue? defaultValue; @@ -764,7 +761,7 @@ mixin FunctionDataForEachParameterMixin implements FunctionData { } forEachOrderedParameterByFunctionNode(functionNode, parameterStructure, ( - ir.VariableDeclaration parameter, { + ir.Variable parameter, { required bool isOptional, required bool isElided, }) { diff --git a/pkg/compiler/lib/src/js_model/js_world_builder.dart b/pkg/compiler/lib/src/js_model/js_world_builder.dart index 4aabebb012a..5a48033e86a 100644 --- a/pkg/compiler/lib/src/js_model/js_world_builder.dart +++ b/pkg/compiler/lib/src/js_model/js_world_builder.dart @@ -403,7 +403,7 @@ class JClosedWorldBuilder { MemberEntity member, ir.FunctionNode originalClosureFunctionNode, JLibrary enclosingLibrary, - Map boxedVariables, + Map boxedVariables, KernelScopeInfo info, { required bool createSignatureMethod, }) { diff --git a/pkg/compiler/lib/src/js_model/locals.dart b/pkg/compiler/lib/src/js_model/locals.dart index 871fe705e3b..91b4973d76d 100644 --- a/pkg/compiler/lib/src/js_model/locals.dart +++ b/pkg/compiler/lib/src/js_model/locals.dart @@ -111,7 +111,7 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap { late final MemberEntity _currentMember; final EntityDataMap _locals = EntityDataMap(); - Map? _variableMap; + Map? _variableMap; Map? _jumpTargetMap; Iterable? _breaksAsContinue; @@ -126,7 +126,7 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap { final variableMap = _variableMap = {}; for (int i = 0; i < localsCount; i++) { final local = source.readLocal() as JLocal; - final node = source.readTreeNode() as ir.VariableDeclaration; + final node = source.readTreeNode() as ir.Variable; LocalData data = LocalData(node); _locals.register(local, data); variableMap[node] = local; @@ -264,7 +264,7 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap { } @override - Local getLocalVariable(ir.VariableDeclaration node) { + Local getLocalVariable(ir.Variable node) { final variableMap = _variableMap ??= {}; return variableMap.putIfAbsent(node, () { JLocal local = JLocal( @@ -686,7 +686,7 @@ class JLocal with EntityMapKey implements Local { } class LocalData { - final ir.VariableDeclaration node; + final ir.Variable node; DartType? _type; @@ -709,7 +709,7 @@ void forEachOrderedParameterAsLocal( ) { KernelToLocalsMap localsMap = globalLocalsMap.getLocalsMap(function); forEachOrderedParameter(elementMap, function, ( - ir.VariableDeclaration variable, { + ir.Variable variable, { required bool isElided, }) { f(localsMap.getLocalVariable(variable), isElided: isElided); diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart index 2796186c722..8c4f4ee2b9e 100644 --- a/pkg/compiler/lib/src/kernel/element_map_impl.dart +++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart @@ -571,7 +571,7 @@ class KernelToElementMap implements IrToElementMap { List parameterTypes = []; List optionalParameterTypes = []; - DartType getParameterType(ir.VariableDeclaration variable) { + DartType getParameterType(ir.Variable variable) { // isCovariant implies this FunctionNode is a class Procedure. var isCovariant = variable.isCovariantByDeclaration || variable.isCovariantByClass; @@ -581,7 +581,7 @@ class KernelToElementMap implements IrToElementMap { ); } - for (ir.VariableDeclaration variable in node.positionalParameters) { + for (ir.Variable variable in node.positionalParameters) { if (parameterTypes.length == node.requiredParameterCount) { optionalParameterTypes.add(getParameterType(variable)); } else { @@ -591,10 +591,9 @@ class KernelToElementMap implements IrToElementMap { List namedParameters = []; Set requiredNamedParameters = {}; List namedParameterTypes = []; - List sortedNamedParameters = - node.namedParameters.toList() - ..sort((a, b) => a.name!.compareTo(b.name!)); - for (ir.VariableDeclaration variable in sortedNamedParameters) { + List sortedNamedParameters = node.namedParameters.toList() + ..sort((a, b) => a.name!.compareTo(b.name!)); + for (ir.Variable variable in sortedNamedParameters) { namedParameters.add(variable.name!); namedParameterTypes.add(getParameterType(variable)); if (variable.isRequired) { @@ -903,9 +902,8 @@ class KernelToElementMap implements IrToElementMap { int typeParameters = node.typeParameters.length; List namedParameters = []; Set requiredNamedParameters = {}; - List sortedNamedParameters = - node.namedParameters.toList() - ..sort((a, b) => a.name!.compareTo(b.name!)); + List sortedNamedParameters = node.namedParameters.toList() + ..sort((a, b) => a.name!.compareTo(b.name!)); for (var variable in sortedNamedParameters) { namedParameters.add(variable.name!); if (variable.isRequired) { diff --git a/pkg/compiler/lib/src/kernel/env.dart b/pkg/compiler/lib/src/kernel/env.dart index a471ce89217..59d671534ac 100644 --- a/pkg/compiler/lib/src/kernel/env.dart +++ b/pkg/compiler/lib/src/kernel/env.dart @@ -516,10 +516,7 @@ class KFunctionData extends KMemberData { JsToElementMap elementMap, void Function(DartType type, String? name, ConstantValue? defaultValue) f, ) { - void handleParameter( - ir.VariableDeclaration parameter, { - bool isOptional = true, - }) { + void handleParameter(ir.Variable parameter, {bool isOptional = true}) { DartType type = elementMap.getDartType(parameter.type); String? name = parameter.name; ConstantValue? defaultValue; diff --git a/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart b/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart index e9d73972003..4d8109adcd2 100644 --- a/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart +++ b/pkg/compiler/lib/src/kernel/no_such_method_resolver.dart @@ -26,8 +26,7 @@ class NoSuchMethodResolver { bool hasForwardingSyntax(JFunction method) { ir.Procedure node = elementMap.lookupProcedure(method); if (node.function.positionalParameters.isEmpty) return false; - ir.VariableDeclaration firstParameter = - node.function.positionalParameters.first; + ir.Variable firstParameter = node.function.positionalParameters.first; ir.Statement? body = node.function.body; ir.Expression? expr; if (body is ir.Block && body.statements.isNotEmpty) { diff --git a/pkg/compiler/lib/src/kernel/transformations/global/constant_transformer.dart b/pkg/compiler/lib/src/kernel/transformations/global/constant_transformer.dart index 078e4ffaa02..46b1a9bdfac 100644 --- a/pkg/compiler/lib/src/kernel/transformations/global/constant_transformer.dart +++ b/pkg/compiler/lib/src/kernel/transformations/global/constant_transformer.dart @@ -69,7 +69,7 @@ class ConstantTransformer extends Transformer { node.value = newInitializer; newInitializer.parent = node; } else if (newInitializer is VariableGet) { - VariableDeclaration parameter = newInitializer.variable; + Variable parameter = newInitializer.variable; final parameterInitializer = parameter.initializer; if (parameterInitializer != null) { Expression newParameterInitializer = _evaluateAndWrapOrNode( diff --git a/pkg/compiler/lib/src/kernel/transformations/modular/late_lowering.dart b/pkg/compiler/lib/src/kernel/transformations/modular/late_lowering.dart index 25c23c5dcc7..12d292cc50a 100644 --- a/pkg/compiler/lib/src/kernel/transformations/modular/late_lowering.dart +++ b/pkg/compiler/lib/src/kernel/transformations/modular/late_lowering.dart @@ -62,8 +62,7 @@ class LateLowering { // Each map contains the mapping from late local variables to cells for a // given function scope. All late local variables are lowered to cells. - final List?> _variableCells = - []; + final List?> _variableCells = []; // Uninitialized late static fields are lowered to cells. final Map _fieldCells = {}; @@ -89,12 +88,12 @@ class LateLowering { Nullability get nonNullable => _contextMember!.enclosingLibrary.nonNullable; - bool _shouldLowerVariable(VariableDeclaration variable) => variable.isLate; + bool _shouldLowerVariable(Variable variable) => variable.isLate; - bool _shouldLowerUninitializedVariable(VariableDeclaration variable) => + bool _shouldLowerUninitializedVariable(Variable variable) => _shouldLowerVariable(variable) && variable.initializer == null; - bool _shouldLowerInitializedVariable(VariableDeclaration variable) => + bool _shouldLowerInitializedVariable(Variable variable) => _shouldLowerVariable(variable) && variable.initializer != null; bool _shouldLowerStaticField(Field field) => @@ -227,7 +226,7 @@ class LateLowering { _variableCells.removeLast(); } - VariableDeclaration? _lookupVariableCell(VariableDeclaration variable) { + Variable? _lookupVariableCell(Variable variable) { assert(_shouldLowerVariable(variable)); for (final scope in _variableCells) { if (scope == null) continue; @@ -237,16 +236,13 @@ class LateLowering { return null; } - VariableDeclaration _addToCurrentScope( - VariableDeclaration variable, - VariableDeclaration cell, - ) { + Variable _addToCurrentScope(Variable variable, Variable cell) { assert(_shouldLowerVariable(variable)); assert(_lookupVariableCell(variable) == null); return (_variableCells.last ??= {})[variable] = cell; } - VariableDeclaration _variableCell(VariableDeclaration variable) { + Variable _variableCell(Variable variable) { assert(_shouldLowerVariable(variable)); final cell = _lookupVariableCell(variable); if (cell != null) return cell; @@ -255,11 +251,11 @@ class LateLowering { : _initializedVariableCell(variable); } - VariableDeclaration _uninitializedVariableCell(VariableDeclaration variable) { + Variable _uninitializedVariableCell(Variable variable) { assert(_shouldLowerUninitializedVariable(variable)); int fileOffset = variable.fileOffset; String? name = variable.name; - final cell = VariableDeclaration( + final cell = Variable( name, initializer: _callCellConstructor( _nameLiteral(name, fileOffset), @@ -285,11 +281,11 @@ class LateLowering { return FunctionExpression(closure)..fileOffset = fileOffset; } - VariableDeclaration _initializedVariableCell(VariableDeclaration variable) { + Variable _initializedVariableCell(Variable variable) { assert(_shouldLowerInitializedVariable(variable)); int fileOffset = variable.fileOffset; String? name = variable.name; - final cell = VariableDeclaration( + final cell = Variable( name, initializer: _callInitializedCellConstructor( _nameLiteral(name, fileOffset), @@ -304,7 +300,7 @@ class LateLowering { } TreeNode transformVariableDeclaration( - VariableDeclaration variable, + Variable variable, Member? contextMember, ) { _contextMember = contextMember; @@ -318,7 +314,7 @@ class LateLowering { return _variableCell(variable); } - VariableGet _variableCellRead(VariableDeclaration variable, int fileOffset) { + VariableGet _variableCellRead(Variable variable, int fileOffset) { assert(_shouldLowerVariable(variable)); return VariableGet(_variableCell(variable))..fileOffset = fileOffset; } @@ -326,7 +322,7 @@ class LateLowering { TreeNode transformVariableGet(VariableGet node, Member contextMember) { _contextMember = contextMember; - VariableDeclaration variable = node.variable; + Variable variable = node.variable; if (!_shouldLowerVariable(variable)) return node; int fileOffset = node.fileOffset; @@ -345,7 +341,7 @@ class LateLowering { TreeNode transformVariableSet(VariableSet node, Member contextMember) { _contextMember = contextMember; - VariableDeclaration variable = node.variable; + Variable variable = node.variable; if (!_shouldLowerVariable(variable)) return node; int fileOffset = node.fileOffset; @@ -418,11 +414,8 @@ class LateLowering { isExtensionTypeMember: field.isExtensionTypeMember, )..fileOffset = fileOffset; - VariableDeclaration setterValue = VariableDeclaration( - 'value', - type: type, - isSynthesized: true, - )..fileOffset = fileOffset; + Variable setterValue = Variable('value', type: type, isSynthesized: true) + ..fileOffset = fileOffset; VariableGet setterValueRead() => VariableGet(setterValue)..fileOffset = fileOffset; @@ -587,14 +580,14 @@ class LateLowering { // } // return value; // } - VariableDeclaration value = VariableDeclaration( + Variable value = Variable( 'value', initializer: fieldRead(), type: type, isSynthesized: true, )..fileOffset = fileOffset; VariableGet valueRead() => VariableGet(value)..fileOffset = fileOffset; - VariableDeclaration result = VariableDeclaration( + Variable result = Variable( 'result', initializer: initializer, type: type, @@ -645,7 +638,7 @@ class LateLowering { // // This lowering avoids generating an extra narrowing node in inference, // but the generated code is worse due to poor register allocation. - VariableDeclaration value = VariableDeclaration( + Variable value = Variable( 'value', initializer: fieldRead(), type: type, @@ -686,11 +679,8 @@ class LateLowering { } enclosingClass.addProcedure(getter); - VariableDeclaration setterValue = VariableDeclaration( - 'value', - type: type, - isSynthesized: true, - )..fileOffset = fileOffset; + Variable setterValue = Variable('value', type: type, isSynthesized: true) + ..fileOffset = fileOffset; VariableGet setterValueRead() => VariableGet(setterValue)..fileOffset = fileOffset; diff --git a/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart b/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart index f85cb9ae0ef..73a8689ac64 100644 --- a/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart +++ b/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart @@ -97,11 +97,11 @@ class ListFactorySpecializer extends BaseSpecializer { // If the length is a constant, use the constant directly so that the // inferrer can see the constant length. int? lengthConstant = _getLengthArgument(args); - VariableDeclaration? lengthVariable; + Variable? lengthVariable; Expression getLength() { if (lengthConstant != null) return IntLiteral(lengthConstant); - lengthVariable ??= VariableDeclaration( + lengthVariable ??= Variable( '_length', initializer: length, isFinal: true, @@ -116,7 +116,7 @@ class ListFactorySpecializer extends BaseSpecializer { Arguments([getLength()], types: args.types), )..fileOffset = node.fileOffset; - final listVariable = VariableDeclaration( + final listVariable = Variable( _listNameFromContext(node), initializer: allocation, isFinal: true, @@ -126,7 +126,7 @@ class ListFactorySpecializer extends BaseSpecializer { isSynthesized: true, )..fileOffset = node.fileOffset; - final indexVariable = VariableDeclaration( + final indexVariable = Variable( _indexNameFromContext(generator), initializer: IntLiteral(0), type: intType, @@ -181,8 +181,8 @@ class ListFactorySpecializer extends BaseSpecializer { Statement _loopBody( int constructorFileOffset, - VariableDeclaration listVariable, - VariableDeclaration indexVariable, + Variable listVariable, + Variable indexVariable, FunctionExpression generator, ) { final inliner = ListGenerateLoopBodyInliner( @@ -241,7 +241,7 @@ class ListFactorySpecializer extends BaseSpecializer { /// use one JavaScript variable with the source name for 'both' variables. String? _listNameFromContext(Expression node) { TreeNode? parent = node.parent; - if (parent is VariableDeclaration) return parent.name; + if (parent is Variable) return parent.name; return '_list'; } @@ -259,10 +259,10 @@ class ListGenerateLoopBodyInliner extends CloneVisitorNotMembers { /// Offset for the constructor call, used for all nodes that carry the value of the list. final int constructorFileOffset; - final VariableDeclaration listVariable; + final Variable listVariable; final FunctionNode function; - late final VariableDeclaration argument; - late final VariableDeclaration parameter; + late final Variable argument; + late final Variable parameter; int functionNestingLevel = 0; ListGenerateLoopBodyInliner( @@ -300,7 +300,7 @@ class ListGenerateLoopBodyInliner extends CloneVisitorNotMembers { return false; } - void bind(VariableDeclaration argument) { + void bind(Variable argument) { // The [argument] is the loop index variable. In the general case this needs // to be copied to a variable for the closure parameter as that is a // separate location that may be mutated. In the usual case the closure @@ -308,7 +308,7 @@ class ListGenerateLoopBodyInliner extends CloneVisitorNotMembers { // argument to help dart2js allocate both locations to the same JavaScript // variable. The argument is usually named after the closure parameter. final closureParameter = function.positionalParameters.single; - parameter = VariableDeclaration( + parameter = Variable( argument.name, initializer: VariableGet(argument)..fileOffset = argument.fileOffset, type: closureParameter.type, @@ -380,8 +380,8 @@ class ListGenerateLoopBodyInliner extends CloneVisitorNotMembers { } @override - VariableDeclaration getVariableClone(VariableDeclaration variable) { - VariableDeclaration? clone = super.getVariableClone(variable); + Variable getVariableClone(Variable variable) { + Variable? clone = super.getVariableClone(variable); return clone ?? variable; } } diff --git a/pkg/compiler/lib/src/kernel/transformations/modular/transform.dart b/pkg/compiler/lib/src/kernel/transformations/modular/transform.dart index 952b0229918..4100b5d4927 100644 --- a/pkg/compiler/lib/src/kernel/transformations/modular/transform.dart +++ b/pkg/compiler/lib/src/kernel/transformations/modular/transform.dart @@ -77,7 +77,7 @@ class _ModularTransformer extends Transformer { } @override - TreeNode defaultVariableDeclaration(VariableDeclaration node) { + TreeNode defaultVariable(Variable node) { node.transformChildren(this); return _lateLowering.transformVariableDeclaration(node, _currentMember); } diff --git a/pkg/compiler/lib/src/serialization/node_indexer.dart b/pkg/compiler/lib/src/serialization/node_indexer.dart index 15ae06855c4..8531c2c0b2b 100644 --- a/pkg/compiler/lib/src/serialization/node_indexer.dart +++ b/pkg/compiler/lib/src/serialization/node_indexer.dart @@ -44,11 +44,11 @@ class TreeNodeIndexerVisitor extends ir.VisitorDefault } @override - void defaultVariableDeclaration(ir.VariableDeclaration node) { + void defaultVariable(ir.Variable node) { if (node.parent is! ir.FunctionDeclaration) { registerNode(node); } - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override diff --git a/pkg/compiler/lib/src/serialization/sink.dart b/pkg/compiler/lib/src/serialization/sink.dart index fdb257cb7b3..8eb1c745a2a 100644 --- a/pkg/compiler/lib/src/serialization/sink.dart +++ b/pkg/compiler/lib/src/serialization/sink.dart @@ -482,8 +482,7 @@ class DataSinkWriter { } else if (value is ir.Member) { _sinkWriter.writeEnum(_TreeNodeKind.member); _writeMemberNode(value); - } else if (value is ir.VariableDeclaration && - value.parent is ir.FunctionDeclaration) { + } else if (value is ir.Variable && value.parent is ir.FunctionDeclaration) { _sinkWriter.writeEnum(_TreeNodeKind.functionDeclarationVariable); _writeTreeNode(value.parent!, memberData); } else if (value is ir.FunctionNode) { diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart index 4a5e23f672a..27b55938f7c 100644 --- a/pkg/compiler/lib/src/ssa/builder.dart +++ b/pkg/compiler/lib/src/ssa/builder.dart @@ -82,7 +82,7 @@ class StackFrame { final AsyncMarker asyncMarker; final KernelToLocalsMap localsMap; // [ir.Let] and [ir.LocalInitializer] bindings. - final Map letBindings; + final Map letBindings; final KernelToTypeInferenceMap typeInferenceMap; final SourceInformationBuilder sourceInformationBuilder; final ir.StaticTypeContext? staticTypeContext; @@ -211,8 +211,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault KernelToLocalsMap get _localsMap => _currentFrame!.localsMap; - Map get _letBindings => - _currentFrame!.letBindings; + Map get _letBindings => _currentFrame!.letBindings; JCommonElements get _commonElements => _elementMap.commonElements; @@ -627,7 +626,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault // were generated by the codegen enqueuer. In practice even in huge programs // there are only very small number of constants created here that are not // actually used. - void registerDefaultValue(ir.VariableDeclaration node) { + void registerDefaultValue(ir.Variable node) { final constantValue = _elementMap.getConstantValue( node.initializer, implicitNull: true, @@ -942,10 +941,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault () { final constructorBody = _elementMap.getConstructorBody(body); - void handleParameter( - ir.VariableDeclaration node, { - required bool isElided, - }) { + void handleParameter(ir.Variable node, {required bool isElided}) { if (isElided) return; Local parameter = _localsMap.getLocalVariable(node); @@ -1195,7 +1191,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault } else if (initializer is ir.LocalInitializer) { // LocalInitializer is like a let-expression that is in scope for the // rest of the initializers. - ir.VariableDeclaration variable = initializer.variable; + ir.Variable variable = initializer.variable; assert(variable.isFinal); variable.initializer!.accept(this); HInstruction value = pop(); @@ -1242,7 +1238,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault // And add them to `builtArguments` in calling-convention order. function.namedParameters.toList() ..sort(namedOrdering) - ..forEach((ir.VariableDeclaration parameter) { + ..forEach((ir.Variable parameter) { var argument = namedArguments[parameter.name]; argument ??= _defaultValueForParameter(parameter); builtArguments.add(argument); @@ -1334,7 +1330,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault element, _sourceInformationBuilder.buildCall(initializer, initializer), () { - void handleParameter(ir.VariableDeclaration node) { + void handleParameter(ir.Variable node) { Local parameter = _localsMap.getLocalVariable(node); HInstruction argument = arguments[index++]; // Because we are inlining the initializer, we must update @@ -1969,7 +1965,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault ); bool nodeIsConstructorBody = definition.kind == MemberKind.constructorBody; - void handleParameter(ir.VariableDeclaration variable) { + void handleParameter(ir.Variable variable) { Local local = _localsMap.getLocalVariable(variable); if (nodeIsConstructorBody && _closureDataLookup @@ -2134,7 +2130,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault ); } - void handleParameter(ir.VariableDeclaration param) { + void handleParameter(ir.Variable param) { Local local = _localsMap.getLocalVariable(param); // Convert Dart function to JavaScript function. HInstruction argument = localsHandler.readLocal(local); @@ -2161,8 +2157,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault handleParameter(functionNode.positionalParameters[position]); } if (functionNode.namedParameters.isNotEmpty) { - List namedParameters = functionNode - .namedParameters + List namedParameters = functionNode.namedParameters // Filter elided parameters. .where( (p) => function.parameterStructure.namedParameters.contains(p.name), @@ -2268,11 +2263,11 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault required TargetChecks checks, }) { Map parameterMap = {}; - List elidedParameters = []; + List elidedParameters = []; Set elidedParameterSet = {}; if (functionNode != null) { void handleParameter( - ir.VariableDeclaration node, { + ir.Variable node, { required bool isOptional, required bool isElided, }) { @@ -2308,7 +2303,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault ir.Member? memberContextNode = _elementMap.getMemberContextNode(member); if (memberContextNode != null) { - for (ir.VariableDeclaration node in elidedParameters) { + for (ir.Variable node in elidedParameters) { Local local = _localsMap.getLocalVariable(node); localsHandler.updateLocal(local, _defaultValueForParameter(node)); } @@ -4644,7 +4639,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault @override void visitVariableGet(ir.VariableGet node) { - ir.VariableDeclaration variable = node.variable; + ir.Variable variable = node.variable; final letBinding = _letBindings[variable]; if (letBinding != null) { stack.add(letBinding); @@ -4753,11 +4748,11 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault @override void visitLegacyVariableStatement(ir.LegacyVariableStatement node) { - defaultVariableDeclaration(node.variable); + defaultVariable(node.variable); } @override - void defaultVariableDeclaration(ir.VariableDeclaration node) { + void defaultVariable(ir.Variable node) { Local local = _localsMap.getLocalVariable(node); if (node.initializer == null) { HInstruction initialValue = graph.addConstantNull(closedWorld); @@ -4783,7 +4778,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault } void _visitLocalSetter( - ir.VariableDeclaration variable, + ir.Variable variable, HInstruction value, SourceInformation? sourceInformation, ) { @@ -4806,7 +4801,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault @override void visitLet(ir.Let node) { - ir.VariableDeclaration variable = node.variable; + ir.Variable variable = node.variable; variable.initializer!.accept(this); HInstruction initializedValue = pop(); // TODO(sra): Apply inferred type information. @@ -4927,7 +4922,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault ), ); namedParameters.sort(nativeOrdering); - for (ir.VariableDeclaration parameter in namedParameters) { + for (ir.Variable parameter in namedParameters) { final value = namedValues[parameter.name]; values.add(value); } @@ -5005,8 +5000,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault List values = _visitPositionalArguments(arguments); while (values.length < parameterStructure.positionalParameters) { - ir.VariableDeclaration parameter = - target.positionalParameters[values.length]; + ir.Variable parameter = target.positionalParameters[values.length]; values.add(_defaultValueForParameter(parameter)); } @@ -5018,13 +5012,13 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault // TODO(sra): Ensure the stored order is canonical so we don't have to // sort. The old builder uses CallStructure.makeArgumentList which depends // on the old element model. - List namedParameters = + List namedParameters = target.namedParameters // Filter elided parameters. .where((p) => parameterStructure.namedParameters.contains(p.name)) .toList() ..sort(namedOrdering); - for (ir.VariableDeclaration parameter in namedParameters) { + for (ir.Variable parameter in namedParameters) { final value = namedValues[parameter.name]; if (value == null) { values.add(_defaultValueForParameter(parameter)); @@ -5059,7 +5053,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault } } - HInstruction _defaultValueForParameter(ir.VariableDeclaration parameter) { + HInstruction _defaultValueForParameter(ir.Variable parameter) { final constant = _elementMap.getConstantValue( parameter.initializer, implicitNull: true, @@ -7027,13 +7021,11 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault // TODO(johnniwinther): can we elide those parameters? This should be // consistent with what we do with instance methods. final procedure = node as ir.Procedure; - List namedParameters = procedure - .function - .namedParameters + List namedParameters = procedure.function.namedParameters .toList(); namedParameters.sort(nativeOrdering); - for (ir.VariableDeclaration variable in namedParameters) { + for (ir.Variable variable in namedParameters) { String parameterName = variable.name!; // TODO(jacobr): consider throwing if parameter names do not match // names of properties in the class. @@ -8362,7 +8354,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(function); forEachOrderedParameter(_elementMap, function, ( - ir.VariableDeclaration variable, { + ir.Variable variable, { required bool isElided, }) { Local local = localsMap.getLocalVariable(variable); @@ -8540,7 +8532,7 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(function); forEachOrderedParameter(_elementMap, function, ( - ir.VariableDeclaration variable, { + ir.Variable variable, { required bool isElided, }) { Local parameter = localsMap.getLocalVariable(variable); @@ -9698,7 +9690,7 @@ class InlineWeeder extends ir.VisitorDefault with ir.VisitorVoidMixin { } @override - void defaultVariableDeclaration(ir.VariableDeclaration node) { + void defaultVariable(ir.Variable node) { registerRegularNode(); skipReductiveNodes(() { visitList(node.annotations); diff --git a/pkg/compiler/test/closure/closure_test.dart b/pkg/compiler/test/closure/closure_test.dart index 656b9c47fa2..72a87f8732c 100644 --- a/pkg/compiler/test/closure/closure_test.dart +++ b/pkg/compiler/test/closure/closure_test.dart @@ -141,7 +141,7 @@ class ClosureIrChecker extends IrDataExtractor { @override String? computeNodeValue(Id id, ir.Node node) { - if (node is ir.VariableDeclaration) { + if (node is ir.Variable) { Local local = _localsMap.getLocalVariable(node); return computeLocalValue(local); } else if (node is ir.FunctionDeclaration) { diff --git a/pkg/compiler/test/inference/inference_test_helper.dart b/pkg/compiler/test/inference/inference_test_helper.dart index 740aa3d91c6..2d805f8d75e 100644 --- a/pkg/compiler/test/inference/inference_test_helper.dart +++ b/pkg/compiler/test/inference/inference_test_helper.dart @@ -143,7 +143,7 @@ class TypeMaskIrComputer extends IrDataExtractor { @override String? computeNodeValue(Id id, ir.TreeNode node) { - if (node is ir.VariableDeclaration && node.parent is ir.FunctionNode) { + if (node is ir.Variable && node.parent is ir.FunctionNode) { Local parameter = _localsMap.getLocalVariable(node); return getParameterValue(parameter, null); } else if (node is ir.FunctionExpression || diff --git a/pkg/dart2bytecode/lib/bytecode_generator.dart b/pkg/dart2bytecode/lib/bytecode_generator.dart index 0466ac6503f..27a938241b9 100644 --- a/pkg/dart2bytecode/lib/bytecode_generator.dart +++ b/pkg/dart2bytecode/lib/bytecode_generator.dart @@ -482,10 +482,10 @@ class BytecodeGenerator extends RecursiveVisitor { FunctionNode function, ) { final parameterNodeLists = >[]; - for (VariableDeclaration variable in function.positionalParameters) { + for (Variable variable in function.positionalParameters) { parameterNodeLists.add(variable.annotations); } - for (VariableDeclaration variable in function.namedParameters) { + for (Variable variable in function.namedParameters) { parameterNodeLists.add(variable.annotations); } @@ -829,7 +829,7 @@ class BytecodeGenerator extends RecursiveVisitor { ); } - ParameterDeclaration getParameterDeclaration(VariableDeclaration variable) { + ParameterDeclaration getParameterDeclaration(Variable variable) { final name = variable.name!; final lib = name.startsWith('_') ? enclosingMember!.enclosingLibrary : null; final nameHandle = objectTable.getNameHandle(lib, name); @@ -1651,7 +1651,7 @@ class BytecodeGenerator extends RecursiveVisitor { } void _genPushContextForVariable( - VariableDeclaration variable, { + Variable variable, { int? currentContextLevel, }) { currentContextLevel ??= locals.currentContextLevel; @@ -1666,13 +1666,13 @@ class BytecodeGenerator extends RecursiveVisitor { } } - void _genPushContextIfCaptured(VariableDeclaration variable) { + void _genPushContextIfCaptured(Variable variable) { if (locals.isCaptured(variable)) { _genPushContextForVariable(variable); } } - void _genLoadVar(VariableDeclaration v, {int? currentContextLevel}) { + void _genLoadVar(Variable v, {int? currentContextLevel}) { if (locals.isCaptured(v)) { _genPushContextForVariable(v, currentContextLevel: currentContextLevel); asm.emitLoadContextVar( @@ -1692,7 +1692,7 @@ class BytecodeGenerator extends RecursiveVisitor { // Stores value into variable. // If variable is captured, context should be pushed before value. - void _genStoreVar(VariableDeclaration variable) { + void _genStoreVar(Variable variable) { if (locals.isCaptured(variable)) { asm.emitStoreContextVar( locals.getVarContextId(variable), @@ -1787,7 +1787,7 @@ class BytecodeGenerator extends RecursiveVisitor { asm.currentSourcePosition = savedSourcePosition; } - int _getDefaultParamConstIndex(VariableDeclaration param) { + int _getDefaultParamConstIndex(Variable param) { final paramInitializer = param.initializer; if (paramInitializer == null) { return cp.addObjectRef(null); @@ -2398,7 +2398,7 @@ class BytecodeGenerator extends RecursiveVisitor { asm.emitSourcePosition(); } - void _copyParamIfCaptured(VariableDeclaration variable) { + void _copyParamIfCaptured(Variable variable) { if (locals.isCaptured(variable)) { if (options.emitLocalVarInfo) { _declareLocalVariable(variable, enclosingFunction!.fileOffset); @@ -2411,10 +2411,7 @@ class BytecodeGenerator extends RecursiveVisitor { } } - void _declareLocalVariable( - VariableDeclaration variable, - int initializedPosition, - ) { + void _declareLocalVariable(Variable variable, int initializedPosition) { bool isCaptured = locals.isCaptured(variable); // Don't add initializing formals or wildcards. if (variable.isInitializingFormal || @@ -2515,7 +2512,7 @@ class BytecodeGenerator extends RecursiveVisitor { /// If member being compiled is a forwarding stub, then returns parameter /// types to check for the forwarding stub target. - Map? _getForwardingParameterTypes( + Map? _getForwardingParameterTypes( FunctionNode function, Member? forwardingTarget, Substitution? forwardingSubstitution, @@ -2526,7 +2523,7 @@ class BytecodeGenerator extends RecursiveVisitor { if (forwardingTarget is Field) { if ((enclosingMember as Procedure).isGetter) { - return const {}; + return const {}; } else { // Forwarding stub for a covariant field setter. assert((enclosingMember as Procedure).isSetter); @@ -2535,14 +2532,14 @@ class BytecodeGenerator extends RecursiveVisitor { function.positionalParameters.length == 1 && function.namedParameters.isEmpty, ); - return { + return { function.positionalParameters.single: forwardingSubstitution! .substituteType(forwardingTarget.type), }; } } - final forwardingParams = {}; + final forwardingParams = {}; for (int i = 0; i < function.positionalParameters.length; ++i) { DartType type = forwardingSubstitution!.substituteType( forwardingTarget.function!.positionalParameters[i].type, @@ -2550,9 +2547,7 @@ class BytecodeGenerator extends RecursiveVisitor { forwardingParams[function.positionalParameters[i]] = type; } for (var hostParam in function.namedParameters) { - VariableDeclaration targetParam = forwardingTarget - .function! - .namedParameters + Variable targetParam = forwardingTarget.function!.namedParameters .firstWhere((p) => p.name == hostParam.name); forwardingParams[hostParam] = forwardingSubstitution!.substituteType( targetParam.type, @@ -2650,8 +2645,8 @@ class BytecodeGenerator extends RecursiveVisitor { /// Returns true if type of [param] should be checked. bool _parameterNeedsTypeCheck( - VariableDeclaration param, - Map? forwardingParameterTypes, + Variable param, + Map? forwardingParameterTypes, ) { if (canSkipTypeChecksForNonCovariantArguments && !param.isCovariantByDeclaration && @@ -2672,7 +2667,7 @@ class BytecodeGenerator extends RecursiveVisitor { bool _hasSkippableTypeChecks( FunctionNode function, Map? forwardingBounds, - Map? forwardingParamTypes, + Map? forwardingParamTypes, ) { for (var typeParam in function.typeParameters) { if (_typeParameterNeedsBoundCheck(typeParam, forwardingBounds)) { @@ -2724,8 +2719,8 @@ class BytecodeGenerator extends RecursiveVisitor { }; void _genArgumentTypeCheck( - VariableDeclaration variable, - Map? forwardingParameterTypes, + Variable variable, + Map? forwardingParameterTypes, ) { final DartType type = (forwardingParameterTypes != null) ? forwardingParameterTypes[variable]! @@ -4870,7 +4865,7 @@ class BytecodeGenerator extends RecursiveVisitor { finallyBlocks.remove(node); } - bool _skipVariableInitialization(VariableDeclaration v, bool isCaptured) { + bool _skipVariableInitialization(Variable 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. @@ -4888,7 +4883,7 @@ class BytecodeGenerator extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { _handleVariableInitialization(node); } @@ -4902,7 +4897,7 @@ class BytecodeGenerator extends RecursiveVisitor { _handleVariableInitialization(node.variable); } - void _handleVariableInitialization(VariableDeclaration node) { + void _handleVariableInitialization(Variable 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 f46f8ff4df1..785aae2b849 100644 --- a/pkg/dart2bytecode/lib/local_vars.dart +++ b/pkg/dart2bytecode/lib/local_vars.dart @@ -12,12 +12,12 @@ 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; - Map? _capturedStackTraceVars; - Map? _capturedIteratorVars; + Map? _capturedSavedContextVars; + Map? _capturedExceptionVars; + Map? _capturedStackTraceVars; + Map? _capturedIteratorVars; final BytecodeOptions options; final StaticTypeContext staticTypeContext; @@ -27,11 +27,11 @@ class LocalVariables { Frame? _currentFrameInternal; Frame get _currentFrame => _currentFrameInternal!; - VarDesc _getVarDesc(VariableDeclaration variable) => + VarDesc _getVarDesc(Variable variable) => _vars[variable] ?? (throw 'Variable descriptor is not created for $variable'); - int _getVarIndex(VariableDeclaration variable, bool isCaptured) { + int _getVarIndex(Variable variable, bool isCaptured) { final v = _getVarDesc(variable); if (v.isCaptured != isCaptured) { throw 'Mismatch in captured state of $variable'; @@ -39,20 +39,17 @@ class LocalVariables { return v.index ?? (throw 'Variable $variable is not allocated'); } - bool isCaptured(VariableDeclaration variable) => - _getVarDesc(variable).isCaptured; + bool isCaptured(Variable variable) => _getVarDesc(variable).isCaptured; - int getVarIndexInFrame(VariableDeclaration variable) => - _getVarIndex(variable, false); + int getVarIndexInFrame(Variable variable) => _getVarIndex(variable, false); - int getVarIndexInContext(VariableDeclaration variable) => - _getVarIndex(variable, true); + int getVarIndexInContext(Variable variable) => _getVarIndex(variable, true); - int getOriginalParamSlotIndex(VariableDeclaration variable) => + int getOriginalParamSlotIndex(Variable variable) => _getVarDesc(variable).originalParamSlotIndex ?? (throw 'Variable $variable does not have originalParamSlotIndex'); - int getParamIndexInFrame(VariableDeclaration variable) => isCaptured(variable) + int getParamIndexInFrame(Variable variable) => isCaptured(variable) ? getOriginalParamSlotIndex(variable) : getVarIndexInFrame(variable); @@ -72,13 +69,13 @@ class LocalVariables { _currentFrame.contextLevelAtEntry ?? (throw "Current frame is top level and it doesn't have a context at entry"); - int getContextLevelOfVar(VariableDeclaration variable) { + int getContextLevelOfVar(Variable variable) { final v = _getVarDesc(variable); assert(v.isCaptured); return v.scope.contextLevel!; } - int getVarContextId(VariableDeclaration variable) { + int getVarContextId(Variable variable) { final v = _getVarDesc(variable); assert(v.isCaptured); return v.scope.contextId!; @@ -111,7 +108,7 @@ class LocalVariables { (throw 'Suspend state variable is not declared in ${_currentFrame.function}'), ); - VariableDeclaration get functionTypeArgsVar => + Variable get functionTypeArgsVar => _currentFrame.functionTypeArgsVar ?? (throw 'FunctionTypeArgs variable is not declared in ${_currentFrame.function}'); @@ -120,25 +117,25 @@ class LocalVariables { bool get hasFunctionTypeArgsVar => _currentFrame.functionTypeArgsVar != null; - VariableDeclaration get receiverVar => + Variable get receiverVar => _currentFrame.receiverVar ?? (throw 'Receiver variable is not declared in ${_currentFrame.function}'); bool get hasCapturedReceiverVar => _currentFrame.capturedReceiverVar != null; - VariableDeclaration get capturedReceiverVar => + Variable get capturedReceiverVar => _currentFrame.capturedReceiverVar ?? (throw 'Captured receiver variable is not declared in ${_currentFrame.function}'); bool get hasReceiver => _currentFrame.receiverVar != null; - VariableDeclaration? capturedSavedContextVar(TreeNode node) => + Variable? capturedSavedContextVar(TreeNode node) => _capturedSavedContextVars?[node]; - VariableDeclaration? capturedExceptionVar(TreeNode node) => + Variable? capturedExceptionVar(TreeNode node) => _capturedExceptionVars?[node]; - VariableDeclaration? capturedStackTraceVar(TreeNode node) => + Variable? capturedStackTraceVar(TreeNode node) => _capturedStackTraceVars?[node]; - VariableDeclaration? capturedIteratorVar(ForInStatement node) => + Variable? capturedIteratorVar(ForInStatement node) => _capturedIteratorVars?[node]; int get frameSize => _currentFrame.frameSize; @@ -152,9 +149,9 @@ class LocalVariables { bool get isSuspendableFunction => _currentFrame.isSuspendableFunction; bool get makesCopyOfParameters => _currentFrame.makesCopyOfParameters; - List get originalNamedParameters => + List get originalNamedParameters => _currentFrame.originalNamedParameters; - List get sortedNamedParameters => + List get sortedNamedParameters => _currentFrame.sortedNamedParameters; LocalVariables(Member node, this.options, this.staticTypeContext) { @@ -192,7 +189,7 @@ class LocalVariables { } class VarDesc { - final VariableDeclaration declaration; + final Variable declaration; Scope scope; bool isCaptured = false; int? index; @@ -227,22 +224,22 @@ class Frame { final Frame? parent; late Scope topScope; - late List originalNamedParameters; - late List sortedNamedParameters; + late List originalNamedParameters; + late List sortedNamedParameters; int numParameters = 0; int numTypeArguments = 0; bool hasOptionalParameters = false; bool hasCapturedParameters = false; bool hasClosures = false; - VariableDeclaration? receiverVar; - VariableDeclaration? capturedReceiverVar; - VariableDeclaration? functionTypeArgsVar; - VariableDeclaration? closureVar; - VariableDeclaration? contextVar; - VariableDeclaration? scratchVar; - VariableDeclaration? returnVar; - VariableDeclaration? suspendStateVar; - Map? syntheticVars; + Variable? receiverVar; + Variable? capturedReceiverVar; + Variable? functionTypeArgsVar; + Variable? closureVar; + Variable? contextVar; + Variable? scratchVar; + Variable? returnVar; + Variable? suspendStateVar; + Map? syntheticVars; int frameSize = 0; List temporaries = []; int? contextLevelAtEntry; @@ -250,7 +247,7 @@ class Frame { Frame(this.function, this.parent); - VariableDeclaration getSyntheticVar(String name) { + Variable getSyntheticVar(String name) { final syntheticVars = this.syntheticVars; if (syntheticVars == null) { throw 'No synthetic variables declared in ${function}!'; @@ -308,12 +305,9 @@ class _ScopeBuilder extends RecursiveVisitor { _ScopeBuilder(this.locals); - List _sortNamedParameters(FunctionNode function) { + List _sortNamedParameters(FunctionNode function) { final params = function.namedParameters.toList(); - params.sort( - (VariableDeclaration a, VariableDeclaration b) => - a.name!.compareTo(b.name!), - ); + params.sort((Variable a, Variable b) => a.name!.compareTo(b.name!)); return params; } @@ -330,7 +324,7 @@ class _ScopeBuilder extends RecursiveVisitor { if (node is Field) { if (_hasReceiverParameter(node)) { final receiverVar = _currentFrame.receiverVar = - _findThisVariable(node) ?? VariableDeclaration('this'); + _findThisVariable(node) ?? Variable('this'); _declareVariable(receiverVar); } node.initializer?.accept(this); @@ -345,14 +339,13 @@ class _ScopeBuilder extends RecursiveVisitor { FunctionNode function = (node as dynamic).function; if (function.dartAsyncMarker != AsyncMarker.Sync) { - final suspendStateVar = _currentFrame.suspendStateVar = - VariableDeclaration(':suspend_state'); + final suspendStateVar = _currentFrame.suspendStateVar = Variable( + ':suspend_state', + ); _declareVariable(suspendStateVar); if (function.dartAsyncMarker != AsyncMarker.SyncStar) { - final returnVar = _currentFrame.returnVar = VariableDeclaration( - ':return', - ); + final returnVar = _currentFrame.returnVar = Variable(':return'); _declareVariable(returnVar); } } @@ -363,14 +356,14 @@ class _ScopeBuilder extends RecursiveVisitor { if (_currentFrame.numTypeArguments > 0) { final functionTypeArgsVar = _currentFrame.functionTypeArgsVar = - VariableDeclaration(':function_type_arguments_var') + Variable(':function_type_arguments_var') ..fileOffset = function.fileOffset; _declareVariable(functionTypeArgsVar); } if (_hasReceiverParameter(node)) { final receiverVar = _currentFrame.receiverVar = - _findThisVariable(node) ?? VariableDeclaration('this'); + _findThisVariable(node) ?? Variable('this'); _declareVariable(receiverVar); } else { final parentReceiverVar = _currentFrame.parent?.receiverVar; @@ -379,9 +372,7 @@ class _ScopeBuilder extends RecursiveVisitor { } } if (node is FunctionDeclaration || node is FunctionExpression) { - final closureVar = _currentFrame.closureVar = VariableDeclaration( - ':closure', - ); + final closureVar = _currentFrame.closureVar = Variable(':closure'); _declareVariable(closureVar); } @@ -407,13 +398,9 @@ class _ScopeBuilder extends RecursiveVisitor { if (node is FunctionDeclaration || node is FunctionExpression || _currentFrame.hasClosures) { - final contextVar = _currentFrame.contextVar = VariableDeclaration( - ':context', - ); + final contextVar = _currentFrame.contextVar = Variable(':context'); _declareVariable(contextVar); - final scratchVar = _currentFrame.scratchVar = VariableDeclaration( - ':scratch', - ); + final scratchVar = _currentFrame.scratchVar = Variable(':scratch'); _declareVariable(scratchVar); } @@ -421,8 +408,7 @@ class _ScopeBuilder extends RecursiveVisitor { if (locals.isCaptured(_currentFrame.receiverVar!)) { // Duplicate receiver variable for local use. _currentFrame.capturedReceiverVar = _currentFrame.receiverVar; - final localReceiverVar = _currentFrame.receiverVar = - VariableDeclaration('this'); + final localReceiverVar = _currentFrame.receiverVar = Variable('this'); _declareVariable(localReceiverVar); } } @@ -459,7 +445,7 @@ class _ScopeBuilder extends RecursiveVisitor { _currentScopeInternal = _currentScope.parent; } - void _declareVariable(VariableDeclaration variable, [Scope? scope]) { + void _declareVariable(Variable variable, [Scope? scope]) { if (scope == null) { scope = _currentScope; } @@ -471,7 +457,7 @@ class _ScopeBuilder extends RecursiveVisitor { locals._vars[variable] = v; } - void _useVariable(VariableDeclaration variable) { + void _useVariable(Variable variable) { final VarDesc? v = locals._vars[variable]; if (v == null) { throw 'Variable $variable is used before declared'; @@ -527,7 +513,7 @@ class _ScopeBuilder extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { _declareVariable(node.variable); node.visitChildren(this); } @@ -669,9 +655,7 @@ class _ScopeBuilder extends RecursiveVisitor { // an extra variable as they can be generated after all finally blocks. if (_enclosingTryBlocks.isNotEmpty && (node.expression != null && node.expression is! BasicLiteral)) { - final returnVar = _currentFrame.returnVar = VariableDeclaration( - ':return', - ); + final returnVar = _currentFrame.returnVar = Variable(':return'); _declareVariable(returnVar, _currentFrame.topScope); } node.visitChildren(this); @@ -839,7 +823,7 @@ class _Allocator extends RecursiveVisitor { ); } - void _allocateVariable(VariableDeclaration variable, {int? paramSlotIndex}) { + void _allocateVariable(Variable variable, {int? paramSlotIndex}) { final VarDesc v = locals._getVarDesc(variable); assert(!v.isAllocated); @@ -871,7 +855,7 @@ class _Allocator extends RecursiveVisitor { _updateFrameSize(); } - void _ensureVariableAllocated(VariableDeclaration? variable) { + void _ensureVariableAllocated(Variable? variable) { if (variable != null) { final VarDesc v = locals._getVarDesc(variable); if (!v.isAllocated) { @@ -880,7 +864,7 @@ class _Allocator extends RecursiveVisitor { } } - void _allocateParameter(VariableDeclaration node, int i) { + void _allocateParameter(Variable node, int i) { final numParameters = _currentFrame.numParameters; assert(0 <= i && i < numParameters); assert( @@ -1033,7 +1017,7 @@ class _Allocator extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { _allocateVariable(node.variable); node.visitChildren(this); } diff --git a/pkg/dart2bytecode/lib/object_table.dart b/pkg/dart2bytecode/lib/object_table.dart index 9896d864557..33b779b36fe 100644 --- a/pkg/dart2bytecode/lib/object_table.dart +++ b/pkg/dart2bytecode/lib/object_table.dart @@ -734,10 +734,7 @@ class ParameterFlags { return null; } - static int getVariableDeclarationFlags( - VariableDeclaration variable, - bool isCode, - ) { + static int getVariableDeclarationFlags(Variable variable, bool isCode) { int flags = 0; if (isCode) { if (variable.isCovariantByDeclaration) { diff --git a/pkg/dart2wasm/lib/async.dart b/pkg/dart2wasm/lib/async.dart index 95a4b96dc78..081fc8930e9 100644 --- a/pkg/dart2wasm/lib/async.dart +++ b/pkg/dart2wasm/lib/async.dart @@ -364,7 +364,7 @@ class AsyncStateMachineCodeGenerator extends StateMachineCodeGenerator { super.visitExpressionStatement(node); } - void _generateAwait(AwaitExpression node, VariableDeclaration awaitValueVar) { + void _generateAwait(AwaitExpression node, Variable awaitValueVar) { // Find the current context. Context? context; TreeNode contextOwner = node; diff --git a/pkg/dart2wasm/lib/await_transformer.dart b/pkg/dart2wasm/lib/await_transformer.dart index 0f54c13af1a..350e5f101d3 100644 --- a/pkg/dart2wasm/lib/await_transformer.dart +++ b/pkg/dart2wasm/lib/await_transformer.dart @@ -336,8 +336,8 @@ class _AwaitTransformer extends Transformer { // variables before the updates. // // temps.first is the flag 'first'. - List temps = [ - VariableDeclaration.forValue(BoolLiteral(true), isFinal: false), + List temps = [ + Variable.forValue(BoolLiteral(true), isFinal: false), ]; List loopBody = []; List initializers = [ @@ -347,13 +347,7 @@ class _AwaitTransformer extends Transformer { List newBody = [body]; for (int i = 0; i < stmt.variables.length; ++i) { VariableStatement decl = stmt.variables[i]; - temps.add( - VariableDeclaration( - null, - type: decl.variable.type, - isSynthesized: true, - ), - ); + temps.add(Variable(null, type: decl.variable.type, isSynthesized: true)); loopBody.add(decl); if (decl.initializer != null) { initializers.addAll(initEffects[i]); @@ -397,7 +391,7 @@ class _AwaitTransformer extends Transformer { labeled.body = WhileStatement(BoolLiteral(true), Block(loopBody)) ..parent = labeled; return Block([ - for (VariableDeclaration temp in temps) VariableStatement(temp), + for (Variable temp in temps) VariableStatement(temp), labeled, ]); } @@ -458,12 +452,12 @@ class _AwaitTransformer extends Transformer { // the current exception after the `await`. // // TODO (omersa): We could mark [TreeNode]s with `await`s and only do this - catch_.exception ??= VariableDeclaration( + catch_.exception ??= Variable( null, type: InterfaceType(coreTypes.objectClass, Nullability.nonNullable), isSynthesized: true, )..parent = catch_; - catch_.stackTrace ??= VariableDeclaration( + catch_.stackTrace ??= Variable( null, type: InterfaceType(coreTypes.stackTraceClass, Nullability.nonNullable), isSynthesized: true, @@ -501,7 +495,7 @@ class _AwaitTransformer extends Transformer { // code generation. // Variable for the finalizer block continuation. - final continuationVar = VariableDeclaration( + final continuationVar = Variable( null, initializer: IntLiteral(stateMachineCodeGen.continuationFallthrough), type: InterfaceType(coreTypes.intClass, Nullability.nonNullable), @@ -510,7 +504,7 @@ class _AwaitTransformer extends Transformer { // When the finalizer continuation is "rethrow", this stores the exception // to rethrow. - final exceptionVar = VariableDeclaration( + final exceptionVar = Variable( null, type: InterfaceType(coreTypes.objectClass, Nullability.nonNullable), isSynthesized: true, @@ -518,7 +512,7 @@ class _AwaitTransformer extends Transformer { // When the finalizer continuation is "rethrow", this stores the stack // trace of the exception in [exceptionVar]. - final stackTraceVar = VariableDeclaration( + final stackTraceVar = Variable( null, type: InterfaceType(coreTypes.stackTraceClass, Nullability.nonNullable), isSynthesized: true, @@ -684,7 +678,7 @@ class _ExpressionTransformer extends Transformer { int nameIndex = 0; /// Variables created for temporaries. - final List variables = []; + final List variables = []; final _AwaitTransformer _statementTransformer; @@ -703,15 +697,12 @@ class _ExpressionTransformer extends Transformer { /// Name an expression by emitting an assignment to a temporary variable. Expression name(Expression expr) { final DartType type = expr.getStaticType(staticTypeContext); - final VariableDeclaration temp = allocateTemporary(nameIndex, type); + final Variable temp = allocateTemporary(nameIndex, type); statements.add(ExpressionStatement(VariableSet(temp, expr))); return castVariableGet(temp, type); } - VariableDeclaration allocateTemporary( - int index, [ - DartType type = const DynamicType(), - ]) { + Variable allocateTemporary(int index, [DartType type = const DynamicType()]) { if (variables.length > index) { // Re-using a temporary. Re-type it to dynamic if we detect reuse with // different type. @@ -722,13 +713,13 @@ class _ExpressionTransformer extends Transformer { return variables[index]; } for (var i = variables.length; i <= index; i++) { - variables.add(VariableDeclaration(":async_temporary_$i", type: type)); + variables.add(Variable(":async_temporary_$i", type: type)); } return variables[index]; } /// Casts a [VariableGet] with `as dynamic` if its type is not `dynamic`. - Expression castVariableGet(VariableDeclaration variable, DartType type) { + Expression castVariableGet(Variable variable, DartType type) { Expression expr = VariableGet(variable); if (type != const DynamicType()) { expr = AsExpression(expr, DynamicType()); @@ -1132,7 +1123,7 @@ class _ExpressionTransformer extends Transformer { final Block rightBody = blockOf(rightStatements); final InterfaceType type = staticTypeContext.typeEnvironment.coreTypes .boolRawType(staticTypeContext.nonNullable); - final VariableDeclaration result = allocateTemporary(nameIndex, type); + final Variable result = allocateTemporary(nameIndex, type); rightBody.addStatement( ExpressionStatement(VariableSet(result, expr.right)), ); @@ -1260,7 +1251,7 @@ class _ExpressionTransformer extends Transformer { @override TreeNode visitLet(Let expr) { final body = transform(expr.body); - final VariableDeclaration variable = expr.variable; + final Variable variable = expr.variable; if (seenAwait) { // There is an await in the body of `let var x = initializer in body` or // to its right. We will produce the sequence of statements: diff --git a/pkg/dart2wasm/lib/closures.dart b/pkg/dart2wasm/lib/closures.dart index 9f29388a465..5d9086a9045 100644 --- a/pkg/dart2wasm/lib/closures.dart +++ b/pkg/dart2wasm/lib/closures.dart @@ -1247,7 +1247,7 @@ class ClosureRepresentationsForParameterCount { void registerFunction(FunctionNode functionNode) { int? prevIndex; - for (VariableDeclaration named in functionNode.namedParameters) { + for (Variable named in functionNode.namedParameters) { String name = named.name!; int nameIndex = nameIds.putIfAbsent(name, () => nameUnions.add()); if (prevIndex != null) { @@ -1358,7 +1358,7 @@ class Context { Context? parent; /// The variables captured by this context. - final List variables = []; + final List variables = []; /// The type parameters captured by this context. final List typeParameters = []; @@ -1392,7 +1392,7 @@ class Context { /// A captured variable or type parameter. class Capture { - /// The captured [VariableDeclaration] or [TypeParameter]. + /// The captured [Variable] or [TypeParameter]. final TreeNode variable; /// Whether the variable was captured in the initializer (if constructor @@ -1413,7 +1413,7 @@ class Capture { bool written = false; Capture(this.variable, this.isInInitializer) { - assert(variable is VariableDeclaration || variable is TypeParameter); + assert(variable is Variable || variable is TypeParameter); } w.ValueType get type => context.struct.fields[fieldIndex].type.unpacked; @@ -1427,7 +1427,7 @@ class Closures { /// [Lambda]s. final Map lambdas = {}; - /// Maps [VariableDeclaration]s and [TypeParameter]s in the member to + /// Maps [Variable]s and [TypeParameter]s in the member to /// [Capture]s. final Map captures = {}; @@ -1554,7 +1554,7 @@ class Closures { assert(_member.enclosingClass != null); struct.fields.add(w.FieldType(_nullableThisType!)); } - for (VariableDeclaration variable in context.variables) { + for (Variable variable in context.variables) { int index = struct.fields.length; struct.fields.add( w.FieldType( @@ -1626,11 +1626,11 @@ class _CaptureFinder extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { if (depth > 0) { variableDepth[node] = depth; } - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override @@ -1652,8 +1652,7 @@ class _CaptureFinder extends RecursiveVisitor { isInInitializer, ); if (functionIsSyncStarOrAsync[declDepth]) capture.written = true; - } else if (variable is VariableDeclaration && - variable.parent is FunctionDeclaration) { + } else if (variable is Variable && variable.parent is FunctionDeclaration) { // Variable is for a function declaration, the function needs to be // compiled as a closure. closures.closurizedFunctions.add(variable.parent as FunctionDeclaration); @@ -1863,7 +1862,7 @@ class _ContextCollector extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { Capture? capture = closures.captures[node]; if (capture != null) { if (isInInitializer == capture.isInInitializer) { @@ -1871,7 +1870,7 @@ class _ContextCollector extends RecursiveVisitor { capture.context = currentContext!; } } - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override diff --git a/pkg/dart2wasm/lib/code_generator.dart b/pkg/dart2wasm/lib/code_generator.dart index 328c811b67d..d26a0f5af69 100644 --- a/pkg/dart2wasm/lib/code_generator.dart +++ b/pkg/dart2wasm/lib/code_generator.dart @@ -83,7 +83,7 @@ abstract class AstCodeGenerator bool exceptionLocationPrinted = false; - final Map locals = {}; + final Map locals = {}; w.Local? thisLocal; w.Local? preciseThisLocal; w.Local? returnValueLocal; @@ -284,7 +284,7 @@ abstract class AstCodeGenerator void setupParamLocal( DartType variableTypeToCheck, - VariableDeclaration variable, + Variable variable, int index, Constant? defaultValue, bool isRequired, @@ -481,10 +481,10 @@ abstract class AstCodeGenerator for (TypeParameter typeParam in functionNode.typeParameters) { typeLocals[typeParam] = paramLocals[paramIndex++]; } - for (VariableDeclaration param in functionNode.positionalParameters) { + for (Variable param in functionNode.positionalParameters) { locals[param] = paramLocals[paramIndex++]; } - for (VariableDeclaration param in functionNode.namedParameters) { + for (Variable param in functionNode.namedParameters) { locals[param] = paramLocals[paramIndex++]; } @@ -672,10 +672,10 @@ abstract class AstCodeGenerator } } - void translateVariableDeclaration(VariableDeclaration node) { + void translateVariableDeclaration(Variable node) { final oldFileOffset = setSourceMapFileOffset(node.fileOffset); try { - visitVariableDeclaration(node); + visitVariable(node); } catch (_) { _printLocation(node); rethrow; @@ -759,7 +759,7 @@ abstract class AstCodeGenerator } @override - void visitVariableDeclaration(VariableDeclaration node) { + void visitVariable(Variable node) { final w.ValueType type = translator.translateTypeOfLocalVariable(node); w.Local? local; final Capture? capture = closures.captures[node]; @@ -810,12 +810,9 @@ abstract class AstCodeGenerator /// Initialize a variable [node] to an initial value which must be left on /// the stack by [pushInitialValue]. /// - /// This is similar to [visitVariableDeclaration] but it gives more control + /// This is similar to [visitVariable] but it gives more control /// over how the variable is initialized. - void initializeVariable( - VariableDeclaration node, - void Function() pushInitialValue, - ) { + void initializeVariable(Variable node, void Function() pushInitialValue) { final w.ValueType type = translator.translateTypeOfLocalVariable(node); w.Local? local; final Capture? capture = closures.captures[node]; @@ -1048,7 +1045,7 @@ abstract class AstCodeGenerator b.local_set(thrownStackTrace); b.local_set(thrownException); - final VariableDeclaration? exceptionDeclaration = catch_.exception; + final Variable? exceptionDeclaration = catch_.exception; if (exceptionDeclaration != null) { initializeVariable(exceptionDeclaration, () { b.local_get(thrownException); @@ -1061,7 +1058,7 @@ abstract class AstCodeGenerator }); } - final VariableDeclaration? stackTraceDeclaration = catch_.stackTrace; + final Variable? stackTraceDeclaration = catch_.stackTrace; if (stackTraceDeclaration != null) { initializeVariable( stackTraceDeclaration, @@ -3667,7 +3664,7 @@ class SynchronousProcedureCodeGenerator extends AstCodeGenerator { final typeParameter = typeParameters[i]; typeLocals[typeParameter] = paramLocals[param++]; } - void setupParameter(VariableDeclaration parameter) { + void setupParameter(Variable parameter) { // The body may assign less precise types to the parameter variable than // what the caller provides. w.Local local = paramLocals[param++]; @@ -4168,7 +4165,7 @@ abstract class ConstructorCodeGeneratorBase extends AstCodeGenerator { List _getConstructorArgumentLocals( List typeParameters, - List parameters, + List parameters, ) { List constructorArgs = []; @@ -4176,7 +4173,7 @@ abstract class ConstructorCodeGeneratorBase extends AstCodeGenerator { constructorArgs.add(typeLocals[typeParameters[i]]!); } - for (VariableDeclaration param in parameters) { + for (Variable param in parameters) { constructorArgs.add(locals[param]!); } @@ -4185,7 +4182,7 @@ abstract class ConstructorCodeGeneratorBase extends AstCodeGenerator { int _setupConstructorParameters( List typeParameters, - List parameters, + List parameters, int parameterOffset, ) { for (int i = 0; i < typeParameters.length; i++) { diff --git a/pkg/dart2wasm/lib/constructor_info.dart b/pkg/dart2wasm/lib/constructor_info.dart index d3c198f9b27..b3bd0b3e8f6 100644 --- a/pkg/dart2wasm/lib/constructor_info.dart +++ b/pkg/dart2wasm/lib/constructor_info.dart @@ -16,21 +16,21 @@ class ConstructorInfo { /// All parameters of the constructor in canonical order (positional first, /// then named sorted by name). - final List allParameters; + final List allParameters; /// Parameters that must be passed to the initializer function. late final List initializerTypeParameters; - late final List initializerParameters; + late final List initializerParameters; /// Parameters that must be passed to the body function from the allocator. /// /// NOTE: Type parameters of a constructor always end up in fields and can be /// loaded from there. The constructor body therefore never needs to get them /// passed explicitly. - late final List bodyParameters; + late final List bodyParameters; /// Parameters that constructor bodies can load via `this`. - final Map parameterToField = {}; + final Map parameterToField = {}; ConstructorInfo(this.constructor, this.translator) : allParameters = [ @@ -108,11 +108,11 @@ class _UsageCollector extends RecursiveVisitor { final Translator translator; final Closures closures; - final variablesRead = {}; - final variablesWritten = {}; - final variablesCaptured = {}; + final variablesRead = {}; + final variablesWritten = {}; + final variablesCaptured = {}; final usedTypeParameters = {}; - final variablesStoredInFields = {}; + final variablesStoredInFields = {}; _UsageCollector(this.translator, this.closures); diff --git a/pkg/dart2wasm/lib/deferred_load/dependencies.dart b/pkg/dart2wasm/lib/deferred_load/dependencies.dart index c55c21785fc..1352560c197 100644 --- a/pkg/dart2wasm/lib/deferred_load/dependencies.dart +++ b/pkg/dart2wasm/lib/deferred_load/dependencies.dart @@ -732,8 +732,7 @@ class _ReferenceDependenciesCollector extends RecursiveVisitor { @override void visitEmptyStatement(EmptyStatement node) => node.visitChildren(this); @override - void defaultVariableDeclaration(VariableDeclaration node) => - node.visitChildren(this); + void defaultVariable(Variable node) => node.visitChildren(this); @override void visitReturnStatement(ReturnStatement node) => node.visitChildren(this); @override diff --git a/pkg/dart2wasm/lib/dispatch_table.dart b/pkg/dart2wasm/lib/dispatch_table.dart index b80820b5160..fc1a9695fdd 100644 --- a/pkg/dart2wasm/lib/dispatch_table.dart +++ b/pkg/dart2wasm/lib/dispatch_table.dart @@ -163,7 +163,7 @@ class SelectorInfo { ), ]; named = { - for (VariableDeclaration param in function.namedParameters) + for (Variable param in function.namedParameters) param.name!: typeForParam(param, param.isRequired), }; returns = returnCount == 0 diff --git a/pkg/dart2wasm/lib/ffi_native_transformer.dart b/pkg/dart2wasm/lib/ffi_native_transformer.dart index ea6dc93d979..88455bf510e 100644 --- a/pkg/dart2wasm/lib/ffi_native_transformer.dart +++ b/pkg/dart2wasm/lib/ffi_native_transformer.dart @@ -219,14 +219,14 @@ class WasmFfiNativeTransformer extends FfiNativeTransformer { // For the imported function arguments, use names in the Dart function but // types in the FFI declaration - final List wasmImportProcedureArgs = []; + final List wasmImportProcedureArgs = []; for (int i = 0; i < ffiFunctionType.positionalParameters.length; i += 1) { final argWasmType = _convertFfiTypeToWasmType( ffiFunctionType.positionalParameters[i], ); if (argWasmType != null) { wasmImportProcedureArgs.add( - VariableDeclaration( + Variable( node.function.positionalParameters[i].name!, type: argWasmType, isSynthesized: true, diff --git a/pkg/dart2wasm/lib/functions.dart b/pkg/dart2wasm/lib/functions.dart index 881e8f8d9bf..9a91ce06ac2 100644 --- a/pkg/dart2wasm/lib/functions.dart +++ b/pkg/dart2wasm/lib/functions.dart @@ -684,7 +684,7 @@ List _getConstructorInputTypes( Translator translator, Constructor member, List typeParameters, - List parameters, + List parameters, w.ValueType Function(DartType) translateType, ) { final List inputs = []; diff --git a/pkg/dart2wasm/lib/js/callback_specializer.dart b/pkg/dart2wasm/lib/js/callback_specializer.dart index 92e454de8cd..63d17e91d6d 100644 --- a/pkg/dart2wasm/lib/js/callback_specializer.dart +++ b/pkg/dart2wasm/lib/js/callback_specializer.dart @@ -18,8 +18,8 @@ class CallbackSpecializer { Statement _generateDispatchCase( FunctionType function, - VariableDeclaration callbackVariable, - List positionalParameters, + Variable callbackVariable, + List positionalParameters, int requiredParameterCount, { required bool boxExternRef, }) { @@ -56,7 +56,7 @@ class CallbackSpecializer { const _InstantiateToBounds().substituteType(function) as FunctionType, ); - final temp = VariableDeclaration( + final temp = Variable( null, initializer: callExpr, type: callExpr.getStaticType(_staticTypeContext), @@ -98,28 +98,28 @@ class CallbackSpecializer { // before being invoked. The second argument will be a `double` indicating // the number of arguments passed. The third argument is a cast closure if // needed. - final callbackVariable = VariableDeclaration( + final callbackVariable = Variable( 'callback', type: _util.nonNullableObjectType, isSynthesized: true, ); - final argumentsLengthWasmI32 = VariableDeclaration( + final argumentsLengthWasmI32 = Variable( 'argumentsLengthWasmI32', type: InterfaceType(_util.wasmI32Class, Nullability.nonNullable), isSynthesized: true, ); - final castClosure = VariableDeclaration( + final castClosure = Variable( 'castClosure', type: _util.nonNullableObjectType, isSynthesized: true, ); // Initialize variable declarations. - List positionalParameters = []; + List positionalParameters = []; List castClosureArguments = []; final positionalParametersLength = function.positionalParameters.length; for (int i = 0; i < positionalParametersLength; i++) { - final parameter = VariableDeclaration( + final parameter = Variable( 'x${i + 1}', type: _util.nullableWasmExternRefType, isSynthesized: true, @@ -137,7 +137,7 @@ class CallbackSpecializer { List body = []; // Convert `WasmI32` argument to Dart `int`. - final argumentsLength = VariableDeclaration( + final argumentsLength = Variable( 'argumentsLength', type: _util.coreTypes.intNonNullableRawType, isSynthesized: true, @@ -305,18 +305,18 @@ class CallbackSpecializer { FunctionNode( null, positionalParameters: [ - VariableDeclaration( + Variable( 'thisModule', type: _util.nonNullableWasmExternRefType, isSynthesized: true, ), - VariableDeclaration( + Variable( 'dartFunction', type: _util.nonNullableWasmExternRefType, isSynthesized: true, ), if (needsCastClosure) - VariableDeclaration( + Variable( 'castClosure', type: _util.nonNullableWasmExternRefType, isSynthesized: true, @@ -362,12 +362,12 @@ class CallbackSpecializer { /// Returns the cast closure if needed. Otherwise, returns `null`. FunctionExpression? _createCastClosure(FunctionType functionType) { final positionalParameters = functionType.positionalParameters; - List castClosureParameters = []; + List castClosureParameters = []; List casts = []; for (int i = 0; i < positionalParameters.length; i++) { final type = positionalParameters[i]; if (_needCastClosure(type)) { - final parameter = VariableDeclaration( + final parameter = Variable( 'x${i + 1}', type: _util.nullableJSValueType, isSynthesized: true, diff --git a/pkg/dart2wasm/lib/js/inline_expander.dart b/pkg/dart2wasm/lib/js/inline_expander.dart index f4268d5cf7e..8342cee58a4 100644 --- a/pkg/dart2wasm/lib/js/inline_expander.dart +++ b/pkg/dart2wasm/lib/js/inline_expander.dart @@ -21,13 +21,13 @@ class InlineExpander { Expression expand(StaticInvocation node) { Arguments arguments = node.arguments; List originalArguments = arguments.positional.sublist(1); - List dartPositionalParameters = []; + List dartPositionalParameters = []; for (int j = 0; j < originalArguments.length; j++) { Expression originalArgument = originalArguments[j]; String parameterString = 'x$j'; DartType type = originalArgument.getStaticType(_staticTypeContext); dartPositionalParameters.add( - VariableDeclaration( + Variable( parameterString, type: _toExternalType(type), isSynthesized: true, diff --git a/pkg/dart2wasm/lib/js/interop_specializer.dart b/pkg/dart2wasm/lib/js/interop_specializer.dart index 5081fc78d1b..7869e7d1154 100644 --- a/pkg/dart2wasm/lib/js/interop_specializer.dart +++ b/pkg/dart2wasm/lib/js/interop_specializer.dart @@ -48,7 +48,7 @@ abstract class _Specializer { /// The parameters that determine arity of the interop procedure that is /// created from this config. - List get parameters; + List get parameters; /// Returns the string that will be the body of the JS trampoline. /// @@ -94,9 +94,9 @@ abstract class _Specializer { Procedure _getRawInteropProcedure() { // Initialize variable declarations. List jsParameterStrings = []; - List dartPositionalParameters = []; + List dartPositionalParameters = []; for (int i = 0; i < parameters.length; i++) { - final VariableDeclaration parameter = parameters[i]; + final Variable parameter = parameters[i]; final DartType parameterType = parameter.type; final interopFunctionParameterType = parameterType == _util.coreTypes.doubleNonNullableRawType @@ -104,7 +104,7 @@ abstract class _Specializer { : _util.nullableWasmExternRefType; String parameterString = 'x$i'; dartPositionalParameters.add( - VariableDeclaration( + Variable( parameterString, type: interopFunctionParameterType, isSynthesized: true, @@ -197,7 +197,7 @@ abstract class _ProcedureSpecializer extends _Specializer { _ProcedureSpecializer(super.context, super.interopMethod, super.jsString); @override - List get parameters => function.positionalParameters; + List get parameters => function.positionalParameters; /// Returns an invocation of a specialized JS method meant to be used in a /// procedure-level lowering. @@ -352,8 +352,10 @@ abstract class _PositionalInvocationSpecializer extends _InvocationSpecializer { ); @override - List get parameters => function.positionalParameters - .sublist(0, invocation.arguments.positional.length); + List get parameters => function.positionalParameters.sublist( + 0, + invocation.arguments.positional.length, + ); /// Returns an invocation of a specialized JS method meant to be used in an /// invocation-level lowering. @@ -367,7 +369,7 @@ abstract class _PositionalInvocationSpecializer extends _InvocationSpecializer { final List jsifiedArguments = []; final List arguments = invocation.arguments.positional; for (int i = 0; i < arguments.length; i += 1) { - final temp = VariableDeclaration( + final temp = Variable( null, initializer: arguments[i], type: arguments[i].getStaticType(factory._staticTypeContext), @@ -463,7 +465,7 @@ class _ObjectLiteralSpecializer extends _InvocationSpecializer { bool get isSetter => false; @override - List get parameters { + List get parameters { // Compute the named parameters that were used in the given `invocation`. // Note that we preserve the procedure's ordering and not the invocation's. // This is also used below for the names of object literal arguments in @@ -480,7 +482,7 @@ class _ObjectLiteralSpecializer extends _InvocationSpecializer { /// /// This defaults to the name of the [variable], but can be changed with a /// `@JS()` annotation. - String _jsKey(VariableDeclaration variable) { + String _jsKey(Variable variable) { // Only support `@JS` renaming on extension type object literal // constructors. final changedName = interopMethod.isExtensionTypeMember @@ -527,7 +529,7 @@ class _ObjectLiteralSpecializer extends _InvocationSpecializer { .toList(); final List jsifiedArguments = []; for (int i = 0; i < arguments.length; i += 1) { - final temp = VariableDeclaration( + final temp = Variable( null, initializer: arguments[i], type: arguments[i].getStaticType(factory._staticTypeContext), diff --git a/pkg/dart2wasm/lib/js/util.dart b/pkg/dart2wasm/lib/js/util.dart index 8c3cc028922..d50c8759c40 100644 --- a/pkg/dart2wasm/lib/js/util.dart +++ b/pkg/dart2wasm/lib/js/util.dart @@ -746,16 +746,14 @@ class CoreTypesUtil { extensionIndex.isStaticInteropType(type) || extensionIndex.isExternalDartReferenceType(type); - Expression variableCheckConstant( - VariableDeclaration variable, - Constant constant, - ) => StaticInvocation( - coreTypes.identicalProcedure, - Arguments([VariableGet(variable), ConstantExpression(constant)]), - ); + Expression variableCheckConstant(Variable variable, Constant constant) => + StaticInvocation( + coreTypes.identicalProcedure, + Arguments([VariableGet(variable), ConstantExpression(constant)]), + ); Expression variableGreaterThanOrEqualToConstant( - VariableDeclaration variable, + Variable variable, Constant constant, ) => InstanceInvocation( InstanceAccessKind.Instance, @@ -807,7 +805,7 @@ class CoreTypesUtil { final conversionProcedure = _dartConversionProcedure( expectedTypeExtensionTypeErasure, ); - final invocationValueVar = VariableDeclaration( + final invocationValueVar = Variable( '#jsInvocation', initializer: invocation, type: nullableWasmExternRefType, @@ -839,13 +837,13 @@ class CoreTypesUtil { // } else { // throw; // } - VariableDeclaration v = VariableDeclaration( + Variable v = Variable( '#vardouble', initializer: AsExpression(expression, coreTypes.doubleNullableRawType), type: coreTypes.doubleNullableRawType, isSynthesized: true, ); - VariableDeclaration v2 = VariableDeclaration( + Variable v2 = Variable( '#varint', initializer: invokeMethod(v, numToIntTarget), type: coreTypes.intNonNullableRawType, @@ -951,7 +949,7 @@ StaticInvocation invokeOneArg(Procedure target, Expression arg) => StaticInvocation(target, Arguments([arg])); InstanceInvocation invokeMethod( - VariableDeclaration receiver, + Variable receiver, Procedure target, [ Arguments? arguments, ]) => InstanceInvocation( @@ -967,7 +965,7 @@ bool parametersNeedParens(List parameters) => parameters.isEmpty || parameters.length > 1; Expression jsifyValue( - VariableDeclaration variable, + Variable variable, DartType expectedType, CoreTypesUtil coreTypes, TypeEnvironment typeEnv, diff --git a/pkg/dart2wasm/lib/param_info.dart b/pkg/dart2wasm/lib/param_info.dart index 21c7a105f98..94ee245f783 100644 --- a/pkg/dart2wasm/lib/param_info.dart +++ b/pkg/dart2wasm/lib/param_info.dart @@ -38,7 +38,7 @@ class ParameterInfo { int get paramCount => positional.length + named.length; - static Constant? _defaultValue(VariableDeclaration param) { + static Constant? _defaultValue(Variable param) { Expression? initializer = param.initializer; if (initializer is ConstantExpression) { return initializer.constant; @@ -90,7 +90,7 @@ class ParameterInfo { }); final named = { - for (VariableDeclaration param in function.namedParameters) + for (Variable param in function.namedParameters) if (param.isRequired) param.name!: null else @@ -120,7 +120,7 @@ class ParameterInfo { return _defaultValue(function.positionalParameters[i]); }); final named = { - for (VariableDeclaration param in function.namedParameters) + for (Variable param in function.namedParameters) param.name!: _defaultValue(param), }; return ParameterInfo._(true, typeParamCount, positional, named); diff --git a/pkg/dart2wasm/lib/record_class_generator.dart b/pkg/dart2wasm/lib/record_class_generator.dart index 52f331fc2e1..1e5228d4e06 100644 --- a/pkg/dart2wasm/lib/record_class_generator.dart +++ b/pkg/dart2wasm/lib/record_class_generator.dart @@ -312,9 +312,9 @@ class _RecordClassGenerator { /// Generate a constructor with name `_`. Named fields are passed in sorted /// order. Constructor _generateConstructor(RecordShape shape, List fields) { - final List positionalParameters = List.generate( + final List positionalParameters = List.generate( fields.length, - (i) => VariableDeclaration('field$i', isSynthesized: true), + (i) => Variable('field$i', isSynthesized: true), ); final List initializers = List.generate( @@ -473,7 +473,7 @@ class _RecordClassGenerator { Nullability.nonNullable, ); - final VariableDeclaration parameter = VariableDeclaration( + final Variable parameter = Variable( 'other', type: nullableObjectType, isSynthesized: true, @@ -545,11 +545,8 @@ class _RecordClassGenerator { /// Generate `_checkRecordType` member. Procedure _generateCheckRecordType(RecordShape shape, List fields) { - final typesParameter = VariableDeclaration('types', type: wasmArrayOfType); - final namesParameter = VariableDeclaration( - 'names', - type: immutableWasmArrayOfString, - ); + final typesParameter = Variable('types', type: wasmArrayOfType); + final namesParameter = Variable('names', type: immutableWasmArrayOfString); final List statements = []; diff --git a/pkg/dart2wasm/lib/state_machine.dart b/pkg/dart2wasm/lib/state_machine.dart index da88f042b70..8f55ba29ee7 100644 --- a/pkg/dart2wasm/lib/state_machine.dart +++ b/pkg/dart2wasm/lib/state_machine.dart @@ -446,8 +446,8 @@ abstract class _ExceptionHandler { } class _Catcher extends _ExceptionHandler { - final List _exceptionVars = []; - final List _stackTraceVars = []; + final List _exceptionVars = []; + final List _stackTraceVars = []; final StateMachineCodeGenerator codeGen; bool _canHandleJSExceptions = false; @@ -487,9 +487,9 @@ const int continuationRethrow = 2; const int continuationJump = 3; class Finalizer extends _ExceptionHandler { - final VariableDeclaration _continuationVar; - final VariableDeclaration _exceptionVar; - final VariableDeclaration _stackTraceVar; + final Variable _continuationVar; + final Variable _exceptionVar; + final Variable _stackTraceVar; final Finalizer? parentFinalizer; final StateMachineCodeGenerator codeGen; @@ -613,8 +613,8 @@ class _IndirectLabelTarget implements LabelTarget { /// used to get the exception and stack trace to throw when compiling /// [Rethrow]. class CatchVariables { - final VariableDeclaration exception; - final VariableDeclaration stackTrace; + final Variable exception; + final Variable stackTrace; CatchVariables._(this.exception, this.stackTrace); } @@ -1049,10 +1049,10 @@ abstract class StateMachineCodeGenerator extends AstCodeGenerator { for (Catch c in node.catches) { if (c.exception != null) { - visitVariableDeclaration(c.exception!); + visitVariable(c.exception!); } if (c.stackTrace != null) { - visitVariableDeclaration(c.stackTrace!); + visitVariable(c.stackTrace!); } } @@ -1340,7 +1340,7 @@ abstract class StateMachineCodeGenerator extends AstCodeGenerator { /// Similar to the [VariableSet] visitor, but the value is pushed to the /// stack by the callback [pushValue]. - void setVariable(VariableDeclaration variable, void Function() pushValue) { + void setVariable(Variable variable, void Function() pushValue) { final w.Local? local = locals[variable]; final Capture? capture = closures.captures[variable]; if (capture != null) { @@ -1357,7 +1357,7 @@ abstract class StateMachineCodeGenerator extends AstCodeGenerator { } } - w.ValueType _getVariable(VariableDeclaration variable) { + w.ValueType _getVariable(Variable variable) { final w.Local? local = locals[variable]; final Capture? capture = closures.captures[variable]; if (capture != null) { @@ -1379,7 +1379,7 @@ abstract class StateMachineCodeGenerator extends AstCodeGenerator { } /// Same as [_getVariable], but boxes the value if it's not already boxed. - void _getVariableBoxed(VariableDeclaration variable) { + void _getVariableBoxed(Variable variable) { final varType = _getVariable(variable); translator.convertType(b, varType, translator.topType); } diff --git a/pkg/dart2wasm/lib/transformers.dart b/pkg/dart2wasm/lib/transformers.dart index b8fb4a4d9bd..85e19bd7a91 100644 --- a/pkg/dart2wasm/lib/transformers.dart +++ b/pkg/dart2wasm/lib/transformers.dart @@ -35,7 +35,7 @@ class _WasmTransformer extends Transformer { Member? _currentMember; StaticTypeContext? _cachedTypeContext; - final Set _implicitFinalVariables = {}; + final Set _implicitFinalVariables = {}; final Library _coreLibrary; final InterfaceType _nonNullableTypeType; @@ -278,11 +278,11 @@ class _WasmTransformer extends Transformer { } @override - defaultVariableDeclaration(VariableDeclaration node) { + defaultVariable(Variable node) { if (!node.isFinal) { _implicitFinalVariables.add(node); } - return super.defaultVariableDeclaration(node); + return super.defaultVariable(node); } @override @@ -407,7 +407,7 @@ class _WasmTransformer extends Transformer { ); } - final iterator = VariableDeclaration( + final iterator = Variable( "#forIterator", initializer: iteratorInitializer..fileOffset = iterable.fileOffset, type: iteratorType, @@ -415,7 +415,7 @@ class _WasmTransformer extends Transformer { )..fileOffset = iterable.fileOffset; // Only used when `isAsync` is true. - final jumpSentinel = VariableDeclaration( + final jumpSentinel = Variable( "#jumpSentinel", initializer: ConstantExpression(BoolConstant(false)), type: InterfaceType(coreTypes.boolClass, Nullability.nonNullable), @@ -492,7 +492,7 @@ class _WasmTransformer extends Transformer { } InstanceInvocation _addToController( - VariableDeclaration controller, + Variable controller, Expression expression, int fileOffset, ) { @@ -615,14 +615,14 @@ class _WasmTransformer extends Transformer { const VoidType(), ]); - final pausedVar = VariableDeclaration( + final pausedVar = Variable( '#paused', initializer: null, type: pausedVarType, isSynthesized: true, ); - final cancelCompleterVar = VariableDeclaration( + final cancelCompleterVar = Variable( '#cancelCompleter', initializer: null, type: InterfaceType(_completerClass, Nullability.nullable, [ @@ -631,7 +631,7 @@ class _WasmTransformer extends Transformer { isSynthesized: true, ); - final isDoneVar = VariableDeclaration( + final isDoneVar = Variable( '#isDone', type: InterfaceType(coreTypes.boolClass, Nullability.nonNullable), initializer: ConstantExpression(BoolConstant(false)), @@ -704,7 +704,7 @@ class _WasmTransformer extends Transformer { ), ); - final onCancelCallbackVar = VariableDeclaration( + final onCancelCallbackVar = Variable( "#onCancelCallback", initializer: onCancelCallback, ); @@ -713,7 +713,7 @@ class _WasmTransformer extends Transformer { FunctionNode(makePauseCheck(), returnType: const VoidType()), ); - final onResumeCallbackVar = VariableDeclaration( + final onResumeCallbackVar = Variable( "#onResumeCallback", initializer: onResumeCallback, ); @@ -733,7 +733,7 @@ class _WasmTransformer extends Transformer { ); // var #controller = ... - final controllerVar = VariableDeclaration( + final controllerVar = Variable( '#controller', initializer: controllerInitializer..fileOffset = fileOffset, type: controllerObjectType, @@ -749,9 +749,9 @@ class _WasmTransformer extends Transformer { // The body will be wrapped with a `try-catch` to pass the error to the // controller, and `try-finally` to close the controller. - final exceptionVar = VariableDeclaration(null, isSynthesized: true); + final exceptionVar = Variable(null, isSynthesized: true); - final stackTraceVar = VariableDeclaration( + final stackTraceVar = Variable( null, isSynthesized: true, type: coreTypes.stackTraceRawType(Nullability.nonNullable), @@ -850,7 +850,7 @@ class _WasmTransformer extends Transformer { Nullability.nonNullable, ); - final bodyVar = VariableDeclaration( + final bodyVar = Variable( '#body', initializer: bodyInitializer..fileOffset = fileOffset, type: bodyFunctionType, @@ -1156,8 +1156,8 @@ class _WasmTransformer extends Transformer { } class _AsyncStarFrame { - final VariableDeclaration controllerVar; - final VariableDeclaration pausedVar; + final Variable controllerVar; + final Variable pausedVar; final DartType emittedValueType; _AsyncStarFrame(this.controllerVar, this.pausedVar, this.emittedValueType); @@ -1304,7 +1304,7 @@ class PushPopWasmArrayTransformer { ); // var newArray = WasmArray(nextCapacity) - final newArrayVariable = VariableDeclaration( + final newArrayVariable = Variable( 'newArray', initializer: arrayAllocation, type: InterfaceType(_wasmArrayClass, Nullability.nonNullable, [ @@ -1471,7 +1471,7 @@ class PushPopWasmArrayTransformer { ); // final temp = array[length] - final arrayGetVariable = VariableDeclaration.forValue( + final arrayGetVariable = Variable.forValue( arrayGet, isFinal: true, type: elementType, @@ -1500,7 +1500,7 @@ class PushPopWasmArrayTransformer { } class _VariableCollector extends RecursiveVisitor { - Set variables = {}; + Set variables = {}; @override void visitVariableGet(VariableGet node) { diff --git a/pkg/dart2wasm/lib/translator.dart b/pkg/dart2wasm/lib/translator.dart index cab2a4ef39d..fff376dc9f3 100644 --- a/pkg/dart2wasm/lib/translator.dart +++ b/pkg/dart2wasm/lib/translator.dart @@ -1301,7 +1301,7 @@ class Translator with KernelNodes { // Look up the closure representation for the signature. int typeCount = functionNode.typeParameters.length; int positionalCount = functionNode.positionalParameters.length; - final List namedParamsSorted = + final List namedParamsSorted = functionNode.namedParameters.toList() ..sort((p1, p2) => p1.name!.compareTo(p2.name!)); List names = namedParamsSorted.map((p) => p.name!).toList(); @@ -1665,7 +1665,7 @@ class Translator with KernelNodes { } bool needToCheckParameter( - VariableDeclaration parameter, { + Variable parameter, { required bool uncheckedEntry, }) { if (options.omitImplicitTypeChecks) return false; @@ -1678,9 +1678,9 @@ class Translator with KernelNodes { ({ List typeParameters, List typeParametersToTypeCheck, - List positional, + List positional, List positionalToTypeCheck, - List named, + List named, List namedToTypeCheck, }) getParametersToCheck(Member member) { @@ -1688,9 +1688,8 @@ class Translator with KernelNodes { final List typeParameters = member is Constructor ? member.enclosingClass.typeParameters : member.function!.typeParameters; - final List positional = - memberFunction.positionalParameters; - final List named = memberFunction.namedParameters; + final List positional = memberFunction.positionalParameters; + final List named = memberFunction.namedParameters; // If this is a CFE-inserted `forwarding-stub` then the types we have to // check against are those from the forwarding target. @@ -1740,16 +1739,14 @@ class Translator with KernelNodes { return [for (final param in typeParameters) param.bound]; } - List _typesFromPositionalParameters( - List typeParameters, - ) { + List _typesFromPositionalParameters(List typeParameters) { if (typeParameters.isEmpty) return const []; return [for (final param in typeParameters) param.type]; } List _typeFromNamedParameters( - List namedOrder, - List namedType, + List namedOrder, + List namedType, ) { if (namedOrder.isEmpty) return const []; final namedTypes = []; @@ -1945,7 +1942,7 @@ class Translator with KernelNodes { ); } - bool canSkipImplicitCheck(VariableDeclaration node) { + bool canSkipImplicitCheck(Variable node) { return inferredArgTypeMetadata[node]?.skipCheck ?? false; } @@ -1955,7 +1952,7 @@ class Translator with KernelNodes { return inferredTypeMetadata[node]?.skipCheck ?? false; } - DartType typeOfParameterVariable(VariableDeclaration node, bool isRequired) { + DartType typeOfParameterVariable(Variable node, bool isRequired) { // We have a guarantee that inferred types are correct. final inferredType = _inferredTypeOfParameterVariable(node); if (inferredType != null) { @@ -1984,7 +1981,7 @@ class Translator with KernelNodes { // The type to use assuming the argument was already checked (in case a // covariant check is needed). - DartType typeOfCheckedParameterVariable(VariableDeclaration node) { + DartType typeOfCheckedParameterVariable(Variable node) { // We have a guarantee that inferred types are correct. final inferredType = _inferredTypeOfParameterVariable(node); if (inferredType != null) { @@ -2004,10 +2001,7 @@ class Translator with KernelNodes { return _inferredTypeOfField(node) ?? node.type; } - w.ValueType translateTypeOfParameter( - VariableDeclaration node, - bool isRequired, - ) { + w.ValueType translateTypeOfParameter(Variable node, bool isRequired) { return translateType(typeOfParameterVariable(node, isRequired)); } @@ -2015,7 +2009,7 @@ class Translator with KernelNodes { return translateType(typeOfField(node)); } - w.ValueType translateTypeOfLocalVariable(VariableDeclaration node) { + w.ValueType translateTypeOfLocalVariable(Variable node) { DartType dartType = _inferredTypeOfLocalVariable(node) ?? node.type; if (dartType is InterfaceType) { final info = classInfo[dartType.classNode]; @@ -2030,7 +2024,7 @@ class Translator with KernelNodes { return translateType(dartType); } - DartType? _inferredTypeOfParameterVariable(VariableDeclaration node) { + DartType? _inferredTypeOfParameterVariable(Variable node) { return _filterInferredType(node.type, inferredArgTypeMetadata[node]); } @@ -2045,7 +2039,7 @@ class Translator with KernelNodes { return _filterInferredType(node.type, inferredTypeMetadata[node]); } - DartType? _inferredTypeOfLocalVariable(VariableDeclaration node) { + DartType? _inferredTypeOfLocalVariable(Variable node) { InferredType? inferredType = inferredTypeMetadata[node]; if (node.isFinal) { inferredType ??= inferredTypeMetadata[node.initializer]; diff --git a/pkg/dev_compiler/lib/src/command/command.dart b/pkg/dev_compiler/lib/src/command/command.dart index 87090bd324a..654685b5ece 100644 --- a/pkg/dev_compiler/lib/src/command/command.dart +++ b/pkg/dev_compiler/lib/src/command/command.dart @@ -914,7 +914,7 @@ ModuleSymbols _emitSymbols( for (var e in compiler.procedureIdentifiers.entries) e.key: lookupName(e.value), }; - var variableJsNames = { + var variableJsNames = { for (var e in compiler.variableIdentifiers.entries) e.key: lookupName(e.value), }; diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 4b0780095bb..ddf15a58838 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -67,7 +67,7 @@ abstract class Compiler { Map get classIdentifiers; Map get memberNames; Map get procedureIdentifiers; - Map get variableIdentifiers; + Map get variableIdentifiers; js_ast.Fun emitFunctionIncremental( List items, Library library, @@ -134,16 +134,16 @@ class ProgramCompiler extends ComputeOnceConstantVisitor /// This mapping is used when generating the symbol information for the /// module. @override - final variableIdentifiers = {}; + final variableIdentifiers = {}; /// Identifiers for kernel variables with an analogous identifier in JS. /// - /// [VariableDeclaration.name] is not necessarily a safe identifier for JS + /// [Variable.name] is not necessarily a safe identifier for JS /// transpiled code. The same name can be used in shadowing contexts. We map /// each kernel variable to a [js_ast.ScopedId] so that at code emission /// time, declarations that would be shadowed are given a unique name. If /// there is no risk of shadowing, the original name will be used. - final Map _variableTempIds = {}; + final Map _variableTempIds = {}; /// Maps a library URI import, that is not in [_libraries], to the /// corresponding Kernel summary module we imported it with. @@ -157,12 +157,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor final Map _summaryToModule; /// The variable for the current catch clause - VariableDeclaration? _rethrowParameter; + Variable? _rethrowParameter; Set? _pendingClasses; /// Temporary variables mapped to their corresponding JavaScript variable. - final _tempVariables = {}; + final _tempVariables = {}; /// Let variables collected for the given function. List? _letVariables; @@ -2062,13 +2062,13 @@ class ProgramCompiler extends ComputeOnceConstantVisitor namedParameter.name: namedParameter, }; DartType reifyParameter( - VariableDeclaration parameter, + Variable parameter, DartType fComputedParameter, ) => isCovariantParameter(parameter) ? _coreTypes.objectNullableRawType : fComputedParameter; NamedType reifyNamedParameter( - VariableDeclaration parameter, + Variable parameter, NamedType fComputedNamedParameter, ) { assert(parameter.name == fComputedNamedParameter.name); @@ -2271,7 +2271,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor if (init is LocalInitializer) { // Temporary locals are created when named arguments don't appear at // the end of the arguments list. - jsInitializers.add(visitVariableDeclaration(init.variable)); + jsInitializers.add(visitVariable(init.variable)); } else if (init is RedirectingInitializer) { var rtiParam = _requiresRtiForInstantiation(init.target.enclosingClass) ? _rtiParam @@ -2401,7 +2401,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor if (init is FieldInitializer) { emitFieldInit(init.field, init.value, init); } else if (init is LocalInitializer) { - body.add(visitVariableDeclaration(init.variable)); + body.add(visitVariable(init.variable)); } else if (init is AssertInitializer) { body.add(visitAssertStatement(init.statement)); } @@ -4194,7 +4194,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor } js_ast.Parameter _emitParameter( - VariableDeclaration node, { + Variable node, { bool withoutInitializer = false, }) { var initializer = node.initializer; @@ -4296,11 +4296,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor _emitCovarianceBoundsCheck(f.typeParameters, body); - void initParameter( - VariableDeclaration p, - js_ast.Identifier jsParam, - bool isOptional, - ) { + void initParameter(Variable p, js_ast.Identifier jsParam, bool isOptional) { // When the parameter is covariant, insert the null check before the // covariant cast to avoid a TypeError when testing equality with null. if (name == '==') { @@ -4394,7 +4390,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor return js.statement('if (# == null) #;', [param, call]); } - js_ast.Expression _defaultParamValue(VariableDeclaration p) { + js_ast.Expression _defaultParamValue(Variable p) { if (p.initializer != null) { return _visitExpression(p.initializer!); } else { @@ -5300,7 +5296,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor js_ast.Catch? _visitCatch(List clauses) { if (clauses.isEmpty) return null; - var caughtError = VariableDeclaration('#e', isSynthesized: true); + var caughtError = Variable('#e', isSynthesized: true); var savedRethrow = _rethrowParameter; _rethrowParameter = caughtError; @@ -5308,12 +5304,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor // don't shadow any names. var exceptionParameter = (clauses.length == 1 ? clauses[0].exception : null) ?? - VariableDeclaration('#ex', isSynthesized: true); + Variable('#ex', isSynthesized: true); var stackTraceParameter = (clauses.length == 1 ? clauses[0].stackTrace : null) ?? (clauses.any((c) => c.stackTrace != null) - ? VariableDeclaration('#st', isSynthesized: true) + ? Variable('#st', isSynthesized: true) : null); js_ast.Statement catchBody = js_ast.Throw(_emitVariableRef(caughtError)); @@ -5347,16 +5343,13 @@ class ProgramCompiler extends ComputeOnceConstantVisitor js_ast.Statement _catchClauseGuard( Catch node, js_ast.Statement otherwise, - VariableDeclaration exceptionParameter, - VariableDeclaration? stackTraceParameter, + Variable exceptionParameter, + Variable? stackTraceParameter, ) { var body = []; var vars = HashSet(); - void declareVariable( - VariableDeclaration? variable, - VariableDeclaration? value, - ) { + void declareVariable(Variable? variable, Variable? value) { if (variable == null || value == null) return; vars.add(variable.name!); if (variable.name != value.name) { @@ -5412,7 +5405,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor } @override - js_ast.Statement visitVariableDeclaration(VariableDeclaration node) { + js_ast.Statement visitVariable(Variable node) { // TODO(jmesserly): casts are sometimes required here. // Kernel does not represent these explicitly. var v = _emitVariableDef(node); @@ -5464,7 +5457,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor /// Detects temporary variables so we can avoid displaying /// them in the debugger if needed. - bool _isTemporaryVariable(VariableDeclaration v) { + bool _isTemporaryVariable(Variable v) { // Late local variables are be exposed to the debugger for inspection and // evaluation by treating the backing store local variable as a regular // non-temporary variable. @@ -5478,7 +5471,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor /// Creates a temporary name recognized by the debugger. /// Assumes `_isTemporaryVariable(v)` is true. - String? _debuggerFriendlyTemporaryVariableName(VariableDeclaration v) { + String? _debuggerFriendlyTemporaryVariableName(Variable v) { assert(_isTemporaryVariable(v)); // Show extension 'this' in the debugger. @@ -5491,7 +5484,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor return null; } - js_ast.ScopedId _emitVariableRef(VariableDeclaration v) { + js_ast.ScopedId _emitVariableRef(Variable v) { if (_isTemporaryVariable(v)) { var name = _debuggerFriendlyTemporaryVariableName(v); name ??= 't\$${_tempVariables.length}'; @@ -5517,7 +5510,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor /// /// This is similar to [_emitVariableRef] but it also attaches source /// location information, so hover will work as expected. - js_ast.Identifier _emitVariableDef(VariableDeclaration v) { + js_ast.Identifier _emitVariableDef(Variable v) { var identifier = _emitVariableRef(v)..sourceInformation = _nodeStart(v); variableIdentifiers[v] = identifier; return identifier; @@ -6732,7 +6725,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor var replacementArguments = node.arguments.positional; var replacements = { for (var i = 0; i < originalParameters.length; i++) - originalParameters[i].accept(cloner) as VariableDeclaration: + originalParameters[i].accept(cloner) as Variable: replacementArguments[i], }; // Clone the body using the same cloner to ensure the cloned parameters diff --git a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart index 200cbf49dec..100911d774b 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart @@ -101,7 +101,7 @@ class SymbolData { /// /// This mapping is used when generating the symbol information for the /// module. - final variableIdentifiers = {}; + final variableIdentifiers = {}; } /// Compiles a kernel [Component] to a bundle of individual libraries. @@ -134,7 +134,7 @@ class LibraryBundleCompiler implements old.Compiler { Map get procedureIdentifiers => _symbolData.procedureIdentifiers; @override - Map get variableIdentifiers => + Map get variableIdentifiers => _symbolData.variableIdentifiers; @override @@ -333,17 +333,17 @@ class LibraryCompiler extends ComputeOnceConstantVisitor /// /// This mapping is used when generating the symbol information for the /// module. - Map get variableIdentifiers => + Map get variableIdentifiers => _symbolData.variableIdentifiers; /// Identifiers for kernel variables with an analogous identifier in JS. /// - /// [VariableDeclaration.name] is not necessarily a safe identifier for JS + /// [Variable.name] is not necessarily a safe identifier for JS /// transpiled code. The same name can be used in shadowing contexts. We map /// each kernel variable to a [js_ast.ScopedId] so that at code emission /// time, references that would be shadowed are given a unique name. If there /// is no risk of shadowing, the original name will be used. - final Map _variableTempIds = {}; + final Map _variableTempIds = {}; /// Maps a library URI import, that is not in [_libraries], to the /// corresponding Kernel summary module we imported it with. @@ -357,10 +357,10 @@ class LibraryCompiler extends ComputeOnceConstantVisitor final Map _summaryToModule; /// The variable for the current catch clause - VariableDeclaration? _rethrowParameter; + Variable? _rethrowParameter; /// Temporary variables mapped to their corresponding JavaScript variable. - final _tempVariables = {}; + final _tempVariables = {}; /// Let variables collected for the given function. List? _letVariables; @@ -2366,13 +2366,13 @@ class LibraryCompiler extends ComputeOnceConstantVisitor namedParameter.name: namedParameter, }; DartType reifyParameter( - VariableDeclaration parameter, + Variable parameter, DartType fComputedParameter, ) => isCovariantParameter(parameter) ? _coreTypes.objectNullableRawType : fComputedParameter; NamedType reifyNamedParameter( - VariableDeclaration parameter, + Variable parameter, NamedType fComputedNamedParameter, ) { assert(parameter.name == fComputedNamedParameter.name); @@ -2575,7 +2575,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor if (init is LocalInitializer) { // Temporary locals are created when named arguments don't appear at // the end of the arguments list. - jsInitializers.add(visitVariableDeclaration(init.variable)); + jsInitializers.add(visitVariable(init.variable)); } else if (init is RedirectingInitializer) { var rtiParam = _requiresRtiForInstantiation(init.target.enclosingClass) ? _rtiParam @@ -2711,7 +2711,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor if (init is FieldInitializer) { body.add(_emitFieldInit(init.field, init.value, init)); } else if (init is LocalInitializer) { - body.add(visitVariableDeclaration(init.variable)); + body.add(visitVariable(init.variable)); } else if (init is AssertInitializer) { body.add(visitAssertStatement(init.statement)); } @@ -4794,7 +4794,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor } js_ast.Parameter _emitParameter( - VariableDeclaration node, { + Variable node, { bool withoutInitializer = false, }) { var initializer = node.initializer; @@ -4896,11 +4896,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor _emitCovarianceBoundsCheck(f.typeParameters, body); - void initParameter( - VariableDeclaration p, - js_ast.Identifier jsParam, - bool isOptional, - ) { + void initParameter(Variable p, js_ast.Identifier jsParam, bool isOptional) { // When the parameter is covariant, insert the null check before the // covariant cast to avoid a TypeError when testing equality with null. if (name == '==') { @@ -4994,7 +4990,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor return js.statement('if (# == null) #;', [param, call]); } - js_ast.Expression _defaultParamValue(VariableDeclaration p) { + js_ast.Expression _defaultParamValue(Variable p) { if (p.initializer != null) { return _visitExpression(p.initializer!); } else { @@ -5914,7 +5910,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor js_ast.Catch? _visitCatch(List clauses) { if (clauses.isEmpty) return null; - var caughtError = VariableDeclaration('#e', isSynthesized: true); + var caughtError = Variable('#e', isSynthesized: true); var savedRethrow = _rethrowParameter; _rethrowParameter = caughtError; @@ -5922,12 +5918,12 @@ class LibraryCompiler extends ComputeOnceConstantVisitor // don't shadow any names. var exceptionParameter = (clauses.length == 1 ? clauses[0].exception : null) ?? - VariableDeclaration('#ex', isSynthesized: true); + Variable('#ex', isSynthesized: true); var stackTraceParameter = (clauses.length == 1 ? clauses[0].stackTrace : null) ?? (clauses.any((c) => c.stackTrace != null) - ? VariableDeclaration('#st', isSynthesized: true) + ? Variable('#st', isSynthesized: true) : null); js_ast.Statement catchBody = js_ast.Throw(_emitVariableRef(caughtError)); @@ -5961,16 +5957,13 @@ class LibraryCompiler extends ComputeOnceConstantVisitor js_ast.Statement _catchClauseGuard( Catch node, js_ast.Statement otherwise, - VariableDeclaration exceptionParameter, - VariableDeclaration? stackTraceParameter, + Variable exceptionParameter, + Variable? stackTraceParameter, ) { var body = []; var vars = HashSet(); - void declareVariable( - VariableDeclaration? variable, - VariableDeclaration? value, - ) { + void declareVariable(Variable? variable, Variable? value) { if (variable == null || value == null) return; vars.add(variable.name!); if (variable.name != value.name) { @@ -6026,7 +6019,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor } @override - js_ast.Statement visitVariableDeclaration(VariableDeclaration node) { + js_ast.Statement visitVariable(Variable node) { // TODO(jmesserly): casts are sometimes required here. // Kernel does not represent these explicitly. var v = _emitVariableDef(node); @@ -6078,7 +6071,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor /// Detects temporary variables so we can avoid displaying /// them in the debugger if needed. - bool _isTemporaryVariable(VariableDeclaration v) { + bool _isTemporaryVariable(Variable v) { // Late local variables are be exposed to the debugger for inspection and // evaluation by treating the backing store local variable as a regular // non-temporary variable. @@ -6092,7 +6085,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor /// Creates a temporary name recognized by the debugger. /// Assumes `_isTemporaryVariable(v)` is true. - String? _debuggerFriendlyTemporaryVariableName(VariableDeclaration v) { + String? _debuggerFriendlyTemporaryVariableName(Variable v) { assert(_isTemporaryVariable(v)); // Show extension 'this' in the debugger. @@ -6105,7 +6098,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor return null; } - js_ast.ScopedId _emitVariableRef(VariableDeclaration v) { + js_ast.ScopedId _emitVariableRef(Variable v) { if (_isTemporaryVariable(v)) { var name = _debuggerFriendlyTemporaryVariableName(v); name ??= 't\$${_tempVariables.length}'; @@ -6131,7 +6124,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor /// /// This is similar to [_emitVariableRef] but it also attaches source /// location information, so hover will work as expected. - js_ast.Identifier _emitVariableDef(VariableDeclaration v) { + js_ast.Identifier _emitVariableDef(Variable v) { var identifier = _emitVariableRef(v)..sourceInformation = _nodeStart(v); variableIdentifiers[v] = identifier; return identifier; @@ -7425,7 +7418,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor var replacementArguments = node.arguments.positional; var replacements = { for (var i = 0; i < originalParameters.length; i++) - originalParameters[i].accept(cloner) as VariableDeclaration: + originalParameters[i].accept(cloner) as Variable: replacementArguments[i], }; // Clone the body using the same cloner to ensure the cloned parameters diff --git a/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart b/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart index efdbc43dffa..d2ec2e54e6e 100644 --- a/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart +++ b/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart @@ -207,7 +207,7 @@ bool _isProcedureFromForeignHelper(String name, Procedure p) => /// Whether the parameter [p] is covariant (either explicitly `covariant` or /// implicitly due to generics) and needs a check for soundness. -bool isCovariantParameter(VariableDeclaration p) { +bool isCovariantParameter(Variable p) { return p.isCovariantByDeclaration || p.isCovariantByClass; } @@ -420,7 +420,7 @@ class InterfaceTypeExtractor extends RecursiveVisitor { /// Replaces [VariableGet] nodes with a different expression defined by a /// replacement map. class VariableGetReplacer extends Transformer { - final Map _replacements; + final Map _replacements; VariableGetReplacer(this._replacements); @@ -460,7 +460,7 @@ class BasicInlineTester extends TreeVisitorDefault { /// /// This is essential to preserve the execution order of the expressions /// passed as arguments. - List? _expectedArgumentOrder; + List? _expectedArgumentOrder; /// The position in [_expectedArgumentOrder] to begin looking for the next /// used argument. diff --git a/pkg/dev_compiler/lib/src/kernel/module_symbols_collector.dart b/pkg/dev_compiler/lib/src/kernel/module_symbols_collector.dart index 1de9e3ab4d2..d9b277b56a2 100644 --- a/pkg/dev_compiler/lib/src/kernel/module_symbols_collector.dart +++ b/pkg/dev_compiler/lib/src/kernel/module_symbols_collector.dart @@ -19,7 +19,7 @@ class ModuleSymbolsCollector extends RecursiveVisitor { final Map _classJsNames; final Map _memberJsNames; final Map _procedureJsNames; - final Map _variableJsNames; + final Map _variableJsNames; ModuleSymbolsCollector( String moduleName, @@ -187,7 +187,7 @@ class ModuleSymbolsCollector extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { var kind = node.isInitializingFormal ? VariableSymbolKind.formal : VariableSymbolKind.local; @@ -198,7 +198,7 @@ class ModuleSymbolsCollector extends RecursiveVisitor { } VariableSymbol _createVariableSymbol( - VariableDeclaration node, + Variable node, VariableSymbolKind kind, ) => VariableSymbol( name: node.name!, diff --git a/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart b/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart index 7569c3d05d3..75338986413 100644 --- a/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart +++ b/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart @@ -364,13 +364,12 @@ class _NullableVariableInference extends RecursiveVisitor { late NullableInference _nullInference; /// Variables that are currently believed to be not-null. - final _notNullLocals = HashSet.identity(); + final _notNullLocals = HashSet.identity(); /// For each variable currently believed to be not-null ([_notNullLocals]), /// this collects variables that it is assigned to, so we update them if we /// later determine that the variable can be null. - final _assignedTo = - HashMap>.identity(); + final _assignedTo = HashMap>.identity(); /// All functions that have been analyzed with [analyzeFunction]. /// @@ -380,7 +379,7 @@ class _NullableVariableInference extends RecursiveVisitor { /// The current variable we are setting/initializing, so we can track if it /// is [_assignedTo] from another variable. - VariableDeclaration? _variableAssignedTo; + Variable? _variableAssignedTo; void enterFunction(FunctionNode node) { if (_functions.contains(node)) return; // local function already analyzed. @@ -417,7 +416,7 @@ class _NullableVariableInference extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { if (_nullInference.allowNotNullDeclarations) { var annotations = node.annotations; if (annotations.isNotEmpty && @@ -458,7 +457,7 @@ class _NullableVariableInference extends RecursiveVisitor { _variableAssignedTo = variable; if (_nullInference.isNullable(node.value)) { - void markNullable(VariableDeclaration? v) { + void markNullable(Variable? v) { _notNullLocals.remove(v); _assignedTo.remove(v)?.forEach(markNullable); } @@ -471,7 +470,7 @@ class _NullableVariableInference extends RecursiveVisitor { value.accept(this); } - bool variableIsNullable(VariableDeclaration variable) { + bool variableIsNullable(Variable variable) { if (_notNullLocals.contains(variable)) { if (_variableAssignedTo != null) { _assignedTo.putIfAbsent(variable, () => []).add(_variableAssignedTo!); diff --git a/pkg/dev_compiler/lib/src/kernel/target.dart b/pkg/dev_compiler/lib/src/kernel/target.dart index 078257ba7cf..9a80616ab7d 100644 --- a/pkg/dev_compiler/lib/src/kernel/target.dart +++ b/pkg/dev_compiler/lib/src/kernel/target.dart @@ -445,7 +445,7 @@ class _CovarianceTransformer extends RecursiveVisitor { field.isCovariantByClass = false; } } - void clearCovariant(VariableDeclaration parameter) { + void clearCovariant(Variable parameter) { parameter.isCovariantByDeclaration = false; parameter.isCovariantByClass = false; } 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 7fb1228ddc1..aa162ccf814 100644 --- a/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart +++ b/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart @@ -532,7 +532,7 @@ Field? getLateFieldTarget(Member node) { /// where '#local' is the local variable holding that value. /// /// The default value of this variable is `null`. -bool isLateLoweredLocal(VariableDeclaration node) { +bool isLateLoweredLocal(Variable node) { return node.isLowered && isLateLoweredLocalName(node.name!); } @@ -578,7 +578,7 @@ String extractLocalNameFromLateLoweredLocal(String name) { /// where '#local#isSet' is the local variable holding the marker. /// /// The default value of this variable is `false`. -bool isLateLoweredIsSetLocal(VariableDeclaration node) { +bool isLateLoweredIsSetLocal(Variable node) { return node.isLowered && isLateLoweredIsSetLocalName(node.name!); } @@ -619,7 +619,7 @@ String extractLocalNameFromLateLoweredIsSet(String name) { /// } /// /// where '#local#get' is the local function for reading the variable. -bool isLateLoweredLocalGetter(VariableDeclaration node) { +bool isLateLoweredLocalGetter(Variable node) { return node.isLowered && isLateLoweredLocalGetterName(node.name!); } @@ -662,7 +662,7 @@ String extractLocalNameFromLateLoweredGetter(String name) { /// /// where '#local#set' is the local function for setting the value of the /// variable. -bool isLateLoweredLocalSetter(VariableDeclaration node) { +bool isLateLoweredLocalSetter(Variable node) { return node.isLowered && isLateLoweredLocalSetterName(node.name!); } @@ -701,7 +701,7 @@ String extractLocalNameFromLateLoweredSetter(String name) { /// int Extension|method(int #this) => #this; /// /// where '#this' is the synthetic "extension this" parameter. -bool isExtensionThis(VariableDeclaration node) { +bool isExtensionThis(Variable node) { assert( node.isLowered || node.cosmeticName == null || @@ -732,7 +732,7 @@ bool hasUnnamedExtensionNamePrefix(String? name) { // Coverage-ignore(suite): Not run. /// Return `true` if [node] is the synthetic parameter holding the `this` value /// in the encoding of extension type instance members and constructors. -bool isExtensionTypeThis(VariableDeclaration node) { +bool isExtensionTypeThis(Variable node) { return node.isLowered && isExtensionTypeThisName(node.name); } @@ -762,7 +762,7 @@ String extractLocalNameForExtensionThis(String name) { /// /// Note that the name can be `null` in case of a synthetic variable created /// for instance for encoding of `?.`. -String? extractLocalNameFromVariable(VariableDeclaration node) { +String? extractLocalNameFromVariable(Variable node) { if (node.isLowered) { String? name = _extractLocalName(node.name!); if (name == null) { @@ -814,7 +814,7 @@ const String joinedIntermediateInfix = "#case#"; /// Returns `true` if [node] is a joined intermediate variable. /// /// See [isJoinedIntermediateName] for details. -bool isJoinedIntermediateVariable(VariableDeclaration node) { +bool isJoinedIntermediateVariable(Variable node) { return node.isLowered && node.name != null && isJoinedIntermediateName(node.name!); diff --git a/pkg/front_end/lib/src/base/incremental_compiler.dart b/pkg/front_end/lib/src/base/incremental_compiler.dart index ab08af88269..9563f15e24c 100644 --- a/pkg/front_end/lib/src/base/incremental_compiler.dart +++ b/pkg/front_end/lib/src/base/incremental_compiler.dart @@ -53,7 +53,7 @@ import 'package:kernel/kernel.dart' TreeNode, TypeParameter, TypeParameterType, - VariableDeclaration, + Variable, VisitorDefault, VisitorVoidMixin; import 'package:kernel/kernel.dart' as kernel show Combinator; @@ -1923,8 +1923,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { // overwrite as well because that mostly means that the value is // currently null. This can also mean that the VM can't send over the // information - this for instance happens for function types. - for (MapEntry def - in foundScope.variables.entries) { + for (MapEntry def in foundScope.variables.entries) { DartType? existingType = usedDefinitions[def.key]; if (existingType == null) { // We found a variable, but we weren't told about it. @@ -2044,7 +2043,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { Builder? subBuilder = builder.lookupLocalMember(afterDot)?.getable; if (subBuilder is MemberBuilder) { if (subBuilder.isExtensionTypeInstanceMember) { - List? positionals = + List? positionals = subBuilder.invokeTarget?.function?.positionalParameters; if (positionals != null && positionals.isNotEmpty && @@ -2217,7 +2216,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { MemoryFileSystem fs = hfs.memory; fs.entityForUri(debugExprUri).writeAsStringSync(expression); - VariableDeclaration? extensionThis; + Variable? extensionThis; // TODO: pass variable declarations instead of // parameter names for proper location detection. @@ -2225,7 +2224,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { FunctionNode parameters = new FunctionNode( null, typeParameters: typeDefinitions, - positionalParameters: usedDefinitions.entries.map(( + positionalParameters: usedDefinitions.entries.map(( MapEntry def, ) { VariableDeclarationImpl variable = new VariableDeclarationImpl( 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 bd03f8d1ea9..42fff6ef6f0 100644 --- a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart +++ b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart @@ -6,12 +6,7 @@ import 'package:_fe_analyzer_shared/src/parser/formal_parameter_kind.dart' show FormalParameterKind; import 'package:_fe_analyzer_shared/src/scanner/scanner.dart' show Token; import 'package:kernel/ast.dart' - show - DartType, - DynamicType, - Expression, - InvalidExpression, - VariableDeclaration; + show DartType, DynamicType, Expression, InvalidExpression, Variable; import 'package:kernel/class_hierarchy.dart'; import '../base/extension_scope.dart'; @@ -149,10 +144,10 @@ class CatchParameterBuilder extends NamedBuilderImpl NamedBuilder? get setable => isAssignable ? this : null; @override - VariableDeclaration get variable => _variable!.asVariableDeclaration; + Variable get variable => _variable!.asVariableDeclaration; @override - VariableDeclaration build(SourceLibraryBuilder library) { + Variable build(SourceLibraryBuilder library) { if (_variable == null) { bool isTypeOmitted = type is OmittedTypeBuilder; DartType? builtType = type.build(library, TypeUse.parameterType); @@ -244,7 +239,7 @@ class FormalParameterBuilder extends NamedBuilderImpl final FormalParameterKind kind; /// The variable declaration created for this formal parameter. - VariableDeclaration? _variable; + Variable? _variable; /// The first token of the default value, if any. /// @@ -289,7 +284,7 @@ class FormalParameterBuilder extends NamedBuilderImpl required this.nameOffset, required this.isClosureContextLoweringEnabled, this.isPrimaryConstructorParameter = false, - VariableDeclaration? variable, + Variable? variable, }) : this.hasDeclaredInitializer = hasImmediatelyDeclaredInitializer, this._defaultValueToken = defaultValueToken, this._wildcardIndex = wildcardIndex, @@ -305,7 +300,7 @@ class FormalParameterBuilder extends NamedBuilderImpl NamedBuilder get getable => this; // An initializing formal parameter might be final without its - // VariableDeclaration being final. See + // [Variable] being final. See // [ProcedureBuilder.computeFormalParameterInitializerScope].. @override bool get isAssignable => @@ -357,10 +352,10 @@ class FormalParameterBuilder extends NamedBuilderImpl NamedBuilder? get setable => isAssignable ? this : null; @override - VariableDeclaration get variable => _variable!.asVariableDeclaration; + Variable get variable => _variable!.asVariableDeclaration; @override - VariableDeclaration build(SourceLibraryBuilder library) { + Variable build(SourceLibraryBuilder library) { if (_variable == null) { bool isTypeOmitted = type is OmittedTypeBuilder; DartType? builtType = type.build(library, TypeUse.parameterType); @@ -629,7 +624,7 @@ class FunctionTypeParameterBuilder implements ParameterBuilder { bool get isWildcard => false; @override - VariableDeclaration build(SourceLibraryBuilder library) { + Variable build(SourceLibraryBuilder library) { throw new UnsupportedError("${this.runtimeType}.build"); } } @@ -656,7 +651,7 @@ abstract class ParameterBuilder { TypeBuilder get type; - VariableDeclaration build(SourceLibraryBuilder library); + Variable build(SourceLibraryBuilder library); } abstract class ParameterVariableBuilder diff --git a/pkg/front_end/lib/src/builder/function_signature.dart b/pkg/front_end/lib/src/builder/function_signature.dart index ce0ad5ad314..809666c974c 100644 --- a/pkg/front_end/lib/src/builder/function_signature.dart +++ b/pkg/front_end/lib/src/builder/function_signature.dart @@ -28,7 +28,7 @@ class FunctionNodeSignature implements FunctionSignature { @override Map get namedParameters { Map map = {}; - for (VariableDeclaration formal in _function.namedParameters) { + for (Variable formal in _function.namedParameters) { map[formal.name!] = ( type: formal.type, hasDeclaredInitializer: formal.hasDeclaredInitializer, @@ -40,7 +40,7 @@ class FunctionNodeSignature implements FunctionSignature { @override List get positionalParameters { List list = []; - for (VariableDeclaration formal in _function.positionalParameters) { + for (Variable formal in _function.positionalParameters) { list.add(( type: formal.type, hasDeclaredInitializer: formal.hasDeclaredInitializer, diff --git a/pkg/front_end/lib/src/builder/variable_builder.dart b/pkg/front_end/lib/src/builder/variable_builder.dart index 679bb08ad7c..1c5e2b8c4af 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 VariableDeclaration; +import 'package:kernel/ast.dart' show Variable; import '../base/lookup_result.dart'; import '../builder/builder.dart'; abstract class VariableBuilder implements Builder, LookupResult { - VariableDeclaration get variable; + Variable get variable; bool get isConst; diff --git a/pkg/front_end/lib/src/fragment/constructor.dart b/pkg/front_end/lib/src/fragment/constructor.dart index a53c5758e0a..54e28fafecf 100644 --- a/pkg/front_end/lib/src/fragment/constructor.dart +++ b/pkg/front_end/lib/src/fragment/constructor.dart @@ -146,7 +146,7 @@ class _ConstructorBodyBuildingContext implements FunctionBodyBuildingContext { _fragment.declaration.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _fragment.declaration.thisVariable; + Variable? get thisVariable => _fragment.declaration.thisVariable; @override ExtensionScope get extensionScope { diff --git a/pkg/front_end/lib/src/fragment/constructor/body_builder_context.dart b/pkg/front_end/lib/src/fragment/constructor/body_builder_context.dart index 11a47cae671..2d594a4809d 100644 --- a/pkg/front_end/lib/src/fragment/constructor/body_builder_context.dart +++ b/pkg/front_end/lib/src/fragment/constructor/body_builder_context.dart @@ -49,7 +49,7 @@ class ConstructorBodyBuilderContext extends BodyBuilderContext { } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { return _declaration.getTearOffParameter(index); } @@ -110,7 +110,7 @@ class ConstructorBodyBuilderContext extends BodyBuilderContext { required TypeInferrer typeInferrer, required Uri fileUri, required Initializer initializer, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, diff --git a/pkg/front_end/lib/src/fragment/constructor/declaration.dart b/pkg/front_end/lib/src/fragment/constructor/declaration.dart index aac17721dfe..b50b25a22a4 100644 --- a/pkg/front_end/lib/src/fragment/constructor/declaration.dart +++ b/pkg/front_end/lib/src/fragment/constructor/declaration.dart @@ -745,7 +745,7 @@ mixin _ConstructorEncodingMixin } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { return _encoding.getTearOffParameter(index); } @@ -755,7 +755,7 @@ mixin _ConstructorEncodingMixin } @override - VariableDeclaration? get thisVariable => _encoding.thisVariable; + Variable? get thisVariable => _encoding.thisVariable; @override List? get thisTypeParameters => _encoding.thisTypeParameters; @@ -764,7 +764,7 @@ mixin _ConstructorEncodingMixin void registerFunctionBody( Statement? body, Scope? scope, - VariableDeclaration? thisVariable, + Variable? thisVariable, ) { _encoding.registerFunctionBody( body: body, @@ -1471,20 +1471,20 @@ abstract class ConstructorFragmentDeclaration { void registerFunctionBody( Statement? body, Scope? scope, - VariableDeclaration? thisVariable, + Variable? thisVariable, ); void registerNoBodyConstructor(); - VariableDeclaration? get thisVariable; + Variable? get thisVariable; List? get thisTypeParameters; void becomeNative(SourceLoader loader); - /// Returns the [VariableDeclaration] for the tear off, if any, of the + /// Returns the [Variable] for the tear off, if any, of the /// [index]th formal parameter declared in the constructor. - VariableDeclaration? getTearOffParameter(int index); + Variable? getTearOffParameter(int index); LocalScope computeFormalParameterScope(LookupScope parent); diff --git a/pkg/front_end/lib/src/fragment/constructor/encoding.dart b/pkg/front_end/lib/src/fragment/constructor/encoding.dart index 83f3a8b29fa..194b3bb5fa9 100644 --- a/pkg/front_end/lib/src/fragment/constructor/encoding.dart +++ b/pkg/front_end/lib/src/fragment/constructor/encoding.dart @@ -45,9 +45,9 @@ abstract class ConstructorEncoding { void prependInitializer(Initializer initializer); - VariableDeclaration? getTearOffParameter(int index); + Variable? getTearOffParameter(int index); - VariableDeclaration? get thisVariable; + Variable? get thisVariable; List? get thisTypeParameters; @@ -92,7 +92,7 @@ abstract class ConstructorEncoding { void registerFunctionBody({ required Statement? body, Scope? scope, - VariableDeclaration? thisVariable, + Variable? thisVariable, }); void registerNoBodyConstructor(); @@ -140,7 +140,7 @@ class RegularConstructorEncoding implements ConstructorEncoding { void registerFunctionBody({ required Statement? body, Scope? scope, - VariableDeclaration? thisVariable, + Variable? thisVariable, }) { if (body != null) { _constructor.function.registerFunctionBody(body); @@ -195,7 +195,7 @@ class RegularConstructorEncoding implements ConstructorEncoding { } @override - VariableDeclaration? get thisVariable => null; + Variable? get thisVariable => null; @override List? get thisTypeParameters => null; @@ -401,7 +401,7 @@ class RegularConstructorEncoding implements ConstructorEncoding { } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { Procedure? constructorTearOff = _constructorTearOff; if (constructorTearOff != null) { if (index < constructorTearOff.function.positionalParameters.length) { @@ -504,7 +504,7 @@ mixin _ExtensionTypeConstructorEncodingMixin /// If this procedure is an extension instance member or extension type /// instance member, [_thisVariable] holds the synthetically added `this` /// parameter. - VariableDeclaration? _thisVariable; + Variable? _thisVariable; /// If this procedure is an extension instance member or extension type /// instance member, [_thisTypeParameters] holds the type parameters copied @@ -529,7 +529,7 @@ mixin _ExtensionTypeConstructorEncodingMixin void registerFunctionBody({ required Statement? body, Scope? scope, - VariableDeclaration? thisVariable, + Variable? thisVariable, }) { if (body != null) { _constructor.function.registerFunctionBody(body); @@ -703,7 +703,7 @@ mixin _ExtensionTypeConstructorEncodingMixin } @override - VariableDeclaration? get thisVariable { + Variable? get thisVariable { assert( _thisVariable != null, "ProcedureBuilder.thisVariable has not been set.", @@ -748,7 +748,7 @@ mixin _ExtensionTypeConstructorEncodingMixin } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { Procedure? constructorTearOff = _constructorTearOff; if (constructorTearOff != null) { if (index < constructorTearOff.function.positionalParameters.length) { @@ -771,7 +771,7 @@ mixin _ExtensionTypeConstructorEncodingMixin return; } if (!_isExternal) { - VariableDeclaration thisVariable = this.thisVariable!; + Variable thisVariable = this.thisVariable!; VariableStatement thisVariableStatement = extern.createVariableStatement( thisVariable, ); @@ -1391,14 +1391,14 @@ class _RegularConstructorContext implements ConstructorContext { } @override - VariableDeclaration? get thisVariable => null; + Variable? get thisVariable => null; } class _ExtensionTypeConstructorContext implements ConstructorContext { final SourceConstructorBuilder _builder; @override - final VariableDeclaration thisVariable; + final Variable thisVariable; _ExtensionTypeConstructorContext(this._builder, this.thisVariable); diff --git a/pkg/front_end/lib/src/fragment/factory.dart b/pkg/front_end/lib/src/fragment/factory.dart index 956e7d79a56..f3055dbfae1 100644 --- a/pkg/front_end/lib/src/fragment/factory.dart +++ b/pkg/front_end/lib/src/fragment/factory.dart @@ -122,7 +122,7 @@ class _FactoryBodyBuildingContext implements FunctionBodyBuildingContext { List? get thisTypeParameters => null; @override - VariableDeclaration? get thisVariable => null; + Variable? get thisVariable => null; @override ExtensionScope get extensionScope => diff --git a/pkg/front_end/lib/src/fragment/factory/body_builder_context.dart b/pkg/front_end/lib/src/fragment/factory/body_builder_context.dart index 63c1280e234..b87f6c7db07 100644 --- a/pkg/front_end/lib/src/fragment/factory/body_builder_context.dart +++ b/pkg/front_end/lib/src/fragment/factory/body_builder_context.dart @@ -29,7 +29,7 @@ class FactoryBodyBuilderContext extends BodyBuilderContext { ); @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { return _declaration.getTearOffParameter(index); } diff --git a/pkg/front_end/lib/src/fragment/factory/declaration.dart b/pkg/front_end/lib/src/fragment/factory/declaration.dart index 378f781deac..6fe630cd53d 100644 --- a/pkg/front_end/lib/src/fragment/factory/declaration.dart +++ b/pkg/front_end/lib/src/fragment/factory/declaration.dart @@ -338,7 +338,7 @@ class FactoryDeclarationImpl } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { return _encoding.getTearOffParameter(index); } @@ -374,7 +374,7 @@ class FactoryDeclarationImpl required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { _encoding.registerFunctionBody( body: body, @@ -417,14 +417,14 @@ abstract class FactoryFragmentDeclaration { /// /// This is used to update the default value for the closure parameter when /// it has been computed for the original parameter. - VariableDeclaration? getTearOffParameter(int index); + Variable? getTearOffParameter(int index); void registerFunctionBody({ required Statement? body, required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); DartType get returnTypeContext; diff --git a/pkg/front_end/lib/src/fragment/factory/encoding.dart b/pkg/front_end/lib/src/fragment/factory/encoding.dart index 6687fb19061..b326576fde8 100644 --- a/pkg/front_end/lib/src/fragment/factory/encoding.dart +++ b/pkg/front_end/lib/src/fragment/factory/encoding.dart @@ -837,7 +837,7 @@ class FactoryEncoding implements InferredTypeListener { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { assert( asyncModifier.kind == AsyncMarker.Sync, @@ -868,7 +868,7 @@ class FactoryEncoding implements InferredTypeListener { FunctionSignature get signature => new FunctionNodeSignature(_procedure.function); - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { if (_tearOff != null) { if (index < _tearOff.function.positionalParameters.length) { return _tearOff.function.positionalParameters[index]; diff --git a/pkg/front_end/lib/src/fragment/field/encoding.dart b/pkg/front_end/lib/src/fragment/field/encoding.dart index 33a34664362..3986ea00736 100644 --- a/pkg/front_end/lib/src/fragment/field/encoding.dart +++ b/pkg/front_end/lib/src/fragment/field/encoding.dart @@ -577,7 +577,7 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding { "Type has not been computed for field ${_fragment.name}.", ); if (needsPromotion) { - VariableDeclaration variable = extern.createVariableCache( + Variable variable = extern.createVariableCache( _createFieldGet(_field!), _type!.withDeclaredNullability(Nullability.nullable), ); @@ -640,7 +640,7 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding { Reference? reference, { required bool isCovariantByDeclaration, }) { - VariableDeclaration parameter = extern.createParameterVariable( + Variable parameter = extern.createParameterVariable( "${_fragment.name}#param", isCovariantByDeclaration: isCovariantByDeclaration, fileOffset: _fragment.nameOffset, @@ -665,7 +665,7 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding { Statement _createSetterBody( CoreTypes coreTypes, String name, - VariableDeclaration parameter, + Variable parameter, ); @override @@ -929,7 +929,7 @@ mixin NonFinalLate on AbstractLateFieldEncoding { Statement _createSetterBody( CoreTypes coreTypes, String name, - VariableDeclaration parameter, + Variable parameter, ) { assert(_type != null, "Type has not been computed for field $name."); return late_lowering.createSetterBody( @@ -1039,7 +1039,7 @@ class LateFinalFieldWithoutInitializerEncoding extends AbstractLateFieldEncoding Statement _createSetterBody( CoreTypes coreTypes, String name, - VariableDeclaration parameter, + Variable parameter, ) { assert(_type != null, "Type has not been computed for field $name."); return late_lowering.createSetterBodyFinal( @@ -1104,7 +1104,7 @@ class LateFinalFieldWithInitializerEncoding extends AbstractLateFieldEncoding { Statement _createSetterBody( CoreTypes coreTypes, String name, - VariableDeclaration parameter, + Variable parameter, ) => throw new UnsupportedError( '$runtimeType._createSetterBody is not supported.', ); @@ -1288,7 +1288,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding { .getProcedureMemberName(ProcedureKind.Getter, _fragment.name) .attachMember(_getter!); if (_fragment.hasSetter) { - VariableDeclaration parameter = extern.createParameterVariable( + Variable parameter = extern.createParameterVariable( "#externalFieldValue", isSynthesized: true, isCovariantByDeclaration: _fragment.modifiers.isCovariant, @@ -1342,7 +1342,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding { ) .attachMember(_getter!); if (!_fragment.modifiers.isFinal) { - VariableDeclaration parameter = + Variable parameter = libraryBuilder.loader.isClosureContextLoweringEnabled ? // Coverage-ignore(suite): Not run. @@ -1863,7 +1863,7 @@ class ExtensionInstanceFieldEncoding implements FieldEncoding { .getProcedureMemberName(ProcedureKind.Getter, _fragment.name) .attachMember(_getter!); if (_fragment.hasSetter) { - VariableDeclaration parameter = extern.createParameterVariable( + Variable parameter = extern.createParameterVariable( "#externalFieldValue", isSynthesized: true, isCovariantByDeclaration: _fragment.modifiers.isCovariant, diff --git a/pkg/front_end/lib/src/fragment/function.dart b/pkg/front_end/lib/src/fragment/function.dart index 96d9ab03e83..ab449892ddc 100644 --- a/pkg/front_end/lib/src/fragment/function.dart +++ b/pkg/front_end/lib/src/fragment/function.dart @@ -33,7 +33,7 @@ abstract class FunctionBodyBuildingContext { LocalScope get formalParameterScope; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; List? get thisTypeParameters; diff --git a/pkg/front_end/lib/src/fragment/getter.dart b/pkg/front_end/lib/src/fragment/getter.dart index f91b1c3f64e..ea176f2d0d4 100644 --- a/pkg/front_end/lib/src/fragment/getter.dart +++ b/pkg/front_end/lib/src/fragment/getter.dart @@ -153,7 +153,7 @@ class _GetterBodyBuildingContext implements FunctionBodyBuildingContext { _fragment.declaration.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _fragment.declaration.thisVariable; + Variable? get thisVariable => _fragment.declaration.thisVariable; @override ExtensionScope get extensionScope { diff --git a/pkg/front_end/lib/src/fragment/getter/body_builder_context.dart b/pkg/front_end/lib/src/fragment/getter/body_builder_context.dart index a03b18a8777..011a9e287ad 100644 --- a/pkg/front_end/lib/src/fragment/getter/body_builder_context.dart +++ b/pkg/front_end/lib/src/fragment/getter/body_builder_context.dart @@ -59,7 +59,7 @@ class GetterFragmentBodyBuilderContext extends BodyBuilderContext { } @override - VariableDeclaration? getTearOffParameter(int index) => null; + Variable? getTearOffParameter(int index) => null; @override void registerFunctionBody({ diff --git a/pkg/front_end/lib/src/fragment/getter/declaration.dart b/pkg/front_end/lib/src/fragment/getter/declaration.dart index 275a2eec075..ef848454653 100644 --- a/pkg/front_end/lib/src/fragment/getter/declaration.dart +++ b/pkg/front_end/lib/src/fragment/getter/declaration.dart @@ -153,7 +153,7 @@ class RegularGetterDeclaration List? get thisTypeParameters => _encoding.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _encoding.thisVariable; + Variable? get thisVariable => _encoding.thisVariable; @override void becomeNative(SourceLoader loader) { @@ -312,7 +312,7 @@ class RegularGetterDeclaration required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { assert( asyncModifier.kind == this.asyncModifier.kind, @@ -357,7 +357,7 @@ abstract class GetterFragmentDeclaration { List? get thisTypeParameters; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; void becomeNative(SourceLoader loader); @@ -372,7 +372,7 @@ abstract class GetterFragmentDeclaration { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); DartType get returnTypeContext; diff --git a/pkg/front_end/lib/src/fragment/getter/encoding.dart b/pkg/front_end/lib/src/fragment/getter/encoding.dart index 05e5a6fbda8..2432ca8b8ff 100644 --- a/pkg/front_end/lib/src/fragment/getter/encoding.dart +++ b/pkg/front_end/lib/src/fragment/getter/encoding.dart @@ -133,7 +133,7 @@ sealed class GetterEncoding implements InferredTypeListener { List? get thisTypeParameters; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; void becomeNative(SourceLoader loader); @@ -184,7 +184,7 @@ sealed class GetterEncoding implements InferredTypeListener { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); } @@ -231,7 +231,7 @@ mixin _DirectGetterEncodingMixin implements GetterEncoding { List? get thisTypeParameters => null; @override - VariableDeclaration? get thisVariable => null; + Variable? get thisVariable => null; BuiltMemberKind get _builtMemberKind; @@ -467,7 +467,7 @@ mixin _DirectGetterEncodingMixin implements GetterEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { if (body != null) { function.registerFunctionBody( @@ -517,7 +517,7 @@ mixin _ExtensionInstanceGetterEncodingMixin implements GetterEncoding { _clonedDeclarationTypeParameters != null ? function.typeParameters : null; @override - VariableDeclaration? get thisVariable => _thisFormal.variable; + Variable? get thisVariable => _thisFormal.variable; BuiltMemberKind get _builtMemberKind; @@ -815,7 +815,7 @@ mixin _ExtensionInstanceGetterEncodingMixin implements GetterEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { if (body != null) { function.registerFunctionBody( diff --git a/pkg/front_end/lib/src/fragment/method.dart b/pkg/front_end/lib/src/fragment/method.dart index 054db07714c..9a85d557caa 100644 --- a/pkg/front_end/lib/src/fragment/method.dart +++ b/pkg/front_end/lib/src/fragment/method.dart @@ -153,7 +153,7 @@ class _MethodBodyBuildingContext implements FunctionBodyBuildingContext { _fragment.declaration.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _fragment.declaration.thisVariable; + Variable? get thisVariable => _fragment.declaration.thisVariable; @override ExtensionScope get extensionScope { diff --git a/pkg/front_end/lib/src/fragment/method/body_builder_context.dart b/pkg/front_end/lib/src/fragment/method/body_builder_context.dart index 728e2e035c7..5ffcf84d43a 100644 --- a/pkg/front_end/lib/src/fragment/method/body_builder_context.dart +++ b/pkg/front_end/lib/src/fragment/method/body_builder_context.dart @@ -59,7 +59,7 @@ class MethodFragmentBodyBuilderContext extends BodyBuilderContext { } @override - VariableDeclaration? getTearOffParameter(int index) => + Variable? getTearOffParameter(int index) => _declaration.getTearOffParameter(index); @override diff --git a/pkg/front_end/lib/src/fragment/method/declaration.dart b/pkg/front_end/lib/src/fragment/method/declaration.dart index 343c9e4e042..59f519ea9bc 100644 --- a/pkg/front_end/lib/src/fragment/method/declaration.dart +++ b/pkg/front_end/lib/src/fragment/method/declaration.dart @@ -135,7 +135,7 @@ class MethodDeclarationImpl List? get thisTypeParameters => _encoding.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _encoding.thisVariable; + Variable? get thisVariable => _encoding.thisVariable; @override void becomeNative(SourceLoader loader) { @@ -273,7 +273,7 @@ class MethodDeclarationImpl } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { return _encoding.getTearOffParameter(index); } @@ -283,7 +283,7 @@ class MethodDeclarationImpl required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { _encoding.registerFunctionBody( body: body, @@ -314,7 +314,7 @@ abstract class MethodFragmentDeclaration { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); DartType get returnTypeContext; @@ -325,7 +325,7 @@ abstract class MethodFragmentDeclaration { List? get thisTypeParameters; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; void becomeNative(SourceLoader loader); @@ -333,5 +333,5 @@ abstract class MethodFragmentDeclaration { LocalScope createFormalParameterScope(LookupScope typeParameterScope); - VariableDeclaration? getTearOffParameter(int index); + Variable? getTearOffParameter(int index); } diff --git a/pkg/front_end/lib/src/fragment/method/encoding.dart b/pkg/front_end/lib/src/fragment/method/encoding.dart index 78ce8aa9793..ce8f599f620 100644 --- a/pkg/front_end/lib/src/fragment/method/encoding.dart +++ b/pkg/front_end/lib/src/fragment/method/encoding.dart @@ -49,7 +49,7 @@ sealed class MethodEncoding implements InferredTypeListener { List? get thisTypeParameters; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; void becomeNative(SourceLoader loader); @@ -93,14 +93,14 @@ sealed class MethodEncoding implements InferredTypeListener { ClassHierarchyBase hierarchy, ); - VariableDeclaration? getTearOffParameter(int index); + Variable? getTearOffParameter(int index); void registerFunctionBody({ required Statement? body, required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); } @@ -161,7 +161,7 @@ mixin _DirectMethodEncodingMixin implements MethodEncoding { List? get thisTypeParameters => null; @override - VariableDeclaration? get thisVariable => null; + Variable? get thisVariable => null; BuiltMemberKind get _builtMemberKind; @@ -381,7 +381,7 @@ mixin _DirectMethodEncodingMixin implements MethodEncoding { } @override - VariableDeclaration? getTearOffParameter(int index) => null; + Variable? getTearOffParameter(int index) => null; @override void onInferredType(DartType type) { @@ -394,7 +394,7 @@ mixin _DirectMethodEncodingMixin implements MethodEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { if (body != null) { function.registerFunctionBody( @@ -459,7 +459,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { /// /// This map is used to set the default values on the closure parameters when /// these have been built. - Map? _extensionTearOffParameterMap; + Map? _extensionTearOffParameterMap; @override List? get clonedAndDeclaredTypeParameters => @@ -490,7 +490,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { Procedure? get readTarget => _extensionTearOff; @override - VariableDeclaration? get thisVariable => _thisFormal.variable; + Variable? get thisVariable => _thisFormal.variable; BuiltMemberKind get _builtMemberKind; @@ -780,7 +780,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { } @override - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { return _extensionTearOffParameterMap?[_fragment .declaredFormals![index] .variable]; @@ -797,7 +797,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { if (body != null) { function.registerFunctionBody( @@ -878,11 +878,8 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { } } - VariableDeclaration copyParameter( - VariableDeclaration parameter, - DartType type, - ) { - VariableDeclaration newParameter; + Variable copyParameter(Variable parameter, DartType type) { + Variable newParameter; switch (parameter) { case PositionalParameter(): // Coverage-ignore(suite): Not run. @@ -902,7 +899,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { isLowered: parameter.isLowered, isRequired: parameter.isRequired, )..fileOffset = parameter.fileOffset; - case VariableDeclaration(): + case Variable(): newParameter = extern.createParameterVariable( parameter.name, type: type, @@ -916,7 +913,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { return newParameter; } - VariableDeclaration extensionThis = copyParameter( + Variable extensionThis = copyParameter( procedure.function.positionalParameters.first, substitution.substituteType( procedure.function.positionalParameters.first.type, @@ -926,7 +923,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { DartType closureReturnType = substitution.substituteType( procedure.function.returnType, ); - List closurePositionalParameters = []; + List closurePositionalParameters = []; List closurePositionalArguments = []; for ( @@ -934,8 +931,7 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { position < procedure.function.positionalParameters.length; position++ ) { - VariableDeclaration parameter = - procedure.function.positionalParameters[position]; + Variable parameter = procedure.function.positionalParameters[position]; if (position == 0) { /// Pass `this` as a captured variable. closurePositionalArguments.add( @@ -943,18 +939,18 @@ mixin _ExtensionInstanceMethodEncodingMixin implements MethodEncoding { ); } else { DartType type = substitution.substituteType(parameter.type); - VariableDeclaration newParameter = copyParameter(parameter, type); + Variable newParameter = copyParameter(parameter, type); closurePositionalParameters.add(newParameter); closurePositionalArguments.add( extern.createVariableGet(newParameter, fileOffset: fileOffset), ); } } - List closureNamedParameters = []; + List closureNamedParameters = []; List closureNamedArguments = []; - for (VariableDeclaration parameter in procedure.function.namedParameters) { + for (Variable parameter in procedure.function.namedParameters) { DartType type = substitution.substituteType(parameter.type); - VariableDeclaration newParameter = copyParameter(parameter, type); + Variable newParameter = copyParameter(parameter, type); closureNamedParameters.add(newParameter); closureNamedArguments.add( extern.createNamedExpression( diff --git a/pkg/front_end/lib/src/fragment/primary_constructor.dart b/pkg/front_end/lib/src/fragment/primary_constructor.dart index 924c97d76c5..dba97014326 100644 --- a/pkg/front_end/lib/src/fragment/primary_constructor.dart +++ b/pkg/front_end/lib/src/fragment/primary_constructor.dart @@ -144,7 +144,7 @@ class _PrimaryConstructorBodyBuildingContext _fragment.declaration.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _fragment.declaration.thisVariable; + Variable? get thisVariable => _fragment.declaration.thisVariable; @override LookupScope get typeParameterScope { diff --git a/pkg/front_end/lib/src/fragment/setter.dart b/pkg/front_end/lib/src/fragment/setter.dart index d0d3b449664..8f07a1cb858 100644 --- a/pkg/front_end/lib/src/fragment/setter.dart +++ b/pkg/front_end/lib/src/fragment/setter.dart @@ -154,7 +154,7 @@ class _SetterFunctionBodyBuildingContext _fragment.declaration.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _fragment.declaration.thisVariable; + Variable? get thisVariable => _fragment.declaration.thisVariable; @override ExtensionScope get extensionScope { diff --git a/pkg/front_end/lib/src/fragment/setter/body_builder_context.dart b/pkg/front_end/lib/src/fragment/setter/body_builder_context.dart index f7a74d73b21..c900b6b1e93 100644 --- a/pkg/front_end/lib/src/fragment/setter/body_builder_context.dart +++ b/pkg/front_end/lib/src/fragment/setter/body_builder_context.dart @@ -59,7 +59,7 @@ class SetterBodyBuilderContext extends BodyBuilderContext { } @override - VariableDeclaration? getTearOffParameter(int index) => null; + Variable? getTearOffParameter(int index) => null; @override void registerFunctionBody({ diff --git a/pkg/front_end/lib/src/fragment/setter/declaration.dart b/pkg/front_end/lib/src/fragment/setter/declaration.dart index 2bcaf5099db..e50d055066b 100644 --- a/pkg/front_end/lib/src/fragment/setter/declaration.dart +++ b/pkg/front_end/lib/src/fragment/setter/declaration.dart @@ -153,7 +153,7 @@ class RegularSetterDeclaration List? get thisTypeParameters => _encoding.thisTypeParameters; @override - VariableDeclaration? get thisVariable => _encoding.thisVariable; + Variable? get thisVariable => _encoding.thisVariable; @override Procedure get writeTarget => _encoding.writeTarget; @@ -316,7 +316,7 @@ class RegularSetterDeclaration required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { List? declaredFormals = _fragment.declaredFormals; if (declaredFormals == null || @@ -395,7 +395,7 @@ abstract class SetterFragmentDeclaration { List? get thisTypeParameters; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; void becomeNative(SourceLoader loader); @@ -412,7 +412,7 @@ abstract class SetterFragmentDeclaration { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); DartType get returnTypeContext; diff --git a/pkg/front_end/lib/src/fragment/setter/encoding.dart b/pkg/front_end/lib/src/fragment/setter/encoding.dart index ecc015119f7..96e8d1bcde8 100644 --- a/pkg/front_end/lib/src/fragment/setter/encoding.dart +++ b/pkg/front_end/lib/src/fragment/setter/encoding.dart @@ -148,7 +148,7 @@ sealed class SetterEncoding { List? get thisTypeParameters; - VariableDeclaration? get thisVariable; + Variable? get thisVariable; Procedure get writeTarget; @@ -200,7 +200,7 @@ sealed class SetterEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }); } @@ -227,7 +227,7 @@ mixin _DirectSetterEncodingMixin implements SetterEncoding { List? get thisTypeParameters => null; @override - VariableDeclaration? get thisVariable => null; + Variable? get thisVariable => null; @override Procedure get writeTarget => _procedure!; @@ -333,7 +333,7 @@ mixin _DirectSetterEncodingMixin implements SetterEncoding { // Replace illegal parameters by single dummy parameter. // Do this after building the parameters, since the diet listener // assumes that parameters are built, even if illegal in number. - VariableDeclaration parameter = new VariableDeclarationImpl( + Variable parameter = new VariableDeclarationImpl( "#synthetic", fileOffset: TreeNode.noOffset, ); @@ -484,7 +484,7 @@ mixin _DirectSetterEncodingMixin implements SetterEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { if (body != null) { function.registerFunctionBody( @@ -531,7 +531,7 @@ mixin _ExtensionInstanceSetterEncodingMixin implements SetterEncoding { _clonedDeclarationTypeParameters != null ? function.typeParameters : null; @override - VariableDeclaration? get thisVariable => _thisFormal.variable; + Variable? get thisVariable => _thisFormal.variable; @override Procedure get writeTarget => _procedure!; @@ -659,8 +659,8 @@ mixin _ExtensionInstanceSetterEncodingMixin implements SetterEncoding { // Replace illegal parameters by single dummy parameter (after #this). // Do this after building the parameters, since the diet listener // assumes that parameters are built, even if illegal in number. - VariableDeclaration thisParameter = function.positionalParameters[0]; - VariableDeclaration parameter = new VariableDeclarationImpl( + Variable thisParameter = function.positionalParameters[0]; + Variable parameter = new VariableDeclarationImpl( "#synthetic", fileOffset: TreeNode.noOffset, ); @@ -856,7 +856,7 @@ mixin _ExtensionInstanceSetterEncodingMixin implements SetterEncoding { required Scope? scope, required AsyncModifier asyncModifier, required DartType? emittedValueType, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, }) { if (body != null) { function.registerFunctionBody( 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 82e73e70469..5bb25792601 100644 --- a/pkg/front_end/lib/src/kernel/assigned_variables_impl.dart +++ b/pkg/front_end/lib/src/kernel/assigned_variables_impl.dart @@ -6,11 +6,10 @@ 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; @@ -21,10 +20,10 @@ class AssignedVariablesImpl this._delegate, { required bool isClosureContextLoweringEnabled, }) : _insideAsserts = isClosureContextLoweringEnabled - ? new AssignedVariables() + ? new AssignedVariables() : null, _outsideAsserts = isClosureContextLoweringEnabled - ? new AssignedVariables() + ? new AssignedVariables() : null, _deferredInsideAssertsByDeferredDelegate = isClosureContextLoweringEnabled @@ -72,7 +71,7 @@ class AssignedVariablesImpl } @override - void declare(VariableDeclaration variable, {bool ignoreDuplicates = false}) { + void declare(Variable variable, {bool ignoreDuplicates = false}) { _delegate.declare(variable, ignoreDuplicates: ignoreDuplicates); _insideAsserts?.declare(variable, ignoreDuplicates: ignoreDuplicates); _outsideAsserts?.declare(variable, ignoreDuplicates: ignoreDuplicates); @@ -153,7 +152,7 @@ class AssignedVariablesImpl } @override - PromotionKeyStore get promotionKeyStore { + PromotionKeyStore get promotionKeyStore { return _delegate.promotionKeyStore; } @@ -165,7 +164,7 @@ class AssignedVariablesImpl } @override - void read(VariableDeclaration variable) { + void read(Variable variable) { _delegate.read(variable); if (_isInsideAssert) { _insideAsserts?.read(variable); @@ -203,7 +202,7 @@ class AssignedVariablesImpl } @override - void write(VariableDeclaration variable) { + void write(Variable 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 da667dfadd2..06c826a2832 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -169,7 +169,7 @@ abstract class BodyBuilder { BuildSingleExpressionResult buildSingleExpression({ required Token token, - required List extraKnownVariables, + required List extraKnownVariables, required List? typeParameterBuilders, required List? formals, required int fileOffset, @@ -323,14 +323,14 @@ class BodyBuilderImpl extends StackListenerImpl List? _multiTargetAnnotations; - final LocalStack _thisVariables; + final LocalStack _thisVariables; /// If the current member is an instance member in an extension declaration or /// an instance member or constructor in and extension type declaration, /// [thisVariable] holds the synthetically added variable holding the value /// for `this`. @override - VariableDeclaration? get thisVariable => _thisVariables.currentOrNull; + Variable? get thisVariable => _thisVariables.currentOrNull; /// If the current member is an instance member of a non-extension /// declaration, and the closure context lowering experiment is enabled, this @@ -342,7 +342,7 @@ class BodyBuilderImpl extends StackListenerImpl final LocalStack _localScopes; int _parameterlessAnonymousMethodDepth = 0; - Set? declaredInCurrentGuard; + Set? declaredInCurrentGuard; JumpTarget? breakTarget; @@ -361,7 +361,7 @@ class BodyBuilderImpl extends StackListenerImpl this.formalParameterScope, required this.hierarchy, required this.coreTypes, - VariableDeclaration? thisVariable, + Variable? thisVariable, this.thisTypeParameters, required this.uri, required this.assignedVariables, @@ -622,7 +622,7 @@ class BodyBuilderImpl extends StackListenerImpl } @override - void registerVariableAssignment(VariableDeclaration variable) { + void registerVariableAssignment(Variable variable) { // TODO(cstefantsova): Always pass [variable] to [assignedVariables.write] // when [InferenceVisitorBase.flowAnalysis] will use // [InternalExpressionVariable] instead of [ExpressionVariable] (that is, @@ -824,7 +824,7 @@ class BodyBuilderImpl extends StackListenerImpl } void wrapVariableInitializerInError( - VariableDeclaration variable, + Variable variable, List context, ) { String name = variable.cosmeticName!; @@ -848,7 +848,7 @@ class BodyBuilderImpl extends StackListenerImpl } } - void declareVariable(VariableDeclaration variable, LocalScope scope) { + void declareVariable(Variable variable, LocalScope scope) { String name = variable.cosmeticName!; Builder? existing = scope.lookupLocalVariable(name); if (existing != null) { @@ -1622,9 +1622,7 @@ class BodyBuilderImpl extends StackListenerImpl ); } else { bool isNullAware = token.isA(TokenType.QUESTION_PERIOD_PERIOD); - VariableDeclaration variable = createVariableDeclarationForValue( - expression, - ); + Variable variable = createVariableDeclarationForValue(expression); push( new Cascade(variable, isNullAware: isNullAware) ..fileOffset = expression.fileOffset, @@ -1889,7 +1887,7 @@ class BodyBuilderImpl extends StackListenerImpl if (scopeKind != LocalScopeKind.orPatternRight && enclosingScopeIsPatternScope) { if (pattern is Pattern) { - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { declareVariable(variable, _localScope); } } @@ -1960,11 +1958,11 @@ class BodyBuilderImpl extends StackListenerImpl push(intern.createAndPattern(operatorToken.charOffset, left, right)); break; case '||': - Map leftVariablesByName = { - for (VariableDeclaration leftVariable in left.declaredVariables) + Map leftVariablesByName = { + for (Variable leftVariable in left.declaredVariables) leftVariable.name!: leftVariable, }; - for (VariableDeclaration rightVariable in right.declaredVariables) { + for (Variable rightVariable in right.declaredVariables) { if (!leftVariablesByName.containsKey(rightVariable.name)) { addProblem( diag.missingVariablePattern.withArguments( @@ -1975,11 +1973,11 @@ class BodyBuilderImpl extends StackListenerImpl ); } } - Map rightVariablesByName = { - for (VariableDeclaration rightVariable in right.declaredVariables) + Map rightVariablesByName = { + for (Variable rightVariable in right.declaredVariables) rightVariable.name!: rightVariable, }; - for (VariableDeclaration leftVariable in left.declaredVariables) { + for (Variable leftVariable in left.declaredVariables) { if (!rightVariablesByName.containsKey(leftVariable.name)) { addProblem( diag.missingVariablePattern.withArguments( @@ -1990,14 +1988,14 @@ class BodyBuilderImpl extends StackListenerImpl ); } } - List jointVariables = [ - for (VariableDeclaration leftVariable in left.declaredVariables) + List jointVariables = [ + for (Variable leftVariable in left.declaredVariables) intern.createVariableDeclaration( leftVariable.fileOffset, leftVariable.name!, ), ]; - for (VariableDeclaration variable in jointVariables) { + for (Variable variable in jointVariables) { declareVariable(variable, _localScope); assignedVariables.declare(variable); } @@ -2502,7 +2500,7 @@ class BodyBuilderImpl extends StackListenerImpl } @override - void registerVariableRead(VariableDeclaration variable) { + void registerVariableRead(Variable variable) { if (variable case InternalVariable variable) { if (!variable.isLocalFunction && !variable.isWildcard) { assignedVariables.read(variable.astVariable); @@ -2518,10 +2516,7 @@ class BodyBuilderImpl extends StackListenerImpl /// Helper method to create a [VariableGet] of the [variable] using /// [charOffset] as the file offset. @override - InternalVariableGet createVariableGet( - VariableDeclaration variable, - int charOffset, - ) { + InternalVariableGet createVariableGet(Variable variable, int charOffset) { registerVariableRead(variable); return intern.createVariableGet(variable, fileOffset: charOffset); } @@ -2530,7 +2525,7 @@ class BodyBuilderImpl extends StackListenerImpl /// using [token] and [charOffset] for offset information and [name] /// for `ExpressionGenerator._plainNameForRead`. ReadOnlyAccessGenerator _createReadOnlyVariableAccess( - VariableDeclaration variable, + Variable variable, Token token, int charOffset, String? name, @@ -2546,7 +2541,7 @@ class BodyBuilderImpl extends StackListenerImpl } @override - bool isDeclaredInEnclosingCase(VariableDeclaration variable) { + bool isDeclaredInEnclosingCase(Variable variable) { return declaredInCurrentGuard?.contains(variable) ?? false; } @@ -2683,7 +2678,7 @@ class BodyBuilderImpl extends StackListenerImpl diag.notAConstantExpression, ); } - VariableDeclaration variable = getable.variable; + Variable variable = getable.variable; if (forStatementScope && getable.isAssignable && getable.isLate && @@ -3215,7 +3210,7 @@ class BodyBuilderImpl extends StackListenerImpl Pattern pattern = toPattern(peek()); createAndEnterLocalScope(kind: LocalScopeKind.ifCaseHead); - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { declareVariable(variable, _localScope); } } @@ -3247,8 +3242,7 @@ class BodyBuilderImpl extends StackListenerImpl // to enter the scope and declare all of the pattern variables. if (patternGuard != null) { createAndEnterLocalScope(kind: LocalScopeKind.ifCaseHead); - for (VariableDeclaration variable - in patternGuard.pattern.declaredVariables) { + for (Variable variable in patternGuard.pattern.declaredVariables) { declareVariable(variable, _localScope); } LocalScope thenScope = _localScope.createNestedScope( @@ -3733,13 +3727,13 @@ class BodyBuilderImpl extends StackListenerImpl variableOrExpression.variable.isLate = false; return [variableOrExpression]; } else if (variableOrExpression is Expression) { - VariableDeclaration variable = new VariableDeclarationImpl.forEffect( + Variable variable = new VariableDeclarationImpl.forEffect( variableOrExpression, ); return [intern.createVariableStatement(variable)]; } else if (variableOrExpression is ExpressionStatement) { // Coverage-ignore-block(suite): Not run. - VariableDeclaration variable = new VariableDeclarationImpl.forEffect( + Variable variable = new VariableDeclarationImpl.forEffect( variableOrExpression.expression, ); return [intern.createVariableStatement(variable)]; @@ -3825,7 +3819,7 @@ class BodyBuilderImpl extends StackListenerImpl if (pattern is Pattern) { pop(); // Metadata. - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { declareVariable(variable, _localScope); } LocalScope forScope = _localScope.createNestedScope( @@ -3839,13 +3833,13 @@ class BodyBuilderImpl extends StackListenerImpl // We use intermediate variables to transfer values between the pattern // variables and the replacement internal variables. It allows to avoid // using the variables with the same name within the same block. - List intermediateVariables = []; - List internalVariables = []; - for (VariableDeclaration variable in pattern.declaredVariables) { + List intermediateVariables = []; + List internalVariables = []; + for (Variable variable in pattern.declaredVariables) { variable.isFinal |= isFinal; // TODO(johnniwinther): Can we avoid creating synthetic variables here? - VariableDeclaration intermediateVariable = intern + Variable intermediateVariable = intern .createVariableDeclarationForValue( intern.createVariableGet( variable, @@ -3854,7 +3848,7 @@ class BodyBuilderImpl extends StackListenerImpl ); intermediateVariables.add(intermediateVariable); - VariableDeclaration internalVariable = intern.createVariableDeclaration( + Variable internalVariable = intern.createVariableDeclaration( variable.fileOffset, variable.name!, initializer: intern.createVariableGet( @@ -3967,12 +3961,12 @@ class BodyBuilderImpl extends StackListenerImpl Object? variableOrExpression = pop(); List? variables; - List? intermediateVariables; + List? intermediateVariables; if (variableOrExpression is PatternVariableDeclaration) { - variables = (pop() as List) + variables = (pop() as List) .map(intern.createVariableStatement) .toList(); // Internal variables. - intermediateVariables = pop() as List; + intermediateVariables = pop() as List; } else { variables = _buildForLoopVariableDeclarations(variableOrExpression)!; } @@ -4088,12 +4082,12 @@ class BodyBuilderImpl extends StackListenerImpl Object? variableOrExpression = pop(); List? variables; - List? intermediateVariables; + List? intermediateVariables; if (variableOrExpression is PatternVariableDeclaration) { - variables = (pop() as List) + variables = (pop() as List) .map(intern.createVariableStatement) .toList(); // Internal variables. - intermediateVariables = pop() as List; + intermediateVariables = pop() as List; } else { variables = _buildForLoopVariableDeclarations(variableOrExpression); } @@ -4137,8 +4131,7 @@ class BodyBuilderImpl extends StackListenerImpl fileEndOffset: result.fileOffset, [ variableOrExpression, - for (VariableDeclaration intermediateVariable - in intermediateVariables!) + for (Variable intermediateVariable in intermediateVariables!) intern.createVariableStatement(intermediateVariable), result, ], @@ -5492,7 +5485,7 @@ class BodyBuilderImpl extends StackListenerImpl } } - VariableDeclaration functionParameter; + Variable functionParameter; if (memberKind == MemberKind.Catch) { functionParameter = (parameter as CatchParameterBuilder).build( libraryBuilder, @@ -7252,8 +7245,7 @@ class BodyBuilderImpl extends StackListenerImpl enterLocalScope(thenScope); } else { createAndEnterLocalScope(kind: LocalScopeKind.ifCaseHead); - for (VariableDeclaration variable - in patternGuard.pattern.declaredVariables) { + for (Variable variable in patternGuard.pattern.declaredVariables) { declareVariable(variable, _localScope); } LocalScope thenScope = _localScope.createNestedScope( @@ -7759,7 +7751,7 @@ class BodyBuilderImpl extends StackListenerImpl identifierName = createWildcardVariableName(wildcardVariableIndex); wildcardVariableIndex++; } - VariableDeclaration variable = new VariableDeclarationImpl( + Variable variable = new VariableDeclarationImpl( identifierName, forSyntheticToken: nameToken.isSynthetic, isFinal: true, @@ -7872,7 +7864,7 @@ class BodyBuilderImpl extends StackListenerImpl ); if (declaration is FunctionDeclaration) { - VariableDeclaration variable = declaration.variable; + Variable variable = declaration.variable; if (annotations != null) { for (Expression annotation in annotations) { variable.addAnnotation(annotation); @@ -8046,9 +8038,8 @@ class BodyBuilderImpl extends StackListenerImpl debugEvent("handleImplicitFormalParameters"); Token token = punctuation; // fallback offset Expression receiver = toValue(peek()); - VariableDeclaration variable = intern.createVariableDeclarationForValue( - receiver, - )..isSynthesized = true; + Variable variable = intern.createVariableDeclarationForValue(receiver) + ..isSynthesized = true; variable.fileOffset = offsetForToken(token); _thisVariables.push(variable); _parameterlessAnonymousMethodDepth++; @@ -8092,7 +8083,7 @@ class BodyBuilderImpl extends StackListenerImpl if (isExpression) { Expression bodyExpr; Expression receiver; - VariableDeclaration variable; + Variable variable; bool isImplicitlyTyped; int typeOffset; @@ -8273,7 +8264,7 @@ class BodyBuilderImpl extends StackListenerImpl if (pattern is Pattern) { pop(); // Metadata. bool isFinal = patternKeyword?.lexeme == 'final'; - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { variable.isFinal |= isFinal; declareVariable(variable, _localScope); } @@ -8928,9 +8919,9 @@ class BodyBuilderImpl extends StackListenerImpl push(containsPatterns); push(labels ?? NullValues.Labels); - List? jointPatternVariables; - List? jointPatternVariablesWithMismatchingFinality; - List? jointPatternVariablesNotInAll; + List? jointPatternVariables; + List? jointPatternVariablesWithMismatchingFinality; + List? jointPatternVariablesNotInAll; enterLocalScope(switchCaseScope); if (expressionCount > 1) { for (int i = 0; i < expressionOrPatterns.length; i++) { @@ -8940,8 +8931,7 @@ class BodyBuilderImpl extends StackListenerImpl if (patternGuard != null) { if (jointPatternVariables == null) { jointPatternVariables = [ - for (VariableDeclaration variable - in patternGuard.pattern.declaredVariables) + for (Variable variable in patternGuard.pattern.declaredVariables) intern.createVariableDeclaration( variable.fileOffset, variable.name!, @@ -8955,15 +8945,15 @@ class BodyBuilderImpl extends StackListenerImpl ); } } else { - Map patternVariablesByName = { - for (VariableDeclaration variable - in patternGuard.pattern.declaredVariables) + Map patternVariablesByName = { + for (Variable variable in patternGuard.pattern.declaredVariables) variable.name!: variable, }; - for (VariableDeclaration jointVariable in jointPatternVariables) { + for (Variable jointVariable in jointPatternVariables) { String jointVariableName = jointVariable.name!; - VariableDeclaration? patternVariable = patternVariablesByName - .remove(jointVariableName); + Variable? patternVariable = patternVariablesByName.remove( + jointVariableName, + ); if (patternVariable != null) { if (patternVariable.isFinal != jointVariable.isFinal) { (jointPatternVariablesWithMismatchingFinality ??= []).add( @@ -8975,13 +8965,11 @@ class BodyBuilderImpl extends StackListenerImpl } } if (patternVariablesByName.isNotEmpty) { - for (VariableDeclaration variable - in patternVariablesByName.values) { - VariableDeclaration jointVariable = - intern.createVariableDeclaration( - variable.fileOffset, - variable.name!, - )..isFinal = variable.isFinal; + for (Variable variable in patternVariablesByName.values) { + Variable jointVariable = intern.createVariableDeclaration( + variable.fileOffset, + variable.name!, + )..isFinal = variable.isFinal; (jointPatternVariablesNotInAll ??= []).add(jointVariable); jointPatternVariables.add(jointVariable); } @@ -9000,7 +8988,7 @@ class BodyBuilderImpl extends StackListenerImpl if (jointPatternVariables.isEmpty) { jointPatternVariables = null; } else { - for (VariableDeclaration jointVariable in jointPatternVariables) { + for (Variable jointVariable in jointPatternVariables) { assert(_localScope.kind == LocalScopeKind.jointVariables); declareVariable(jointVariable, _localScope); assignedVariables.declare(jointVariable); @@ -9058,7 +9046,7 @@ class BodyBuilderImpl extends StackListenerImpl // makes the variables visible in the 'when' clause of the head. Object? pattern = peek(); if (pattern is Pattern) { - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { declareVariable(variable, _localScope); } } @@ -9097,7 +9085,7 @@ class BodyBuilderImpl extends StackListenerImpl // body of the case. Object? pattern = peek(); if (pattern is Pattern) { - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { declareVariable(variable, _localScope); } } @@ -9131,12 +9119,10 @@ class BodyBuilderImpl extends StackListenerImpl // check this switch case to see if it falls through to the next case. Statement block = popBlock(statementCount, beginToken, null); exitLocalScope(expectedScopeKinds: const [LocalScopeKind.switchCaseBody]); - List? jointPatternVariables = - pop() as List?; - List? jointPatternVariablesWithMismatchingFinality = - pop() as List?; - List? jointPatternVariablesNotInAll = - pop() as List?; + List? jointPatternVariables = pop() as List?; + List? jointPatternVariablesWithMismatchingFinality = + pop() as List?; + List? jointPatternVariablesNotInAll = pop() as List?; // The current scope should be the scope of the body of the switch case // because we want to lookup the first use of the pattern variables @@ -9152,12 +9138,12 @@ class BodyBuilderImpl extends StackListenerImpl bool hasDefaultOrLabels = defaultKeyword != null || labelCount > 0; - List? usedJointPatternVariables; + List? usedJointPatternVariables; List? jointVariableFirstUseOffsets; if (jointPatternVariables != null) { usedJointPatternVariables = []; - Map firstUseOffsets = {}; - for (VariableDeclaration variable in jointPatternVariables) { + Map firstUseOffsets = {}; + for (Variable variable in jointPatternVariables) { if (usedNamesOffsets?[variable.name!] case [int offset, ...]) { usedJointPatternVariables.add(variable); firstUseOffsets[variable] = offset; @@ -9166,7 +9152,7 @@ class BodyBuilderImpl extends StackListenerImpl if (jointPatternVariablesWithMismatchingFinality != null || jointPatternVariablesNotInAll != null || hasDefaultOrLabels) { - for (VariableDeclaration jointVariable in usedJointPatternVariables) { + for (Variable jointVariable in usedJointPatternVariables) { if (jointPatternVariablesWithMismatchingFinality?.contains( jointVariable, ) ?? @@ -9203,7 +9189,7 @@ class BodyBuilderImpl extends StackListenerImpl } } jointVariableFirstUseOffsets = [ - for (VariableDeclaration variable in usedJointPatternVariables) + for (Variable variable in usedJointPatternVariables) firstUseOffsets[variable]!, ]; } @@ -9229,8 +9215,7 @@ class BodyBuilderImpl extends StackListenerImpl PatternGuard? patternGuard = expressionsOrPatternGuards.first.patternGuard; if (patternGuard != null) { - for (VariableDeclaration variable - in patternGuard.pattern.declaredVariables) { + for (Variable variable in patternGuard.pattern.declaredVariables) { String variableName = variable.name!; if (usedNamesOffsets[variableName] case [int offset, ...]) { addProblem( @@ -9414,7 +9399,7 @@ class BodyBuilderImpl extends StackListenerImpl Object? pattern = pop(); createAndEnterLocalScope(kind: LocalScopeKind.caseHead); if (pattern is Pattern) { - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { declareVariable(variable, _localScope); } } @@ -10725,7 +10710,7 @@ class BodyBuilderImpl extends StackListenerImpl PrefixBuilder prefix, int charOffset, ) { - VariableDeclaration check = intern.createVariableDeclarationForValue( + Variable check = intern.createVariableDeclarationForValue( intern.checkLibraryIsLoaded(charOffset, prefix.dependency!), ); return new DeferredCheck(check, expression, fileOffset: charOffset); @@ -11066,7 +11051,7 @@ class BodyBuilderImpl extends StackListenerImpl declaredVariables: const [], ); } else { - VariableDeclaration declaredVariable = intern.createVariableDeclaration( + Variable declaredVariable = intern.createVariableDeclaration( variable.charOffset, variable.lexeme, type: patternType, @@ -11175,7 +11160,7 @@ class BodyBuilderImpl extends StackListenerImpl Expression initializer = popForValue(); Pattern pattern = toPattern(pop()); bool isFinal = keyword.lexeme == 'final'; - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { variable.isFinal = isFinal; variable.hasDeclaredInitializer = true; declareVariable(variable, _localScope); @@ -11606,7 +11591,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, @@ -11643,7 +11628,7 @@ class BodyBuilderImpl extends StackListenerImpl kind: LocalScopeKind.ifElement, ); enterLocalScope(extraKnownVariablesScope); - for (VariableDeclaration extraVariable in extraKnownVariables) { + for (Variable extraVariable in extraKnownVariables) { declareVariable(extraVariable, _localScope); assignedVariables.declare(extraVariable); } diff --git a/pkg/front_end/lib/src/kernel/body_builder_context.dart b/pkg/front_end/lib/src/kernel/body_builder_context.dart index 7d90d09876f..9ae42e7d3d3 100644 --- a/pkg/front_end/lib/src/kernel/body_builder_context.dart +++ b/pkg/front_end/lib/src/kernel/body_builder_context.dart @@ -290,10 +290,10 @@ abstract class BodyBuilderContext { throw new UnsupportedError('${runtimeType}.registerInitializedField'); } - /// Returns the [VariableDeclaration] for the [index]th formal parameter + /// Returns the [Variable] for the [index]th formal parameter /// declared in the constructor, factory, or method tear-off currently being /// built. - VariableDeclaration? getTearOffParameter(int index) { + Variable? getTearOffParameter(int index) { throw new UnsupportedError('${runtimeType}.getTearOffParameter'); } @@ -381,7 +381,7 @@ abstract class BodyBuilderContext { required TypeInferrer typeInferrer, required Uri fileUri, required Initializer initializer, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, 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 e6bbf0ae803..1354c8215d9 100644 --- a/pkg/front_end/lib/src/kernel/body_builder_helpers.dart +++ b/pkg/front_end/lib/src/kernel/body_builder_helpers.dart @@ -292,11 +292,11 @@ class FormalParameters extends Parameters { returnTypeBuilder?.build(library, TypeUse.returnType) ?? const DynamicType(); int requiredParameterCount = 0; - List positionalParameters = []; - List namedParameters = []; + List positionalParameters = []; + List namedParameters = []; if (parameters != null) { for (FormalParameterBuilder formal in parameters!) { - VariableDeclaration parameter = formal.build(library); + Variable parameter = formal.build(library); if (formal.isPositional) { positionalParameters.add(parameter); if (formal.isRequiredPositional) requiredParameterCount++; @@ -304,7 +304,7 @@ class FormalParameters extends Parameters { namedParameters.add(parameter); } } - namedParameters.sort((VariableDeclaration a, VariableDeclaration b) { + namedParameters.sort((Variable a, Variable b) { return a.name!.compareTo(b.name!); }); } diff --git a/pkg/front_end/lib/src/kernel/collections.dart b/pkg/front_end/lib/src/kernel/collections.dart index ef4dd177686..92a71134003 100644 --- a/pkg/front_end/lib/src/kernel/collections.dart +++ b/pkg/front_end/lib/src/kernel/collections.dart @@ -315,7 +315,7 @@ class ForInElement extends ControlFlowElement /// [ScopeProvider] nodes in the output. Scope? scope; - VariableDeclaration? variable; + Variable? variable; ForInEncoding? encoding; @@ -477,7 +477,7 @@ class PatternForElement extends ControlFlowElementImpl with ControlFlowElementMixin implements ForElementBase { PatternVariableDeclaration patternVariableDeclaration; - List intermediateVariables; + List intermediateVariables; // May be empty, but not null. @override @@ -755,7 +755,7 @@ class PatternForMapEntry extends TreeNode with InternalTreeNode, ControlFlowMapEntryMixin implements ForMapEntryBase, ControlFlowMapEntry { PatternVariableDeclaration patternVariableDeclaration; - List intermediateVariables; + List intermediateVariables; @override final List variables; @@ -826,7 +826,7 @@ class ForInMapEntry extends TreeNode /// [ScopeProvider] nodes in the output. Scope? scope; - VariableDeclaration? variable; + Variable? variable; ForInEncoding? encoding; diff --git a/pkg/front_end/lib/src/kernel/combined_member_signature.dart b/pkg/front_end/lib/src/kernel/combined_member_signature.dart index 99bea0a1da2..20996c18d1d 100644 --- a/pkg/front_end/lib/src/kernel/combined_member_signature.dart +++ b/pkg/front_end/lib/src/kernel/combined_member_signature.dart @@ -423,8 +423,7 @@ abstract class CombinedMemberSignatureBase { ); break; case ProcedureKind.Setter: - VariableDeclaration parameter = - member.function.positionalParameters.first; + Variable parameter = member.function.positionalParameters.first; combinedMemberSignature = _createSetterMemberSignature( declarationNode, indexedContainer, @@ -537,7 +536,7 @@ abstract class CombinedMemberSignatureBase { DartType type, { required bool isCovariantByDeclaration, required bool isCovariantByClass, - VariableDeclaration? parameter, + Variable? parameter, required bool copyLocation, }) { Reference? reference = indexedContainer?.lookupSetterReference(member.name); @@ -559,7 +558,7 @@ abstract class CombinedMemberSignatureBase { fileUri = declarationNode.fileUri; fileOffset = fileStartOffset = fileEndOffset = declarationNode.fileOffset; } - VariableDeclaration setterParameter; + Variable setterParameter; if (_isClosureContextLoweringEnabled) { // Coverage-ignore-block(suite): Not run. setterParameter = @@ -630,18 +629,18 @@ abstract class CombinedMemberSignatureBase { fileOffset = fileStartOffset = fileEndOffset = declarationNode.fileOffset; } FunctionNode function = procedure.function; - List positionalParameters = []; + List positionalParameters = []; FreshTypeParametersFromStructuralParameters freshTypeParameters = getFreshTypeParametersFromStructuralParameters( functionType.typeParameters, ); CloneVisitorNotMembers cloner = new CloneVisitorNotMembers(); for (int i = 0; i < function.positionalParameters.length; i++) { - VariableDeclaration parameter = function.positionalParameters[i]; + Variable parameter = function.positionalParameters[i]; DartType parameterType = freshTypeParameters.substitute( functionType.positionalParameters[i], ); - VariableDeclaration positionalParameter; + Variable positionalParameter; if (_isClosureContextLoweringEnabled) { // Coverage-ignore-block(suite): Not run. positionalParameter = @@ -672,10 +671,7 @@ abstract class CombinedMemberSignatureBase { positionalParameters.add(positionalParameter); } - VariableDeclaration cloneNamedParameter( - VariableDeclaration parameter, - NamedType namedType, - ) { + Variable cloneNamedParameter(Variable parameter, NamedType namedType) { if (_isClosureContextLoweringEnabled) { // Coverage-ignore-block(suite): Not run. return new NamedParameter( @@ -706,11 +702,11 @@ abstract class CombinedMemberSignatureBase { } } - List namedParameters = []; + List namedParameters = []; int namedParameterCount = function.namedParameters.length; if (namedParameterCount == 1) { NamedType namedType = functionType.namedParameters.first; - VariableDeclaration parameter = function.namedParameters.first; + Variable parameter = function.namedParameters.first; namedParameters.add(cloneNamedParameter(parameter, namedType)); } else if (namedParameterCount > 1) { Map namedTypes = {}; @@ -718,7 +714,7 @@ abstract class CombinedMemberSignatureBase { namedTypes[namedType.name] = namedType; } for (int i = 0; i < namedParameterCount; i++) { - VariableDeclaration parameter = function.namedParameters[i]; + Variable parameter = function.namedParameters[i]; NamedType namedParameterType = namedTypes[parameter.name]!; namedParameters.add(cloneNamedParameter(parameter, namedParameterType)); } 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 cf1f6306c36..1fc3119dfcb 100644 --- a/pkg/front_end/lib/src/kernel/const_conditional_simplifier.dart +++ b/pkg/front_end/lib/src/kernel/const_conditional_simplifier.dart @@ -129,7 +129,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 = {}; @@ -169,7 +169,7 @@ class _ConstantEvaluator extends TryConstantEvaluator { return _evaluate(expression); } - Constant? _evaluateVariableGet(VariableDeclaration variable) { + Constant? _evaluateVariableGet(Variable 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; @@ -180,8 +180,10 @@ class _ConstantEvaluator extends TryConstantEvaluator { return _evaluate(initializer); } - Constant? _lookupVariableGet(VariableDeclaration variable) => _variableCache - .putIfAbsent(variable, () => _evaluateVariableGet(variable)); + Constant? _lookupVariableGet(Variable variable) => _variableCache.putIfAbsent( + variable, + () => _evaluateVariableGet(variable), + ); @override Constant visitVariableGet(VariableGet node) => @@ -259,7 +261,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 111070f3fcc..b3a56161b1c 100644 --- a/pkg/front_end/lib/src/kernel/constant_evaluator.dart +++ b/pkg/front_end/lib/src/kernel/constant_evaluator.dart @@ -168,7 +168,7 @@ class ConstantsTransformer extends RemovingTransformer { /// Whether to preserve constant [Field]s. All use-sites will be rewritten. bool get keepFields => backend.keepFields; - /// Whether to preserve constant [VariableDeclaration]s. All use-sites will be + /// Whether to preserve constant [Variable]s. All use-sites will be /// rewritten. bool get keepLocals => backend.keepLocals; @@ -403,7 +403,7 @@ class ConstantsTransformer extends RemovingTransformer { transformTypeParameterList(node.typeParameters, node); final int positionalParameterCount = node.positionalParameters.length; for (int i = 0; i < positionalParameterCount; ++i) { - final VariableDeclaration variable = node.positionalParameters[i]; + final Variable variable = node.positionalParameters[i]; transformAnnotations(variable.annotations, variable); Expression? initializer = variable.initializer; if (initializer != null) { @@ -413,7 +413,7 @@ class ConstantsTransformer extends RemovingTransformer { )..parent = variable; } } - for (final VariableDeclaration variable in node.namedParameters) { + for (final Variable variable in node.namedParameters) { transformAnnotations(variable.annotations, variable); Expression? initializer = variable.initializer; if (initializer != null) { @@ -452,9 +452,7 @@ class ConstantsTransformer extends RemovingTransformer { TreeNode? removalSentinel, ) { if (removalSentinel != null) { - VariableDeclaration? variable = transformOrRemoveVariableDeclaration( - node.variable, - ); + Variable? variable = transformOrRemoveVariableDeclaration(node.variable); if (variable == null) { return removalSentinel; } @@ -468,10 +466,7 @@ class ConstantsTransformer extends RemovingTransformer { } @override - TreeNode defaultVariableDeclaration( - VariableDeclaration node, - TreeNode? removalSentinel, - ) { + TreeNode defaultVariable(Variable node, TreeNode? removalSentinel) { transformAnnotations(node.annotations, node); Expression? initializer = node.initializer; @@ -1008,16 +1003,15 @@ class ConstantsTransformer extends RemovingTransformer { ); } else { // matchResultVariable: int RVAR = -1; - VariableDeclaration matchResultVariable = extern - .createInitializedVariable( - extern.createIntLiteral( - typeEnvironment.coreTypes, - -1, - fileOffset: node.fileOffset, - ), - typeEnvironment.coreTypes.intNonNullableRawType, - fileOffset: node.fileOffset, - ); + Variable matchResultVariable = extern.createInitializedVariable( + extern.createIntLiteral( + typeEnvironment.coreTypes, + -1, + fileOffset: node.fileOffset, + ), + typeEnvironment.coreTypes.intNonNullableRawType, + fileOffset: node.fileOffset, + ); LabeledStatement innerLabeledStatement = extern.createLabeledStatement( dummyStatement, fileOffset: node.fileOffset, @@ -1050,7 +1044,7 @@ class ConstantsTransformer extends RemovingTransformer { List replacementCases = []; - List declaredVariableHelpers = []; + List declaredVariableHelpers = []; List cases = []; @@ -1079,7 +1073,7 @@ class ConstantsTransformer extends RemovingTransformer { // TODO(johnniwinther): Remove this when an error is reported in case of // variables and labels on the same switch case. - Map> declaredVariablesByName = {}; + Map> declaredVariablesByName = {}; // In weak mode we need to throw on `null` for non-nullable types. bool needsThrowForNull = false; @@ -1096,8 +1090,8 @@ class ConstantsTransformer extends RemovingTransformer { // TODO(cstefantsova): Make sure an error is reported if the variables // declared in the heads aren't compatible to each other. - Map caseDeclaredVariableHelpersByName = { - for (VariableDeclaration variable in switchCase.jointVariables) + Map caseDeclaredVariableHelpersByName = { + for (Variable variable in switchCase.jointVariables) variable.name!: extern.createUninitializedVariable( const DynamicType(), // Avoid step debugging on the declaration of intermediate @@ -1110,10 +1104,10 @@ class ConstantsTransformer extends RemovingTransformer { bool isContinueTarget = switchCaseIndex.containsKey(switchCase); - List caseVariables = []; + List caseVariables = []; // TODO(johnniwinther): Is there a way to avoid these name clashes? - Map> caseVariablesByName = {}; + Map> caseVariablesByName = {}; Expression? caseCondition; for ( @@ -1128,18 +1122,17 @@ class ConstantsTransformer extends RemovingTransformer { if (isContinueTarget) { // TODO(johnniwinther): In this case it should be an error to have // any variables. This is not currently reported. - for (VariableDeclaration declaredVariable - in pattern.declaredVariables) { + for (Variable declaredVariable in pattern.declaredVariables) { replacementStatements.add( extern.createVariableStatement(declaredVariable), ); } - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { (declaredVariablesByName[variable.name!] ??= []).add(variable); } } else { - for (VariableDeclaration variable in pattern.declaredVariables) { + for (Variable variable in pattern.declaredVariables) { (caseVariablesByName[variable.name!] ??= []).add(variable); } caseVariables.addAll(pattern.declaredVariables); @@ -1160,11 +1153,10 @@ class ConstantsTransformer extends RemovingTransformer { ); } - for (VariableDeclaration declaredVariable - in pattern.declaredVariables) { + for (Variable declaredVariable in pattern.declaredVariables) { String variableName = declaredVariable.name!; - VariableDeclaration? variableHelper = + Variable? variableHelper = caseDeclaredVariableHelpersByName[variableName]; if (variableHelper != null) { // headCondition: `headCondition` && @@ -1208,11 +1200,10 @@ class ConstantsTransformer extends RemovingTransformer { } } - for (List variables - in caseVariablesByName.values) { + for (List variables in caseVariablesByName.values) { if (variables.length > 1) { for (int i = 0; i < variables.length; i++) { - VariableDeclaration variable = variables[i]; + Variable variable = variables[i]; variable.isLowered = true; variable.name = createJoinedIntermediateName(variable.name!, i); } @@ -1223,7 +1214,7 @@ class ConstantsTransformer extends RemovingTransformer { caseDeclaredVariableHelpersByName.values, ); - for (VariableDeclaration jointVariable in switchCase.jointVariables) { + for (Variable jointVariable in switchCase.jointVariables) { // In case of [InvalidExpression], there's an error associated with // the variable, and it shouldn't be initialized. if (jointVariable.initializer is! InvalidExpression) { @@ -1273,8 +1264,7 @@ class ConstantsTransformer extends RemovingTransformer { ], [node.fileOffset], extern.createBlock([ - for (VariableDeclaration jointVariable - in switchCase.jointVariables) + for (Variable jointVariable in switchCase.jointVariables) extern.createVariableStatement(jointVariable), if (body is! Block || body.statements.isNotEmpty) body, ], fileOffset: node.fileOffset), @@ -1297,7 +1287,7 @@ class ConstantsTransformer extends RemovingTransformer { replacementCases.add(replacementCase); } else { caseBlock = extern.createBlock([ - for (VariableDeclaration jointVariable in switchCase.jointVariables) + for (Variable jointVariable in switchCase.jointVariables) extern.createVariableStatement(jointVariable), if (body is! Block || body.statements.isNotEmpty) body, ], fileOffset: switchCase.fileOffset); @@ -1331,7 +1321,7 @@ class ConstantsTransformer extends RemovingTransformer { } cases.add( extern.createBlock([ - for (VariableDeclaration caseVariable in caseVariables) + for (Variable caseVariable in caseVariables) extern.createVariableStatement(caseVariable), caseBlock, if (breakStatement != null) @@ -1369,8 +1359,7 @@ class ConstantsTransformer extends RemovingTransformer { // TODO(johnniwinther): Find a better way to avoid name clashes between // cases. - for (List variables - in declaredVariablesByName.values) { + for (List variables in declaredVariablesByName.values) { if (variables.length > 1) { for (int i = 1; i < variables.length; i++) { variables[i].name = '${variables[i].name}${"#$i"}'; @@ -1387,10 +1376,9 @@ class ConstantsTransformer extends RemovingTransformer { replacementStatements = [ extern.createVariableStatement(matchResultVariable), ...replacementStatements, - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), - for (VariableDeclaration declaredVariableHelper - in declaredVariableHelpers) + for (Variable declaredVariableHelper in declaredVariableHelpers) extern.createVariableStatement(declaredVariableHelper), innerLabeledStatement, extern.createSwitchStatement( @@ -1404,10 +1392,9 @@ class ConstantsTransformer extends RemovingTransformer { } else { replacementStatements = [ ...replacementStatements, - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), - for (VariableDeclaration declaredVariableHelper - in declaredVariableHelpers) + for (Variable declaredVariableHelper in declaredVariableHelpers) extern.createVariableStatement(declaredVariableHelper), ...cases, ]; @@ -1646,17 +1633,17 @@ class ConstantsTransformer extends RemovingTransformer { } List cacheVariables = [ - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), ]; - Iterable declarations = + Iterable declarations = node.patternGuard.pattern.declaredVariables; Statement ifStatement; if (declarations.isNotEmpty) { // If we need local declarations, create a new block to avoid naming // collision with declarations in the same parent block. ifStatement = extern.createBlock([ - for (VariableDeclaration declaration in declarations) + for (Variable declaration in declarations) extern.createVariableStatement(declaration), extern.createIfStatement( condition, @@ -1720,7 +1707,7 @@ class ConstantsTransformer extends RemovingTransformer { replacementStatements, ); replacementStatements = [ - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), ...replacementStatements, ]; @@ -1730,7 +1717,7 @@ class ConstantsTransformer extends RemovingTransformer { inCacheInitializer: false, ); replacementStatements = [ - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), // TODO(cstefantsova): Provide a better diagnostic message. extern.createIfStatement( @@ -1762,8 +1749,7 @@ class ConstantsTransformer extends RemovingTransformer { ]; } replacementStatements = [ - for (VariableDeclaration declaredVariable - in node.pattern.declaredVariables) + for (Variable declaredVariable in node.pattern.declaredVariables) extern.createVariableStatement(declaredVariable), ...replacementStatements, ]; @@ -1814,10 +1800,9 @@ class ConstantsTransformer extends RemovingTransformer { effects: effects, ); replacementStatements = [ - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), - for (VariableDeclaration declaredVariable - in node.pattern.declaredVariables) + for (Variable declaredVariable in node.pattern.declaredVariables) extern // Coverage-ignore(suite): Not run. .createVariableStatement(declaredVariable), ...replacementStatements, @@ -1832,10 +1817,9 @@ class ConstantsTransformer extends RemovingTransformer { ); replacementStatements = [ - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), - for (VariableDeclaration declaredVariable - in node.pattern.declaredVariables) + for (Variable declaredVariable in node.pattern.declaredVariables) extern // Coverage-ignore(suite): Not run. .createVariableStatement(declaredVariable), // TODO(cstefantsova): Provide a better diagnostic message. @@ -1998,7 +1982,7 @@ class ConstantsTransformer extends RemovingTransformer { Expression replacement; if (primitiveEqualConstantsOnly) { - VariableDeclaration valueVariable = extern.createUninitializedVariable( + Variable valueVariable = extern.createUninitializedVariable( node.staticType!, // Avoid step debugging on the declarations of the value variable. // TODO(johnniwinther): Find a more systematic way of omitting @@ -2081,7 +2065,7 @@ class ConstantsTransformer extends RemovingTransformer { ); // valueVariable: `valueType` valueVariable; - VariableDeclaration valueVariable = extern.createUninitializedVariable( + Variable valueVariable = extern.createUninitializedVariable( node.staticType!, // Avoid step debugging on the declaration of the value variable. // TODO(johnniwinther): Find a more systematic way of omitting @@ -2162,8 +2146,7 @@ class ConstantsTransformer extends RemovingTransformer { cases.add( extern.createBlock([ - for (VariableDeclaration declaredVariable - in pattern.declaredVariables) + for (Variable declaredVariable in pattern.declaredVariables) extern.createVariableStatement(declaredVariable), extern.createIfStatement( caseCondition, @@ -2228,7 +2211,7 @@ class ConstantsTransformer extends RemovingTransformer { replacement = extern.createBlockExpression( extern.createBlock([ extern.createVariableStatement(valueVariable), - for (VariableDeclaration declaration in matchingCache.declarations) + for (Variable declaration in matchingCache.declarations) extern.createVariableStatement(declaration), labeledStatement, ], fileOffset: node.fileOffset), @@ -2262,7 +2245,7 @@ class ConstantsTransformer extends RemovingTransformer { @override TreeNode visitVariableGet(VariableGet node, TreeNode? removalSentinel) { - final VariableDeclaration variable = node.variable; + final Variable variable = node.variable; if (variable.isConst) { // TODO(63414): Obtain the initializer parent uniformly rather than using // the 'switch'. @@ -3711,7 +3694,7 @@ class ConstantEvaluator env.addTypeParameterValue(klass.typeParameters[i], typeArguments[i]); } for (int i = 0; i < function.positionalParameters.length; i++) { - final VariableDeclaration parameter = function.positionalParameters[i]; + final Variable parameter = function.positionalParameters[i]; final Constant value = (i < positionalArguments.length) ? positionalArguments[i] // TODO(johnniwinther): This should call [_evaluateSubexpression]. @@ -3719,7 +3702,7 @@ class ConstantEvaluator if (value is AbortConstant) return value; env.addVariableValue(parameter, value); } - for (final VariableDeclaration parameter in function.namedParameters) { + for (final Variable parameter in function.namedParameters) { final Constant value = namedArguments[parameter.name] ?? // TODO(johnniwinther): This should call [_evaluateSubexpression]. @@ -3744,7 +3727,7 @@ class ConstantEvaluator if (constant is AbortConstant) return constant; instanceBuilder!.setFieldValue(init.field, constant); case LocalInitializer(): - final VariableDeclaration variable = init.variable; + final Variable variable = init.variable; Constant constant = _evaluateSubexpression(variable.initializer!); if (constant is AbortConstant) return constant; env.addVariableValue(variable, constant); @@ -4901,7 +4884,7 @@ class ConstantEvaluator // // TODO(kustermann): The heuristic of allowing all [VariableGet]s on [Let] // variables might allow more than it should. - final VariableDeclaration variable = node.variable; + final Variable variable = node.variable; if (enableConstFunctions || inExtensionTypeConstConstructor) { return env.lookupVariable(variable) ?? // Coverage-ignore(suite): Not run. @@ -4938,7 +4921,7 @@ class ConstantEvaluator @override Constant visitVariableSet(VariableSet node) { if (enableConstFunctions || inExtensionTypeConstConstructor) { - final VariableDeclaration variable = node.variable; + final Variable variable = node.variable; Constant value = _evaluateSubexpression(node.value); if (value is AbortConstant) return value; Constant? result = env.updateVariableValue(variable, value); @@ -4949,7 +4932,7 @@ class ConstantEvaluator return createEvaluationErrorConstant( node, diag.constEvalError.withArguments( - message: 'VariableDeclaration set of an unknown value.', + message: 'Variable set of an unknown value.', ), ); } @@ -5058,7 +5041,7 @@ class ConstantEvaluator } Constant _getFromEnvironmentDefaultValue(Procedure target) { - VariableDeclaration variable = target.function.namedParameters.singleWhere( + Variable variable = target.function.namedParameters.singleWhere( (v) => v.name == 'defaultValue', ); return evaluateExpressionInContext(target, variable.initializer!); @@ -5341,7 +5324,7 @@ class ConstantEvaluator env.addTypeParameterValue(function.typeParameters[i], typeArguments[i]); } for (int i = 0; i < function.positionalParameters.length; i++) { - final VariableDeclaration parameter = function.positionalParameters[i]; + final Variable parameter = function.positionalParameters[i]; final Constant value = (i < positionalArguments.length) ? positionalArguments[i] // TODO(johnniwinther): This should call [_evaluateSubexpression]. @@ -5349,7 +5332,7 @@ class ConstantEvaluator if (value is AbortConstant) return value; env.addVariableValue(parameter, value); } - for (final VariableDeclaration parameter in function.namedParameters) { + for (final Variable parameter in function.namedParameters) { final Constant value = namedArguments[parameter.name] ?? // TODO(johnniwinther): This should call [_evaluateSubexpression]. @@ -6369,7 +6352,7 @@ class StatementConstantEvaluator } @override - ExecutionStatus visitVariableDeclaration(VariableDeclaration node) { + ExecutionStatus visitVariable(Variable node) { Constant value; if (node.initializer != null) { value = evaluate(node.initializer!); @@ -6536,15 +6519,14 @@ 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; @@ -6565,14 +6547,14 @@ class EvaluationEnvironment { _typeParameters[parameter] = value; } - void addVariableValue(VariableDeclaration variable, Constant value) { + void addVariableValue(Variable variable, Constant value) { _variables[variable] = new EvaluationReference(value); if (value is UnevaluatedConstant) { _unreadUnevaluatedVariables.add(variable); } } - Constant? updateVariableValue(VariableDeclaration variable, Constant value) { + Constant? updateVariableValue(Variable variable, Constant value) { EvaluationReference? reference = _variables[variable]; if (reference != null) { reference.value = value; @@ -6581,7 +6563,7 @@ class EvaluationEnvironment { return _parent?.updateVariableValue(variable, value); } - Constant? lookupVariable(VariableDeclaration variable) { + Constant? lookupVariable(Variable variable) { Constant? value = _variables[variable]?.value; if (value is UnevaluatedConstant) { _unreadUnevaluatedVariables.remove(variable); @@ -6596,8 +6578,7 @@ class EvaluationEnvironment { if (_unreadUnevaluatedVariables.isEmpty) return const []; // Coverage-ignore(suite): Not run. return _unreadUnevaluatedVariables.map( - (VariableDeclaration variable) => - _variables[variable]!.value as UnevaluatedConstant, + (Variable variable) => _variables[variable]!.value as UnevaluatedConstant, ); } @@ -6890,7 +6871,7 @@ class HasUninstantiatedVisitor extends FindTypeVisitor { } } -bool _isFormalParameter(VariableDeclaration variable) { +bool _isFormalParameter(Variable variable) { final TreeNode? parent = variable.parent; if (variable is FunctionParameter) { return true; @@ -6909,7 +6890,7 @@ class _InlinedBlock extends Block { class _PatternSwitchStatementInfo { /// The variable used as the switch expression in the generated /// [SwitchStatement]. - final VariableDeclaration switchIndexVariable; + final Variable switchIndexVariable; /// The labeled statement that wraps the case matching. /// diff --git a/pkg/front_end/lib/src/kernel/constructor_tearoff_lowering.dart b/pkg/front_end/lib/src/kernel/constructor_tearoff_lowering.dart index 4b661753ae7..05e4f1676ab 100644 --- a/pkg/front_end/lib/src/kernel/constructor_tearoff_lowering.dart +++ b/pkg/front_end/lib/src/kernel/constructor_tearoff_lowering.dart @@ -366,8 +366,8 @@ DelayedDefaultValueCloner _createParameters( bool isClosureContextLoweringEnabled = libraryBuilder.loader.isClosureContextLoweringEnabled; - VariableDeclaration createTearOffParameter( - VariableDeclaration constructorParameter, { + Variable createTearOffParameter( + Variable constructorParameter, { required bool isPositional, }) { DartType tearOffParameterType = substitution.substituteType( @@ -397,17 +397,16 @@ DelayedDefaultValueCloner _createParameters( } } - for (VariableDeclaration constructorParameter - in function.positionalParameters) { - VariableDeclaration tearOffParameter = createTearOffParameter( + for (Variable constructorParameter in function.positionalParameters) { + Variable tearOffParameter = createTearOffParameter( constructorParameter, isPositional: true, ); tearOff.function.positionalParameters.add(tearOffParameter); tearOffParameter.parent = tearOff.function; } - for (VariableDeclaration constructorParameter in function.namedParameters) { - VariableDeclaration tearOffParameter = createTearOffParameter( + for (Variable constructorParameter in function.namedParameters) { + Variable tearOffParameter = createTearOffParameter( constructorParameter, isPositional: false, ); @@ -443,15 +442,13 @@ Arguments _createArguments( int fileOffset, ) { List positionalArguments = []; - for (VariableDeclaration tearOffParameter - in tearOff.function.positionalParameters) { + for (Variable tearOffParameter in tearOff.function.positionalParameters) { positionalArguments.add( extern.createVariableGet(tearOffParameter, fileOffset: fileOffset), ); } List namedArguments = []; - for (VariableDeclaration tearOffParameter - in tearOff.function.namedParameters) { + for (Variable tearOffParameter in tearOff.function.namedParameters) { namedArguments.add( extern.createNamedExpression( tearOffParameter.name!, diff --git a/pkg/front_end/lib/src/kernel/dart_scope_calculator.dart b/pkg/front_end/lib/src/kernel/dart_scope_calculator.dart index 10e84e24552..4339b0703e4 100644 --- a/pkg/front_end/lib/src/kernel/dart_scope_calculator.dart +++ b/pkg/front_end/lib/src/kernel/dart_scope_calculator.dart @@ -17,7 +17,7 @@ class DartScope { final Class? cls; final Member? member; final bool isStatic; - final Map variables; + final Map variables; final List typeParameters; DartScope( @@ -32,7 +32,7 @@ class DartScope { Map variablesAsMapToType() { Map result = {}; - for (MapEntry entry in variables.entries) { + for (MapEntry entry in variables.entries) { result[entry.key] = entry.value.type; } return result; @@ -62,7 +62,7 @@ class DartScope2 { final Class? cls; final Member? member; final bool isStatic; - final Map variables; + final Map variables; final List typeParameters; DartScope2( @@ -96,8 +96,8 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { final List findScopes = []; int? closestLessOrEqualFoundOffset; - final Set hoistedUnwritten = {}; - final List> scopes = []; + final Set hoistedUnwritten = {}; + final List> scopes = []; final List> typeParameterScopes = []; Class? _currentCls = null; @@ -115,9 +115,9 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { } void addFound(TreeNode node) { - Map definitions = {}; - for (List scope in scopes) { - for (VariableDeclaration decl in scope) { + Map definitions = {}; + for (List scope in scopes) { + for (Variable decl in scope) { String? name = decl.name; if (name != null && !decl.isSynthesized && @@ -271,10 +271,10 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { // The constructor is special in that the parameters from the contained // function node is in scope in the initializers. node.function.accept(this); - for (VariableDeclaration param in node.function.positionalParameters) { + for (Variable param in node.function.positionalParameters) { scopes.last.add(param); } - for (VariableDeclaration param in node.function.namedParameters) { + for (Variable param in node.function.namedParameters) { scopes.last.add(param); } for (Initializer initializer in node.initializers) { @@ -376,9 +376,9 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { if (node.isHoisted) hoistedUnwritten.add(node); - super.defaultVariableDeclaration(node); + super.defaultVariable(node); // Declare it after. scopes.last.add(node); } @@ -563,13 +563,12 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { static bool _allHaveTheSameDefinitions(List scopes) { if (scopes.isEmpty) return false; - Map variables = scopes.first.variables; + Map variables = scopes.first.variables; for (int i = 1; i < scopes.length; i++) { DartScope2 scope = scopes[i]; if (scope.variables.length != variables.length) return false; - for (MapEntry entry - in scope.variables.entries) { - VariableDeclaration? existing = variables[entry.key]; + for (MapEntry entry in scope.variables.entries) { + Variable? existing = variables[entry.key]; if (existing == null) { return false; } else { @@ -699,13 +698,13 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { return [filtered[1]]; } if (filtered.length == 2 && - filtered[0].node is VariableDeclaration && + filtered[0].node is Variable && filtered[1].node is FieldInitializer) { // Pick the FieldInitializer (i.e. have the variable in scope). return [filtered[1]]; } if (filtered.length == 2 && - filtered[0].node is VariableDeclaration && + filtered[0].node is Variable && filtered[1].node is VariableGet && filtered[1].node.parent?.parent is SuperInitializer) { // E.g. `Foo(super.bar)`. @@ -720,7 +719,7 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { return [filtered[1]]; } if (filtered.length == 2 && - filtered[0].node is VariableDeclaration && + filtered[0].node is Variable && filtered[1].node is VariableGet && filtered[0].node.parent?.parent is Procedure && (filtered[0].node.parent?.parent as Procedure).isRedirectingFactory) { @@ -739,7 +738,7 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { return [filtered[0]]; } if (filtered.length == 2 && - filtered[0].node is VariableDeclaration && + filtered[0].node is Variable && filtered[1].node is VariableGet && filtered[0].node.parent?.parent is Constructor && filtered[1].node.parent?.parent is Arguments) { @@ -872,7 +871,7 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { filtered[1].node is FunctionNode && filtered[2].node is ReturnStatement && filtered[3].node is Let && - filtered[4].node is VariableDeclaration) { + filtered[4].node is Variable) { // The 10 is not special. This has just been observed to contain lots of // scopes. return filtered[0]; @@ -883,8 +882,7 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { // The 10 is not special. This has just been observed to contain lots of // scopes. for (int i = 3; i < filtered.length - 1; i++) { - if (filtered[i].node is Let && - filtered[i + 1].node is VariableDeclaration) { + if (filtered[i].node is Let && filtered[i + 1].node is Variable) { return filtered[0]; } } @@ -898,8 +896,7 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { filtered[i + 1].node is FunctionNode && filtered[i + 2].node is ReturnStatement) { for (int j = i + 1; j < filtered.length - 1; j++) { - if (filtered[j].node is Let && - filtered[j + 1].node is VariableDeclaration) { + if (filtered[j].node is Let && filtered[j + 1].node is Variable) { return filtered[0]; } } @@ -927,8 +924,8 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { static DartScope2? _looksLikePatternMatching(List filtered) { if (filtered.length > 5 && - filtered[0].node is VariableDeclaration && - (filtered[0].node as VariableDeclaration).isHoisted) { + filtered[0].node is Variable && + (filtered[0].node as Variable).isHoisted) { // The 5 is not special. This has just been observed to contain lots of // scopes. // Pattern matching looks something like this: @@ -963,13 +960,13 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { } } if (filtered.length > 5 && - filtered[0].node is VariableDeclaration && - filtered[1].node is VariableDeclaration && + filtered[0].node is Variable && + filtered[1].node is Variable && filtered.last.node is LocalFunctionInvocation) { // It's beginning to look a lot like a late lowered nullable pattern // matching case. - VariableDeclaration variable1 = filtered[0].node as VariableDeclaration; - VariableDeclaration variable2 = filtered[1].node as VariableDeclaration; + Variable variable1 = filtered[0].node as Variable; + Variable variable2 = filtered[1].node as Variable; if (variable1.isSynthesized && variable1.name?.startsWith("#") == true && variable2.isSynthesized && @@ -981,8 +978,8 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { } } if (filtered.length <= 4 && - filtered[0].node is VariableDeclaration && - (filtered[0].node as VariableDeclaration).isHoisted && + filtered[0].node is Variable && + (filtered[0].node as Variable).isHoisted && filtered.last.node is VariableSet && (filtered.last.node as VariableSet).variable == filtered[0].node) { return filtered.last; @@ -991,28 +988,28 @@ class DartScopeBuilder2 extends VisitorDefault with VisitorVoidMixin { } static DartScope2? _looksLikeLateLoweredLocal(List filtered) { - VariableDeclaration? variable1; - VariableDeclaration? variable2; + Variable? variable1; + Variable? variable2; if (filtered.length > 5 && - filtered[0].node is VariableDeclaration && - filtered[1].node is VariableDeclaration) { + filtered[0].node is Variable && + filtered[1].node is Variable) { // A nullable one, e.g. `late Foo? foo` becomes something like // ``` // Foo? #foo; // bool #foo#isSet = false; // ``` - variable1 = filtered[0].node as VariableDeclaration; - variable2 = filtered[1].node as VariableDeclaration; + variable1 = filtered[0].node as Variable; + variable2 = filtered[1].node as Variable; } else if (filtered.length > 5 && - filtered[0].node is VariableDeclaration && - filtered[2].node is VariableDeclaration) { + filtered[0].node is Variable && + filtered[2].node is Variable) { // A non-nullable one, e.g. `late Foo foo` becomes something like // ``` // Foo? #foo; // Foo #foo#get() => bla bla // ``` - variable1 = filtered[0].node as VariableDeclaration; - variable2 = filtered[2].node as VariableDeclaration; + variable1 = filtered[0].node as Variable; + variable2 = filtered[2].node as Variable; } if (variable1 != null && variable2 != null) { // isLateLoweredLocalName/isLateLoweredLocalSetter/etc is in the CFE so we diff --git a/pkg/front_end/lib/src/kernel/expression_generator.dart b/pkg/front_end/lib/src/kernel/expression_generator.dart index 72ed799b7e1..93c0ea87b74 100644 --- a/pkg/front_end/lib/src/kernel/expression_generator.dart +++ b/pkg/front_end/lib/src/kernel/expression_generator.dart @@ -434,7 +434,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 VariableDeclaration variable; + final Variable variable; VariableUseGenerator( ExpressionGeneratorHelper helper, @@ -641,7 +641,7 @@ class ForInLateFinalVariableUseGenerator extends VariableUseGenerator { ForInLateFinalVariableUseGenerator( ExpressionGeneratorHelper helper, Token token, - VariableDeclaration variable, + Variable variable, ) : super(helper, token, variable); @override @@ -959,7 +959,7 @@ class ThisPropertyAccessGenerator extends Generator { /// The synthetic variable used for 'this' in instance extension members /// and instance extension type members/constructor bodies. - VariableDeclaration? thisVariable; + Variable? thisVariable; ThisPropertyAccessGenerator( ExpressionGeneratorHelper helper, @@ -2560,7 +2560,7 @@ class ExtensionInstanceAccessGenerator extends Generator { /// instance method. // TODO(johnniwinther): Handle static access to extension instance members, // in which case the access is erroneous and [extensionThis] is `null`. - final VariableDeclaration extensionThis; + final Variable extensionThis; /// The type parameters synthetically added to the current extension /// instance method. @@ -2584,7 +2584,7 @@ class ExtensionInstanceAccessGenerator extends Generator { Token token, Extension extension, Name targetName, - VariableDeclaration extensionThis, + Variable extensionThis, List? extensionTypeParameters, MemberBuilder? getterBuilder, MemberBuilder? setterBuilder, 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 6ae4e15f2c8..516b775940a 100644 --- a/pkg/front_end/lib/src/kernel/expression_generator_helper.dart +++ b/pkg/front_end/lib/src/kernel/expression_generator_helper.dart @@ -39,7 +39,7 @@ typedef Expression_Generator_Initializer = dynamic; typedef Expression_Initializer = dynamic; abstract class ExpressionGeneratorHelper { - VariableDeclaration? get thisVariable; + Variable? get thisVariable; Uri get uri; @@ -84,7 +84,7 @@ abstract class ExpressionGeneratorHelper { LibraryFeatures get libraryFeatures; - bool isDeclaredInEnclosingCase(VariableDeclaration variable); + bool isDeclaredInEnclosingCase(Variable variable); Generator processLookupResult({ required LookupResult? lookupResult, @@ -227,17 +227,17 @@ abstract class ExpressionGeneratorHelper { /// Creates a [VariableGet] of the [variable] using [charOffset] as the file /// offset of the created node. - Expression createVariableGet(VariableDeclaration variable, int charOffset); + Expression createVariableGet(Variable variable, int charOffset); /// Registers that [variable] is read from. /// /// This is needed for type promotion. - void registerVariableRead(VariableDeclaration variable); + void registerVariableRead(Variable variable); /// Registers that [variable] is assigned to. /// /// This is needed for type promotion. - void registerVariableAssignment(VariableDeclaration variable); + void registerVariableAssignment(Variable 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 5a0a01cd9ba..1fdbf174477 100644 --- a/pkg/front_end/lib/src/kernel/external_ast_helper.dart +++ b/pkg/front_end/lib/src/kernel/external_ast_helper.dart @@ -293,8 +293,8 @@ FunctionExpression createFunctionExpression( FunctionNode createFunctionNode( Statement? body, { List? typeParameters, - List? positionalParameters, - List? namedParameters, + List? positionalParameters, + List? namedParameters, int? requiredParameterCount, DartType returnType = const DynamicType(), required int fileOffset, @@ -357,15 +357,15 @@ Field createImmutableField( ..fileEndOffset = fileEndOffset; } -/// Creates an initialized (but mutable) [VariableDeclaration] of the static +/// Creates an initialized (but mutable) [Variable] of the static /// [type]. -VariableDeclaration createInitializedVariable( +Variable createInitializedVariable( Expression expression, DartType type, { required int fileOffset, String? name, }) { - return new VariableDeclaration( + return new Variable( name, initializer: expression, type: type, @@ -491,7 +491,7 @@ LabeledStatement createLabeledStatement( /// Creates a [Let] of [variable] with the given [body] using /// `variable.fileOffset` as the file offset for the let. -Let createLet(VariableDeclaration variable, Expression body) { +Let createLet(Variable variable, Expression body) { return new Let(variable, body)..fileOffset = variable.fileOffset; } @@ -506,7 +506,7 @@ Let createLetEffect({required Expression effect, required Expression result}) { /// Creates an invocation of the local function [variable] with the provided /// [arguments]. LocalFunctionInvocation createLocalFunctionInvocation( - VariableDeclaration variable, { + Variable variable, { Arguments? arguments, required int fileOffset, }) { @@ -624,7 +624,7 @@ LogicalExpression createOrExpression( } // TODO(johnniwinther): Should this require a type? -VariableDeclaration createParameterVariable( +Variable createParameterVariable( String? name, { DartType type = const DynamicType(), required int fileOffset, @@ -637,7 +637,7 @@ VariableDeclaration createParameterVariable( Expression? initializer, bool hasDeclaredInitializer = false, }) { - return new VariableDeclaration( + return new Variable( name, type: type, isCovariantByDeclaration: isCovariantByDeclaration, @@ -853,40 +853,36 @@ TypeParameter createTypeParameter(String? name, {required int fileOffset}) { return new TypeParameter(name)..fileOffset = fileOffset; } -/// Creates an uninitialized [VariableDeclaration] of the static [type]. -VariableDeclaration createUninitializedVariable( +/// Creates an uninitialized [Variable] of the static [type]. +Variable createUninitializedVariable( DartType type, { required int fileOffset, bool isFinal = false, }) { - return new VariableDeclaration( - null, - type: type, - isSynthesized: true, - isFinal: isFinal, - )..fileOffset = fileOffset; + return new Variable(null, type: type, isSynthesized: true, isFinal: isFinal) + ..fileOffset = fileOffset; } -/// Creates a [VariableDeclaration] for [expression] with the static [type] +/// Creates a [Variable] for [expression] with the static [type] /// using `expression.fileOffset` as the file offset for the declaration. // TODO(johnniwinther): Merge the use of this with [createVariableCache]. -VariableDeclaration createVariable(Expression expression, DartType type) { +Variable createVariable(Expression expression, DartType type) { assert(expression is! ThisExpression); - return new VariableDeclaration.forValue(expression, type: type) + return new Variable.forValue(expression, type: type) ..fileOffset = expression.fileOffset; } -/// Creates a [VariableDeclaration] for caching [expression] of the static +/// Creates a [Variable] for caching [expression] of the static /// [type] using `expression.fileOffset` as the file offset for the declaration. -VariableDeclaration createVariableCache(Expression expression, DartType type) { - return new VariableDeclaration.forValue(expression, type: type) +Variable createVariableCache(Expression expression, DartType type) { + return new Variable.forValue(expression, type: type) ..fileOffset = expression.fileOffset; } /// Creates a [VariableGet] of [variable] using `variable.fileOffset` as the /// file offset for the expression. VariableGet createVariableGet( - VariableDeclaration variable, { + Variable variable, { DartType? promotedType, int? fileOffset, }) { @@ -897,7 +893,7 @@ VariableGet createVariableGet( /// Creates a [VariableSet] of [variable] with the [value]. Expression createVariableSet( - VariableDeclaration variable, + Variable variable, Expression value, { bool allowFinalAssignment = false, required int fileOffset, @@ -917,6 +913,6 @@ Expression createVariableSet( } } -VariableStatement createVariableStatement(VariableDeclaration variable) { +VariableStatement createVariableStatement(Variable variable) { return new VariableStatement(variable)..fileOffset = variable.fileOffset; } diff --git a/pkg/front_end/lib/src/kernel/forwarding_node.dart b/pkg/front_end/lib/src/kernel/forwarding_node.dart index 7713f10f6a8..a7171819bcf 100644 --- a/pkg/front_end/lib/src/kernel/forwarding_node.dart +++ b/pkg/front_end/lib/src/kernel/forwarding_node.dart @@ -352,8 +352,7 @@ class ForwardingNode { List positionalArguments = new List.generate( function.positionalParameters.length, (int index) { - VariableDeclaration parameter = - function.positionalParameters[index]; + Variable parameter = function.positionalParameters[index]; int fileOffset = parameter.fileOffset; Expression expression = extern.createVariableGet(parameter); DartType superParameterType = type.positionalParameters[index]; @@ -381,7 +380,7 @@ class ForwardingNode { List namedArguments = new List.generate( function.namedParameters.length, (int index) { - VariableDeclaration parameter = function.namedParameters[index]; + Variable parameter = function.namedParameters[index]; int fileOffset = parameter.fileOffset; Expression expression = extern.createVariableGet(parameter); DartType superParameterType = type.namedParameters @@ -441,7 +440,7 @@ class ForwardingNode { case ProcedureKind.Setter: DartType superParameterType = _combinedMemberSignature .getMemberTypeForTarget(superTarget); - VariableDeclaration parameter = function.positionalParameters[0]; + Variable parameter = function.positionalParameters[0]; int fileOffset = parameter.fileOffset; Expression expression = extern.createVariableGet(parameter); if (isForwardingSemiStub) { @@ -564,16 +563,12 @@ class ForwardingNode { FunctionType signatureType = procedure.function.computeFunctionType( procedure.enclosingLibrary.nonNullable, ); - List positionalParameters = + List positionalParameters = procedure.function.positionalParameters; - List namedParameters = - procedure.function.namedParameters; + List namedParameters = procedure.function.namedParameters; int requiredParameterCount = procedure.function.requiredParameterCount; bool hasUpdate = false; - bool updateNullability( - VariableDeclaration parameter, { - required bool isRequired, - }) { + bool updateNullability(Variable parameter, {required bool isRequired}) { // Parameters in nnbd libraries that backends might not be able to pass // a non-null value for must be nullable. This allows backends to do the // appropriate parameter checks in the forwarder stub for null placeholder @@ -586,7 +581,7 @@ class ForwardingNode { } for (int i = 0; i < positionalParameters.length; i++) { - VariableDeclaration parameter = positionalParameters[i]; + Variable parameter = positionalParameters[i]; bool isRequired = i < requiredParameterCount; if (updateNullability(parameter, isRequired: isRequired)) { parameter.type = parameter.type.withDeclaredNullability( @@ -596,7 +591,7 @@ class ForwardingNode { } } - for (VariableDeclaration parameter in namedParameters) { + for (Variable parameter in namedParameters) { if (updateNullability(parameter, isRequired: parameter.isRequired)) { parameter.type = parameter.type.withDeclaredNullability( Nullability.nullable, diff --git a/pkg/front_end/lib/src/kernel/hierarchy/members_builder.dart b/pkg/front_end/lib/src/kernel/hierarchy/members_builder.dart index f512c364835..60f8d056fb1 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/members_builder.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/members_builder.dart @@ -310,6 +310,6 @@ class ClassMembersBuilder implements ClassHierarchyMembers { } } -int compareNamedParameters(VariableDeclaration a, VariableDeclaration b) { +int compareNamedParameters(Variable a, Variable b) { return a.name!.compareTo(b.name!); } diff --git a/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart b/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart index 1d950e2290d..3ae6a31dbae 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart @@ -156,10 +156,8 @@ class ClassMembersNodeBuilder extends MembersNodeBuilder { )) { List declaredTypeParameters = declaredFunction.typeParameters; - List declaredPositional = - declaredFunction.positionalParameters; - List declaredNamed = - declaredFunction.namedParameters; + List declaredPositional = declaredFunction.positionalParameters; + List declaredNamed = declaredFunction.namedParameters; declaredNamed = declaredNamed.toList()..sort(compareNamedParameters); DartType? inferredReturnType; diff --git a/pkg/front_end/lib/src/kernel/internal_ast.dart b/pkg/front_end/lib/src/kernel/internal_ast.dart index da3af2a5340..6a540a4da99 100644 --- a/pkg/front_end/lib/src/kernel/internal_ast.dart +++ b/pkg/front_end/lib/src/kernel/internal_ast.dart @@ -40,7 +40,7 @@ import 'external_ast_helper.dart' as extern; /// @docImport 'package:_fe_analyzer_shared/src/flow_analysis/flow_analysis.dart'; typedef SharedMatchContext = - shared.MatchContext; + shared.MatchContext; mixin InternalTreeNode implements TreeNode { @override @@ -457,7 +457,7 @@ class ActualArguments extends TreeNode with InternalTreeNode { class Cascade extends InternalExpression { /// The temporary variable holding the cascade receiver expression in its /// initializer; - VariableDeclaration variable; + Variable variable; /// `true` if the access is null-aware, i.e. of the form `a?..b()`. final bool isNullAware; @@ -515,7 +515,7 @@ class Cascade extends InternalExpression { /// Internal expression representing an anonymous method invocation. class AnonymousMethodExpression extends InternalExpression { - VariableDeclaration variable; + Variable variable; Expression body; final bool isCascade; final bool isImplicitlyTyped; @@ -562,7 +562,7 @@ class AnonymousMethodExpression extends InternalExpression { // TODO(johnniwinther): Change the representation to be direct and perform // the [Let] encoding in the replacement. class DeferredCheck extends InternalExpression { - VariableDeclaration variable; + Variable variable; Expression expression; DeferredCheck(this.variable, this.expression, {required int fileOffset}) { @@ -750,7 +750,7 @@ class TypeAliasedFactoryInvocation extends InternalExpression { class FunctionDeclarationImpl extends FunctionDeclaration { bool hasImplicitReturnType = false; - FunctionDeclarationImpl(VariableDeclaration variable, FunctionNode function) + FunctionDeclarationImpl(Variable variable, FunctionNode function) : super(variable, function); static void setHasImplicitReturnType( @@ -968,12 +968,12 @@ class ReturnStatementImpl extends ReturnStatement { } } -/// Front end specific implementation of [VariableDeclaration]. +/// Front end specific implementation of [Variable]. class VariableDeclarationImpl extends LegacyVariable with InternalVariableMixin implements InternalVariable { @override - VariableDeclaration get astVariable => this; + Variable get astVariable => this; @override final bool forSyntheticToken; @@ -1136,10 +1136,10 @@ class InternalLocalVariable extends TreeNode int fileEqualsOffset = TreeNode.noOffset; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration variable) { + void set variable(Variable variable) { throw new UnsupportedError("${this.runtimeType}.variable="); } @@ -1176,13 +1176,13 @@ class InternalPositionalParameter extends TreeNode } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [Variable] interface. Remove this. List? get capturedContexts { throw new UnsupportedError("${this.runtimeType}.capturedContexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [Variable] interface. Remove this. void set capturedContexts(List? value) { throw new UnsupportedError("${this.runtimeType}.capturedContexts="); } @@ -1248,10 +1248,10 @@ class InternalPositionalParameter extends TreeNode @override // Coverage-ignore(suite): Not run. - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration value) { + void set variable(Variable value) { throw new UnsupportedError("${this.runtimeType}"); } } @@ -1282,13 +1282,13 @@ class InternalNamedParameter extends TreeNode } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [Variable] interface. Remove this. List? get capturedContexts { throw new UnsupportedError("${this.runtimeType}.capturedContexts"); } @override - // TODO(62620): Conforming to [VariableDeclaration] interface. Remove this. + // TODO(62620): Conforming to [Variable] interface. Remove this. void set capturedContexts(List? value) { throw new UnsupportedError("${this.runtimeType}.capturedContexts="); } @@ -1373,10 +1373,10 @@ class InternalNamedParameter extends TreeNode @override // Coverage-ignore(suite): Not run. - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration value) { + void set variable(Variable value) { throw new UnsupportedError("${this.runtimeType}"); } } @@ -1852,11 +1852,11 @@ mixin DelegatingVariableMixin on InternalVariableMixin @override // Coverage-ignore(suite): Not run. - VariableDeclaration get variable => astVariable.variable; + Variable get variable => astVariable.variable; @override // Coverage-ignore(suite): Not run. - void set variable(VariableDeclaration value) { + void set variable(Variable value) { astVariable.variable = value; } @@ -1878,7 +1878,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`. - VariableDeclaration get astVariable; + Variable get astVariable; bool get forSyntheticToken; @@ -1902,14 +1902,14 @@ abstract interface class InternalVariable implements IVariable, Annotatable { /// /// This is set in `InferenceVisitor.visitVariableDeclaration` when late /// lowering is enabled. - abstract VariableDeclaration? lateGetter; + abstract Variable? lateGetter; /// The synthesized local setter function for an assignable lowered late /// variable. /// /// This is set in `InferenceVisitor.visitVariableDeclaration` when late /// lowering is enabled. - abstract VariableDeclaration? lateSetter; + abstract Variable? lateSetter; /// Is `true` if this a lowered late final variable without an initializer. /// @@ -1947,10 +1947,10 @@ mixin InternalVariableMixin on TreeNode implements InternalVariable { bool isStaticLate = false; @override - VariableDeclaration? lateGetter; + Variable? lateGetter; @override - VariableDeclaration? lateSetter; + Variable? lateSetter; @override bool isLateFinalWithoutInitializer = false; @@ -1962,7 +1962,7 @@ mixin InternalVariableMixin on TreeNode implements InternalVariable { String? lateName; @override - VariableDeclaration get asVariableDeclaration => this as VariableDeclaration; + Variable get asVariableDeclaration => this as Variable; } /// Front end specific implementation of [LoadLibrary]. @@ -5678,13 +5678,13 @@ sealed class _BaseForInElement extends InternalForInElement { /// inferring the for-in iterable. DartType _computeElementTypeContext(InferenceVisitorBase visitor); - /// Computes the [VariableDeclaration] that will be used in the emitted + /// Computes the [Variable] that will be used in the emitted /// [ForInStatement]. /// /// This can be the variable declared as the for-in element or a synthetic /// variable, when there is no declared variable or it doesn't suffice for /// the correct runtime behavior. - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -5695,12 +5695,12 @@ sealed class _BaseForInElement extends InternalForInElement { /// assignment to the for-in element. ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }); /// Helper for creating a synthetic variable declaration for the emitted /// [ForInStatement]. - VariableDeclaration _createSyntheticVariableDeclaration( + Variable _createSyntheticVariableDeclaration( DartType type, { required int forOffset, required bool isClosureContextLoweringEnabled, @@ -5732,7 +5732,7 @@ sealed class _BaseForInElement extends InternalForInElement { isAsync: isAsync, ); DartType inferredType = iterableResult.inferredType; - VariableDeclaration variable = _computeLoopVariable( + Variable variable = _computeLoopVariable( visitor, inferredType, forOffset: forOffset, @@ -5756,21 +5756,21 @@ sealed class _VariableForInElement extends _BaseForInElement { _VariableForInElement({required this.error}); - VariableDeclaration get _variableDeclaration; + Variable get _variableDeclaration; /// If the assignment to [variableDeclaration] needs additional steps, like /// a type coercion, this holds a synthetic variable declaration used as an /// intermediate step. - VariableDeclaration? _variableForSideEffect; + Variable? _variableForSideEffect; @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, required bool isClosureContextLoweringEnabled, }) { - VariableDeclaration loopVariable; + Variable loopVariable; DartType loopVariableType; bool checkAssignment = true; if (_variableDeclaration.variable case InternalVariable variable) { @@ -5787,7 +5787,7 @@ sealed class _VariableForInElement extends _BaseForInElement { loopVariableType = _variableDeclaration.type; } if (checkAssignment) { - VariableDeclaration tempVariable = _createSyntheticVariableDeclaration( + Variable tempVariable = _createSyntheticVariableDeclaration( type, forOffset: forOffset, isClosureContextLoweringEnabled: isClosureContextLoweringEnabled, @@ -5827,7 +5827,7 @@ sealed class _VariableForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { return new ForInEncoding( preLoopError: error, @@ -5849,8 +5849,7 @@ class VariableInitializationForInElement extends _VariableForInElement { }); @override - VariableDeclaration get _variableDeclaration => - variableInitialization.variable; + Variable get _variableDeclaration => variableInitialization.variable; @override // Coverage-ignore(suite): Not run. @@ -5887,7 +5886,7 @@ class SingleVariableDeclarationForInElement extends _VariableForInElement { }); @override - VariableDeclaration get _variableDeclaration => variableStatement.variable; + Variable get _variableDeclaration => variableStatement.variable; @override // Coverage-ignore(suite): Not run. @@ -5959,7 +5958,7 @@ class MultiVariableDeclarationForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { return new ForInEncoding( preLoopError: error, @@ -5970,7 +5969,7 @@ class MultiVariableDeclarationForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6008,7 +6007,7 @@ class UnassignableForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { return new ForInEncoding( preLoopError: error, @@ -6021,7 +6020,7 @@ class UnassignableForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6101,7 +6100,7 @@ class InvalidForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { return new ForInEncoding( bodyPrologue: extern.createBlock([ @@ -6111,7 +6110,7 @@ class InvalidForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6129,7 +6128,7 @@ class InvalidForInElement extends _BaseForInElement { /// an already defined local variable. class ExistingVariableForInElement extends _BaseForInElement { /// The variable used as the for-in element. - final VariableDeclaration variable; + final Variable variable; /// The file offset of the variable name. final int nameOffset; @@ -6165,7 +6164,7 @@ class ExistingVariableForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { ExpressionInferenceResult result = visitor.inferVariableSet( variable: variable as InternalVariable, @@ -6183,7 +6182,7 @@ class ExistingVariableForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6243,7 +6242,7 @@ class PropertyForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { ExpressionInferenceResult result = visitor.inferPropertySet( fileOffset: nameOffset, @@ -6264,7 +6263,7 @@ class PropertyForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6314,7 +6313,7 @@ class StaticForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { ExpressionInferenceResult result = visitor.inferStaticSet( member: target, @@ -6332,7 +6331,7 @@ class StaticForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6416,7 +6415,7 @@ class ExtensionForInElement extends _BaseForInElement { @override ForInEncoding _computeEncoding( InferenceVisitorBase visitor, { - required VariableDeclaration loopVariable, + required Variable loopVariable, }) { ExpressionInferenceResult result = visitor.inferExtensionSet( data: _data, @@ -6433,7 +6432,7 @@ class ExtensionForInElement extends _BaseForInElement { } @override - VariableDeclaration _computeLoopVariable( + Variable _computeLoopVariable( InferenceVisitorBase visitor, DartType type, { required int forOffset, @@ -6467,9 +6466,9 @@ class ForInEncoding { /// The result of inferring a for-in loop element and iterable. class ForInHeaderResult { - /// The [VariableDeclaration] that should be used as the variable in the + /// The [Variable] that should be used as the variable in the /// emitted [ForInStatement]. - final VariableDeclaration loopVariable; + final Variable loopVariable; /// The [Expression] that should be used as the iterable in the emitted /// [ForInStatement]. 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 f27b961e5ed..100d7553c3d 100644 --- a/pkg/front_end/lib/src/kernel/internal_ast_helper.dart +++ b/pkg/front_end/lib/src/kernel/internal_ast_helper.dart @@ -93,7 +93,7 @@ AssertStatement createAssertStatement( AssignedVariablePattern createAssignedVariablePattern( int fileOffset, - VariableDeclaration variable, + Variable variable, ) { return new AssignedVariablePattern(variable)..fileOffset = fileOffset; } @@ -163,8 +163,8 @@ CastPattern createCastPattern(int fileOffset, Pattern pattern, DartType type) { Catch createCatch( int fileOffset, DartType exceptionType, - VariableDeclaration? exceptionParameter, - VariableDeclaration? stackTraceParameter, + Variable? exceptionParameter, + Variable? stackTraceParameter, DartType stackTraceType, Statement body, ) { @@ -349,7 +349,7 @@ ForInMapEntry createForInMapEntry( // Coverage-ignore(suite): Not run. ForInStatement createForInStatement( - VariableDeclaration variable, + Variable variable, Expression expression, Statement body, { required bool isAsync, @@ -521,7 +521,7 @@ Expression createIntLiteralLarge( InvalidPattern createInvalidPattern( Expression expression, { - required List declaredVariables, + required List declaredVariables, }) { return new InvalidPattern(expression, declaredVariables: declaredVariables) ..fileOffset = expression.fileOffset; @@ -782,7 +782,7 @@ OrPattern createOrPattern( int fileOffset, Pattern left, Pattern right, { - required List orPatternJointVariables, + required List orPatternJointVariables, }) { return new OrPattern( left, @@ -809,7 +809,7 @@ PatternAssignment createPatternAssignment( PatternForElement createPatternForElement( int fileOffset, { required PatternVariableDeclaration patternVariableDeclaration, - required List intermediateVariables, + required List intermediateVariables, required List variables, required Expression? condition, required List updates, @@ -828,7 +828,7 @@ PatternForElement createPatternForElement( PatternForMapEntry createPatternForMapEntry( int fileOffset, { required PatternVariableDeclaration patternVariableDeclaration, - required List intermediateVariables, + required List intermediateVariables, required List variableInitializations, required Expression? condition, required List updates, @@ -859,7 +859,7 @@ PatternSwitchCase createPatternSwitchCase( Statement body, { required bool isDefault, required bool hasLabel, - required List jointVariables, + required List jointVariables, required List? jointVariableFirstUseOffsets, }) { return new PatternSwitchCase( @@ -1162,9 +1162,9 @@ UnaryExpression createUnary( return new UnaryExpression(unaryName, expression)..fileOffset = fileOffset; } -/// Creates [VariableDeclaration] for a variable named [name] at the given +/// Creates [Variable] for a variable named [name] at the given /// [functionNestingLevel]. -VariableDeclaration createVariableDeclaration( +Variable createVariableDeclaration( int fileOffset, String? name, { Expression? initializer, @@ -1203,7 +1203,7 @@ VariableDeclarationImpl createVariableDeclarationForValue( } InternalVariableGet createVariableGet( - VariableDeclaration variable, { + Variable variable, { required int fileOffset, }) { return new InternalVariableGet(variable as InternalVariable) @@ -1211,7 +1211,7 @@ InternalVariableGet createVariableGet( } VariableInitialization createVariableInitialization({ - required VariableDeclaration variable, + required Variable variable, required Expression? initializer, required bool hasDeclaredInitializer, required int fileOffset, @@ -1226,13 +1226,13 @@ VariableInitialization createVariableInitialization({ VariablePattern createVariablePattern( int fileOffset, DartType? type, - VariableDeclaration variable, + Variable variable, ) { return new VariablePattern(type, variable)..fileOffset = fileOffset; } InternalVariableSet createVariableSet( - VariableDeclaration variable, + Variable variable, Expression value, { required int fileOffset, }) { @@ -1240,7 +1240,7 @@ InternalVariableSet createVariableSet( ..fileOffset = fileOffset; } -VariableStatement createVariableStatement(VariableDeclaration variable) { +VariableStatement createVariableStatement(Variable variable) { return new VariableStatement(variable)..fileOffset = variable.fileOffset; } @@ -1276,9 +1276,9 @@ bool isErroneousNode(Object? node) { ExpressionStatement statement = node; node = statement.expression; } - if (node is VariableDeclaration) { + if (node is Variable) { // Coverage-ignore-block(suite): Not run. - VariableDeclaration variable = node; + Variable variable = node; node = variable.initializer; } if (node is Let) { diff --git a/pkg/front_end/lib/src/kernel/kernel_helper.dart b/pkg/front_end/lib/src/kernel/kernel_helper.dart index 11d5818f221..4b3e54176d3 100644 --- a/pkg/front_end/lib/src/kernel/kernel_helper.dart +++ b/pkg/front_end/lib/src/kernel/kernel_helper.dart @@ -143,9 +143,8 @@ class DelayedDefaultValueCloner { } else if (i < positionalSuperParameters.length) { int? superParameterIndex = positionalSuperParameters[i]; if (superParameterIndex != null) { - VariableDeclaration originalParameter = - _original.positionalParameters[i]; - VariableDeclaration synthesizedParameter = + Variable originalParameter = _original.positionalParameters[i]; + Variable synthesizedParameter = _synthesized.positionalParameters[superParameterIndex]; _cloneDefaultValueForSuperParameters( originalParameter, @@ -183,10 +182,9 @@ class DelayedDefaultValueCloner { int? originalNamedParameterIndex = originalNamedParameterIndices[superParameterName]; if (originalNamedParameterIndex != null) { - VariableDeclaration originalParameter = + Variable originalParameter = _original.namedParameters[originalNamedParameterIndex]; - VariableDeclaration synthesizedParameter = - _synthesized.namedParameters[i]; + Variable synthesizedParameter = _synthesized.namedParameters[i]; _cloneDefaultValueForSuperParameters( originalParameter, synthesizedParameter, @@ -201,8 +199,7 @@ class DelayedDefaultValueCloner { } } else { for (int i = 0; i < _synthesized.positionalParameters.length; i++) { - VariableDeclaration synthesizedParameter = - _synthesized.positionalParameters[i]; + Variable synthesizedParameter = _synthesized.positionalParameters[i]; if (i < _original.positionalParameters.length) { if (i >= _synthesized.requiredParameterCount) { if (i < _original.requiredParameterCount) { @@ -234,15 +231,14 @@ class DelayedDefaultValueCloner { } } if (_synthesized.namedParameters.isNotEmpty) { - Map originalParameters = {}; + Map originalParameters = {}; for (int i = 0; i < _original.namedParameters.length; i++) { originalParameters[_original.namedParameters[i].name!] = _original.namedParameters[i]; } for (int i = 0; i < _synthesized.namedParameters.length; i++) { - VariableDeclaration synthesizedParameter = - _synthesized.namedParameters[i]; - VariableDeclaration? originalParameter = + Variable synthesizedParameter = _synthesized.namedParameters[i]; + Variable? originalParameter = originalParameters[synthesizedParameter.name!]; if (originalParameter != null) { if (!originalParameter.isRequired && @@ -266,10 +262,7 @@ class DelayedDefaultValueCloner { _hasCloned = true; } - void _cloneInitializer( - VariableDeclaration originalParameter, - VariableDeclaration clonedParameter, - ) { + void _cloneInitializer(Variable originalParameter, Variable clonedParameter) { if (originalParameter.initializer != null) { CloneVisitorNotMembers cloner = _cloner ??= new CloneVisitorNotMembers(); clonedParameter.initializer = cloner.clone(originalParameter.initializer!) @@ -280,8 +273,8 @@ class DelayedDefaultValueCloner { } void _cloneDefaultValueForSuperParameters( - VariableDeclaration originalParameter, - VariableDeclaration synthesizedParameter, + Variable originalParameter, + Variable synthesizedParameter, TypeEnvironment typeEnvironment, { required bool isOptional, }) { @@ -339,10 +332,9 @@ class TypeDependency { void copyInferred() { if (_hasBeenInferred) return; for (int i = 0; i < original.function!.positionalParameters.length; i++) { - VariableDeclaration synthesizedParameter = + Variable synthesizedParameter = synthesized.function!.positionalParameters[i]; - VariableDeclaration originalParameter = - original.function!.positionalParameters[i]; + Variable originalParameter = original.function!.positionalParameters[i]; synthesizedParameter.type = substitution.substituteType( originalParameter.type, ); @@ -352,10 +344,8 @@ class TypeDependency { } } for (int i = 0; i < original.function!.namedParameters.length; i++) { - VariableDeclaration synthesizedParameter = - synthesized.function!.namedParameters[i]; - VariableDeclaration originalParameter = - original.function!.namedParameters[i]; + Variable synthesizedParameter = synthesized.function!.namedParameters[i]; + Variable originalParameter = original.function!.namedParameters[i]; synthesizedParameter.type = substitution.substituteType( originalParameter.type, ); diff --git a/pkg/front_end/lib/src/kernel/kernel_target.dart b/pkg/front_end/lib/src/kernel/kernel_target.dart index dad1c2e7e71..7435c313e01 100644 --- a/pkg/front_end/lib/src/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/kernel/kernel_target.dart @@ -1081,11 +1081,8 @@ class KernelTarget { bool isClosureContextLoweringEnabled = libraryBuilder.loader.isClosureContextLoweringEnabled; - VariableDeclaration copyFormal( - VariableDeclaration formal, { - required bool isPositional, - }) { - VariableDeclaration copy; + Variable copyFormal(Variable formal, {required bool isPositional}) { + Variable copy; if (isClosureContextLoweringEnabled) { // Coverage-ignore-block(suite): Not run. if (isPositional) { @@ -1106,7 +1103,7 @@ class KernelTarget { ); } } else { - copy = new VariableDeclaration( + copy = new Variable( formal.name, isFinal: formal.isFinal, isConst: formal.isConst, @@ -1133,19 +1130,17 @@ class KernelTarget { } } } - List positionalParameters = []; - List namedParameters = []; + List positionalParameters = []; + List namedParameters = []; List positional = []; List named = []; - for (VariableDeclaration formal - in superConstructor.function.positionalParameters) { + for (Variable formal in superConstructor.function.positionalParameters) { positionalParameters.add(copyFormal(formal, isPositional: true)); positional.add(new VariableGet(positionalParameters.last)); } - for (VariableDeclaration formal - in superConstructor.function.namedParameters) { - VariableDeclaration clone = copyFormal(formal, isPositional: false); + for (Variable formal in superConstructor.function.namedParameters) { + Variable clone = copyFormal(formal, isPositional: false); namedParameters.add(clone); named.add( new NamedExpression( 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 bbaedda26e1..9fc126f0cc4 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 VariableDeclaration; +import 'package:kernel/ast.dart' show Variable; import '../base/lookup_result.dart'; import '../builder/builder.dart'; @@ -18,7 +18,7 @@ class VariableBuilderImpl extends NamedBuilderImpl final Uri fileUri; @override - final VariableDeclaration variable; + final Variable variable; VariableBuilderImpl(this.name, this.variable, this.fileUri); diff --git a/pkg/front_end/lib/src/kernel/late_lowering.dart b/pkg/front_end/lib/src/kernel/late_lowering.dart index 8346c854b74..05de4a95547 100644 --- a/pkg/front_end/lib/src/kernel/late_lowering.dart +++ b/pkg/front_end/lib/src/kernel/late_lowering.dart @@ -65,7 +65,7 @@ Statement createGetterWithInitializer( // Generate: // // return let # = _#field in isSentinel(#) ? _#field = : #; - VariableDeclaration variable = new VariableDeclaration.forValue( + Variable variable = new Variable.forValue( createVariableRead(needsPromotion: false)..fileOffset = fileOffset, type: type.withDeclaredNullability(Nullability.nullable), )..fileOffset = fileOffset; @@ -89,7 +89,7 @@ Statement createGetterWithInitializer( // Generate: // // return let # = _#field in # == null ? _#field = : #; - VariableDeclaration variable = new VariableDeclaration.forValue( + Variable variable = new Variable.forValue( createVariableRead(needsPromotion: false)..fileOffset = fileOffset, type: type.withDeclaredNullability(Nullability.nullable), )..fileOffset = fileOffset; @@ -138,10 +138,8 @@ Statement createGetterWithInitializerWithRecheck( ) ..fileOffset = fileOffset ..forErrorHandling = true; - VariableDeclaration temp = new VariableDeclaration.forValue( - initializer, - type: type, - )..fileOffset = fileOffset; + Variable temp = new Variable.forValue(initializer, type: type) + ..fileOffset = fileOffset; switch (isSetEncoding) { case IsSetEncoding.useIsSetField: // Generate: @@ -190,7 +188,7 @@ Statement createGetterWithInitializerWithRecheck( // ? let #2 = in isSentinel(_#field) // ? _#field = #2 : throw '...' // : #1; - VariableDeclaration variable = new VariableDeclaration.forValue( + Variable variable = new Variable.forValue( createVariableRead(needsPromotion: false)..fileOffset = fileOffset, type: type, )..fileOffset = fileOffset; @@ -233,7 +231,7 @@ Statement createGetterWithInitializerWithRecheck( // ? let #2 = in _#field == null // ? _#field = #2 : throw '...' // : #1; - VariableDeclaration variable = new VariableDeclaration.forValue( + Variable variable = new Variable.forValue( createVariableRead(needsPromotion: false)..fileOffset = fileOffset, type: type.withDeclaredNullability(Nullability.nullable), )..fileOffset = fileOffset; @@ -308,7 +306,7 @@ Statement createGetterBodyWithoutInitializer( // Generate: // // return let # = _#field in isSentinel(#) ? throw '...' : #; - VariableDeclaration variable = new VariableDeclaration.forValue( + Variable variable = new Variable.forValue( createVariableRead()..fileOffset = fileOffset, type: type.withDeclaredNullability(Nullability.nullable), )..fileOffset = fileOffset; @@ -332,7 +330,7 @@ Statement createGetterBodyWithoutInitializer( // Generate: // // return let # = _#field in # == null ? throw '...' : #; - VariableDeclaration variable = new VariableDeclaration.forValue( + Variable variable = new Variable.forValue( createVariableRead()..fileOffset = fileOffset, type: type.withDeclaredNullability(Nullability.nullable), )..fileOffset = fileOffset; @@ -357,7 +355,7 @@ Statement createSetterBody( CoreTypes coreTypes, int fileOffset, String name, - VariableDeclaration parameter, + Variable parameter, DartType type, { required bool shouldReturnValue, required Expression createVariableWrite(Expression value), @@ -407,7 +405,7 @@ Statement createSetterBodyFinal( CoreTypes coreTypes, int fileOffset, String name, - VariableDeclaration parameter, + Variable parameter, DartType type, { required bool shouldReturnValue, required Expression createVariableRead(), diff --git a/pkg/front_end/lib/src/kernel/member_covariance.dart b/pkg/front_end/lib/src/kernel/member_covariance.dart index 126ebca5d70..f3f529a16da 100644 --- a/pkg/front_end/lib/src/kernel/member_covariance.dart +++ b/pkg/front_end/lib/src/kernel/member_covariance.dart @@ -16,7 +16,7 @@ class Covariance { static const int Covariant = 2; /// Returns the covariance mask for [parameter]. - static int covarianceFromParameter(VariableDeclaration parameter) => + static int covarianceFromParameter(Variable parameter) => (parameter.isCovariantByDeclaration ? Covariant : 0) | (parameter.isCovariantByClass ? GenericCovariantImpl : 0); @@ -26,10 +26,7 @@ class Covariance { (field.isCovariantByClass ? GenericCovariantImpl : 0); /// Applies the [covariance] mask to [parameter]. - static void covarianceToParameter( - int covariance, - VariableDeclaration parameter, - ) { + static void covarianceToParameter(int covariance, Variable parameter) { if ((covariance & Covariant) != 0) { parameter.isCovariantByDeclaration = true; } @@ -138,7 +135,7 @@ class Covariance { Map? namedParameters; if (function.namedParameters.isNotEmpty) { for (int index = 0; index < function.namedParameters.length; index++) { - VariableDeclaration parameter = function.namedParameters[index]; + Variable parameter = function.namedParameters[index]; int covariance = covarianceFromParameter(parameter); if (covariance != 0) { namedParameters ??= {}; @@ -309,7 +306,7 @@ class Covariance { } } if (_namedParameters != null) { - for (VariableDeclaration parameter in function.namedParameters) { + for (Variable parameter in function.namedParameters) { covarianceToParameter(getNamedVariance(parameter.name!), parameter); } } diff --git a/pkg/front_end/lib/src/kernel/resolver.dart b/pkg/front_end/lib/src/kernel/resolver.dart index 03986c315a5..6e2a046f5a8 100644 --- a/pkg/front_end/lib/src/kernel/resolver.dart +++ b/pkg/front_end/lib/src/kernel/resolver.dart @@ -520,7 +520,7 @@ class Resolver { constantContext: constantContext, initializers: initializers, forPrimaryConstructor: forPrimaryConstructor, - parameters: [ + parameters: [ for (FormalParameterBuilder formal in bodyBuilderContext.formals ?? []) formal.variable, @@ -873,9 +873,9 @@ class Resolver { required LookupScope scope, required Token token, required Procedure procedure, - required List extraKnownVariables, + required List extraKnownVariables, required ExpressionEvaluationHelper expressionEvaluationHelper, - required VariableDeclaration? extensionThis, + required Variable? extensionThis, }) { _ResolverContext context = new _ResolverContext( typeInferenceEngine: _typeInferenceEngine, @@ -921,7 +921,7 @@ class Resolver { : new List.generate( parameters.positionalParameters.length, (int i) { - VariableDeclaration formal = parameters.positionalParameters[i]; + Variable formal = parameters.positionalParameters[i]; String formalName = formal.name!; bool isWildcard = libraryFeatures.wildcardVariables.isEnabled && @@ -958,7 +958,7 @@ class Resolver { Expression expression = result.expression; if (formals != null) { for (int i = 0; i < formals.length; i++) { - VariableDeclaration variable = formals[i].variable; + Variable variable = formals[i].variable; context.typeInferrer.flowAnalysis.declare( variable, new SharedTypeView(variable.type), @@ -966,7 +966,7 @@ class Resolver { ); } } - for (VariableDeclaration extraVariable in extraKnownVariables) { + for (Variable extraVariable in extraKnownVariables) { context.typeInferrer.flowAnalysis.declare( extraVariable, new SharedTypeView(extraVariable.type), @@ -979,10 +979,10 @@ class Resolver { // TODO(cstefantsova): Remove special-casing over // ExpressionCompilerProcedureBodyBuildContext below by computing formals in // it. - List formalParameters = + List formalParameters = bodyBuilderContext is ExpressionCompilerProcedureBodyBuildContext ? [] - : [ + : [ for (FormalParameterBuilder formal in bodyBuilderContext.formals ?? []) formal.variable, @@ -1126,7 +1126,7 @@ class Resolver { required BodyBuilderContext bodyBuilderContext, required LookupScope scope, required ConstantContext constantContext, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, required List? thisTypeParameters, required LocalScope? formalParameterScope, required ThisVariable? internalThisVariable, @@ -1155,7 +1155,7 @@ class Resolver { required BodyBuilderContext bodyBuilderContext, required LookupScope scope, required LocalScope? formalParameterScope, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, required List? thisTypeParameters, required ConstantContext constantContext, required ThisVariable? internalThisVariable, @@ -1240,7 +1240,7 @@ class Resolver { assignedVariables.read(variable.astVariable); } return intern.createVariableGet( - variable as VariableDeclaration, + variable as Variable, fileOffset: fileOffset, ); } @@ -1248,7 +1248,7 @@ class Resolver { void _declareFormals({ required TypeInferrer typeInferrer, required BodyBuilderContext bodyBuilderContext, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, required List? formals, }) { if (thisVariable != null && bodyBuilderContext.isConstructor) { @@ -1263,7 +1263,7 @@ class Resolver { if (formals != null) { for (int i = 0; i < formals.length; i++) { FormalParameterBuilder parameter = formals[i]; - VariableDeclaration variable = parameter.variable; + Variable variable = parameter.variable; // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. typeInferrer.flowAnalysis.declare( @@ -1289,7 +1289,7 @@ class Resolver { required ConstantContext constantContext, required List initializers, required bool forPrimaryConstructor, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ContextAllocationStrategy contextAllocationStrategy, }) { @@ -1353,7 +1353,7 @@ class Resolver { required Statement? body, required Uri fileUri, required BodyBuilderContext bodyBuilderContext, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, required List initializers, required ConstantContext constantContext, required ThisVariable? internalThisVariable, @@ -1401,7 +1401,7 @@ class Resolver { // https://github.com/dart-lang/sdk/issues/32289 noLocation, ); - VariableDeclaration originParameter = parameter.variable; + Variable originParameter = parameter.variable; initializer = context.typeInferrer.inferParameterInitializer( fileUri: fileUri, initializer: initializer, @@ -1414,8 +1414,9 @@ class Resolver { } parameter.initializerWasInferred = true; } - VariableDeclaration? tearOffParameter = bodyBuilderContext - .getTearOffParameter(declaredParameterIndex); + Variable? tearOffParameter = bodyBuilderContext.getTearOffParameter( + declaredParameterIndex, + ); if (tearOffParameter != null) { Expression tearOffInitializer = _simpleCloner.cloneInContext( initializer!, @@ -1430,7 +1431,7 @@ class Resolver { } } - late List? parameters = [ + late List? parameters = [ for (FormalParameterBuilder formal in bodyBuilderContext.formals ?? []) formal.variable, ]; diff --git a/pkg/front_end/lib/src/kernel/resolver_helpers.dart b/pkg/front_end/lib/src/kernel/resolver_helpers.dart index a8238d28e62..7b55738914f 100644 --- a/pkg/front_end/lib/src/kernel/resolver_helpers.dart +++ b/pkg/front_end/lib/src/kernel/resolver_helpers.dart @@ -13,7 +13,7 @@ typedef BodyBuilderCreator = LocalScope? formalParameterScope, required ClassHierarchy hierarchy, required CoreTypes coreTypes, - VariableDeclaration? thisVariable, + Variable? thisVariable, List? thisTypeParameters, required Uri uri, required AssignedVariablesImpl assignedVariables, @@ -39,7 +39,7 @@ class ResolverForTesting extends Resolver { required BodyBuilderContext bodyBuilderContext, required LookupScope scope, required LocalScope? formalParameterScope, - required VariableDeclaration? thisVariable, + required Variable? thisVariable, required List? thisTypeParameters, required ConstantContext constantContext, required ThisVariable? internalThisVariable, @@ -217,7 +217,7 @@ class _InitializerBuilder { ScopeProviderInfo? _inferInitializer( Initializer initializer, { - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -245,7 +245,7 @@ class _InitializerBuilder { required List initializers, required AsyncModifier asyncModifier, required bool forPrimaryConstructor, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ContextAllocationStrategy contextAllocationStrategy, }) { @@ -629,7 +629,7 @@ class _InitializerBuilder { required SourceLibraryBuilder libraryBuilder, required TypeInferrer typeInferrer, required _SuperParameterArguments? superParameterArguments, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -754,7 +754,7 @@ class _InitializerBuilder { int positionalSuperParameterCount = superTarget.function.positionalParameters.length; Set superTargetNamedParameterNames = { - for (VariableDeclaration namedParameter + for (Variable namedParameter in superTarget.function.namedParameters) ?namedParameter // Coverage-ignore(suite): Not run. .name, diff --git a/pkg/front_end/lib/src/source/check_helper.dart b/pkg/front_end/lib/src/source/check_helper.dart index e8fdc287ae2..d2d99105481 100644 --- a/pkg/front_end/lib/src/source/check_helper.dart +++ b/pkg/front_end/lib/src/source/check_helper.dart @@ -183,7 +183,7 @@ extension CheckHelper on ProblemReporting { } if (function.namedParameters.isNotEmpty) { for (int i = 0; i < function.namedParameters.length; i++) { - VariableDeclaration parameter = function.namedParameters[i]; + Variable parameter = function.namedParameters[i]; if (parameter.isRequired && !argumentNames.contains(parameter.name!)) { return diag.valueForRequiredParameterNotProvidedError .withArguments(parameterName: parameter.name!) diff --git a/pkg/front_end/lib/src/source/source_class_builder.dart b/pkg/front_end/lib/src/source/source_class_builder.dart index d5410abf49e..60a12138097 100644 --- a/pkg/front_end/lib/src/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/source/source_class_builder.dart @@ -1336,10 +1336,9 @@ class SourceClassBuilder extends ClassBuilderImpl ) { List functionTypeParameters = procedure.function.typeParameters; - List positionalParameters = + List positionalParameters = procedure.function.positionalParameters; - List namedParameters = - procedure.function.namedParameters; + List namedParameters = procedure.function.namedParameters; DartType returnType = procedure.function.returnType; for (TypeParameter functionParameter in functionTypeParameters) { @@ -1355,7 +1354,7 @@ class SourceClassBuilder extends ClassBuilderImpl ); } } - for (VariableDeclaration formal in positionalParameters) { + for (Variable formal in positionalParameters) { if (!formal.isCovariantByDeclaration) { for (TypeParameter typeParameter in typeParameters) { Variance formalVariance = Variance.contravariant.combine( @@ -1370,7 +1369,7 @@ class SourceClassBuilder extends ClassBuilderImpl } } } - for (VariableDeclaration named in namedParameters) { + for (Variable named in namedParameters) { for (TypeParameter typeParameter in typeParameters) { Variance namedVariance = Variance.contravariant.combine( computeVariance(typeParameter, named.type), @@ -1874,7 +1873,7 @@ class SourceClassBuilder extends ClassBuilderImpl DartType declaredType, DartType interfaceType, bool isCovariantByDeclaration, - VariableDeclaration? declaredParameter, + Variable? declaredParameter, bool isInterfaceCheck, { bool asIfDeclaredParameter = false, required Member? localMember, @@ -2075,10 +2074,8 @@ class SourceClassBuilder extends ClassBuilderImpl i < interfaceFunction.positionalParameters.length; i++ ) { - VariableDeclaration declaredParameter = - declaredFunction.positionalParameters[i]; - VariableDeclaration interfaceParameter = - interfaceFunction.positionalParameters[i]; + Variable declaredParameter = declaredFunction.positionalParameters[i]; + Variable interfaceParameter = interfaceFunction.positionalParameters[i]; DartType declaredParameterType = declaredParameter.type; if (declaredSignatureType != null) { declaredParameterType = declaredSignatureType.positionalParameters[i]; @@ -2137,20 +2134,18 @@ class SourceClassBuilder extends ClassBuilderImpl ); } - int compareNamedParameters(VariableDeclaration p0, VariableDeclaration p1) { + int compareNamedParameters(Variable p0, Variable p1) { return p0.name!.compareTo(p1.name!); } - List sortedFromDeclared = new List.of( + List sortedFromDeclared = new List.of( declaredFunction.namedParameters, )..sort(compareNamedParameters); - List sortedFromInterface = new List.of( + List sortedFromInterface = new List.of( interfaceFunction.namedParameters, )..sort(compareNamedParameters); - Iterator declaredNamedParameters = - sortedFromDeclared.iterator; - Iterator interfaceNamedParameters = - sortedFromInterface.iterator; + Iterator declaredNamedParameters = sortedFromDeclared.iterator; + Iterator interfaceNamedParameters = sortedFromInterface.iterator; outer: while (declaredNamedParameters.moveNext() && interfaceNamedParameters.moveNext()) { @@ -2185,7 +2180,7 @@ class SourceClassBuilder extends ClassBuilderImpl break outer; } } - VariableDeclaration declaredParameter = declaredNamedParameters.current; + Variable declaredParameter = declaredNamedParameters.current; _checkTypes( types, interfaceSubstitution, @@ -2318,9 +2313,7 @@ class SourceClassBuilder extends ClassBuilderImpl ); DartType declaredType = declaredMember.setterType; DartType interfaceType = interfaceMember.setterType; - VariableDeclaration? declaredParameter = declaredMember - .function - ?.positionalParameters + Variable? declaredParameter = declaredMember.function?.positionalParameters .elementAt(0); bool isCovariantByDeclaration = declaredParameter?.isCovariantByDeclaration ?? false; 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 17da84b2dd0..42a7161a94e 100644 --- a/pkg/front_end/lib/src/source/source_function_builder.dart +++ b/pkg/front_end/lib/src/source/source_function_builder.dart @@ -16,7 +16,7 @@ import 'source_library_builder.dart'; import 'source_type_parameter_builder.dart'; /// Builds the [TypeParameter]s for [declaredTypeParameters] and the parameter -/// [VariableDeclaration]s for [declaredFormals] and adds them to [function]. +/// [Variable]s for [declaredFormals] and adds them to [function]. /// /// If [classTypeParameters] the bounds on type parameters and formal parameter /// types will be marked as `isCovariantByClass` depending on their use of the @@ -60,7 +60,7 @@ void buildTypeParametersAndFormals( if (declaredFormals != null) { for (int i = 0; i < declaredFormals.length; i++) { FormalParameterBuilder formal = declaredFormals[i]; - VariableDeclaration parameter = + Variable parameter = (formal.build(libraryBuilder) as InternalVariable).astVariable; if (needsCheckVisitor != null) { if (parameter.type.accept(needsCheckVisitor)) { diff --git a/pkg/front_end/lib/src/source/source_library_builder.dart b/pkg/front_end/lib/src/source/source_library_builder.dart index 7ba74b832c1..b06cfc26f9d 100644 --- a/pkg/front_end/lib/src/source/source_library_builder.dart +++ b/pkg/front_end/lib/src/source/source_library_builder.dart @@ -1220,10 +1220,9 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { ); } for (int j = 0; j < positionalCount; ++j) { - VariableDeclaration forwarderParameter = + Variable forwarderParameter = forwarder.function.positionalParameters[j]; - VariableDeclaration originParameter = - origin.function.positionalParameters[j]; + Variable originParameter = origin.function.positionalParameters[j]; if (originParameter.initializer != null) { forwarderParameter.initializer = cloner.clone( originParameter.initializer!, @@ -1232,14 +1231,12 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { } } - Map originNamedMap = - {}; - for (VariableDeclaration originNamed in origin.function.namedParameters) { + Map originNamedMap = {}; + for (Variable originNamed in origin.function.namedParameters) { originNamedMap[originNamed.name!] = originNamed; } - for (VariableDeclaration forwarderNamed - in forwarder.function.namedParameters) { - VariableDeclaration? originNamed = originNamedMap[forwarderNamed.name]; + for (Variable forwarderNamed in forwarder.function.namedParameters) { + Variable? originNamed = originNamedMap[forwarderNamed.name]; if (originNamed == null) { return unhandled( "null", diff --git a/pkg/front_end/lib/src/source/source_loader.dart b/pkg/front_end/lib/src/source/source_loader.dart index 7ca062720ec..1f473cb3c2f 100644 --- a/pkg/front_end/lib/src/source/source_loader.dart +++ b/pkg/front_end/lib/src/source/source_loader.dart @@ -1491,7 +1491,7 @@ severity: $severity String? enclosingClassOrExtension, bool isClassInstanceMember, Procedure procedure, - VariableDeclaration? extensionThis, + Variable? extensionThis, List extraKnownVariables, ExpressionEvaluationHelper expressionEvaluationHelper, ) async { diff --git a/pkg/front_end/lib/src/source/value_kinds.dart b/pkg/front_end/lib/src/source/value_kinds.dart index f88d4e96ae8..0b57e448e7e 100644 --- a/pkg/front_end/lib/src/source/value_kinds.dart +++ b/pkg/front_end/lib/src/source/value_kinds.dart @@ -242,7 +242,7 @@ class ValueKinds { NullValues.NominalParameters, ); static const ValueKind VariableDeclarationListOrNull = - const SingleValueKind>( + const SingleValueKind>( NullValues.VariableDeclarationList, ); } diff --git a/pkg/front_end/lib/src/testing/id_extractor.dart b/pkg/front_end/lib/src/testing/id_extractor.dart index 44e8719f482..4971e85191b 100644 --- a/pkg/front_end/lib/src/testing/id_extractor.dart +++ b/pkg/front_end/lib/src/testing/id_extractor.dart @@ -334,7 +334,7 @@ abstract class DataExtractor extends VisitorDefault } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { if (node.name != null && node.parent is! FunctionDeclaration) { // Skip synthetic variables and function declaration variables. computeForNode( 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 d47851f867c..d52f7674f64 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 @@ -37,7 +37,7 @@ class ScopeProviderInfo { final ScopeProviderInfoKind kind; Scope? scope; - VariableDeclaration? thisVariable; + Variable? thisVariable; ScopeProviderInfo({required this.kind}); } @@ -151,7 +151,7 @@ abstract class ContextAllocationStrategy { } void handleDeclarationOfVariable( - VariableDeclaration variable, { + Variable variable, { required CaptureKind captureKind, }); @@ -187,7 +187,7 @@ class TrivialContextAllocationStrategy extends ContextAllocationStrategy { @override void handleDeclarationOfVariable( - VariableDeclaration variable, { + Variable variable, { required CaptureKind captureKind, }) { assert(_currentScopeProviderInfo != null); @@ -265,7 +265,7 @@ class LoopDepthAllocationStrategy @override void handleDeclarationOfVariable( - VariableDeclaration variable, { + Variable 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 136dbd984b5..2b0a2cbadac 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 VariableDeclaration _target; + final Variable _target; final DartType _type; final DelayedExpression _value; final bool hasEffect; @@ -634,7 +634,7 @@ class DelayedAssignment extends DelayedExpression { }) { if (effects != null && hasEffect) { // Coverage-ignore-block(suite): Not run. - VariableDeclaration tempVariable = _cache.createTemporaryVariable( + Variable tempVariable = _cache.createTemporaryVariable( _type, fileOffset: fileOffset, ); @@ -682,7 +682,7 @@ class DelayedAssignment extends DelayedExpression { List? effects, }) { if (effects != null && hasEffect) { - VariableDeclaration tempVariable = _cache.createTemporaryVariable( + Variable tempVariable = _cache.createTemporaryVariable( _type, fileOffset: fileOffset, ); diff --git a/pkg/front_end/lib/src/type_inference/inference_results.dart b/pkg/front_end/lib/src/type_inference/inference_results.dart index 0bac823ef44..f159aa15ac2 100644 --- a/pkg/front_end/lib/src/type_inference/inference_results.dart +++ b/pkg/front_end/lib/src/type_inference/inference_results.dart @@ -139,7 +139,7 @@ abstract class InvocationInferenceResult { static Expression _insertHoistedExpressions( Expression expression, - List hoistedExpressions, + List hoistedExpressions, ) { if (hoistedExpressions.isNotEmpty) { for (int index = hoistedExpressions.length - 1; index >= 0; index--) { @@ -164,7 +164,7 @@ class SuccessfulInferenceResult implements InvocationInferenceResult { @override final List typeArguments; - final List? hoistedArguments; + final List? hoistedArguments; @override final List positional; @@ -189,7 +189,7 @@ class SuccessfulInferenceResult implements InvocationInferenceResult { Expression expression, { DartType? extensionReceiverType, }) { - List? hoistedArguments = this.hoistedArguments; + List? hoistedArguments = this.hoistedArguments; if (hoistedArguments == null || hoistedArguments.isEmpty) { return expression; } else if (expression is RedirectingFactoryInvocation) { @@ -221,7 +221,7 @@ class SuccessfulInferenceResult implements InvocationInferenceResult { return expression; } else if (expression is InstanceInvocation) { if (!isPureExpression(expression.receiver)) { - VariableDeclaration receiver = createVariable( + Variable receiver = createVariable( expression.receiver, inferredReceiverType ?? const DynamicType(), ); @@ -249,7 +249,7 @@ class SuccessfulInferenceResult implements InvocationInferenceResult { if (extensionReceiverType != null) { Expression receiver = expression.arguments.positional.first; if (!isPureExpression(receiver)) { - VariableDeclaration receiverVariable = createVariable( + Variable receiverVariable = createVariable( receiver, extensionReceiverType, ); @@ -308,7 +308,7 @@ class WrapInProblemInferenceResult implements InvocationInferenceResult { @override final bool isInapplicable; - final List? hoistedArguments; + final List? hoistedArguments; @override final List positional; @@ -345,7 +345,7 @@ class WrapInProblemInferenceResult implements InvocationInferenceResult { expression: expression, message: message, ); - List? hoistedArguments = this.hoistedArguments; + List? hoistedArguments = this.hoistedArguments; if (hoistedArguments == null || hoistedArguments.isEmpty) { return expression; } else { @@ -398,7 +398,7 @@ class SuccessfulInitializerInvocationInferenceResult @override final Initializer initializer; - final List? hoistedArguments; + final List? hoistedArguments; SuccessfulInitializerInvocationInferenceResult({ required this.initializer, @@ -415,9 +415,9 @@ class SuccessfulInitializerInvocationInferenceResult @override void addHoistedArguments(List initializers) { - List? hoistedArguments = this.hoistedArguments; + List? hoistedArguments = this.hoistedArguments; if (hoistedArguments != null && hoistedArguments.isNotEmpty) { - for (VariableDeclaration hoistedArgument in hoistedArguments) { + for (Variable hoistedArgument in hoistedArguments) { initializers.add( new LocalInitializer(hoistedArgument) ..fileOffset = hoistedArgument.fileOffset, @@ -496,7 +496,7 @@ class ExpressionInferenceResult { /// A guard used for creating null-shorting null-aware actions. class NullAwareGuard { /// The variable used to guard the null-aware action. - final VariableDeclaration _nullAwareVariable; + final Variable _nullAwareVariable; /// The file offset used for the null-test. int _nullAwareFileOffset; 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 f0517f1c38d..24fca469f96 100644 --- a/pkg/front_end/lib/src/type_inference/inference_visitor.dart +++ b/pkg/front_end/lib/src/type_inference/inference_visitor.dart @@ -110,13 +110,13 @@ class InferenceVisitorImpl extends InferenceVisitorBase TreeNode, Statement, Expression, - VariableDeclaration, + Variable, Pattern, InvalidExpression, TypeDeclarationType, TypeDeclaration >, - NullShortingMixin, + NullShortingMixin, StackChecker, ExpressionVisitor1ExperimentExclusionMixin< ExpressionInferenceResult, @@ -310,10 +310,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // Null-aware access is not needed on `this`. return receiver; } - VariableDeclaration? receiverVariable = createVariable( - receiver, - receiverType, - ); + Variable? receiverVariable = createVariable(receiver, receiverType); createNullAwareGuard(receiverVariable); Expression variableGet = createVariableGet( receiverVariable, @@ -327,7 +324,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase return variableGet; } - void createNullAwareGuard(VariableDeclaration variable) { + void createNullAwareGuard(Variable variable) { flowAnalysis.storeExpressionInfo( variable.initializer!, startNullShorting( @@ -1852,7 +1849,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase valueResult = ensureAssignableResult(valueType, valueResult); Expression value = valueResult.expression; - VariableDeclaration? valueVariable; + Variable? valueVariable; if (forEffect) { // No need for value variable. } else { @@ -1860,7 +1857,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase value = createVariableGet(valueVariable); } - VariableDeclaration? receiverVariable; + Variable? receiverVariable; if (forEffect || isPureExpression(receiver)) { // No need for receiver variable. } else { @@ -1882,7 +1879,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase replacement = assignment; } else { assert(valueVariable != null); - VariableDeclaration assignmentVariable = createVariable( + Variable assignmentVariable = createVariable( assignment, const VoidType(), ); @@ -1952,7 +1949,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiver = ensureAssignable(extensionOnType, receiverType, receiver); receiverType = extensionOnType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver; Expression writeReceiver; if (isPureExpression(receiver)) { @@ -1991,7 +1988,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase DartType readType = readTarget.getGetterType(this); DartType valueType = writeTarget.getSetterType(this); - VariableDeclaration? valueVariable; + Variable? valueVariable; if (!node.forEffect && node.isPost) { // For postfix expressions like `a = E(o).b++` that are not for effect we // need to store the read value as the result after assignment. @@ -2017,7 +2014,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase DartType binaryType = binaryResult.inferredType; Expression binary = binaryResult.expression; - VariableDeclaration? binaryVariable; + Variable? binaryVariable; if (!node.forEffect && !node.isPost) { // For prefix expressions like `a = ++E(o).b` we need to store the binary // result as the result after assignment. @@ -2035,19 +2032,13 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression replacement; if (valueVariable != null) { assert(binaryVariable == null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable, createLet(writeVariable, createVariableGet(valueVariable)), ); } else if (binaryVariable != null) { - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( binaryVariable, createLet(writeVariable, createVariableGet(binaryVariable)), @@ -2275,7 +2266,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression receiver = receiverResult.expression; DartType receiverType = receiverResult.inferredType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; if (node.isNullAware) { DartType nonNullReceiverType = receiverType.toNonNull(); receiverVariable = createVariable(receiver, receiverType); @@ -2402,7 +2393,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // // let v1 = o in let v2 = v1.a in v2 == null ? v1.a = b : v2 // - VariableDeclaration readVariable = createVariable(read, readType); + Variable readVariable = createVariable(read, readType); Expression equalsNull = createEqualsNull( createVariableGet(readVariable), fileOffset: node.fileOffset, @@ -2487,7 +2478,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiver = ensureAssignable(extensionOnType, receiverType, receiver); receiverType = extensionOnType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver; Expression writeReceiver; if (isPureExpression(receiver)) { @@ -2543,7 +2534,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ); Expression value = binaryResult.expression; - VariableDeclaration? valueVariable; + Variable? valueVariable; if (node.forEffect) { // No need for value variable. } else { @@ -2565,10 +2556,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase replacement = write; } else { assert(valueVariable != null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable!, createLet(writeVariable, createVariableGet(valueVariable)), @@ -2978,13 +2966,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase targetType.typeArguments, ); List positional = function.positionalParameters - .map( - (VariableDeclaration decl) => substitution.substituteType(decl.type), - ) + .map((Variable decl) => substitution.substituteType(decl.type)) .toList(growable: false); List named = function.namedParameters .map( - (VariableDeclaration decl) => new NamedType( + (Variable decl) => new NamedType( decl.name!, substitution.substituteType(decl.type), isRequired: decl.isRequired, @@ -3116,14 +3102,12 @@ class InferenceVisitorImpl extends InferenceVisitorBase targetType.typeArguments, ); List positional = function.positionalParameters - .map( - (VariableDeclaration decl) => substitution.substituteType(decl.type), - ) + .map((Variable decl) => substitution.substituteType(decl.type)) .toList(growable: false); List named = function.namedParameters .map( // Coverage-ignore(suite): Not run. - (VariableDeclaration decl) => new NamedType( + (Variable decl) => new NamedType( decl.name!, substitution.substituteType(decl.type), isRequired: decl.isRequired, @@ -3341,7 +3325,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase errorTemplate: diag.forInLoopTypeNotIterable, ); - VariableDeclaration loopVariable = extern.createUninitializedVariable( + Variable loopVariable = extern.createUninitializedVariable( elementType, fileOffset: node.fileOffset, isFinal: true, @@ -3379,7 +3363,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase forOffset: node.fileOffset, isClosureContextLoweringEnabled: isClosureContextLoweringEnabled, ); - VariableDeclaration variable = headerResult.loopVariable; + Variable variable = headerResult.loopVariable; Expression iterable = headerResult.iterable; flowAnalysis.forEach_bodyBegin(node); @@ -3443,7 +3427,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase List? variables; for (int index = 0; index < node.variables.length; index++) { VariableStatement variableStatement = node.variables[index]; - VariableDeclaration variable = variableStatement.variable; + Variable variable = variableStatement.variable; if (variable.name == null) { if (variable.initializer != null) { ExpressionInferenceResult result = inferExpression( @@ -3559,7 +3543,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase bool oldInTryOrLocalFunction = _inTryOrLocalFunction; _inTryOrLocalFunction = true; - VariableDeclaration variable = node.variable; + Variable variable = node.variable; flowAnalysis.functionExpression_begin(node); inferMetadata(this, variable); DartType? returnContext = node.hasImplicitReturnType @@ -3591,7 +3575,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase @override ScopeProviderInfo beginFunctionBodyInference( - List parameters, { + List parameters, { required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, }) { @@ -3615,11 +3599,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase _contextAllocationStrategy.exitScopeProvider(scopeProviderInfo); } - void _handleDeclarationsOfParameters(List parameters) { - for (VariableDeclaration parameter in parameters) { + void _handleDeclarationsOfParameters(List parameters) { + for (Variable parameter in parameters) { // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - VariableDeclaration parameterAstVariable = + Variable parameterAstVariable = (parameter as InternalVariable).astVariable; _contextAllocationStrategy.handleDeclarationOfVariable( parameterAstVariable, @@ -3743,7 +3727,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (isThisExpression(left)) { replacement = left; } else { - VariableDeclaration variable = createVariable(left, t1); + Variable variable = createVariable(left, t1); Expression equalsNull = createEqualsNull( createVariableGet(variable), fileOffset: lhsResult.expression.fileOffset, @@ -3815,7 +3799,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase node.then, node.otherwise, { - for (VariableDeclaration variable + for (Variable variable in node.patternGuard.pattern.declaredVariables) variable.name!: variable, }, @@ -4235,7 +4219,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase expression: element.expression, pattern: element.patternGuard.pattern, variables: { - for (VariableDeclaration variable + for (Variable variable in element.patternGuard.pattern.declaredVariables) variable.name!: variable, }, @@ -4354,15 +4338,14 @@ class InferenceVisitorImpl extends InferenceVisitorBase ..parent = patternVariableDeclaration; } - List declaredVariables = + List declaredVariables = patternVariableDeclaration.pattern.declaredVariables; assert(declaredVariables.length == element.intermediateVariables.length); assert(declaredVariables.length == element.variableInitializations.length); for (int i = 0; i < declaredVariables.length; i++) { DartType type = declaredVariables[i].type; - VariableDeclaration intermediateVariable = - element.intermediateVariables[i]; + Variable intermediateVariable = element.intermediateVariables[i]; intermediateVariable.initializer = inferExpression( intermediateVariable.initializer!, type, @@ -4410,7 +4393,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ) { VariableStatement variableStatement = element.variableInitializations[index]; - VariableDeclaration variable = variableStatement.variable; + Variable variable = variableStatement.variable; if (variable.name == null) { if (variable.initializer != null) { ExpressionInferenceResult initializerResult = inferExpression( @@ -4517,7 +4500,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isClosureContextLoweringEnabled: isClosureContextLoweringEnabled, ); - VariableDeclaration variable = node.variable = result.loopVariable; + Variable variable = node.variable = result.loopVariable; node.iterable = result.iterable..parent = node; flowAnalysis.forEach_bodyBegin(node); @@ -4940,7 +4923,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType = isSet ? typeSchemaEnvironment.setType(elementType, Nullability.nonNullable) : typeSchemaEnvironment.listType(elementType, Nullability.nonNullable); - VariableDeclaration? result; + Variable? result; if (index == 0 && elements[index] is SpreadElement) { SpreadElement initialSpread = elements[index] as SpreadElement; final bool typeMatches = @@ -5054,7 +5037,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5132,7 +5115,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase void _addExpressionElement( Expression element, InterfaceType receiverType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5154,7 +5137,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase IfElement element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5205,7 +5188,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase IfCaseElement element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5261,7 +5244,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForElement element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5294,7 +5277,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase PatternForElement element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5323,8 +5306,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // Coverage-ignore(suite): Not run. ?.registerAlias(element, loop); body.add(element.patternVariableDeclaration); - for (VariableDeclaration intermediateVariable - in element.intermediateVariables) { + for (Variable intermediateVariable in element.intermediateVariables) { body.add(extern.createVariableStatement(intermediateVariable)); } body.add(loop); @@ -5334,7 +5316,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInElement node, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5383,7 +5365,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase SpreadElement element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5397,7 +5379,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // a single 'addAll' call instead of a for-loop with calls to 'add'. // Null-aware spreads require testing the subexpression's value. - VariableDeclaration? temp; + Variable? temp; if (element.isNullAware) { temp = _createVariable( value, @@ -5428,7 +5410,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase body.add(statement); } else { // Null-aware spreads require testing the subexpression's value. - VariableDeclaration? temp; + Variable? temp; if (element.isNullAware) { temp = _createVariable( value, @@ -5441,11 +5423,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase value = _createNullCheckedVariableGet(temp); } - VariableDeclaration variable = _createForInVariable( + Variable variable = _createForInVariable( element.fileOffset, const DynamicType(), ); - VariableDeclaration castedVar = _createVariable( + Variable castedVar = _createVariable( _createImplicitAs( element.expression.fileOffset, _createVariableGet(variable), @@ -5488,7 +5470,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase NullAwareElement element, InterfaceType receiverType, DartType elementType, - VariableDeclaration result, + Variable result, List body, { required bool isSet, }) { @@ -5513,7 +5495,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase DartType nullableElementType = elementType.withDeclaredNullability( Nullability.nullable, ); - VariableDeclaration temp = _createVariable(value, nullableElementType); + Variable temp = _createVariable(value, nullableElementType); body.add(extern.createVariableStatement(temp)); Statement statement = _createIf( @@ -5593,7 +5575,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase node.valueType, Nullability.nonNullable, ); - VariableDeclaration? result; + Variable? result; if (index == 0 && node.entries[index] is SpreadMapEntry) { SpreadMapEntry initialSpread = node.entries[index] as SpreadMapEntry; @@ -5664,7 +5646,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { if (entry is ControlFlowMapEntry) { @@ -5741,7 +5723,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase void _addNormalEntry( MapLiteralEntry entry, InterfaceType receiverType, - VariableDeclaration result, + Variable result, List body, ) { body.add( @@ -5762,7 +5744,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { List thenBody = []; @@ -5813,7 +5795,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { List thenBody = []; @@ -5869,7 +5851,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { List statements = []; @@ -5902,7 +5884,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { List statements = []; @@ -5928,8 +5910,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // Coverage-ignore(suite): Not run. ?.registerAlias(entry, loop); body.add(entry.patternVariableDeclaration); - for (VariableDeclaration intermediateVariable - in entry.intermediateVariables) { + for (Variable intermediateVariable in entry.intermediateVariables) { body.add(extern.createVariableStatement(intermediateVariable)); } body.add(loop); @@ -5940,7 +5921,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { List statements; @@ -5990,7 +5971,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { Expression value = entry.expression; @@ -6009,7 +5990,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // a single 'addAll' call instead of a for-loop with calls to '[]='. // Null-aware spreads require testing the subexpression's value. - VariableDeclaration? temp; + Variable? temp; if (entry.isNullAware) { temp = _createVariable( value, @@ -6043,7 +6024,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase body.add(statement); } else { // Null-aware spreads require testing the subexpression's value. - VariableDeclaration? temp; + Variable? temp; if (entry.isNullAware) { temp = _createVariable( value, @@ -6062,11 +6043,8 @@ class InferenceVisitorImpl extends InferenceVisitorBase Nullability.nonNullable, [const DynamicType(), const DynamicType()], ); - VariableDeclaration variable = _createForInVariable( - entry.fileOffset, - variableType, - ); - VariableDeclaration keyVar = _createVariable( + Variable variable = _createForInVariable(entry.fileOffset, variableType); + Variable keyVar = _createVariable( _createImplicitAs( entry.expression.fileOffset, _createGetKey( @@ -6078,7 +6056,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ), keyType, ); - VariableDeclaration valueVar = _createVariable( + Variable valueVar = _createVariable( _createImplicitAs( entry.expression.fileOffset, _createGetValue( @@ -6126,7 +6104,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase InterfaceType receiverType, DartType keyType, DartType valueType, - VariableDeclaration result, + Variable result, List body, ) { assert(entry.isKeyNullAware || entry.isValueNullAware); @@ -6168,10 +6146,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase DartType nullableValueType = valueType.withDeclaredNullability( Nullability.nullable, ); - VariableDeclaration valueTemp = _createVariable( - valueExpression, - nullableValueType, - ); + Variable valueTemp = _createVariable(valueExpression, nullableValueType); valueExpression = _createNullCheckedVariableGet(valueTemp); IfStatement ifValueNotNullStatement = _createIf( @@ -6191,10 +6166,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase DartType nullableKeyType = keyType.withDeclaredNullability( Nullability.nullable, ); - VariableDeclaration keyTemp = _createVariable( - keyExpression, - nullableKeyType, - ); + Variable keyTemp = _createVariable(keyExpression, nullableKeyType); keyExpression = _createNullCheckedVariableGet(keyTemp); IfStatement ifKeyNotNullStatement = _createIf( @@ -6235,7 +6207,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // #t[#keyTemp] = #valueTemp{int}; // } - VariableDeclaration keyTemp = _createVariable(keyExpression, keyType); + Variable keyTemp = _createVariable(keyExpression, keyType); keyExpression = _createVariableGet(keyTemp); desugaredStatement.statements.insert( @@ -6334,7 +6306,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } Expression spreadExpression = element.expression; if (element.isNullAware) { - VariableDeclaration temp = _createVariable( + Variable temp = _createVariable( spreadExpression, typeSchemaEnvironment.iterableType( elementType, @@ -6358,7 +6330,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase parts.add(makeLiteral(node.fileOffset, currentPart)); currentPart = null; } - VariableDeclaration temp = _createVariable( + Variable temp = _createVariable( element.expression, elementType.withDeclaredNullability(Nullability.nullable), ); @@ -6475,7 +6447,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } Expression spreadExpression = entry.expression; if (entry.isNullAware) { - VariableDeclaration temp = _createVariable( + Variable temp = _createVariable( spreadExpression, collectionType.withDeclaredNullability(Nullability.nullable), ); @@ -6511,7 +6483,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression desugaredExpression = new NullLiteral(); if (entry.isValueNullAware) { - VariableDeclaration valueTemp = _createVariable( + Variable valueTemp = _createVariable( valueExpression, node.valueType.withDeclaredNullability(Nullability.nullable), ); @@ -6535,7 +6507,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } if (entry.isKeyNullAware) { - VariableDeclaration keyTemp = _createVariable( + Variable keyTemp = _createVariable( entry.key, node.keyType.withDeclaredNullability(Nullability.nullable), ); @@ -6623,24 +6595,23 @@ class InferenceVisitorImpl extends InferenceVisitorBase ); } - VariableDeclaration _createVariable(Expression expression, DartType type) { + Variable _createVariable(Expression expression, DartType type) { assert(expression.fileOffset != TreeNode.noOffset); - return new VariableDeclaration.forValue(expression, type: type) + return new Variable.forValue(expression, type: type) ..fileOffset = expression.fileOffset; } - VariableDeclaration _createForInVariable(int fileOffset, DartType type) { + Variable _createForInVariable(int fileOffset, DartType type) { assert(fileOffset != TreeNode.noOffset); - return new VariableDeclaration.forValue(null, type: type) - ..fileOffset = fileOffset; + return new Variable.forValue(null, type: type)..fileOffset = fileOffset; } - VariableGet _createVariableGet(VariableDeclaration variable) { + VariableGet _createVariableGet(Variable variable) { assert(variable.fileOffset != TreeNode.noOffset); return new VariableGet(variable)..fileOffset = variable.fileOffset; } - VariableGet _createNullCheckedVariableGet(VariableDeclaration variable) { + VariableGet _createNullCheckedVariableGet(Variable variable) { assert(variable.fileOffset != TreeNode.noOffset); DartType promotedType = variable.type.withDeclaredNullability( Nullability.nonNullable, @@ -6908,7 +6879,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInStatement _createForInStatement( int fileOffset, - VariableDeclaration variable, + Variable variable, Expression iterable, Statement body, { bool isAsync = false, @@ -6920,7 +6891,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Let _createNullAwareGuard( int fileOffset, - VariableDeclaration variable, + Variable variable, Expression defaultValue, DartType type, { Expression? nullCheckedValue, @@ -7360,7 +7331,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase expression: entry.expression, pattern: entry.patternGuard.pattern, variables: { - for (VariableDeclaration variable + for (Variable variable in entry.patternGuard.pattern.declaredVariables) variable.name!: variable, }, @@ -7501,14 +7472,14 @@ class InferenceVisitorImpl extends InferenceVisitorBase ..parent = patternVariableDeclaration; } - List declaredVariables = + List declaredVariables = patternVariableDeclaration.pattern.declaredVariables; assert(declaredVariables.length == entry.intermediateVariables.length); assert(declaredVariables.length == entry.variables.length); for (int i = 0; i < declaredVariables.length; i++) { DartType type = declaredVariables[i].type; - VariableDeclaration intermediateVariable = entry.intermediateVariables[i]; + Variable intermediateVariable = entry.intermediateVariables[i]; intermediateVariable.initializer = inferExpression( intermediateVariable.initializer!, type, @@ -7575,7 +7546,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase List? variables; for (int index = 0; index < entry.variables.length; index++) { VariableStatement variableStatement = entry.variables[index]; - VariableDeclaration variable = variableStatement.variable; + Variable variable = variableStatement.variable; if (variable.name == null) { if (variable.initializer != null) { ExpressionInferenceResult result = inferExpression( @@ -7693,7 +7664,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase forOffset: node.forOffset, isClosureContextLoweringEnabled: isClosureContextLoweringEnabled, ); - VariableDeclaration variable = node.variable = result.loopVariable; + Variable variable = node.variable = result.loopVariable; node.iterable = result.iterable..parent = node; flowAnalysis.forEach_bodyBegin(node); @@ -8542,7 +8513,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression read = readResult.expression; DartType readType = readResult.inferredType; - VariableDeclaration? valueVariable; + Variable? valueVariable; if (!node.forEffect && node.isPost) { // For postfix expressions like `a = o.b++` that are not for effect we // need to store the read value as the result after assignment. @@ -8575,10 +8546,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (valueVariable == null) { replacement = write; } else { - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable, createLet(writeVariable, createVariableGet(valueVariable)), @@ -8606,7 +8574,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression read = readResult.expression; DartType readType = readResult.inferredType; - VariableDeclaration? valueVariable; + Variable? valueVariable; if (!node.forEffect && node.isPost) { // For postfix expressions like `a = o.b++` that are not for effect we // need to store the read value as the result after assignment. @@ -8641,10 +8609,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (valueVariable == null) { replacement = write; } else { - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable, createLet(writeVariable, createVariableGet(valueVariable)), @@ -8671,7 +8636,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression read = readResult.expression; DartType readType = readResult.inferredType; - VariableDeclaration? valueVariable; + Variable? valueVariable; if (!node.forEffect && node.isPost) { // For postfix expressions like `a = o.b++` that are not for effect we // need to store the read value as the result after assignment. @@ -8705,10 +8670,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (valueVariable == null) { replacement = write; } else { - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable, createLet(writeVariable, createVariableGet(valueVariable)), @@ -8737,7 +8699,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression receiver = receiverResult.expression; DartType receiverType = receiverResult.inferredType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver; Expression writeReceiver; if (node.isNullAware) { @@ -8779,7 +8741,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression read = readResult.expression; DartType readType = readResult.inferredType; - VariableDeclaration? valueVariable; + Variable? valueVariable; if (!node.forEffect && node.isPost) { // For postfix expressions like `a = o.b++` that are not for effect we // need to store the read value as the result after assignment. @@ -8825,10 +8787,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (valueVariable == null) { replacement = write; } else { - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable, createLet(writeVariable, createVariableGet(valueVariable)), @@ -8867,7 +8826,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression receiver = receiverResult.expression; DartType receiverType = receiverResult.inferredType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver; Expression writeReceiver; if (node.isNullAware) { @@ -8969,7 +8928,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression receiver = receiverResult.expression; DartType receiverType = receiverResult.inferredType; - VariableDeclaration receiverVariable; + Variable receiverVariable; if (node.isNullAware) { receiverVariable = createVariable(receiver, receiverType); createNullAwareGuard(receiverVariable); @@ -9062,7 +9021,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // // let v1 = o in let v2 = v1.a in v2 == null ? v1.a = b : v2 // - VariableDeclaration readVariable = createVariable(read, readType); + Variable readVariable = createVariable(read, readType); Expression equalsNull = createEqualsNull( createVariableGet(readVariable), fileOffset: node.fileOffset, @@ -9178,7 +9137,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // // let v1 = a in v1 == null ? a = b : v1 // - VariableDeclaration readVariable = createVariable(read, readType); + Variable readVariable = createVariable(read, readType); Expression equalsNull = createEqualsNull( createVariableGet(readVariable), fileOffset: node.fileOffset, @@ -9294,7 +9253,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiverType = nonNullReceiverType; } - VariableDeclaration? receiverVariable; + Variable? receiverVariable; if (!node.forEffect && !isPureExpression(receiver)) { receiverVariable = createVariable(receiver, receiverType); receiver = createVariableGet(receiverVariable); @@ -9322,7 +9281,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase indexResult, ).expression; - VariableDeclaration? indexVariable; + Variable? indexVariable; if (!node.forEffect && !isPureExpression(index)) { indexVariable = createVariable(index, indexResult.inferredType); index = createVariableGet(indexVariable); @@ -9336,7 +9295,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase valueResult = ensureAssignableResult(valueType, valueResult); Expression value = valueResult.expression; - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression? returnedValue; if (node.forEffect) { } else if (isPureExpression(value)) { @@ -9366,7 +9325,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (node.forEffect) { replacement = assignment; } else { - VariableDeclaration assignmentVariable = createVariable( + Variable assignmentVariable = createVariable( assignment, const VoidType(), ); @@ -9413,7 +9372,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase indexResult, ).expression; - VariableDeclaration? indexVariable; + Variable? indexVariable; if (!isPureExpression(index)) { indexVariable = createVariable(index, indexResult.inferredType); index = createVariableGet(indexVariable); @@ -9427,7 +9386,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase valueResult = ensureAssignableResult(valueType, valueResult); Expression value = valueResult.expression; - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression returnedValue; if (isPureExpression(value)) { returnedValue = clonePureExpression(value); @@ -9452,10 +9411,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase indexSetTarget.classMember as Procedure, )..fileOffset = node.fileOffset; - VariableDeclaration assignmentVariable = createVariable( - assignment, - const VoidType(), - ); + Variable assignmentVariable = createVariable(assignment, const VoidType()); Expression replacement = createLet(assignmentVariable, returnedValue); if (valueVariable != null) { replacement = createLet(valueVariable, replacement); @@ -9614,7 +9570,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiver = ensureAssignable(extensionOnType, receiverType, receiver); receiverType = extensionOnType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; if (!node.forEffect && !isPureExpression(receiver)) { receiverVariable = createVariable(receiver, receiverType); receiver = createVariableGet(receiverVariable); @@ -9642,7 +9598,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase valueResult = ensureAssignableResult(valueType, valueResult); Expression value = valueResult.expression; - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression? returnedValue; if (node.forEffect) { // Returned value is not needed. @@ -9671,7 +9627,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression replacement = assignment; if (returnedValue != null) { assert(!node.forEffect); - VariableDeclaration assignmentVariable = createVariable( + Variable assignmentVariable = createVariable( assignment, const VoidType(), ); @@ -9712,7 +9668,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiverType = nonNullReceiverType; } - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver = receiver; Expression writeReceiver; if (isPureExpression(readReceiver)) { @@ -9756,7 +9712,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); - VariableDeclaration? indexVariable; + Variable? indexVariable; Expression readIndex = indexResult.expression; Map Function() whyNotPromotedIndex = flowAnalysis.whyNotPromoted(flowAnalysis.getExpressionInfo(readIndex)); @@ -9815,7 +9771,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase typeContext: typeContext, ); - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression? returnedValue; if (node.forEffect) { // No need for value variable. @@ -9869,15 +9825,12 @@ class InferenceVisitorImpl extends InferenceVisitorBase // : readVariable // // - VariableDeclaration readVariable = createVariable(read, readType); + Variable readVariable = createVariable(read, readType); Expression equalsNull = createEqualsNull( createVariableGet(readVariable), fileOffset: node.testOffset, ); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); VariableGet variableGet = createVariableGet(readVariable); if (!identical(nonNullableReadType, readType)) { variableGet.promotedType = nonNullableReadType; @@ -9945,7 +9898,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); - VariableDeclaration? indexVariable; + Variable? indexVariable; Expression readIndex = indexResult.expression; Expression writeIndex; if (isPureExpression(readIndex)) { @@ -9996,7 +9949,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase typeContext: typeContext, ); - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression? returnedValue; if (node.forEffect) { // No need for a value variable. @@ -10048,15 +10001,12 @@ class InferenceVisitorImpl extends InferenceVisitorBase // : v2 // - VariableDeclaration readVariable = createVariable(read, readType); + Variable readVariable = createVariable(read, readType); Expression equalsNull = createEqualsNull( createVariableGet(readVariable), fileOffset: node.testOffset, ); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); VariableGet readVariableGet = createVariableGet(readVariable); if (!identical(nonNullableReadType, readType)) { readVariableGet.promotedType = nonNullableReadType; @@ -10134,7 +10084,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiver = ensureAssignable(extensionOnType, receiverType, receiver); receiverType = extensionOnType; - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver; Expression writeReceiver; if (isPureExpression(receiver)) { @@ -10173,7 +10123,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); - VariableDeclaration? indexVariable; + Variable? indexVariable; Expression readIndex = indexResult.expression; Expression writeIndex; if (isPureExpression(readIndex)) { @@ -10228,7 +10178,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase typeContext: typeContext, ); - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression? returnedValue; if (node.forEffect) { // No need for a value variable. @@ -10285,15 +10235,12 @@ class InferenceVisitorImpl extends InferenceVisitorBase // valueVariable) // : readVariable // - VariableDeclaration readVariable = createVariable(read, readType); + Variable readVariable = createVariable(read, readType); Expression equalsNull = createEqualsNull( createVariableGet(readVariable), fileOffset: node.testOffset, ); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); VariableGet readVariableGet = createVariableGet(readVariable); if (!identical(nonNullableReadType, readType)) { readVariableGet.promotedType = nonNullableReadType; @@ -11198,7 +11145,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiverType = nonNullReceiverType; } - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver = receiver; Expression writeReceiver; if (isPureExpression(readReceiver)) { @@ -11232,7 +11179,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); - VariableDeclaration? indexVariable; + Variable? indexVariable; Expression readIndex = indexResult.expression; Map Function() whyNotPromotedIndex = flowAnalysis.whyNotPromoted(flowAnalysis.getExpressionInfo(readIndex)); @@ -11264,7 +11211,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression read = readResult.expression; DartType readType = readResult.inferredType; - VariableDeclaration? leftVariable; + Variable? leftVariable; Expression left; if (node.forEffect) { left = read; @@ -11312,7 +11259,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression binary = binaryResult.expression; DartType binaryType = binaryResult.inferredType; - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression valueExpression; if (node.forEffect || node.forPostIncDec) { valueExpression = binary; @@ -11352,10 +11299,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase assert(leftVariable != null); assert(valueVariable == null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); inner = createLet( leftVariable!, createLet(writeVariable, createVariableGet(leftVariable)), @@ -11371,10 +11315,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase assert(leftVariable == null); assert(valueVariable != null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); inner = createLet( valueVariable!, createLet(writeVariable, createVariableGet(valueVariable)), @@ -11418,7 +11359,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); - VariableDeclaration? indexVariable; + Variable? indexVariable; Expression readIndex = indexResult.expression; Expression writeIndex; if (isPureExpression(readIndex)) { @@ -11443,7 +11384,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase readTarget.classMember as Procedure, )..fileOffset = node.readOffset; - VariableDeclaration? leftVariable; + Variable? leftVariable; Expression left; if (node.forEffect) { left = read; @@ -11489,7 +11430,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase writeIndex, ); - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression valueExpression; if (node.forEffect || node.forPostIncDec) { valueExpression = binary; @@ -11526,10 +11467,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase assert(leftVariable != null); assert(valueVariable == null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( leftVariable!, createLet(writeVariable, createVariableGet(leftVariable)), @@ -11545,10 +11483,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase assert(leftVariable == null); assert(valueVariable != null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable!, createLet(writeVariable, createVariableGet(valueVariable)), @@ -11625,7 +11560,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase extensionTypeArguments, ); - VariableDeclaration? receiverVariable; + Variable? receiverVariable; Expression readReceiver; Expression writeReceiver; if (isPureExpression(receiver)) { @@ -11645,7 +11580,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isVoidAllowed: true, ); - VariableDeclaration? indexVariable; + Variable? indexVariable; Expression readIndex = indexResult.expression; Expression writeIndex; if (isPureExpression(readIndex)) { @@ -11674,7 +11609,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression read = readResult.expression; DartType readType = readResult.inferredType; - VariableDeclaration? leftVariable; + Variable? leftVariable; Expression left; if (node.forEffect) { left = read; @@ -11720,7 +11655,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression binary = binaryResult.expression; DartType binaryType = binaryResult.inferredType; - VariableDeclaration? valueVariable; + Variable? valueVariable; Expression valueExpression; if (node.forEffect || node.forPostIncDec) { valueExpression = binary; @@ -11764,10 +11699,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase assert(leftVariable != null); assert(valueVariable == null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( leftVariable!, createLet(writeVariable, createVariableGet(leftVariable)), @@ -11785,10 +11717,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase assert(leftVariable == null); assert(valueVariable != null); - VariableDeclaration writeVariable = createVariable( - write, - const VoidType(), - ); + Variable writeVariable = createVariable(write, const VoidType()); replacement = createLet( valueVariable!, createLet(writeVariable, createVariableGet(valueVariable)), @@ -11934,7 +11863,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (node.isCascade) { inferredType = initializerType; - VariableDeclaration tempVar = new VariableDeclaration( + Variable tempVar = new Variable( null, initializer: bodyResult.expression, isSynthesized: true, @@ -11949,8 +11878,8 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression replacement; if (node.isNullAware) { - VariableDeclaration tempVar = - new VariableDeclaration( + Variable tempVar = + new Variable( null, initializer: node.variable.initializer!, isSynthesized: true, @@ -12385,7 +12314,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ) { DartType typeContext = bodyContext.returnContext; DartType inferredType; - VariableDeclaration? thisVariable = _constructorContext?.thisVariable; + Variable? thisVariable = _constructorContext?.thisVariable; if (bodyContext.isRoot && thisVariable != null) { // The constructor is lowered with an explicit variable for `this`. This // means that `return;` should be encoded as `return #this;` where `#this` @@ -12542,7 +12471,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase // Create the set: Set setVar = new Set(); InterfaceType receiverType; - VariableDeclaration setVar = new VariableDeclaration.forValue( + Variable setVar = new Variable.forValue( new StaticInvocation( engine.setFactory, new Arguments([], types: [node.typeArgument]), @@ -13127,7 +13056,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase for (int caseIndex = 0; caseIndex < node.cases.length; caseIndex++) { PatternSwitchCase switchCase = node.cases[caseIndex]; - List jointVariablesNotInAll = []; + List jointVariablesNotInAll = []; for ( int headIndex = 0; headIndex < switchCase.patternGuards.length; @@ -13152,11 +13081,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase } Map inferredVariableTypes = { - for (VariableDeclaration variable in pattern.declaredVariables) + for (Variable variable in pattern.declaredVariables) variable.name!: variable.type, }; if (headIndex == 0) { - for (VariableDeclaration jointVariable in switchCase.jointVariables) { + for (Variable jointVariable in switchCase.jointVariables) { DartType? inferredType = inferredVariableTypes[jointVariable.name!]; if (inferredType != null) { jointVariable.type = inferredType; @@ -13167,7 +13096,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } } else { for (int i = 0; i < switchCase.jointVariables.length; ++i) { - VariableDeclaration jointVariable = switchCase.jointVariables[i]; + Variable jointVariable = switchCase.jointVariables[i]; // The error on joint variables not present in all case heads is // reported in BodyBuilder. DartType? inferredType = inferredVariableTypes[jointVariable.name!]; @@ -13447,7 +13376,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase @override // Coverage-ignore(suite): Not run. - StatementInferenceResult visitVariableDeclaration( + StatementInferenceResult visitVariable( covariant VariableDeclarationImpl node, ) { return _inferInternalExpressionVariableDeclaration(node, node); @@ -13789,7 +13718,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase List named = namedUnsorted; Map? namedElements = node.namedElements; List originalElementOrder = node.originalElementOrder; - List? hoistedExpressions; + List? hoistedExpressions; List? positionalTypeContexts; Map? namedTypeContexts; @@ -13940,7 +13869,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (needsHoisting && !isPureExpression(expression)) { // We hoist the value of the [NamedExpression] into a synthesized // variable, and replace the value with a read of the variable. - VariableDeclaration variable = createVariable(expression, type); + Variable variable = createVariable(expression, type); hoistedExpressions ??= []; hoistedExpressions.add(variable); element.value = createVariableGet(variable)..parent = element; @@ -13959,7 +13888,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (needsHoisting && !isPureExpression(expression)) { // We hoist the positional element into a synthesized variable, and // replace the element in [positional] with a read of the variable. - VariableDeclaration variable = createVariable(expression, type); + Variable variable = createVariable(expression, type); hoistedExpressions ??= []; hoistedExpressions.add(variable); positional[positionalIndex] = createVariableGet(variable); @@ -14011,7 +13940,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase )..fileOffset = node.fileOffset; } if (hoistedExpressions != null) { - for (VariableDeclaration variable in hoistedExpressions) { + for (Variable variable in hoistedExpressions) { result = createLet(variable, result); } } @@ -14345,41 +14274,31 @@ class InferenceVisitorImpl extends InferenceVisitorBase } @override - FlowAnalysis get flow => + FlowAnalysis get flow => flowAnalysis; @override - SwitchExpressionMemberInfo + SwitchExpressionMemberInfo getSwitchExpressionMemberInfo(Expression node, int index) { SwitchExpressionCase switchExpressionCase = (node as SwitchExpression).cases[index]; Pattern pattern = switchExpressionCase.patternGuard.pattern; - Map variables = { - for (VariableDeclaration declaredVariable in pattern.declaredVariables) + Map variables = { + for (Variable declaredVariable in pattern.declaredVariables) declaredVariable.name!: declaredVariable, }; - return new SwitchExpressionMemberInfo< - TreeNode, - Expression, - VariableDeclaration - >( - head: - new CaseHeadOrDefaultInfo( - pattern: pattern, - guard: switchExpressionCase.patternGuard.guard, - variables: variables, - ), + return new SwitchExpressionMemberInfo( + head: new CaseHeadOrDefaultInfo( + pattern: pattern, + guard: switchExpressionCase.patternGuard.guard, + variables: variables, + ), expression: switchExpressionCase.expression, ); } @override - SwitchStatementMemberInfo< - TreeNode, - Statement, - Expression, - VariableDeclaration - > + SwitchStatementMemberInfo getSwitchStatementMemberInfo(covariant SwitchStatement node, int caseIndex) { SwitchCase case_ = node.cases[caseIndex]; if (case_ is SwitchCaseImpl) { @@ -14403,7 +14322,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase pattern: patternGuard.pattern, guard: patternGuard.guard, variables: { - for (VariableDeclaration variable + for (Variable variable in patternGuard.pattern.declaredVariables) variable.name!: variable, }, @@ -14413,7 +14332,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase ], body: [case_.body], variables: { - for (VariableDeclaration jointVariable in case_.jointVariables) + for (Variable jointVariable in case_.jointVariables) jointVariable.name!: jointVariable, }, hasLabels: case_.hasLabel, @@ -14537,7 +14456,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase void handleCase_afterCaseHeads( Statement node, int caseIndex, - Iterable variables, + Iterable variables, ) {} @override @@ -14613,7 +14532,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } @override - void setVariableType(VariableDeclaration variable, SharedTypeView type) { + void setVariableType(Variable variable, SharedTypeView type) { variable.type = type.unwrapTypeView(); } @@ -14844,20 +14763,18 @@ class InferenceVisitorImpl extends InferenceVisitorBase node.left = (rewrite as Pattern)..parent = node; } - Map leftDeclaredVariablesByName = { - for (VariableDeclaration variable in node.left.declaredVariables) + Map leftDeclaredVariablesByName = { + for (Variable variable in node.left.declaredVariables) variable.name!: variable, }; - Map jointVariableNames = { - for (VariableDeclaration variable in node.orPatternJointVariables) + Map jointVariableNames = { + for (Variable variable in node.orPatternJointVariables) variable.name!: variable, }; - for (VariableDeclaration rightVariable in node.right.declaredVariables) { + for (Variable rightVariable in node.right.declaredVariables) { String rightVariableName = rightVariable.name!; - VariableDeclaration? leftVariable = - leftDeclaredVariablesByName[rightVariableName]; - VariableDeclaration? jointVariable = - jointVariableNames[rightVariableName]; + Variable? leftVariable = leftDeclaredVariablesByName[rightVariableName]; + Variable? jointVariable = jointVariableNames[rightVariableName]; if (leftVariable != null && jointVariable != null) { if (leftVariable.type != rightVariable.type || leftVariable.isFinal != rightVariable.isFinal) { @@ -16140,7 +16057,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase @override void finishJoinedPatternVariable( - VariableDeclaration variable, { + Variable variable, { required JoinedPatternVariableLocation location, required JoinedPatternVariableInconsistency inconsistency, required bool isFinal, @@ -16767,7 +16684,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase return node is DotShorthand; } - CaptureKind _captureKindForVariable(VariableDeclaration variable) { + CaptureKind _captureKindForVariable(Variable variable) { int variableKey = assignedVariables.promotionKeyStore.keyForVariable( variable, ); @@ -16821,7 +16738,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase } StatementInferenceResult _inferInternalExpressionVariableDeclaration( - VariableDeclaration node, + Variable node, InternalVariable nodeVariable, { VariableStatement? variableStatement, }) { @@ -16856,8 +16773,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (node.isLate && node.hasDeclaredInitializer) { // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - VariableDeclaration variable = - (node.variable as InternalVariable).astVariable; + Variable variable = (node.variable as InternalVariable).astVariable; if (isClosureContextLoweringEnabled) { _contextAllocationStrategy.handleVariablesCapturedByNode( node, @@ -16933,9 +16849,9 @@ class InferenceVisitorImpl extends InferenceVisitorBase node.type, late_lowering.computeIsSetStrategy(libraryBuilder), ); - VariableDeclaration? isSetVariable; + Variable? isSetVariable; if (isSetEncoding == late_lowering.IsSetEncoding.useIsSetField) { - isSetVariable = new VariableDeclaration( + isSetVariable = new Variable( late_lowering.computeLateLocalIsSetName(node.name!), initializer: new BoolLiteral(false)..fileOffset = fileOffset, type: coreTypes.boolRawType(Nullability.nonNullable), @@ -16960,7 +16876,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression createIsSetWrite(Expression value) => new VariableSet(isSetVariable!, value); - VariableDeclaration getVariable = new VariableDeclaration( + Variable getVariable = new Variable( late_lowering.computeLateLocalGetterName(node.name!), isLowered: true, )..fileOffset = fileOffset; @@ -17016,11 +16932,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase if (!node.isFinal || node.initializer == null) { nodeVariable.isLateFinalWithoutInitializer = node.isFinal && node.initializer == null; - VariableDeclaration setVariable = new VariableDeclaration( + Variable setVariable = new Variable( late_lowering.computeLateLocalSetterName(node.name!), isLowered: true, )..fileOffset = fileOffset; - VariableDeclaration setterParameter = new VariableDeclaration( + Variable setterParameter = new Variable( "${node.name}#param", type: node.type, )..fileOffset = fileOffset; @@ -17054,7 +16970,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase isSetEncoding: isSetEncoding, ) ..fileOffset = fileOffset, - positionalParameters: [setterParameter], + positionalParameters: [setterParameter], ), ) // TODO(johnniwinther): Reinsert the file offset when the vm doesn't 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 8db669693a7..3fa3a834f6f 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 @@ -69,15 +69,14 @@ Set _computeExplicitlyTypedParameterSet( ) { Set result = {}; int unnamedParameterIndex = 0; - for (VariableDeclaration positionalParameter + for (Variable positionalParameter in functionExpression.function.positionalParameters) { int key = unnamedParameterIndex++; if (!(positionalParameter as InternalVariable).isImplicitlyTyped) { result.add(key); } } - for (VariableDeclaration namedParameter - in functionExpression.function.namedParameters) { + for (Variable namedParameter in functionExpression.function.namedParameters) { String key = namedParameter.name!; if (!(namedParameter as InternalVariable).isImplicitlyTyped) { result.add(key); @@ -114,12 +113,12 @@ enum MethodContravarianceCheckKind { Expression _hoist( Expression expression, DartType type, - List? hoistedExpressions, + List? hoistedExpressions, ) { if (hoistedExpressions != null && !isThisExpression(expression) && expression is! FunctionExpression) { - VariableDeclaration variable = createVariable(expression, type); + Variable variable = createVariable(expression, type); hoistedExpressions.add(variable); return createVariableGet(variable); } @@ -162,8 +161,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. @@ -811,10 +810,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor { // Replace expression with: // `let t = expression in t == null ? null : t.call` - VariableDeclaration t = new VariableDeclaration.forValue( - expression, - type: expressionType, - )..fileOffset = fileOffset; + Variable t = new Variable.forValue(expression, type: expressionType) + ..fileOffset = fileOffset; tearOff = new Let( t, new ConditionalExpression( @@ -1713,7 +1710,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { InvocationTargetType invocationTargetType, TypeArguments? typeArguments, ActualArguments arguments, { - List? hoistedExpressions, + List? hoistedExpressions, bool isSpecialCasedBinaryOperator = false, bool isSpecialCasedTernaryOperator = false, DartType? receiverType, @@ -1751,7 +1748,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { FunctionType calleeType, TypeArguments? typeArguments, ActualArguments actualArguments, - List? hoistedExpressions, { + List? hoistedExpressions, { bool isSpecialCasedBinaryOperator = false, bool isSpecialCasedTernaryOperator = false, DartType? receiverType, @@ -1794,7 +1791,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { List? inferredTypes; FunctionTypeInstantiator? instantiator; - List? localHoistedExpressions; + List? localHoistedExpressions; int hoistingEndIndex; if (isConst) { // Hoisting is never needed for constant expressions. @@ -1814,7 +1811,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { if (actualArguments.hasNamedBeforePositional && hoistedExpressions == null && !isConst) { - hoistedExpressions = localHoistedExpressions = []; + hoistedExpressions = localHoistedExpressions = []; } TypeConstraintGatherer? gatherer; @@ -2255,7 +2252,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { // Let `(P0 x0, ..., Pm xm)` be the set of formal parameters of the closure // (including required, positional optional, and named optional parameters). // If any type `Pi` is missing, denote it as `_`. - List formals = [ + List formals = [ ...function.positionalParameters, ...function.namedParameters, ]; @@ -2363,13 +2360,12 @@ abstract class InferenceVisitorBase implements InferenceVisitor { } } - List positionalParameters = - function.positionalParameters; + List positionalParameters = function.positionalParameters; for (int i = 0; i < positionalParameters.length; i++) { - VariableDeclaration parameter = positionalParameters[i]; + Variable parameter = positionalParameters[i]; // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - VariableDeclaration parameterAstVariable = + Variable parameterAstVariable = (parameter as InternalVariable).astVariable; flowAnalysis.declare( parameterAstVariable, @@ -2386,10 +2382,10 @@ abstract class InferenceVisitorBase implements InferenceVisitor { ..parent = parameter; } } - for (VariableDeclaration parameter in function.namedParameters) { + for (Variable parameter in function.namedParameters) { // TODO(62401): Remove the cast when the flow analysis uses // [InternalExpressionVariable]s. - VariableDeclaration parameterAstVariable = + Variable parameterAstVariable = (parameter as InternalVariable).astVariable; flowAnalysis.declare( parameterAstVariable, @@ -2407,7 +2403,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { } } - for (VariableDeclaration parameter in function.namedParameters) { + for (Variable parameter in function.namedParameters) { InternalVariable formal = parameter as InternalVariable; // Required named parameters shouldn't have initializers. if (formal.isRequired && formal.hasDeclaredInitializer) { @@ -2547,7 +2543,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isImplicitCall, }) { InvocationInferenceResult result = inferInvocation( @@ -2591,7 +2587,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isImplicitCall, }) { InvocationInferenceResult result = inferInvocation( @@ -2633,7 +2629,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isExpressionInvocation, required bool isImplicitCall, Name? implicitInvocationPropertyName, @@ -2682,7 +2678,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isImplicitCall, }) { assert( @@ -2846,7 +2842,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isImplicitCall, }) { assert(target.isCallFunction || target.isNullableCallFunction); @@ -2881,7 +2877,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { functionType: null, )..fileOffset = fileOffset; } else if (receiver is VariableGet) { - VariableDeclaration variable = receiver.variable; + Variable variable = receiver.variable; TreeNode? parent = variable.parent; if (parent is FunctionDeclaration) { assert( @@ -3031,7 +3027,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isImplicitCall, required bool isSpecialCasedBinaryOperator, required bool isSpecialCasedTernaryOperator, @@ -3238,14 +3234,14 @@ abstract class InferenceVisitorBase implements InferenceVisitor { required TypeArguments? typeArguments, required ActualArguments arguments, required DartType typeContext, - required List? hoistedExpressions, + required List? hoistedExpressions, required bool isExpressionInvocation, }) { Expression originalReceiver = receiver; - List? locallyHoistedExpressions; + List? locallyHoistedExpressions; if (hoistedExpressions == null) { - hoistedExpressions = locallyHoistedExpressions = []; + hoistedExpressions = locallyHoistedExpressions = []; } if (arguments.positionalCount > 0 || arguments.namedCount > 0) { receiver = _hoist(receiver, receiverType, hoistedExpressions); @@ -3439,7 +3435,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isExpressionInvocation, }) { assert( @@ -3476,7 +3472,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { ExpressionInferenceResult _insertHoistedExpression( ExpressionInferenceResult result, - List? hoistedExpressions, + List? hoistedExpressions, ) { if (hoistedExpressions != null && hoistedExpressions.isNotEmpty) { Expression expression = result.expression; @@ -3497,7 +3493,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeArguments? typeArguments, ActualArguments arguments, DartType typeContext, - List? hoistedExpressions, { + List? hoistedExpressions, { required bool isExpressionInvocation, }) { assert( @@ -3542,7 +3538,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { required bool isExpressionInvocation, required bool isImplicitCall, Name? implicitInvocationPropertyName, - List? hoistedExpressions, + List? hoistedExpressions, ObjectAccessTarget? target, }) { target ??= findInterfaceMember( @@ -4535,8 +4531,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor { )..fileOffset = fileOffset, )..fileOffset = fileOffset; } else { - VariableDeclaration valueVariable = createVariable(value, valueType); - VariableDeclaration assignmentVariable = createVariable( + Variable valueVariable = createVariable(value, valueType); + Variable assignmentVariable = createVariable( new StaticInvocation( writeTarget.member as Procedure, new Arguments( @@ -4755,10 +4751,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor { if (uninstantiatedType.isPotentiallyNullable) { // Replace expression with: // `let t = expression in t == null ? null : t<...>` - VariableDeclaration t = new VariableDeclaration.forValue( - expression, - type: uninstantiatedType, - )..fileOffset = expression.fileOffset; + Variable t = new Variable.forValue(expression, type: uninstantiatedType) + ..fileOffset = expression.fileOffset; Expression nullCheck = new EqualsNull( new VariableGet(t)..fileOffset = expression.fileOffset, @@ -5039,7 +5033,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { } } if (expression is VariableGet) { - VariableDeclaration variable = expression.variable; + Variable variable = expression.variable; if (variable is VariableDeclarationImpl && variable.isLocalFunction) { return diag.invalidCastLocalFunction; } @@ -5716,7 +5710,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { /// /// [parameters] are those of the function being inferred. ScopeProviderInfo beginFunctionBodyInference( - List parameters, { + List parameters, { required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, }); @@ -5800,12 +5794,7 @@ FunctionType replaceReturnType(FunctionType functionType, DartType returnType) { } class _WhyNotPromotedVisitor - implements - NonPromotionReasonVisitor< - List, - Node, - VariableDeclaration - > { + implements NonPromotionReasonVisitor, Node, Variable> { final InferenceVisitorBase inferrer; Member? propertyReference; @@ -5814,7 +5803,7 @@ class _WhyNotPromotedVisitor @override List visitDemoteViaExplicitWrite( - DemoteViaExplicitWrite reason, + DemoteViaExplicitWrite reason, ) { TreeNode node = reason.node as TreeNode; if (inferrer.dataForTesting != null) { @@ -6123,7 +6112,7 @@ class _ArgumentInfo { extension on List<_ArgumentInfo> { (List positional, List named) computeArguments({ - required List? hoistedExpressions, + required List? hoistedExpressions, required int hoistingEndIndex, }) { List positional = []; @@ -6415,7 +6404,7 @@ class ExtensionSetData { /// Data resulting from the inference of a pattern in a for-in element. class PatternForInData { - final VariableDeclaration loopVariable; + final Variable loopVariable; final Expression iterable; final PatternVariableDeclaration Function() computePatternVariableDeclaration; diff --git a/pkg/front_end/lib/src/type_inference/matching_cache.dart b/pkg/front_end/lib/src/type_inference/matching_cache.dart index 01d3a8a071a..813acbc7046 100644 --- a/pkg/front_end/lib/src/type_inference/matching_cache.dart +++ b/pkg/front_end/lib/src/type_inference/matching_cache.dart @@ -49,7 +49,7 @@ class MatchingCache { bool _isClosed = false; /// The declarations need for the cached expressions. - List _declarations = []; + List _declarations = []; /// Map for the known cached keys and their corresponding expressions. Map _cacheKeyMap = {}; @@ -65,7 +65,7 @@ class MatchingCache { /// if (o case [int a, _] || [_, int a]) { ... } /// /// where a joint variable is used instead of the two declared 'a' variables. - Map _variableAliases = {}; + Map _variableAliases = {}; MatchingCache( this._matchingCacheIndex, @@ -82,16 +82,16 @@ class MatchingCache { /// /// where a joint variable is used instead of the two declared 'a' variables. void declareJointVariables( - List jointVariables, - List variables1, - List variables2, + List jointVariables, + List variables1, + List variables2, ) { - Map jointVariablesMap = {}; - for (VariableDeclaration variable in jointVariables) { + Map jointVariablesMap = {}; + for (Variable variable in jointVariables) { jointVariablesMap[variable.name!] = variable; } - for (VariableDeclaration variable in variables1) { - VariableDeclaration? jointVariable = jointVariablesMap[variable.name!]; + for (Variable variable in variables1) { + Variable? jointVariable = jointVariablesMap[variable.name!]; if (jointVariable != null) { _variableAliases[variable] = jointVariable; } else { @@ -101,8 +101,8 @@ class MatchingCache { registerDeclaration(variable); } } - for (VariableDeclaration variable in variables2) { - VariableDeclaration? jointVariable = jointVariablesMap[variable.name!]; + for (Variable variable in variables2) { + Variable? jointVariable = jointVariablesMap[variable.name!]; if (jointVariable != null) { _variableAliases[variable] = jointVariable; } else { @@ -122,8 +122,8 @@ class MatchingCache { /// /// where a joint variable is the unaliased variable for of the two /// declared 'a' variables. - VariableDeclaration getUnaliasedVariable(VariableDeclaration variable) { - VariableDeclaration? unalias = _variableAliases[variable]; + Variable getUnaliasedVariable(Variable variable) { + Variable? unalias = _variableAliases[variable]; if (unalias != null) { // Joint variables might themselves be joint, for instance in nested // or patterns. @@ -166,7 +166,7 @@ class MatchingCache { /// Registers that the variable or local function [declaration] is need for /// the cached expressions. - void registerDeclaration(VariableDeclaration declaration) { + void registerDeclaration(Variable declaration) { assert(!_isClosed); _declarations.add(declaration); } @@ -176,18 +176,15 @@ class MatchingCache { /// /// Once called, the matching cache is closed and no new cacheable expressions /// can be created. - Iterable get declarations { + Iterable get declarations { _isClosed = true; return _declarations; } - /// Creates a [VariableDeclaration] for a temporary variable of the given + /// Creates a [Variable] for a temporary variable of the given /// [type] and registers it with [registerDeclaration]. - VariableDeclaration createTemporaryVariable( - DartType type, { - required int fileOffset, - }) { - VariableDeclaration variable = createUninitializedVariable( + Variable createTemporaryVariable(DartType type, {required int fileOffset}) { + Variable variable = createUninitializedVariable( type, fileOffset: fileOffset, ); @@ -1252,13 +1249,13 @@ class Cache { /// non-late variable. /// /// Otherwise [_variable] is unused. - VariableDeclaration? _variable; + Variable? _variable; /// If cached using late lowering, this will be the boolean variable that /// tracks whether [_variable] as been initialized. /// /// Otherwise [_isSetVariable] is unused. - VariableDeclaration? _isSetVariable; + Variable? _isSetVariable; /// The name used to name [_variable], [_isSetVariable] and [_getVariable]. final String _name; @@ -1352,7 +1349,7 @@ class Cache { if (!_isLate) { // To avoid closurizing initializers we always inline the initializer // unless it is not a late variable. - VariableDeclaration? variable = _variable; + Variable? variable = _variable; if (variable == null) { variable = _variable = createVariableCache( @@ -1378,8 +1375,8 @@ class Cache { } else { assert(_isLate, "Unexpected non-late cache ${cacheKey.name}"); - VariableDeclaration? variable = _variable; - VariableDeclaration? isSetVariable = _isSetVariable; + Variable? variable = _variable; + Variable? isSetVariable = _isSetVariable; if (variable == null) { DartType? cacheType; for (CacheExpression expression in _accesses.values) { diff --git a/pkg/front_end/lib/src/type_inference/matching_expressions.dart b/pkg/front_end/lib/src/type_inference/matching_expressions.dart index 0ae0f83370d..0f4960b97dc 100644 --- a/pkg/front_end/lib/src/type_inference/matching_expressions.dart +++ b/pkg/front_end/lib/src/type_inference/matching_expressions.dart @@ -902,9 +902,7 @@ class MatchingExpressionVisitor fileOffset: node.fileOffset, ); } - VariableDeclaration target = matchingCache.getUnaliasedVariable( - node.variable, - ); + Variable target = matchingCache.getUnaliasedVariable(node.variable); // TODO(johnniwinther): Avoid hoisting variables for irrefutable tails. target.isHoisted = true; CacheableExpression valueExpression = new PromotedCacheableExpression( diff --git a/pkg/front_end/lib/src/type_inference/shared_type_analyzer.dart b/pkg/front_end/lib/src/type_inference/shared_type_analyzer.dart index 0257d10a162..0b36de6e755 100644 --- a/pkg/front_end/lib/src/type_inference/shared_type_analyzer.dart +++ b/pkg/front_end/lib/src/type_inference/shared_type_analyzer.dart @@ -22,7 +22,7 @@ class SharedTypeAnalyzerErrors TreeNode, Statement, Expression, - VariableDeclaration, + Variable, Pattern, InvalidExpression > { @@ -74,7 +74,7 @@ class SharedTypeAnalyzerErrors @override InvalidExpression duplicateAssignmentPatternVariable({ - required VariableDeclaration variable, + required Variable variable, required Pattern original, required Pattern duplicate, }) { @@ -154,8 +154,8 @@ class SharedTypeAnalyzerErrors @override void inconsistentJoinedPatternVariable({ - required VariableDeclaration variable, - required VariableDeclaration component, + required Variable variable, + required Variable component, }) { // TODO(johnniwinther): How should we handle errors that are not report // here? Should we have a sentinel error node, allow a nullable result, or ? 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 03aab4202d1..88881246dca 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< - VariableDeclaration, + Variable, TypeDeclarationType, TypeDeclaration, TreeNode > with shared.TypeConstraintGeneratorMixin< - VariableDeclaration, + Variable, 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 02a094d95e2..134ec9fe7e6 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 @@ -381,14 +381,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, ); } @@ -417,11 +417,7 @@ class TypeInferenceEngineImpl extends TypeInferenceEngine { // TODO(cstefantsova): Merge with [TypeInferenceResultForTesting]. class InferenceDataForTesting - extends - shared.TypeConstraintGenerationDataForTesting< - VariableDeclaration, - TreeNode - > { + extends shared.TypeConstraintGenerationDataForTesting { final FlowAnalysisResult flowAnalysisResult = new FlowAnalysisResult(); final TypeInferenceResultForTesting typeInferenceResult = @@ -452,7 +448,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. @@ -467,14 +463,14 @@ class FlowAnalysisResult { class OperationsCfe with TypeAnalyzerOperationsMixin< - VariableDeclaration, + Variable, TypeDeclarationType, TypeDeclaration, TreeNode > implements TypeAnalyzerOperations< - VariableDeclaration, + Variable, TypeDeclarationType, TypeDeclaration, TreeNode @@ -601,7 +597,7 @@ class OperationsCfe bool isExtensionTypeInternal(DartType type) => type is ExtensionType; @override - bool isFinal(VariableDeclaration variable) { + bool isFinal(Variable variable) { return variable.isFinal; } @@ -689,7 +685,7 @@ class OperationsCfe } @override - SharedTypeView variableType(VariableDeclaration variable) { + SharedTypeView variableType(Variable 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. @@ -778,7 +774,7 @@ class OperationsCfe } @override - bool isVariableFinal(VariableDeclaration node) { + bool isVariableFinal(Variable node) { return node.isFinal; } @@ -1103,7 +1099,7 @@ class OperationsCfe @override TypeConstraintGenerator< - VariableDeclaration, + Variable, TypeDeclarationType, TypeDeclaration, TreeNode @@ -1190,11 +1186,7 @@ class OperationsCfe /// Type inference results used for testing. class TypeInferenceResultForTesting - extends - shared.TypeConstraintGenerationDataForTesting< - VariableDeclaration, - TreeNode - > { + extends shared.TypeConstraintGenerationDataForTesting { 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 e2f07d93dae..b0ecfb27219 100644 --- a/pkg/front_end/lib/src/type_inference/type_inferrer.dart +++ b/pkg/front_end/lib/src/type_inference/type_inferrer.dart @@ -41,8 +41,7 @@ abstract class TypeInferrer { ExtensionScope get extensionScope; /// Returns the [FlowAnalysis] used during inference. - FlowAnalysis - get flowAnalysis; + FlowAnalysis get flowAnalysis; AssignedVariablesImpl get assignedVariables; @@ -66,7 +65,7 @@ abstract class TypeInferrer { required DartType returnType, required AsyncModifier asyncModifier, required Statement body, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -79,7 +78,7 @@ abstract class TypeInferrer { required Uri fileUri, required ConstructorContext constructorContext, required Initializer initializer, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -125,7 +124,7 @@ class TypeInferrerImpl implements TypeInferrer { TypeAnalyzerOptions typeAnalyzerOptions; @override - late final FlowAnalysis + late final FlowAnalysis flowAnalysis = new FlowAnalysis( operations, assignedVariables, @@ -261,7 +260,7 @@ class TypeInferrerImpl implements TypeInferrer { required DartType returnType, required AsyncModifier asyncModifier, required Statement body, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -336,14 +335,14 @@ class TypeInferrerImpl implements TypeInferrer { if (isClosureContextLoweringEnabled) { scopeProviderInfo = visitor.beginFunctionBodyInference( [ - for (VariableDeclaration positionalParameter + for (Variable positionalParameter in redirectingFactoryFunction.positionalParameters) new InternalPositionalParameter( astVariable: positionalParameter as PositionalParameter, isImplicitlyTyped: false, fileOffset: positionalParameter.fileOffset, ), - for (VariableDeclaration namedParameter + for (Variable namedParameter in redirectingFactoryFunction.namedParameters) new InternalNamedParameter( astVariable: namedParameter as NamedParameter, @@ -358,7 +357,7 @@ class TypeInferrerImpl implements TypeInferrer { List arguments = []; int positionalCount = 0; - for (VariableDeclaration parameter + for (Variable parameter in redirectingFactoryFunction.positionalParameters) { flowAnalysis.declare( parameter, @@ -384,8 +383,7 @@ class TypeInferrerImpl implements TypeInferrer { arguments.add(new PositionalArgument(variableGet)); positionalCount++; } - for (VariableDeclaration parameter - in redirectingFactoryFunction.namedParameters) { + for (Variable parameter in redirectingFactoryFunction.namedParameters) { flowAnalysis.declare( parameter, new SharedTypeView(parameter.type), @@ -448,7 +446,7 @@ class TypeInferrerImpl implements TypeInferrer { required Uri fileUri, required ConstructorContext constructorContext, required Initializer initializer, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -554,8 +552,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; @@ -587,7 +585,7 @@ class TypeInferrerImplBenchmarked implements TypeInferrer { required DartType returnType, required AsyncModifier asyncModifier, required Statement body, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -617,7 +615,7 @@ class TypeInferrerImplBenchmarked implements TypeInferrer { required Uri fileUri, required ConstructorContext constructorContext, required Initializer initializer, - required List parameters, + required List parameters, required ThisVariable? internalThisVariable, required ScopeProviderInfo? scopeProviderInfo, required ContextAllocationStrategy contextAllocationStrategy, @@ -740,5 +738,5 @@ abstract class ConstructorContext { FunctionSignature get signature; /// The variable used for `this`, if any. - VariableDeclaration? get thisVariable; + Variable? get thisVariable; } 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 fb64e0f5508..e5ea75fac2b 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,12 +20,11 @@ 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< - VariableDeclaration, + Variable, TypeDeclarationType, TypeDeclaration, TreeNode @@ -33,7 +32,7 @@ typedef MergedTypeConstraint = typedef UnknownTypeConstraintOrigin = shared.UnknownTypeConstraintOrigin< - VariableDeclaration, + Variable, TypeDeclarationType, TypeDeclaration, TreeNode diff --git a/pkg/front_end/test/comments_on_certain_arguments_tool.dart b/pkg/front_end/test/comments_on_certain_arguments_tool.dart index b7f1b5fb382..fde8302332a 100644 --- a/pkg/front_end/test/comments_on_certain_arguments_tool.dart +++ b/pkg/front_end/test/comments_on_certain_arguments_tool.dart @@ -215,7 +215,7 @@ class InvocationVisitor extends RecursiveVisitor { Arguments arguments, InvocationExpression invocation, ) { - List positionalParameters; + List positionalParameters; if (node is Procedure) { positionalParameters = node.function.positionalParameters; } else if (node is Constructor) { @@ -288,7 +288,7 @@ Map cache = {}; void check( Expression argumentExpression, - VariableDeclaration parameter, + Variable parameter, NamedNode targetNode, String expectedComment, ) { diff --git a/pkg/front_end/test/compiler_test_helper.dart b/pkg/front_end/test/compiler_test_helper.dart index d2bc83046f7..041661efb71 100644 --- a/pkg/front_end/test/compiler_test_helper.dart +++ b/pkg/front_end/test/compiler_test_helper.dart @@ -292,7 +292,7 @@ class BodyBuilderTest extends BodyBuilderImpl { LocalScope? formalParameterScope, required ClassHierarchy hierarchy, required CoreTypes coreTypes, - VariableDeclaration? thisVariable, + Variable? thisVariable, List? thisTypeParameters, required Uri uri, required AssignedVariablesImpl assignedVariables, diff --git a/pkg/front_end/test/dart_scope_calculator_test.dart b/pkg/front_end/test/dart_scope_calculator_test.dart index 5558d3f7b7f..1dfbe8e4798 100644 --- a/pkg/front_end/test/dart_scope_calculator_test.dart +++ b/pkg/front_end/test/dart_scope_calculator_test.dart @@ -269,7 +269,7 @@ class ScopeTestingBinaryPrinter extends BinaryPrinter { currentUri = prevUri; } - Set setVariables = {}; + Set setVariables = {}; @override void visitVariableSet(VariableSet node) { @@ -377,7 +377,7 @@ class ScopeTestingBinaryPrinter extends BinaryPrinter { VariableIndexer2? varIndexer = getVariableIndexerForTesting() as VariableIndexer2?; Map expectedVariablesMap = {}; - for (VariableDeclaration variable in varIndexer?.declsOrder ?? const []) { + for (Variable variable in varIndexer?.declsOrder ?? const []) { String? name = variable.name; if (name != null && name != "" && !variable.isSynthesized) { if (variable.isHoisted && !setVariables.contains(variable)) { @@ -586,7 +586,7 @@ class ScopeTestingBinaryPrinter extends BinaryPrinter { } @override - void writeVariableDeclaration(VariableDeclaration node) { + void writeVariableDeclaration(Variable node) { bool oldCheckOffset = checkOffset; checkOffset = true; super.writeVariableDeclaration(node); @@ -595,23 +595,23 @@ class ScopeTestingBinaryPrinter extends BinaryPrinter { } class VariableIndexer2 implements VariableIndexer { - List declsOrder = []; - List declsOrderPopped = []; + List declsOrder = []; + List declsOrderPopped = []; @override - Map? index; + Map? index; @override List? scopes; @override int stackHeight = 0; @override - int? operator [](VariableDeclaration node) { + int? operator [](Variable node) { return index == null ? null : index![node]; } @override - void declare(VariableDeclaration node) { - (index ??= {})[node] = stackHeight++; + void declare(Variable node) { + (index ??= {})[node] = stackHeight++; declsOrder.add(node); } diff --git a/pkg/front_end/test/expression_suite.dart b/pkg/front_end/test/expression_suite.dart index c1884ce43fc..f813f9053bc 100644 --- a/pkg/front_end/test/expression_suite.dart +++ b/pkg/front_end/test/expression_suite.dart @@ -41,7 +41,7 @@ import "package:kernel/ast.dart" Procedure, TreeNode, TypeParameter, - VariableDeclaration; + Variable; import 'package:kernel/target/targets.dart' show TargetFlags; import 'package:kernel/text/ast_to_text.dart' show Printer; import "package:testing/src/log.dart" show splitLines; @@ -222,7 +222,7 @@ class OutputParametersMatches fail(tests, "Compiled expression contains named parameters."), ); } - List positionals = + List positionals = compiledProcedure.function.positionalParameters; if (positionals.length != test.definitions.length) { return Future.value( diff --git a/pkg/front_end/test/generator_to_string_test.dart b/pkg/front_end/test/generator_to_string_test.dart index 28c892d2ec4..9bd06f4bb87 100644 --- a/pkg/front_end/test/generator_to_string_test.dart +++ b/pkg/front_end/test/generator_to_string_test.dart @@ -50,7 +50,7 @@ import 'package:kernel/ast.dart' ProcedureKind, StringLiteral, TypeParameter, - VariableDeclaration, + Variable, VariableGet, defaultLanguageVersion; import 'package:kernel/class_hierarchy.dart'; @@ -82,10 +82,8 @@ Future main() async { hasNamedBeforePositional: false, positionalCount: 1, ); - Expression expression = new VariableGet( - new VariableDeclaration("expression"), - ); - Expression index = new VariableGet(new VariableDeclaration("index")); + Expression expression = new VariableGet(new Variable("expression")); + Expression index = new VariableGet(new Variable("index")); UriTranslator uriTranslator = await c.options.getUriTranslator(); SourceLoader loader = new KernelTarget( c, @@ -179,10 +177,7 @@ Future main() async { new TypeParameter("T", const DynamicType(), const DynamicType()), loader: null, ); - VariableDeclaration variable = new VariableDeclaration( - null, - isSynthesized: true, - ); + Variable variable = new Variable(null, isSynthesized: true); TypeInferenceEngineImpl engine = new TypeInferenceEngineImpl(); engine.prepareTopLevel(coreTypes, hierarchy); 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 f9c4f1a10e9..130650ab366 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,8 +72,7 @@ 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/inferred_variable_types_test.dart b/pkg/front_end/test/id_tests/inferred_variable_types_test.dart index 8134f42c740..d5aa1aa92c8 100644 --- a/pkg/front_end/test/id_tests/inferred_variable_types_test.dart +++ b/pkg/front_end/test/id_tests/inferred_variable_types_test.dart @@ -75,7 +75,7 @@ class InferredTypeArgumentDataExtractor extends CfeDataExtractor { @override DartType? computeNodeValue(Id id, TreeNode node) { - if (node is VariableDeclaration || node is LocalFunction) { + if (node is Variable || node is LocalFunction) { return typeInferenceResult.inferredVariableTypes[node]; } return null; diff --git a/pkg/front_end/test/member_covariance_test.dart b/pkg/front_end/test/member_covariance_test.dart index 240859f14a5..92ba7912572 100644 --- a/pkg/front_end/test/member_covariance_test.dart +++ b/pkg/front_end/test/member_covariance_test.dart @@ -133,9 +133,7 @@ void main() { ProcedureKind.Method, new FunctionNode( null, - positionalParameters: [ - new VariableDeclaration(null, isSynthesized: true), - ], + positionalParameters: [new Variable(null, isSynthesized: true)], ), fileUri: dummyUri, ); @@ -162,11 +160,11 @@ void main() { new FunctionNode( null, positionalParameters: [ - new VariableDeclaration(null, isSynthesized: true), - new VariableDeclaration(null, isSynthesized: true), - new VariableDeclaration(null, isSynthesized: true), - new VariableDeclaration(null, isSynthesized: true), - new VariableDeclaration(null, isSynthesized: true), + new Variable(null, isSynthesized: true), + new Variable(null, isSynthesized: true), + new Variable(null, isSynthesized: true), + new Variable(null, isSynthesized: true), + new Variable(null, isSynthesized: true), ], ), fileUri: dummyUri, @@ -204,11 +202,11 @@ void main() { new FunctionNode( null, namedParameters: [ - new VariableDeclaration('a'), - new VariableDeclaration('b'), - new VariableDeclaration('c'), - new VariableDeclaration('d'), - new VariableDeclaration('e'), + new Variable('a'), + new Variable('b'), + new Variable('c'), + new Variable('d'), + new Variable('e'), ], ), fileUri: dummyUri, diff --git a/pkg/front_end/test/predicates/predicate_test.dart b/pkg/front_end/test/predicates/predicate_test.dart index e45e47438ba..157a18dc885 100644 --- a/pkg/front_end/test/predicates/predicate_test.dart +++ b/pkg/front_end/test/predicates/predicate_test.dart @@ -215,7 +215,7 @@ class PredicateDataExtractor extends CfeDataExtractor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { Object? identity; String? name; String? tag; @@ -257,7 +257,7 @@ class PredicateDataExtractor extends CfeDataExtractor { features[Tags.name] = name; } } - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override diff --git a/pkg/front_end/test/static_types/static_type_test.dart b/pkg/front_end/test/static_types/static_type_test.dart index b2355eb368b..ad49cd42ac0 100644 --- a/pkg/front_end/test/static_types/static_type_test.dart +++ b/pkg/front_end/test/static_types/static_type_test.dart @@ -161,7 +161,7 @@ class StaticTypeDataExtractor extends CfeDataExtractor { object is BlockExpression || (object is NullLiteral && // Skip implicit initializers/default values. - (object.parent is VariableDeclaration || object.parent is Field) && + (object.parent is Variable || object.parent is Field) && object.fileOffset == object.parent?.fileOffset); @override 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 dcd21e9e48a..9ac0793cb8b 100644 --- a/pkg/front_end/test/static_types/type_arguments_test.dart +++ b/pkg/front_end/test/static_types/type_arguments_test.dart @@ -93,7 +93,7 @@ class TypeArgumentsVisitor extends VerifyingAnalysis { typeArgument, variableStatementType, )) { - // [VariableDeclaration] is used as an exclusive member of, for + // [Variable] is used as an exclusive member of, for // instance, `FunctionNode.positionalParameters`. if (typeArgument != variableStatementType) { registerError( diff --git a/pkg/front_end/test/text_representation/internal_ast_text_representation_test.dart b/pkg/front_end/test/text_representation/internal_ast_text_representation_test.dart index a1524db2abe..9d022384db0 100644 --- a/pkg/front_end/test/text_representation/internal_ast_text_representation_test.dart +++ b/pkg/front_end/test/text_representation/internal_ast_text_representation_test.dart @@ -47,7 +47,7 @@ void testStatement( } void testVariableDeclaration( - VariableDeclaration node, + Variable node, String normal, { String? verbose, String? limited, @@ -224,20 +224,16 @@ void main() { void _testVariableDeclarations() { testStatement( forest.variablesDeclaration([ - new VariableStatement(new VariableDeclaration('a')), - new VariableStatement(new VariableDeclaration('b')), + new VariableStatement(new Variable('a')), + new VariableStatement(new Variable('b')), ], dummyUri), ''' dynamic a, b;''', ); testStatement( forest.variablesDeclaration([ - new VariableStatement( - new VariableDeclaration('a', type: const VoidType()), - ), - new VariableStatement( - new VariableDeclaration('b', initializer: new NullLiteral()), - ), + new VariableStatement(new Variable('a', type: const VoidType())), + new VariableStatement(new Variable('b', initializer: new NullLiteral())), ], dummyUri), ''' void a, b = null;''', @@ -249,21 +245,18 @@ void _testTryStatement() { Block emptyBlock2 = new Block([]); Block returnBlock1 = new Block([new ReturnStatement()]); Block returnBlock2 = new Block([new ReturnStatement()]); - Catch emptyCatchBlock = new Catch( - new VariableDeclaration('e'), - new Block([]), - ); + Catch emptyCatchBlock = new Catch(new Variable('e'), new Block([])); Catch emptyCatchBlockOnVoid = new Catch( - new VariableDeclaration('e'), + new Variable('e'), new Block([]), guard: const VoidType(), ); Catch returnCatchBlock = new Catch( - new VariableDeclaration('e'), + new Variable('e'), new Block([new ReturnStatement()]), ); Catch returnCatchBlockOnVoid = new Catch( - new VariableDeclaration('e'), + new Variable('e'), new Block([new ReturnStatement()]), guard: const VoidType(), ); @@ -827,9 +820,7 @@ continue label0;''', } void _testCascade() { - VariableDeclaration variable = new VariableDeclaration.forValue( - new IntLiteral(0), - ); + Variable variable = new Variable.forValue(new IntLiteral(0)); Cascade cascade = new Cascade(variable, isNullAware: false); testExpression(cascade, ''' let final dynamic #0 = 0 in cascade {} => #0'''); @@ -878,9 +869,7 @@ void _testDeferredCheck() { library, 'pre', ); - VariableDeclaration check = new VariableDeclaration.forValue( - new CheckLibraryIsLoaded(dependency), - ); + Variable check = new Variable.forValue(new CheckLibraryIsLoaded(dependency)); testExpression( new DeferredCheck(check, new IntLiteral(0), fileOffset: TreeNode.noOffset), ''' @@ -1601,7 +1590,7 @@ void _testIfNullPropertySet() { } void _testIfNullSet() { - VariableDeclaration variable = new VariableDeclaration('foo'); + Variable variable = new Variable('foo'); testExpression( new IfNullSet( new VariableGet(variable), diff --git a/pkg/front_end/test/text_representation/text_representation_test.dart b/pkg/front_end/test/text_representation/text_representation_test.dart index 0385bf10bc8..3c194df7da4 100644 --- a/pkg/front_end/test/text_representation/text_representation_test.dart +++ b/pkg/front_end/test/text_representation/text_representation_test.dart @@ -187,7 +187,7 @@ class TextRepresentationDataExtractor extends CfeDataExtractor { String? computeNodeValue(Id id, TreeNode node) { if (node is ConstantExpression) { return node.constant.toText(strategy); - } else if (node is VariableDeclaration) { + } else if (node is Variable) { DartType type = node.type; return type.toText(strategy); } @@ -199,13 +199,12 @@ class TextRepresentationDataExtractor extends CfeDataExtractor { ActualData value1, ActualData value2, ) { - // Prefer [VariableDeclaration] over [ConstantExpression]. This is done to + // Prefer [Variable] over [ConstantExpression]. This is done to // avoid conflict between a parameter and its implicit initializer. - if (value1.object is ConstantExpression && - value2.object is VariableDeclaration) { + if (value1.object is ConstantExpression && value2.object is Variable) { return value2; } else if (value2.object is ConstantExpression && - value1.object is VariableDeclaration) { + value1.object is Variable) { return value1; } return super.mergeData(value1, value2); diff --git a/pkg/front_end/tool/ast_model.dart b/pkg/front_end/tool/ast_model.dart index 22137998ec4..a0f303b4645 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 { - // TODO(johnniwinther): This should be [VariableDeclaration]. + // TODO(johnniwinther): This should be [Variable]. 'LegacyVariable': 'name', 'TypeParameter': 'name', 'StructuralParameter': 'name', @@ -64,7 +64,7 @@ const Set _interchangeableClasses = const { 'DartType', 'Initializer', 'Pattern', - 'VariableDeclaration', + 'Variable', }; /// Names of subclasses of [NamedNode] that do _not_ have a `visitXReference` @@ -254,7 +254,7 @@ enum AstClassKind { /// A node class that declares a nominal entity but used without reference. /// - /// For instance [VariableDeclaration] which introduces a new entity when it + /// For instance [Variable] which introduces a new entity when it /// occurs in a [Block] but is used as a reference when it occurs in a /// [VariableGet]. declarative, @@ -399,7 +399,7 @@ enum AstFieldKind { /// A reference to a declarative [Node]. /// - /// For instance the reference to [VariableDeclaration] in [VariableGet]. + /// For instance the reference to [Variable] in [VariableGet]. use, /// A list of values. diff --git a/pkg/front_end/tool/unreachable_if_finder.dart b/pkg/front_end/tool/unreachable_if_finder.dart index 94cf0e64db3..bdeb5b04357 100644 --- a/pkg/front_end/tool/unreachable_if_finder.dart +++ b/pkg/front_end/tool/unreachable_if_finder.dart @@ -48,13 +48,13 @@ class UnreachableIfFinder extends RecursiveVisitor { return unreachableIfFinder.warnings; } - final Set unwritten; + final Set unwritten; UnreachableIfFinder._(this.unwritten); 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`. - VariableDeclaration? newKnownValueHere; + Variable? newKnownValueHere; bool conditionNegated = false; if (condition is Not) { @@ -123,14 +123,14 @@ class UnreachableIfFinder extends RecursiveVisitor { } class EffectivelyFinal extends RecursiveVisitor { - final Set unwritten = {}; + final Set unwritten = {}; EffectivelyFinal._(); @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { unwritten.add(node); - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart index 61637e5bca1..9c80e1039f1 100644 --- a/pkg/kernel/lib/binary/ast_from_binary.dart +++ b/pkg/kernel/lib/binary/ast_from_binary.dart @@ -132,7 +132,7 @@ bool _lateIsInitialized(dynamic value) { } class BinaryBuilder { - final List variableStack = []; + final List variableStack = []; final List labelStack = []; int labelStackBase = 0; int switchCaseStackBase = 0; @@ -2124,8 +2124,8 @@ class BinaryBuilder { readUInt30(); // total parameter count. int requiredParameterCount = readUInt30(); int variableStackHeight = variableStack.length; - List positional = readAndPushVariableDeclarationList(); - List named = readAndPushVariableDeclarationList(); + List positional = readAndPushVariableDeclarationList(); + List named = readAndPushVariableDeclarationList(); DartType returnType = readDartType(); DartType? futureValueType = readDartTypeOption(); RedirectingFactoryTarget? redirectingFactoryTarget; @@ -2210,7 +2210,7 @@ class BinaryBuilder { final List typeParameters = typeParameterStack .cast() .toList(); - final List variables = variableStack.toList(); + final List variables = variableStack.toList(); final Library currentLibrary = _currentLibrary!; result.lazyBuilder = () { _byteOffset = savedByteOffset; @@ -2234,20 +2234,20 @@ class BinaryBuilder { }; } - void pushVariableDeclaration(VariableDeclaration variable) { + void pushVariableDeclaration(Variable variable) { variableStack.add(variable); } - void pushVariableDeclarations(List variables) { + void pushVariableDeclarations(List variables) { variableStack.addAll(variables); } - VariableDeclaration readVariableReference() { + Variable readVariableReference() { readUInt30(); // offset of the variable declaration in the binary. return _readVariableReferenceInternal(); } - VariableDeclaration _readVariableReferenceInternal() { + Variable _readVariableReferenceInternal() { int index = readUInt30(); if (index >= variableStack.length) { throw fail( @@ -2763,7 +2763,7 @@ class BinaryBuilder { Expression _readLocalFunctionInvocation() { int offset = readOffset(); - VariableDeclaration variable = readVariableReference(); + Variable variable = readVariableReference(); return new LocalFunctionInvocation( variable, readArguments(), @@ -3146,7 +3146,7 @@ class BinaryBuilder { Expression _readLet() { int offset = readOffset(); - VariableDeclaration variable = readVariableDeclaration(); + Variable variable = readVariableDeclaration(); int stackHeight = variableStack.length; pushVariableDeclaration(variable); Expression body = readExpression(); @@ -3279,14 +3279,14 @@ class BinaryBuilder { ); } - List _readVariableReferenceList() { + List _readVariableReferenceList() { int length = readUInt30(); if (!useGrowableLists && length == 0) { // When lists don't have to be growable anyway, we might as well use an // almost constant one for the empty list. return emptyListOfVariableDeclaration; } - return new List.generate( + return new List.generate( length, (_) => readVariableReference(), growable: useGrowableLists, @@ -3315,7 +3315,7 @@ class BinaryBuilder { AssignedVariablePattern _readAssignedVariablePattern() { int fileOffset = readOffset(); - VariableDeclaration variable = readVariableReference(); + Variable variable = readVariableReference(); DartType? matchedType = readDartTypeOption(); bool needsCheck = readByte() == 1; return AssignedVariablePattern(variable) @@ -3346,8 +3346,7 @@ class BinaryBuilder { InvalidPattern _readInvalidPattern() { int fileOffset = readOffset(); Expression invalidExpression = readExpression(); - List declaredVariables = - readAndPushVariableDeclarationList(); + List declaredVariables = readAndPushVariableDeclarationList(); return InvalidPattern( invalidExpression, declaredVariables: declaredVariables, @@ -3472,8 +3471,7 @@ class BinaryBuilder { int fileOffset = readOffset(); Pattern left = _readPattern(); Pattern right = _readPattern(); - List orPatternJointVariables = - _readVariableReferenceList(); + List orPatternJointVariables = _readVariableReferenceList(); return new OrPattern( left, right, @@ -3530,7 +3528,7 @@ class BinaryBuilder { VariablePattern _readVariablePattern() { int fileOffset = readOffset(); DartType? type = readDartTypeOption(); - VariableDeclaration variable = readVariableDeclaration(); + Variable variable = readVariableDeclaration(); DartType? matchedType = readDartTypeOption(); return new VariablePattern(type, variable) ..matchedValueType = matchedType @@ -3840,7 +3838,7 @@ class BinaryBuilder { int variableStackHeight = variableStack.length; int offset = readOffset(); int bodyOffset = readOffset(); - VariableDeclaration variable = readAndPushVariableDeclaration(); + Variable variable = readAndPushVariableDeclaration(); Expression iterable = readExpression(); Statement body = readStatement(); variableStack.length = variableStackHeight; @@ -3932,19 +3930,19 @@ class BinaryBuilder { } VariableStatement _readVariableStatement() { - VariableDeclaration variable = _readVariableDeclaration(); + Variable variable = _readVariableDeclaration(); return new VariableStatement(variable)..fileOffset = variable.fileOffset; } - VariableDeclaration _readVariableDeclaration() { - VariableDeclaration variable = readVariableDeclaration(); + Variable _readVariableDeclaration() { + Variable variable = readVariableDeclaration(); variableStack.add(variable); // Will be popped by the enclosing scope. return variable; } Statement _readFunctionDeclaration() { int offset = readOffset(); - VariableDeclaration variable = readVariableDeclaration(); + Variable variable = readVariableDeclaration(); variableStack.add(variable); // Will be popped by the enclosing scope. final LocalFunctionId id = LocalFunctionId(readUInt30()); return new FunctionDeclaration(variable, readFunctionNode()) @@ -3982,8 +3980,8 @@ class BinaryBuilder { int variableStackHeight = variableStack.length; int offset = readOffset(); DartType guard = readDartType(); - VariableDeclaration? exception = readAndPushVariableDeclarationOption(); - VariableDeclaration? stackTrace = readAndPushVariableDeclarationOption(); + Variable? exception = readAndPushVariableDeclarationOption(); + Variable? stackTrace = readAndPushVariableDeclarationOption(); Statement body = readStatement(); variableStack.length = variableStackHeight; return new Catch(exception, body, guard: guard, stackTrace: stackTrace) @@ -4433,7 +4431,7 @@ class BinaryBuilder { } List readAndPushVariableStatementList() { - List list = readAndPushVariableDeclarationList(); + List list = readAndPushVariableDeclarationList(); return new List.generate( list.length, (int index) => @@ -4442,39 +4440,39 @@ class BinaryBuilder { ); } - List readAndPushVariableDeclarationList() { + List readAndPushVariableDeclarationList() { int length = readUInt30(); if (!useGrowableLists && length == 0) { // When lists don't have to be growable anyway, we might as well use an // almost constant one for the empty list. return emptyListOfVariableDeclaration; } - return new List.generate( + return new List.generate( length, (_) => readAndPushVariableDeclaration(), growable: useGrowableLists, ); } - VariableDeclaration? readAndPushVariableDeclarationOption() { + Variable? readAndPushVariableDeclarationOption() { return readAndCheckOptionTag() ? readAndPushVariableDeclaration() : null; } - VariableDeclaration readAndPushVariableDeclaration() { - VariableDeclaration variable = readVariableDeclaration(); + Variable readAndPushVariableDeclaration() { + Variable variable = readVariableDeclaration(); variableStack.add(variable); return variable; } - VariableDeclaration readVariableDeclaration() { + Variable readVariableDeclaration() { int offset = readOffset(); int fileEqualsOffset = readOffset(); // The [VariableDeclaration] instance is not created at this point yet, // so `null` is temporarily set as the parent of the annotation nodes. List annotations = readAnnotationList(null); int flags = readUInt30(); - VariableDeclaration node = - new VariableDeclaration( + Variable node = + new Variable( readStringOrNullIfEmpty(), type: readDartType(), initializer: readExpressionOption(), @@ -4759,10 +4757,10 @@ class BinaryBuilderWithMetadata extends BinaryBuilder implements BinarySource { } @override - VariableDeclaration readVariableDeclaration() { + Variable readVariableDeclaration() { final int nodeOffset = _byteOffset; final bool hasMetadata = _hasMetadata(_byteOffset); - final VariableDeclaration result = super.readVariableDeclaration(); + final Variable result = super.readVariableDeclaration(); return hasMetadata ? _associateMetadata(result, nodeOffset) : result; } diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart index 6385f2343d6..534507b533f 100644 --- a/pkg/kernel/lib/binary/ast_to_binary.dart +++ b/pkg/kernel/lib/binary/ast_to_binary.dart @@ -89,7 +89,7 @@ class BinaryPrinter _sink.flushAndDestroy(); } - int _getVariableIndex(VariableDeclaration variable) { + int _getVariableIndex(Variable variable) { int? index = (_variableIndexer ??= _newVariableIndexer())[variable]; assert(index != null, "No index found for ${variable}"); return index!; @@ -2476,7 +2476,7 @@ class BinaryPrinter } @override - void visitVariableDeclaration(VariableDeclaration node) { + void visitVariable(Variable node) { writeByte(Tag.VariableDeclaration); writeVariableDeclaration(node); } @@ -2485,7 +2485,7 @@ class BinaryPrinter writeVariableDeclaration(node.variable); } - void writeVariableDeclaration(VariableDeclaration node) { + void writeVariableDeclaration(Variable node) { if (_metadataSubsections != null) { _writeNodeMetadata(node); } @@ -2506,11 +2506,11 @@ class BinaryPrinter writeList(nodes, writeVariableStatement); } - void writeVariableDeclarationList(List nodes) { + void writeVariableDeclarationList(List nodes) { writeList(nodes, writeVariableDeclaration); } - void writeOptionalVariableDeclaration(VariableDeclaration? node) { + void writeOptionalVariableDeclaration(Variable? node) { if (node == null) { writeByte(Tag.Nothing); } else { @@ -2800,7 +2800,7 @@ class BinaryPrinter writeNode(node.receiver); } - void _writeVariableReference(VariableDeclaration variable) { + void _writeVariableReference(Variable variable) { int index = _getVariableIndex(variable); writeUInt30(variable.binaryOffsetNoTag); writeUInt30(index); @@ -3408,12 +3408,12 @@ class BinaryPrinter typedef bool LibraryFilter(Library _); class VariableIndexer { - Map? index; + Map? index; List? scopes; int stackHeight = 0; - void declare(VariableDeclaration node) { - (index ??= {})[node] = stackHeight++; + void declare(Variable node) { + (index ??= {})[node] = stackHeight++; } void pushScope() { @@ -3428,7 +3428,7 @@ class VariableIndexer { stackHeight += numberOfVariables; } - int? operator [](VariableDeclaration node) { + int? operator [](Variable node) { return index == null ? null : index![node]; } } diff --git a/pkg/kernel/lib/clone.dart b/pkg/kernel/lib/clone.dart index 907db1a5743..7eca6ccaf08 100644 --- a/pkg/kernel/lib/clone.dart +++ b/pkg/kernel/lib/clone.dart @@ -18,8 +18,7 @@ class CloneVisitorNotMembers ExpressionVisitorExperimentExclusionMixin, StatementVisitorExperimentExclusionMixin implements TreeVisitor { - final Map _variables = - {}; + final Map _variables = {}; final Map labels = {}; final Map switchCases = {}; @@ -52,17 +51,14 @@ class CloneVisitorNotMembers /// Returns the clone of [variable] or `null` if no clone has been created /// for variable. - VariableDeclaration? getVariableClone(VariableDeclaration variable) { + Variable? getVariableClone(Variable variable) { return _variables[variable]; } /// Registers [clone] as the clone for [variable]. /// /// Returns the [clone]. - VariableDeclaration setVariableClone( - VariableDeclaration variable, - VariableDeclaration clone, - ) { + Variable setVariableClone(Variable variable, Variable clone) { return _variables[variable] = clone; } @@ -201,14 +197,14 @@ class CloneVisitorNotMembers @override TreeNode visitVariableGet(VariableGet node) { - VariableDeclaration? variable = getVariableClone(node.variable); + Variable? variable = getVariableClone(node.variable); assert(variable != null, "Missing clone for variable ${node.variable}."); return new VariableGet(variable!, visitOptionalType(node.promotedType)); } @override TreeNode visitVariableSet(VariableSet node) { - VariableDeclaration? variable = getVariableClone(node.variable); + Variable? variable = getVariableClone(node.variable); assert(variable != null, "Missing clone for variable ${node.variable}."); return new VariableSet(variable!, clone(node.value)); } @@ -524,7 +520,7 @@ class CloneVisitorNotMembers @override TreeNode visitLet(Let node) { - VariableDeclaration newVariable = clone(node.variable); + Variable newVariable = clone(node.variable); return new Let(newVariable, clone(node.body)); } @@ -618,7 +614,7 @@ class CloneVisitorNotMembers @override TreeNode visitForInStatement(ForInStatement node) { - VariableDeclaration newVariable = clone(node.variable); + Variable newVariable = clone(node.variable); return new ForInStatement( newVariable, clone(node.iterable), @@ -681,8 +677,8 @@ class CloneVisitorNotMembers @override TreeNode visitCatch(Catch node) { - VariableDeclaration? newException = cloneOptional(node.exception); - VariableDeclaration? newStackTrace = cloneOptional(node.stackTrace); + Variable? newException = cloneOptional(node.exception); + Variable? newStackTrace = cloneOptional(node.stackTrace); return new Catch( newException, clone(node.body), @@ -702,7 +698,7 @@ class CloneVisitorNotMembers } @override - TreeNode visitVariableDeclaration(VariableDeclaration node) { + TreeNode visitVariable(Variable node) { throw new UnimplementedError( "${this.runtimeType}.visitVariableDeclaration", ); @@ -832,7 +828,7 @@ class CloneVisitorNotMembers @override TreeNode visitFunctionDeclaration(FunctionDeclaration node) { - VariableDeclaration newVariable = clone(node.variable); + Variable newVariable = clone(node.variable); // Create the declaration before cloning the body to support recursive // [LocalFunctionInvocation] nodes. FunctionDeclaration declaration = new FunctionDeclaration( @@ -887,11 +883,9 @@ class CloneVisitorNotMembers List typeParameters = node.typeParameters .map(clone) .toList(); - List positional = node.positionalParameters - .map(clone) - .toList(); - List named = node.namedParameters.map(clone).toList(); - VariableDeclaration? thisVariable = cloneOptional(node.thisVariable); + List positional = node.positionalParameters.map(clone).toList(); + List named = node.namedParameters.map(clone).toList(); + Variable? thisVariable = cloneOptional(node.thisVariable); final DartType? futureValueType = node.emittedValueType != null ? visitType(node.emittedValueType!) : null; @@ -1626,8 +1620,8 @@ class CloneProcedureWithoutBody extends CloneVisitorWithMembers { Procedure cloneProcedureWith( Procedure node, Reference? reference, { - List? positionalParameters, - List? namedParameters, + List? positionalParameters, + List? namedParameters, }) { Procedure cloned = cloneProcedure(node, reference); if (positionalParameters != null) { diff --git a/pkg/kernel/lib/naive_type_checker.dart b/pkg/kernel/lib/naive_type_checker.dart index f6853e3bbf7..afd85d5ffde 100644 --- a/pkg/kernel/lib/naive_type_checker.dart +++ b/pkg/kernel/lib/naive_type_checker.dart @@ -233,10 +233,8 @@ ${ownType} is not a subtype of ${superType} } for (int i = 0; i < superFunction.positionalParameters.length; ++i) { - final VariableDeclaration ownParameter = - ownFunction.positionalParameters[i]; - final VariableDeclaration superParameter = - superFunction.positionalParameters[i]; + final Variable ownParameter = ownFunction.positionalParameters[i]; + final Variable superParameter = superFunction.positionalParameters[i]; if (!_isValidParameterOverride( ownSubstitution.substituteType(ownParameter.type), superSubstitution.substituteType(superParameter.type), @@ -257,14 +255,13 @@ super method declares ${superParameter.type} // Note: FunctionNode.namedParameters are not sorted so we convert them // to map to make lookup faster. - final Map ownParameters = - new Map.fromIterable( + final Map ownParameters = + new Map.fromIterable( ownFunction.namedParameters, key: (v) => v.name, ); - for (VariableDeclaration superParameter in superFunction.namedParameters) { - final VariableDeclaration? ownParameter = - ownParameters[superParameter.name]; + for (Variable superParameter in superFunction.namedParameters) { + final Variable? ownParameter = ownParameters[superParameter.name]; if (ownParameter == null) { return 'override is missing ${superParameter.name} parameter'; } diff --git a/pkg/kernel/lib/src/ast/dummies.dart b/pkg/kernel/lib/src/ast/dummies.dart index a1eb579e935..6207aa4b6c2 100644 --- a/pkg/kernel/lib/src/ast/dummies.dart +++ b/pkg/kernel/lib/src/ast/dummies.dart @@ -14,7 +14,7 @@ final List emptyListOfNamedExpression = List.filled( /// Almost const [], but not const in an attempt to avoid /// polymorphism. See https://dart-review.googlesource.com/c/sdk/+/185828. -final List emptyListOfVariableDeclaration = List.filled( +final List emptyListOfVariableDeclaration = List.filled( 0, dummyVariableDeclaration, growable: false, @@ -481,12 +481,12 @@ final VariableStatement dummyVariableStatement = new VariableStatement( dummyVariableDeclaration, ); -/// Non-nullable [VariableDeclaration] dummy value. +/// Non-nullable [Variable] dummy value. /// /// This is used as the removal sentinel in [RemovingTransformer] and can be /// used for instance as a dummy initial value for the `List.filled` /// constructor. -final VariableDeclaration dummyVariableDeclaration = new VariableDeclaration( +final Variable dummyVariableDeclaration = new Variable( null, isSynthesized: true, ); diff --git a/pkg/kernel/lib/src/ast/expressions.dart b/pkg/kernel/lib/src/ast/expressions.dart index c452998fe03..a7569d8f12c 100644 --- a/pkg/kernel/lib/src/ast/expressions.dart +++ b/pkg/kernel/lib/src/ast/expressions.dart @@ -202,7 +202,7 @@ class InvalidExpression extends Expression { class VariableGet extends Expression { /// The target variable. - VariableDeclaration variable; + Variable variable; /// Null if not promoted. DartType? promotedType; @@ -270,7 +270,7 @@ class VariableGet extends Expression { /// Evaluates to the value of [value]. class VariableSet extends Expression { /// The target variable. - VariableDeclaration variable; + Variable variable; Expression value; @@ -2335,7 +2335,7 @@ class FunctionInvocation extends InstanceInvocationExpression { /// An invocation of a local function declaration. class LocalFunctionInvocation extends InvocationExpression { /// The variable declaration for the function declaration. - VariableDeclaration variable; + Variable variable; @override Arguments arguments; @@ -5150,7 +5150,7 @@ class FileUriConstantExpression extends ConstantExpression /// Synthetic expression of form `let v = x in y` class Let extends Expression { - VariableDeclaration variable; // Must have an initializer. + Variable variable; // Must have an initializer. Expression body; Let(this.variable, this.body) { diff --git a/pkg/kernel/lib/src/ast/functions.dart b/pkg/kernel/lib/src/ast/functions.dart index 44181fbdd77..0cb22c3f0a3 100644 --- a/pkg/kernel/lib/src/ast/functions.dart +++ b/pkg/kernel/lib/src/ast/functions.dart @@ -39,9 +39,9 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer { List typeParameters; int requiredParameterCount; - List positionalParameters; - List namedParameters; - VariableDeclaration? thisVariable; + List positionalParameters; + List namedParameters; + Variable? thisVariable; DartType returnType; // Not null. Statement? _body; @@ -104,19 +104,18 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer { FunctionNode( this._body, { List? typeParameters, - List? positionalParameters, - List? namedParameters, + List? positionalParameters, + List? namedParameters, int? requiredParameterCount, this.returnType = const DynamicType(), this.asyncMarker = AsyncMarker.Sync, AsyncMarker? dartAsyncMarker, this.emittedValueType, this.thisVariable, - }) : this.positionalParameters = - positionalParameters ?? [], + }) : this.positionalParameters = positionalParameters ?? [], this.requiredParameterCount = requiredParameterCount ?? positionalParameters?.length ?? 0, - this.namedParameters = namedParameters ?? [], + this.namedParameters = namedParameters ?? [], this.typeParameters = typeParameters ?? [], this.dartAsyncMarker = dartAsyncMarker ?? asyncMarker { setParents(this.typeParameters, this); @@ -125,10 +124,10 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer { _body?.parent = this; } - static DartType _getTypeOfVariable(VariableDeclaration node) => node.type; + static DartType _getTypeOfVariable(Variable node) => node.type; static NamedType _getNamedTypeOfVariable( - VariableDeclaration node, [ + Variable node, [ Substitution? substitution, ]) { return new NamedType( @@ -162,14 +161,14 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer { if (typeParametersToCopy.isEmpty || reuseTypeParameters) { structuralParameters = const []; returnType = this.returnType; - List thisPositionals = this.positionalParameters; + List thisPositionals = this.positionalParameters; positionalParameters = List.generate( thisPositionals.length, (index) => _getTypeOfVariable(thisPositionals[index]), growable: false, ); - List thisNamed = this.namedParameters; + List thisNamed = this.namedParameters; if (thisNamed.isEmpty) { namedParameters = const []; } else { @@ -189,7 +188,7 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer { Substitution substitution = freshStructuralParameters.substitution; returnType = substitution.substituteType(this.returnType); - List thisPositionals = this.positionalParameters; + List thisPositionals = this.positionalParameters; positionalParameters = List.generate( thisPositionals.length, (index) => substitution.substituteType( @@ -197,7 +196,7 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer { ), growable: false, ); - List thisNamed = this.namedParameters; + List thisNamed = this.namedParameters; if (thisNamed.isEmpty) { namedParameters = const []; } else { diff --git a/pkg/kernel/lib/src/ast/initializers.dart b/pkg/kernel/lib/src/ast/initializers.dart index 69602b1eccb..d77d576d38b 100644 --- a/pkg/kernel/lib/src/ast/initializers.dart +++ b/pkg/kernel/lib/src/ast/initializers.dart @@ -323,7 +323,7 @@ class RedirectingInitializer extends Initializer { /// The variable is in scope for the remainder of the initializer list, but is /// not in scope in the constructor body. class LocalInitializer extends Initializer { - VariableDeclaration variable; + Variable variable; LocalInitializer(this.variable) { variable.parent = this; diff --git a/pkg/kernel/lib/src/ast/patterns.dart b/pkg/kernel/lib/src/ast/patterns.dart index 0a196d4087c..6de14f3f202 100644 --- a/pkg/kernel/lib/src/ast/patterns.dart +++ b/pkg/kernel/lib/src/ast/patterns.dart @@ -9,7 +9,7 @@ sealed class Pattern extends TreeNode { /// /// These variables are initialized to the values captured by the variable /// patterns nested in the pattern. - List get declaredVariables; + List get declaredVariables; @override R accept(PatternVisitor visitor); @@ -64,7 +64,7 @@ class ConstantPattern extends Pattern { } @override - List get declaredVariables => const []; + List get declaredVariables => const []; @override R accept(PatternVisitor visitor) => visitor.visitConstantPattern(this); @@ -105,7 +105,7 @@ class AndPattern extends Pattern { Pattern right; @override - List get declaredVariables => [ + List get declaredVariables => [ ...left.declaredVariables, ...right.declaredVariables, ]; @@ -158,15 +158,15 @@ class OrPattern extends Pattern { Pattern left; Pattern right; - final List orPatternJointVariables; + final List orPatternJointVariables; @override - List get declaredVariables => orPatternJointVariables; + List get declaredVariables => orPatternJointVariables; OrPattern( this.left, this.right, { - required List orPatternJointVariables, + required List orPatternJointVariables, }) : orPatternJointVariables = orPatternJointVariables { left.parent = this; right.parent = this; @@ -223,7 +223,7 @@ class CastPattern extends Pattern { String? get variableName => pattern.variableName; @override - List get declaredVariables => pattern.declaredVariables; + List get declaredVariables => pattern.declaredVariables; @override R accept(PatternVisitor visitor) => visitor.visitCastPattern(this); @@ -275,7 +275,7 @@ class NullAssertPattern extends Pattern { String? get variableName => pattern.variableName; @override - List get declaredVariables => pattern.declaredVariables; + List get declaredVariables => pattern.declaredVariables; @override R accept(PatternVisitor visitor) => @@ -324,7 +324,7 @@ class NullCheckPattern extends Pattern { String? get variableName => pattern.variableName; @override - List get declaredVariables => pattern.declaredVariables; + List get declaredVariables => pattern.declaredVariables; @override R accept(PatternVisitor visitor) => visitor.visitNullCheckPattern(this); @@ -478,7 +478,7 @@ class ListPattern extends Pattern { FunctionType? indexGetType; @override - List get declaredVariables => [ + List get declaredVariables => [ for (Pattern pattern in patterns) ...pattern.declaredVariables, ]; @@ -658,7 +658,7 @@ class ObjectPattern extends Pattern { } @override - List get declaredVariables { + List get declaredVariables { return [for (NamedPattern field in fields) ...field.declaredVariables]; } @@ -761,7 +761,7 @@ class RelationalPattern extends Pattern { } @override - List get declaredVariables => const []; + List get declaredVariables => const []; @override R accept(PatternVisitor visitor) => @@ -823,7 +823,7 @@ class WildcardPattern extends Pattern { WildcardPattern(this.type); @override - List get declaredVariables => const []; + List get declaredVariables => const []; @override R accept(PatternVisitor visitor) => visitor.visitWildcardPattern(this); @@ -872,7 +872,7 @@ class WildcardPattern extends Pattern { } class AssignedVariablePattern extends Pattern { - final VariableDeclaration variable; + final Variable variable; /// The type of the expression against which this pattern is matched. /// @@ -936,7 +936,7 @@ class AssignedVariablePattern extends Pattern { void visitChildren(Visitor v) {} @override - List get declaredVariables => const []; + List get declaredVariables => const []; @override String? get variableName => variable.name!; @@ -1016,7 +1016,7 @@ class MapPattern extends Pattern { FunctionType? indexGetType; @override - List get declaredVariables => [ + List get declaredVariables => [ for (MapPatternEntry entry in entries) if (entry is! MapPatternRestEntry) ...entry.value.declaredVariables, ]; @@ -1182,7 +1182,7 @@ class NamedPattern extends Pattern { List? typeArguments; @override - List get declaredVariables => pattern.declaredVariables; + List get declaredVariables => pattern.declaredVariables; NamedPattern(this.name, this.pattern) { pattern.parent = this; @@ -1268,7 +1268,7 @@ class RecordPattern extends Pattern { RecordType? lookupType; @override - List get declaredVariables => [ + List get declaredVariables => [ for (Pattern pattern in patterns) ...pattern.declaredVariables, ]; @@ -1319,7 +1319,7 @@ class RecordPattern extends Pattern { class VariablePattern extends Pattern { // TODO(johnniwinther): Should this be accessed through [variable] instead? DartType? type; - VariableDeclaration variable; + Variable variable; /// The type of the expression against which this pattern is matched. /// @@ -1327,7 +1327,7 @@ class VariablePattern extends Pattern { DartType? matchedValueType; @override - List get declaredVariables => [variable]; + List get declaredVariables => [variable]; VariablePattern(this.type, this.variable) { variable.parent = this; @@ -1421,7 +1421,7 @@ class RestPattern extends Pattern { } @override - List get declaredVariables => + List get declaredVariables => subPattern?.declaredVariables ?? const []; @override @@ -1442,7 +1442,7 @@ class InvalidPattern extends Pattern { Expression invalidExpression; @override - final List declaredVariables; + final List declaredVariables; InvalidPattern(this.invalidExpression, {required this.declaredVariables}) { invalidExpression.parent = this; @@ -1741,7 +1741,7 @@ class PatternSwitchCase extends TreeNode implements SwitchCase { bool hasLabel; - final List jointVariables; + final List jointVariables; // TODO(johnniwinther): Serialize this field. final List? jointVariableFirstUseOffsets; diff --git a/pkg/kernel/lib/src/ast/statements.dart b/pkg/kernel/lib/src/ast/statements.dart index dbb1edbe0f3..91ff1073ed3 100644 --- a/pkg/kernel/lib/src/ast/statements.dart +++ b/pkg/kernel/lib/src/ast/statements.dart @@ -638,7 +638,7 @@ class ForInStatement extends Statement implements LoopStatement, ScopeProvider { List? get fileOffsetsIfMultiple => [fileOffset, bodyOffset]; // Has no initializer. - VariableDeclaration variable; + Variable variable; Expression iterable; @@ -1225,8 +1225,8 @@ class TryCatch extends Statement { class Catch extends TreeNode implements ScopeProvider { DartType guard; // Not null, defaults to dynamic. - VariableDeclaration? exception; - VariableDeclaration? stackTrace; + Variable? exception; + Variable? stackTrace; Statement body; @override @@ -1468,8 +1468,7 @@ class YieldStatement extends Statement { /// 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 LegacyVariable extends TreeNode - implements VariableDeclaration, Annotatable { +class LegacyVariable extends TreeNode implements Variable, Annotatable { /// Offset of the equals sign in the source file it comes from. /// /// Valid values are from 0 and up, or -1 ([TreeNode.noOffset]) @@ -1912,13 +1911,13 @@ class LegacyVariable extends TreeNode } @override - VariableDeclaration get asVariableDeclaration => this; + Variable get asVariableDeclaration => this; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration value) { + void set variable(Variable value) { throw new UnsupportedError("${this.runtimeType}.variable="); } @@ -1968,20 +1967,19 @@ class LegacyVariable extends TreeNode /// Declaration of a local variable. abstract class VariableStatement extends Statement { /// The declared variable. - abstract final VariableDeclaration variable; + abstract final Variable variable; /// The declared initializer, if any. abstract Expression? initializer; - factory VariableStatement(VariableDeclaration variable) = - LegacyVariableStatement; + factory VariableStatement(Variable variable) = LegacyVariableStatement; } /// Declaration of a local variable. class LegacyVariableStatement extends Statement implements VariableStatement { /// The declared variable. @override - VariableDeclaration variable; + Variable variable; LegacyVariableStatement(this.variable) { variable.parent = this; @@ -2036,7 +2034,7 @@ class LegacyVariableStatement extends Statement implements VariableStatement { /// /// The body of the function may use [variable] as its self-reference. class FunctionDeclaration extends Statement implements LocalFunction { - VariableDeclaration variable; // Is final and has no initializer. + Variable variable; // Is final and has no initializer. @override FunctionNode function; @@ -2098,7 +2096,7 @@ class FunctionDeclaration extends Statement implements LocalFunction { class VariableInitialization extends Statement implements VariableStatement, ContextConsumer { @override - VariableDeclaration variable; + Variable variable; @override Expression? initializer; diff --git a/pkg/kernel/lib/src/ast/typedefs.dart b/pkg/kernel/lib/src/ast/typedefs.dart index ea9faea6dc1..3a3915779c8 100644 --- a/pkg/kernel/lib/src/ast/typedefs.dart +++ b/pkg/kernel/lib/src/ast/typedefs.dart @@ -29,8 +29,8 @@ class Typedef extends NamedNode required this.fileUri, List? typeParameters, List? typeParametersOfFunctionType, - List? positionalParameters, - List? namedParameters, + List? positionalParameters, + List? namedParameters, }) : this.typeParameters = typeParameters ?? [], super(reference) { setParents(this.typeParameters, this); diff --git a/pkg/kernel/lib/src/ast/variables.dart b/pkg/kernel/lib/src/ast/variables.dart index 87e173ec9de..6528870fc27 100644 --- a/pkg/kernel/lib/src/ast/variables.dart +++ b/pkg/kernel/lib/src/ast/variables.dart @@ -24,7 +24,7 @@ sealed class VariableBase extends TreeNode implements Annotatable { } /// This is a helper class to enable mixing a mixin into concrete -/// implementations of the sealed class [VariableDeclaration]. It's not supposed +/// implementations of the sealed class [Variable]. It's not supposed /// to be used as a type annotation, but purely for declaring the class /// hierarchy. abstract interface class IVariable implements TreeNode { @@ -52,7 +52,7 @@ abstract interface class IVariable implements TreeNode { abstract int binaryOffsetNoTag; abstract List? capturedContexts; abstract int fileEqualsOffset; - abstract VariableDeclaration variable; + abstract Variable variable; void clearAnnotations(); VariableContext? get context; @@ -73,11 +73,11 @@ abstract interface class IVariable implements TreeNode { bool get hasIsWildcard; bool get hasIsSuperInitializingFormal; bool get hasIsErroneouslyInitialized; - VariableDeclaration get asVariableDeclaration; + Variable get asVariableDeclaration; } /// The root of the sealed hierarchy of non-type variables. -sealed class VariableDeclaration extends VariableBase +sealed class Variable extends VariableBase implements IVariable, ContextConsumer { /// Static type of the variable. @override @@ -123,7 +123,7 @@ sealed class VariableDeclaration extends VariableBase @override abstract bool isErroneouslyInitialized; - factory VariableDeclaration( + factory Variable( String? name, { Expression? initializer, DartType type, @@ -142,7 +142,7 @@ sealed class VariableDeclaration extends VariableBase bool isWildcard, }) = LegacyVariable; - factory VariableDeclaration.forValue( + factory Variable.forValue( Expression? initializer, { bool isFinal, bool isConst, @@ -154,7 +154,7 @@ sealed class VariableDeclaration extends VariableBase DartType type, }) = LegacyVariable.forValue; - VariableDeclaration.empty(); + Variable.empty(); @override bool get hasIsFinal; @@ -189,7 +189,7 @@ sealed class VariableDeclaration extends VariableBase bool get isAssignable; @override - VariableDeclaration get asVariableDeclaration => this; + Variable get asVariableDeclaration => this; abstract String? name; @@ -204,7 +204,7 @@ sealed class VariableDeclaration extends VariableBase /// 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 VariableDeclaration { +class LocalVariable extends Variable { @override String? cosmeticName; @@ -501,10 +501,10 @@ class LocalVariable extends VariableDeclaration { int fileEqualsOffset = TreeNode.noOffset; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration variable) { + void set variable(Variable variable) { throw new UnsupportedError("${this.runtimeType}.variable="); } @@ -530,7 +530,7 @@ class LocalVariable extends VariableDeclaration { /// } catch (e, s) { /// bar(); /// } -class CatchVariable extends VariableDeclaration { +class CatchVariable extends Variable { final String catchVariableName; @override @@ -822,10 +822,10 @@ class CatchVariable extends VariableDeclaration { int fileEqualsOffset = TreeNode.noOffset; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration variable) { + void set variable(Variable variable) { throw new UnsupportedError("${this.runtimeType}.variable="); } @@ -844,7 +844,7 @@ class CatchVariable extends VariableDeclaration { } /// Abstract parameter class, the parent for positional and named parameters. -sealed class FunctionParameter extends VariableDeclaration { +sealed class FunctionParameter extends Variable { Expression? defaultValue; FunctionParameter({ @@ -1189,10 +1189,10 @@ class PositionalParameter extends FunctionParameter { int fileEqualsOffset = TreeNode.noOffset; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration value) { + void set variable(Variable value) { throw new UnsupportedError("${this.runtimeType}"); } } @@ -1350,16 +1350,16 @@ class NamedParameter extends FunctionParameter { } @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration value) { + void set variable(Variable value) { throw new UnsupportedError("${this.runtimeType}"); } } /// The variable storage for `this`. -class ThisVariable extends VariableDeclaration { +class ThisVariable extends Variable { @override String get cosmeticName => "this-variable"; @@ -1637,10 +1637,10 @@ class ThisVariable extends VariableDeclaration { int fileEqualsOffset = TreeNode.noOffset; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration variable) { + void set variable(Variable variable) { throw new UnsupportedError("${this.runtimeType}.variable="); } @@ -1657,7 +1657,7 @@ class ThisVariable extends VariableDeclaration { /// A variable introduced during desugaring. Such variables don't correspond to /// any variable declared by the programmer. -class SyntheticVariable extends VariableDeclaration { +class SyntheticVariable extends Variable { @override String? cosmeticName; @@ -1931,10 +1931,10 @@ class SyntheticVariable extends VariableDeclaration { int fileEqualsOffset = TreeNode.noOffset; @override - VariableDeclaration get variable => this; + Variable get variable => this; @override - void set variable(VariableDeclaration variable) { + void set variable(Variable variable) { throw new UnsupportedError("${this.runtimeType}.variable="); } diff --git a/pkg/kernel/lib/src/coverage.dart b/pkg/kernel/lib/src/coverage.dart index c4998baf39d..8373be99c83 100644 --- a/pkg/kernel/lib/src/coverage.dart +++ b/pkg/kernel/lib/src/coverage.dart @@ -993,37 +993,37 @@ class CoverageVisitor implements Visitor { @override void visitLocalVariable(LocalVariable node) { - visited.add(VariableDeclarationKind.LocalVariable); + visited.add(VariableKind.LocalVariable); node.visitChildren(this); } @override void visitCatchVariable(CatchVariable node) { - visited.add(VariableDeclarationKind.CatchVariable); + visited.add(VariableKind.CatchVariable); node.visitChildren(this); } @override void visitPositionalParameter(PositionalParameter node) { - visited.add(VariableDeclarationKind.PositionalParameter); + visited.add(VariableKind.PositionalParameter); node.visitChildren(this); } @override void visitNamedParameter(NamedParameter node) { - visited.add(VariableDeclarationKind.NamedParameter); + visited.add(VariableKind.NamedParameter); node.visitChildren(this); } @override void visitThisVariable(ThisVariable node) { - visited.add(VariableDeclarationKind.ThisVariable); + visited.add(VariableKind.ThisVariable); node.visitChildren(this); } @override void visitSyntheticVariable(SyntheticVariable node) { - visited.add(VariableDeclarationKind.SyntheticVariable); + visited.add(VariableKind.SyntheticVariable); node.visitChildren(this); } @@ -1481,7 +1481,7 @@ enum StatementKind { YieldStatement, } -enum VariableDeclarationKind { +enum VariableKind { CatchVariable, LocalVariable, NamedParameter, @@ -1519,7 +1519,7 @@ Set missingNodes(CoverageVisitor visitor) { ...InitializerKind.values, ...PatternKind.values, ...StatementKind.values, - ...VariableDeclarationKind.values, + ...VariableKind.values, ...DartTypeKind.values, }; all.removeAll(visitor.visited); @@ -1570,13 +1570,9 @@ Set missingStatements(CoverageVisitor visitor) { return all; } -/// Returns the set of [VariableDeclarationKind]s not visited by [visitor]. -Set missingVariableDeclarations( - CoverageVisitor visitor, -) { - Set all = new Set.of( - VariableDeclarationKind.values, - ); +/// Returns the set of [VariableKind]s not visited by [visitor]. +Set missingVariables(CoverageVisitor visitor) { + Set all = new Set.of(VariableKind.values); all.removeAll(visitor.visited); return all; } diff --git a/pkg/kernel/lib/src/equivalence.dart b/pkg/kernel/lib/src/equivalence.dart index d4882d5d660..87b9b45c3bd 100644 --- a/pkg/kernel/lib/src/equivalence.dart +++ b/pkg/kernel/lib/src/equivalence.dart @@ -13614,10 +13614,10 @@ class EquivalenceStrategy { return visitor.checkValues(node.flags, other.flags, 'flags'); } - bool checkVariableDeclaration_flags( + bool checkVariable_flags( EquivalenceVisitor visitor, - VariableDeclaration node, - VariableDeclaration other, + Variable node, + Variable other, ) { return checkVariableBase_flags(visitor, node, other); } @@ -13627,7 +13627,7 @@ class EquivalenceStrategy { LocalVariable node, LocalVariable other, ) { - return checkVariableDeclaration_flags(visitor, node, other); + return checkVariable_flags(visitor, node, other); } bool checkVariableBase_fileOffset( @@ -13638,10 +13638,10 @@ class EquivalenceStrategy { return checkTreeNode_fileOffset(visitor, node, other); } - bool checkVariableDeclaration_fileOffset( + bool checkVariable_fileOffset( EquivalenceVisitor visitor, - VariableDeclaration node, - VariableDeclaration other, + Variable node, + Variable other, ) { return checkVariableBase_fileOffset(visitor, node, other); } @@ -13651,7 +13651,7 @@ class EquivalenceStrategy { LocalVariable node, LocalVariable other, ) { - return checkVariableDeclaration_fileOffset(visitor, node, other); + return checkVariable_fileOffset(visitor, node, other); } bool checkCatchVariable_catchVariableName( @@ -13725,7 +13725,7 @@ class EquivalenceStrategy { CatchVariable node, CatchVariable other, ) { - return checkVariableDeclaration_flags(visitor, node, other); + return checkVariable_flags(visitor, node, other); } bool checkCatchVariable_fileOffset( @@ -13733,7 +13733,7 @@ class EquivalenceStrategy { CatchVariable node, CatchVariable other, ) { - return checkVariableDeclaration_fileOffset(visitor, node, other); + return checkVariable_fileOffset(visitor, node, other); } bool checkPositionalParameter_cosmeticName( @@ -13827,7 +13827,7 @@ class EquivalenceStrategy { FunctionParameter node, FunctionParameter other, ) { - return checkVariableDeclaration_flags(visitor, node, other); + return checkVariable_flags(visitor, node, other); } bool checkPositionalParameter_flags( @@ -13843,7 +13843,7 @@ class EquivalenceStrategy { FunctionParameter node, FunctionParameter other, ) { - return checkVariableDeclaration_fileOffset(visitor, node, other); + return checkVariable_fileOffset(visitor, node, other); } bool checkPositionalParameter_fileOffset( @@ -14003,7 +14003,7 @@ class EquivalenceStrategy { ThisVariable node, ThisVariable other, ) { - return checkVariableDeclaration_flags(visitor, node, other); + return checkVariable_flags(visitor, node, other); } bool checkThisVariable_fileOffset( @@ -14011,7 +14011,7 @@ class EquivalenceStrategy { ThisVariable node, ThisVariable other, ) { - return checkVariableDeclaration_fileOffset(visitor, node, other); + return checkVariable_fileOffset(visitor, node, other); } bool checkSyntheticVariable_cosmeticName( @@ -14097,7 +14097,7 @@ class EquivalenceStrategy { SyntheticVariable node, SyntheticVariable other, ) { - return checkVariableDeclaration_flags(visitor, node, other); + return checkVariable_flags(visitor, node, other); } bool checkSyntheticVariable_fileOffset( @@ -14105,7 +14105,7 @@ class EquivalenceStrategy { SyntheticVariable node, SyntheticVariable other, ) { - return checkVariableDeclaration_fileOffset(visitor, node, other); + return checkVariable_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 ebca61bb722..9ac6b8b3281 100644 --- a/pkg/kernel/lib/src/node_creator.dart +++ b/pkg/kernel/lib/src/node_creator.dart @@ -40,7 +40,7 @@ class NodeCreator { final Map _pendingInitializers; final Map _pendingMembers; final Map _pendingNodes; - final Map _pendingVariableDeclarations; + final Map _pendingVariables; /// The set of all kinds of nodes created by this node creator. final Set _createdKinds = {}; @@ -53,7 +53,7 @@ class NodeCreator { /// /// Needed nodes are added to the context of the created nodes. For instance, /// a needed [Class] is added to the [_component] and a needed - /// [VariableDeclaration] is added to a enclosing [Block]. + /// [Variable] is added to a enclosing [Block]. List _neededLibraries = []; List _neededClasses = []; List _neededExtensionTypeDeclarations = []; @@ -65,7 +65,7 @@ class NodeCreator { List _neededProcedures = []; List _neededFields = []; List _neededLibraryDependencies = []; - List _neededVariableDeclarations = []; + List _neededVariables = []; List _neededLabeledStatements = []; List _neededFunctionDeclarations = []; List _neededSwitchCases = []; @@ -79,8 +79,7 @@ class NodeCreator { Iterable patterns = PatternKind.values, Iterable initializers = InitializerKind.values, Iterable members = MemberKind.values, - Iterable variableDeclarations = - VariableDeclarationKind.values, + Iterable variables = VariableKind.values, Iterable nodes = NodeKind.values, }) : _pendingExpressions = _createPending(expressions, {}), _pendingStatements = _createPending(statements, { @@ -94,15 +93,14 @@ 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, - }), + _pendingVariables = _createPending(variables, { + VariableKind.CatchVariable, + VariableKind.LocalVariable, + VariableKind.PositionalParameter, + VariableKind.NamedParameter, + VariableKind.SyntheticVariable, + VariableKind.ThisVariable, + }), _pendingNodes = _createPending(nodes, {NodeKind.TypeVariable}), _uri = Uri.parse('test:uri') { _createdKinds.addAll(_pendingExpressions.keys); @@ -110,7 +108,7 @@ class NodeCreator { _createdKinds.addAll(_pendingDartTypes.keys); _createdKinds.addAll(_pendingInitializers.keys); _createdKinds.addAll(_pendingMembers.keys); - _createdKinds.addAll(_pendingVariableDeclarations.keys); + _createdKinds.addAll(_pendingVariables.keys); _createdKinds.addAll(_pendingNodes.keys); } @@ -135,13 +133,13 @@ class NodeCreator { } _neededLabeledStatements.clear(); statement = Block([ - for (VariableDeclaration neededVariable in _neededVariableDeclarations) + for (Variable neededVariable in _neededVariables) VariableStatement(neededVariable), ..._neededFunctionDeclarations, statement, ]); _neededFunctionDeclarations.clear(); - _neededVariableDeclarations.clear(); + _neededVariables.clear(); return statement; } @@ -671,20 +669,19 @@ class NodeCreator { return field; } - /// Returns a [VariableDeclaration] node that fits the requirements. + /// Returns a [Variable] node that fits the requirements. /// - /// If no such [VariableDeclaration] exists in [_neededVariableDeclarations], - /// a new [VariableDeclaration] is created and added to - /// [_neededVariableDeclarations]. + /// If no such [Variable] exists in [_neededVariables], + /// a new [Variable] is created and added to + /// [_neededVariables]. // TODO(johnniwinther): Add requirements when/where needed. - VariableDeclaration _needVariableDeclaration() { - for (VariableDeclaration variableDeclaration - in _neededVariableDeclarations) { - return variableDeclaration; + Variable _needVariable() { + for (Variable variable in _neededVariables) { + return variable; } - VariableDeclaration variableDeclaration = VariableDeclaration('foo'); - _neededVariableDeclarations.add(variableDeclaration); - return variableDeclaration; + Variable variable = Variable('foo'); + _neededVariables.add(variable); + return variable; } /// Returns a [LabeledStatement] node that fits the requirements. @@ -731,7 +728,7 @@ class NodeCreator { return functionDeclaration; } FunctionDeclaration functionDeclaration = FunctionDeclaration( - VariableDeclaration('foo'), + Variable('foo'), FunctionNode(Block([])), ); _neededFunctionDeclarations.add(functionDeclaration); @@ -921,7 +918,7 @@ class NodeCreator { return IsExpression(_createExpression(), _createDartType()) ..fileOffset = _needFileOffset(); case ExpressionKind.Let: - return Let(_createVariableDeclaration(), _createExpression()) + return Let(_createVariable(), _createExpression()) ..fileOffset = _needFileOffset(); case ExpressionKind.ListConcatenation: return _createOneOf(_pendingExpressions, kind, index, [ @@ -1191,15 +1188,13 @@ class NodeCreator { ..fileOffset = _needFileOffset(); case ExpressionKind.VariableGet: return _createOneOf(_pendingExpressions, kind, index, [ + () => VariableGet(_needVariable())..fileOffset = _needFileOffset(), () => - VariableGet(_needVariableDeclaration()) - ..fileOffset = _needFileOffset(), - () => - VariableGet(_needVariableDeclaration(), _createDartType()) + VariableGet(_needVariable(), _createDartType()) ..fileOffset = _needFileOffset(), ]); case ExpressionKind.VariableSet: - return VariableSet(_needVariableDeclaration(), _createExpression()) + return VariableSet(_needVariable(), _createExpression()) ..fileOffset = _needFileOffset(); case ExpressionKind.RecordIndexGet: return RecordIndexGet( @@ -1294,7 +1289,7 @@ class NodeCreator { return AndPattern(_createPattern(), _createPattern()) ..fileOffset = _needFileOffset(); case PatternKind.AssignedVariablePattern: - return AssignedVariablePattern(_needVariableDeclaration()) + return AssignedVariablePattern(_needVariable()) ..fileOffset = _needFileOffset(); case PatternKind.CastPattern: return CastPattern(_createPattern(), _createDartType()) @@ -1373,10 +1368,10 @@ class NodeCreator { case PatternKind.VariablePattern: return _createOneOf(_pendingPatterns, kind, index, [ () => - VariablePattern(null, _createVariableDeclaration()) + VariablePattern(null, _createVariable()) ..fileOffset = _needFileOffset(), () => - VariablePattern(_createDartType(), _createVariableDeclaration()) + VariablePattern(_createDartType(), _createVariable()) ..fileOffset = _needFileOffset(), ]); case PatternKind.WildcardPattern: @@ -1455,13 +1450,13 @@ class NodeCreator { case StatementKind.ForInStatement: return _createOneOf(_pendingStatements, kind, index, [ () => ForInStatement( - _createVariableDeclaration(), + _createVariable(), _createExpression(), _createStatement(), isAsync: false, )..fileOffset = _needFileOffset(), () => ForInStatement( - _createVariableDeclaration(), + _createVariable(), _createExpression(), _createStatement(), isAsync: true, @@ -1473,15 +1468,15 @@ class NodeCreator { ForStatement([], null, [], _createStatement()) ..fileOffset = _needFileOffset(), () => ForStatement( - [VariableStatement(_createVariableDeclaration())], + [VariableStatement(_createVariable())], _createExpression(), [_createExpression()], _createStatement(), )..fileOffset = _needFileOffset(), () => ForStatement( [ - VariableStatement(_createVariableDeclaration()), - VariableStatement(_createVariableDeclaration()), + VariableStatement(_createVariable()), + VariableStatement(_createVariable()), ], _createExpression(), [_createExpression(), _createExpression()], @@ -1490,7 +1485,7 @@ class NodeCreator { ]); case StatementKind.FunctionDeclaration: return FunctionDeclaration( - VariableDeclaration(null, isSynthesized: true), + Variable(null, isSynthesized: true), _createFunctionNode(), )..fileOffset = _needFileOffset(); case StatementKind.IfStatement: @@ -1543,15 +1538,15 @@ class NodeCreator { ..fileOffset = _needFileOffset(); case StatementKind.LegacyVariableStatement: return _createOneOf(_pendingStatements, kind, index, [ + () => + VariableStatement(Variable('foo')..fileOffset = _needFileOffset()) + ..fileOffset = _needFileOffset(), () => VariableStatement( - VariableDeclaration('foo')..fileOffset = _needFileOffset(), - )..fileOffset = _needFileOffset(), - () => VariableStatement( - VariableDeclaration('foo', initializer: _createExpression()) + Variable('foo', initializer: _createExpression()) ..fileOffset = _needFileOffset(), )..fileOffset = _needFileOffset(), () => VariableStatement( - VariableDeclaration('foo', type: _createDartType()) + Variable('foo', type: _createDartType()) ..fileOffset = _needFileOffset(), )..fileOffset = _needFileOffset(), ]); @@ -1609,12 +1604,12 @@ class NodeCreator { } } - /// Creates a [VariableDeclaration] node. + /// Creates a [Variable] node. /// - /// If there are any pending [VariableDeclaration] nodes, one of these is + /// If there are any pending [Variable] nodes, one of these is /// created. - VariableDeclaration _createVariableDeclaration() { - return VariableDeclaration('foo'); + Variable _createVariable() { + return Variable('foo'); } /// Creates a [DartType] node. @@ -1883,7 +1878,7 @@ class NodeCreator { case InitializerKind.InvalidInitializer: return InvalidInitializer('')..fileOffset = _needFileOffset(); case InitializerKind.LocalInitializer: - return LocalInitializer(_createVariableDeclaration()) + return LocalInitializer(_createVariable()) ..fileOffset = _needFileOffset(); case InitializerKind.RedirectingInitializer: return RedirectingInitializer(_needConstructor(), _createArguments()) @@ -2135,13 +2130,13 @@ class NodeCreator { )..fileOffset = _needFileOffset(); case NodeKind.LegacyVariable: return _createOneOf(_pendingNodes, kind, index, [ - () => VariableDeclaration('foo')..fileOffset = _needFileOffset(), + () => Variable('foo')..fileOffset = _needFileOffset(), () => - VariableDeclaration('foo', initializer: _createExpression()) + Variable('foo', initializer: _createExpression()) ..fileOffset = _needFileOffset(), () => - VariableDeclaration('foo', type: _createDartType()) + Variable('foo', type: _createDartType()) ..fileOffset = _needFileOffset(), ]); case NodeKind.TypeVariable: diff --git a/pkg/kernel/lib/src/printer.dart b/pkg/kernel/lib/src/printer.dart index 04fb2b70998..5d5fe4d368f 100644 --- a/pkg/kernel/lib/src/printer.dart +++ b/pkg/kernel/lib/src/printer.dart @@ -99,7 +99,7 @@ class AstPrinter { int _constantLevel = 0; int _indentationLevel = 0; late final Map _labelNames = {}; - late final Map _variableDeclarationNames = {}; + late final Map _variableDeclarationNames = {}; late final Map _variableNames = {}; AstPrinter(this._strategy); @@ -264,7 +264,7 @@ class AstPrinter { if (name != null) { return name; } - return _variableDeclarationNames[node as VariableDeclaration] ??= + return _variableDeclarationNames[node as Variable] ??= '#${_variableDeclarationNames.length}'; } } @@ -518,7 +518,7 @@ class AstPrinter { /// If [isLate] and [type] are provided, these values are used instead of /// the corresponding properties on [node]. void writeVariableInitialization( - VariableDeclaration node, { + Variable node, { bool includeModifiersAndType = true, bool? isLate, DartType? type, @@ -561,7 +561,7 @@ class AstPrinter { /// If [isLate] and [type] are provided, these values are used instead of /// the corresponding properties on [node]. void writeExpressionVariable( - VariableDeclaration node, { + Variable node, { bool includeModifiersAndType = true, bool? isLate, DartType? type, diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart index 128c46d40b6..4e0a6a87b08 100644 --- a/pkg/kernel/lib/target/targets.dart +++ b/pkg/kernel/lib/target/targets.dart @@ -156,7 +156,7 @@ class ConstantsBackend { bool get alwaysInlineConstants => true; /// Inline control of constant variables. The given constant expression - /// is the initializer of a [Field] or [VariableDeclaration] node. + /// is the initializer of a [Field] or [Variable] node. /// If this method returns `true`, the variable will be inlined at all /// points of reference and the variable itself removed (unless overridden /// by the `keepFields` or `keepLocals` properties). @@ -184,7 +184,7 @@ class ConstantsBackend { /// All use-sites will be rewritten based on [shouldInlineConstant]. bool get keepFields => true; - /// If `true` constant [VariableDeclaration]s are not removed from the AST + /// If `true` constant [Variable]s are not removed from the AST /// even when use-sites are inlined. /// /// All use-sites will be rewritten based on [shouldInlineConstant]. diff --git a/pkg/kernel/lib/text/ast_to_text.dart b/pkg/kernel/lib/text/ast_to_text.dart index 44b3d6c25b9..7c0d7b4ea70 100644 --- a/pkg/kernel/lib/text/ast_to_text.dart +++ b/pkg/kernel/lib/text/ast_to_text.dart @@ -146,8 +146,7 @@ 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', @@ -162,7 +161,7 @@ class NameSystem { final Disambiguator prefixes = new Disambiguator(); - String nameVariable(VariableDeclaration node) => variables.getName(node); + String nameVariable(Variable node) => variables.getName(node); String nameLibrary(Reference node) => libraries.getName(node); String nameTypeParameter(TypeParameter node) => typeParameters.getName(node); String nameStructuralParameter(StructuralParameter node) => @@ -243,7 +242,7 @@ class NameSystem { } abstract class Annotator { - String annotateVariable(Printer printer, VariableDeclaration node); + String annotateVariable(Printer printer, Variable node); String annotateReturn(Printer printer, FunctionNode node); String annotateField(Printer printer, Field node); } @@ -369,11 +368,11 @@ class Printer extends VisitorDefault with VisitorVoidMixin { } } - String getVariableName(VariableDeclaration node) { + String getVariableName(Variable node) { return node.cosmeticName ?? syntheticNames.nameVariable(node); } - String getVariableReference(VariableDeclaration node) { + String getVariableReference(Variable node) { return getVariableName(node); } @@ -673,7 +672,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { if (showOffsets && node is TreeNode) { writeWord("[${node.fileOffset}]"); } - if (showMetadata && node is TreeNode && node is! VariableDeclaration) { + if (showMetadata && node is TreeNode && node is! Variable) { writeMetadata( node, separateLines: node is Member || node is FunctionDeclaration, @@ -980,8 +979,8 @@ class Printer extends VisitorDefault with VisitorVoidMixin { } void writeParameterList( - List positional, - List named, + List positional, + List named, int requiredParameterCount, ) { writeSymbol('('); @@ -1112,7 +1111,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { writeWord(getTypedefReference(typedefNode)); } - void writeVariableReference(VariableDeclaration variable) { + void writeVariableReference(Variable variable) { final bool highlight = shouldHighlight(variable); if (highlight) { startHighlight(variable); @@ -1255,7 +1254,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { endLine(';'); } - void writeExpressionVariable(VariableDeclaration node) { + void writeExpressionVariable(Variable node) { // TODO(cstefantsova): Printer of the new variables is broken. if (node is LegacyVariable && node is! FunctionParameter) { writeVariableDeclaration(node); @@ -2717,13 +2716,13 @@ class Printer extends VisitorDefault with VisitorVoidMixin { writeSpace(); writeWord('catch'); writeSymbol('('); - VariableDeclaration? exception = node.exception; + Variable? exception = node.exception; if (exception != null) { writeExpressionVariable(exception); } else { writeWord('no-exception-var'); } - VariableDeclaration? stackTrace = node.stackTrace; + Variable? stackTrace = node.stackTrace; if (stackTrace != null) { writeComma(); writeExpressionVariable(stackTrace); @@ -2781,10 +2780,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { writeFunction(node.function, name: getVariableName(node.variable)); } - void writeVariableDeclaration( - VariableDeclaration node, { - bool useVarKeyword = false, - }) { + void writeVariableDeclaration(Variable node, {bool useVarKeyword = false}) { switch (node) { case LocalVariable(): case CatchVariable(): @@ -2846,7 +2842,7 @@ class Printer extends VisitorDefault with VisitorVoidMixin { } void writeVariableStatement(VariableStatement node) { - VariableDeclaration variable = node.variable; + Variable variable = node.variable; if (node is VariableInitialization) { if (showOffsets) writeWord("[${node.fileOffset}]"); if (showMetadata) writeMetadata(node); diff --git a/pkg/kernel/lib/text/debug_printer.dart b/pkg/kernel/lib/text/debug_printer.dart index c234028ecf5..22d4bc7d108 100644 --- a/pkg/kernel/lib/text/debug_printer.dart +++ b/pkg/kernel/lib/text/debug_printer.dart @@ -85,7 +85,7 @@ class DebugPrinter extends VisitorDefault } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { openNode(node, '${node.runtimeType}', { 'name': '${node.name ?? '--unnamed--'}', 'isFinal': '${node.isFinal}', diff --git a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart index 1f10718409f..f5bf065547a 100644 --- a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart +++ b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart @@ -24,7 +24,7 @@ const String _locationFieldName = r'_location'; bool _hasNamedParameter(FunctionNode function, String name) { return function.namedParameters.any( - (VariableDeclaration parameter) => parameter.name == name, + (Variable parameter) => parameter.name == name, ); } @@ -34,11 +34,8 @@ bool _hasNamedArgument(Arguments arguments, String argumentName) { ); } -VariableDeclaration? _getNamedParameter( - FunctionNode function, - String parameterName, -) { - for (VariableDeclaration parameter in function.namedParameters) { +Variable? _getNamedParameter(FunctionNode function, String parameterName) { + for (Variable parameter in function.namedParameters) { if (parameter.name == parameterName) { return parameter; } @@ -87,10 +84,7 @@ void _maybeAddCreationLocationArgument( /// Adds a named parameter to a function if the function does not already have /// a named parameter with the name or optional positional parameters. -bool _maybeAddNamedParameter( - FunctionNode function, - VariableDeclaration variable, -) { +bool _maybeAddNamedParameter(FunctionNode function, Variable variable) { if (_hasNamedParameter(function, _creationLocationParameterName)) { // Gracefully handle if this method is called on a function that has already // been transformed. @@ -177,9 +171,7 @@ class _WidgetCallSiteTransformer extends Transformer { @override Procedure visitProcedure(Procedure node) { if (_isWidgetFactory(node)) { - final VariableDeclaration locationParameter = node - .function - .namedParameters + final Variable locationParameter = node.function.namedParameters .firstWhere( (parameter) => parameter.name == _creationLocationParameterName, ); @@ -306,7 +298,7 @@ class _WidgetCallSiteTransformer extends Transformer { // location parameter of the surrounding factory since it isn't a // constant expression. !isConst) { - final VariableDeclaration? creationLocationParameter = _getNamedParameter( + final Variable? creationLocationParameter = _getNamedParameter( _currentFactory!.function, _creationLocationParameterName, ); @@ -500,7 +492,7 @@ class WidgetCreatorTracker { _creationLocationParameterName, ), ); - final VariableDeclaration variable = new VariableDeclaration( + final Variable variable = new Variable( _creationLocationParameterName, type: new InterfaceType( tracking.locationClass, @@ -771,7 +763,7 @@ class WidgetCreatorTracker { if (procedure.isFactory) { _maybeAddNamedParameter( procedure.function, - new VariableDeclaration( + new Variable( _creationLocationParameterName, type: new InterfaceType( tracking.locationClass, @@ -804,7 +796,7 @@ class WidgetCreatorTracker { return; } - final VariableDeclaration variable = new VariableDeclaration( + final Variable variable = new Variable( _creationLocationParameterName, type: new InterfaceType( tracking.locationClass, @@ -878,7 +870,7 @@ class WidgetCreatorTracker { if (method != null && _hasWidgetFactoryAnnotation(method)) { _maybeAddNamedParameter( method.function, - new VariableDeclaration( + new Variable( _creationLocationParameterName, type: new InterfaceType( _locationClass!, @@ -892,7 +884,7 @@ class WidgetCreatorTracker { if (tearOff != null && _hasWidgetFactoryAnnotation(tearOff)) { _maybeAddNamedParameter( tearOff.function, - new VariableDeclaration( + new Variable( _creationLocationParameterName, type: new InterfaceType( _locationClass!, diff --git a/pkg/kernel/lib/type_checker.dart b/pkg/kernel/lib/type_checker.dart index 8ac6b0336be..a1ccc4cbdd0 100644 --- a/pkg/kernel/lib/type_checker.dart +++ b/pkg/kernel/lib/type_checker.dart @@ -274,7 +274,7 @@ class TypeCheckingVisitor ); } } - for (VariableDeclaration namedParameter in node.namedParameters) { + for (Variable namedParameter in node.namedParameters) { if (!namedParameter.isRequired) { handleOptionalParameter( namedParameter, @@ -304,7 +304,7 @@ class TypeCheckingVisitor } void handleOptionalParameter( - VariableDeclaration parameter, { + Variable parameter, { required bool isPartOfAbstractExternalOrNoSuchMethodForwarderMethod, }) { Expression? initializer = parameter.initializer; @@ -1256,7 +1256,7 @@ class TypeCheckingVisitor } @override - void visitVariableDeclaration(VariableDeclaration node) { + void visitVariable(Variable node) { if (node.initializer != null) { node.initializer = checkExpressionAndAssignability( node.initializer!, @@ -1342,7 +1342,7 @@ class TypeCheckingVisitor @override void visitLocalInitializer(LocalInitializer node) { - visitVariableDeclaration(node.variable); + visitVariable(node.variable); } @override diff --git a/pkg/kernel/lib/verifier.dart b/pkg/kernel/lib/verifier.dart index 137fb7e03a9..4b2d8959761 100644 --- a/pkg/kernel/lib/verifier.dart +++ b/pkg/kernel/lib/verifier.dart @@ -143,9 +143,8 @@ 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 = {}; @@ -270,7 +269,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { // TODO(cstefantsova): Remove this method when the new variable model is // supported. bool _isNewModelVariable(TreeNode node) { - return node is VariableDeclaration && node is! LegacyVariable || + return node is Variable && node is! LegacyVariable || node is FunctionParameter; } @@ -322,7 +321,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { exitTreeNode(node); } - void declareVariable(VariableDeclaration variable) { + void declareVariable(Variable variable) { if (variableDeclarationsInScope.contains(variable)) { problem(variable, "Variable '$variable' declared more than once."); } @@ -330,7 +329,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { variableStack.add(variable); } - void undeclareVariable(VariableDeclaration variable) { + void undeclareVariable(Variable variable) { variableDeclarationsInScope.remove(variable); } @@ -390,7 +389,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { structuralParametersInScope.removeAll(parameters); } - void checkVariableInScope(VariableDeclaration variable, TreeNode where) { + void checkVariableInScope(Variable variable, TreeNode where) { if (!variableDeclarationsInScope.contains(variable)) { problem(where, "Variable '$variable' used out of scope."); } @@ -988,7 +987,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { positionalIndex++ ) { if (positionalIndex >= node.requiredParameterCount) { - VariableDeclaration positionalParameter = + Variable positionalParameter = node.positionalParameters[positionalIndex]; if (positionalParameter.initializer == null && // Global transformations like TFA may not maintain this @@ -1002,7 +1001,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { } } } - for (VariableDeclaration namedParameter in node.namedParameters) { + for (Variable namedParameter in node.namedParameters) { if (!namedParameter.isRequired && namedParameter.initializer == null && // Global transformations like TFA may not maintain this @@ -1160,11 +1159,11 @@ class VerifyingVisitor extends RecursiveResultVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { return _verifyVariableDeclaration(node); } - void _verifyVariableDeclaration(VariableDeclaration node) { + void _verifyVariableDeclaration(Variable node) { enterTreeNode(node); visitChildren(node); declareVariable(node.variable); @@ -1209,7 +1208,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { _verifyVariable(node); } - void _verifyVariable(VariableDeclaration node) { + void _verifyVariable(Variable node) { enterTreeNode(node); TreeNode? oldParent = enterParent(node); _visitAnnotations(node.annotations); diff --git a/pkg/kernel/lib/visitor.dart b/pkg/kernel/lib/visitor.dart index 2705e852772..ea5983e62a9 100644 --- a/pkg/kernel/lib/visitor.dart +++ b/pkg/kernel/lib/visitor.dart @@ -629,28 +629,24 @@ abstract class VariableVisitor { } /// Helper mixin for [VariableVisitor] that implements visit methods by -/// delegating to the [visitVariableDeclaration] method. +/// delegating to the [visitVariable] method. mixin VariableVisitorDefaultMixin implements VariableVisitor { - R defaultVariableDeclaration(VariableDeclaration node); + R defaultVariable(Variable node); @override - R visitLegacyVariable(LegacyVariable node) => - defaultVariableDeclaration(node); + R visitLegacyVariable(LegacyVariable node) => defaultVariable(node); @override - R visitPositionalParameter(PositionalParameter node) => - defaultVariableDeclaration(node); + R visitPositionalParameter(PositionalParameter node) => defaultVariable(node); @override - R visitNamedParameter(NamedParameter node) => - defaultVariableDeclaration(node); + R visitNamedParameter(NamedParameter node) => defaultVariable(node); @override - R visitLocalVariable(LocalVariable node) => defaultVariableDeclaration(node); + R visitLocalVariable(LocalVariable node) => defaultVariable(node); @override - R visitCatchVariable(CatchVariable node) => defaultVariableDeclaration(node); + R visitCatchVariable(CatchVariable node) => defaultVariable(node); @override - R visitThisVariable(ThisVariable node) => defaultVariableDeclaration(node); + R visitThisVariable(ThisVariable node) => defaultVariable(node); @override - R visitSyntheticVariable(SyntheticVariable node) => - defaultVariableDeclaration(node); + R visitSyntheticVariable(SyntheticVariable node) => defaultVariable(node); } abstract class MemberVisitor { @@ -888,8 +884,7 @@ abstract class TreeVisitorDefault @override R defaultStatement(Statement node) => defaultTreeNode(node); @override - R defaultVariableDeclaration(VariableDeclaration node) => - defaultTreeNode(node); + R defaultVariable(Variable node) => defaultTreeNode(node); @override R defaultInitializer(Initializer node) => defaultTreeNode(node); @override @@ -1019,8 +1014,7 @@ abstract class TreeVisitor1Default @override R defaultStatement(Statement node, A arg) => defaultTreeNode(node, arg); @override - R defaultVariableDeclaration(VariableDeclaration node, A arg) => - defaultTreeNode(node, arg); + R defaultVariable(Variable node, A arg) => defaultTreeNode(node, arg); @override R defaultInitializer(Initializer node, A arg) => defaultTreeNode(node, arg); @override @@ -2225,10 +2219,8 @@ class RemovingTransformer extends TreeVisitor1Default { /// supported with `null` as the result. /// /// This is convenience method for calling [transformOrRemove] with removal - /// sentinel for [VariableDeclaration] nodes. - VariableDeclaration? transformOrRemoveVariableDeclaration( - VariableDeclaration node, - ) { + /// sentinel for [Variable] nodes. + Variable? transformOrRemoveVariableDeclaration(Variable node) { return transformOrRemove(node, dummyVariableDeclaration); } @@ -2450,15 +2442,12 @@ class RemovingTransformer extends TreeVisitor1Default { transformList(nodes, parent, dummyTypeParameter); } - /// Transforms or removes [VariableDeclaration] nodes in [nodes] as children + /// Transforms or removes [Variable] nodes in [nodes] as children /// of [parent]. /// /// This is convenience method for calling [transformList] with removal - /// sentinel for [VariableDeclaration] nodes. - void transformVariableDeclarationList( - List nodes, - TreeNode parent, - ) { + /// sentinel for [Variable] nodes. + void transformVariableDeclarationList(List nodes, TreeNode parent) { transformList(nodes, parent, dummyVariableDeclaration); } @@ -2963,31 +2952,28 @@ abstract class VariableVisitor1 { } /// Helper mixin for [VariableVisitor1] that implements visit methods by -/// delegating to the [visitVariableDeclaration] method. +/// delegating to the [defaultVariable] method. mixin VariableVisitor1DefaultMixin implements VariableVisitor1 { - R defaultVariableDeclaration(VariableDeclaration node, A arg); + R defaultVariable(Variable node, A arg); @override R visitLegacyVariable(LegacyVariable node, A arg) => - defaultVariableDeclaration(node, arg); + defaultVariable(node, arg); @override R visitPositionalParameter(PositionalParameter node, A arg) => - defaultVariableDeclaration(node, arg); + defaultVariable(node, arg); @override R visitNamedParameter(NamedParameter node, A arg) => - defaultVariableDeclaration(node, arg); + defaultVariable(node, arg); @override - R visitLocalVariable(LocalVariable node, A arg) => - defaultVariableDeclaration(node, arg); + R visitLocalVariable(LocalVariable node, A arg) => defaultVariable(node, arg); @override - R visitCatchVariable(CatchVariable node, A arg) => - defaultVariableDeclaration(node, arg); + R visitCatchVariable(CatchVariable node, A arg) => defaultVariable(node, arg); @override - R visitThisVariable(ThisVariable node, A arg) => - defaultVariableDeclaration(node, arg); + R visitThisVariable(ThisVariable node, A arg) => defaultVariable(node, arg); @override R visitSyntheticVariable(SyntheticVariable node, A arg) => - defaultVariableDeclaration(node, arg); + defaultVariable(node, arg); } /// [DartTypeVisitorExperimentExclusionMixin] is intended to reduce the effects @@ -3231,20 +3217,20 @@ mixin StatementVisitorExperimentExclusionMixin ); } - /// Since [VariableDeclaration] is abstract due to an experiment, it doesn't + /// Since [Variable] is abstract due to an experiment, it doesn't /// have its own visit method in [StatementVisitor]. However, for the /// transitional period the backends would rely on having - /// [visitVariableDeclaration] and on needing to override it. Since the + /// [visitVariable] and on needing to override it. Since the /// statement visitors in the backends should mix in /// [StatementVisitorExperimentExclusionMixin], we can deliver the abstract - /// declaration of [visitVariableDeclaration] to them via the mixin. At the + /// declaration of [visitVariable] to them via the mixin. At the /// same time, it allows us to redirect [visitVariableStatement] to the - /// overrides of [visitVariableDeclarations] the backends already have. - R visitVariableDeclaration(VariableDeclaration node); + /// overrides of [visitVariable] the backends already have. + R visitVariable(Variable node); @override R visitLegacyVariableStatement(LegacyVariableStatement node) { - return visitVariableDeclaration(node.variable); + return visitVariable(node.variable); } } @@ -3255,19 +3241,19 @@ mixin StatementVisitorExperimentExclusionMixin /// nodes. The methods throw an exception signaling that the experimental nodes /// aren't supported. mixin VariableVisitorExperimentExclusionMixin implements VariableVisitor { - /// Since [VariableDeclaration] is abstract due to an experiment, it doesn't + /// Since [Variable] is abstract due to an experiment, it doesn't /// have its own visit method in [VariableVisitor]. However, for the /// transitional period the backends would rely on having - /// [visitVariableDeclaration] and on needing to override it. Since the + /// [visitVariable] and on needing to override it. Since the /// statement visitors in the backends should mix in /// [VariableVisitorExperimentExclusionMixin], we can deliver the abstract - /// declaration of [visitVariableDeclaration] to them via the mixin. At the + /// declaration of [visitVariable] to them via the mixin. At the /// same time, it allows us to redirect [visitVariableStatement] to the - /// overrides of [visitVariableDeclarations] the backends already have. - R visitVariableDeclaration(VariableDeclaration node); + /// overrides of [visitVariable] the backends already have. + R visitVariable(Variable node); @override - R visitLegacyVariable(LegacyVariable node) => visitVariableDeclaration(node); + R visitLegacyVariable(LegacyVariable node) => visitVariable(node); @override R visitPositionalParameter(PositionalParameter node) { @@ -3317,7 +3303,7 @@ mixin StatementVisitor1ExperimentExclusionMixin ); } - /// Since [VariableDeclaration] is abstract due to an experiment, it doesn't + /// Since [Variable] is abstract due to an experiment, it doesn't /// have its own visit method in [StatementVisitor1]. However, for the /// transitional period the backends would rely on having /// [visitVariableDeclaration] and on needing to override it. Since the @@ -3326,7 +3312,7 @@ mixin StatementVisitor1ExperimentExclusionMixin /// declaration of [visitVariableDeclaration] to them via the mixin. At the /// same time, it allows us to redirect [visitVariableStatement] to the /// overrides of [visitVariableDeclarations] the backends already have. - R visitVariableDeclaration(VariableDeclaration node, A arg); + R visitVariableDeclaration(Variable node, A arg); @override R visitLegacyVariableStatement(LegacyVariableStatement node, A arg) { diff --git a/pkg/kernel/test/class_hierarchy_test.dart b/pkg/kernel/test/class_hierarchy_test.dart index f51e055dd58..469aec65d84 100644 --- a/pkg/kernel/test/class_hierarchy_test.dart +++ b/pkg/kernel/test/class_hierarchy_test.dart @@ -507,7 +507,7 @@ class H extends self::G implements self::C, self::A {} new FunctionNode( body, returnType: const VoidType(), - positionalParameters: [new VariableDeclaration('_', type: type)], + positionalParameters: [new Variable('_', type: type)], ), fileUri: library.fileUri, ); diff --git a/pkg/kernel/test/convert_field_to_setter_getter_test.dart b/pkg/kernel/test/convert_field_to_setter_getter_test.dart index ff689ec349f..1175deb0375 100644 --- a/pkg/kernel/test/convert_field_to_setter_getter_test.dart +++ b/pkg/kernel/test/convert_field_to_setter_getter_test.dart @@ -82,7 +82,7 @@ void main() { FunctionNode setterFunction = new FunctionNode( new Block([]), - positionalParameters: [new VariableDeclaration("foo")], + positionalParameters: [new Variable("foo")], ); Procedure setter = new Procedure( new Name("f"), diff --git a/pkg/kernel/test/generalized_tracking_test.dart b/pkg/kernel/test/generalized_tracking_test.dart index fa15633c3cc..eee2e8bad02 100644 --- a/pkg/kernel/test/generalized_tracking_test.dart +++ b/pkg/kernel/test/generalized_tracking_test.dart @@ -25,10 +25,10 @@ void main() { new FunctionNode( null, namedParameters: [ - new VariableDeclaration('file', type: const DynamicType()), - new VariableDeclaration('line', type: const DynamicType()), - new VariableDeclaration('column', type: const DynamicType()), - new VariableDeclaration('name', type: const DynamicType()), + new Variable('file', type: const DynamicType()), + new Variable('line', type: const DynamicType()), + new Variable('column', type: const DynamicType()), + new Variable('name', type: const DynamicType()), ], ), name: new Name('_', developerLib), diff --git a/pkg/kernel/test/verify_test.dart b/pkg/kernel/test/verify_test.dart index 02647f4b131..859087aa066 100644 --- a/pkg/kernel/test/verify_test.dart +++ b/pkg/kernel/test/verify_test.dart @@ -27,7 +27,7 @@ void main() { negative1Test( 'VariableGet out of scope', (TestHarness test) { - VariableDeclaration node = test.makeVariable(); + Variable node = test.makeVariable(); test.addNode(VariableGet(node)); return node; }, @@ -36,7 +36,7 @@ void main() { negative1Test( 'VariableSet out of scope', (TestHarness test) { - VariableDeclaration variable = test.makeVariable(); + Variable variable = test.makeVariable(); test.addNode(VariableSet(variable, new NullLiteral())); return variable; }, @@ -45,7 +45,7 @@ void main() { negative1Test( 'Variable block scope', (TestHarness test) { - VariableDeclaration variable = test.makeVariable(); + Variable variable = test.makeVariable(); test.addNode( Block([ new Block([new VariableStatement(variable)]), @@ -59,7 +59,7 @@ void main() { negative1Test( 'Variable let scope', (TestHarness test) { - VariableDeclaration variable = test.makeVariable(); + Variable variable = test.makeVariable(); test.addNode( LogicalExpression( new Let(variable, new VariableGet(variable)), @@ -74,7 +74,7 @@ void main() { negative1Test( 'Variable redeclared', (TestHarness test) { - VariableDeclaration variable = test.makeVariable(); + Variable variable = test.makeVariable(); test.addNode( Procedure( new Name('bar'), @@ -362,7 +362,7 @@ void main() { ProcedureKind.Method, new FunctionNode( new EmptyStatement(), - positionalParameters: [new VariableDeclaration('p')], + positionalParameters: [new Variable('p')], ), isStatic: true, fileUri: dummyUri, @@ -398,7 +398,7 @@ void main() { ProcedureKind.Method, new FunctionNode( new EmptyStatement(), - positionalParameters: [new VariableDeclaration('p')], + positionalParameters: [new Variable('p')], ), isStatic: true, fileUri: dummyUri, @@ -1006,8 +1006,7 @@ class TestHarness { enclosingLibrary.addTypedef(node); } - VariableDeclaration makeVariable() => - new VariableDeclaration(null, isSynthesized: true); + Variable makeVariable() => new Variable(null, isSynthesized: true); TypeParameter makeTypeParameter([String? name]) { return new TypeParameter(name, objectRawType, const DynamicType()); diff --git a/pkg/vm/lib/embedder/shims.dart b/pkg/vm/lib/embedder/shims.dart index 61834995687..80ddb164e80 100644 --- a/pkg/vm/lib/embedder/shims.dart +++ b/pkg/vm/lib/embedder/shims.dart @@ -127,7 +127,7 @@ class EntryPointShimValueParameter extends EntryPointShimParameter { EntryPointShimValueParameter._(String name, {super.type}) : super._('v_' + name); - factory EntryPointShimValueParameter.fromDeclaration(VariableDeclaration v) { + factory EntryPointShimValueParameter.fromDeclaration(Variable v) { return EntryPointShimValueParameter._(v.name ?? gensym, type: v.type); } } diff --git a/pkg/vm/lib/modular/transformations/call_site_annotator.dart b/pkg/vm/lib/modular/transformations/call_site_annotator.dart index b6ce4ac5084..6641972ce10 100644 --- a/pkg/vm/lib/modular/transformations/call_site_annotator.dart +++ b/pkg/vm/lib/modular/transformations/call_site_annotator.dart @@ -106,9 +106,9 @@ class AnnotateWithStaticTypes extends RecursiveVisitor { } } - /// Return [true] if the given list of [VariableDeclaration] contains + /// Return [true] if the given list of [Variable] contains /// any annotated with generic-covariant-impl. - static bool containsGenericCovariantImpl(List decls) => + static bool containsGenericCovariantImpl(List decls) => decls.any((p) => p.isCovariantByClass); /// Returns [true] if the given [member] has any parameters annotated with diff --git a/pkg/vm/lib/modular/transformations/ffi/definitions.dart b/pkg/vm/lib/modular/transformations/ffi/definitions.dart index 9e61a4c18a1..a84e7dc5a6b 100644 --- a/pkg/vm/lib/modular/transformations/ffi/definitions.dart +++ b/pkg/vm/lib/modular/transformations/ffi/definitions.dart @@ -590,12 +590,12 @@ class _FfiDefinitionTransformer extends FfiTransformer { /// #fromTypedDataBase(Object #typedDataBase, int #offsetInBytes) : /// super._fromTypedDataBase(#typedDataBase, #offsetInBytes); /// ``` - final VariableDeclaration typedDataBase = VariableDeclaration( + final Variable typedDataBase = Variable( "#typedDataBase", type: coreTypes.objectNonNullableRawType, isSynthesized: true, ); - final VariableDeclaration offsetInBytes = VariableDeclaration( + final Variable offsetInBytes = Variable( "#offsetInBytes", type: coreTypes.intNonNullableRawType, isSynthesized: true, @@ -636,7 +636,7 @@ class _FfiDefinitionTransformer extends FfiTransformer { /// super.sizeInBytes, /// ) : super._fromTypedData(); /// ``` - final VariableDeclaration typedData = VariableDeclaration( + final Variable typedData = Variable( "#typedData", type: InterfaceType( typedDataClass, @@ -645,12 +645,12 @@ class _FfiDefinitionTransformer extends FfiTransformer { ), isSynthesized: true, ); - final VariableDeclaration offset = VariableDeclaration( + final Variable offset = Variable( "#offset", type: coreTypes.intNonNullableRawType, isSynthesized: true, ); - final VariableDeclaration sizeInBytes = VariableDeclaration( + final Variable sizeInBytes = Variable( "#sizeInBytes", type: coreTypes.intNonNullableRawType, isSynthesized: true, @@ -1095,7 +1095,7 @@ class _FfiDefinitionTransformer extends FfiTransformer { setterReference == field.setterReference, "Unexpected setter reference for ${field}, found $setterReference.", ); - final VariableDeclaration argument = VariableDeclaration( + final Variable argument = Variable( '#v', type: field.type, isSynthesized: true, diff --git a/pkg/vm/lib/modular/transformations/ffi/finalizable.dart b/pkg/vm/lib/modular/transformations/ffi/finalizable.dart index 88fd45dc3f8..62ae6676c3a 100644 --- a/pkg/vm/lib/modular/transformations/ffi/finalizable.dart +++ b/pkg/vm/lib/modular/transformations/ffi/finalizable.dart @@ -253,7 +253,7 @@ mixin FinalizableTransformer on Transformer { return inScope(node, () => super.visitSwitchStatement(node)); } - bool _possiblyUninitialized(VariableDeclaration declaration) { + bool _possiblyUninitialized(Variable declaration) { if (declaration.isLate) { // Also mark late variables with initializers as uninitialized. // Otherwise we would would start running the initializer in a fence. @@ -271,15 +271,15 @@ mixin FinalizableTransformer on Transformer { } @override - TreeNode defaultVariableDeclaration(VariableDeclaration node) { - node = super.defaultVariableDeclaration(node) as VariableDeclaration; + TreeNode defaultVariable(Variable node) { + node = super.defaultVariable(node) as Variable; if (_currentScope == null) { // Global variable. return node; } if (_isFinalizable(node.type)) { if (_possiblyUninitialized(node)) { - final alwaysInitializedDeclaration = VariableDeclaration( + final alwaysInitializedDeclaration = Variable( ':${node.name}:finalizableValue', type: node.type.withDeclaredNullability(Nullability.nullable), ); @@ -553,7 +553,7 @@ mixin FinalizableTransformer on Transformer { Expression expression, List declarations, ) { - final resultVariable = VariableDeclaration( + final resultVariable = Variable( ":expressionValueWrappedFinalizable", initializer: expression, type: staticTypeContext!.getExpressionType(expression), @@ -647,11 +647,11 @@ class FindCaptures extends RecursiveVisitor { } @override - void defaultVariableDeclaration(VariableDeclaration node) { + void defaultVariable(Variable node) { if (_isFinalizable(node.type)) { _currentScope.addDeclaration(node); } - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override @@ -695,16 +695,15 @@ class _Scope { /// like to prevent arbitrary reorderings when generating code from this. /// /// Includes [_possiblyUninitializedDeclarations] keys. - final List _declarations = []; + final List _declarations = []; /// The late and non-nullable Finalizable declarations in this scope mapped /// to nullable non-late variables that contain the same value. /// /// The map is mutable, because we populate it during visiting statements. - final Map - _possiblyUninitializedDeclarations = {}; + final Map _possiblyUninitializedDeclarations = {}; - /// [ThisExpression] is not a [VariableDeclaration] and needs to be tracked + /// [ThisExpression] is not a [Variable] and needs to be tracked /// separately. final bool declaresThis; @@ -736,22 +735,22 @@ ${parent?.toStringIndented(indentation: indentation + 2)} return nonIndented.replaceAll('\n', (' ' * indentation) + '\n'); } - void addDeclaration(VariableDeclaration declaration) { + void addDeclaration(Variable declaration) { _declarations.add(declaration); allDeclarationsIsEmpty = false; } void addPossiblyUninitializedDeclaration( - VariableDeclaration possiblyUninitialized, - VariableDeclaration nullableValue, + Variable possiblyUninitialized, + Variable nullableValue, ) { assert(possiblyUninitialized.parent is VariableStatement); _possiblyUninitializedDeclarations[possiblyUninitialized] = nullableValue; addDeclaration(possiblyUninitialized); } - VariableDeclaration? alwaysInitializedDeclaration( - VariableDeclaration possiblyUninitialized, { + Variable? alwaysInitializedDeclaration( + Variable possiblyUninitialized, { required bool checkAncestorScopes, }) { final resultThisScope = @@ -768,8 +767,8 @@ ${parent?.toStringIndented(indentation: indentation + 2)} ); } - VariableDeclaration variableToFence( - VariableDeclaration declaration, { + Variable variableToFence( + Variable declaration, { required bool checkAncestorScopes, }) { final possibleValueToFence = alwaysInitializedDeclaration( @@ -791,7 +790,7 @@ ${parent?.toStringIndented(indentation: indentation + 2)} /// All declarations in this and parent scopes. /// /// Excluding `this`. - List get allDeclarations => [ + List get allDeclarations => [ ...?parent?.allDeclarations, ..._declarations, ]; @@ -806,9 +805,9 @@ ${parent?.toStringIndented(indentation: indentation + 2)} return parent?.capturingScope; }(); - Map? _captures; + Map? _captures; - Map get captures { + Map get captures { if (_captures != null) { return _captures!; } @@ -820,7 +819,7 @@ ${parent?.toStringIndented(indentation: indentation + 2)} bool _capturesThis = false; - void addCapture(VariableDeclaration declaration) { + void addCapture(Variable declaration) { final capturingScope_ = capturingScope; if (capturingScope_ == null) { // We're not in a nested closure. diff --git a/pkg/vm/lib/modular/transformations/ffi/native.dart b/pkg/vm/lib/modular/transformations/ffi/native.dart index 49c22d6be56..053a7a19b50 100644 --- a/pkg/vm/lib/modular/transformations/ffi/native.dart +++ b/pkg/vm/lib/modular/transformations/ffi/native.dart @@ -257,7 +257,7 @@ class FfiNativeTransformer extends FfiTransformer { !env.isSubtypeOf(dartParameterType, pointerVoidType)); } - VariableDeclaration _declareTemporary( + Variable _declareTemporary( Expression initializer, DartType dartParameterType, DartType ffiParameterType, @@ -266,7 +266,7 @@ class FfiNativeTransformer extends FfiTransformer { (_requiresPointerConversion(dartParameterType, ffiParameterType) ? nativeFieldWrapperClass1Type : dartParameterType); - return VariableDeclaration( + return Variable( variableDeclarationTemporaryName, initializer: initializer, type: wrappedType, @@ -276,7 +276,7 @@ class FfiNativeTransformer extends FfiTransformer { } Expression _getTemporary( - VariableDeclaration temporary, + Variable temporary, DartType dartParameterType, DartType ffiParameterType, { required bool checkForNullptr, @@ -288,7 +288,7 @@ class FfiNativeTransformer extends FfiTransformer { ); if (checkForNullptr) { - final pointerAddressVar = VariableDeclaration( + final pointerAddressVar = Variable( "#pointerAddress", initializer: pointerAddress, type: coreTypes.intNonNullableRawType, @@ -401,7 +401,7 @@ class FfiNativeTransformer extends FfiTransformer { } // final T #t1 = foo(Pointer.fromAddress(_getNativeField(#t0))); - final result = VariableDeclaration( + final result = Variable( variableDeclarationTemporaryName, initializer: resultInitializer, type: dartFunctionType.returnType, @@ -613,10 +613,8 @@ class FfiNativeTransformer extends FfiTransformer { positionalParameters: [ for (final positionalParameter in wrappedDartFunctionType.positionalParameters) - VariableDeclaration( - /*name=*/ '#t${varCounter++}', - type: positionalParameter, - )..fileOffset = node.fileOffset, + Variable(/*name=*/ '#t${varCounter++}', type: positionalParameter) + ..fileOffset = node.fileOffset, ], returnType: wrappedDartFunctionType.returnType, )..fileOffset = node.fileOffset, diff --git a/pkg/vm/lib/modular/transformations/ffi/native_type_cfe.dart b/pkg/vm/lib/modular/transformations/ffi/native_type_cfe.dart index 5716b5b211f..977a40cb7be 100644 --- a/pkg/vm/lib/modular/transformations/ffi/native_type_cfe.dart +++ b/pkg/vm/lib/modular/transformations/ffi/native_type_cfe.dart @@ -181,7 +181,7 @@ sealed class NativeTypeCfe { /// [offsetInBytes] and [unaligned] based on the ABI of the struct. It also /// wraps the expression in a return statement. Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, @@ -234,7 +234,7 @@ sealed class NativeTypeCfe { DartType dartType, int fileOffset, bool unalignedAccess, - VariableDeclaration argument, + Variable argument, FfiTransformer transformer, Procedure offsetGetter, ) { @@ -289,7 +289,7 @@ final class InvalidNativeTypeCfe extends NativeTypeCfe { @override Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, @@ -396,7 +396,7 @@ class PrimitiveNativeTypeCfe extends NativeTypeCfe { /// ``` @override Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, @@ -483,7 +483,7 @@ class PointerNativeTypeCfe extends NativeTypeCfe { /// ``` @override Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, @@ -582,7 +582,7 @@ abstract mixin class _CompoundLoadAndStoreMixin implements NativeTypeCfe { /// ``` @override Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, @@ -896,7 +896,7 @@ class ArrayNativeTypeCfe extends NativeTypeCfe { /// ``` @override Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, @@ -985,7 +985,7 @@ class AbiSpecificNativeTypeCfe extends NativeTypeCfe { @override Expression generateStore( - VariableDeclaration value, { + Variable value, { required DartType dartType, required int fileOffset, required Expression typedDataBase, diff --git a/pkg/vm/lib/modular/transformations/ffi/use_sites.dart b/pkg/vm/lib/modular/transformations/ffi/use_sites.dart index 42a1d09214d..88de750b20b 100644 --- a/pkg/vm/lib/modular/transformations/ffi/use_sites.dart +++ b/pkg/vm/lib/modular/transformations/ffi/use_sites.dart @@ -372,13 +372,13 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final nativeTypeCfe = NativeTypeCfe(this, typeArg) as AbiSpecificNativeTypeCfe; - final arrayVar = VariableDeclaration( + final arrayVar = Variable( "#array", initializer: NullCheck(node.arguments.positional[0]), type: InterfaceType(arrayClass, Nullability.nonNullable), isSynthesized: true, )..fileOffset = node.fileOffset; - final indexVar = VariableDeclaration( + final indexVar = Variable( "#index", initializer: NullCheck(node.arguments.positional[1]), type: coreTypes.intNonNullableRawType, @@ -858,7 +858,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final closureName = '#ffiClosure$callCount'; ++callCount; - final pointerVar = VariableDeclaration( + final pointerVar = Variable( functionPointerVarName, initializer: functionPointer, type: pointerType, @@ -868,14 +868,11 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final positionalParameters = [ for (int i = 0; i < dartSignature.positionalParameters.length; ++i) - VariableDeclaration( - 'arg${i + 1}', - type: dartSignature.positionalParameters[i], - ), + Variable('arg${i + 1}', type: dartSignature.positionalParameters[i]), ]; final closure = FunctionDeclaration( - VariableDeclaration(closureName, type: dartSignature, isSynthesized: true) + Variable(closureName, type: dartSignature, isSynthesized: true) ..addAnnotation( ConstantExpression( InstanceConstant(coreTypes.pragmaClass.reference, [], { @@ -1126,7 +1123,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final targetType = node.arguments.types[0] as FunctionType; // void _handler(List args) => target(args[0], args[1], ...) - final args = VariableDeclaration('args', type: listType, isFinal: true) + final args = Variable('args', type: listType, isFinal: true) ..fileOffset = node.fileOffset; final targetArgs = []; for (int i = 0; i < targetType.positionalParameters.length; ++i) { @@ -1161,7 +1158,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { )..fileOffset = node.fileOffset; // final _callback = NativeCallable._listener(_handler, debugName); - final nativeCallable = VariableDeclaration.forValue( + final nativeCallable = Variable.forValue( ConstructorInvocation( nativeCallablePrivateListenerConstructor, Arguments( @@ -1499,7 +1496,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { targetOffset = ConstantExpression(IntConstant(0)); } - final sourceVar = VariableDeclaration( + final sourceVar = Variable( "#source", initializer: sourceStruct, type: sourceStructType, @@ -1573,13 +1570,13 @@ mixin _FfiUseSiteTransformer on FfiTransformer { (c) => c.name == Name("#fromTypedDataBase"), ); - final arrayVar = VariableDeclaration( + final arrayVar = Variable( "#array", initializer: NullCheck(node.arguments.positional[0]), type: InterfaceType(arrayClass, Nullability.nonNullable), isSynthesized: true, )..fileOffset = node.fileOffset; - final indexVar = VariableDeclaration( + final indexVar = Variable( "#index", initializer: NullCheck(node.arguments.positional[1]), type: coreTypes.intNonNullableRawType, @@ -1688,12 +1685,12 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final nativeTypeCfe = NativeTypeCfe(this, typeArg) as AbiSpecificNativeTypeCfe; - final arrayLoadVar = VariableDeclaration( + final arrayLoadVar = Variable( "#array", type: InterfaceType(arrayClass, Nullability.nonNullable, [typeArg]), isSynthesized: true, )..fileOffset = node.fileOffset; - final indexLoadVar = VariableDeclaration( + final indexLoadVar = Variable( "#index", type: coreTypes.intNonNullableRawType, isSynthesized: true, @@ -1720,17 +1717,17 @@ mixin _FfiUseSiteTransformer on FfiTransformer { ), ); - final arrayStoreVar = VariableDeclaration( + final arrayStoreVar = Variable( "#array", type: InterfaceType(arrayClass, Nullability.nonNullable, [typeArg]), isSynthesized: true, )..fileOffset = node.fileOffset; - final indexStoreVar = VariableDeclaration( + final indexStoreVar = Variable( "#index", type: coreTypes.intNonNullableRawType, isSynthesized: true, )..fileOffset = node.fileOffset; - final valueStoreVar = VariableDeclaration( + final valueStoreVar = Variable( "#value", type: coreTypes.intNullableRawType, isSynthesized: true, @@ -1817,25 +1814,25 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final dartType = node.arguments.types[0]; final elementType = arraySingleElementType(dartType as InterfaceType); - final arrayVar = VariableDeclaration( + final arrayVar = Variable( "#array", initializer: NullCheck(node.arguments.positional[0]), type: InterfaceType(arrayClass, Nullability.nonNullable), isSynthesized: true, )..fileOffset = node.fileOffset; - final indexVar = VariableDeclaration( + final indexVar = Variable( "#index", initializer: NullCheck(node.arguments.positional[1]), type: coreTypes.intNonNullableRawType, isSynthesized: true, )..fileOffset = node.fileOffset; - final singleElementSizeVar = VariableDeclaration( + final singleElementSizeVar = Variable( "#singleElementSize", initializer: inlineSizeOf(elementType as InterfaceType), type: coreTypes.intNonNullableRawType, isSynthesized: true, )..fileOffset = node.fileOffset; - final elementSizeVar = VariableDeclaration( + final elementSizeVar = Variable( "#elementSize", initializer: multiply( VariableGet(singleElementSizeVar), @@ -1850,7 +1847,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { type: coreTypes.intNonNullableRawType, isSynthesized: true, )..fileOffset = node.fileOffset; - final offsetVar = VariableDeclaration( + final offsetVar = Variable( "#offset", initializer: multiply(VariableGet(elementSizeVar), VariableGet(indexVar)), type: coreTypes.intNonNullableRawType, @@ -1923,7 +1920,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { } // `[]=` - final valueVar = VariableDeclaration( + final valueVar = Variable( "#value", initializer: NullCheck(node.arguments.positional[2]), type: InterfaceType(arrayClass, Nullability.nonNullable), @@ -2127,7 +2124,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { final numParams = parameterTypes.length; String methodPostfix = ''; final newArguments = []; - final newParameters = []; + final newParameters = []; bool isTransformed = false; for (int i = 0; i < numParams; i++) { final parameter = target.function.positionalParameters[i]; @@ -2147,7 +2144,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { if (postFix == 'C' || postFix == 'E' || postFix == 'T') { isTransformed = true; } - newParameters.add(VariableDeclaration(parameter.name, type: newType)); + newParameters.add(Variable(parameter.name, type: newType)); newArguments.add(newArgument); } @@ -2205,7 +2202,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { Expression argument, ) _replaceNativeCallParameterAndArgument( - VariableDeclaration parameter, + Variable parameter, DartType parameterType, Expression argument, int fileOffset, @@ -2433,7 +2430,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer { const [], ); - final valueVar = VariableDeclaration( + final valueVar = Variable( variableName, initializer: compound, type: compoundType, diff --git a/pkg/vm/lib/modular/transformations/for_in_lowering.dart b/pkg/vm/lib/modular/transformations/for_in_lowering.dart index 8d67a25fef9..915fe15d861 100644 --- a/pkg/vm/lib/modular/transformations/for_in_lowering.dart +++ b/pkg/vm/lib/modular/transformations/for_in_lowering.dart @@ -74,7 +74,7 @@ class ForInLowering { // } final valueVariable = stmt.variable; - final streamVariable = new VariableDeclaration( + final streamVariable = new Variable( ForInVariables.stream, initializer: stmt.iterable, type: stmt.iterable.getStaticType(staticTypeContext), @@ -86,7 +86,7 @@ class ForInLowering { staticTypeContext.nullable, [valueVariable.type], ); - final forIteratorVariable = VariableDeclaration( + final forIteratorVariable = Variable( ForInVariables.forIterator, initializer: new ConstructorInvocation( coreTypes.streamIteratorDefaultConstructor, @@ -124,7 +124,7 @@ class ForInLowering { // let _ = asyncStarMoveNextCall in (condition) whileCondition = new Let( - new VariableDeclaration( + new Variable( null, initializer: asyncStarMoveNextCall, isSynthesized: true, @@ -292,8 +292,7 @@ class ForInLowering { ]); } - (VariableDeclaration, Statement) - _createSyncForIteratorVariableAndInitialization({ + (Variable, Statement) _createSyncForIteratorVariableAndInitialization({ required Expression initializer, required DartType type, required int fileOffset, @@ -309,7 +308,7 @@ class ForInLowering { ); return (variable, initialization); } else { - final variableAndInitialization = VariableDeclaration( + final variableAndInitialization = Variable( ForInVariables.syncForIterator, initializer: initializer, type: type, @@ -323,7 +322,7 @@ class ForInLowering { } Statement _ensureSyncForLoopVariableInitialization({ - required VariableDeclaration variable, + required Variable variable, required Expression initializer, }) { if (isClosureContextLoweringEnabled) { diff --git a/pkg/vm/lib/modular/transformations/late_var_init_transformer.dart b/pkg/vm/lib/modular/transformations/late_var_init_transformer.dart index bfb6a01aebe..459013c6eb9 100644 --- a/pkg/vm/lib/modular/transformations/late_var_init_transformer.dart +++ b/pkg/vm/lib/modular/transformations/late_var_init_transformer.dart @@ -45,7 +45,7 @@ class LateVarInitTransformer { Nullability.nonNullable, ); final fn = FunctionDeclaration( - VariableDeclaration( + Variable( "#${node.variable.name}#initializer", type: functionType, isSynthesized: true, diff --git a/pkg/vm/lib/modular/transformations/mixin_full_resolution.dart b/pkg/vm/lib/modular/transformations/mixin_full_resolution.dart index 277fc7d96be..1503f46dce5 100644 --- a/pkg/vm/lib/modular/transformations/mixin_full_resolution.dart +++ b/pkg/vm/lib/modular/transformations/mixin_full_resolution.dart @@ -177,8 +177,7 @@ class MixinFullResolution { Procedure? setter = setters[field.name]; if (setter != null) { setters.remove(field.name); - VariableDeclaration parameter = - setter.function.positionalParameters.first; + Variable parameter = setter.function.positionalParameters.first; clone.isCovariantByDeclaration = parameter.isCovariantByDeclaration; clone.isCovariantByClass = parameter.isCovariantByClass; } diff --git a/pkg/vm/lib/modular/transformations/type_casts_optimizer.dart b/pkg/vm/lib/modular/transformations/type_casts_optimizer.dart index 309c55901ed..92e3d90b10c 100644 --- a/pkg/vm/lib/modular/transformations/type_casts_optimizer.dart +++ b/pkg/vm/lib/modular/transformations/type_casts_optimizer.dart @@ -32,7 +32,7 @@ TreeNode transformAsExpression( if (canBeReducedToNullCheckAndCast(node, operandType, env)) { // Transform 'x as T' to 'Let tmp = x in (tmp == null) ? tmp as T : tmp'. - final tmp = VariableDeclaration( + final tmp = Variable( null, initializer: node.operand, type: operandType, diff --git a/pkg/vm/lib/transformations/type_flow/analysis.dart b/pkg/vm/lib/transformations/type_flow/analysis.dart index 5c9057d855c..6349a078a8d 100644 --- a/pkg/vm/lib/transformations/type_flow/analysis.dart +++ b/pkg/vm/lib/transformations/type_flow/analysis.dart @@ -2023,8 +2023,7 @@ class TypeFlowAnalysis final Map _summaries = {}; final Map _fieldValues = {}; - final Map _sharedCapturedVariables = - {}; + final Map _sharedCapturedVariables = {}; final Map _sharedCapturedThisVariables = {}; final Map _closureByCallMethod = {}; final Map _callMethodByClosure = {}; @@ -2177,16 +2176,15 @@ class TypeFlowAnalysis Type? fieldType(Field field) => _fieldValues[field]?.value; - Type? capturedVariableType(VariableDeclaration v) => - _sharedCapturedVariables[v]?.value; + Type? capturedVariableType(Variable v) => _sharedCapturedVariables[v]?.value; Args? argumentTypes(Member member) => _summaries[member]?.argumentTypes; - Type? argumentType(Member member, VariableDeclaration memberParam) { + Type? argumentType(Member member, Variable memberParam) { return _summaries[member]?.argumentType(member, memberParam); } - List? uncheckedParameters(Member member) => + List? uncheckedParameters(Member member) => _summaries[member]?.uncheckedParameters; Type? resultType(Member member) => _summaries[member]?.resultType; @@ -2368,7 +2366,7 @@ class TypeFlowAnalysis /// ---- Implementation of [SharedVariableBuilder] interface. ---- @override - SharedVariable getSharedVariable(VariableDeclaration variable) => + SharedVariable getSharedVariable(Variable variable) => _sharedCapturedVariables[variable] ??= _SharedVariableImpl( variable.name ?? '__tmp', ); diff --git a/pkg/vm/lib/transformations/type_flow/signature_shaking.dart b/pkg/vm/lib/transformations/type_flow/signature_shaking.dart index 4a9f560ce76..68d06baebe3 100644 --- a/pkg/vm/lib/transformations/type_flow/signature_shaking.dart +++ b/pkg/vm/lib/transformations/type_flow/signature_shaking.dart @@ -186,11 +186,7 @@ class _ParameterInfo { bool get canBeEliminated => (!isUsed || (isNeverPassed || isConstant && !isChecked) && !isWritten); - void observeParameter( - Member member, - VariableDeclaration param, - SignatureShaker shaker, - ) { + void observeParameter(Member member, Variable param, SignatureShaker shaker) { final Type? type = shaker.typeFlowAnalysis.argumentType(member, param); // A parameter is considered constant if the TFA has inferred it to have a @@ -231,7 +227,7 @@ class _Collect extends RecursiveVisitor { final CoreTypes coreTypes; /// Parameters of the current function. - final Map localParameters = {}; + final Map localParameters = {}; /// Set of [VariableGet] nodes corresponding to parameters in the current /// function which are passed as arguments to eligible calls. They are tracked @@ -249,11 +245,11 @@ class _Collect extends RecursiveVisitor { useDependencies.clear(); final FunctionNode fun = member.function!; for (int i = 0; i < fun.positionalParameters.length; i++) { - final VariableDeclaration param = fun.positionalParameters[i]; + final Variable param = fun.positionalParameters[i]; localParameters[param] = info.ensurePositional(i) ..observeParameter(member, param, shaker); } - for (VariableDeclaration param in fun.namedParameters) { + for (Variable param in fun.namedParameters) { localParameters[param] = info.ensureNamed(param.name!) ..observeParameter(member, param, shaker); } @@ -370,8 +366,8 @@ class _Transform extends RecursiveVisitor { final SignatureShaker shaker; late StaticTypeContext typeContext; - final Map eliminatedParams = {}; - final Set unusedParams = {}; + final Map eliminatedParams = {}; + final Set unusedParams = {}; final List addedInitializers = []; _Transform(this.shaker); @@ -379,7 +375,7 @@ class _Transform extends RecursiveVisitor { void eliminateUsedParameter( Member member, _ParameterInfo param, - VariableDeclaration variable, + Variable variable, ) { Constant value; if (param.isConstant) { @@ -414,8 +410,8 @@ class _Transform extends RecursiveVisitor { if (!info.transformNeeded(function)) return; - final List positional = []; - final List named = []; + final List positional = []; + final List named = []; // 1. All positional parameters that are always passed and can't be // eliminated, as required positional parameters. int firstNotAlwaysPassed = function.positionalParameters.length; @@ -425,7 +421,7 @@ class _Transform extends RecursiveVisitor { firstNotAlwaysPassed = i; break; } - final VariableDeclaration variable = function.positionalParameters[i]; + final Variable variable = function.positionalParameters[i]; if (param.isUsed) { if (param.canBeEliminated) { eliminateUsedParameter(member, param, variable); @@ -440,10 +436,9 @@ class _Transform extends RecursiveVisitor { } // 2. All named parameters that are always passed and can't be eliminated, // as required positional parameters, alphabetically by name. - final List sortedNamed = - function.namedParameters.toList() - ..sort((var1, var2) => var1.name!.compareTo(var2.name!)); - for (VariableDeclaration variable in sortedNamed) { + final List sortedNamed = function.namedParameters.toList() + ..sort((var1, var2) => var1.name!.compareTo(var2.name!)); + for (Variable variable in sortedNamed) { final _ParameterInfo param = info.named[variable.name!]!; if (param.isAlwaysPassed) { if (param.isUsed) { @@ -471,7 +466,7 @@ class _Transform extends RecursiveVisitor { ) { final _ParameterInfo param = info.positional[i]; assert(!param.isAlwaysPassed); - final VariableDeclaration variable = function.positionalParameters[i]; + final Variable variable = function.positionalParameters[i]; if (param.isUsed) { if (param.canBeEliminated) { eliminateUsedParameter(member, param, variable); @@ -491,7 +486,7 @@ class _Transform extends RecursiveVisitor { } // 4. All named parameters that are not always passed and can't be // eliminated, as named parameters in alphabetical order. - for (VariableDeclaration variable in sortedNamed) { + for (Variable variable in sortedNamed) { final _ParameterInfo param = info.named[variable.name!]!; if (!param.isAlwaysPassed) { if (param.isUsed) { @@ -595,13 +590,13 @@ class _Transform extends RecursiveVisitor { return exp is VariableGet && unusedParams.contains(exp.variable); } - Map hoisted = {}; + Map hoisted = {}; if (hoistingNeeded) { if (call is Initializer) { final Constructor constructor = call.parent as Constructor; forEachArgumentRev(args, info, (Expression arg, _ParameterInfo param) { if (mayHaveOrSeeSideEffects(arg) && !isUnusedParam(arg)) { - VariableDeclaration argVar = VariableDeclaration( + Variable argVar = Variable( null, initializer: arg, type: arg.getStaticType(typeContext), @@ -619,7 +614,7 @@ class _Transform extends RecursiveVisitor { Expression current = call as Expression; forEachArgumentRev(args, info, (Expression arg, _ParameterInfo param) { if (mayHaveOrSeeSideEffects(arg) && !isUnusedParam(arg)) { - VariableDeclaration argVar = VariableDeclaration( + Variable argVar = Variable( null, initializer: arg, type: arg.getStaticType(typeContext), @@ -633,7 +628,7 @@ class _Transform extends RecursiveVisitor { if (receiver != null && mayHaveOrSeeSideEffects(receiver)) { assert(!isUnusedParam(receiver)); assert(receiver.parent == call); - final VariableDeclaration receiverVar = VariableDeclaration( + final Variable receiverVar = Variable( null, initializer: receiver, type: receiver.getStaticType(typeContext), diff --git a/pkg/vm/lib/transformations/type_flow/summary.dart b/pkg/vm/lib/transformations/type_flow/summary.dart index ea882d051a9..e9aaf6e490a 100644 --- a/pkg/vm/lib/transformations/type_flow/summary.dart +++ b/pkg/vm/lib/transformations/type_flow/summary.dart @@ -693,15 +693,15 @@ class TypeCheck extends Statement { // "unchecked" entrypoint. bool isTestedOnlyOnCheckedEntryPoint; - bool get isParameterCheck => node is VariableDeclaration; - VariableDeclaration get parameterVariable => node as VariableDeclaration; + bool get isParameterCheck => node is Variable; + Variable get parameterVariable => node as Variable; bool alwaysPass = true; bool alwaysFail = true; TypeCheck(this.arg, this.type, this.node, this.staticType) : isTestedOnlyOnCheckedEntryPoint = - node is VariableDeclaration && !node.isCovariantByDeclaration; + node is Variable && !node.isCovariantByDeclaration; @override void accept(StatementVisitor visitor) => visitor.visitTypeCheck(this); @@ -965,7 +965,7 @@ abstract class SharedVariable { abstract class SharedVariableBuilder { /// [SharedVariable] representing captured [variable]. - SharedVariable getSharedVariable(VariableDeclaration variable); + SharedVariable getSharedVariable(Variable variable); /// [SharedVariable] representing captured `this` in [member]. SharedVariable getSharedCapturedThis(Member member); @@ -1197,7 +1197,7 @@ class Summary { return new Args(argTypes, names: argNames); } - Type argumentType(Member member, VariableDeclaration memberParam) { + Type argumentType(Member member, Variable memberParam) { final int firstParamIndex = numTypeParams(member) + (hasReceiverArg(member) ? 1 : 0); final positional = member.function!.positionalParameters; @@ -1217,8 +1217,8 @@ class Summary { throw "Could not find argument type of parameter ${memberParam.name}"; } - List get uncheckedParameters { - final params = []; + List get uncheckedParameters { + final params = []; for (Statement statement in _statements) { if (statement is TypeCheck && statement.alwaysPass && @@ -1244,11 +1244,11 @@ class Summary { } FunctionNode function = member.function!; statements.length = implicit; - for (VariableDeclaration param in function.positionalParameters) { + for (Variable param in function.positionalParameters) { statements.add(paramsByName[param.name]!); } positionalParameterCount = statements.length; - for (VariableDeclaration param in function.namedParameters) { + for (Variable param in function.namedParameters) { statements.add(paramsByName[param.name]!); } parameterCount = statements.length; diff --git a/pkg/vm/lib/transformations/type_flow/summary_collector.dart b/pkg/vm/lib/transformations/type_flow/summary_collector.dart index d6207c94e90..a8a0e3bb838 100644 --- a/pkg/vm/lib/transformations/type_flow/summary_collector.dart +++ b/pkg/vm/lib/transformations/type_flow/summary_collector.dart @@ -282,13 +282,13 @@ class _SummaryNormalizer implements StatementVisitor { /// modified in loops and try blocks. class _VariablesInfoCollector extends RecursiveVisitor { /// Maps declared variables to their declaration index. - final Map varIndex = {}; + final Map varIndex = {}; /// Variable declarations. - final List varDeclarations = []; + final List varDeclarations = []; /// Set of captured variables. - Set? captured; + Set? captured; /// Set of variables which were modified for each loop, switch statement /// and try block statement. Doesn't include captured variables and @@ -314,7 +314,7 @@ class _VariablesInfoCollector extends RecursiveVisitor { int get numVariables => varDeclarations.length; - bool isCaptured(VariableDeclaration variable) { + bool isCaptured(Variable variable) { final captured = this.captured; return captured != null && captured.contains(variable); } @@ -349,11 +349,11 @@ class _VariablesInfoCollector extends RecursiveVisitor { bool _isDeclaredBefore(int variableIndex, int entryDeclarationCounter) => variableIndex < entryDeclarationCounter; - void _captureVariable(VariableDeclaration variable) { - (captured ??= {}).add(variable); + void _captureVariable(Variable variable) { + (captured ??= {}).add(variable); } - void _useVariable(VariableDeclaration variable, bool isVarAssignment) { + void _useVariable(Variable variable, bool isVarAssignment) { final index = varIndex[variable]!; if (_isDeclaredBefore(index, numVariablesAtFunctionEntry)) { _captureVariable(variable); @@ -409,7 +409,7 @@ class _VariablesInfoCollector extends RecursiveVisitor { } @override - defaultVariableDeclaration(VariableDeclaration node) { + defaultVariable(Variable node) { final int index = numVariables; varDeclarations.add(node); varIndex[node] = index; @@ -593,7 +593,7 @@ class SummaryCollector extends RecursiveResultVisitor { // Cached unconditional reads of captured variables // (can be reused to avoid repetitive reads). - Map? _capturedVariableReads; + Map? _capturedVariableReads; // Counts number of Joins inserted for each variable. Only used to set // readable names for such joins (foo_0, foo_1 etc.) @@ -801,11 +801,7 @@ class SummaryCollector extends RecursiveResultVisitor { useTypesFrom = FunctionNode( null, positionalParameters: [ - VariableDeclaration( - "value", - type: target.type, - isSynthesized: true, - ), + Variable("value", type: target.type, isSynthesized: true), ], ); } else { @@ -979,7 +975,7 @@ class SummaryCollector extends RecursiveResultVisitor { return _summary; } - bool _useTypeCheckForParameter(VariableDeclaration decl) { + bool _useTypeCheckForParameter(Variable decl) { return decl.isCovariantByDeclaration || decl.isCovariantByClass; } @@ -1129,7 +1125,7 @@ class SummaryCollector extends RecursiveResultVisitor { return param; } - void _declareVariable(VariableDeclaration decl, TypeExpr initialValue) { + void _declareVariable(Variable decl, TypeExpr initialValue) { final int varIndex = _variablesInfo.varIndex[decl]!; assert(_variablesInfo.varDeclarations[varIndex] == decl); assert(_variableValues[varIndex] == null); @@ -1144,7 +1140,7 @@ class SummaryCollector extends RecursiveResultVisitor { } } - void _writeVariable(VariableDeclaration variable, TypeExpr value) { + void _writeVariable(Variable variable, TypeExpr value) { if (_variablesInfo.isCaptured(variable)) { assert(_aggregateVariable[_variablesInfo.varIndex[variable]!]); final sharedVar = _sharedVariableBuilder.getSharedVariable(variable); @@ -1164,7 +1160,7 @@ class SummaryCollector extends RecursiveResultVisitor { TypeExpr _readReceiver() => _receiver!; - TypeExpr _readVariable(VariableDeclaration variable, TreeNode node) { + TypeExpr _readVariable(Variable variable, TreeNode node) { if (_variablesInfo.isCaptured(variable)) { assert(_aggregateVariable[_variablesInfo.varIndex[variable]!]); final cachedRead = _capturedVariableReads?[variable]; @@ -1214,8 +1210,7 @@ class SummaryCollector extends RecursiveResultVisitor { } Join _makeJoin(int varIndex, TypeExpr value) { - final VariableDeclaration variable = - _variablesInfo.varDeclarations[varIndex]; + final Variable variable = _variablesInfo.varDeclarations[varIndex]; final name = '${variable.name}_${_variableVersions[varIndex]++}'; final Join join = new Join(name, variable.type); join.condition = _currentCondition; @@ -1363,7 +1358,7 @@ class SummaryCollector extends RecursiveResultVisitor { } // TODO(alexmarkov): Avoid declaring variables with static types. - void _declareVariableWithStaticType(VariableDeclaration decl) { + void _declareVariableWithStaticType(Variable decl) { final initializer = decl.initializer; if (initializer != null) { _visit(initializer); @@ -2599,7 +2594,7 @@ class SummaryCollector extends RecursiveResultVisitor { @override TypeExpr? visitForStatement(ForStatement node) { - node.variables.forEach((v) => defaultVariableDeclaration(v.variable)); + node.variables.forEach((v) => defaultVariable(v.variable)); final List joins = _insertJoinsForModifiedVariables(node, false); final trueState = _cloneVariableValues(_variableValues); final falseState = _cloneVariableValues(_variableValues); @@ -2808,11 +2803,11 @@ class SummaryCollector extends RecursiveResultVisitor { @override TypeExpr? visitLegacyVariableStatement(LegacyVariableStatement node) { - defaultVariableDeclaration(node.variable); + defaultVariable(node.variable); return null; } - TypeExpr? defaultVariableDeclaration(VariableDeclaration node) { + TypeExpr? defaultVariable(Variable node) { final variable = node.variable; variable.annotations.forEach(_visitAnnotation); final initializer = variable.initializer; @@ -2892,7 +2887,7 @@ class SummaryCollector extends RecursiveResultVisitor { @override TypeExpr? visitLocalInitializer(LocalInitializer node) { - defaultVariableDeclaration(node.variable); + defaultVariable(node.variable); return null; } diff --git a/pkg/vm/lib/transformations/type_flow/transformer.dart b/pkg/vm/lib/transformations/type_flow/transformer.dart index 0424f71ad0a..bb73ad50df1 100644 --- a/pkg/vm/lib/transformations/type_flow/transformer.dart +++ b/pkg/vm/lib/transformations/type_flow/transformer.dart @@ -267,11 +267,7 @@ class MoveFieldInitializers { } final Initializer newInit = initializedFields.contains(f) ? LocalInitializer( - VariableDeclaration( - null, - initializer: initExpr, - isSynthesized: true, - ), + Variable(null, initializer: initExpr, isSynthesized: true), ) : FieldInitializer(f, initExpr); newInit.parent = c; @@ -314,7 +310,7 @@ class CleanupAnnotations extends RecursiveVisitor { } void _cleanupAnnotations(Node node, List annotations) { - if (node is VariableDeclaration || + if (node is Variable || node is Member || node is Class || node is Library) { @@ -899,12 +895,12 @@ class AnnotateKernel extends RecursiveVisitor { } @override - defaultVariableDeclaration(VariableDeclaration node) { + defaultVariable(Variable node) { final inferredType = _typeFlowAnalysis.capturedVariableType(node); if (inferredType != null) { _setInferredType(node, inferredType); } - super.defaultVariableDeclaration(node); + super.defaultVariable(node); } @override @@ -1150,7 +1146,7 @@ class TreeShaker { } } - void addUsedParameters(List params) { + void addUsedParameters(List params) { for (var param in params) { // Do not visit initializer (default value) of a parameter as it is // going to be removed during pass 2. @@ -1207,11 +1203,7 @@ class FieldMorpher { if (isSetter) { final isAbstract = !shaker.isFieldSetterReachable(field); final parameter = - new VariableDeclaration( - 'value', - type: field.type, - isSynthesized: true, - ) + new Variable('value', type: field.type, isSynthesized: true) ..isCovariantByDeclaration = field.isCovariantByDeclaration ..isCovariantByClass = field.isCovariantByClass ..fileOffset = field.fileOffset; @@ -1436,7 +1428,7 @@ class _TreeShakerPass1 extends RemovingTransformer { TreeNode _makeUnreachableInitializer(List args) { return new LocalInitializer( - new VariableDeclaration( + new Variable( null, initializer: _makeUnreachableCall(args), isSynthesized: true, @@ -1916,7 +1908,7 @@ class _TreeShakerPass1 extends RemovingTransformer { if (!shaker.retainField(field)) { if (mayHaveSideEffects(node.value)) { return LocalInitializer( - VariableDeclaration( + Variable( null, initializer: node.value, isSynthesized: true, diff --git a/pkg/vm/lib/transformations/type_flow/types.dart b/pkg/vm/lib/transformations/type_flow/types.dart index b6901624aed..7d27f2f2e7c 100644 --- a/pkg/vm/lib/transformations/type_flow/types.dart +++ b/pkg/vm/lib/transformations/type_flow/types.dart @@ -1077,11 +1077,9 @@ class Closure { ? member.enclosingClass!.typeParameters : functionNode.typeParameters; final freshTypeParameters = getFreshTypeParameters(typeParameters); - List convertParameters( - List params, - ) => [ + List convertParameters(List params) => [ for (final p in params) - VariableDeclaration( + Variable( p.name, initializer: (p.initializer != null) ? ConstantExpression( diff --git a/pkg/vm/lib/transformations/type_flow/utils.dart b/pkg/vm/lib/transformations/type_flow/utils.dart index d84e85499cf..2756a5fba86 100644 --- a/pkg/vm/lib/transformations/type_flow/utils.dart +++ b/pkg/vm/lib/transformations/type_flow/utils.dart @@ -139,7 +139,7 @@ bool isSorted(List list) { return true; } -VariableDeclaration? findNamedParameter(FunctionNode function, String name) { +Variable? findNamedParameter(FunctionNode function, String name) { return function.namedParameters.firstWhereOrNull((p) => p.name == name); } diff --git a/pkg/vm/test/transformations/type_flow/summary_collector_test.dart b/pkg/vm/test/transformations/type_flow/summary_collector_test.dart index 26ee2e36cfa..3dce331ab3f 100644 --- a/pkg/vm/test/transformations/type_flow/summary_collector_test.dart +++ b/pkg/vm/test/transformations/type_flow/summary_collector_test.dart @@ -102,11 +102,11 @@ class FakeSharedVariable implements SharedVariable { } class FakeSharedVariableBuilder implements SharedVariableBuilder { - final Map _sharedVariables = {}; + final Map _sharedVariables = {}; final Map _sharedCapturedThisVariables = {}; @override - SharedVariable getSharedVariable(VariableDeclaration variable) => + SharedVariable getSharedVariable(Variable variable) => _sharedVariables[variable] ??= FakeSharedVariable( variable.name ?? '__tmp', );