Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: pkg/front_end/lib/src/fasta/builder/class_builder.dart

Issue 2788153002: Create separate scopes for constructors, setters, and other members. (Closed)
Patch Set: One more flaky standalone/io test. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/builder/class_builder.dart
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 a6e892aeda295e0a3b0b72f2edbb8d0a9710b164..6cbecb53381ccacb3a42be09234794c967ab64c5 100644
--- a/pkg/front_end/lib/src/fasta/builder/class_builder.dart
+++ b/pkg/front_end/lib/src/fasta/builder/class_builder.dart
@@ -15,12 +15,12 @@ import 'builder.dart'
MetadataBuilder,
MixinApplicationBuilder,
NamedTypeBuilder,
+ Scope,
+ ScopeBuilder,
TypeBuilder,
TypeDeclarationBuilder,
TypeVariableBuilder;
-import '../scope.dart' show AccessErrorBuilder, AmbiguousBuilder, Scope;
-
abstract class ClassBuilder<T extends TypeBuilder, R>
extends TypeDeclarationBuilder<T, R> {
final List<TypeVariableBuilder> typeVariables;
@@ -29,7 +29,13 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
List<T> interfaces;
- final Map<String, Builder> members;
+ final Scope scope;
+
+ final Scope constructors;
+
+ final ScopeBuilder scopeBuilder;
+
+ final ScopeBuilder constructorScopeBuilder;
ClassBuilder(
List<MetadataBuilder> metadata,
@@ -38,10 +44,13 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
this.typeVariables,
this.supertype,
this.interfaces,
- this.members,
+ this.scope,
+ this.constructors,
LibraryBuilder parent,
int charOffset)
- : super(metadata, modifiers, name, parent, charOffset);
+ : scopeBuilder = new ScopeBuilder(scope),
+ constructorScopeBuilder = new ScopeBuilder(constructors),
+ super(metadata, modifiers, name, parent, charOffset);
/// Returns true if this class is the result of applying a mixin to its
/// superclass.
@@ -51,10 +60,6 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
List<ConstructorReferenceBuilder> get constructorReferences => null;
- Map<String, Builder> get constructors;
-
- Map<String, Builder> get membersInScope => members;
-
LibraryBuilder get library {
LibraryBuilder library = parent;
return library.partOfLibrary ?? library;
@@ -63,70 +68,23 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
@override
int resolveConstructors(LibraryBuilder library) {
if (constructorReferences == null) return 0;
- Scope scope = computeInstanceScope(library.scope);
for (ConstructorReferenceBuilder ref in constructorReferences) {
ref.resolveIn(scope);
}
return constructorReferences.length;
}
- Scope computeInstanceScope(Scope parent) {
- if (typeVariables != null) {
- Map<String, Builder> local = <String, Builder>{};
- for (TypeVariableBuilder t in typeVariables) {
- local[t.name] = t;
- }
- parent = new Scope(local, null, parent, isModifiable: false);
- }
- return new Scope(membersInScope, null, parent, isModifiable: false);
- }
-
/// Used to lookup a static member of this class.
Builder findStaticBuilder(String name, int charOffset, Uri fileUri,
{bool isSetter: false}) {
- Builder builder = members[name];
- if (builder?.next != null) {
- Builder getterBuilder;
- Builder setterBuilder;
- Builder current = builder;
- while (current != null) {
- if (current.isGetter && getterBuilder == null) {
- getterBuilder = current;
- } else if (current.isSetter && setterBuilder == null) {
- setterBuilder = current;
- } else {
- return new AmbiguousBuilder(name, builder, charOffset, fileUri);
- }
- current = current.next;
- }
- if (getterBuilder?.isInstanceMember ?? false) {
- getterBuilder = null;
- }
- if (setterBuilder?.isInstanceMember ?? false) {
- setterBuilder = null;
- }
- builder = isSetter ? setterBuilder : getterBuilder;
- if (builder == null) {
- if (isSetter && getterBuilder != null) {
- return new AccessErrorBuilder(
- name, getterBuilder, charOffset, fileUri);
- } else if (!isSetter && setterBuilder != null) {
- return new AccessErrorBuilder(
- name, setterBuilder, charOffset, fileUri);
- }
- }
- }
- if (builder == null) {
- return null;
- } else if (isSetter && builder.isGetter) {
- return null;
- } else {
- return builder.isInstanceMember ? null : builder;
- }
+ Builder builder = isSetter
+ ? scope.lookupSetter(name, charOffset, fileUri, isInstanceScope: false)
+ : scope.lookup(name, charOffset, fileUri, isInstanceScope: false);
+ return builder;
}
Builder findConstructorOrFactory(String name, int charOffset, Uri uri) {
- return constructors[name];
+ return constructors.lookup(name, charOffset, uri);
}
/// Returns a map which maps the type variables of [superclass] to their
@@ -193,14 +151,14 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
}
void forEach(void f(String name, MemberBuilder builder)) {
- members.forEach(f);
+ scope.forEach(f);
}
/// Don't use for scope lookup. Only use when an element is known to exist
/// (and isn't a setter).
MemberBuilder operator [](String name) {
// TODO(ahe): Rename this to getLocalMember.
- return members[name] ?? internalError("Not found: '$name'.");
+ return scope.local[name] ?? internalError("Not found: '$name'.");
}
void addCompileTimeError(int charOffset, String message) {
« no previous file with comments | « pkg/front_end/lib/src/fasta/builder/builder.dart ('k') | pkg/front_end/lib/src/fasta/builder/library_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698