From 9a71c998f9033afab858ce3a6b535c1aa372955f Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Thu, 8 Aug 2019 14:01:16 +0000 Subject: [PATCH] [cfe] Rename Declaration and DeclarationBuilder Rename Declaration to Builder and DeclarationBuilder to TypeParameterScopeBuilder. This prepares for the introduciton of a DeclarationBuilder superclass of ClassBuilder, MixinDeclarationBuilder and ExtensionDeclarationBuilder. Change-Id: I2d392372f458f39ebaea87ec10f365b822ee3841 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112088 Reviewed-by: Dmitry Stefantsov Commit-Queue: Johnni Winther --- .../lib/src/fasta/builder/builder.dart | 2 +- .../lib/src/fasta/builder/class_builder.dart | 44 +-- .../constructor_reference_builder.dart | 8 +- .../lib/src/fasta/builder/declaration.dart | 14 +- .../lib/src/fasta/builder/enum_builder.dart | 8 +- .../lib/src/fasta/builder/field_builder.dart | 4 +- .../builder/formal_parameter_builder.dart | 4 +- .../src/fasta/builder/library_builder.dart | 42 ++- .../lib/src/fasta/builder/member_builder.dart | 4 +- .../src/fasta/builder/modifier_builder.dart | 6 +- .../lib/src/fasta/builder/name_iterator.dart | 4 +- .../src/fasta/builder/named_type_builder.dart | 6 +- .../lib/src/fasta/builder/prefix_builder.dart | 12 +- .../src/fasta/builder/procedure_builder.dart | 18 +- .../builder/type_declaration_builder.dart | 9 +- .../src/fasta/dill/dill_library_builder.dart | 30 +- .../src/fasta/dill/dill_member_builder.dart | 4 +- pkg/front_end/lib/src/fasta/export.dart | 4 +- pkg/front_end/lib/src/fasta/import.dart | 12 +- .../lib/src/fasta/kernel/body_builder.dart | 38 +-- .../fasta/kernel/class_hierarchy_builder.dart | 240 +++++++------ .../fasta/kernel/expression_generator.dart | 8 +- .../kernel/expression_generator_helper.dart | 4 +- .../lib/src/fasta/kernel/forwarding_node.dart | 8 +- .../lib/src/fasta/kernel/kernel_target.dart | 15 +- .../fasta/kernel/kernel_variable_builder.dart | 6 +- .../fasta/kernel/load_library_builder.dart | 4 +- .../lib/src/fasta/kernel/unlinked_scope.dart | 10 +- pkg/front_end/lib/src/fasta/loader.dart | 10 +- pkg/front_end/lib/src/fasta/scope.dart | 114 +++---- .../lib/src/fasta/source/diet_listener.dart | 18 +- .../lib/src/fasta/source/outline_builder.dart | 77 +++-- .../fasta/source/source_class_builder.dart | 24 +- .../fasta/source/source_library_builder.dart | 320 ++++++++++-------- .../lib/src/fasta/source/source_loader.dart | 37 +- .../type_promotion_look_ahead_listener.dart | 34 +- .../lib/src/fasta/target_implementation.dart | 22 +- .../lib/src/testing/id_testing_utils.dart | 6 +- .../fasta/type_promotion_look_ahead_test.dart | 8 +- 39 files changed, 622 insertions(+), 616 deletions(-) diff --git a/pkg/front_end/lib/src/fasta/builder/builder.dart b/pkg/front_end/lib/src/fasta/builder/builder.dart index 45ed3340340c..285dc07160c7 100644 --- a/pkg/front_end/lib/src/fasta/builder/builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/builder.dart @@ -20,7 +20,7 @@ export 'class_builder.dart' show ClassBuilder; export 'constructor_reference_builder.dart' show ConstructorReferenceBuilder; -export 'declaration.dart' show Declaration; +export 'declaration.dart' show Builder; export 'dynamic_type_builder.dart' show DynamicTypeBuilder; diff --git a/pkg/front_end/lib/src/fasta/builder/class_builder.dart b/pkg/front_end/lib/src/fasta/builder/class_builder.dart index 6f1f42b842c6..f8fdfcc18e66 100644 --- a/pkg/front_end/lib/src/fasta/builder/class_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/class_builder.dart @@ -56,7 +56,7 @@ import '../dill/dill_member_builder.dart' show DillMemberBuilder; import 'builder.dart' show ConstructorReferenceBuilder, - Declaration, + Builder, LibraryBuilder, MemberBuilder, MetadataBuilder, @@ -107,7 +107,7 @@ import '../fasta_codes.dart' import '../kernel/kernel_builder.dart' show ConstructorReferenceBuilder, - Declaration, + Builder, FunctionBuilder, NamedTypeBuilder, LibraryBuilder, @@ -204,7 +204,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { } void buildOutlineExpressions(LibraryBuilder library) { - void build(String ignore, Declaration declaration) { + void build(String ignore, Builder declaration) { MemberBuilder member = declaration; member.buildOutlineExpressions(library); } @@ -244,7 +244,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { // Copy keys to avoid concurrent modification error. List names = constructors.keys.toList(); for (String name in names) { - Declaration declaration = constructors[name]; + Builder declaration = constructors[name]; do { if (declaration.parent != this) { unexpected("$fileUri", "${declaration.parent.fileUri}", charOffset, @@ -255,7 +255,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { ConstructorReferenceBuilder redirectionTarget = declaration.redirectionTarget; if (redirectionTarget != null) { - Declaration targetBuilder = redirectionTarget.target; + Builder targetBuilder = redirectionTarget.target; if (declaration.next == null) { // Only the first one (that is, the last on in the linked list) // is actually in the kernel tree. This call creates a StaticGet @@ -324,13 +324,13 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { } /// Used to lookup a static member of this class. - Declaration findStaticBuilder( + Builder findStaticBuilder( String name, int charOffset, Uri fileUri, LibraryBuilder accessingLibrary, {bool isSetter: false}) { if (accessingLibrary.origin != library.origin && name.startsWith("_")) { return null; } - Declaration declaration = isSetter + Builder declaration = isSetter ? scope.lookupSetter(name, charOffset, fileUri, isInstanceScope: false) : scope.lookup(name, charOffset, fileUri, isInstanceScope: false); if (declaration == null && isPatch) { @@ -341,12 +341,12 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { return declaration; } - Declaration findConstructorOrFactory( + Builder findConstructorOrFactory( String name, int charOffset, Uri uri, LibraryBuilder accessingLibrary) { if (accessingLibrary.origin != library.origin && name.startsWith("_")) { return null; } - Declaration declaration = constructors.lookup(name, charOffset, uri); + Builder declaration = constructors.lookup(name, charOffset, uri); if (declaration == null && isPatch) { return origin.findConstructorOrFactory( name, charOffset, uri, accessingLibrary); @@ -354,7 +354,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { return declaration; } - void forEach(void f(String name, Declaration builder)) { + void forEach(void f(String name, Builder builder)) { scope.forEach(f); } @@ -384,7 +384,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { /// For example, this method is convenient for use when building synthetic /// members, such as those of an enum. MemberBuilder firstMemberNamed(String name) { - Declaration declaration = getLocalMember(name); + Builder declaration = getLocalMember(name); while (declaration.next != null) { declaration = declaration.next; } @@ -484,7 +484,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { ClassBuilder superClass; TypeBuilder superClassType = supertype; if (superClassType is NamedTypeBuilder) { - Declaration decl = superClassType.declaration; + Builder decl = superClassType.declaration; if (decl is ClassBuilder) { superClass = decl; } @@ -497,7 +497,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { for (TypeBuilder type in interfaces) { if (type is NamedTypeBuilder) { int charOffset = -1; // TODO(ahe): Get offset from type. - Declaration decl = type.declaration; + Builder decl = type.declaration; if (decl is ClassBuilder) { ClassBuilder interface = decl; if (superClass == interface) { @@ -1424,7 +1424,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { void checkMixinDeclaration() { assert(cls.isMixinDeclaration); - for (Declaration constructory in constructors.local.values) { + for (Builder constructory in constructors.local.values) { if (!constructory.isSynthetic && (constructory.isFactory || constructory.isConstructor)) { addProblem( @@ -1463,24 +1463,24 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { } @override - void applyPatch(Declaration patch) { + void applyPatch(Builder patch) { if (patch is ClassBuilder) { patch.actualOrigin = this; // TODO(ahe): Complain if `patch.supertype` isn't null. - scope.local.forEach((String name, Declaration member) { - Declaration memberPatch = patch.scope.local[name]; + scope.local.forEach((String name, Builder member) { + Builder memberPatch = patch.scope.local[name]; if (memberPatch != null) { member.applyPatch(memberPatch); } }); - scope.setters.forEach((String name, Declaration member) { - Declaration memberPatch = patch.scope.setters[name]; + scope.setters.forEach((String name, Builder member) { + Builder memberPatch = patch.scope.setters[name]; if (memberPatch != null) { member.applyPatch(memberPatch); } }); - constructors.local.forEach((String name, Declaration member) { - Declaration memberPatch = patch.constructors.local[name]; + constructors.local.forEach((String name, Builder member) { + Builder memberPatch = patch.constructors.local[name]; if (memberPatch != null) { member.applyPatch(memberPatch); } @@ -1640,7 +1640,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder { Map constructors = this.constructors.local; Iterable names = constructors.keys; for (String name in names) { - Declaration constructor = constructors[name]; + Builder constructor = constructors[name]; do { if (constructor is RedirectingFactoryBuilder) { checkRedirectingFactory(constructor, typeEnvironment); diff --git a/pkg/front_end/lib/src/fasta/builder/constructor_reference_builder.dart b/pkg/front_end/lib/src/fasta/builder/constructor_reference_builder.dart index d3f8d63d8f58..6dac8522e074 100644 --- a/pkg/front_end/lib/src/fasta/builder/constructor_reference_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/constructor_reference_builder.dart @@ -9,7 +9,7 @@ import '../messages.dart' show noLength, templateConstructorNotFound; import 'builder.dart' show ClassBuilder, - Declaration, + Builder, LibraryBuilder, PrefixBuilder, QualifiedName, @@ -29,10 +29,10 @@ class ConstructorReferenceBuilder { /// This is the name of a named constructor. As `bar` in `new Foo.bar()`. final String suffix; - Declaration target; + Builder target; ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix, - Declaration parent, this.charOffset) + Builder parent, this.charOffset) : fileUri = parent.fileUri; String get fullNameForErrors { @@ -42,7 +42,7 @@ class ConstructorReferenceBuilder { void resolveIn(Scope scope, LibraryBuilder accessingLibrary) { final name = this.name; - Declaration declaration; + Builder declaration; if (name is QualifiedName) { String prefix = name.qualifier; String middle = name.name; diff --git a/pkg/front_end/lib/src/fasta/builder/declaration.dart b/pkg/front_end/lib/src/fasta/builder/declaration.dart index 4b3d60156e45..38db8e2fcc6d 100644 --- a/pkg/front_end/lib/src/fasta/builder/declaration.dart +++ b/pkg/front_end/lib/src/fasta/builder/declaration.dart @@ -6,15 +6,15 @@ library fasta.declaration; import '../problems.dart' show unsupported; -abstract class Declaration { +abstract class Builder { /// Used when multiple things with the same name are declared within the same /// parent. Only used for top-level and class-member declarations, not for /// block scopes. - Declaration next; + Builder next; - Declaration(); + Builder(); - Declaration get parent; + Builder get parent; Uri get fileUri; @@ -22,7 +22,7 @@ abstract class Declaration { get target => unsupported("${runtimeType}.target", charOffset, fileUri); - Declaration get origin => this; + Builder get origin => this; String get fullNameForErrors; @@ -69,7 +69,7 @@ abstract class Declaration { } /// Applies [patch] to this declaration. - void applyPatch(Declaration patch) { + void applyPatch(Builder patch) { unsupported("${runtimeType}.applyPatch", charOffset, fileUri); } @@ -82,5 +82,5 @@ abstract class Declaration { /// Resolve constructors (lookup names in scope) recorded in this builder and /// return the number of constructors resolved. - int resolveConstructors(covariant Declaration parent) => 0; + int resolveConstructors(covariant Builder parent) => 0; } diff --git a/pkg/front_end/lib/src/fasta/builder/enum_builder.dart b/pkg/front_end/lib/src/fasta/builder/enum_builder.dart index 3d4660024180..093e2f0a777a 100644 --- a/pkg/front_end/lib/src/fasta/builder/enum_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/enum_builder.dart @@ -48,7 +48,7 @@ import '../source/source_class_builder.dart' show SourceClassBuilder; import '../kernel/kernel_builder.dart' show - Declaration, + Builder, FormalParameterBuilder, ClassBuilder, ConstructorBuilder, @@ -280,7 +280,7 @@ class EnumBuilder extends SourceClassBuilder { if (enumConstantInfos != null) { for (EnumConstantInfo enumConstantInfo in enumConstantInfos) { if (enumConstantInfo != null) { - Declaration declaration = firstMemberNamed(enumConstantInfo.name); + Builder declaration = firstMemberNamed(enumConstantInfo.name); if (declaration.isField) { FieldBuilder field = declaration; values.add(new StaticGet(field.build(libraryBuilder))); @@ -324,7 +324,7 @@ class EnumBuilder extends SourceClassBuilder { for (EnumConstantInfo enumConstantInfo in enumConstantInfos) { if (enumConstantInfo != null) { String constant = enumConstantInfo.name; - Declaration declaration = firstMemberNamed(constant); + Builder declaration = firstMemberNamed(constant); FieldBuilder field; if (declaration.isField) { field = declaration; @@ -344,7 +344,7 @@ class EnumBuilder extends SourceClassBuilder { } @override - Declaration findConstructorOrFactory( + Builder findConstructorOrFactory( String name, int charOffset, Uri uri, LibraryBuilder library) { return null; } diff --git a/pkg/front_end/lib/src/fasta/builder/field_builder.dart b/pkg/front_end/lib/src/fasta/builder/field_builder.dart index cd38adfae84b..364614dc4543 100644 --- a/pkg/front_end/lib/src/fasta/builder/field_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/field_builder.dart @@ -23,7 +23,7 @@ import '../kernel/body_builder.dart' show BodyBuilder; import '../kernel/kernel_builder.dart' show ClassBuilder, - Declaration, + Builder, ImplicitFieldType, TypeBuilder, LibraryBuilder, @@ -59,7 +59,7 @@ class FieldBuilder extends MemberBuilder { bool hadTypesInferred = false; FieldBuilder(this.metadata, this.type, this.name, this.modifiers, - Declaration compilationUnit, int charOffset, int charEndOffset) + Builder compilationUnit, int charOffset, int charEndOffset) : field = new Field(null, fileUri: compilationUnit?.fileUri) ..fileOffset = charOffset ..fileEndOffset = charEndOffset, diff --git a/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart b/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart index c792326a691d..177280dd21d1 100644 --- a/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart @@ -34,7 +34,7 @@ import '../kernel/body_builder.dart' show BodyBuilder; import '../kernel/kernel_builder.dart' show ClassBuilder, - Declaration, + Builder, ConstructorBuilder, FieldBuilder, LibraryBuilder, @@ -132,7 +132,7 @@ class FormalParameterBuilder extends ModifierBuilder { void finalizeInitializingFormal() { Object cls = parent.parent; if (cls is ClassBuilder) { - Declaration field = cls.scope.lookup(name, charOffset, fileUri); + Builder field = cls.scope.lookup(name, charOffset, fileUri); if (field is FieldBuilder) { target.type = field.target.type; } diff --git a/pkg/front_end/lib/src/fasta/builder/library_builder.dart b/pkg/front_end/lib/src/fasta/builder/library_builder.dart index 06b5e59632e0..f74ee3d7360e 100644 --- a/pkg/front_end/lib/src/fasta/builder/library_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/library_builder.dart @@ -28,7 +28,7 @@ import '../severity.dart' show Severity; import 'builder.dart' show ClassBuilder, - Declaration, + Builder, FieldBuilder, ModifierBuilder, NameIterator, @@ -79,7 +79,7 @@ abstract class LibraryBuilder extends ModifierBuilder { {int offset: 0, int length, bool explicit}); @override - Declaration get parent => null; + Builder get parent => null; bool get isPart => false; @@ -96,7 +96,7 @@ abstract class LibraryBuilder extends ModifierBuilder { Uri get uri; - Iterator get iterator { + Iterator get iterator { return LibraryLocalDeclarationIterator(this); } @@ -104,7 +104,7 @@ abstract class LibraryBuilder extends ModifierBuilder { return new LibraryLocalDeclarationNameIterator(this); } - Declaration addBuilder(String name, Declaration declaration, int charOffset); + Builder addBuilder(String name, Builder declaration, int charOffset); void addExporter( LibraryBuilder exporter, List combinators, int charOffset) { @@ -133,16 +133,15 @@ abstract class LibraryBuilder extends ModifierBuilder { } /// Returns true if the export scope was modified. - bool addToExportScope(String name, Declaration member, - [int charOffset = -1]) { + bool addToExportScope(String name, Builder member, [int charOffset = -1]) { if (name.startsWith("_")) return false; if (member is PrefixBuilder) return false; - Map map = + Map map = member.isSetter ? exportScope.setters : exportScope.local; - Declaration existing = map[name]; + Builder existing = map[name]; if (existing == member) return false; if (existing != null) { - Declaration result = computeAmbiguousDeclaration( + Builder result = computeAmbiguousDeclaration( name, existing, member, charOffset, isExport: true); map[name] = result; @@ -153,11 +152,10 @@ abstract class LibraryBuilder extends ModifierBuilder { return true; } - void addToScope( - String name, Declaration member, int charOffset, bool isImport); + void addToScope(String name, Builder member, int charOffset, bool isImport); - Declaration computeAmbiguousDeclaration( - String name, Declaration declaration, Declaration other, int charOffset, + Builder computeAmbiguousDeclaration( + String name, Builder declaration, Builder other, int charOffset, {bool isExport: false, bool isImport: false}); int finishDeferredLoadTearoffs() => 0; @@ -180,7 +178,7 @@ abstract class LibraryBuilder extends ModifierBuilder { /// If [constructorName] is null or the empty string, it's assumed to be an /// unnamed constructor. it's an error if [constructorName] starts with /// `"_"`, and [bypassLibraryPrivacy] is false. - Declaration getConstructor(String className, + Builder getConstructor(String className, {String constructorName, bool bypassLibraryPrivacy: false}) { constructorName ??= ""; if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { @@ -190,12 +188,12 @@ abstract class LibraryBuilder extends ModifierBuilder { -1, null); } - Declaration cls = (bypassLibraryPrivacy ? scope : exportScope) + Builder cls = (bypassLibraryPrivacy ? scope : exportScope) .lookup(className, -1, null); if (cls is ClassBuilder) { // TODO(ahe): This code is similar to code in `endNewExpression` in // `body_builder.dart`, try to share it. - Declaration constructor = + Builder constructor = cls.findConstructorOrFactory(constructorName, -1, null, this); if (constructor == null) { // Fall-through to internal error below. @@ -235,7 +233,7 @@ abstract class LibraryBuilder extends ModifierBuilder { /// Don't use for scope lookup. Only use when an element is known to exist /// (and not a setter). - Declaration getLocalMember(String name) { + Builder getLocalMember(String name) { return scope.local[name] ?? internalProblem( templateInternalProblemNotFoundIn.withArguments(name, "$fileUri"), @@ -243,7 +241,7 @@ abstract class LibraryBuilder extends ModifierBuilder { fileUri); } - Declaration lookup(String name, int charOffset, Uri fileUri) { + Builder lookup(String name, int charOffset, Uri fileUri) { return scope.lookup(name, charOffset, fileUri); } @@ -260,14 +258,14 @@ abstract class LibraryBuilder extends ModifierBuilder { List takeImplicitlyTypedFields() => null; } -class LibraryLocalDeclarationIterator implements Iterator { +class LibraryLocalDeclarationIterator implements Iterator { final LibraryBuilder library; - final Iterator iterator; + final Iterator iterator; LibraryLocalDeclarationIterator(this.library) : iterator = library.scope.iterator; - Declaration get current => iterator.current; + Builder get current => iterator.current; bool moveNext() { while (iterator.moveNext()) { @@ -284,7 +282,7 @@ class LibraryLocalDeclarationNameIterator implements NameIterator { LibraryLocalDeclarationNameIterator(this.library) : iterator = library.scope.nameIterator; - Declaration get current => iterator.current; + Builder get current => iterator.current; String get name => iterator.name; diff --git a/pkg/front_end/lib/src/fasta/builder/member_builder.dart b/pkg/front_end/lib/src/fasta/builder/member_builder.dart index e7142101e239..dd40c72b2198 100644 --- a/pkg/front_end/lib/src/fasta/builder/member_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/member_builder.dart @@ -7,13 +7,13 @@ library fasta.member_builder; import '../problems.dart' show unsupported; import 'builder.dart' - show ClassBuilder, Declaration, LibraryBuilder, ModifierBuilder; + show ClassBuilder, Builder, LibraryBuilder, ModifierBuilder; abstract class MemberBuilder extends ModifierBuilder { /// For top-level members, the parent is set correctly during /// construction. However, for class members, the parent is initially the /// library and updated later. - Declaration parent; + Builder parent; String get name; diff --git a/pkg/front_end/lib/src/fasta/builder/modifier_builder.dart b/pkg/front_end/lib/src/fasta/builder/modifier_builder.dart index c990a53c9e27..907ec5a6c74d 100644 --- a/pkg/front_end/lib/src/fasta/builder/modifier_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/modifier_builder.dart @@ -19,10 +19,10 @@ import '../modifier.dart' namedMixinApplicationMask, staticMask; -import 'builder.dart' show Declaration; +import 'builder.dart' show Builder; -abstract class ModifierBuilder extends Declaration { - Declaration parent; +abstract class ModifierBuilder extends Builder { + Builder parent; final int charOffset; diff --git a/pkg/front_end/lib/src/fasta/builder/name_iterator.dart b/pkg/front_end/lib/src/fasta/builder/name_iterator.dart index 9a931247f500..11303b4adc2f 100644 --- a/pkg/front_end/lib/src/fasta/builder/name_iterator.dart +++ b/pkg/front_end/lib/src/fasta/builder/name_iterator.dart @@ -4,8 +4,8 @@ library fasta.name_iterator; -import 'builder.dart' show Declaration; +import 'builder.dart' show Builder; -abstract class NameIterator implements Iterator { +abstract class NameIterator implements Iterator { String get name; } diff --git a/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart b/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart index 3490c42e6b83..d35ed9729286 100644 --- a/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart @@ -28,7 +28,7 @@ import '../severity.dart' show Severity; import 'builder.dart' show - Declaration, + Builder, Identifier, LibraryBuilder, PrefixBuilder, @@ -73,11 +73,11 @@ class NamedTypeBuilder extends TypeBuilder { Scope scope, int charOffset, Uri fileUri, LibraryBuilder library) { if (declaration != null) return; final name = this.name; - Declaration member; + Builder member; if (name is QualifiedName) { Object qualifier = name.qualifier; String prefixName = flattenName(qualifier, charOffset, fileUri); - Declaration prefix = scope.lookup(prefixName, charOffset, fileUri); + Builder prefix = scope.lookup(prefixName, charOffset, fileUri); if (prefix is PrefixBuilder) { member = prefix.lookup(name.name, name.charOffset, fileUri); } diff --git a/pkg/front_end/lib/src/fasta/builder/prefix_builder.dart b/pkg/front_end/lib/src/fasta/builder/prefix_builder.dart index bb356a495f80..f8202801ee00 100644 --- a/pkg/front_end/lib/src/fasta/builder/prefix_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/prefix_builder.dart @@ -4,7 +4,7 @@ library fasta.prefix_builder; -import 'builder.dart' show Declaration, LibraryBuilder, Scope; +import 'builder.dart' show Builder, LibraryBuilder, Scope; import 'package:kernel/ast.dart' show LibraryDependency; @@ -12,7 +12,7 @@ import '../builder/builder.dart' show LibraryBuilder; import '../kernel/load_library_builder.dart' show LoadLibraryBuilder; -class PrefixBuilder extends Declaration { +class PrefixBuilder extends Builder { final String name; final Scope exportScope = new Scope.top(); @@ -41,14 +41,14 @@ class PrefixBuilder extends Declaration { Uri get fileUri => parent.fileUri; - Declaration lookup(String name, int charOffset, Uri fileUri) { + Builder lookup(String name, int charOffset, Uri fileUri) { return exportScope.lookup(name, charOffset, fileUri); } - void addToExportScope(String name, Declaration member, int charOffset) { - Map map = + void addToExportScope(String name, Builder member, int charOffset) { + Map map = member.isSetter ? exportScope.setters : exportScope.local; - Declaration existing = map[name]; + Builder existing = map[name]; if (existing != null) { map[name] = parent.computeAmbiguousDeclaration( name, existing, member, charOffset, diff --git a/pkg/front_end/lib/src/fasta/builder/procedure_builder.dart b/pkg/front_end/lib/src/fasta/builder/procedure_builder.dart index 04fc4585c5fe..331438a7c322 100644 --- a/pkg/front_end/lib/src/fasta/builder/procedure_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/procedure_builder.dart @@ -15,7 +15,7 @@ import 'package:kernel/type_algebra.dart'; import 'builder.dart' show - Declaration, + Builder, FormalParameterBuilder, LibraryBuilder, MemberBuilder, @@ -65,7 +65,7 @@ import '../kernel/kernel_builder.dart' show ClassBuilder, ConstructorReferenceBuilder, - Declaration, + Builder, FormalParameterBuilder, LibraryBuilder, MetadataBuilder, @@ -160,7 +160,7 @@ abstract class FunctionBuilder extends MemberBuilder { /// Language Specifiction, 4th ed, section 9.2. Scope computeFormalParameterScope(Scope parent) { if (formals == null) return parent; - Map local = {}; + Map local = {}; for (FormalParameterBuilder formal in formals) { if (!isConstructor || !formal.isInitializingFormal) { local[formal.name] = formal; @@ -187,7 +187,7 @@ abstract class FunctionBuilder extends MemberBuilder { // parameter initializer scope. if (formals == null) return parent; - Map local = {}; + Map local = {}; for (FormalParameterBuilder formal in formals) { local[formal.name] = formal.forFormalParameterInitializerScope(); } @@ -200,7 +200,7 @@ abstract class FunctionBuilder extends MemberBuilder { /// to support generic methods. Scope computeTypeParameterScope(Scope parent) { if (typeVariables == null) return parent; - Map local = {}; + Map local = {}; for (TypeVariableBuilder variable in typeVariables) { local[variable.name] = variable; } @@ -384,7 +384,7 @@ abstract class FunctionBuilder extends MemberBuilder { } void becomeNative(Loader loader) { - Declaration constructor = loader.getNativeAnnotation(); + Builder constructor = loader.getNativeAnnotation(); Arguments arguments = new Arguments([new StringLiteral(nativeMethodName)]); Expression annotation; @@ -411,7 +411,7 @@ abstract class FunctionBuilder extends MemberBuilder { return true; } - void reportPatchMismatch(Declaration patch) { + void reportPatchMismatch(Builder patch) { library.addProblem(messagePatchDeclarationMismatch, patch.charOffset, noLength, patch.fileUri, context: [ messagePatchDeclarationOrigin.withLocation(fileUri, charOffset, noLength) @@ -550,7 +550,7 @@ class ProcedureBuilder extends FunctionBuilder { } @override - void applyPatch(Declaration patch) { + void applyPatch(Builder patch) { if (patch is ProcedureBuilder) { if (checkPatch(patch)) { patch.actualOrigin = this; @@ -763,7 +763,7 @@ class ConstructorBuilder extends FunctionBuilder { } @override - void applyPatch(Declaration patch) { + void applyPatch(Builder patch) { if (patch is ConstructorBuilder) { if (checkPatch(patch)) { patch.actualOrigin = this; diff --git a/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart b/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart index 1157dbfe29c4..fa2c7bd260bc 100644 --- a/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart @@ -7,12 +7,7 @@ library fasta.type_declaration_builder; import 'package:kernel/ast.dart' show DartType; import 'builder.dart' - show - Declaration, - LibraryBuilder, - MetadataBuilder, - ModifierBuilder, - TypeBuilder; + show Builder, LibraryBuilder, MetadataBuilder, ModifierBuilder, TypeBuilder; abstract class TypeDeclarationBuilder extends ModifierBuilder { final List metadata; @@ -21,7 +16,7 @@ abstract class TypeDeclarationBuilder extends ModifierBuilder { final String name; - Declaration parent; + Builder parent; TypeDeclarationBuilder( this.metadata, this.modifiers, this.name, this.parent, int charOffset, diff --git a/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart index e86027f2a327..c058725fbddc 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart @@ -32,12 +32,7 @@ import '../fasta_codes.dart' import '../problems.dart' show internalProblem, unhandled, unimplemented; import '../kernel/kernel_builder.dart' - show - Declaration, - DynamicTypeBuilder, - InvalidTypeBuilder, - LibraryBuilder, - Scope; + show Builder, DynamicTypeBuilder, InvalidTypeBuilder, LibraryBuilder, Scope; import '../kernel/redirecting_factory_body.dart' show RedirectingFactoryBody; @@ -52,22 +47,22 @@ import 'dill_type_alias_builder.dart' show DillTypeAliasBuilder; class LazyLibraryScope extends Scope { DillLibraryBuilder libraryBuilder; - LazyLibraryScope(Map local, - Map setters, Scope parent, String debugName, + LazyLibraryScope(Map local, Map setters, + Scope parent, String debugName, {bool isModifiable: true}) : super(local, setters, parent, debugName, isModifiable: isModifiable); LazyLibraryScope.top({bool isModifiable: false}) - : this({}, {}, null, "top", + : this({}, {}, null, "top", isModifiable: isModifiable); - Map get local { + Map get local { if (libraryBuilder == null) throw new StateError("No library builder."); libraryBuilder.ensureLoaded(); return super.local; } - Map get setters { + Map get setters { if (libraryBuilder == null) throw new StateError("No library builder."); libraryBuilder.ensureLoaded(); return super.setters; @@ -173,7 +168,7 @@ class DillLibraryBuilder extends LibraryBuilder { } @override - Declaration addBuilder(String name, Declaration declaration, int charOffset) { + Builder addBuilder(String name, Builder declaration, int charOffset) { if (name == null || name.isEmpty) return null; bool isSetter = declaration.isSetter; if (isSetter) { @@ -201,14 +196,13 @@ class DillLibraryBuilder extends LibraryBuilder { } @override - void addToScope( - String name, Declaration member, int charOffset, bool isImport) { + void addToScope(String name, Builder member, int charOffset, bool isImport) { unimplemented("addToScope", charOffset, fileUri); } @override - Declaration computeAmbiguousDeclaration( - String name, Declaration builder, Declaration other, int charOffset, + Builder computeAmbiguousDeclaration( + String name, Builder builder, Builder other, int charOffset, {bool isExport: false, bool isImport: false}) { if (builder == other) return builder; if (builder is InvalidTypeBuilder) return builder; @@ -240,7 +234,7 @@ class DillLibraryBuilder extends LibraryBuilder { if (exportsAlreadyFinalized) return; exportsAlreadyFinalized = true; unserializableExports?.forEach((String name, String messageText) { - Declaration declaration; + Builder declaration; switch (name) { case "dynamic": case "void": @@ -287,7 +281,7 @@ class DillLibraryBuilder extends LibraryBuilder { -1, fileUri); } - Declaration declaration; + Builder declaration; if (isSetter) { declaration = library.exportScope.setters[name]; exportScopeBuilder.addSetter(name, declaration); diff --git a/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart index a648190da6f6..e733b848e330 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart @@ -9,7 +9,7 @@ import 'package:kernel/ast.dart' import '../kernel/kernel_builder.dart' show - Declaration, + Builder, MemberBuilder, isRedirectingGenerativeConstructorImplementation; @@ -23,7 +23,7 @@ class DillMemberBuilder extends MemberBuilder { final Member member; - DillMemberBuilder(Member member, Declaration parent) + DillMemberBuilder(Member member, Builder parent) : modifiers = computeModifiers(member), member = member, super(parent, member.fileOffset); diff --git a/pkg/front_end/lib/src/fasta/export.dart b/pkg/front_end/lib/src/fasta/export.dart index 476de4c6f1d9..05044ebaf1f6 100644 --- a/pkg/front_end/lib/src/fasta/export.dart +++ b/pkg/front_end/lib/src/fasta/export.dart @@ -4,7 +4,7 @@ library fasta.export; -import 'builder/builder.dart' show Declaration, LibraryBuilder; +import 'builder/builder.dart' show Builder, LibraryBuilder; import 'combinator.dart' show Combinator; @@ -23,7 +23,7 @@ class Export { Uri get fileUri => exporter.fileUri; - bool addToExportScope(String name, Declaration member) { + bool addToExportScope(String name, Builder member) { if (combinators != null) { for (Combinator combinator in combinators) { if (combinator.isShow && !combinator.names.contains(name)) return false; diff --git a/pkg/front_end/lib/src/fasta/import.dart b/pkg/front_end/lib/src/fasta/import.dart index 9ba401963bc8..af6a7fb1d33d 100644 --- a/pkg/front_end/lib/src/fasta/import.dart +++ b/pkg/front_end/lib/src/fasta/import.dart @@ -6,7 +6,7 @@ library fasta.import; import 'package:kernel/ast.dart' show LibraryDependency; -import 'builder/builder.dart' show Declaration, LibraryBuilder; +import 'builder/builder.dart' show Builder, LibraryBuilder; import 'builder/prefix_builder.dart' show PrefixBuilder; @@ -59,17 +59,17 @@ class Import { void finalizeImports(LibraryBuilder importer) { if (nativeImportPath != null) return; - void Function(String, Declaration) add; + void Function(String, Builder) add; if (prefixBuilder == null) { - add = (String name, Declaration member) { + add = (String name, Builder member) { importer.addToScope(name, member, charOffset, true); }; } else { - add = (String name, Declaration member) { + add = (String name, Builder member) { prefixBuilder.addToExportScope(name, member, charOffset); }; } - imported.exportScope.forEach((String name, Declaration member) { + imported.exportScope.forEach((String name, Builder member) { if (combinators != null) { for (Combinator combinator in combinators) { if (combinator.isShow && !combinator.names.contains(name)) return; @@ -79,7 +79,7 @@ class Import { add(name, member); }); if (prefixBuilder != null) { - Declaration existing = + Builder existing = importer.addBuilder(prefix, prefixBuilder, prefixCharOffset); if (existing == prefixBuilder) { importer.addToScope(prefix, prefixBuilder, prefixCharOffset, true); diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index 5d1b18c25ad6..e08d626c08c0 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -438,7 +438,7 @@ class BodyBuilder extends ScopeListener Scope outerSwitchScope = pop(); if (switchScope.unclaimedForwardDeclarations != null) { switchScope.unclaimedForwardDeclarations - .forEach((String name, Declaration declaration) { + .forEach((String name, Builder declaration) { if (outerSwitchScope == null) { JumpTarget target = declaration; for (Statement statement in target.users) { @@ -476,7 +476,7 @@ class BodyBuilder extends ScopeListener void declareVariable(VariableDeclaration variable, Scope scope) { String name = variable.name; - Declaration existing = scope.local[name]; + Builder existing = scope.local[name]; if (existing != null) { // This reports an error for duplicated declarations in the same scope: // `{ var x; var x; }` @@ -616,7 +616,7 @@ class BodyBuilder extends ScopeListener Expression initializer = pop(); Identifier identifier = pop(); String name = identifier.name; - Declaration declaration; + Builder declaration; if (classBuilder != null) { declaration = classBuilder.getLocalMember(name); } else { @@ -1795,7 +1795,7 @@ class BodyBuilder extends ScopeListener if (token.isSynthetic) { return new ParserErrorGenerator(this, token, fasta.messageSyntheticToken); } - Declaration declaration = scope.lookup(name, charOffset, uri); + Builder declaration = scope.lookup(name, charOffset, uri); if (declaration is UnlinkedDeclaration) { return new UnlinkedGenerator(this, token, declaration); } @@ -1893,7 +1893,7 @@ class BodyBuilder extends ScopeListener } else { if (declaration.hasProblem && declaration is! AccessErrorBuilder) return declaration; - Declaration setter; + Builder setter; if (declaration.isSetter) { setter = declaration; } else if (declaration.isGetter) { @@ -3693,8 +3693,7 @@ class BodyBuilder extends ScopeListener return buildProblem(fasta.messageEnumInstantiation, nameToken.charOffset, nameToken.length); } - Declaration b = - type.findConstructorOrFactory(name, charOffset, uri, library); + Builder b = type.findConstructorOrFactory(name, charOffset, uri, library); Member target = b?.target; if (b == null) { // Not found. Reported below. @@ -4016,7 +4015,7 @@ class BodyBuilder extends ScopeListener ..fileOffset = name.charOffset; // TODO(ahe): Why are we looking up in local scope, but declaring in parent // scope? - Declaration existing = scope.local[name.name]; + Builder existing = scope.local[name.name]; if (existing != null) { reportDuplicatedDeclaration(existing, name.name, name.charOffset); } @@ -4754,7 +4753,7 @@ class BodyBuilder extends ScopeListener if (hasTarget) { identifier = pop(); name = identifier.name; - Declaration namedTarget = scope.lookupLabel(identifier.name); + Builder namedTarget = scope.lookupLabel(identifier.name); if (namedTarget != null && namedTarget is! JumpTarget) { Token labelToken = continueKeyword.next; push(problemInLoopOrSwitch = buildProblemStatement( @@ -4974,8 +4973,7 @@ class BodyBuilder extends ScopeListener [int charOffset = -1]) { addProblemErrorIfConst(message, charOffset, className.length); // TODO(ahe): The following doesn't make sense to Analyzer AST. - Declaration constructor = - library.loader.getAbstractClassInstantiationError(); + Builder constructor = library.loader.getAbstractClassInstantiationError(); Expression invocation = buildStaticInvocation( constructor.target, forest.arguments([ @@ -5048,7 +5046,7 @@ class BodyBuilder extends ScopeListener Initializer buildFieldInitializer(bool isSynthetic, String name, int fieldNameOffset, int assignmentOffset, Expression expression, {DartType formalType}) { - Declaration builder = + Builder builder = classBuilder.scope.local[name] ?? classBuilder.origin.scope.local[name]; if (builder?.next != null) { // Duplicated name, already reported. @@ -5079,7 +5077,7 @@ class BodyBuilder extends ScopeListener .withArguments(name) .withLocation(uri, builder.charOffset, name.length) ]); - Declaration constructor = + Builder constructor = library.loader.getDuplicatedFieldInitializerError(); Expression invocation = buildStaticInvocation( constructor.target, @@ -5339,7 +5337,7 @@ class BodyBuilder extends ScopeListener @override void reportDuplicatedDeclaration( - Declaration existing, String name, int charOffset) { + Builder existing, String name, int charOffset) { List context = existing.isSynthetic ? null : [ @@ -5485,7 +5483,7 @@ class Operator { String toString() => "operator($name)"; } -class JumpTarget extends Declaration { +class JumpTarget extends Builder { final List users = []; final JumpTargetKind kind; @@ -5555,7 +5553,7 @@ class JumpTarget extends Declaration { String get fullNameForErrors => ""; } -class LabelTarget extends Declaration implements JumpTarget { +class LabelTarget extends Builder implements JumpTarget { @override final MemberBuilder parent; @@ -5673,13 +5671,13 @@ class FormalParameters { } Scope computeFormalParameterScope( - Scope parent, Declaration declaration, ExpressionGeneratorHelper helper) { + Scope parent, Builder declaration, ExpressionGeneratorHelper helper) { if (parameters == null) return parent; assert(parameters.isNotEmpty); - Map local = {}; + Map local = {}; for (FormalParameterBuilder parameter in parameters) { - Declaration existing = local[parameter.name]; + Builder existing = local[parameter.name]; if (existing != null) { helper.reportDuplicatedDeclaration( existing, parameter.name, parameter.charOffset); @@ -5724,7 +5722,7 @@ String debugName(String className, String name, [String prefix]) { String getNodeName(Object node) { if (node is Identifier) { return node.name; - } else if (node is Declaration) { + } else if (node is Builder) { return node.fullNameForErrors; } else if (node is QualifiedName) { return flattenName(node, node.charOffset, null); diff --git a/pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart b/pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart index b10e55cf7d83..34c9d4e25a2d 100644 --- a/pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart @@ -76,7 +76,7 @@ import 'forwarding_node.dart' show ForwardingNode; import 'kernel_builder.dart' show - Declaration, + Builder, FormalParameterBuilder, ImplicitFieldType, ClassBuilder, @@ -98,7 +98,7 @@ class DebugLogger { void log(Object message) => print(message); } -int compareDeclarations(Declaration a, Declaration b) { +int compareDeclarations(Builder a, Builder b) { return ClassHierarchy.compareMembers(a.target, b.target); } @@ -116,7 +116,7 @@ bool isNameVisibleIn(Name name, LibraryBuilder library) { /// See the section named "Class Member Conflicts" in [Dart Programming /// Language Specification]( /// ../../../../../../docs/language/dartLangSpec.tex#classMemberConflicts). -bool isInheritanceConflict(Declaration a, Declaration b) { +bool isInheritanceConflict(Builder a, Builder b) { if (a.isStatic) return true; if (memberKind(a.target) == memberKind(b.target)) return false; if (a.isField) return !(b.isField || b.isGetter || b.isSetter); @@ -127,7 +127,7 @@ bool isInheritanceConflict(Declaration a, Declaration b) { return true; } -bool impliesSetter(Declaration declaration) { +bool impliesSetter(Builder declaration) { return declaration.isField && !(declaration.isFinal || declaration.isConst); } @@ -251,7 +251,7 @@ class ClassHierarchyBuilder { ClassHierarchyNode supertypeNode = getNodeFromKernelClass(supertype); List supertypes = clsNode.superclasses; int depth = supertypeNode.depth; - Declaration supertypeDeclaration = supertypeNode.cls; + Builder supertypeDeclaration = supertypeNode.cls; if (depth < supertypes.length) { TypeBuilder asSupertypeOf = supertypes[depth]; if (asSupertypeOf.declaration == supertypeDeclaration) @@ -341,7 +341,7 @@ class ClassHierarchyBuilder { Member getCombinedMemberSignatureKernel(Class cls, Name name, bool isSetter, int charOffset, SourceLibraryBuilder library) { - Declaration declaration = + Builder declaration = getNodeFromKernelClass(cls).getInterfaceMember(name, isSetter); if (declaration?.isStatic ?? true) return null; if (declaration.next != null) { @@ -384,7 +384,7 @@ class ClassHierarchyNodeBuilder { bool hasNoSuchMethod = false; - List abstractMembers = null; + List abstractMembers = null; ClassHierarchyNodeBuilder(this.hierarchy, this.cls); @@ -402,8 +402,7 @@ class ClassHierarchyNodeBuilder { /// /// If [mergeKind] is `MergeKind.supertypes`, [a] should implement [b], and /// [b] is implicitly abstract. - Declaration handleMergeConflict( - Declaration a, Declaration b, MergeKind mergeKind) { + Builder handleMergeConflict(Builder a, Builder b, MergeKind mergeKind) { debug?.log( "handleMergeConflict: ${fullName(a)} ${fullName(b)} ${mergeKind}"); // TODO(ahe): Enable this optimization, but be careful about abstract @@ -414,7 +413,7 @@ class ClassHierarchyNodeBuilder { // Don't check overrides involving duplicated members. return a; } - Declaration result = checkInheritanceConflict(a, b); + Builder result = checkInheritanceConflict(a, b); if (result != null) return result; result = a; switch (mergeKind) { @@ -540,19 +539,19 @@ class ClassHierarchyNodeBuilder { return result; } - Declaration checkInheritanceConflict(Declaration a, Declaration b) { + Builder checkInheritanceConflict(Builder a, Builder b) { if (a is DelayedMember) { - Declaration result; + Builder result; for (int i = 0; i < a.declarations.length; i++) { - Declaration d = checkInheritanceConflict(a.declarations[i], b); + Builder d = checkInheritanceConflict(a.declarations[i], b); result ??= d; } return result; } if (b is DelayedMember) { - Declaration result; + Builder result; for (int i = 0; i < b.declarations.length; i++) { - Declaration d = checkInheritanceConflict(a, b.declarations[i]); + Builder d = checkInheritanceConflict(a, b.declarations[i]); result ??= d; } return result; @@ -564,12 +563,12 @@ class ClassHierarchyNodeBuilder { return null; } - bool inferMethodTypes(ProcedureBuilder a, Declaration b) { + bool inferMethodTypes(ProcedureBuilder a, Builder b) { debug?.log( "Trying to infer types for ${fullName(a)} based on ${fullName(b)}"); if (b is DelayedMember) { bool hasSameSignature = true; - List declarations = b.declarations; + List declarations = b.declarations; for (int i = 0; i < declarations.length; i++) { if (!inferMethodTypes(a, declarations[i])) { hasSameSignature = false; @@ -763,7 +762,7 @@ class ClassHierarchyNodeBuilder { return result; } - bool inferGetterType(ProcedureBuilder a, Declaration b) { + bool inferGetterType(ProcedureBuilder a, Builder b) { debug?.log( "Inferring getter types for ${fullName(a)} based on ${fullName(b)}"); Member bTarget = b.target; @@ -796,7 +795,7 @@ class ClassHierarchyNodeBuilder { return a.target.function.returnType == bType; } - bool inferSetterType(ProcedureBuilder a, Declaration b) { + bool inferSetterType(ProcedureBuilder a, Builder b) { debug?.log( "Inferring setter types for ${fullName(a)} based on ${fullName(b)}"); Member bTarget = b.target; @@ -836,7 +835,7 @@ class ClassHierarchyNodeBuilder { return aParameter.type == bType; } - void checkValidOverride(Declaration a, Declaration b) { + void checkValidOverride(Builder a, Builder b) { debug?.log( "checkValidOverride(${fullName(a)}, ${fullName(b)}) ${a.runtimeType}"); if (a is ProcedureBuilder) { @@ -860,12 +859,12 @@ class ClassHierarchyNodeBuilder { } } - bool inferFieldTypes(MemberBuilder a, Declaration b) { + bool inferFieldTypes(MemberBuilder a, Builder b) { debug?.log( "Trying to infer field types for ${fullName(a)} based on ${fullName(b)}"); if (b is DelayedMember) { bool hasSameSignature = true; - List declarations = b.declarations; + List declarations = b.declarations; for (int i = 0; i < declarations.length; i++) { if (!inferFieldTypes(a, declarations[i])) { hasSameSignature = false; @@ -945,8 +944,8 @@ class ClassHierarchyNodeBuilder { return result; } - void copyParameterCovariance(Declaration parent, - VariableDeclaration aParameter, VariableDeclaration bParameter) { + void copyParameterCovariance(Builder parent, VariableDeclaration aParameter, + VariableDeclaration bParameter) { if (parent == cls) { if (bParameter.isCovariant) { aParameter.isCovariant = true; @@ -958,7 +957,7 @@ class ClassHierarchyNodeBuilder { } void copyParameterCovarianceFromField( - Declaration parent, VariableDeclaration aParameter, Field bField) { + Builder parent, VariableDeclaration aParameter, Field bField) { if (parent == cls) { if (bField.isCovariant) { aParameter.isCovariant = true; @@ -969,7 +968,7 @@ class ClassHierarchyNodeBuilder { } } - void copyFieldCovariance(Declaration parent, Field aField, Field bField) { + void copyFieldCovariance(Builder parent, Field aField, Field bField) { if (parent == cls) { if (bField.isCovariant) { aField.isCovariant = true; @@ -981,7 +980,7 @@ class ClassHierarchyNodeBuilder { } void copyFieldCovarianceFromParameter( - Declaration parent, Field aField, VariableDeclaration bParameter) { + Builder parent, Field aField, VariableDeclaration bParameter) { if (parent == cls) { if (bParameter.isCovariant) { aField.isCovariant = true; @@ -993,7 +992,7 @@ class ClassHierarchyNodeBuilder { } void copyTypeParameterCovariance( - Declaration parent, TypeParameter aParameter, TypeParameter bParameter) { + Builder parent, TypeParameter aParameter, TypeParameter bParameter) { if (parent == cls) { if (bParameter.isGenericCovariantImpl) { aParameter.isGenericCovariantImpl = true; @@ -1001,7 +1000,7 @@ class ClassHierarchyNodeBuilder { } } - void reportInheritanceConflict(Declaration a, Declaration b) { + void reportInheritanceConflict(Builder a, Builder b) { String name = a.fullNameForErrors; if (a.parent != b.parent) { if (a.parent == cls) { @@ -1017,8 +1016,8 @@ class ClassHierarchyNodeBuilder { context: inheritedConflictContext(a, b)); } } else if (a.isStatic != b.isStatic) { - Declaration staticMember; - Declaration instanceMember; + Builder staticMember; + Builder instanceMember; if (a.isStatic) { staticMember = a; instanceMember = b; @@ -1038,8 +1037,8 @@ class ClassHierarchyNodeBuilder { // we always report the one with higher charOffset as the duplicate, // the message duplication logic ensures that we only report this // problem once. - Declaration existing; - Declaration duplicate; + Builder existing; + Builder duplicate; assert(a.fileUri == b.fileUri); if (a.charOffset < b.charOffset) { existing = a; @@ -1066,7 +1065,7 @@ class ClassHierarchyNodeBuilder { /// /// If [mergeKind] is `MergeKind.supertypes`, [member] isn't /// implementing/overriding anything. - void handleOnlyA(Declaration member, MergeKind mergeKind) { + void handleOnlyA(Builder member, MergeKind mergeKind) { if (mergeKind == MergeKind.interfacesMembers || mergeKind == MergeKind.interfacesSetters) { return; @@ -1090,7 +1089,7 @@ class ClassHierarchyNodeBuilder { /// /// If [mergeKind] is `MergeKind.supertypes`, [member] is implicitly /// abstract, and not implemented. - Declaration handleOnlyB(Declaration member, MergeKind mergeKind) { + Builder handleOnlyB(Builder member, MergeKind mergeKind) { if (mergeKind == MergeKind.interfacesMembers || mergeKind == MergeKind.interfacesSetters) { return member; @@ -1121,8 +1120,8 @@ class ClassHierarchyNodeBuilder { return member; } - void recordAbstractMember(Declaration member) { - abstractMembers ??= []; + void recordAbstractMember(Builder member) { + abstractMembers ??= []; if (member is DelayedMember) { abstractMembers.addAll(member.declarations); } else { @@ -1143,7 +1142,7 @@ class ClassHierarchyNodeBuilder { Scope scope = cls.scope; if (cls.isMixinApplication) { - Declaration mixin = cls.mixedInType.declaration; + Builder mixin = cls.mixedInType.declaration; inferMixinApplication(); // recordSupertype(cls.mixedInType); while (mixin.isNamedMixinApplication) { @@ -1157,35 +1156,33 @@ class ClassHierarchyNodeBuilder { } /// Members (excluding setters) declared in [cls]. - List localMembers = - new List.from(scope.local.values) - ..sort(compareDeclarations); + List localMembers = new List.from(scope.local.values) + ..sort(compareDeclarations); /// Setters declared in [cls]. - List localSetters = - new List.from(scope.setters.values) - ..sort(compareDeclarations); + List localSetters = new List.from(scope.setters.values) + ..sort(compareDeclarations); // Add implied setters from fields in [localMembers]. localSetters = mergeAccessors(localMembers, localSetters); /// Members (excluding setters) declared in [cls] or its superclasses. This /// includes static methods of [cls], but not its superclasses. - List classMembers; + List classMembers; /// Setters declared in [cls] or its superclasses. This includes static /// setters of [cls], but not its superclasses. - List classSetters; + List classSetters; /// Members (excluding setters) inherited from interfaces. This contains no static /// members. Is null if no interfaces are implemented by this class or its /// superclasses. - List interfaceMembers; + List interfaceMembers; /// Setters inherited from interfaces. This contains no static setters. Is /// null if no interfaces are implemented by this class or its /// superclasses. - List interfaceSetters; + List interfaceSetters; List superclasses; @@ -1323,7 +1320,7 @@ class ClassHierarchyNodeBuilder { if (supertype is NamedTypeBuilder) { debug?.log( "In ${this.cls.fullNameForErrors} recordSupertype(${supertype.fullNameForErrors})"); - Declaration declaration = supertype.declaration; + Builder declaration = supertype.declaration; if (declaration is! ClassBuilder) return supertype; ClassBuilder cls = declaration; if (cls.isMixinApplication) { @@ -1355,7 +1352,7 @@ class ClassHierarchyNodeBuilder { List substSupertypes( NamedTypeBuilder supertype, List supertypes) { - Declaration declaration = supertype.declaration; + Builder declaration = supertype.declaration; if (declaration is! ClassBuilder) return supertypes; ClassBuilder cls = declaration; List typeVariables = cls.typeVariables; @@ -1426,10 +1423,10 @@ class ClassHierarchyNodeBuilder { ClassHierarchyNode supernode, List interfaces) { debug?.log( "mergeInterfaces($cls (${this.cls}) ${supernode.interfaces} ${interfaces}"); - List> memberLists = - new List>(interfaces.length + 1); - List> setterLists = - new List>(interfaces.length + 1); + List> memberLists = + new List>(interfaces.length + 1); + List> setterLists = + new List>(interfaces.length + 1); memberLists[0] = supernode.interfaceMembers; setterLists[0] = supernode.interfaceSetters; for (int i = 0; i < interfaces.length; i++) { @@ -1449,16 +1446,15 @@ class ClassHierarchyNodeBuilder { mergeLists(setterLists, MergeKind.interfacesSetters)); } - List mergeLists( - List> input, MergeKind mergeKind) { + List mergeLists(List> input, MergeKind mergeKind) { // This is a k-way merge sort (where k is `input.length + 1`). We merge the // lists pairwise, which reduces the number of lists to merge by half on // each iteration. Consequently, we perform O(log k) merges. while (input.length > 1) { - List> output = >[]; + List> output = >[]; for (int i = 0; i < input.length - 1; i += 2) { - List first = input[i]; - List second = input[i + 1]; + List first = input[i]; + List second = input[i + 1]; if (first == null) { output.add(second); } else if (second == null) { @@ -1478,17 +1474,16 @@ class ClassHierarchyNodeBuilder { /// Merge [and check] accessors. This entails copying mutable fields to /// setters to simulate implied setters, and checking that setters don't /// override regular methods. - List mergeAccessors( - List members, List setters) { - final List mergedSetters = new List.filled( + List mergeAccessors(List members, List setters) { + final List mergedSetters = new List.filled( members.length + setters.length, null, growable: true); int storeIndex = 0; int i = 0; int j = 0; while (i < members.length && j < setters.length) { - final Declaration member = members[i]; - final Declaration setter = setters[j]; + final Builder member = members[i]; + final Builder setter = setters[j]; final int compare = compareDeclarations(member, setter); if (compare == 0) { mergedSetters[storeIndex++] = setter; @@ -1505,7 +1500,7 @@ class ClassHierarchyNodeBuilder { } } while (i < members.length) { - final Declaration member = members[i]; + final Builder member = members[i]; if (impliesSetter(member)) { mergedSetters[storeIndex++] = member; } @@ -1526,7 +1521,7 @@ class ClassHierarchyNodeBuilder { void reportMissingMembers() { Map contextMap = {}; for (int i = 0; i < abstractMembers.length; i++) { - Declaration declaration = abstractMembers[i]; + Builder declaration = abstractMembers[i]; Member target = declaration.target; if (isNameVisibleIn(target.name, cls.library)) { String name = declaration.fullNameForErrors; @@ -1557,17 +1552,17 @@ class ClassHierarchyNodeBuilder { // TOOD(ahe): Implement this. } - List merge( - List aList, List bList, MergeKind mergeKind) { - final List result = new List.filled( + List merge( + List aList, List bList, MergeKind mergeKind) { + final List result = new List.filled( aList.length + bList.length, null, growable: true); int storeIndex = 0; int i = 0; int j = 0; while (i < aList.length && j < bList.length) { - final Declaration a = aList[i]; - final Declaration b = bList[j]; + final Builder a = aList[i]; + final Builder b = bList[j]; if ((mergeKind == MergeKind.interfacesMembers || mergeKind == MergeKind.interfacesSetters) && a.isStatic) { @@ -1593,7 +1588,7 @@ class ClassHierarchyNodeBuilder { } } while (i < aList.length) { - final Declaration a = aList[i]; + final Builder a = aList[i]; if (!(mergeKind == MergeKind.interfacesMembers || mergeKind == MergeKind.interfacesSetters) || !a.isStatic) { @@ -1603,7 +1598,7 @@ class ClassHierarchyNodeBuilder { i++; } while (j < bList.length) { - final Declaration b = bList[j]; + final Builder b = bList[j]; if (!b.isStatic) { result[storeIndex++] = handleOnlyB(b, mergeKind); } @@ -1662,10 +1657,10 @@ class ClassHierarchyNode { /// All the members of this class including [classMembers] of its /// superclasses. The members are sorted by [compareDeclarations]. - final List classMembers; + final List classMembers; /// Similar to [classMembers] but for setters. - final List classSetters; + final List classSetters; /// All the interface members of this class including [interfaceMembers] of /// its supertypes. The members are sorted by [compareDeclarations]. @@ -1674,12 +1669,12 @@ class ClassHierarchyNode { /// from interfaces. /// /// This may be null, in which case [classMembers] is the interface members. - final List interfaceMembers; + final List interfaceMembers; /// Similar to [interfaceMembers] but for setters. /// /// This may be null, in which case [classSetters] is the interface setters. - final List interfaceSetters; + final List interfaceSetters; /// All superclasses of [cls] excluding itself. The classes are sorted by /// depth from the root (Object) in ascending order. @@ -1713,13 +1708,13 @@ class ClassHierarchyNode { List result = new List( 1 + superclasses.length + interfaces.length); for (int i = 0; i < superclasses.length; i++) { - Declaration declaration = superclasses[i].declaration; + Builder declaration = superclasses[i].declaration; if (declaration is ClassBuilder) { result[i] = hierarchy.getNodeFromClass(declaration); } } for (int i = 0; i < interfaces.length; i++) { - Declaration declaration = interfaces[i].declaration; + Builder declaration = interfaces[i].declaration; if (declaration is ClassBuilder) { result[i + superclasses.length] = hierarchy.getNodeFromClass(declaration); @@ -1769,12 +1764,11 @@ class ClassHierarchyNode { return "$sb"; } - void printMembers( - List members, StringBuffer sb, String heading) { + void printMembers(List members, StringBuffer sb, String heading) { sb.write(" "); sb.write(heading); sb.writeln(":"); - for (Declaration member in members) { + for (Builder member in members) { sb ..write(" ") ..write(member.parent.fullNameForErrors) @@ -1784,7 +1778,7 @@ class ClassHierarchyNode { } } - Declaration getInterfaceMember(Name name, bool isSetter) { + Builder getInterfaceMember(Name name, bool isSetter) { return findMember( name, isSetter @@ -1792,7 +1786,7 @@ class ClassHierarchyNode { : interfaceMembers ?? classMembers); } - Declaration findMember(Name name, List declarations) { + Builder findMember(Name name, List declarations) { // TODO(ahe): Consider creating a map or scope. The obvious choice would be // to use scopes, but they don't handle private names correctly. @@ -1800,7 +1794,7 @@ class ClassHierarchyNode { int low = 0, high = declarations.length - 1; while (low <= high) { int mid = low + ((high - low) >> 1); - Declaration pivot = declarations[mid]; + Builder pivot = declarations[mid]; int comparison = ClassHierarchy.compareNames(name, pivot.target.name); if (comparison < 0) { high = mid - 1; @@ -1816,7 +1810,7 @@ class ClassHierarchyNode { return null; } - Declaration getDispatchTarget(Name name, bool isSetter) { + Builder getDispatchTarget(Name name, bool isSetter) { return findMember(name, isSetter ? classSetters : classMembers); } @@ -1827,9 +1821,9 @@ class ClassHierarchyNode { } class MergeResult { - final List mergedMembers; + final List mergedMembers; - final List mergedSetters; + final List mergedSetters; MergeResult(this.mergedMembers, this.mergedSetters); } @@ -1860,7 +1854,7 @@ enum MergeKind { settersWithMembers, } -List inheritedConflictContext(Declaration a, Declaration b) { +List inheritedConflictContext(Builder a, Builder b) { return inheritedConflictContextKernel( a.target, b.target, a.fullNameForErrors.length); } @@ -1977,8 +1971,8 @@ class TypeBuilderConstraintGatherer extends TypeConstraintGatherer class DelayedOverrideCheck { final ClassBuilder cls; - final Declaration a; - final Declaration b; + final Builder a; + final Builder b; const DelayedOverrideCheck(this.cls, this.a, this.b); @@ -1990,7 +1984,7 @@ class DelayedOverrideCheck { isInterfaceCheck: !cls.isMixinApplication); } - Declaration a = this.a; + Builder a = this.a; debug?.log( "Delayed override check of ${fullName(a)} ${fullName(b)} wrt. ${cls.fullNameForErrors}"); if (cls == a.parent) { @@ -2080,13 +2074,13 @@ class DelayedOverrideCheck { } } -abstract class DelayedMember extends Declaration { +abstract class DelayedMember extends Builder { /// The class which has inherited [declarations]. @override final ClassBuilder parent; /// Conflicting declarations. - final List declarations; + final List declarations; final isSetter; @@ -2095,7 +2089,7 @@ abstract class DelayedMember extends Declaration { DelayedMember( this.parent, this.declarations, this.isSetter, this.modifyKernel); - void addAllDeclarationsTo(List declarations) { + void addAllDeclarationsTo(List declarations) { for (int i = 0; i < this.declarations.length; i++) { addDeclarationIfDifferent(this.declarations[i], declarations); } @@ -2131,7 +2125,7 @@ class InheritedImplementationInterfaceConflict extends DelayedMember { final bool isInheritableConflict; InheritedImplementationInterfaceConflict(ClassBuilder parent, - List declarations, bool isSetter, bool modifyKernel, + List declarations, bool isSetter, bool modifyKernel, {this.isInheritableConflict = true}) : super(parent, declarations, isSetter, modifyKernel); @@ -2148,7 +2142,7 @@ class InheritedImplementationInterfaceConflict extends DelayedMember { return combinedMemberSignatureResult; } if (!parent.isAbstract) { - Declaration concreteImplementation = declarations.first; + Builder concreteImplementation = declarations.first; for (int i = 1; i < declarations.length; i++) { new DelayedOverrideCheck( parent, concreteImplementation, declarations[i]) @@ -2168,14 +2162,10 @@ class InheritedImplementationInterfaceConflict extends DelayedMember { parent, declarations, isSetter, modifyKernel); } - static Declaration combined( - ClassBuilder parent, - Declaration concreteImplementation, - Declaration other, - bool isSetter, - bool createForwarders, + static Builder combined(ClassBuilder parent, Builder concreteImplementation, + Builder other, bool isSetter, bool createForwarders, {bool isInheritableConflict = true}) { - List declarations = []; + List declarations = []; if (concreteImplementation is DelayedMember) { concreteImplementation.addAllDeclarationsTo(declarations); } else { @@ -2197,7 +2187,7 @@ class InheritedImplementationInterfaceConflict extends DelayedMember { } class InterfaceConflict extends DelayedMember { - InterfaceConflict(ClassBuilder parent, List declarations, + InterfaceConflict(ClassBuilder parent, List declarations, bool isSetter, bool modifyKernel) : super(parent, declarations, isSetter, modifyKernel); @@ -2248,10 +2238,10 @@ class InterfaceConflict extends DelayedMember { return combinedMemberSignatureResult = declarations.first.target; } DartType thisType = parent.cls.thisType; - Declaration bestSoFar; + Builder bestSoFar; DartType bestTypeSoFar; for (int i = declarations.length - 1; i >= 0; i--) { - Declaration candidate = declarations[i]; + Builder candidate = declarations[i]; Member target = candidate.target; DartType candidateType = computeMemberType(hierarchy, thisType, target); if (bestSoFar == null) { @@ -2272,7 +2262,7 @@ class InterfaceConflict extends DelayedMember { if (bestSoFar != null) { debug?.log("Combined Member Signature bestSoFar: ${fullName(bestSoFar)}"); for (int i = 0; i < declarations.length; i++) { - Declaration candidate = declarations[i]; + Builder candidate = declarations[i]; Member target = candidate.target; DartType candidateType = computeMemberType(hierarchy, thisType, target); if (!isMoreSpecific(hierarchy, bestTypeSoFar, candidateType)) { @@ -2297,7 +2287,7 @@ class InterfaceConflict extends DelayedMember { if (bestSoFar == null) { String name = parent.fullNameForErrors; int length = parent.isAnonymousMixinApplication ? 1 : name.length; - List context = declarations.map((Declaration d) { + List context = declarations.map((Builder d) { return messageDeclaredMemberConflictsWithInheritedMemberCause .withLocation(d.fileUri, d.charOffset, d.fullNameForErrors.length); }).toList(); @@ -2355,9 +2345,9 @@ class InterfaceConflict extends DelayedMember { : new InterfaceConflict(parent, declarations, isSetter, modifyKernel); } - static Declaration combined(ClassBuilder parent, Declaration a, Declaration b, + static Builder combined(ClassBuilder parent, Builder a, Builder b, bool isSetter, bool createForwarders) { - List declarations = []; + List declarations = []; if (a is DelayedMember) { a.addAllDeclarationsTo(declarations); } else { @@ -2380,16 +2370,16 @@ class InterfaceConflict extends DelayedMember { class AbstractMemberOverridingImplementation extends DelayedMember { AbstractMemberOverridingImplementation( ClassBuilder parent, - Declaration abstractMember, - Declaration concreteImplementation, + Builder abstractMember, + Builder concreteImplementation, bool isSetter, bool modifyKernel) - : super(parent, [concreteImplementation, abstractMember], + : super(parent, [concreteImplementation, abstractMember], isSetter, modifyKernel); - Declaration get concreteImplementation => declarations[0]; + Builder get concreteImplementation => declarations[0]; - Declaration get abstractMember => declarations[1]; + Builder get abstractMember => declarations[1]; Member check(ClassHierarchyBuilder hierarchy) { if (!parent.isAbstract && !hierarchy.nodes[parent.cls].hasNoSuchMethod) { @@ -2418,7 +2408,7 @@ class AbstractMemberOverridingImplementation extends DelayedMember { concreteImplementation, isSetter, modifyKernel); } - static Declaration selectAbstract(Declaration declaration) { + static Builder selectAbstract(Builder declaration) { if (declaration is AbstractMemberOverridingImplementation) { return declaration.abstractMember; } else { @@ -2426,7 +2416,7 @@ class AbstractMemberOverridingImplementation extends DelayedMember { } } - static Declaration selectConcrete(Declaration declaration) { + static Builder selectConcrete(Builder declaration) { if (declaration is AbstractMemberOverridingImplementation) { return declaration.concreteImplementation; } else { @@ -2436,7 +2426,7 @@ class AbstractMemberOverridingImplementation extends DelayedMember { } void addDeclarationIfDifferent( - Declaration declaration, List declarations) { + Builder declaration, List declarations) { Member target = declaration.target; if (target is Procedure) { FunctionNode function = target.function; @@ -2454,12 +2444,12 @@ void addDeclarationIfDifferent( declarations.add(declaration); } -String fullName(Declaration declaration) { +String fullName(Builder declaration) { String suffix = declaration.isSetter ? "=" : ""; if (declaration is DelayedMember) { return "${declaration.fullNameForErrors}$suffix"; } - Declaration parent = declaration.parent; + Builder parent = declaration.parent; return parent == null ? "${declaration.fullNameForErrors}$suffix" : "${parent.fullNameForErrors}.${declaration.fullNameForErrors}$suffix"; @@ -2469,7 +2459,7 @@ int compareNamedParameters(VariableDeclaration a, VariableDeclaration b) { return a.name.compareTo(b.name); } -bool isAbstract(Declaration declaration) { +bool isAbstract(Builder declaration) { return declaration.target.isAbstract || declaration is InterfaceConflict; } @@ -2587,11 +2577,11 @@ void reportCantInferFieldType(ClassBuilder cls, FieldBuilder member) { } ClassBuilder getClass(TypeBuilder type) { - Declaration declaration = type.declaration; + Builder declaration = type.declaration; return declaration is ClassBuilder ? declaration : null; } -bool hasExplicitReturnType(Declaration declaration) { +bool hasExplicitReturnType(Builder declaration) { assert(declaration is ProcedureBuilder || declaration is DillMemberBuilder, "${declaration.runtimeType}"); return declaration is ProcedureBuilder @@ -2599,7 +2589,7 @@ bool hasExplicitReturnType(Declaration declaration) { : true; } -bool hasExplicitlyTypedFormalParameter(Declaration declaration, int index) { +bool hasExplicitlyTypedFormalParameter(Builder declaration, int index) { assert(declaration is ProcedureBuilder || declaration is DillMemberBuilder, "${declaration.runtimeType}"); return declaration is ProcedureBuilder diff --git a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart index 1aa8699ba41c..419b85a00ff3 100644 --- a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart +++ b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart @@ -111,7 +111,7 @@ import 'kernel_ast_api.dart' import 'kernel_builder.dart' show AccessErrorBuilder, - Declaration, + Builder, ClassBuilder, InvalidTypeBuilder, NamedTypeBuilder, @@ -1451,7 +1451,7 @@ class StaticAccessGenerator extends Generator { super(helper, token); factory StaticAccessGenerator.fromBuilder(ExpressionGeneratorHelper helper, - Declaration declaration, Token token, Declaration builderSetter) { + Builder declaration, Token token, Builder builderSetter) { if (declaration is AccessErrorBuilder) { AccessErrorBuilder error = declaration; declaration = error.builder; @@ -1851,7 +1851,7 @@ class TypeUseGenerator extends ReadOnlyAccessGenerator { if (declaration is ClassBuilder) { ClassBuilder declaration = this.declaration; - Declaration member = declaration.findStaticBuilder( + Builder member = declaration.findStaticBuilder( name.name, offsetForToken(send.token), _uri, _helper.library); Generator generator; @@ -1874,7 +1874,7 @@ class TypeUseGenerator extends ReadOnlyAccessGenerator { return _helper.buildProblem( member.message, member.charOffset, name.name.length); } else { - Declaration setter; + Builder setter; if (member.isSetter) { setter = member; } else if (member.isGetter) { diff --git a/pkg/front_end/lib/src/fasta/kernel/expression_generator_helper.dart b/pkg/front_end/lib/src/fasta/kernel/expression_generator_helper.dart index a68e82b456a2..128a924f2ca9 100644 --- a/pkg/front_end/lib/src/fasta/kernel/expression_generator_helper.dart +++ b/pkg/front_end/lib/src/fasta/kernel/expression_generator_helper.dart @@ -22,7 +22,7 @@ import 'constness.dart' show Constness; import 'forest.dart' show Forest; -import 'kernel_builder.dart' show Declaration, PrefixBuilder, UnresolvedType; +import 'kernel_builder.dart' show Builder, PrefixBuilder, UnresolvedType; import 'kernel_ast_api.dart' show @@ -144,7 +144,7 @@ abstract class ExpressionGeneratorHelper implements InferenceHelper { List buildDartTypeArguments(List unresolvedTypes); void reportDuplicatedDeclaration( - Declaration existing, String name, int charOffset); + Builder existing, String name, int charOffset); Expression wrapSyntheticExpression(Expression node, int charOffset); diff --git a/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart b/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart index 529f402de782..764d18b4fb17 100644 --- a/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart +++ b/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart @@ -37,20 +37,20 @@ import "../type_inference/type_inference_engine.dart" import "../type_inference/type_inferrer.dart" show getNamedFormal; import "kernel_builder.dart" - show ClassHierarchyBuilder, Declaration, DelayedMember, ClassBuilder; + show ClassHierarchyBuilder, Builder, DelayedMember, ClassBuilder; class ForwardingNode { final ClassHierarchyBuilder hierarchy; final ClassBuilder parent; - final Declaration combinedMemberSignatureResult; + final Builder combinedMemberSignatureResult; final ProcedureKind kind; /// A list containing the directly implemented and directly inherited /// procedures of the class in question. - final List _candidates; + final List _candidates; ForwardingNode(this.hierarchy, this.parent, this.combinedMemberSignatureResult, this._candidates, this.kind); @@ -355,7 +355,7 @@ class ForwardingNode { /// Returns the [i]th element of [_candidates], finalizing it if necessary. Member getCandidateAt(int i) { - Declaration candidate = _candidates[i]; + Builder candidate = _candidates[i]; assert(candidate is! DelayedMember); return candidate.target; } diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart index 50c1c2642cd3..67ecf89a812c 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart @@ -89,7 +89,7 @@ import 'constant_evaluator.dart' as constants show transformLibraries; import 'kernel_builder.dart' show ClassBuilder, - Declaration, + Builder, InvalidTypeBuilder, FieldBuilder, NamedTypeBuilder, @@ -217,9 +217,9 @@ class KernelTarget extends TargetImplementation { List result = []; loader.builders.forEach((Uri uri, LibraryBuilder library) { if (library.loader == loader) { - Iterator iterator = library.iterator; + Iterator iterator = library.iterator; while (iterator.moveNext()) { - Declaration member = iterator.current; + Builder member = iterator.current; if (member is SourceClassBuilder && !member.isPatch) { result.add(member); } @@ -341,8 +341,7 @@ class KernelTarget extends TargetImplementation { nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource)); if (loader.first != null) { // TODO(sigmund): do only for full program - Declaration declaration = - loader.first.exportScope.lookup("main", -1, null); + Builder declaration = loader.first.exportScope.lookup("main", -1, null); if (declaration is AmbiguousBuilder) { AmbiguousBuilder problem = declaration; declaration = problem.getFirstDeclaration(); @@ -368,9 +367,9 @@ class KernelTarget extends TargetImplementation { Class objectClass = this.objectClass; loader.builders.forEach((Uri uri, LibraryBuilder library) { if (library.loader == loader) { - Iterator iterator = library.iterator; + Iterator iterator = library.iterator; while (iterator.moveNext()) { - Declaration declaration = iterator.current; + Builder declaration = iterator.current; if (declaration is SourceClassBuilder) { Class cls = declaration.target; if (cls != objectClass) { @@ -687,7 +686,7 @@ class KernelTarget extends TargetImplementation { for (VariableDeclaration formal in constructor.function.positionalParameters) { if (formal.isFieldFormal) { - Declaration fieldBuilder = builder.scope.local[formal.name] ?? + Builder fieldBuilder = builder.scope.local[formal.name] ?? builder.origin.scope.local[formal.name]; if (fieldBuilder is FieldBuilder) { myInitializedFields.add(fieldBuilder.field); diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_variable_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_variable_builder.dart index 26e737b4f0dc..6f1317a90a9d 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_variable_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_variable_builder.dart @@ -6,11 +6,11 @@ library fasta.kernel_variable_builder; import 'package:kernel/ast.dart' show VariableDeclaration; -import 'kernel_builder.dart' show Declaration; +import 'kernel_builder.dart' show Builder; -class VariableBuilder extends Declaration { +class VariableBuilder extends Builder { @override - final Declaration parent; + final Builder parent; @override final Uri fileUri; diff --git a/pkg/front_end/lib/src/fasta/kernel/load_library_builder.dart b/pkg/front_end/lib/src/fasta/kernel/load_library_builder.dart index a09cd2bfee92..7748bdbf7224 100644 --- a/pkg/front_end/lib/src/fasta/kernel/load_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/load_library_builder.dart @@ -19,12 +19,12 @@ import 'package:kernel/ast.dart' import '../source/source_library_builder.dart' show SourceLibraryBuilder; -import 'kernel_builder.dart' show Declaration; +import 'kernel_builder.dart' show Builder; import 'forest.dart' show Forest; /// Builder to represent the `deferLibrary.loadLibrary` calls and tear-offs. -class LoadLibraryBuilder extends Declaration { +class LoadLibraryBuilder extends Builder { final SourceLibraryBuilder parent; final LibraryDependency importDependency; diff --git a/pkg/front_end/lib/src/fasta/kernel/unlinked_scope.dart b/pkg/front_end/lib/src/fasta/kernel/unlinked_scope.dart index 6949064cf317..df16b061f066 100644 --- a/pkg/front_end/lib/src/fasta/kernel/unlinked_scope.dart +++ b/pkg/front_end/lib/src/fasta/kernel/unlinked_scope.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 'kernel_builder.dart' show Declaration, Scope; +import 'kernel_builder.dart' show Builder, Scope; /// Scope that returns an [UnlinkedDeclaration] if a name can't be resolved. /// This is intended to be used as the `enclosingScope` in `BodyBuilder` to @@ -10,13 +10,13 @@ import 'kernel_builder.dart' show Declaration, Scope; class UnlinkedScope extends Scope { UnlinkedScope() : super.top(isModifiable: false); - Declaration lookupIn(String name, int charOffset, Uri fileUri, - Map map, bool isInstanceScope) { + Builder lookupIn(String name, int charOffset, Uri fileUri, + Map map, bool isInstanceScope) { return new UnlinkedDeclaration(name, isInstanceScope, charOffset, fileUri); } } -class UnlinkedDeclaration extends Declaration { +class UnlinkedDeclaration extends Builder { final String name; final bool isInstanceScope; @@ -31,7 +31,7 @@ class UnlinkedDeclaration extends Declaration { this.name, this.isInstanceScope, this.charOffset, this.fileUri); @override - Declaration get parent => null; + Builder get parent => null; @override String get fullNameForErrors => name; diff --git a/pkg/front_end/lib/src/fasta/loader.dart b/pkg/front_end/lib/src/fasta/loader.dart index edbc4f4c4492..33b2bfcb38a1 100644 --- a/pkg/front_end/lib/src/fasta/loader.dart +++ b/pkg/front_end/lib/src/fasta/loader.dart @@ -11,7 +11,7 @@ import 'dart:collection' show Queue; import 'package:kernel/ast.dart' show Library; import 'builder/builder.dart' - show ClassBuilder, Declaration, LibraryBuilder, TypeBuilder; + show ClassBuilder, Builder, LibraryBuilder, TypeBuilder; import 'crash.dart' show firstSourceUri; @@ -323,17 +323,17 @@ fileUri: ${contextMessage.uri} return formattedMessage; } - Declaration getAbstractClassInstantiationError() { + Builder getAbstractClassInstantiationError() { return target.getAbstractClassInstantiationError(this); } - Declaration getCompileTimeError() => target.getCompileTimeError(this); + Builder getCompileTimeError() => target.getCompileTimeError(this); - Declaration getDuplicatedFieldInitializerError() { + Builder getDuplicatedFieldInitializerError() { return target.getDuplicatedFieldInitializerError(this); } - Declaration getNativeAnnotation() => target.getNativeAnnotation(this); + Builder getNativeAnnotation() => target.getNativeAnnotation(this); ClassBuilder computeClassBuilderFromTargetClass(covariant Object cls); diff --git a/pkg/front_end/lib/src/fasta/scope.dart b/pkg/front_end/lib/src/fasta/scope.dart index c74cc9928657..8c013a8a077b 100644 --- a/pkg/front_end/lib/src/fasta/scope.dart +++ b/pkg/front_end/lib/src/fasta/scope.dart @@ -4,8 +4,7 @@ library fasta.scope; -import 'builder/builder.dart' - show Declaration, NameIterator, TypeVariableBuilder; +import 'builder/builder.dart' show Builder, NameIterator, TypeVariableBuilder; import 'fasta_codes.dart' show @@ -20,10 +19,10 @@ import 'problems.dart' show internalProblem, unsupported; class MutableScope { /// Names declared in this scope. - Map local; + Map local; /// Setters declared in this scope. - Map setters; + Map setters; /// The scope that this scope is nested within, or `null` if this is the top /// level scope. @@ -44,32 +43,31 @@ class Scope extends MutableScope { /// succeed. final bool isModifiable; - Map labels; + Map labels; - Map forwardDeclaredLabels; + Map forwardDeclaredLabels; Map usedNames; - Scope(Map local, Map setters, - Scope parent, String debugName, {this.isModifiable: true}) - : super(local, setters = setters ?? const {}, parent, + Scope(Map local, Map setters, Scope parent, + String debugName, {this.isModifiable: true}) + : super(local, setters = setters ?? const {}, parent, debugName); Scope.top({bool isModifiable: false}) - : this({}, {}, null, "top", + : this({}, {}, null, "top", isModifiable: isModifiable); Scope.immutable() - : this(const {}, const {}, null, + : this(const {}, const {}, null, "immutable", isModifiable: false); Scope.nested(Scope parent, String debugName, {bool isModifiable: true}) - : this( - {}, {}, parent, debugName, + : this({}, {}, parent, debugName, isModifiable: isModifiable); - Iterator get iterator { + Iterator get iterator { return new ScopeLocalDeclarationIterator(this); } @@ -133,9 +131,9 @@ class Scope extends MutableScope { } } - Declaration lookupIn(String name, int charOffset, Uri fileUri, - Map map, bool isInstanceScope) { - Declaration builder = map[name]; + Builder lookupIn(String name, int charOffset, Uri fileUri, + Map map, bool isInstanceScope) { + Builder builder = map[name]; if (builder == null) return null; if (builder.next != null) { return new AmbiguousBuilder(name.isEmpty ? classNameOrDebugName : name, @@ -147,10 +145,10 @@ class Scope extends MutableScope { } } - Declaration lookup(String name, int charOffset, Uri fileUri, + Builder lookup(String name, int charOffset, Uri fileUri, {bool isInstanceScope: true}) { recordUse(name, charOffset, fileUri); - Declaration builder = + Builder builder = lookupIn(name, charOffset, fileUri, local, isInstanceScope); if (builder != null) return builder; builder = lookupIn(name, charOffset, fileUri, setters, isInstanceScope); @@ -164,10 +162,10 @@ class Scope extends MutableScope { return builder ?? parent?.lookup(name, charOffset, fileUri); } - Declaration lookupSetter(String name, int charOffset, Uri fileUri, + Builder lookupSetter(String name, int charOffset, Uri fileUri, {bool isInstanceScope: true}) { recordUse(name, charOffset, fileUri); - Declaration builder = + Builder builder = lookupIn(name, charOffset, fileUri, setters, isInstanceScope); if (builder != null) return builder; builder = lookupIn(name, charOffset, fileUri, local, isInstanceScope); @@ -183,9 +181,9 @@ class Scope extends MutableScope { bool hasLocalLabel(String name) => labels != null && labels.containsKey(name); - void declareLabel(String name, Declaration target) { + void declareLabel(String name, Builder target) { if (isModifiable) { - labels ??= {}; + labels ??= {}; labels[name] = target; } else { internalProblem( @@ -193,9 +191,9 @@ class Scope extends MutableScope { } } - void forwardDeclareLabel(String name, Declaration target) { + void forwardDeclareLabel(String name, Builder target) { declareLabel(name, target); - forwardDeclaredLabels ??= {}; + forwardDeclaredLabels ??= {}; forwardDeclaredLabels[name] = target; } @@ -208,11 +206,11 @@ class Scope extends MutableScope { return true; } - Map get unclaimedForwardDeclarations { + Map get unclaimedForwardDeclarations { return forwardDeclaredLabels; } - Declaration lookupLabel(String name) { + Builder lookupLabel(String name) { return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name); } @@ -222,7 +220,7 @@ class Scope extends MutableScope { /// that can be used as context for reporting a compile-time error about /// [name] being used before its declared. [fileUri] is used to bind the /// location of this message. - LocatedMessage declare(String name, Declaration builder, Uri fileUri) { + LocatedMessage declare(String name, Builder builder, Uri fileUri) { if (isModifiable) { if (usedNames?.containsKey(name) ?? false) { return templateDuplicatedNamePreviouslyUsedCause @@ -239,12 +237,12 @@ class Scope extends MutableScope { void merge( Scope scope, - Declaration computeAmbiguousDeclaration( - String name, Declaration existing, Declaration member)) { - Map map = local; + Builder computeAmbiguousDeclaration( + String name, Builder existing, Builder member)) { + Map map = local; - void mergeMember(String name, Declaration member) { - Declaration existing = map[name]; + void mergeMember(String name, Builder member) { + Builder existing = map[name]; if (existing != null) { if (existing != member) { member = computeAmbiguousDeclaration(name, existing, member); @@ -258,7 +256,7 @@ class Scope extends MutableScope { scope.setters.forEach(mergeMember); } - void forEach(f(String name, Declaration member)) { + void forEach(f(String name, Builder member)) { local.forEach(f); setters.forEach(f); } @@ -276,10 +274,10 @@ class Scope extends MutableScope { int nestingLevel = (parent?.writeOn(sink) ?? -1) + 1; String indent = " " * nestingLevel; sink.writeln("$indent{"); - local.forEach((String name, Declaration member) { + local.forEach((String name, Builder member) { sink.writeln("$indent $name"); }); - setters.forEach((String name, Declaration member) { + setters.forEach((String name, Builder member) { sink.writeln("$indent $name="); }); return nestingLevel; @@ -287,11 +285,11 @@ class Scope extends MutableScope { Scope computeMixinScope() { List names = this.local.keys.toList(); - Map local = {}; + Map local = {}; bool needsCopy = false; for (int i = 0; i < names.length; i++) { String name = names[i]; - Declaration declaration = this.local[name]; + Builder declaration = this.local[name]; if (declaration.isStatic) { needsCopy = true; } else { @@ -299,10 +297,10 @@ class Scope extends MutableScope { } } names = this.setters.keys.toList(); - Map setters = {}; + Map setters = {}; for (int i = 0; i < names.length; i++) { String name = names[i]; - Declaration declaration = this.setters[name]; + Builder declaration = this.setters[name]; if (declaration.isStatic) { needsCopy = true; } else { @@ -321,21 +319,21 @@ class ScopeBuilder { ScopeBuilder(this.scope); - void addMember(String name, Declaration builder) { + void addMember(String name, Builder builder) { scope.local[name] = builder; } - void addSetter(String name, Declaration builder) { + void addSetter(String name, Builder builder) { scope.setters[name] = builder; } - Declaration operator [](String name) => scope.local[name]; + Builder operator [](String name) => scope.local[name]; } -abstract class ProblemBuilder extends Declaration { +abstract class ProblemBuilder extends Builder { final String name; - final Declaration builder; + final Builder builder; final int charOffset; @@ -356,11 +354,10 @@ abstract class ProblemBuilder extends Declaration { /// Represents a [builder] that's being accessed incorrectly. For example, an /// attempt to write to a final field, or to read from a setter. class AccessErrorBuilder extends ProblemBuilder { - AccessErrorBuilder( - String name, Declaration builder, int charOffset, Uri fileUri) + AccessErrorBuilder(String name, Builder builder, int charOffset, Uri fileUri) : super(name, builder, charOffset, fileUri); - Declaration get parent => builder; + Builder get parent => builder; bool get isFinal => builder.isFinal; @@ -386,18 +383,17 @@ class AccessErrorBuilder extends ProblemBuilder { } class AmbiguousBuilder extends ProblemBuilder { - AmbiguousBuilder( - String name, Declaration builder, int charOffset, Uri fileUri) + AmbiguousBuilder(String name, Builder builder, int charOffset, Uri fileUri) : super(name, builder, charOffset, fileUri); - Declaration get parent => null; + Builder get parent => null; Message get message => templateDuplicatedDeclarationUse.withArguments(name); // TODO(ahe): Also provide context. - Declaration getFirstDeclaration() { - Declaration declaration = builder; + Builder getFirstDeclaration() { + Builder declaration = builder; while (declaration.next != null) { declaration = declaration.next; } @@ -405,17 +401,17 @@ class AmbiguousBuilder extends ProblemBuilder { } } -class ScopeLocalDeclarationIterator implements Iterator { - Iterator local; - final Iterator setters; - Declaration current; +class ScopeLocalDeclarationIterator implements Iterator { + Iterator local; + final Iterator setters; + Builder current; ScopeLocalDeclarationIterator(Scope scope) : local = scope.local.values.iterator, setters = scope.setters.values.iterator; bool moveNext() { - Declaration next = current?.next; + Builder next = current?.next; if (next != null) { current = next; return true; @@ -450,7 +446,7 @@ class ScopeLocalDeclarationNameIterator extends ScopeLocalDeclarationIterator super(scope); bool moveNext() { - Declaration next = current?.next; + Builder next = current?.next; if (next != null) { current = next; return true; diff --git a/pkg/front_end/lib/src/fasta/source/diet_listener.dart b/pkg/front_end/lib/src/fasta/source/diet_listener.dart index 6437f68265f8..04476fb3013a 100644 --- a/pkg/front_end/lib/src/fasta/source/diet_listener.dart +++ b/pkg/front_end/lib/src/fasta/source/diet_listener.dart @@ -243,7 +243,7 @@ class DietListener extends StackListener { checkEmpty(typedefKeyword.charOffset); if (name is ParserRecovery) return; - Declaration typedefBuilder = lookupBuilder(typedefKeyword, null, name); + Builder typedefBuilder = lookupBuilder(typedefKeyword, null, name); parseMetadata(typedefBuilder, metadata, typedefBuilder.target); if (typedefBuilder is TypeAliasBuilder) { TypeBuilder type = typedefBuilder.type; @@ -672,7 +672,7 @@ class DietListener extends StackListener { checkEmpty(token.charOffset); if (names == null || currentClassIsParserRecovery) return; - Declaration declaration = lookupBuilder(token, null, names.first); + Builder declaration = lookupBuilder(token, null, names.first); // TODO(paulberry): don't re-parse the field if we've already parsed it // for type inference. parseFields( @@ -860,9 +860,9 @@ class DietListener extends StackListener { listener.checkEmpty(token.charOffset); } - Declaration lookupBuilder(Token token, Token getOrSet, String name) { + Builder lookupBuilder(Token token, Token getOrSet, String name) { // TODO(ahe): Can I move this to Scope or ScopeBuilder? - Declaration declaration; + Builder declaration; if (currentClass != null) { if (uri != currentClass.fileUri) { unexpected("$uri", "${currentClass.fileUri}", currentClass.charOffset, @@ -884,9 +884,9 @@ class DietListener extends StackListener { return declaration; } - Declaration lookupConstructor(Token token, Object nameOrQualified) { + Builder lookupConstructor(Token token, Object nameOrQualified) { assert(currentClass != null); - Declaration declaration; + Builder declaration; String suffix; if (nameOrQualified is QualifiedName) { suffix = nameOrQualified.name; @@ -899,12 +899,12 @@ class DietListener extends StackListener { return declaration; } - Declaration handleDuplicatedName(Declaration declaration, Token token) { + Builder handleDuplicatedName(Builder declaration, Token token) { int offset = token.charOffset; if (declaration?.next == null) { return declaration; } else { - Declaration nearestDeclaration; + Builder nearestDeclaration; int minDistance = -1; do { // Only look at declarations from this file (part). @@ -928,7 +928,7 @@ class DietListener extends StackListener { } } - void checkBuilder(Token token, Declaration declaration, Object name) { + void checkBuilder(Token token, Builder declaration, Object name) { if (declaration == null) { internalProblem(templateInternalProblemNotFound.withArguments("$name"), token.charOffset, uri); diff --git a/pkg/front_end/lib/src/fasta/source/outline_builder.dart b/pkg/front_end/lib/src/fasta/source/outline_builder.dart index 46c4e9a0223a..830352fc5224 100644 --- a/pkg/front_end/lib/src/fasta/source/outline_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/outline_builder.dart @@ -89,7 +89,11 @@ import '../quote.dart' show unescapeString; import '../scanner.dart' show Token; import 'source_library_builder.dart' - show DeclarationBuilder, DeclarationKind, FieldInfo, SourceLibraryBuilder; + show + TypeParameterScopeBuilder, + TypeParameterScopeKind, + FieldInfo, + SourceLibraryBuilder; import 'stack_listener.dart' show FixedNullableList, NullValue, ParserRecovery, StackListener; @@ -443,7 +447,8 @@ class OutlineBuilder extends StackListener { @override void beginClassOrNamedMixinApplication(Token token) { debugEvent("beginClassOrNamedMixinApplication"); - library.beginNestedDeclaration(DeclarationKind.classOrNamedMixinApplication, + library.beginNestedDeclaration( + TypeParameterScopeKind.classOrNamedMixinApplication, "class or mixin application"); } @@ -452,8 +457,8 @@ class OutlineBuilder extends StackListener { debugEvent("beginClassDeclaration"); List typeVariables = pop(); push(typeVariables ?? NullValue.TypeVariables); - library.currentDeclaration - .registerClassDeclaration(name.lexeme, name.charOffset, typeVariables); + library.currentTypeParameterScopeBuilder + .markAsClassDeclaration(name.lexeme, name.charOffset, typeVariables); push(abstractToken != null ? abstractMask : 0); } @@ -462,8 +467,8 @@ class OutlineBuilder extends StackListener { debugEvent("beginMixinDeclaration"); List typeVariables = pop(); push(typeVariables ?? NullValue.TypeVariables); - library.currentDeclaration - .registerMixinDeclaration(name.lexeme, name.charOffset, typeVariables); + library.currentTypeParameterScopeBuilder + .markAsMixinDeclaration(name.lexeme, name.charOffset, typeVariables); } @override @@ -471,14 +476,15 @@ class OutlineBuilder extends StackListener { if (kind == ClassKind.Extension) { assert(checkState(token, [ValueKind.TypeBuilder])); TypeBuilder extensionThisType = peek(); - library.currentDeclaration.registerExtensionThisType(extensionThisType); + library.currentTypeParameterScopeBuilder + .registerExtensionThisType(extensionThisType); } debugEvent("beginClassOrMixinBody"); // Resolve unresolved types from the class header (i.e., superclass, mixins, // and implemented types) before adding members from the class body which // should not shadow these unresolved types. - library.currentDeclaration - .resolveTypes(library.currentDeclaration.typeVariables, library); + library.currentTypeParameterScopeBuilder.resolveTypes( + library.currentTypeParameterScopeBuilder.typeVariables, library); } @override @@ -487,7 +493,7 @@ class OutlineBuilder extends StackListener { debugEvent("beginNamedMixinApplication"); List typeVariables = pop(); push(typeVariables ?? NullValue.TypeVariables); - library.currentDeclaration.registerNamedMixinApplication( + library.currentTypeParameterScopeBuilder.markAsNamedMixinApplication( name.lexeme, name.charOffset, typeVariables); push(abstractToken != null ? abstractMask : 0); } @@ -547,7 +553,7 @@ class OutlineBuilder extends StackListener { checkEmpty(beginToken.charOffset); if (name is ParserRecovery) { library.endNestedDeclaration( - DeclarationKind.classDeclaration, ""); + TypeParameterScopeKind.classDeclaration, ""); return; } @@ -585,7 +591,7 @@ class OutlineBuilder extends StackListener { checkEmpty(mixinToken.charOffset); if (name is ParserRecovery) { library.endNestedDeclaration( - DeclarationKind.mixinDeclaration, ""); + TypeParameterScopeKind.mixinDeclaration, ""); return; } int startOffset = @@ -619,7 +625,7 @@ class OutlineBuilder extends StackListener { [ValueKind.TypeVariableListOrNull, ValueKind.MetadataListOrNull])); debugEvent("beginExtensionDeclaration"); library.beginNestedDeclaration( - DeclarationKind.extensionDeclaration, "extension"); + TypeParameterScopeKind.extensionDeclaration, "extension"); List typeVariables = pop(); int offset = nameToken?.charOffset ?? extensionKeyword.charOffset; String name = nameToken?.lexeme ?? @@ -628,8 +634,8 @@ class OutlineBuilder extends StackListener { push(name); push(offset); push(typeVariables ?? NullValue.TypeVariables); - library.currentDeclaration - .registerExtensionDeclaration(name, offset, typeVariables); + library.currentTypeParameterScopeBuilder + .markAsExtensionDeclaration(name, offset, typeVariables); } @override @@ -679,7 +685,8 @@ class OutlineBuilder extends StackListener { @override void beginTopLevelMethod(Token lastConsumed, Token externalToken) { - library.beginNestedDeclaration(DeclarationKind.topLevelMethod, "#method", + library.beginNestedDeclaration( + TypeParameterScopeKind.topLevelMethod, "#method", hasMembers: false); push(externalToken != null ? externalMask : 0); } @@ -712,7 +719,7 @@ class OutlineBuilder extends StackListener { List metadata = pop(); checkEmpty(beginToken.charOffset); library - .endNestedDeclaration(DeclarationKind.topLevelMethod, "#method") + .endNestedDeclaration(TypeParameterScopeKind.topLevelMethod, "#method") .resolveTypes(typeVariables, library); if (name is ParserRecovery) return; final int startCharOffset = @@ -780,7 +787,8 @@ class OutlineBuilder extends StackListener { void beginMethod(Token externalToken, Token staticToken, Token covariantToken, Token varFinalOrConst, Token getOrSet, Token name) { inConstructor = - name?.lexeme == library.currentDeclaration.name && getOrSet == null; + name?.lexeme == library.currentTypeParameterScopeBuilder.name && + getOrSet == null; List modifiers; if (externalToken != null) { modifiers ??= []; @@ -815,7 +823,7 @@ class OutlineBuilder extends StackListener { push(varFinalOrConst?.charOffset ?? -1); push(modifiers ?? NullValue.Modifiers); library.beginNestedDeclaration( - DeclarationKind.staticOrInstanceMethodOrConstructor, "#method", + TypeParameterScopeKind.staticOrInstanceMethodOrConstructor, "#method", hasMembers: false); } @@ -919,10 +927,9 @@ class OutlineBuilder extends StackListener { List metadata = pop(); String documentationComment = getDocumentationComment(beginToken); - DeclarationBuilder declarationBuilder = library.endNestedDeclaration( - DeclarationKind.staticOrInstanceMethodOrConstructor, "#method"); + TypeParameterScopeBuilder declarationBuilder = library.endNestedDeclaration( + TypeParameterScopeKind.staticOrInstanceMethodOrConstructor, "#method"); if (name is ParserRecovery) { - declarationBuilder.resolveTypes(typeVariables, library); nativeMethodName = null; inConstructor = false; declarationBuilder.resolveTypes(typeVariables, library); @@ -935,9 +942,10 @@ class OutlineBuilder extends StackListener { : library.computeAndValidateConstructorName(name, charOffset); if (constructorName == null && (modifiers & staticMask) == 0 && - library.currentDeclaration.kind == - DeclarationKind.extensionDeclaration) { - DeclarationBuilder extension = library.currentDeclaration; + library.currentTypeParameterScopeBuilder.kind == + TypeParameterScopeKind.extensionDeclaration) { + TypeParameterScopeBuilder extension = + library.currentTypeParameterScopeBuilder; Map substitution; if (extension.typeVariables != null) { // We synthesize the names of the generated [TypeParameter]s, i.e. @@ -1059,7 +1067,7 @@ class OutlineBuilder extends StackListener { checkEmpty(beginToken.charOffset); if (name is ParserRecovery || mixinApplication is ParserRecovery) { library.endNestedDeclaration( - DeclarationKind.namedMixinApplication, ""); + TypeParameterScopeKind.namedMixinApplication, ""); return; } @@ -1324,7 +1332,7 @@ class OutlineBuilder extends StackListener { @override void beginFunctionTypeAlias(Token token) { - library.beginNestedDeclaration(DeclarationKind.typedef, "#typedef", + library.beginNestedDeclaration(TypeParameterScopeKind.typedef, "#typedef", hasMembers: false); } @@ -1332,7 +1340,7 @@ class OutlineBuilder extends StackListener { void beginFunctionType(Token beginToken) { debugEvent("beginFunctionType"); library.beginNestedDeclaration( - DeclarationKind.functionType, "#function_type", + TypeParameterScopeKind.functionType, "#function_type", hasMembers: false); } @@ -1340,7 +1348,7 @@ class OutlineBuilder extends StackListener { void beginFunctionTypedFormalParameter(Token token) { debugEvent("beginFunctionTypedFormalParameter"); library.beginNestedDeclaration( - DeclarationKind.functionType, "#function_type", + TypeParameterScopeKind.functionType, "#function_type", hasMembers: false); } @@ -1392,11 +1400,12 @@ class OutlineBuilder extends StackListener { // `library.addFunctionType`. if (name is ParserRecovery) { pop(); // Metadata. - library.endNestedDeclaration(DeclarationKind.typedef, ""); + library.endNestedDeclaration( + TypeParameterScopeKind.typedef, ""); return; } library.beginNestedDeclaration( - DeclarationKind.functionType, "#function_type", + TypeParameterScopeKind.functionType, "#function_type", hasMembers: false); functionType = library.addFunctionType(returnType, null, formals, charOffset); @@ -1408,7 +1417,7 @@ class OutlineBuilder extends StackListener { if (name is ParserRecovery) { pop(); // Metadata. library.endNestedDeclaration( - DeclarationKind.functionType, ""); + TypeParameterScopeKind.functionType, ""); return; } if (type is FunctionTypeBuilder) { @@ -1633,7 +1642,7 @@ class OutlineBuilder extends StackListener { Token lastConsumed, Token externalToken, Token constToken) { inConstructor = true; library.beginNestedDeclaration( - DeclarationKind.factoryMethod, "#factory_method", + TypeParameterScopeKind.factoryMethod, "#factory_method", hasMembers: false); push((externalToken != null ? externalMask : 0) | (constToken != null ? constMask : 0)); @@ -1660,7 +1669,7 @@ class OutlineBuilder extends StackListener { List metadata = pop(); if (name is ParserRecovery) { library.endNestedDeclaration( - DeclarationKind.factoryMethod, ""); + TypeParameterScopeKind.factoryMethod, ""); return; } String documentationComment = getDocumentationComment(beginToken); diff --git a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart index 0cca364f4e6e..66cef5e2fceb 100644 --- a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart @@ -26,7 +26,7 @@ import '../kernel/kernel_builder.dart' show ClassBuilder, ConstructorReferenceBuilder, - Declaration, + Builder, FieldBuilder, FunctionBuilder, InvalidTypeBuilder, @@ -111,7 +111,7 @@ class SourceClassBuilder extends ClassBuilder SourceLibraryBuilder get library => super.library; Class build(SourceLibraryBuilder library, LibraryBuilder coreLibrary) { - void buildBuilders(String name, Declaration declaration) { + void buildBuilders(String name, Builder declaration) { do { if (declaration.parent != this) { if (fileUri != declaration.parent.fileUri) { @@ -190,8 +190,8 @@ class SourceClassBuilder extends ClassBuilder } } - constructors.forEach((String name, Declaration constructor) { - Declaration member = scopeBuilder[name]; + constructors.forEach((String name, Builder constructor) { + Builder member = scopeBuilder[name]; if (member == null) return; if (!member.isStatic) return; // TODO(ahe): Revisit these messages. It seems like the last two should @@ -212,8 +212,8 @@ class SourceClassBuilder extends ClassBuilder } }); - scope.setters.forEach((String name, Declaration setter) { - Declaration member = scopeBuilder[name]; + scope.setters.forEach((String name, Builder setter) { + Builder member = scopeBuilder[name]; if (member == null || !(member.isField && !member.isFinal && !member.isConst || member.isRegularMethod && member.isStatic && setter.isStatic)) { @@ -234,8 +234,8 @@ class SourceClassBuilder extends ClassBuilder } }); - scope.setters.forEach((String name, Declaration setter) { - Declaration constructor = constructorScopeBuilder[name]; + scope.setters.forEach((String name, Builder setter) { + Builder constructor = constructorScopeBuilder[name]; if (constructor == null || !setter.isStatic) return; addProblem(templateConflictsWithConstructor.withArguments(name), setter.charOffset, noLength); @@ -285,17 +285,17 @@ class SourceClassBuilder extends ClassBuilder cls.annotations.forEach((m) => m.fileOffset = origin.cls.fileOffset); int count = 0; - scope.forEach((String name, Declaration declaration) { + scope.forEach((String name, Builder declaration) { count += declaration.finishPatch(); }); - constructors.forEach((String name, Declaration declaration) { + constructors.forEach((String name, Builder declaration) { count += declaration.finishPatch(); }); return count; } - List computeDirectSupertypes(ClassBuilder objectClass) { - final List result = []; + List computeDirectSupertypes(ClassBuilder objectClass) { + final List result = []; final TypeBuilder supertype = this.supertype; if (supertype != null) { result.add(supertype.declaration); diff --git a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart index d9bae910379f..210f149065ec 100644 --- a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart @@ -61,7 +61,7 @@ import '../builder/builder.dart' show ClassBuilder, ConstructorReferenceBuilder, - Declaration, + Builder, EnumConstantInfo, FormalParameterBuilder, FunctionTypeBuilder, @@ -153,7 +153,7 @@ import '../kernel/kernel_builder.dart' BuiltinTypeBuilder, ClassBuilder, ConstructorReferenceBuilder, - Declaration, + Builder, DynamicTypeBuilder, EnumConstantInfo, FormalParameterBuilder, @@ -225,7 +225,7 @@ class SourceLibraryBuilder extends LibraryBuilder { final SourceLoader loader; - final DeclarationBuilder libraryDeclaration; + final TypeParameterScopeBuilder libraryDeclaration; final List constructorReferences = []; @@ -264,7 +264,7 @@ class SourceLibraryBuilder extends LibraryBuilder { /// declaration (class, method, and so on), we don't have enough information /// to create a builder and this object records its members and types until, /// for example, [addClass] is called. - DeclarationBuilder currentDeclaration; + TypeParameterScopeBuilder currentTypeParameterScopeBuilder; bool canAddImplementationBuilders = false; @@ -320,8 +320,14 @@ class SourceLibraryBuilder extends LibraryBuilder { SourceLibraryBuilder.internal(SourceLoader loader, Uri fileUri, Scope scope, SourceLibraryBuilder actualOrigin, Library library, Library nameOrigin) - : this.fromScopes(loader, fileUri, new DeclarationBuilder.library(), - scope ?? new Scope.top(), actualOrigin, library, nameOrigin); + : this.fromScopes( + loader, + fileUri, + new TypeParameterScopeBuilder.library(), + scope ?? new Scope.top(), + actualOrigin, + library, + nameOrigin); SourceLibraryBuilder.fromScopes( this.loader, @@ -331,7 +337,7 @@ class SourceLibraryBuilder extends LibraryBuilder { this.actualOrigin, this.library, this._nameOrigin) - : currentDeclaration = libraryDeclaration, + : currentTypeParameterScopeBuilder = libraryDeclaration, legacyMode = loader.target.legacyMode, super( fileUri, libraryDeclaration.toScope(importScope), new Scope.top()); @@ -357,7 +363,8 @@ class SourceLibraryBuilder extends LibraryBuilder { bool get isSynthetic => accessProblem != null; TypeBuilder addType(TypeBuilder type, int charOffset) { - currentDeclaration.addType(new UnresolvedType(type, charOffset, fileUri)); + currentTypeParameterScopeBuilder + .addType(new UnresolvedType(type, charOffset, fileUri)); return type; } @@ -398,25 +405,26 @@ class SourceLibraryBuilder extends LibraryBuilder { return ref; } - void beginNestedDeclaration(DeclarationKind kind, String name, + void beginNestedDeclaration(TypeParameterScopeKind kind, String name, {bool hasMembers: true}) { - currentDeclaration = - currentDeclaration.createNested(kind, name, hasMembers); + currentTypeParameterScopeBuilder = + currentTypeParameterScopeBuilder.createNested(kind, name, hasMembers); } - DeclarationBuilder endNestedDeclaration(DeclarationKind kind, String name) { + TypeParameterScopeBuilder endNestedDeclaration( + TypeParameterScopeKind kind, String name) { assert( - currentDeclaration.kind == kind, + currentTypeParameterScopeBuilder.kind == kind, "Unexpected declaration. " - "Trying to end a ${currentDeclaration.kind} as a $kind."); + "Trying to end a ${currentTypeParameterScopeBuilder.kind} as a $kind."); assert( - (name?.startsWith(currentDeclaration.name) ?? - (name == currentDeclaration.name)) || - currentDeclaration.name == "operator" || + (name?.startsWith(currentTypeParameterScopeBuilder.name) ?? + (name == currentTypeParameterScopeBuilder.name)) || + currentTypeParameterScopeBuilder.name == "operator" || identical(name, ""), - "${name} != ${currentDeclaration.name}"); - DeclarationBuilder previous = currentDeclaration; - currentDeclaration = currentDeclaration.parent; + "${name} != ${currentTypeParameterScopeBuilder.name}"); + TypeParameterScopeBuilder previous = currentTypeParameterScopeBuilder; + currentTypeParameterScopeBuilder = currentTypeParameterScopeBuilder.parent; return previous; } @@ -449,7 +457,7 @@ class SourceLibraryBuilder extends LibraryBuilder { String computeAndValidateConstructorName(Object name, int charOffset, {isFactory: false}) { - String className = currentDeclaration.name; + String className = currentTypeParameterScopeBuilder.name; String prefix; String suffix; if (name is QualifiedName) { @@ -471,9 +479,9 @@ class SourceLibraryBuilder extends LibraryBuilder { messageConstructorWithWrongName, charOffset, prefix.length, fileUri, context: [ templateConstructorWithWrongNameContext - .withArguments(currentDeclaration.name) - .withLocation(uri, currentDeclaration.charOffset, - currentDeclaration.name.length) + .withArguments(currentTypeParameterScopeBuilder.name) + .withLocation(uri, currentTypeParameterScopeBuilder.charOffset, + currentTypeParameterScopeBuilder.name.length) ]); return suffix; @@ -624,14 +632,14 @@ class SourceLibraryBuilder extends LibraryBuilder { } } - Declaration addBuilder(String name, Declaration declaration, int charOffset) { + Builder addBuilder(String name, Builder declaration, int charOffset) { // TODO(ahe): Set the parent correctly here. Could then change the // implementation of MemberBuilder.isTopLevel to test explicitly for a // LibraryBuilder. if (name == null) { unhandled("null", "name", charOffset, fileUri); } - if (currentDeclaration == libraryDeclaration) { + if (currentTypeParameterScopeBuilder == libraryDeclaration) { if (declaration is MemberBuilder) { declaration.parent = this; } else if (declaration is TypeDeclarationBuilder) { @@ -643,20 +651,20 @@ class SourceLibraryBuilder extends LibraryBuilder { "${declaration.runtimeType}", "addBuilder", charOffset, fileUri); } } else { - assert(currentDeclaration.parent == libraryDeclaration); + assert(currentTypeParameterScopeBuilder.parent == libraryDeclaration); } bool isConstructor = declaration is FunctionBuilder && (declaration.isConstructor || declaration.isFactory); - if (!isConstructor && name == currentDeclaration.name) { + if (!isConstructor && name == currentTypeParameterScopeBuilder.name) { addProblem( messageMemberWithSameNameAsClass, charOffset, noLength, fileUri); } - Map members = isConstructor - ? currentDeclaration.constructors + Map members = isConstructor + ? currentTypeParameterScopeBuilder.constructors : (declaration.isSetter - ? currentDeclaration.setters - : currentDeclaration.members); - Declaration existing = members[name]; + ? currentTypeParameterScopeBuilder.setters + : currentTypeParameterScopeBuilder.members); + Builder existing = members[name]; if (declaration.next != null && declaration.next != existing) { unexpected( "${declaration.next.fileUri}@${declaration.next.charOffset}", @@ -667,8 +675,8 @@ class SourceLibraryBuilder extends LibraryBuilder { declaration.next = existing; if (declaration is PrefixBuilder && existing is PrefixBuilder) { assert(existing.next is! PrefixBuilder); - Declaration deferred; - Declaration other; + Builder deferred; + Builder other; if (declaration.deferred) { deferred = declaration; other = existing; @@ -687,7 +695,7 @@ class SourceLibraryBuilder extends LibraryBuilder { } return existing ..exportScope.merge(declaration.exportScope, - (String name, Declaration existing, Declaration member) { + (String name, Builder existing, Builder member) { return computeAmbiguousDeclaration( name, existing, member, charOffset); }); @@ -695,9 +703,9 @@ class SourceLibraryBuilder extends LibraryBuilder { String fullName = name; if (isConstructor) { if (name.isEmpty) { - fullName = currentDeclaration.name; + fullName = currentTypeParameterScopeBuilder.name; } else { - fullName = "${currentDeclaration.name}.$name"; + fullName = "${currentTypeParameterScopeBuilder.name}.$name"; } } addProblem(templateDuplicatedDeclaration.withArguments(fullName), @@ -712,9 +720,9 @@ class SourceLibraryBuilder extends LibraryBuilder { return members[name] = declaration; } - bool isDuplicatedDeclaration(Declaration existing, Declaration other) { + bool isDuplicatedDeclaration(Builder existing, Builder other) { if (existing == null) return false; - Declaration next = existing.next; + Builder next = existing.next; if (next == null) { if (existing.isGetter && other.isSetter) return false; if (existing.isSetter && other.isGetter) return false; @@ -734,21 +742,21 @@ class SourceLibraryBuilder extends LibraryBuilder { Library build(LibraryBuilder coreLibrary, {bool modifyTarget}) { assert(implementationBuilders.isEmpty); canAddImplementationBuilders = true; - Iterator iterator = this.iterator; + Iterator iterator = this.iterator; while (iterator.moveNext()) { buildBuilder(iterator.current, coreLibrary); } for (ImplementationInfo info in implementationBuilders) { String name = info.name; - Declaration declaration = info.declaration; + Builder declaration = info.declaration; int charOffset = info.charOffset; addBuilder(name, declaration, charOffset); buildBuilder(declaration, coreLibrary); } canAddImplementationBuilders = false; - scope.setters.forEach((String name, Declaration setter) { - Declaration member = scopeBuilder[name]; + scope.setters.forEach((String name, Builder setter) { + Builder member = scopeBuilder[name]; if (member == null || !member.isField || member.isFinal || @@ -788,7 +796,7 @@ class SourceLibraryBuilder extends LibraryBuilder { /// [MixinApplicationBuilder] /// (../kernel/kernel_mixin_application_builder.dart)). void addImplementationBuilder( - String name, Declaration declaration, int charOffset) { + String name, Builder declaration, int charOffset) { assert(canAddImplementationBuilders, "$uri"); implementationBuilders .add(new ImplementationInfo(name, declaration, charOffset)); @@ -921,10 +929,10 @@ class SourceLibraryBuilder extends LibraryBuilder { NameIterator partDeclarations = part.nameIterator; while (partDeclarations.moveNext()) { String name = partDeclarations.name; - Declaration declaration = partDeclarations.current; + Builder declaration = partDeclarations.current; if (declaration.next != null) { - List duplicated = []; + List duplicated = []; while (declaration.next != null) { duplicated.add(declaration); partDeclarations.moveNext(); @@ -952,7 +960,7 @@ class SourceLibraryBuilder extends LibraryBuilder { // part library still keeps these declarations in its scope so that // DietListener can find them. for (int i = duplicated.length; i > 0; i--) { - Declaration declaration = duplicated[i - 1]; + Builder declaration = duplicated[i - 1]; addBuilder(name, declaration, declaration.charOffset); } } else { @@ -1008,12 +1016,12 @@ class SourceLibraryBuilder extends LibraryBuilder { import.finalizeImports(this); } if (!explicitCoreImport) { - loader.coreLibrary.exportScope.forEach((String name, Declaration member) { + loader.coreLibrary.exportScope.forEach((String name, Builder member) { addToScope(name, member, -1, true); }); } - exportScope.forEach((String name, Declaration member) { + exportScope.forEach((String name, Builder member) { if (member.parent != this) { switch (name) { case "dynamic": @@ -1031,7 +1039,7 @@ class SourceLibraryBuilder extends LibraryBuilder { // library if the have 'next' pointers, so don't add them as // additionalExports either. Add the last one only (the one that // will eventually be added to the library). - Declaration memberLast = member; + Builder memberLast = member; while (memberLast.next != null) memberLast = memberLast.next; library.additionalExports.add(memberLast.target.reference); } @@ -1041,11 +1049,10 @@ class SourceLibraryBuilder extends LibraryBuilder { } @override - void addToScope( - String name, Declaration member, int charOffset, bool isImport) { - Map map = + void addToScope(String name, Builder member, int charOffset, bool isImport) { + Map map = member.isSetter ? importScope.setters : importScope.local; - Declaration existing = map[name]; + Builder existing = map[name]; if (existing != null) { if (existing != member) { map[name] = computeAmbiguousDeclaration( @@ -1076,7 +1083,7 @@ class SourceLibraryBuilder extends LibraryBuilder { @override int resolveConstructors(_) { int count = 0; - Iterator iterator = this.iterator; + Iterator iterator = this.iterator; while (iterator.moveNext()) { count += iterator.current.resolveConstructors(this); } @@ -1208,7 +1215,7 @@ class SourceLibraryBuilder extends LibraryBuilder { int endOffset, int supertypeOffset) { _addClass( - DeclarationKind.classDeclaration, + TypeParameterScopeKind.classDeclaration, documentationComment, metadata, modifiers, @@ -1235,7 +1242,7 @@ class SourceLibraryBuilder extends LibraryBuilder { int endOffset, int supertypeOffset) { _addClass( - DeclarationKind.mixinDeclaration, + TypeParameterScopeKind.mixinDeclaration, documentationComment, metadata, modifiers, @@ -1250,7 +1257,7 @@ class SourceLibraryBuilder extends LibraryBuilder { } void _addClass( - DeclarationKind kind, + TypeParameterScopeKind kind, String documentationComment, List metadata, int modifiers, @@ -1263,8 +1270,9 @@ class SourceLibraryBuilder extends LibraryBuilder { int endOffset, int supertypeOffset) { // Nested declaration began in `OutlineBuilder.beginClassDeclaration`. - DeclarationBuilder declaration = endNestedDeclaration(kind, className) - ..resolveTypes(typeVariables, this); + TypeParameterScopeBuilder declaration = + endNestedDeclaration(kind, className) + ..resolveTypes(typeVariables, this); assert(declaration.parent == libraryDeclaration); Map members = declaration.members; Map constructors = declaration.constructors; @@ -1341,7 +1349,7 @@ class SourceLibraryBuilder extends LibraryBuilder { } Map checkTypeVariables( - List typeVariables, Declaration owner) { + List typeVariables, Builder owner) { if (typeVariables?.isEmpty ?? true) return null; Map typeVariablesByName = {}; @@ -1382,8 +1390,8 @@ class SourceLibraryBuilder extends LibraryBuilder { int nameOffset, int endOffset) { // Nested declaration began in `OutlineBuilder.beginExtensionDeclaration`. - DeclarationBuilder declaration = endNestedDeclaration( - DeclarationKind.extensionDeclaration, extensionName) + TypeParameterScopeBuilder declaration = endNestedDeclaration( + TypeParameterScopeKind.extensionDeclaration, extensionName) ..resolveTypes(typeVariables, this); assert(declaration.parent == libraryDeclaration); Map members = declaration.members; @@ -1593,10 +1601,11 @@ class SourceLibraryBuilder extends LibraryBuilder { // application in the same order as they're declared on the subclass. if (isGeneric) { this.beginNestedDeclaration( - DeclarationKind.unnamedMixinApplication, "mixin application"); + TypeParameterScopeKind.unnamedMixinApplication, + "mixin application"); - applicationTypeVariables = - copyTypeVariables(typeVariables, currentDeclaration); + applicationTypeVariables = copyTypeVariables( + typeVariables, currentTypeParameterScopeBuilder); List newTypes = []; if (supertype is NamedTypeBuilder && supertype.arguments != null) { @@ -1610,11 +1619,14 @@ class SourceLibraryBuilder extends LibraryBuilder { } } for (TypeBuilder newType in newTypes) { - currentDeclaration.addType(new UnresolvedType(newType, -1, null)); + currentTypeParameterScopeBuilder + .addType(new UnresolvedType(newType, -1, null)); } - DeclarationBuilder mixinDeclaration = this.endNestedDeclaration( - DeclarationKind.unnamedMixinApplication, "mixin application"); + TypeParameterScopeBuilder mixinDeclaration = this + .endNestedDeclaration( + TypeParameterScopeKind.unnamedMixinApplication, + "mixin application"); mixinDeclaration.resolveTypes(applicationTypeVariables, this); applicationTypeArguments = []; @@ -1686,7 +1698,7 @@ class SourceLibraryBuilder extends LibraryBuilder { int charOffset, int charEndOffset) { // Nested declaration began in `OutlineBuilder.beginNamedMixinApplication`. - endNestedDeclaration(DeclarationKind.namedMixinApplication, name) + endNestedDeclaration(TypeParameterScopeKind.namedMixinApplication, name) .resolveTypes(typeVariables, this); NamedTypeBuilder supertype = applyMixins(mixinApplication, startCharOffset, charOffset, charEndOffset, name, false, @@ -1763,7 +1775,7 @@ class SourceLibraryBuilder extends LibraryBuilder { addNativeMethod(procedure); } if (procedure.isConst) { - currentDeclaration?.hasConstConstructor = true; + currentTypeParameterScopeBuilder?.hasConstConstructor = true; // const constructors will have their initializers compiled and written // into the outline. procedure.beginInitializers = beginInitializers ?? Token.eof(-1); @@ -1830,10 +1842,12 @@ class SourceLibraryBuilder extends LibraryBuilder { int charEndOffset, String nativeMethodName) { TypeBuilder returnType = addNamedType( - currentDeclaration.parent.name, [], charOffset); + currentTypeParameterScopeBuilder.parent.name, + [], + charOffset); // Nested declaration began in `OutlineBuilder.beginFactoryMethod`. - DeclarationBuilder factoryDeclaration = - endNestedDeclaration(DeclarationKind.factoryMethod, "#factory_method"); + TypeParameterScopeBuilder factoryDeclaration = endNestedDeclaration( + TypeParameterScopeKind.factoryMethod, "#factory_method"); // Prepare the simple procedure name. String procedureName; @@ -1853,7 +1867,8 @@ class SourceLibraryBuilder extends LibraryBuilder { returnType, procedureName, copyTypeVariables( - currentDeclaration.typeVariables ?? const [], + currentTypeParameterScopeBuilder.typeVariables ?? + const [], factoryDeclaration), formals, this, @@ -1870,7 +1885,8 @@ class SourceLibraryBuilder extends LibraryBuilder { returnType, procedureName, copyTypeVariables( - currentDeclaration.typeVariables ?? const [], + currentTypeParameterScopeBuilder.typeVariables ?? + const [], factoryDeclaration), formals, ProcedureKind.Factory, @@ -1887,13 +1903,14 @@ class SourceLibraryBuilder extends LibraryBuilder { procedure.target, documentationComment); metadataCollector?.setConstructorNameOffset(procedure.target, name); - DeclarationBuilder savedDeclaration = currentDeclaration; - currentDeclaration = factoryDeclaration; + TypeParameterScopeBuilder savedDeclaration = + currentTypeParameterScopeBuilder; + currentTypeParameterScopeBuilder = factoryDeclaration; for (TypeVariableBuilder tv in procedure.typeVariables) { NamedTypeBuilder t = procedure.returnType; t.arguments.add(addNamedType(tv.name, null, procedure.charOffset)); } - currentDeclaration = savedDeclaration; + currentTypeParameterScopeBuilder = savedDeclaration; factoryDeclaration.resolveTypes(procedure.typeVariables, this); addBuilder(procedureName, procedure, charOffset); @@ -1931,7 +1948,7 @@ class SourceLibraryBuilder extends LibraryBuilder { ?.setDocumentationComment(typedef.target, documentationComment); checkTypeVariables(typeVariables, typedef); // Nested declaration began in `OutlineBuilder.beginFunctionTypeAlias`. - endNestedDeclaration(DeclarationKind.typedef, "#typedef") + endNestedDeclaration(TypeParameterScopeKind.typedef, "#typedef") .resolveTypes(typeVariables, this); addBuilder(name, typedef, charOffset); } @@ -1945,7 +1962,7 @@ class SourceLibraryBuilder extends LibraryBuilder { checkTypeVariables(typeVariables, null); // Nested declaration began in `OutlineBuilder.beginFunctionType` or // `OutlineBuilder.beginFunctionTypedFormalParameter`. - endNestedDeclaration(DeclarationKind.functionType, "#function_type") + endNestedDeclaration(TypeParameterScopeKind.functionType, "#function_type") .resolveTypes(typeVariables, this); return addType(builder, charOffset); } @@ -1982,7 +1999,7 @@ class SourceLibraryBuilder extends LibraryBuilder { MetadataBuilder.buildAnnotations(library, metadata, this, null, null); } - void buildBuilder(Declaration declaration, LibraryBuilder coreLibrary) { + void buildBuilder(Builder declaration, LibraryBuilder coreLibrary) { Class cls; Member member; Typedef typedef; @@ -2018,7 +2035,7 @@ class SourceLibraryBuilder extends LibraryBuilder { if (cls != null) { if (declaration.next != null) { int count = 0; - Declaration current = declaration.next; + Builder current = declaration.next; while (current != null) { count++; current = current.next; @@ -2038,7 +2055,7 @@ class SourceLibraryBuilder extends LibraryBuilder { } void addNativeDependency(String nativeImportPath) { - Declaration constructor = loader.getNativeAnnotation(); + Builder constructor = loader.getNativeAnnotation(); Arguments arguments = new Arguments([new StringLiteral(nativeImportPath)]); Expression annotation; @@ -2100,8 +2117,8 @@ class SourceLibraryBuilder extends LibraryBuilder { } @override - Declaration computeAmbiguousDeclaration( - String name, Declaration declaration, Declaration other, int charOffset, + Builder computeAmbiguousDeclaration( + String name, Builder declaration, Builder other, int charOffset, {bool isExport: false, bool isImport: false}) { // TODO(ahe): Can I move this to Scope or Prefix? if (declaration == other) return declaration; @@ -2117,7 +2134,7 @@ class SourceLibraryBuilder extends LibraryBuilder { } bool isLocal = false; bool isLoadLibrary = false; - Declaration preferred; + Builder preferred; Uri uri; Uri otherUri; Uri preferredUri; @@ -2171,7 +2188,7 @@ class SourceLibraryBuilder extends LibraryBuilder { // imports. return declaration ..exportScope.merge(other.exportScope, - (String name, Declaration existing, Declaration member) { + (String name, Builder existing, Builder member) { return computeAmbiguousDeclaration( name, existing, member, charOffset, isExport: isExport, isImport: isImport); @@ -2281,7 +2298,7 @@ class SourceLibraryBuilder extends LibraryBuilder { /// If [synthesizeTypeParameterNames] is `true` the names of the /// [TypeParameter] are prefix with '#' to indicate that their synthesized. List copyTypeVariables( - List original, DeclarationBuilder declaration, + List original, TypeParameterScopeBuilder declaration, {bool synthesizeTypeParameterNames: false}) { List newTypes = []; List copy = []; @@ -2374,7 +2391,7 @@ class SourceLibraryBuilder extends LibraryBuilder { count += computeDefaultTypesForVariables( declaration.typeVariables, legacyMode || issues.isNotEmpty); } - declaration.forEach((String name, Declaration member) { + declaration.forEach((String name, Builder member) { if (member is ProcedureBuilder) { List issues = legacyMode ? const [] @@ -2414,9 +2431,9 @@ class SourceLibraryBuilder extends LibraryBuilder { NameIterator originDeclarations = origin.nameIterator; while (originDeclarations.moveNext()) { String name = originDeclarations.name; - Declaration member = originDeclarations.current; + Builder member = originDeclarations.current; bool isSetter = member.isSetter; - Declaration patch = isSetter ? scope.setters[name] : scope.local[name]; + Builder patch = isSetter ? scope.setters[name] : scope.local[name]; if (patch != null) { // [patch] has the same name as a [member] in [origin] library, so it // must be a patch to [member]. @@ -2436,7 +2453,7 @@ class SourceLibraryBuilder extends LibraryBuilder { NameIterator patchDeclarations = nameIterator; while (patchDeclarations.moveNext()) { String name = patchDeclarations.name; - Declaration member = patchDeclarations.current; + Builder member = patchDeclarations.current; // We need to inject all non-patch members into the origin library. This // should only apply to private members. if (member.isPatch) { @@ -2452,14 +2469,14 @@ class SourceLibraryBuilder extends LibraryBuilder { int finishPatchMethods() { if (!isPatch) return 0; int count = 0; - Iterator iterator = this.iterator; + Iterator iterator = this.iterator; while (iterator.moveNext()) { count += iterator.current.finishPatch(); } return count; } - void injectMemberFromPatch(String name, Declaration member) { + void injectMemberFromPatch(String name, Builder member) { if (member.isSetter) { assert(scope.setters[name] == null); scopeBuilder.addSetter(name, member); @@ -2469,7 +2486,7 @@ class SourceLibraryBuilder extends LibraryBuilder { } } - void exportMemberFromPatch(String name, Declaration member) { + void exportMemberFromPatch(String name, Builder member) { if (uri.scheme != "dart" || !uri.path.startsWith("_")) { addProblem(templatePatchInjectionFailed.withArguments(name, uri), member.charOffset, noLength, member.fileUri); @@ -2806,9 +2823,9 @@ class SourceLibraryBuilder extends LibraryBuilder { void checkBoundsInOutline(TypeEnvironment typeEnvironment) { if (loader.target.legacyMode) return; - Iterator iterator = this.iterator; + Iterator iterator = this.iterator; while (iterator.moveNext()) { - Declaration declaration = iterator.current; + Builder declaration = iterator.current; if (declaration is FieldBuilder) { checkBoundsInField(declaration.target, typeEnvironment); } else if (declaration is ProcedureBuilder) { @@ -2839,7 +2856,9 @@ class SourceLibraryBuilder extends LibraryBuilder { } } -enum DeclarationKind { +// The kind of type parameter scope built by a [TypeParameterScopeBuilder] +// object. +enum TypeParameterScopeKind { library, classOrNamedMixinApplication, classDeclaration, @@ -2854,18 +2873,21 @@ enum DeclarationKind { functionType, } +/// A builder object preparing for building declarations that can introduce type +/// parameter and/or members. +/// /// Unlike [Scope], this scope is used during construction of builders to /// ensure types and members are added to and resolved in the correct location. -class DeclarationBuilder { - DeclarationKind _kind; +class TypeParameterScopeBuilder { + TypeParameterScopeKind _kind; - final DeclarationBuilder parent; + final TypeParameterScopeBuilder parent; - final Map members; + final Map members; - final Map constructors; + final Map constructors; - final Map setters; + final Map setters; final List types = []; @@ -2887,18 +2909,18 @@ class DeclarationBuilder { bool hasConstConstructor = false; - DeclarationBuilder(this._kind, this.members, this.setters, this.constructors, - this._name, this._charOffset, this.parent) { + TypeParameterScopeBuilder(this._kind, this.members, this.setters, + this.constructors, this._name, this._charOffset, this.parent) { assert(_name != null); } - DeclarationBuilder.library() - : this(DeclarationKind.library, {}, - {}, null, "", -1, null); + TypeParameterScopeBuilder.library() + : this(TypeParameterScopeKind.library, {}, + {}, null, "", -1, null); - DeclarationBuilder createNested( - DeclarationKind kind, String name, bool hasMembers) { - return new DeclarationBuilder( + TypeParameterScopeBuilder createNested( + TypeParameterScopeKind kind, String name, bool hasMembers) { + return new TypeParameterScopeBuilder( kind, hasMembers ? {} : null, hasMembers ? {} : null, @@ -2908,77 +2930,79 @@ class DeclarationBuilder { this); } - /// Registers the this declaration as a class declaration with the given - /// [name] and [typeVariables] located [charOffset]. - void registerClassDeclaration( + /// Registers that this builder is preparing for a class declaration with the + /// given [name] and [typeVariables] located [charOffset]. + void markAsClassDeclaration( String name, int charOffset, List typeVariables) { - assert(_kind == DeclarationKind.classOrNamedMixinApplication, + assert(_kind == TypeParameterScopeKind.classOrNamedMixinApplication, "Unexpected declaration kind: $_kind"); - _kind = DeclarationKind.classDeclaration; + _kind = TypeParameterScopeKind.classDeclaration; _name = name; _charOffset = charOffset; _typeVariables = typeVariables; } - /// Registers the this declaration as a named mixin application with the given - /// [name] and [typeVariables] located [charOffset]. - void registerNamedMixinApplication( + /// Registers that this builder is preparing for a named mixin application + /// with the given [name] and [typeVariables] located [charOffset]. + void markAsNamedMixinApplication( String name, int charOffset, List typeVariables) { - assert(_kind == DeclarationKind.classOrNamedMixinApplication, + assert(_kind == TypeParameterScopeKind.classOrNamedMixinApplication, "Unexpected declaration kind: $_kind"); - _kind = DeclarationKind.namedMixinApplication; + _kind = TypeParameterScopeKind.namedMixinApplication; _name = name; _charOffset = charOffset; _typeVariables = typeVariables; } - /// Registers the this declaration as a mixin declaration with the given - /// [name] and [typeVariables] located [charOffset]. - void registerMixinDeclaration( + /// Registers that this builder is preparing for a mixin declaration with the + /// given [name] and [typeVariables] located [charOffset]. + void markAsMixinDeclaration( String name, int charOffset, List typeVariables) { // TODO(johnniwinther): Avoid using 'classOrNamedMixinApplication' for mixin // declaration. These are syntactically distinct so we don't need the // transition. - assert(_kind == DeclarationKind.classOrNamedMixinApplication, + assert(_kind == TypeParameterScopeKind.classOrNamedMixinApplication, "Unexpected declaration kind: $_kind"); - _kind = DeclarationKind.mixinDeclaration; + _kind = TypeParameterScopeKind.mixinDeclaration; _name = name; _charOffset = charOffset; _typeVariables = typeVariables; } - /// Registers the this declaration as an extension declaration with the given - /// [name] and [typeVariables] located [charOffset]. - void registerExtensionDeclaration( + /// Registers that this builder is preparing for an extension declaration with + /// the given [name] and [typeVariables] located [charOffset]. + void markAsExtensionDeclaration( String name, int charOffset, List typeVariables) { - assert(_kind == DeclarationKind.extensionDeclaration, + assert(_kind == TypeParameterScopeKind.extensionDeclaration, "Unexpected declaration kind: $_kind"); _name = name; _charOffset = charOffset; _typeVariables = typeVariables; } - /// Registers the 'extension this type' of this extension declaration. + /// Registers the 'extension this type' of the extension declaration prepared + /// for by this builder. /// /// See [extensionThisType] for terminology. void registerExtensionThisType(TypeBuilder type) { - assert(_kind == DeclarationKind.extensionDeclaration, + assert(_kind == TypeParameterScopeKind.extensionDeclaration, "DeclarationBuilder.registerExtensionThisType is not supported $_kind"); assert(_extensionThisType == null, "Extension this type has already been set."); _extensionThisType = type; } - /// Returns what kind of declaration this [DeclarationBuilder] is creating. + /// Returns what kind of declaration this [TypeParameterScopeBuilder] is + /// preparing for. /// /// This information is transient for some declarations. In particular /// classes and named mixin applications are initially created with the kind - /// [DeclarationKind.classOrNamedMixinApplication] before a call to either - /// [registerClassDeclaration] or [registerNamedMixinApplication] sets the + /// [TypeParameterScopeKind.classOrNamedMixinApplication] before a call to + /// either [markAsClassDeclaration] or [markAsNamedMixinApplication] sets the /// value to its actual kind. // TODO(johnniwinther): Avoid the transition currently used on mixin // declarations. - DeclarationKind get kind => _kind; + TypeParameterScopeKind get kind => _kind; String get name => _name; @@ -2986,7 +3010,8 @@ class DeclarationBuilder { List get typeVariables => _typeVariables; - /// Returns the 'extension this type' of this extension declaration. + /// Returns the 'extension this type' of the extension declaration prepared + /// for by this builder. /// /// The 'extension this type' is the type mentioned in the on-clause of the /// extension declaration. For instance `B` in this extension declaration: @@ -2998,13 +3023,18 @@ class DeclarationBuilder { /// The 'extension this type' is the type if `this` expression in instance /// methods declared in extension declarations. TypeBuilder get extensionThisType { - assert(kind == DeclarationKind.extensionDeclaration, + assert(kind == TypeParameterScopeKind.extensionDeclaration, "DeclarationBuilder.extensionThisType not supported on $kind."); assert(_extensionThisType != null, "DeclarationBuilder.extensionThisType has not been set on $this."); return _extensionThisType; } + /// Adds the yet unresolved [type] to this scope builder. + /// + /// Unresolved type will be resolved through [resolveTypes] when the scope + /// is fully built. This allows for resolving self-referencing types, like + /// type parameter used in their own bound, for instance `>`. void addType(UnresolvedType type) { types.add(type); } @@ -3025,7 +3055,7 @@ class DeclarationBuilder { String name = nameOrQualified is QualifiedName ? nameOrQualified.qualifier : nameOrQualified; - Declaration declaration; + Builder declaration; if (name != null) { if (members != null) { declaration = members[name]; @@ -3079,14 +3109,14 @@ class FieldInfo { class ImplementationInfo { final String name; - final Declaration declaration; + final Builder declaration; final int charOffset; const ImplementationInfo(this.name, this.declaration, this.charOffset); } -Uri computeLibraryUri(Declaration declaration) { - Declaration current = declaration; +Uri computeLibraryUri(Builder declaration) { + Builder current = declaration; do { if (current is LibraryBuilder) return current.uri; current = current.parent; diff --git a/pkg/front_end/lib/src/fasta/source/source_loader.dart b/pkg/front_end/lib/src/fasta/source/source_loader.dart index 8b69fc8a2853..2d8e0ea64b5d 100644 --- a/pkg/front_end/lib/src/fasta/source/source_loader.dart +++ b/pkg/front_end/lib/src/fasta/source/source_loader.dart @@ -74,7 +74,7 @@ import '../kernel/kernel_builder.dart' show ClassBuilder, ClassHierarchyBuilder, - Declaration, + Builder, DelayedMember, DelayedOverrideCheck, EnumBuilder, @@ -317,10 +317,9 @@ class SourceLoader extends Loader { if (token == null) return null; DietListener dietListener = createDietListener(library); - Declaration parent = library; + Builder parent = library; if (enclosingClass != null) { - Declaration cls = - dietListener.memberScope.lookup(enclosingClass, -1, null); + Builder cls = dietListener.memberScope.lookup(enclosingClass, -1, null); if (cls is ClassBuilder) { parent = cls; dietListener @@ -410,7 +409,7 @@ class SourceLoader extends Loader { wasChanged = false; for (SourceLibraryBuilder exported in both) { for (Export export in exported.exporters) { - exported.exportScope.forEach((String name, Declaration member) { + exported.exportScope.forEach((String name, Builder member) { if (export.addToExportScope(name, member)) { wasChanged = true; } @@ -439,13 +438,13 @@ class SourceLoader extends Loader { // TODO(sigmund): should be `covarint SourceLibraryBuilder`. builders.forEach((Uri uri, dynamic l) { SourceLibraryBuilder library = l; - Set members = new Set(); - Iterator iterator = library.iterator; + Set members = new Set(); + Iterator iterator = library.iterator; while (iterator.moveNext()) { members.add(iterator.current); } List exports = []; - library.exportScope.forEach((String name, Declaration member) { + library.exportScope.forEach((String name, Builder member) { while (member != null) { if (!members.contains(member)) { exports.add(name); @@ -586,9 +585,9 @@ class SourceLoader extends Loader { List workList = []; for (LibraryBuilder library in builders.values) { if (library.loader == this) { - Iterator members = library.iterator; + Iterator members = library.iterator; while (members.moveNext()) { - Declaration member = members.current; + Builder member = members.current; if (member is SourceClassBuilder) { workList.add(member); } @@ -611,11 +610,11 @@ class SourceLoader extends Loader { workList = []; for (int i = 0; i < previousWorkList.length; i++) { SourceClassBuilder cls = previousWorkList[i]; - List directSupertypes = + List directSupertypes = cls.computeDirectSupertypes(objectClass); bool allSupertypesProcessed = true; for (int i = 0; i < directSupertypes.length; i++) { - Declaration supertype = directSupertypes[i]; + Builder supertype = directSupertypes[i]; if (supertype is SourceClassBuilder && supertype.library.loader == this && !topologicallySortedClasses.contains(supertype)) { @@ -657,13 +656,11 @@ class SourceLoader extends Loader { return classes; } - void checkClassSupertypes( - SourceClassBuilder cls, - List directSupertypes, - Set blackListedClasses) { + void checkClassSupertypes(SourceClassBuilder cls, + List directSupertypes, Set blackListedClasses) { // Check that the direct supertypes aren't black-listed or enums. for (int i = 0; i < directSupertypes.length; i++) { - Declaration supertype = directSupertypes[i]; + Builder supertype = directSupertypes[i]; if (supertype is EnumBuilder) { cls.addProblem(templateExtendingEnum.withArguments(supertype.name), cls.charOffset, noLength); @@ -685,7 +682,7 @@ class SourceLoader extends Loader { var builder = mixedInType.declaration; if (builder is ClassBuilder) { isClassBuilder = true; - for (Declaration constructory in builder.constructors.local.values) { + for (Builder constructory in builder.constructors.local.values) { if (constructory.isConstructor && !constructory.isSynthetic) { cls.addProblem( templateIllegalMixinDueToConstructors @@ -979,9 +976,9 @@ class SourceLoader extends Loader { builders.forEach((Uri uri, LibraryBuilder library) { if (library.loader == this) { library.buildOutlineExpressions(); - Iterator iterator = library.iterator; + Iterator iterator = library.iterator; while (iterator.moveNext()) { - Declaration declaration = iterator.current; + Builder declaration = iterator.current; if (declaration is ClassBuilder) { declaration.buildOutlineExpressions(library); } else if (declaration is MemberBuilder) { diff --git a/pkg/front_end/lib/src/fasta/source/type_promotion_look_ahead_listener.dart b/pkg/front_end/lib/src/fasta/source/type_promotion_look_ahead_listener.dart index 9c0f3e7cc317..c4de27ce223b 100644 --- a/pkg/front_end/lib/src/fasta/source/type_promotion_look_ahead_listener.dart +++ b/pkg/front_end/lib/src/fasta/source/type_promotion_look_ahead_listener.dart @@ -4,7 +4,7 @@ library fasta.type_promotion_look_ahead_listener; -import '../builder/builder.dart' show Declaration; +import '../builder/builder.dart' show Builder; import '../messages.dart' show LocatedMessage, Message, MessageCode; @@ -32,7 +32,7 @@ abstract class TypePromotionState { final List scopes = [new Scope.top(isModifiable: true)]; - final List stack = []; + final List stack = []; TypePromotionState(this.uri); @@ -63,19 +63,19 @@ abstract class TypePromotionState { void pushReference(Token token) { String name = token.lexeme; - Declaration declaration = currentScope.lookup(name, token.charOffset, uri); + Builder declaration = currentScope.lookup(name, token.charOffset, uri); stack.add(declaration); } - Declaration pop() => stack.removeLast(); + Builder pop() => stack.removeLast(); - void push(Declaration declaration) { + void push(Builder declaration) { stack.add(declaration); } - Declaration popPushNull(String name, Token token) { + Builder popPushNull(String name, Token token) { int last = stack.length - 1; - Declaration declaration = stack[last]; + Builder declaration = stack[last]; stack[last] = nullValue(name, token); return declaration; } @@ -88,7 +88,7 @@ abstract class TypePromotionState { stack.add(nullValue(name, token)); } - Declaration nullValue(String name, Token token) => null; + Builder nullValue(String name, Token token) => null; void report(LocatedMessage message, Severity severity, {List context}); @@ -98,7 +98,7 @@ abstract class TypePromotionState { void checkEmpty(Token token) {} } -class UnspecifiedDeclaration extends Declaration { +class UnspecifiedDeclaration extends Builder { final String name; @override @@ -110,7 +110,7 @@ class UnspecifiedDeclaration extends Declaration { UnspecifiedDeclaration(this.name, this.fileUri, this.charOffset); @override - Declaration get parent => null; + Builder get parent => null; @override String get fullNameForErrors => name; @@ -119,7 +119,7 @@ class UnspecifiedDeclaration extends Declaration { String toString() => "UnspecifiedDeclaration($name)"; } -class NoArguments extends Declaration { +class NoArguments extends Builder { NoArguments(); @override @@ -129,7 +129,7 @@ class NoArguments extends Declaration { int get charOffset => -1; @override - Declaration get parent => null; + Builder get parent => null; @override String get fullNameForErrors => "<>"; @@ -198,7 +198,7 @@ class TypePromotionLookAheadListener extends Listener { void handleAssignmentExpression(Token token) { debugEvent("AssignmentExpression", token); state.pop(); // Right-hand side. - Declaration lhs = state.popPushNull(token.lexeme, token); + Builder lhs = state.popPushNull(token.lexeme, token); if (lhs is UnspecifiedDeclaration) { state.registerWrite(lhs, token); } @@ -850,7 +850,7 @@ class TypePromotionLookAheadListener extends Listener { @override void handleIsOperator(Token isOperator, Token not) { debugEvent("IsOperator", isOperator); - Declaration lhs = state.popPushNull(isOperator.lexeme, isOperator); + Builder lhs = state.popPushNull(isOperator.lexeme, isOperator); if (not == null && lhs is UnspecifiedDeclaration) { state.registerPromotionCandidate(lhs, isOperator); } @@ -1173,7 +1173,7 @@ class TypePromotionLookAheadListener extends Listener { @override void handleSend(Token beginToken, Token endToken) { debugEvent("Send", beginToken); - Declaration arguments = state.pop(); + Builder arguments = state.pop(); if (identical(arguments, noArgumentsSentinel)) { // Leave the receiver on the stack. } else { @@ -1339,7 +1339,7 @@ class TypePromotionLookAheadListener extends Listener { @override void handleUnaryPostfixAssignmentExpression(Token token) { debugEvent("UnaryPostfixAssignmentExpression", token); - Declaration expr = state.popPushNull(token.lexeme, token); + Builder expr = state.popPushNull(token.lexeme, token); if (expr is UnspecifiedDeclaration) { state.registerWrite(expr, token); } @@ -1348,7 +1348,7 @@ class TypePromotionLookAheadListener extends Listener { @override void handleUnaryPrefixAssignmentExpression(Token token) { debugEvent("UnaryPrefixAssignmentExpression", token); - Declaration expr = state.popPushNull(token.lexeme, token); + Builder expr = state.popPushNull(token.lexeme, token); if (expr is UnspecifiedDeclaration) { state.registerWrite(expr, token); } diff --git a/pkg/front_end/lib/src/fasta/target_implementation.dart b/pkg/front_end/lib/src/fasta/target_implementation.dart index 586100d8cf71..dd80c6f9357c 100644 --- a/pkg/front_end/lib/src/fasta/target_implementation.dart +++ b/pkg/front_end/lib/src/fasta/target_implementation.dart @@ -10,7 +10,7 @@ import 'package:kernel/target/targets.dart' as backend show Target; import '../base/processed_options.dart' show ProcessedOptions; -import 'builder/builder.dart' show Declaration, ClassBuilder, LibraryBuilder; +import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; import 'compiler_context.dart' show CompilerContext; @@ -41,12 +41,12 @@ abstract class TargetImplementation extends Target { /// Shared with [CompilerContext]. final Map uriToSource = CompilerContext.current.uriToSource; - Declaration cachedAbstractClassInstantiationError; - Declaration cachedCompileTimeError; - Declaration cachedDuplicatedFieldInitializerError; - Declaration cachedFallThroughError; - Declaration cachedNativeAnnotation; - Declaration cachedNativeExtensionAnnotation; + Builder cachedAbstractClassInstantiationError; + Builder cachedCompileTimeError; + Builder cachedDuplicatedFieldInitializerError; + Builder cachedFallThroughError; + Builder cachedNativeAnnotation; + Builder cachedNativeExtensionAnnotation; bool enableConstantUpdate2018; bool enableControlFlowCollections; @@ -91,7 +91,7 @@ abstract class TargetImplementation extends Target { /// [AbstractClassInstantiationError] error. The constructor is expected to /// accept a single argument of type String, which is the name of the /// abstract class. - Declaration getAbstractClassInstantiationError(Loader loader) { + Builder getAbstractClassInstantiationError(Loader loader) { if (cachedAbstractClassInstantiationError != null) { return cachedAbstractClassInstantiationError; } @@ -102,7 +102,7 @@ abstract class TargetImplementation extends Target { /// Returns a reference to the constructor used for creating a compile-time /// error. The constructor is expected to accept a single argument of type /// String, which is the compile-time error message. - Declaration getCompileTimeError(Loader loader) { + Builder getCompileTimeError(Loader loader) { if (cachedCompileTimeError != null) return cachedCompileTimeError; return cachedCompileTimeError = loader.coreLibrary .getConstructor("_CompileTimeError", bypassLibraryPrivacy: true); @@ -111,7 +111,7 @@ abstract class TargetImplementation extends Target { /// Returns a reference to the constructor used for creating a runtime error /// when a final field is initialized twice. The constructor is expected to /// accept a single argument which is the name of the field. - Declaration getDuplicatedFieldInitializerError(Loader loader) { + Builder getDuplicatedFieldInitializerError(Loader loader) { if (cachedDuplicatedFieldInitializerError != null) { return cachedDuplicatedFieldInitializerError; } @@ -123,7 +123,7 @@ abstract class TargetImplementation extends Target { /// Returns a reference to the constructor used for creating `native` /// annotations. The constructor is expected to accept a single argument of /// type String, which is the name of the native method. - Declaration getNativeAnnotation(Loader loader) { + Builder getNativeAnnotation(Loader loader) { if (cachedNativeAnnotation != null) return cachedNativeAnnotation; LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1, accessor: loader.coreLibrary); diff --git a/pkg/front_end/lib/src/testing/id_testing_utils.dart b/pkg/front_end/lib/src/testing/id_testing_utils.dart index 9670d2d7741a..5cc948c6e9de 100644 --- a/pkg/front_end/lib/src/testing/id_testing_utils.dart +++ b/pkg/front_end/lib/src/testing/id_testing_utils.dart @@ -81,7 +81,7 @@ Member lookupClassMember(Class cls, String memberName, {bool required: true}) { }); } -DeclarationBuilder lookupLibraryDeclarationBuilder( +TypeParameterScopeBuilder lookupLibraryDeclarationBuilder( CompilerResult compilerResult, Library library, {bool required: true}) { SourceLoader loader = compilerResult.kernelTargetForTesting.loader; @@ -94,7 +94,7 @@ DeclarationBuilder lookupLibraryDeclarationBuilder( ClassBuilder lookupClassBuilder(CompilerResult compilerResult, Class cls, {bool required: true}) { - DeclarationBuilder libraryBuilder = lookupLibraryDeclarationBuilder( + TypeParameterScopeBuilder libraryBuilder = lookupLibraryDeclarationBuilder( compilerResult, cls.enclosingLibrary, required: required); ClassBuilder clsBuilder = libraryBuilder.members[cls.name]; @@ -135,7 +135,7 @@ MemberBuilder lookupMemberBuilder(CompilerResult compilerResult, Member member, compilerResult, member.enclosingClass, member, member.name.name, required: required); } else { - DeclarationBuilder libraryBuilder = lookupLibraryDeclarationBuilder( + TypeParameterScopeBuilder libraryBuilder = lookupLibraryDeclarationBuilder( compilerResult, member.enclosingLibrary); if (member is Procedure && member.isSetter) { memberBuilder = libraryBuilder.members[member.name.name]; diff --git a/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart b/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart index 8b4fe9a3dfc8..ebc39e77bae3 100644 --- a/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart +++ b/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart @@ -7,7 +7,7 @@ import 'dart:convert' show jsonDecode; import 'package:front_end/src/base/processed_options.dart' show ProcessedOptions; -import 'package:front_end/src/fasta/builder/builder.dart' show Declaration; +import 'package:front_end/src/fasta/builder/builder.dart' show Builder; import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext; @@ -133,7 +133,7 @@ class TestState extends TypePromotionState { } @override - Declaration nullValue(String name, Token token) { + Builder nullValue(String name, Token token) { return new DebugDeclaration(name, uri, token?.charOffset ?? -1); } @@ -188,7 +188,7 @@ class TestListener extends TypePromotionLookAheadListener { } } -class DebugDeclaration extends Declaration { +class DebugDeclaration extends Builder { final String name; @override @@ -199,7 +199,7 @@ class DebugDeclaration extends Declaration { DebugDeclaration(this.name, this.fileUri, this.charOffset); - Declaration get parent => null; + Builder get parent => null; String get fullNameForErrors => name;