Skip to content

Commit

Permalink
[cfe] Rename Declaration and DeclarationBuilder
Browse files Browse the repository at this point in the history
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 <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Aug 8, 2019
1 parent e9a9d94 commit 9a71c99
Show file tree
Hide file tree
Showing 39 changed files with 622 additions and 616 deletions.
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/builder/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
44 changes: 22 additions & 22 deletions pkg/front_end/lib/src/fasta/builder/class_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import '../dill/dill_member_builder.dart' show DillMemberBuilder;
import 'builder.dart'
show
ConstructorReferenceBuilder,
Declaration,
Builder,
LibraryBuilder,
MemberBuilder,
MetadataBuilder,
Expand Down Expand Up @@ -107,7 +107,7 @@ import '../fasta_codes.dart'
import '../kernel/kernel_builder.dart'
show
ConstructorReferenceBuilder,
Declaration,
Builder,
FunctionBuilder,
NamedTypeBuilder,
LibraryBuilder,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder {
// Copy keys to avoid concurrent modification error.
List<String> 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,
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -341,20 +341,20 @@ 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);
}
return declaration;
}

void forEach(void f(String name, Declaration builder)) {
void forEach(void f(String name, Builder builder)) {
scope.forEach(f);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1640,7 +1640,7 @@ abstract class ClassBuilder extends TypeDeclarationBuilder {
Map<String, MemberBuilder> constructors = this.constructors.local;
Iterable<String> names = constructors.keys;
for (String name in names) {
Declaration constructor = constructors[name];
Builder constructor = constructors[name];
do {
if (constructor is RedirectingFactoryBuilder) {
checkRedirectingFactory(constructor, typeEnvironment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../messages.dart' show noLength, templateConstructorNotFound;
import 'builder.dart'
show
ClassBuilder,
Declaration,
Builder,
LibraryBuilder,
PrefixBuilder,
QualifiedName,
Expand All @@ -29,10 +29,10 @@ class ConstructorReferenceBuilder {
/// This is the name of a named constructor. As `bar` in `new Foo<T>.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 {
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions pkg/front_end/lib/src/fasta/builder/declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ 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;

int get charOffset;

get target => unsupported("${runtimeType}.target", charOffset, fileUri);

Declaration get origin => this;
Builder get origin => this;

String get fullNameForErrors;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions pkg/front_end/lib/src/fasta/builder/enum_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import '../source/source_class_builder.dart' show SourceClassBuilder;

import '../kernel/kernel_builder.dart'
show
Declaration,
Builder,
FormalParameterBuilder,
ClassBuilder,
ConstructorBuilder,
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand All @@ -344,7 +344,7 @@ class EnumBuilder extends SourceClassBuilder {
}

@override
Declaration findConstructorOrFactory(
Builder findConstructorOrFactory(
String name, int charOffset, Uri uri, LibraryBuilder library) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/fasta/builder/field_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import '../kernel/body_builder.dart' show BodyBuilder;
import '../kernel/kernel_builder.dart'
show
ClassBuilder,
Declaration,
Builder,
ImplicitFieldType,
TypeBuilder,
LibraryBuilder,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import '../kernel/body_builder.dart' show BodyBuilder;
import '../kernel/kernel_builder.dart'
show
ClassBuilder,
Declaration,
Builder,
ConstructorBuilder,
FieldBuilder,
LibraryBuilder,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9a71c99

Please sign in to comment.