Replace Builder by Declaration

Change-Id: I1d9997ab22290e9fc882b64b0934f70c6aed2261
Reviewed-on: https://dart-review.googlesource.com/57505
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Peter von der Ahé <ahe@google.com>
This commit is contained in:
Peter von der Ahé 2018-05-31 09:19:33 +00:00 committed by commit-bot@chromium.org
parent 39b0efd613
commit bb0808db80
39 changed files with 703 additions and 643 deletions

View file

@ -4,14 +4,6 @@
library fasta.builder; library fasta.builder;
import '../../base/instrumentation.dart' show Instrumentation;
import '../problems.dart' show unhandled, unsupported;
import 'library_builder.dart' show LibraryBuilder;
import 'class_builder.dart' show ClassBuilder;
export '../scope.dart' show AccessErrorBuilder, Scope, ScopeBuilder; export '../scope.dart' show AccessErrorBuilder, Scope, ScopeBuilder;
export 'builtin_type_builder.dart' show BuiltinTypeBuilder; export 'builtin_type_builder.dart' show BuiltinTypeBuilder;
@ -20,6 +12,8 @@ export 'class_builder.dart' show ClassBuilder;
export 'constructor_reference_builder.dart' show ConstructorReferenceBuilder; export 'constructor_reference_builder.dart' show ConstructorReferenceBuilder;
export 'declaration.dart' show Declaration;
export 'dynamic_type_builder.dart' show DynamicTypeBuilder; export 'dynamic_type_builder.dart' show DynamicTypeBuilder;
export 'enum_builder.dart' show EnumBuilder; export 'enum_builder.dart' show EnumBuilder;
@ -61,93 +55,3 @@ export 'type_variable_builder.dart' show TypeVariableBuilder;
export 'unresolved_type.dart' show UnresolvedType; export 'unresolved_type.dart' show UnresolvedType;
export 'void_type_builder.dart' show VoidTypeBuilder; export 'void_type_builder.dart' show VoidTypeBuilder;
abstract class Builder {
/// Used when multiple things with the same name are declared within the same
/// parent. Only used for declarations, not for scopes.
///
// TODO(ahe): Move to member builder or something. Then we can make
// this a const class.
Builder next;
/// The values of [parent], [charOffset], and [fileUri] aren't stored. We
/// need to evaluate the memory impact of doing so, but want to ensure the
/// information is always provided.
Builder(Builder parent, int charOffset, Uri fileUri);
int get charOffset => -1;
Uri get fileUri => null;
/// Resolve constructors (lookup names in scope) recorded in this builder and
/// return the number of constructors resolved.
int resolveConstructors(LibraryBuilder parent) => 0;
Builder get parent => null;
bool get isFinal => false;
bool get isField => false;
bool get isRegularMethod => false;
bool get isGetter => false;
bool get isSetter => false;
bool get isInstanceMember => false;
bool get isStatic => false;
bool get isTopLevel => false;
bool get isTypeDeclaration => false;
bool get isTypeVariable => false;
bool get isConstructor => false;
bool get isFactory => false;
bool get isLocal => false;
bool get isConst => false;
bool get isSynthetic => false;
get target => unsupported("${runtimeType}.target", charOffset, fileUri);
bool get hasProblem => false;
bool get isPatch => this != origin;
Builder get origin => this;
String get fullNameForErrors;
Uri computeLibraryUri() {
Builder builder = this;
do {
if (builder is LibraryBuilder) return builder.uri;
builder = builder.parent;
} while (builder != null);
return unhandled("no library parent", "${runtimeType}", -1, null);
}
void prepareTopLevelInference(
covariant LibraryBuilder library, ClassBuilder currentClass) {}
void instrumentTopLevelInference(Instrumentation instrumentation) {}
/// Applies [patch] to this.
void applyPatch(Builder patch) {
unsupported("${runtimeType}.applyPatch", charOffset, fileUri);
}
/// Returns the number of patches that was finished.
int finishPatch() {
if (!isPatch) return 0;
unsupported("${runtimeType}.finishPatch", charOffset, fileUri);
return 0;
}
}

View file

@ -8,8 +8,8 @@ import '../problems.dart' show internalProblem;
import 'builder.dart' import 'builder.dart'
show show
Builder,
ConstructorReferenceBuilder, ConstructorReferenceBuilder,
Declaration,
LibraryBuilder, LibraryBuilder,
MemberBuilder, MemberBuilder,
MetadataBuilder, MetadataBuilder,
@ -90,19 +90,19 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
} }
/// Used to lookup a static member of this class. /// Used to lookup a static member of this class.
Builder findStaticBuilder( Declaration findStaticBuilder(
String name, int charOffset, Uri fileUri, LibraryBuilder accessingLibrary, String name, int charOffset, Uri fileUri, LibraryBuilder accessingLibrary,
{bool isSetter: false}) { {bool isSetter: false}) {
if (accessingLibrary.origin != library.origin && name.startsWith("_")) { if (accessingLibrary.origin != library.origin && name.startsWith("_")) {
return null; return null;
} }
Builder builder = isSetter Declaration declaration = isSetter
? scope.lookupSetter(name, charOffset, fileUri, isInstanceScope: false) ? scope.lookupSetter(name, charOffset, fileUri, isInstanceScope: false)
: scope.lookup(name, charOffset, fileUri, isInstanceScope: false); : scope.lookup(name, charOffset, fileUri, isInstanceScope: false);
return builder; return declaration;
} }
Builder findConstructorOrFactory( Declaration findConstructorOrFactory(
String name, int charOffset, Uri uri, LibraryBuilder accessingLibrary) { String name, int charOffset, Uri uri, LibraryBuilder accessingLibrary) {
if (accessingLibrary.origin != library.origin && name.startsWith("_")) { if (accessingLibrary.origin != library.origin && name.startsWith("_")) {
return null; return null;
@ -137,14 +137,14 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
Map<TypeVariableBuilder, TypeBuilder> substitutionMap; Map<TypeVariableBuilder, TypeBuilder> substitutionMap;
List arguments; List arguments;
List variables; List variables;
Builder builder; Declaration declaration;
/// If [application] is mixing in [superclass] directly or via other named /// If [application] is mixing in [superclass] directly or via other named
/// mixin applications, return it. /// mixin applications, return it.
NamedTypeBuilder findSuperclass(MixinApplicationBuilder application) { NamedTypeBuilder findSuperclass(MixinApplicationBuilder application) {
for (TypeBuilder t in application.mixins) { for (TypeBuilder t in application.mixins) {
if (t is NamedTypeBuilder) { if (t is NamedTypeBuilder) {
if (t.builder == superclass) return t; if (t.declaration == superclass) return t;
} else if (t is MixinApplicationBuilder) { } else if (t is MixinApplicationBuilder) {
NamedTypeBuilder s = findSuperclass(t); NamedTypeBuilder s = findSuperclass(t);
if (s != null) return s; if (s != null) return s;
@ -154,16 +154,16 @@ abstract class ClassBuilder<T extends TypeBuilder, R>
} }
void handleNamedTypeBuilder(NamedTypeBuilder t) { void handleNamedTypeBuilder(NamedTypeBuilder t) {
builder = t.builder; declaration = t.declaration;
arguments = t.arguments ?? const []; arguments = t.arguments ?? const [];
if (builder is ClassBuilder) { if (declaration is ClassBuilder) {
ClassBuilder cls = builder; ClassBuilder cls = declaration;
variables = cls.typeVariables; variables = cls.typeVariables;
supertype = cls.supertype; supertype = cls.supertype;
} }
} }
while (builder != superclass) { while (declaration != superclass) {
variables = null; variables = null;
if (supertype is NamedTypeBuilder) { if (supertype is NamedTypeBuilder) {
handleNamedTypeBuilder(supertype); handleNamedTypeBuilder(supertype);

View file

@ -8,15 +8,19 @@ import '../messages.dart' show noLength, templateConstructorNotFound;
import 'builder.dart' import 'builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
Declaration,
LibraryBuilder, LibraryBuilder,
PrefixBuilder, PrefixBuilder,
QualifiedName, QualifiedName,
Scope, Scope,
TypeBuilder; TypeBuilder;
class ConstructorReferenceBuilder extends Builder { class ConstructorReferenceBuilder {
final int charOffset;
final Uri fileUri;
final Object name; final Object name;
final List<TypeBuilder> typeArguments; final List<TypeBuilder> typeArguments;
@ -24,38 +28,38 @@ class ConstructorReferenceBuilder extends Builder {
/// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`. /// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`.
final String suffix; final String suffix;
Builder target; Declaration target;
ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix, ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix,
Builder parent, int charOffset) Declaration parent, this.charOffset)
: super(parent, charOffset, parent.fileUri); : fileUri = parent.fileUri;
String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}"; String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}";
void resolveIn(Scope scope, LibraryBuilder accessingLibrary) { void resolveIn(Scope scope, LibraryBuilder accessingLibrary) {
final name = this.name; final name = this.name;
Builder builder; Declaration declaration;
if (name is QualifiedName) { if (name is QualifiedName) {
String prefix = name.prefix; String prefix = name.prefix;
String middle = name.suffix; String middle = name.suffix;
builder = scope.lookup(prefix, charOffset, fileUri); declaration = scope.lookup(prefix, charOffset, fileUri);
if (builder is PrefixBuilder) { if (declaration is PrefixBuilder) {
PrefixBuilder prefix = builder; PrefixBuilder prefix = declaration;
builder = prefix.lookup(middle, name.charOffset, fileUri); declaration = prefix.lookup(middle, name.charOffset, fileUri);
} else if (builder is ClassBuilder) { } else if (declaration is ClassBuilder) {
ClassBuilder cls = builder; ClassBuilder cls = declaration;
builder = cls.findConstructorOrFactory( declaration = cls.findConstructorOrFactory(
middle, name.charOffset, fileUri, accessingLibrary); middle, name.charOffset, fileUri, accessingLibrary);
if (suffix == null) { if (suffix == null) {
target = builder; target = declaration;
return; return;
} }
} }
} else { } else {
builder = scope.lookup(name, charOffset, fileUri); declaration = scope.lookup(name, charOffset, fileUri);
} }
if (builder is ClassBuilder) { if (declaration is ClassBuilder) {
target = builder.findConstructorOrFactory( target = declaration.findConstructorOrFactory(
suffix ?? "", charOffset, fileUri, accessingLibrary); suffix ?? "", charOffset, fileUri, accessingLibrary);
} }
if (target == null) { if (target == null) {

View file

@ -0,0 +1,93 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// 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.
library fasta.declaration;
import '../problems.dart' show unhandled, unsupported;
import 'library_builder.dart' show LibraryBuilder;
abstract class Declaration {
/// 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;
Declaration();
Declaration get parent;
Uri get fileUri;
int get charOffset;
get target => unsupported("${runtimeType}.target", charOffset, fileUri);
Declaration get origin => this;
String get fullNameForErrors;
bool get hasProblem => false;
bool get isConst => false;
bool get isConstructor => false;
bool get isFactory => false;
bool get isField => false;
bool get isFinal => false;
bool get isGetter => false;
bool get isInstanceMember => false;
bool get isLocal => false;
bool get isPatch => this != origin;
bool get isRegularMethod => false;
bool get isSetter => false;
bool get isStatic => false;
bool get isSynthetic => false;
bool get isTopLevel => false;
bool get isTypeDeclaration => false;
bool get isTypeVariable => false;
Uri computeLibraryUri() {
Declaration declaration = this;
do {
if (declaration is LibraryBuilder) return declaration.uri;
declaration = declaration.parent;
} while (declaration != null);
return unhandled("no library parent", "${runtimeType}", -1, null);
}
/// Applies [patch] to this declaration.
void applyPatch(Declaration patch) {
unsupported("${runtimeType}.applyPatch", charOffset, fileUri);
}
/// Returns the number of patches that was finished.
int finishPatch() {
if (!isPatch) return 0;
unsupported("${runtimeType}.finishPatch", charOffset, fileUri);
return 0;
}
/// Resolve constructors (lookup names in scope) recorded in this builder and
/// return the number of constructors resolved.
int resolveConstructors(covariant Declaration parent) => 0;
void prepareTopLevelInference(covariant library, covariant currentClass) {}
void instrumentTopLevelInference(covariant instrumentation) {}
}

View file

@ -22,8 +22,8 @@ import '../messages.dart'
import 'builder.dart' import 'builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
Declaration,
ModifierBuilder, ModifierBuilder,
PrefixBuilder, PrefixBuilder,
Scope, Scope,
@ -51,6 +51,9 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
exportScopeBuilder = new ScopeBuilder(exportScope), exportScopeBuilder = new ScopeBuilder(exportScope),
super(null, -1, fileUri); super(null, -1, fileUri);
@override
Declaration get parent => null;
bool get isPart => false; bool get isPart => false;
@override @override
@ -66,7 +69,7 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
Uri get uri; Uri get uri;
Builder addBuilder(String name, Builder builder, int charOffset); Declaration addBuilder(String name, Declaration declaration, int charOffset);
void addExporter( void addExporter(
LibraryBuilder exporter, List<Combinator> combinators, int charOffset) { LibraryBuilder exporter, List<Combinator> combinators, int charOffset) {
@ -93,16 +96,17 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
} }
/// Returns true if the export scope was modified. /// Returns true if the export scope was modified.
bool addToExportScope(String name, Builder member) { bool addToExportScope(String name, Declaration member) {
if (name.startsWith("_")) return false; if (name.startsWith("_")) return false;
if (member is PrefixBuilder) return false; if (member is PrefixBuilder) return false;
Map<String, Builder> map = Map<String, Declaration> map =
member.isSetter ? exportScope.setters : exportScope.local; member.isSetter ? exportScope.setters : exportScope.local;
Builder existing = map[name]; Declaration existing = map[name];
if (existing == member) return false; if (existing == member) return false;
if (existing != null) { if (existing != null) {
Builder result = Declaration result = computeAmbiguousDeclaration(
buildAmbiguousBuilder(name, existing, member, -1, isExport: true); name, existing, member, -1,
isExport: true);
map[name] = result; map[name] = result;
return result != existing; return result != existing;
} else { } else {
@ -111,10 +115,11 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
return true; return true;
} }
void addToScope(String name, Builder member, int charOffset, bool isImport); void addToScope(
String name, Declaration member, int charOffset, bool isImport);
Builder buildAmbiguousBuilder( Declaration computeAmbiguousDeclaration(
String name, Builder builder, Builder other, int charOffset, String name, Declaration declaration, Declaration other, int charOffset,
{bool isExport: false, bool isImport: false}); {bool isExport: false, bool isImport: false});
int finishDeferredLoadTearoffs() => 0; int finishDeferredLoadTearoffs() => 0;
@ -135,7 +140,7 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
/// If [constructorName] is null or the empty string, it's assumed to be an /// If [constructorName] is null or the empty string, it's assumed to be an
/// unnamed constructor. it's an error if [constructorName] starts with /// unnamed constructor. it's an error if [constructorName] starts with
/// `"_"`, and [bypassLibraryPrivacy] is false. /// `"_"`, and [bypassLibraryPrivacy] is false.
Builder getConstructor(String className, Declaration getConstructor(String className,
{String constructorName, bool bypassLibraryPrivacy: false}) { {String constructorName, bool bypassLibraryPrivacy: false}) {
constructorName ??= ""; constructorName ??= "";
if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { if (constructorName.startsWith("_") && !bypassLibraryPrivacy) {
@ -145,12 +150,12 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
-1, -1,
null); null);
} }
Builder cls = (bypassLibraryPrivacy ? scope : exportScope) Declaration cls = (bypassLibraryPrivacy ? scope : exportScope)
.lookup(className, -1, null); .lookup(className, -1, null);
if (cls is ClassBuilder) { if (cls is ClassBuilder) {
// TODO(ahe): This code is similar to code in `endNewExpression` in // TODO(ahe): This code is similar to code in `endNewExpression` in
// `body_builder.dart`, try to share it. // `body_builder.dart`, try to share it.
Builder constructor = Declaration constructor =
cls.findConstructorOrFactory(constructorName, -1, null, this); cls.findConstructorOrFactory(constructorName, -1, null, this);
if (constructor == null) { if (constructor == null) {
// Fall-through to internal error below. // Fall-through to internal error below.
@ -182,17 +187,17 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
void becomeCoreLibrary(dynamicType); void becomeCoreLibrary(dynamicType);
void forEach(void f(String name, Builder builder)) { void forEach(void f(String name, Declaration declaration)) {
scope.forEach((String name, Builder builder) { scope.forEach((String name, Declaration declaration) {
if (builder.parent == this) { if (declaration.parent == this) {
f(name, builder); f(name, declaration);
} }
}); });
} }
/// Don't use for scope lookup. Only use when an element is known to exist /// Don't use for scope lookup. Only use when an element is known to exist
/// (and not a setter). /// (and not a setter).
Builder operator [](String name) { Declaration operator [](String name) {
return scope.local[name] ?? return scope.local[name] ??
internalProblem( internalProblem(
templateInternalProblemNotFoundIn.withArguments(name, "$fileUri"), templateInternalProblemNotFoundIn.withArguments(name, "$fileUri"),
@ -200,7 +205,7 @@ abstract class LibraryBuilder<T extends TypeBuilder, R>
fileUri); fileUri);
} }
Builder lookup(String name, int charOffset, Uri fileUri) { Declaration lookup(String name, int charOffset, Uri fileUri) {
return scope.lookup(name, charOffset, fileUri); return scope.lookup(name, charOffset, fileUri);
} }

View file

@ -5,13 +5,13 @@
library fasta.member_builder; library fasta.member_builder;
import 'builder.dart' import 'builder.dart'
show Builder, ClassBuilder, LibraryBuilder, ModifierBuilder; show ClassBuilder, Declaration, LibraryBuilder, ModifierBuilder;
abstract class MemberBuilder extends ModifierBuilder { abstract class MemberBuilder extends ModifierBuilder {
/// For top-level members, the parent is set correctly during /// For top-level members, the parent is set correctly during
/// construction. However, for class members, the parent is initially the /// construction. However, for class members, the parent is initially the
/// library and updated later. /// library and updated later.
Builder parent; Declaration parent;
String get name; String get name;

View file

@ -4,25 +4,24 @@
library fasta.metadata_builder; library fasta.metadata_builder;
import 'builder.dart' show Builder, TypeBuilder; import 'builder.dart' show Declaration, TypeBuilder;
import 'constructor_reference_builder.dart' show ConstructorReferenceBuilder; import 'constructor_reference_builder.dart' show ConstructorReferenceBuilder;
abstract class MetadataBuilder<T extends TypeBuilder> extends Builder { abstract class MetadataBuilder<T extends TypeBuilder> {
MetadataBuilder(Builder parent, int charOffset) MetadataBuilder(Declaration parent, int charOffset);
: super(parent, -1, parent.fileUri);
factory MetadataBuilder.fromConstructor( factory MetadataBuilder.fromConstructor(
ConstructorReferenceBuilder constructorReference, ConstructorReferenceBuilder constructorReference,
List arguments, List arguments,
Builder parent, Declaration parent,
int charOffset) { int charOffset) {
return new ConstructorMetadataBuilder( return new ConstructorMetadataBuilder(
constructorReference, arguments, parent, charOffset); constructorReference, arguments, parent, charOffset);
} }
factory MetadataBuilder.fromExpression( factory MetadataBuilder.fromExpression(
Object expression, String postfix, Builder parent, int charOffset) { Object expression, String postfix, Declaration parent, int charOffset) {
return new ExpressionMetadataBuilder( return new ExpressionMetadataBuilder(
expression, postfix, parent, charOffset); expression, postfix, parent, charOffset);
} }
@ -34,12 +33,9 @@ class ConstructorMetadataBuilder<T extends TypeBuilder>
final List arguments; final List arguments;
ConstructorMetadataBuilder( ConstructorMetadataBuilder(this.constructorReference, this.arguments,
this.constructorReference, this.arguments, Builder parent, int charOffset) Declaration parent, int charOffset)
: super(parent, charOffset); : super(parent, charOffset);
@override
String get fullNameForErrors => constructorReference.fullNameForErrors;
} }
/// Expression metadata (without arguments). /// Expression metadata (without arguments).
@ -54,11 +50,6 @@ class ExpressionMetadataBuilder<T extends TypeBuilder>
final String identifier; final String identifier;
ExpressionMetadataBuilder( ExpressionMetadataBuilder(
this.qualified, this.identifier, Builder parent, int charOffset) this.qualified, this.identifier, Declaration parent, int charOffset)
: super(parent, charOffset); : super(parent, charOffset);
@override
String get fullNameForErrors {
return identifier == null ? qualified : "$qualified.$identifier";
}
} }

View file

@ -14,16 +14,17 @@ import '../modifier.dart'
namedMixinApplicationMask, namedMixinApplicationMask,
staticMask; staticMask;
import 'builder.dart' show Builder; import 'builder.dart' show Declaration;
abstract class ModifierBuilder extends Declaration {
final Declaration parent;
abstract class ModifierBuilder extends Builder {
final int charOffset; final int charOffset;
final Uri fileUri; final Uri fileUri;
ModifierBuilder(Builder parent, this.charOffset, [Uri fileUri]) ModifierBuilder(this.parent, this.charOffset, [Uri fileUri])
: fileUri = fileUri ?? parent?.fileUri, : fileUri = fileUri ?? parent?.fileUri;
super(parent, charOffset, fileUri ?? parent?.fileUri);
int get modifiers; int get modifiers;

View file

@ -8,7 +8,7 @@ import '../fasta_codes.dart' show Message;
import 'builder.dart' import 'builder.dart'
show show
Builder, Declaration,
InvalidTypeBuilder, InvalidTypeBuilder,
PrefixBuilder, PrefixBuilder,
QualifiedName, QualifiedName,
@ -21,7 +21,7 @@ abstract class NamedTypeBuilder<T extends TypeBuilder, R> extends TypeBuilder {
List<T> arguments; List<T> arguments;
TypeDeclarationBuilder<T, R> builder; TypeDeclarationBuilder<T, R> declaration;
NamedTypeBuilder(this.name, this.arguments); NamedTypeBuilder(this.name, this.arguments);
@ -29,17 +29,17 @@ abstract class NamedTypeBuilder<T extends TypeBuilder, R> extends TypeBuilder {
[Message message]); [Message message]);
@override @override
void bind(TypeDeclarationBuilder builder) { void bind(TypeDeclarationBuilder declaration) {
this.builder = builder?.origin; this.declaration = declaration?.origin;
} }
@override @override
void resolveIn(Scope scope, int charOffset, Uri fileUri) { void resolveIn(Scope scope, int charOffset, Uri fileUri) {
if (builder != null) return; if (declaration != null) return;
final name = this.name; final name = this.name;
Builder member; Declaration member;
if (name is QualifiedName) { if (name is QualifiedName) {
var prefix = scope.lookup(name.prefix, charOffset, fileUri); Declaration prefix = scope.lookup(name.prefix, charOffset, fileUri);
if (prefix is PrefixBuilder) { if (prefix is PrefixBuilder) {
member = prefix.lookup(name.suffix, name.charOffset, fileUri); member = prefix.lookup(name.suffix, name.charOffset, fileUri);
} }
@ -47,10 +47,10 @@ abstract class NamedTypeBuilder<T extends TypeBuilder, R> extends TypeBuilder {
member = scope.lookup(name, charOffset, fileUri); member = scope.lookup(name, charOffset, fileUri);
} }
if (member is TypeDeclarationBuilder) { if (member is TypeDeclarationBuilder) {
builder = member.origin; declaration = member.origin;
return; return;
} }
builder = buildInvalidType(charOffset, fileUri); declaration = buildInvalidType(charOffset, fileUri);
} }
String get debugName => "NamedTypeBuilder"; String get debugName => "NamedTypeBuilder";

View file

@ -4,9 +4,9 @@
library fasta.prefix_builder; library fasta.prefix_builder;
import '../builder/builder.dart' show Builder, LibraryBuilder, Scope; import 'builder.dart' show Declaration, LibraryBuilder, Scope;
class PrefixBuilder extends Builder { class PrefixBuilder extends Declaration {
final String name; final String name;
final Scope exportScope = new Scope.top(); final Scope exportScope = new Scope.top();
@ -18,19 +18,20 @@ class PrefixBuilder extends Builder {
@override @override
final int charOffset; final int charOffset;
PrefixBuilder(this.name, this.deferred, this.parent, this.charOffset) PrefixBuilder(this.name, this.deferred, this.parent, this.charOffset);
: super(parent, charOffset, parent.fileUri);
Builder lookup(String name, int charOffset, Uri fileUri) { Uri get fileUri => parent.fileUri;
Declaration lookup(String name, int charOffset, Uri fileUri) {
return exportScope.lookup(name, charOffset, fileUri); return exportScope.lookup(name, charOffset, fileUri);
} }
void addToExportScope(String name, Builder member, int charOffset) { void addToExportScope(String name, Declaration member, int charOffset) {
Map<String, Builder> map = Map<String, Declaration> map =
member.isSetter ? exportScope.setters : exportScope.local; member.isSetter ? exportScope.setters : exportScope.local;
Builder existing = map[name]; Declaration existing = map[name];
if (existing != null) { if (existing != null) {
map[name] = parent.buildAmbiguousBuilder( map[name] = parent.computeAmbiguousDeclaration(
name, existing, member, charOffset, name, existing, member, charOffset,
isExport: true); isExport: true);
} else { } else {

View file

@ -11,7 +11,7 @@ import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind;
import 'builder.dart' import 'builder.dart'
show show
Builder, Declaration,
FormalParameterBuilder, FormalParameterBuilder,
LibraryBuilder, LibraryBuilder,
MemberBuilder, MemberBuilder,
@ -68,7 +68,7 @@ abstract class ProcedureBuilder<T extends TypeBuilder> extends MemberBuilder {
/// Language Specifiction, 4th ed, section 9.2. /// Language Specifiction, 4th ed, section 9.2.
Scope computeFormalParameterScope(Scope parent) { Scope computeFormalParameterScope(Scope parent) {
if (formals == null) return parent; if (formals == null) return parent;
Map<String, Builder> local = <String, Builder>{}; Map<String, Declaration> local = <String, Declaration>{};
for (FormalParameterBuilder formal in formals) { for (FormalParameterBuilder formal in formals) {
if (!isConstructor || !formal.hasThis) { if (!isConstructor || !formal.hasThis) {
local[formal.name] = formal; local[formal.name] = formal;
@ -95,7 +95,7 @@ abstract class ProcedureBuilder<T extends TypeBuilder> extends MemberBuilder {
// parameter initializer scope. // parameter initializer scope.
if (formals == null) return parent; if (formals == null) return parent;
Map<String, Builder> local = <String, Builder>{}; Map<String, Declaration> local = <String, Declaration>{};
for (FormalParameterBuilder formal in formals) { for (FormalParameterBuilder formal in formals) {
local[formal.name] = formal.forFormalParameterInitializerScope(); local[formal.name] = formal.forFormalParameterInitializerScope();
} }
@ -108,7 +108,7 @@ abstract class ProcedureBuilder<T extends TypeBuilder> extends MemberBuilder {
/// to support generic methods. /// to support generic methods.
Scope computeTypeParameterScope(Scope parent) { Scope computeTypeParameterScope(Scope parent) {
if (typeVariables == null) return parent; if (typeVariables == null) return parent;
Map<String, Builder> local = <String, Builder>{}; Map<String, Declaration> local = <String, Declaration>{};
for (TypeVariableBuilder variable in typeVariables) { for (TypeVariableBuilder variable in typeVariables) {
local[variable.name] = variable; local[variable.name] = variable;
} }

View file

@ -5,7 +5,12 @@
library fasta.type_declaration_builder; library fasta.type_declaration_builder;
import 'builder.dart' import 'builder.dart'
show Builder, LibraryBuilder, MetadataBuilder, ModifierBuilder, TypeBuilder; show
Declaration,
LibraryBuilder,
MetadataBuilder,
ModifierBuilder,
TypeBuilder;
abstract class TypeDeclarationBuilder<T extends TypeBuilder, R> abstract class TypeDeclarationBuilder<T extends TypeBuilder, R>
extends ModifierBuilder { extends ModifierBuilder {
@ -15,7 +20,7 @@ abstract class TypeDeclarationBuilder<T extends TypeBuilder, R>
final String name; final String name;
Builder parent; Declaration parent;
TypeDeclarationBuilder( TypeDeclarationBuilder(
this.metadata, this.modifiers, this.name, this.parent, int charOffset, this.metadata, this.modifiers, this.name, this.parent, int charOffset,

View file

@ -29,11 +29,11 @@ class UnresolvedType<T extends TypeBuilder> {
void checkType() { void checkType() {
TypeBuilder resolvedType = builder; TypeBuilder resolvedType = builder;
if (resolvedType is NamedTypeBuilder) { if (resolvedType is NamedTypeBuilder) {
TypeDeclarationBuilder declaration = resolvedType.builder; TypeDeclarationBuilder declaration = resolvedType.declaration;
if (declaration is ClassBuilder) { if (declaration is ClassBuilder) {
if (resolvedType.arguments != null && if (resolvedType.arguments != null &&
resolvedType.arguments.length != declaration.typeVariablesCount) { resolvedType.arguments.length != declaration.typeVariablesCount) {
resolvedType.builder = resolvedType.buildInvalidType( resolvedType.declaration = resolvedType.buildInvalidType(
charOffset, charOffset,
fileUri, fileUri,
templateTypeArgumentMismatch.withArguments( templateTypeArgumentMismatch.withArguments(
@ -42,7 +42,7 @@ class UnresolvedType<T extends TypeBuilder> {
} else if (declaration is FunctionTypeAliasBuilder) { } else if (declaration is FunctionTypeAliasBuilder) {
if (resolvedType.arguments != null && if (resolvedType.arguments != null &&
resolvedType.arguments.length != declaration.typeVariablesCount) { resolvedType.arguments.length != declaration.typeVariablesCount) {
resolvedType.builder = resolvedType.buildInvalidType( resolvedType.declaration = resolvedType.buildInvalidType(
charOffset, charOffset,
fileUri, fileUri,
templateTypeArgumentMismatch.withArguments( templateTypeArgumentMismatch.withArguments(
@ -56,7 +56,7 @@ class UnresolvedType<T extends TypeBuilder> {
void normalizeType() { void normalizeType() {
TypeBuilder resolvedType = builder; TypeBuilder resolvedType = builder;
if (resolvedType is NamedTypeBuilder) { if (resolvedType is NamedTypeBuilder) {
TypeDeclarationBuilder declaration = resolvedType.builder; TypeDeclarationBuilder declaration = resolvedType.declaration;
if (declaration is ClassBuilder) { if (declaration is ClassBuilder) {
if (resolvedType.arguments != null && if (resolvedType.arguments != null &&
resolvedType.arguments.length != declaration.typeVariablesCount) { resolvedType.arguments.length != declaration.typeVariablesCount) {

View file

@ -25,7 +25,7 @@ import '../problems.dart' show internalProblem, unhandled, unimplemented;
import '../kernel/kernel_builder.dart' import '../kernel/kernel_builder.dart'
show show
Builder, Declaration,
DynamicTypeBuilder, DynamicTypeBuilder,
InvalidTypeBuilder, InvalidTypeBuilder,
KernelInvalidTypeBuilder, KernelInvalidTypeBuilder,
@ -105,22 +105,23 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
} }
} }
Builder addBuilder(String name, Builder builder, int charOffset) { @override
Declaration addBuilder(String name, Declaration declaration, int charOffset) {
if (name == null || name.isEmpty) return null; if (name == null || name.isEmpty) return null;
bool isSetter = builder.isSetter; bool isSetter = declaration.isSetter;
if (isSetter) { if (isSetter) {
scopeBuilder.addSetter(name, builder); scopeBuilder.addSetter(name, declaration);
} else { } else {
scopeBuilder.addMember(name, builder); scopeBuilder.addMember(name, declaration);
} }
if (!name.startsWith("_")) { if (!name.startsWith("_")) {
if (isSetter) { if (isSetter) {
exportScopeBuilder.addSetter(name, builder); exportScopeBuilder.addSetter(name, declaration);
} else { } else {
exportScopeBuilder.addMember(name, builder); exportScopeBuilder.addMember(name, declaration);
} }
} }
return builder; return declaration;
} }
void addTypedef(Typedef typedef) { void addTypedef(Typedef typedef) {
@ -129,13 +130,14 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
} }
@override @override
void addToScope(String name, Builder member, int charOffset, bool isImport) { void addToScope(
String name, Declaration member, int charOffset, bool isImport) {
unimplemented("addToScope", charOffset, fileUri); unimplemented("addToScope", charOffset, fileUri);
} }
@override @override
Builder buildAmbiguousBuilder( Declaration computeAmbiguousDeclaration(
String name, Builder builder, Builder other, int charOffset, String name, Declaration builder, Declaration other, int charOffset,
{bool isExport: false, bool isImport: false}) { {bool isExport: false, bool isImport: false}) {
if (builder == other) return builder; if (builder == other) return builder;
if (builder is InvalidTypeBuilder) return builder; if (builder is InvalidTypeBuilder) return builder;
@ -154,17 +156,17 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
void finalizeExports() { void finalizeExports() {
unserializableExports?.forEach((String name, String message) { unserializableExports?.forEach((String name, String message) {
Builder builder; Declaration declaration;
switch (name) { switch (name) {
case "dynamic": case "dynamic":
case "void": case "void":
// TODO(ahe): It's likely that we shouldn't be exporting these types // TODO(ahe): It's likely that we shouldn't be exporting these types
// from dart:core, and this case can be removed. // from dart:core, and this case can be removed.
builder = loader.coreLibrary.exportScopeBuilder[name]; declaration = loader.coreLibrary.exportScopeBuilder[name];
break; break;
default: default:
builder = new KernelInvalidTypeBuilder( declaration = new KernelInvalidTypeBuilder(
name, name,
-1, -1,
null, null,
@ -172,7 +174,7 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
? null ? null
: templateUnspecified.withArguments(message)); : templateUnspecified.withArguments(message));
} }
exportScopeBuilder.addMember(name, builder); exportScopeBuilder.addMember(name, declaration);
}); });
for (var reference in library.additionalExports) { for (var reference in library.additionalExports) {
@ -203,22 +205,22 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
-1, -1,
fileUri); fileUri);
} }
Builder builder; Declaration declaration;
if (isSetter) { if (isSetter) {
builder = library.exportScope.setters[name]; declaration = library.exportScope.setters[name];
exportScopeBuilder.addSetter(name, builder); exportScopeBuilder.addSetter(name, declaration);
} else { } else {
builder = library.exportScope.local[name]; declaration = library.exportScope.local[name];
exportScopeBuilder.addMember(name, builder); exportScopeBuilder.addMember(name, declaration);
} }
if (builder == null) { if (declaration == null) {
internalProblem( internalProblem(
templateUnspecified.withArguments( templateUnspecified.withArguments(
"Exported element '$name' not found in '$libraryUri'."), "Exported element '$name' not found in '$libraryUri'."),
-1, -1,
fileUri); fileUri);
} }
assert(node == builder.target); assert(node == declaration.target);
} }
} }
} }

View file

@ -9,7 +9,7 @@ import 'package:kernel/ast.dart'
import '../kernel/kernel_builder.dart' import '../kernel/kernel_builder.dart'
show show
Builder, Declaration,
MemberBuilder, MemberBuilder,
isRedirectingGenerativeConstructorImplementation; isRedirectingGenerativeConstructorImplementation;
@ -23,7 +23,7 @@ class DillMemberBuilder extends MemberBuilder {
final Member member; final Member member;
DillMemberBuilder(Member member, Builder parent) DillMemberBuilder(Member member, Declaration parent)
: modifiers = computeModifiers(member), : modifiers = computeModifiers(member),
member = member, member = member,
super(parent, member.fileOffset); super(parent, member.fileOffset);

View file

@ -4,7 +4,7 @@
library fasta.export; library fasta.export;
import 'builder/builder.dart' show Builder, LibraryBuilder; import 'builder/builder.dart' show Declaration, LibraryBuilder;
import 'combinator.dart' show Combinator; import 'combinator.dart' show Combinator;
@ -23,7 +23,7 @@ class Export {
Uri get fileUri => exporter.fileUri; Uri get fileUri => exporter.fileUri;
bool addToExportScope(String name, Builder member) { bool addToExportScope(String name, Declaration member) {
if (combinators != null) { if (combinators != null) {
for (Combinator combinator in combinators) { for (Combinator combinator in combinators) {
if (combinator.isShow && !combinator.names.contains(name)) return false; if (combinator.isShow && !combinator.names.contains(name)) return false;

View file

@ -6,7 +6,7 @@ library fasta.import;
import 'package:kernel/ast.dart' show LibraryDependency; import 'package:kernel/ast.dart' show LibraryDependency;
import 'builder/builder.dart' show Builder, LibraryBuilder; import 'builder/builder.dart' show Declaration, LibraryBuilder;
import 'kernel/kernel_builder.dart' show toKernelCombinators; import 'kernel/kernel_builder.dart' show toKernelCombinators;
@ -16,8 +16,6 @@ import 'combinator.dart' show Combinator;
import 'configuration.dart' show Configuration; import 'configuration.dart' show Configuration;
typedef void AddToScope(String name, Builder member);
class Import { class Import {
/// The library that is importing [imported]; /// The library that is importing [imported];
final LibraryBuilder importer; final LibraryBuilder importer;
@ -60,17 +58,17 @@ class Import {
void finalizeImports(LibraryBuilder importer) { void finalizeImports(LibraryBuilder importer) {
if (nativeImportUri != null) return; if (nativeImportUri != null) return;
AddToScope add; void Function(String, Declaration) add;
if (prefixBuilder == null) { if (prefixBuilder == null) {
add = (String name, Builder member) { add = (String name, Declaration member) {
importer.addToScope(name, member, charOffset, true); importer.addToScope(name, member, charOffset, true);
}; };
} else { } else {
add = (String name, Builder member) { add = (String name, Declaration member) {
prefixBuilder.addToExportScope(name, member, charOffset); prefixBuilder.addToExportScope(name, member, charOffset);
}; };
} }
imported.exportScope.forEach((String name, Builder member) { imported.exportScope.forEach((String name, Declaration member) {
if (combinators != null) { if (combinators != null) {
for (Combinator combinator in combinators) { for (Combinator combinator in combinators) {
if (combinator.isShow && !combinator.names.contains(name)) return; if (combinator.isShow && !combinator.names.contains(name)) return;
@ -80,7 +78,8 @@ class Import {
add(name, member); add(name, member);
}); });
if (prefixBuilder != null) { if (prefixBuilder != null) {
Builder existing = importer.addBuilder(prefix, prefixBuilder, charOffset); Declaration existing =
importer.addBuilder(prefix, prefixBuilder, charOffset);
if (existing == prefixBuilder) { if (existing == prefixBuilder) {
importer.addToScope(prefix, prefixBuilder, prefixCharOffset, true); importer.addToScope(prefix, prefixBuilder, prefixCharOffset, true);
} }

View file

@ -321,9 +321,9 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
Scope outerSwitchScope = pop(); Scope outerSwitchScope = pop();
if (switchScope.unclaimedForwardDeclarations != null) { if (switchScope.unclaimedForwardDeclarations != null) {
switchScope.unclaimedForwardDeclarations switchScope.unclaimedForwardDeclarations
.forEach((String name, Builder builder) { .forEach((String name, Declaration declaration) {
if (outerSwitchScope == null) { if (outerSwitchScope == null) {
JumpTarget target = builder; JumpTarget target = declaration;
for (kernel.Statement statement in target.users) { for (kernel.Statement statement in target.users) {
statement.parent.replaceChild( statement.parent.replaceChild(
statement, statement,
@ -331,7 +331,7 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
fasta.templateLabelNotFound.withArguments(name))); fasta.templateLabelNotFound.withArguments(name)));
} }
} else { } else {
outerSwitchScope.forwardDeclareLabel(name, builder); outerSwitchScope.forwardDeclareLabel(name, declaration);
} }
}); });
} }
@ -360,7 +360,7 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
void declareVariable(Object variable, Scope scope) { void declareVariable(Object variable, Scope scope) {
String name = forest.getVariableDeclarationName(variable); String name = forest.getVariableDeclarationName(variable);
Builder existing = scope.local[name]; Declaration existing = scope.local[name];
if (existing != null) { if (existing != null) {
// This reports an error for duplicated declarations in the same scope: // This reports an error for duplicated declarations in the same scope:
// `{ var x; var x; }` // `{ var x; var x; }`
@ -1291,7 +1291,7 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
// objects directly. // objects directly.
var supertype = builder.supertype; var supertype = builder.supertype;
if (supertype is NamedTypeBuilder) { if (supertype is NamedTypeBuilder) {
var builder = supertype.builder; var builder = supertype.declaration;
if (builder is ClassBuilder) return builder; if (builder is ClassBuilder) return builder;
} }
return null; return null;
@ -1350,20 +1350,23 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
scopeLookup(Scope scope, String name, Token token, scopeLookup(Scope scope, String name, Token token,
{bool isQualified: false, PrefixBuilder prefix}) { {bool isQualified: false, PrefixBuilder prefix}) {
int charOffset = offsetForToken(token); int charOffset = offsetForToken(token);
Builder builder = scope.lookup(name, charOffset, uri); Declaration declaration = scope.lookup(name, charOffset, uri);
if (builder == null && prefix == null && (classBuilder?.isPatch ?? false)) { if (declaration == null &&
prefix == null &&
(classBuilder?.isPatch ?? false)) {
// The scope of a patched method includes the origin class. // The scope of a patched method includes the origin class.
builder = declaration =
classBuilder.origin.findStaticBuilder(name, charOffset, uri, library); classBuilder.origin.findStaticBuilder(name, charOffset, uri, library);
} }
if (builder != null && member.isField && builder.isInstanceMember) { if (declaration != null && member.isField && declaration.isInstanceMember) {
return new IncompleteErrorGenerator(this, token, return new IncompleteErrorGenerator(this, token,
fasta.templateThisAccessInFieldInitializer.withArguments(name)); fasta.templateThisAccessInFieldInitializer.withArguments(name));
} }
if (builder == null || (!isInstanceContext && builder.isInstanceMember)) { if (declaration == null ||
(!isInstanceContext && declaration.isInstanceMember)) {
Name n = new Name(name, library.library); Name n = new Name(name, library.library);
if (!isQualified && isInstanceContext) { if (!isQualified && isInstanceContext) {
assert(builder == null); assert(declaration == null);
if (constantContext != ConstantContext.none || member.isField) { if (constantContext != ConstantContext.none || member.isField) {
return new UnresolvedNameGenerator(this, token, n); return new UnresolvedNameGenerator(this, token, n);
} }
@ -1377,23 +1380,23 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
} else { } else {
return new UnresolvedNameGenerator(this, token, n); return new UnresolvedNameGenerator(this, token, n);
} }
} else if (builder.isTypeDeclaration) { } else if (declaration.isTypeDeclaration) {
if (constantContext != ConstantContext.none && if (constantContext != ConstantContext.none &&
builder.isTypeVariable && declaration.isTypeVariable &&
!member.isConstructor) { !member.isConstructor) {
deprecated_addCompileTimeError( deprecated_addCompileTimeError(
charOffset, "Not a constant expression."); charOffset, "Not a constant expression.");
} }
TypeUseGenerator<Expression, Statement, Arguments> generator = TypeUseGenerator<Expression, Statement, Arguments> generator =
new TypeUseGenerator<Expression, Statement, Arguments>( new TypeUseGenerator<Expression, Statement, Arguments>(
this, token, prefix, charOffset, builder, name); this, token, prefix, charOffset, declaration, name);
return (prefix?.deferred == true) return (prefix?.deferred == true)
? new DeferredAccessGenerator<Expression, Statement, Arguments>( ? new DeferredAccessGenerator<Expression, Statement, Arguments>(
this, token, prefix, generator) this, token, prefix, generator)
: generator; : generator;
} else if (builder.isLocal) { } else if (declaration.isLocal) {
if (constantContext != ConstantContext.none && if (constantContext != ConstantContext.none &&
!builder.isConst && !declaration.isConst &&
!member.isConstructor) { !member.isConstructor) {
deprecated_addCompileTimeError( deprecated_addCompileTimeError(
charOffset, "Not a constant expression."); charOffset, "Not a constant expression.");
@ -1402,21 +1405,21 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
// VariableDeclaration being final. See // VariableDeclaration being final. See
// [ProcedureBuilder.computeFormalParameterInitializerScope]. If that // [ProcedureBuilder.computeFormalParameterInitializerScope]. If that
// wasn't the case, we could always use [VariableUseGenerator]. // wasn't the case, we could always use [VariableUseGenerator].
if (builder.isFinal) { if (declaration.isFinal) {
var fact = var fact = typePromoter.getFactForAccess(
typePromoter.getFactForAccess(builder.target, functionNestingLevel); declaration.target, functionNestingLevel);
var scope = typePromoter.currentScope; var scope = typePromoter.currentScope;
return new ReadOnlyAccessGenerator<Expression, Statement, Arguments>( return new ReadOnlyAccessGenerator<Expression, Statement, Arguments>(
this, this,
token, token,
toExpression(new ShadowVariableGet(builder.target, fact, scope) toExpression(new ShadowVariableGet(declaration.target, fact, scope)
..fileOffset = charOffset), ..fileOffset = charOffset),
name); name);
} else { } else {
return new VariableUseGenerator<Expression, Statement, Arguments>( return new VariableUseGenerator<Expression, Statement, Arguments>(
this, token, builder.target); this, token, declaration.target);
} }
} else if (builder.isInstanceMember) { } else if (declaration.isInstanceMember) {
if (constantContext != ConstantContext.none && if (constantContext != ConstantContext.none &&
!inInitializer && !inInitializer &&
// TODO(ahe): This is a hack because Fasta sets up the scope // TODO(ahe): This is a hack because Fasta sets up the scope
@ -1430,26 +1433,26 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
Name n = new Name(name, library.library); Name n = new Name(name, library.library);
Member getter; Member getter;
Member setter; Member setter;
if (builder is AccessErrorBuilder) { if (declaration is AccessErrorBuilder) {
setter = builder.parent.target; setter = declaration.parent.target;
getter = lookupInstanceMember(n); getter = lookupInstanceMember(n);
} else { } else {
getter = builder.target; getter = declaration.target;
setter = lookupInstanceMember(n, isSetter: true); setter = lookupInstanceMember(n, isSetter: true);
} }
return new ThisPropertyAccessGenerator<Expression, Statement, Arguments>( return new ThisPropertyAccessGenerator<Expression, Statement, Arguments>(
this, token, n, getter, setter); this, token, n, getter, setter);
} else if (builder.isRegularMethod) { } else if (declaration.isRegularMethod) {
assert(builder.isStatic || builder.isTopLevel); assert(declaration.isStatic || declaration.isTopLevel);
StaticAccessGenerator<Expression, Statement, Arguments> generator = StaticAccessGenerator<Expression, Statement, Arguments> generator =
new StaticAccessGenerator<Expression, Statement, Arguments>( new StaticAccessGenerator<Expression, Statement, Arguments>(
this, token, builder.target, null); this, token, declaration.target, null);
return (prefix?.deferred == true) return (prefix?.deferred == true)
? new DeferredAccessGenerator<Expression, Statement, Arguments>( ? new DeferredAccessGenerator<Expression, Statement, Arguments>(
this, token, prefix, generator) this, token, prefix, generator)
: generator; : generator;
} else if (builder is PrefixBuilder) { } else if (declaration is PrefixBuilder) {
if (constantContext != ConstantContext.none && builder.deferred) { if (constantContext != ConstantContext.none && declaration.deferred) {
deprecated_addCompileTimeError( deprecated_addCompileTimeError(
charOffset, charOffset,
"'$name' can't be used in a constant expression because it's " "'$name' can't be used in a constant expression because it's "
@ -1458,23 +1461,24 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
"You might try moving the constant to the deferred library, " "You might try moving the constant to the deferred library, "
"or removing 'deferred' from the import."); "or removing 'deferred' from the import.");
} }
return builder; return declaration;
} else if (builder is LoadLibraryBuilder) { } else if (declaration is LoadLibraryBuilder) {
return new LoadLibraryGenerator<Expression, Statement, Arguments>( return new LoadLibraryGenerator<Expression, Statement, Arguments>(
this, token, builder); this, token, declaration);
} else { } else {
if (builder.hasProblem && builder is! AccessErrorBuilder) return builder; if (declaration.hasProblem && declaration is! AccessErrorBuilder)
Builder setter; return declaration;
if (builder.isSetter) { Declaration setter;
setter = builder; if (declaration.isSetter) {
} else if (builder.isGetter) { setter = declaration;
} else if (declaration.isGetter) {
setter = scope.lookupSetter(name, charOffset, uri); setter = scope.lookupSetter(name, charOffset, uri);
} else if (builder.isField && !builder.isFinal) { } else if (declaration.isField && !declaration.isFinal) {
setter = builder; setter = declaration;
} }
StaticAccessGenerator<Expression, Statement, Arguments> generator = StaticAccessGenerator<Expression, Statement, Arguments> generator =
new StaticAccessGenerator<Expression, Statement, new StaticAccessGenerator<Expression, Statement,
Arguments>.fromBuilder(this, builder, token, setter); Arguments>.fromBuilder(this, declaration, token, setter);
if (constantContext != ConstantContext.none) { if (constantContext != ConstantContext.none) {
Member readTarget = generator.readTarget; Member readTarget = generator.readTarget;
if (!(readTarget is Field && readTarget.isConst || if (!(readTarget is Field && readTarget.isConst ||
@ -2846,7 +2850,8 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
return deprecated_buildCompileTimeError( return deprecated_buildCompileTimeError(
"An enum class can't be instantiated.", nameToken.charOffset); "An enum class can't be instantiated.", nameToken.charOffset);
} }
Builder b = type.findConstructorOrFactory(name, charOffset, uri, library); Declaration b =
type.findConstructorOrFactory(name, charOffset, uri, library);
Member target; Member target;
Member initialTarget; Member initialTarget;
List<DartType> targetTypeArguments; List<DartType> targetTypeArguments;
@ -3820,7 +3825,8 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
[int charOffset = -1]) { [int charOffset = -1]) {
addProblemErrorIfConst(message, charOffset, className.length); addProblemErrorIfConst(message, charOffset, className.length);
// TODO(ahe): The following doesn't make sense to Analyzer AST. // TODO(ahe): The following doesn't make sense to Analyzer AST.
Builder constructor = library.loader.getAbstractClassInstantiationError(); Declaration constructor =
library.loader.getAbstractClassInstantiationError();
return toExpression(new Throw(toKernelExpression(buildStaticInvocation( return toExpression(new Throw(toKernelExpression(buildStaticInvocation(
constructor.target, constructor.target,
forest.arguments(<Expression>[ forest.arguments(<Expression>[
@ -3872,7 +3878,7 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
@override @override
Initializer buildFieldInitializer( Initializer buildFieldInitializer(
bool isSynthetic, String name, int offset, Expression expression) { bool isSynthetic, String name, int offset, Expression expression) {
Builder builder = Declaration builder =
classBuilder.scope.local[name] ?? classBuilder.origin.scope.local[name]; classBuilder.scope.local[name] ?? classBuilder.origin.scope.local[name];
if (builder is KernelFieldBuilder && builder.isInstanceMember) { if (builder is KernelFieldBuilder && builder.isInstanceMember) {
initializedFields ??= <String, int>{}; initializedFields ??= <String, int>{};
@ -3894,7 +3900,7 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
.withArguments(name) .withArguments(name)
.withLocation(uri, builder.charOffset, noLength) .withLocation(uri, builder.charOffset, noLength)
]); ]);
Builder constructor = Declaration constructor =
library.loader.getDuplicatedFieldInitializerError(); library.loader.getDuplicatedFieldInitializerError();
return buildInvalidInitializer( return buildInvalidInitializer(
toExpression(new Throw(toKernelExpression(buildStaticInvocation( toExpression(new Throw(toKernelExpression(buildStaticInvocation(
@ -4218,16 +4224,24 @@ class InitializedIdentifier extends Identifier {
String toString() => "initialized-identifier($name, $initializer)"; String toString() => "initialized-identifier($name, $initializer)";
} }
class JumpTarget<Statement> extends Builder { class JumpTarget<Statement> extends Declaration {
final List<Statement> users = <Statement>[]; final List<Statement> users = <Statement>[];
final JumpTargetKind kind; final JumpTargetKind kind;
final int functionNestingLevel; final int functionNestingLevel;
JumpTarget(this.kind, this.functionNestingLevel, MemberBuilder member, @override
int charOffset) final MemberBuilder parent;
: super(member, charOffset, member.fileUri);
@override
final int charOffset;
JumpTarget(
this.kind, this.functionNestingLevel, this.parent, this.charOffset);
@override
Uri get fileUri => parent.fileUri;
bool get isBreakTarget => kind == JumpTargetKind.Break; bool get isBreakTarget => kind == JumpTargetKind.Break;
@ -4283,22 +4297,31 @@ class JumpTarget<Statement> extends Builder {
String get fullNameForErrors => "<jump-target>"; String get fullNameForErrors => "<jump-target>";
} }
class LabelTarget<Statement> extends Builder implements JumpTarget<Statement> { class LabelTarget<Statement> extends Declaration
implements JumpTarget<Statement> {
final List<Object> labels; final List<Object> labels;
@override
final MemberBuilder parent;
final JumpTarget breakTarget; final JumpTarget breakTarget;
final JumpTarget continueTarget; final JumpTarget continueTarget;
final int functionNestingLevel; final int functionNestingLevel;
LabelTarget(this.labels, MemberBuilder member, this.functionNestingLevel, @override
int charOffset) final int charOffset;
LabelTarget(
this.labels, this.parent, this.functionNestingLevel, this.charOffset)
: breakTarget = new JumpTarget<Statement>( : breakTarget = new JumpTarget<Statement>(
JumpTargetKind.Break, functionNestingLevel, member, charOffset), JumpTargetKind.Break, functionNestingLevel, parent, charOffset),
continueTarget = new JumpTarget<Statement>( continueTarget = new JumpTarget<Statement>(
JumpTargetKind.Continue, functionNestingLevel, member, charOffset), JumpTargetKind.Continue, functionNestingLevel, parent, charOffset);
super(member, charOffset, member.fileUri);
@override
Uri get fileUri => parent.fileUri;
bool get hasUsers => breakTarget.hasUsers || continueTarget.hasUsers; bool get hasUsers => breakTarget.hasUsers || continueTarget.hasUsers;
@ -4402,18 +4425,18 @@ class FormalParameters<Expression, Statement, Arguments> {
typeParameters: typeParameters); typeParameters: typeParameters);
} }
Scope computeFormalParameterScope(Scope parent, Builder builder, Scope computeFormalParameterScope(Scope parent, Declaration declaration,
ExpressionGeneratorHelper<dynamic, dynamic, Arguments> helper) { ExpressionGeneratorHelper<dynamic, dynamic, Arguments> helper) {
if (required.length == 0 && optional == null) return parent; if (required.length == 0 && optional == null) return parent;
Map<String, Builder> local = <String, Builder>{}; Map<String, Declaration> local = <String, Declaration>{};
for (VariableDeclaration parameter in required) { for (VariableDeclaration parameter in required) {
if (local[parameter.name] != null) { if (local[parameter.name] != null) {
helper.deprecated_addCompileTimeError( helper.deprecated_addCompileTimeError(
parameter.fileOffset, "Duplicated name."); parameter.fileOffset, "Duplicated name.");
} }
local[parameter.name] = local[parameter.name] = new KernelVariableBuilder(
new KernelVariableBuilder(parameter, builder, builder.fileUri); parameter, declaration, declaration.fileUri);
} }
if (optional != null) { if (optional != null) {
for (VariableDeclaration parameter in optional.formals) { for (VariableDeclaration parameter in optional.formals) {
@ -4421,8 +4444,8 @@ class FormalParameters<Expression, Statement, Arguments> {
helper.deprecated_addCompileTimeError( helper.deprecated_addCompileTimeError(
parameter.fileOffset, "Duplicated name."); parameter.fileOffset, "Duplicated name.");
} }
local[parameter.name] = local[parameter.name] = new KernelVariableBuilder(
new KernelVariableBuilder(parameter, builder, builder.fileUri); parameter, declaration, declaration.fileUri);
} }
} }
return new Scope(local, null, parent, "formals", isModifiable: false); return new Scope(local, null, parent, "formals", isModifiable: false);
@ -4455,7 +4478,7 @@ String debugName(String className, String name, [String prefix]) {
String getNodeName(Object node) { String getNodeName(Object node) {
if (node is Identifier) { if (node is Identifier) {
return node.name; return node.name;
} else if (node is Builder) { } else if (node is Declaration) {
return node.fullNameForErrors; return node.fullNameForErrors;
} else if (node is ThisAccessGenerator) { } else if (node is ThisAccessGenerator) {
return node.isSuper ? "super" : "this"; return node.isSuper ? "super" : "this";

View file

@ -48,8 +48,8 @@ import 'kernel_ast_api.dart'
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
AccessErrorBuilder, AccessErrorBuilder,
Builder,
BuiltinTypeBuilder, BuiltinTypeBuilder,
Declaration,
FunctionTypeAliasBuilder, FunctionTypeAliasBuilder,
KernelClassBuilder, KernelClassBuilder,
KernelFunctionTypeAliasBuilder, KernelFunctionTypeAliasBuilder,
@ -455,24 +455,24 @@ abstract class StaticAccessGenerator<Expression, Statement, Arguments>
factory StaticAccessGenerator.fromBuilder( factory StaticAccessGenerator.fromBuilder(
ExpressionGeneratorHelper<Expression, Statement, Arguments> helper, ExpressionGeneratorHelper<Expression, Statement, Arguments> helper,
Builder builder, Declaration declaration,
Token token, Token token,
Builder builderSetter) { Declaration builderSetter) {
if (builder is AccessErrorBuilder) { if (declaration is AccessErrorBuilder) {
AccessErrorBuilder error = builder; AccessErrorBuilder error = declaration;
builder = error.builder; declaration = error.builder;
// We should only see an access error here if we've looked up a setter // We should only see an access error here if we've looked up a setter
// when not explicitly looking for a setter. // when not explicitly looking for a setter.
assert(builder.isSetter); assert(declaration.isSetter);
} else if (builder.target == null) { } else if (declaration.target == null) {
return unhandled( return unhandled(
"${builder.runtimeType}", "${declaration.runtimeType}",
"StaticAccessGenerator.fromBuilder", "StaticAccessGenerator.fromBuilder",
offsetForToken(token), offsetForToken(token),
helper.uri); helper.uri);
} }
Member getter = builder.target.hasGetter ? builder.target : null; Member getter = declaration.target.hasGetter ? declaration.target : null;
Member setter = builder.target.hasSetter ? builder.target : null; Member setter = declaration.target.hasSetter ? declaration.target : null;
if (setter == null) { if (setter == null) {
if (builderSetter?.target?.hasSetter ?? false) { if (builderSetter?.target?.hasSetter ?? false) {
setter = builderSetter.target; setter = builderSetter.target;
@ -720,7 +720,8 @@ abstract class ErroneousExpressionGenerator<Expression, Statement, Arguments>
@override @override
buildPropertyAccess( buildPropertyAccess(
IncompleteSendGenerator send, int operatorOffset, bool isNullAware) { IncompleteSendGenerator send, int operatorOffset, bool isNullAware) {
return this; return send.withReceiver(buildSimpleRead(), operatorOffset,
isNullAware: isNullAware);
} }
@override @override

View file

@ -73,9 +73,9 @@ import '../type_inference/type_schema.dart' show UnknownType;
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
ConstructorReferenceBuilder, ConstructorReferenceBuilder,
Declaration,
KernelLibraryBuilder, KernelLibraryBuilder,
KernelProcedureBuilder, KernelProcedureBuilder,
KernelRedirectingFactoryBuilder, KernelRedirectingFactoryBuilder,
@ -199,20 +199,20 @@ abstract class KernelClassBuilder
// Copy keys to avoid concurrent modification error. // Copy keys to avoid concurrent modification error.
List<String> names = constructors.keys.toList(); List<String> names = constructors.keys.toList();
for (String name in names) { for (String name in names) {
Builder builder = constructors[name]; Declaration declaration = constructors[name];
if (builder.parent != this) { if (declaration.parent != this) {
unexpected( unexpected(
"$fileUri", "${builder.parent.fileUri}", charOffset, fileUri); "$fileUri", "${declaration.parent.fileUri}", charOffset, fileUri);
} }
if (builder is KernelRedirectingFactoryBuilder) { if (declaration is KernelRedirectingFactoryBuilder) {
// Compute the immediate redirection target, not the effective. // Compute the immediate redirection target, not the effective.
ConstructorReferenceBuilder redirectionTarget = ConstructorReferenceBuilder redirectionTarget =
builder.redirectionTarget; declaration.redirectionTarget;
if (redirectionTarget != null) { if (redirectionTarget != null) {
Builder targetBuilder = redirectionTarget.target; Declaration targetBuilder = redirectionTarget.target;
addRedirectingConstructor(builder, library); addRedirectingConstructor(declaration, library);
if (targetBuilder is ProcedureBuilder) { if (targetBuilder is ProcedureBuilder) {
List<DartType> typeArguments = builder.typeArguments; List<DartType> typeArguments = declaration.typeArguments;
if (typeArguments == null) { if (typeArguments == null) {
// TODO(32049) If type arguments aren't specified, they should // TODO(32049) If type arguments aren't specified, they should
// be inferred. Currently, the inference is not performed. // be inferred. Currently, the inference is not performed.
@ -222,10 +222,10 @@ abstract class KernelClassBuilder
const DynamicType(), const DynamicType(),
growable: true); growable: true);
} }
builder.setRedirectingFactoryBody( declaration.setRedirectingFactoryBody(
targetBuilder.target, typeArguments); targetBuilder.target, typeArguments);
} else if (targetBuilder is DillMemberBuilder) { } else if (targetBuilder is DillMemberBuilder) {
List<DartType> typeArguments = builder.typeArguments; List<DartType> typeArguments = declaration.typeArguments;
if (typeArguments == null) { if (typeArguments == null) {
// TODO(32049) If type arguments aren't specified, they should // TODO(32049) If type arguments aren't specified, they should
// be inferred. Currently, the inference is not performed. // be inferred. Currently, the inference is not performed.
@ -235,19 +235,19 @@ abstract class KernelClassBuilder
const DynamicType(), const DynamicType(),
growable: true); growable: true);
} }
builder.setRedirectingFactoryBody( declaration.setRedirectingFactoryBody(
targetBuilder.member, typeArguments); targetBuilder.member, typeArguments);
} else { } else {
var message = templateRedirectionTargetNotFound var message = templateRedirectionTargetNotFound
.withArguments(redirectionTarget.fullNameForErrors); .withArguments(redirectionTarget.fullNameForErrors);
if (builder.isConst) { if (declaration.isConst) {
addCompileTimeError(message, builder.charOffset, noLength); addCompileTimeError(message, declaration.charOffset, noLength);
} else { } else {
addProblem(message, builder.charOffset, noLength); addProblem(message, declaration.charOffset, noLength);
} }
// CoreTypes aren't computed yet, and this is the outline // CoreTypes aren't computed yet, and this is the outline
// phase. So we can't and shouldn't create a method body. // phase. So we can't and shouldn't create a method body.
builder.body = new RedirectingFactoryBody.unresolved( declaration.body = new RedirectingFactoryBody.unresolved(
redirectionTarget.fullNameForErrors); redirectionTarget.fullNameForErrors);
} }
} }
@ -830,24 +830,24 @@ abstract class KernelClassBuilder
} }
@override @override
void applyPatch(Builder patch) { void applyPatch(Declaration patch) {
if (patch is KernelClassBuilder) { if (patch is KernelClassBuilder) {
patch.actualOrigin = this; patch.actualOrigin = this;
// TODO(ahe): Complain if `patch.supertype` isn't null. // TODO(ahe): Complain if `patch.supertype` isn't null.
scope.local.forEach((String name, Builder member) { scope.local.forEach((String name, Declaration member) {
Builder memberPatch = patch.scope.local[name]; Declaration memberPatch = patch.scope.local[name];
if (memberPatch != null) { if (memberPatch != null) {
member.applyPatch(memberPatch); member.applyPatch(memberPatch);
} }
}); });
scope.setters.forEach((String name, Builder member) { scope.setters.forEach((String name, Declaration member) {
Builder memberPatch = patch.scope.setters[name]; Declaration memberPatch = patch.scope.setters[name];
if (memberPatch != null) { if (memberPatch != null) {
member.applyPatch(memberPatch); member.applyPatch(memberPatch);
} }
}); });
constructors.local.forEach((String name, Builder member) { constructors.local.forEach((String name, Declaration member) {
Builder memberPatch = patch.constructors.local[name]; Declaration memberPatch = patch.constructors.local[name];
if (memberPatch != null) { if (memberPatch != null) {
member.applyPatch(memberPatch); member.applyPatch(memberPatch);
} }
@ -876,29 +876,29 @@ abstract class KernelClassBuilder
} }
@override @override
Builder findStaticBuilder( Declaration findStaticBuilder(
String name, int charOffset, Uri fileUri, LibraryBuilder accessingLibrary, String name, int charOffset, Uri fileUri, LibraryBuilder accessingLibrary,
{bool isSetter: false}) { {bool isSetter: false}) {
Builder builder = super.findStaticBuilder( Declaration declaration = super.findStaticBuilder(
name, charOffset, fileUri, accessingLibrary, name, charOffset, fileUri, accessingLibrary,
isSetter: isSetter); isSetter: isSetter);
if (builder == null && isPatch) { if (declaration == null && isPatch) {
return origin.findStaticBuilder( return origin.findStaticBuilder(
name, charOffset, fileUri, accessingLibrary, name, charOffset, fileUri, accessingLibrary,
isSetter: isSetter); isSetter: isSetter);
} }
return builder; return declaration;
} }
@override @override
Builder findConstructorOrFactory( Declaration findConstructorOrFactory(
String name, int charOffset, Uri uri, LibraryBuilder accessingLibrary) { String name, int charOffset, Uri uri, LibraryBuilder accessingLibrary) {
Builder builder = Declaration declaration =
super.findConstructorOrFactory(name, charOffset, uri, accessingLibrary); super.findConstructorOrFactory(name, charOffset, uri, accessingLibrary);
if (builder == null && isPatch) { if (declaration == null && isPatch) {
return origin.findConstructorOrFactory( return origin.findConstructorOrFactory(
name, charOffset, uri, accessingLibrary); name, charOffset, uri, accessingLibrary);
} }
return builder; return declaration;
} }
} }

View file

@ -42,7 +42,7 @@ import '../source/source_class_builder.dart' show SourceClassBuilder;
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
Builder, Declaration,
EnumBuilder, EnumBuilder,
FormalParameterBuilder, FormalParameterBuilder,
KernelClassBuilder, KernelClassBuilder,
@ -266,7 +266,7 @@ class KernelEnumBuilder extends SourceClassBuilder
new FieldInitializer(nameField, new FieldInitializer(nameField,
new VariableGet(constructor.function.positionalParameters[1])) new VariableGet(constructor.function.positionalParameters[1]))
..parent = constructor); ..parent = constructor);
KernelClassBuilder objectClass = objectType.builder; KernelClassBuilder objectClass = objectType.declaration;
MemberBuilder superConstructor = objectClass.findConstructorOrFactory( MemberBuilder superConstructor = objectClass.findConstructorOrFactory(
"", charOffset, fileUri, libraryBuilder); "", charOffset, fileUri, libraryBuilder);
if (superConstructor == null || !superConstructor.isConstructor) { if (superConstructor == null || !superConstructor.isConstructor) {
@ -298,7 +298,7 @@ class KernelEnumBuilder extends SourceClassBuilder
} }
@override @override
Builder findConstructorOrFactory( Declaration findConstructorOrFactory(
String name, int charOffset, Uri uri, LibraryBuilder library) { String name, int charOffset, Uri uri, LibraryBuilder library) {
return null; return null;
} }

View file

@ -110,7 +110,7 @@ import 'kernel_ast_api.dart'
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
Builder, Declaration,
KernelClassBuilder, KernelClassBuilder,
KernelInvalidTypeBuilder, KernelInvalidTypeBuilder,
LoadLibraryBuilder, LoadLibraryBuilder,
@ -1304,12 +1304,12 @@ class KernelTypeUseGenerator extends KernelReadOnlyAccessGenerator
if (declaration is KernelClassBuilder) { if (declaration is KernelClassBuilder) {
KernelClassBuilder declaration = this.declaration; KernelClassBuilder declaration = this.declaration;
Builder builder = declaration.findStaticBuilder( Declaration member = declaration.findStaticBuilder(
name.name, offsetForToken(token), uri, helper.library); name.name, offsetForToken(token), uri, helper.library);
Generator generator; Generator generator;
if (builder == null) { if (member == null) {
// If we find a setter, [builder] is an [AccessErrorBuilder], not null. // If we find a setter, [member] is an [AccessErrorBuilder], not null.
if (send is IncompletePropertyAccessGenerator) { if (send is IncompletePropertyAccessGenerator) {
generator = new UnresolvedNameGenerator(helper, send.token, name); generator = new UnresolvedNameGenerator(helper, send.token, name);
} else { } else {
@ -1317,18 +1317,18 @@ class KernelTypeUseGenerator extends KernelReadOnlyAccessGenerator
arguments, name.name, null, token.charOffset, Constness.implicit); arguments, name.name, null, token.charOffset, Constness.implicit);
} }
} else { } else {
Builder setter; Declaration setter;
if (builder.isSetter) { if (member.isSetter) {
setter = builder; setter = member;
} else if (builder.isGetter) { } else if (member.isGetter) {
setter = declaration.findStaticBuilder( setter = declaration.findStaticBuilder(
name.name, offsetForToken(token), uri, helper.library, name.name, offsetForToken(token), uri, helper.library,
isSetter: true); isSetter: true);
} else if (builder.isField && !builder.isFinal) { } else if (member.isField && !member.isFinal) {
setter = builder; setter = member;
} }
generator = new StaticAccessGenerator<Expression, Statement, generator = new StaticAccessGenerator<Expression, Statement,
Arguments>.fromBuilder(helper, builder, send.token, setter); Arguments>.fromBuilder(helper, member, send.token, setter);
} }
return arguments == null return arguments == null

View file

@ -25,7 +25,7 @@ import '../source/source_library_builder.dart' show SourceLibraryBuilder;
import 'kernel_body_builder.dart' show KernelBodyBuilder; import 'kernel_body_builder.dart' show KernelBodyBuilder;
import 'kernel_builder.dart' import 'kernel_builder.dart'
show Builder, FieldBuilder, KernelTypeBuilder, MetadataBuilder; show Declaration, FieldBuilder, KernelTypeBuilder, MetadataBuilder;
import 'kernel_shadow_ast.dart' show ShadowField; import 'kernel_shadow_ast.dart' show ShadowField;
@ -41,7 +41,7 @@ class KernelFieldBuilder extends FieldBuilder<Expression> {
this.type, this.type,
String name, String name,
int modifiers, int modifiers,
Builder compilationUnit, Declaration compilationUnit,
int charOffset, int charOffset,
this.initializerTokenForInference, this.initializerTokenForInference,
this.hasInitializer) this.hasInitializer)

View file

@ -49,10 +49,10 @@ import '../source/source_library_builder.dart'
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
AccessErrorBuilder, AccessErrorBuilder,
Builder,
BuiltinTypeBuilder, BuiltinTypeBuilder,
ClassBuilder, ClassBuilder,
ConstructorReferenceBuilder, ConstructorReferenceBuilder,
Declaration,
DynamicTypeBuilder, DynamicTypeBuilder,
FormalParameterBuilder, FormalParameterBuilder,
InvalidTypeBuilder, InvalidTypeBuilder,
@ -233,7 +233,7 @@ class KernelLibraryBuilder
} }
Map<String, TypeVariableBuilder> checkTypeVariables( Map<String, TypeVariableBuilder> checkTypeVariables(
List<TypeVariableBuilder> typeVariables, Builder owner) { List<TypeVariableBuilder> typeVariables, Declaration owner) {
if (typeVariables?.isEmpty ?? true) return null; if (typeVariables?.isEmpty ?? true) return null;
Map<String, TypeVariableBuilder> typeVariablesByName = Map<String, TypeVariableBuilder> typeVariablesByName =
<String, TypeVariableBuilder>{}; <String, TypeVariableBuilder>{};
@ -479,7 +479,7 @@ class KernelLibraryBuilder
typeVariables: typeVariables, typeVariables: typeVariables,
modifiers: modifiers, modifiers: modifiers,
interfaces: interfaces); interfaces: interfaces);
checkTypeVariables(typeVariables, supertype.builder); checkTypeVariables(typeVariables, supertype.declaration);
} }
@override @override
@ -727,34 +727,34 @@ class KernelLibraryBuilder
} }
@override @override
void buildBuilder(Builder builder, LibraryBuilder coreLibrary) { void buildBuilder(Declaration declaration, LibraryBuilder coreLibrary) {
Class cls; Class cls;
Member member; Member member;
Typedef typedef; Typedef typedef;
if (builder is SourceClassBuilder) { if (declaration is SourceClassBuilder) {
cls = builder.build(this, coreLibrary); cls = declaration.build(this, coreLibrary);
} else if (builder is KernelFieldBuilder) { } else if (declaration is KernelFieldBuilder) {
member = builder.build(this)..isStatic = true; member = declaration.build(this)..isStatic = true;
} else if (builder is KernelProcedureBuilder) { } else if (declaration is KernelProcedureBuilder) {
member = builder.build(this)..isStatic = true; member = declaration.build(this)..isStatic = true;
} else if (builder is KernelFunctionTypeAliasBuilder) { } else if (declaration is KernelFunctionTypeAliasBuilder) {
typedef = builder.build(this); typedef = declaration.build(this);
} else if (builder is KernelEnumBuilder) { } else if (declaration is KernelEnumBuilder) {
cls = builder.build(this, coreLibrary); cls = declaration.build(this, coreLibrary);
} else if (builder is PrefixBuilder) { } else if (declaration is PrefixBuilder) {
// Ignored. Kernel doesn't represent prefixes. // Ignored. Kernel doesn't represent prefixes.
return; return;
} else if (builder is BuiltinTypeBuilder) { } else if (declaration is BuiltinTypeBuilder) {
// Nothing needed. // Nothing needed.
return; return;
} else { } else {
unhandled("${builder.runtimeType}", "buildBuilder", builder.charOffset, unhandled("${declaration.runtimeType}", "buildBuilder",
builder.fileUri); declaration.charOffset, declaration.fileUri);
return; return;
} }
if (builder.isPatch) { if (declaration.isPatch) {
// The kernel node of a patch is shared with the origin builder. We have // The kernel node of a patch is shared with the origin declaration. We
// two builders: the origin, and the patch, but only one kernel node // have two builders: the origin, and the patch, but only one kernel node
// (which corresponds to the final output). Consequently, the node // (which corresponds to the final output). Consequently, the node
// shouldn't be added to its apparent kernel parent as this would create // shouldn't be added to its apparent kernel parent as this would create
// a duplicate entry in the parent's list of children/members. // a duplicate entry in the parent's list of children/members.
@ -770,7 +770,7 @@ class KernelLibraryBuilder
} }
void addNativeDependency(Uri nativeImportUri) { void addNativeDependency(Uri nativeImportUri) {
Builder constructor = loader.getNativeAnnotation(); Declaration constructor = loader.getNativeAnnotation();
Arguments arguments = Arguments arguments =
new Arguments(<Expression>[new StringLiteral("$nativeImportUri")]); new Arguments(<Expression>[new StringLiteral("$nativeImportUri")]);
Expression annotation; Expression annotation;
@ -865,16 +865,16 @@ class KernelLibraryBuilder
} }
@override @override
Builder buildAmbiguousBuilder( Declaration computeAmbiguousDeclaration(
String name, Builder builder, Builder other, int charOffset, String name, Declaration declaration, Declaration other, int charOffset,
{bool isExport: false, bool isImport: false}) { {bool isExport: false, bool isImport: false}) {
// TODO(ahe): Can I move this to Scope or Prefix? // TODO(ahe): Can I move this to Scope or Prefix?
if (builder == other) return builder; if (declaration == other) return declaration;
if (builder is InvalidTypeBuilder) return builder; if (declaration is InvalidTypeBuilder) return declaration;
if (other is InvalidTypeBuilder) return other; if (other is InvalidTypeBuilder) return other;
if (builder is AccessErrorBuilder) { if (declaration is AccessErrorBuilder) {
AccessErrorBuilder error = builder; AccessErrorBuilder error = declaration;
builder = error.builder; declaration = error.builder;
} }
if (other is AccessErrorBuilder) { if (other is AccessErrorBuilder) {
AccessErrorBuilder error = other; AccessErrorBuilder error = other;
@ -882,28 +882,28 @@ class KernelLibraryBuilder
} }
bool isLocal = false; bool isLocal = false;
bool isLoadLibrary = false; bool isLoadLibrary = false;
Builder preferred; Declaration preferred;
Uri uri; Uri uri;
Uri otherUri; Uri otherUri;
Uri preferredUri; Uri preferredUri;
Uri hiddenUri; Uri hiddenUri;
if (scope.local[name] == builder) { if (scope.local[name] == declaration) {
isLocal = true; isLocal = true;
preferred = builder; preferred = declaration;
hiddenUri = other.computeLibraryUri(); hiddenUri = other.computeLibraryUri();
} else { } else {
uri = builder.computeLibraryUri(); uri = declaration.computeLibraryUri();
otherUri = other.computeLibraryUri(); otherUri = other.computeLibraryUri();
if (builder is LoadLibraryBuilder) { if (declaration is LoadLibraryBuilder) {
isLoadLibrary = true; isLoadLibrary = true;
preferred = builder; preferred = declaration;
preferredUri = otherUri; preferredUri = otherUri;
} else if (other is LoadLibraryBuilder) { } else if (other is LoadLibraryBuilder) {
isLoadLibrary = true; isLoadLibrary = true;
preferred = other; preferred = other;
preferredUri = uri; preferredUri = uri;
} else if (otherUri?.scheme == "dart" && uri?.scheme != "dart") { } else if (otherUri?.scheme == "dart" && uri?.scheme != "dart") {
preferred = builder; preferred = declaration;
preferredUri = uri; preferredUri = uri;
hiddenUri = otherUri; hiddenUri = otherUri;
} else if (uri?.scheme == "dart" && otherUri?.scheme != "dart") { } else if (uri?.scheme == "dart" && otherUri?.scheme != "dart") {
@ -930,14 +930,15 @@ class KernelLibraryBuilder
} }
return preferred; return preferred;
} }
if (builder.next == null && other.next == null) { if (declaration.next == null && other.next == null) {
if (isImport && builder is PrefixBuilder && other is PrefixBuilder) { if (isImport && declaration is PrefixBuilder && other is PrefixBuilder) {
// Handles the case where the same prefix is used for different // Handles the case where the same prefix is used for different
// imports. // imports.
return builder return declaration
..exportScope.merge(other.exportScope, ..exportScope.merge(other.exportScope,
(String name, Builder existing, Builder member) { (String name, Declaration existing, Declaration member) {
return buildAmbiguousBuilder(name, existing, member, charOffset, return computeAmbiguousDeclaration(
name, existing, member, charOffset,
isExport: isExport, isImport: isImport); isExport: isExport, isImport: isImport);
}); });
} }
@ -1022,7 +1023,7 @@ class KernelLibraryBuilder
for (var declaration in libraryDeclaration.members.values) { for (var declaration in libraryDeclaration.members.values) {
if (declaration is KernelClassBuilder) { if (declaration is KernelClassBuilder) {
count += computeDefaultTypesForVariables(declaration.typeVariables); count += computeDefaultTypesForVariables(declaration.typeVariables);
declaration.forEach((String name, Builder member) { declaration.forEach((String name, Declaration member) {
if (member is KernelProcedureBuilder) { if (member is KernelProcedureBuilder) {
count += computeDefaultTypesForVariables(member.typeVariables); count += computeDefaultTypesForVariables(member.typeVariables);
} }
@ -1047,7 +1048,7 @@ class KernelLibraryBuilder
@override @override
void addImportsToScope() { void addImportsToScope() {
super.addImportsToScope(); super.addImportsToScope();
exportScope.forEach((String name, Builder member) { exportScope.forEach((String name, Declaration member) {
if (member.parent != this) { if (member.parent != this) {
switch (name) { switch (name) {
case "dynamic": case "dynamic":
@ -1071,9 +1072,9 @@ class KernelLibraryBuilder
@override @override
void applyPatches() { void applyPatches() {
if (!isPatch) return; if (!isPatch) return;
origin.forEach((String name, Builder member) { origin.forEach((String name, Declaration member) {
bool isSetter = member.isSetter; bool isSetter = member.isSetter;
Builder patch = isSetter ? scope.setters[name] : scope.local[name]; Declaration patch = isSetter ? scope.setters[name] : scope.local[name];
if (patch != null) { if (patch != null) {
// [patch] has the same name as a [member] in [origin] library, so it // [patch] has the same name as a [member] in [origin] library, so it
// must be a patch to [member]. // must be a patch to [member].
@ -1090,7 +1091,7 @@ class KernelLibraryBuilder
} }
} }
}); });
forEach((String name, Builder member) { forEach((String name, Declaration member) {
// We need to inject all non-patch members into the origin library. This // We need to inject all non-patch members into the origin library. This
// should only apply to private members. // should only apply to private members.
if (member.isPatch) { if (member.isPatch) {
@ -1106,13 +1107,13 @@ class KernelLibraryBuilder
int finishPatchMethods() { int finishPatchMethods() {
if (!isPatch) return 0; if (!isPatch) return 0;
int count = 0; int count = 0;
forEach((String name, Builder member) { forEach((String name, Declaration member) {
count += member.finishPatch(); count += member.finishPatch();
}); });
return count; return count;
} }
void injectMemberFromPatch(String name, Builder member) { void injectMemberFromPatch(String name, Declaration member) {
if (member.isSetter) { if (member.isSetter) {
assert(scope.setters[name] == null); assert(scope.setters[name] == null);
scopeBuilder.addSetter(name, member); scopeBuilder.addSetter(name, member);
@ -1122,7 +1123,7 @@ class KernelLibraryBuilder
} }
} }
void exportMemberFromPatch(String name, Builder member) { void exportMemberFromPatch(String name, Declaration member) {
if (uri.scheme != "dart" || !uri.path.startsWith("_")) { if (uri.scheme != "dart" || !uri.path.startsWith("_")) {
addCompileTimeError(templatePatchInjectionFailed.withArguments(name, uri), addCompileTimeError(templatePatchInjectionFailed.withArguments(name, uri),
member.charOffset, noLength, member.fileUri); member.charOffset, noLength, member.fileUri);

View file

@ -37,7 +37,7 @@ class KernelNamedTypeBuilder
Supertype handleInvalidSupertype( Supertype handleInvalidSupertype(
LibraryBuilder library, int charOffset, Uri fileUri) { LibraryBuilder library, int charOffset, Uri fileUri) {
var template = builder.isTypeVariable var template = declaration.isTypeVariable
? templateSupertypeIsTypeVariable ? templateSupertypeIsTypeVariable
: templateSupertypeIsIllegal; : templateSupertypeIsIllegal;
library.addCompileTimeError( library.addCompileTimeError(
@ -46,12 +46,12 @@ class KernelNamedTypeBuilder
} }
DartType build(LibraryBuilder library) { DartType build(LibraryBuilder library) {
return builder.buildType(library, arguments); return declaration.buildType(library, arguments);
} }
Supertype buildSupertype( Supertype buildSupertype(
LibraryBuilder library, int charOffset, Uri fileUri) { LibraryBuilder library, int charOffset, Uri fileUri) {
TypeDeclarationBuilder declaration = builder; TypeDeclarationBuilder declaration = this.declaration;
if (declaration is KernelClassBuilder) { if (declaration is KernelClassBuilder) {
return declaration.buildSupertype(library, arguments); return declaration.buildSupertype(library, arguments);
} else if (declaration is KernelInvalidTypeBuilder) { } else if (declaration is KernelInvalidTypeBuilder) {
@ -68,7 +68,7 @@ class KernelNamedTypeBuilder
Supertype buildMixedInType( Supertype buildMixedInType(
LibraryBuilder library, int charOffset, Uri fileUri) { LibraryBuilder library, int charOffset, Uri fileUri) {
TypeDeclarationBuilder declaration = builder; TypeDeclarationBuilder declaration = this.declaration;
if (declaration is KernelClassBuilder) { if (declaration is KernelClassBuilder) {
return declaration.buildMixedInType(library, arguments); return declaration.buildMixedInType(library, arguments);
} else if (declaration is KernelInvalidTypeBuilder) { } else if (declaration is KernelInvalidTypeBuilder) {
@ -84,9 +84,9 @@ class KernelNamedTypeBuilder
} }
TypeBuilder subst(Map<TypeVariableBuilder, TypeBuilder> substitution) { TypeBuilder subst(Map<TypeVariableBuilder, TypeBuilder> substitution) {
TypeBuilder result = substitution[builder]; TypeBuilder result = substitution[declaration];
if (result != null) { if (result != null) {
assert(builder is TypeVariableBuilder); assert(declaration is TypeVariableBuilder);
return result; return result;
} else if (arguments != null) { } else if (arguments != null) {
List<KernelTypeBuilder> arguments; List<KernelTypeBuilder> arguments;
@ -100,7 +100,7 @@ class KernelNamedTypeBuilder
i++; i++;
} }
if (arguments != null) { if (arguments != null) {
return new KernelNamedTypeBuilder(name, arguments)..bind(builder); return new KernelNamedTypeBuilder(name, arguments)..bind(declaration);
} }
} }
return this; return this;

View file

@ -60,9 +60,9 @@ import '../source/source_library_builder.dart' show SourceLibraryBuilder;
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
ConstructorReferenceBuilder, ConstructorReferenceBuilder,
Declaration,
FormalParameterBuilder, FormalParameterBuilder,
KernelFormalParameterBuilder, KernelFormalParameterBuilder,
KernelLibraryBuilder, KernelLibraryBuilder,
@ -217,7 +217,7 @@ abstract class KernelFunctionBuilder
Member build(SourceLibraryBuilder library); Member build(SourceLibraryBuilder library);
void becomeNative(Loader loader) { void becomeNative(Loader loader) {
Builder constructor = loader.getNativeAnnotation(); Declaration constructor = loader.getNativeAnnotation();
Arguments arguments = Arguments arguments =
new Arguments(<Expression>[new StringLiteral(nativeMethodName)]); new Arguments(<Expression>[new StringLiteral(nativeMethodName)]);
Expression annotation; Expression annotation;
@ -244,7 +244,7 @@ abstract class KernelFunctionBuilder
return true; return true;
} }
void reportPatchMismatch(Builder patch) { void reportPatchMismatch(Declaration patch) {
library.addCompileTimeError(messagePatchDeclarationMismatch, library.addCompileTimeError(messagePatchDeclarationMismatch,
patch.charOffset, noLength, patch.fileUri, context: [ patch.charOffset, noLength, patch.fileUri, context: [
messagePatchDeclarationOrigin.withLocation(fileUri, charOffset, noLength) messagePatchDeclarationOrigin.withLocation(fileUri, charOffset, noLength)
@ -385,7 +385,7 @@ class KernelProcedureBuilder extends KernelFunctionBuilder {
} }
@override @override
void applyPatch(Builder patch) { void applyPatch(Declaration patch) {
if (patch is KernelProcedureBuilder) { if (patch is KernelProcedureBuilder) {
if (checkPatch(patch)) { if (checkPatch(patch)) {
patch.actualOrigin = this; patch.actualOrigin = this;
@ -556,7 +556,7 @@ class KernelConstructorBuilder extends KernelFunctionBuilder {
} }
@override @override
void applyPatch(Builder patch) { void applyPatch(Declaration patch) {
if (patch is KernelConstructorBuilder) { if (patch is KernelConstructorBuilder) {
if (checkPatch(patch)) { if (checkPatch(patch)) {
patch.actualOrigin = this; patch.actualOrigin = this;

View file

@ -76,8 +76,8 @@ import '../uri_translator.dart' show UriTranslator;
import 'kernel_builder.dart' import 'kernel_builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
Declaration,
InvalidTypeBuilder, InvalidTypeBuilder,
KernelClassBuilder, KernelClassBuilder,
KernelLibraryBuilder, KernelLibraryBuilder,
@ -187,9 +187,9 @@ class KernelTarget extends TargetImplementation {
void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set) { void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set) {
if (cls == null) return; if (cls == null) return;
forEachDirectSupertype(cls, (NamedTypeBuilder type) { forEachDirectSupertype(cls, (NamedTypeBuilder type) {
Builder builder = type.builder; Declaration declaration = type.declaration;
if (builder is ClassBuilder) { if (declaration is ClassBuilder) {
set.add(builder); set.add(declaration);
} }
}); });
} }
@ -199,7 +199,7 @@ class KernelTarget extends TargetImplementation {
List<SourceClassBuilder> result = <SourceClassBuilder>[]; List<SourceClassBuilder> result = <SourceClassBuilder>[];
loader.builders.forEach((Uri uri, LibraryBuilder library) { loader.builders.forEach((Uri uri, LibraryBuilder library) {
if (library.loader == loader) { if (library.loader == loader) {
library.forEach((String name, Builder member) { library.forEach((String name, Declaration member) {
if (member is SourceClassBuilder && !member.isPatch) { if (member is SourceClassBuilder && !member.isPatch) {
result.add(member); result.add(member);
} }
@ -273,13 +273,14 @@ class KernelTarget extends TargetImplementation {
return component; return component;
} }
/// Build the kernel representation of the component loaded by this target. The /// Build the kernel representation of the component loaded by this
/// component will contain full bodies for the code loaded from sources, and /// target. The component will contain full bodies for the code loaded from
/// only references to the code loaded by the [DillTarget], which may or may /// sources, and only references to the code loaded by the [DillTarget],
/// not include method bodies (depending on what was loaded into that target, /// which may or may not include method bodies (depending on what was loaded
/// an outline or a full kernel component). /// into that target, an outline or a full kernel component).
/// ///
/// If [verify], run the default kernel verification on the resulting component. /// If [verify], run the default kernel verification on the resulting
/// component.
@override @override
Future<Component> buildComponent({bool verify: false}) async { Future<Component> buildComponent({bool verify: false}) async {
if (loader.first == null) return null; if (loader.first == null) return null;
@ -385,12 +386,13 @@ class KernelTarget extends TargetImplementation {
nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource); nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource);
if (loader.first != null) { if (loader.first != null) {
// TODO(sigmund): do only for full program // TODO(sigmund): do only for full program
Builder builder = loader.first.exportScope.lookup("main", -1, null); Declaration declaration =
if (builder is KernelProcedureBuilder) { loader.first.exportScope.lookup("main", -1, null);
component.mainMethod = builder.procedure; if (declaration is KernelProcedureBuilder) {
} else if (builder is DillMemberBuilder) { component.mainMethod = declaration.procedure;
if (builder.member is Procedure) { } else if (declaration is DillMemberBuilder) {
component.mainMethod = builder.member; if (declaration.member is Procedure) {
component.mainMethod = declaration.member;
} }
} }
} }
@ -403,21 +405,22 @@ class KernelTarget extends TargetImplementation {
Class objectClass = this.objectClass; Class objectClass = this.objectClass;
loader.builders.forEach((Uri uri, LibraryBuilder library) { loader.builders.forEach((Uri uri, LibraryBuilder library) {
if (library.loader == loader) { if (library.loader == loader) {
library.forEach((String name, Builder builder) { library.forEach((String name, Declaration declaration) {
while (builder != null) { while (declaration != null) {
if (builder is SourceClassBuilder) { if (declaration is SourceClassBuilder) {
Class cls = builder.target; Class cls = declaration.target;
if (cls != objectClass) { if (cls != objectClass) {
cls.supertype ??= objectClass.asRawSupertype; cls.supertype ??= objectClass.asRawSupertype;
builder.supertype ??= new KernelNamedTypeBuilder("Object", null) declaration.supertype ??=
..bind(objectClassBuilder); new KernelNamedTypeBuilder("Object", null)
..bind(objectClassBuilder);
} }
if (builder.isMixinApplication) { if (declaration.isMixinApplication) {
cls.mixedInType = builder.mixedInType.buildMixedInType( cls.mixedInType = declaration.mixedInType.buildMixedInType(
library, builder.charOffset, builder.fileUri); library, declaration.charOffset, declaration.fileUri);
} }
} }
builder = builder.next; declaration = declaration.next;
} }
}); });
} }
@ -435,7 +438,7 @@ class KernelTarget extends TargetImplementation {
ticker.logMs("Installed default constructors"); ticker.logMs("Installed default constructors");
} }
KernelClassBuilder get objectClassBuilder => objectType.builder; KernelClassBuilder get objectClassBuilder => objectType.declaration;
Class get objectClass => objectClassBuilder.cls; Class get objectClass => objectClassBuilder.cls;
@ -463,7 +466,7 @@ class KernelTarget extends TargetImplementation {
SourceClassBuilder named = supertype; SourceClassBuilder named = supertype;
TypeBuilder type = named.supertype; TypeBuilder type = named.supertype;
if (type is NamedTypeBuilder) { if (type is NamedTypeBuilder) {
supertype = type.builder; supertype = type.declaration;
} else { } else {
unhandled("${type.runtimeType}", "installDefaultConstructor", unhandled("${type.runtimeType}", "installDefaultConstructor",
builder.charOffset, builder.fileUri); builder.charOffset, builder.fileUri);
@ -620,7 +623,7 @@ class KernelTarget extends TargetImplementation {
Map<Constructor, List<FieldInitializer>> fieldInitializers = Map<Constructor, List<FieldInitializer>> fieldInitializers =
<Constructor, List<FieldInitializer>>{}; <Constructor, List<FieldInitializer>>{};
Constructor superTarget; Constructor superTarget;
builder.constructors.forEach((String name, Builder member) { builder.constructors.forEach((String name, Declaration member) {
if (member.isFactory) return; if (member.isFactory) return;
MemberBuilder constructorBuilder = member; MemberBuilder constructorBuilder = member;
Constructor constructor = constructorBuilder.target; Constructor constructor = constructorBuilder.target;

View file

@ -6,15 +6,18 @@ library fasta.kernel_variable_builder;
import 'package:kernel/ast.dart' show VariableDeclaration; import 'package:kernel/ast.dart' show VariableDeclaration;
import 'kernel_builder.dart' show Builder; import 'kernel_builder.dart' show Declaration;
class KernelVariableBuilder extends Declaration {
@override
final Declaration parent;
@override
final Uri fileUri;
class KernelVariableBuilder extends Builder {
final VariableDeclaration variable; final VariableDeclaration variable;
KernelVariableBuilder( KernelVariableBuilder(this.variable, this.parent, this.fileUri);
VariableDeclaration variable, Builder parent, Uri fileUri)
: variable = variable,
super(parent, variable.fileOffset, fileUri);
@override @override
int get charOffset => variable.fileOffset; int get charOffset => variable.fileOffset;

View file

@ -16,12 +16,12 @@ import 'package:kernel/ast.dart'
ProcedureKind, ProcedureKind,
ReturnStatement; ReturnStatement;
import 'kernel_builder.dart' show Builder, KernelLibraryBuilder; import 'kernel_builder.dart' show Declaration, KernelLibraryBuilder;
import 'forest.dart' show Forest; import 'forest.dart' show Forest;
/// Builder to represent the `deferLibrary.loadLibrary` calls and tear-offs. /// Builder to represent the `deferLibrary.loadLibrary` calls and tear-offs.
class LoadLibraryBuilder extends Builder { class LoadLibraryBuilder extends Declaration {
final KernelLibraryBuilder parent; final KernelLibraryBuilder parent;
final LibraryDependency importDependency; final LibraryDependency importDependency;
@ -33,8 +33,9 @@ class LoadLibraryBuilder extends Builder {
/// null, no tear-offs were seen in the code and no method is generated. /// null, no tear-offs were seen in the code and no method is generated.
Member tearoff; Member tearoff;
LoadLibraryBuilder(this.parent, this.importDependency, this.charOffset) LoadLibraryBuilder(this.parent, this.importDependency, this.charOffset);
: super(parent, charOffset, parent.fileUri);
Uri get fileUri => parent.fileUri;
LoadLibrary createLoadLibrary(int charOffset, Forest forest) { LoadLibrary createLoadLibrary(int charOffset, Forest forest) {
return forest.loadLibrary(importDependency)..fileOffset = charOffset; return forest.loadLibrary(importDependency)..fileOffset = charOffset;

View file

@ -24,11 +24,11 @@ KernelTypeBuilder substituteRange(
Map<TypeVariableBuilder, KernelTypeBuilder> lowerSubstitution, Map<TypeVariableBuilder, KernelTypeBuilder> lowerSubstitution,
{bool isCovariant = true}) { {bool isCovariant = true}) {
if (type is KernelNamedTypeBuilder) { if (type is KernelNamedTypeBuilder) {
if (type.builder is KernelTypeVariableBuilder) { if (type.declaration is KernelTypeVariableBuilder) {
if (isCovariant) { if (isCovariant) {
return upperSubstitution[type.builder] ?? type; return upperSubstitution[type.declaration] ?? type;
} }
return lowerSubstitution[type.builder] ?? type; return lowerSubstitution[type.declaration] ?? type;
} }
if (type.arguments == null || type.arguments.length == 0) { if (type.arguments == null || type.arguments.length == 0) {
return type; return type;
@ -45,7 +45,7 @@ KernelTypeBuilder substituteRange(
} }
if (arguments != null) { if (arguments != null) {
return new KernelNamedTypeBuilder(type.name, arguments) return new KernelNamedTypeBuilder(type.name, arguments)
..bind(type.builder); ..bind(type.declaration);
} }
return type; return type;
} }
@ -201,9 +201,9 @@ class TypeVariablesGraph implements Graph<int> {
void collectReferencesFrom(int index, TypeBuilder type) { void collectReferencesFrom(int index, TypeBuilder type) {
if (type is NamedTypeBuilder) { if (type is NamedTypeBuilder) {
if (type.builder is TypeVariableBuilder && if (type.declaration is TypeVariableBuilder &&
this.variables.contains(type.builder)) { this.variables.contains(type.declaration)) {
edges[variableIndices[type.builder]].add(index); edges[variableIndices[type.declaration]].add(index);
} }
if (type.arguments != null) { if (type.arguments != null) {
for (TypeBuilder argument in type.arguments) { for (TypeBuilder argument in type.arguments) {

View file

@ -8,7 +8,7 @@ import 'dart:async' show Future;
import 'dart:collection' show Queue; import 'dart:collection' show Queue;
import 'builder/builder.dart' show Builder, LibraryBuilder; import 'builder/builder.dart' show Declaration, LibraryBuilder;
import 'deprecated_problems.dart' show firstSourceUri; import 'deprecated_problems.dart' show firstSourceUri;
@ -263,17 +263,17 @@ severity: $severity
return true; return true;
} }
Builder getAbstractClassInstantiationError() { Declaration getAbstractClassInstantiationError() {
return target.getAbstractClassInstantiationError(this); return target.getAbstractClassInstantiationError(this);
} }
Builder getCompileTimeError() => target.getCompileTimeError(this); Declaration getCompileTimeError() => target.getCompileTimeError(this);
Builder getDuplicatedFieldInitializerError() { Declaration getDuplicatedFieldInitializerError() {
return target.getDuplicatedFieldInitializerError(this); return target.getDuplicatedFieldInitializerError(this);
} }
Builder getNativeAnnotation() => target.getNativeAnnotation(this); Declaration getNativeAnnotation() => target.getNativeAnnotation(this);
void recordMessage(Severity severity, Message message, int charOffset, void recordMessage(Severity severity, Message message, int charOffset,
int length, Uri fileUri, int length, Uri fileUri,

View file

@ -4,7 +4,7 @@
library fasta.scope; library fasta.scope;
import 'builder/builder.dart' show Builder, TypeVariableBuilder; import 'builder/builder.dart' show Declaration, TypeVariableBuilder;
import 'fasta_codes.dart' import 'fasta_codes.dart'
show show
@ -19,10 +19,10 @@ import 'problems.dart' show internalProblem, unsupported;
class MutableScope { class MutableScope {
/// Names declared in this scope. /// Names declared in this scope.
Map<String, Builder> local; Map<String, Declaration> local;
/// Setters declared in this scope. /// Setters declared in this scope.
Map<String, Builder> setters; Map<String, Declaration> setters;
/// The scope that this scope is nested within, or `null` if this is the top /// The scope that this scope is nested within, or `null` if this is the top
/// level scope. /// level scope.
@ -42,28 +42,28 @@ class Scope extends MutableScope {
/// succeed. /// succeed.
final bool isModifiable; final bool isModifiable;
Map<String, Builder> labels; Map<String, Declaration> labels;
Map<String, Builder> forwardDeclaredLabels; Map<String, Declaration> forwardDeclaredLabels;
Map<String, int> usedNames; Map<String, int> usedNames;
Scope(Map<String, Builder> local, Map<String, Builder> setters, Scope parent, Scope(Map<String, Declaration> local, Map<String, Declaration> setters,
String debugName, {this.isModifiable: true}) Scope parent, String debugName, {this.isModifiable: true})
: super(local, setters = setters ?? const <String, Builder>{}, parent, : super(local, setters = setters ?? const <String, Declaration>{}, parent,
debugName); debugName);
Scope.top({bool isModifiable: false}) Scope.top({bool isModifiable: false})
: this(<String, Builder>{}, <String, Builder>{}, null, "top", : this(<String, Declaration>{}, <String, Declaration>{}, null, "top",
isModifiable: isModifiable); isModifiable: isModifiable);
Scope.immutable() Scope.immutable()
: this(const <String, Builder>{}, const <String, Builder>{}, null, : this(const <String, Declaration>{}, const <String, Declaration>{}, null,
"immutable", "immutable",
isModifiable: false); isModifiable: false);
Scope.nested(Scope parent, String debugName, {bool isModifiable: true}) Scope.nested(Scope parent, String debugName, {bool isModifiable: true})
: this(<String, Builder>{}, null, parent, debugName, : this(<String, Declaration>{}, null, parent, debugName,
isModifiable: isModifiable); isModifiable: isModifiable);
Scope copyWithParent(Scope parent, String debugName) { Scope copyWithParent(Scope parent, String debugName) {
@ -122,9 +122,9 @@ class Scope extends MutableScope {
} }
} }
Builder lookupIn(String name, int charOffset, Uri fileUri, Declaration lookupIn(String name, int charOffset, Uri fileUri,
Map<String, Builder> map, bool isInstanceScope) { Map<String, Declaration> map, bool isInstanceScope) {
Builder builder = map[name]; Declaration builder = map[name];
if (builder == null) return null; if (builder == null) return null;
if (builder.next != null) { if (builder.next != null) {
return new AmbiguousBuilder(name, builder, charOffset, fileUri); return new AmbiguousBuilder(name, builder, charOffset, fileUri);
@ -135,10 +135,10 @@ class Scope extends MutableScope {
} }
} }
Builder lookup(String name, int charOffset, Uri fileUri, Declaration lookup(String name, int charOffset, Uri fileUri,
{bool isInstanceScope: true}) { {bool isInstanceScope: true}) {
recordUse(name, charOffset, fileUri); recordUse(name, charOffset, fileUri);
Builder builder = Declaration builder =
lookupIn(name, charOffset, fileUri, local, isInstanceScope); lookupIn(name, charOffset, fileUri, local, isInstanceScope);
if (builder != null) return builder; if (builder != null) return builder;
builder = lookupIn(name, charOffset, fileUri, setters, isInstanceScope); builder = lookupIn(name, charOffset, fileUri, setters, isInstanceScope);
@ -152,10 +152,10 @@ class Scope extends MutableScope {
return builder ?? parent?.lookup(name, charOffset, fileUri); return builder ?? parent?.lookup(name, charOffset, fileUri);
} }
Builder lookupSetter(String name, int charOffset, Uri fileUri, Declaration lookupSetter(String name, int charOffset, Uri fileUri,
{bool isInstanceScope: true}) { {bool isInstanceScope: true}) {
recordUse(name, charOffset, fileUri); recordUse(name, charOffset, fileUri);
Builder builder = Declaration builder =
lookupIn(name, charOffset, fileUri, setters, isInstanceScope); lookupIn(name, charOffset, fileUri, setters, isInstanceScope);
if (builder != null) return builder; if (builder != null) return builder;
builder = lookupIn(name, charOffset, fileUri, local, isInstanceScope); builder = lookupIn(name, charOffset, fileUri, local, isInstanceScope);
@ -171,9 +171,9 @@ class Scope extends MutableScope {
bool hasLocalLabel(String name) => labels != null && labels.containsKey(name); bool hasLocalLabel(String name) => labels != null && labels.containsKey(name);
void declareLabel(String name, Builder target) { void declareLabel(String name, Declaration target) {
if (isModifiable) { if (isModifiable) {
labels ??= <String, Builder>{}; labels ??= <String, Declaration>{};
labels[name] = target; labels[name] = target;
} else { } else {
internalProblem( internalProblem(
@ -181,9 +181,9 @@ class Scope extends MutableScope {
} }
} }
void forwardDeclareLabel(String name, Builder target) { void forwardDeclareLabel(String name, Declaration target) {
declareLabel(name, target); declareLabel(name, target);
forwardDeclaredLabels ??= <String, Builder>{}; forwardDeclaredLabels ??= <String, Declaration>{};
forwardDeclaredLabels[name] = target; forwardDeclaredLabels[name] = target;
} }
@ -196,11 +196,11 @@ class Scope extends MutableScope {
return true; return true;
} }
Map<String, Builder> get unclaimedForwardDeclarations { Map<String, Declaration> get unclaimedForwardDeclarations {
return forwardDeclaredLabels; return forwardDeclaredLabels;
} }
Builder lookupLabel(String name) { Declaration lookupLabel(String name) {
return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name); return (labels == null ? null : labels[name]) ?? parent?.lookupLabel(name);
} }
@ -210,7 +210,7 @@ class Scope extends MutableScope {
/// that can be used as context for reporting a compile-time error about /// 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 /// [name] being used before its declared. [fileUri] is used to bind the
/// location of this message. /// location of this message.
LocatedMessage declare(String name, Builder builder, Uri fileUri) { LocatedMessage declare(String name, Declaration builder, Uri fileUri) {
if (isModifiable) { if (isModifiable) {
if (usedNames?.containsKey(name) ?? false) { if (usedNames?.containsKey(name) ?? false) {
return templateDuplicatedNamePreviouslyUsedCause return templateDuplicatedNamePreviouslyUsedCause
@ -225,15 +225,17 @@ class Scope extends MutableScope {
return null; return null;
} }
void merge(Scope scope, void merge(
buildAmbiguousBuilder(String name, Builder existing, Builder member)) { Scope scope,
Map<String, Builder> map = local; Declaration computeAmbiguousDeclaration(
String name, Declaration existing, Declaration member)) {
Map<String, Declaration> map = local;
void mergeMember(String name, Builder member) { void mergeMember(String name, Declaration member) {
Builder existing = map[name]; Declaration existing = map[name];
if (existing != null) { if (existing != null) {
if (existing != member) { if (existing != member) {
member = buildAmbiguousBuilder(name, existing, member); member = computeAmbiguousDeclaration(name, existing, member);
} }
} }
map[name] = member; map[name] = member;
@ -244,7 +246,7 @@ class Scope extends MutableScope {
scope.setters.forEach(mergeMember); scope.setters.forEach(mergeMember);
} }
void forEach(f(String name, Builder member)) { void forEach(f(String name, Declaration member)) {
local.forEach(f); local.forEach(f);
setters.forEach(f); setters.forEach(f);
} }
@ -262,10 +264,10 @@ class Scope extends MutableScope {
int nestingLevel = (parent?.writeOn(sink) ?? -1) + 1; int nestingLevel = (parent?.writeOn(sink) ?? -1) + 1;
String indent = " " * nestingLevel; String indent = " " * nestingLevel;
sink.writeln("$indent{"); sink.writeln("$indent{");
local.forEach((String name, Builder member) { local.forEach((String name, Declaration member) {
sink.writeln("$indent $name"); sink.writeln("$indent $name");
}); });
setters.forEach((String name, Builder member) { setters.forEach((String name, Declaration member) {
sink.writeln("$indent $name="); sink.writeln("$indent $name=");
}); });
return nestingLevel; return nestingLevel;
@ -277,24 +279,27 @@ class ScopeBuilder {
ScopeBuilder(this.scope); ScopeBuilder(this.scope);
void addMember(String name, Builder builder) { void addMember(String name, Declaration builder) {
scope.local[name] = builder; scope.local[name] = builder;
} }
void addSetter(String name, Builder builder) { void addSetter(String name, Declaration builder) {
scope.setters[name] = builder; scope.setters[name] = builder;
} }
Builder operator [](String name) => scope.local[name]; Declaration operator [](String name) => scope.local[name];
} }
abstract class ProblemBuilder extends Builder { abstract class ProblemBuilder extends Declaration {
final String name; final String name;
final Builder builder; final Declaration builder;
ProblemBuilder(this.name, this.builder, int charOffset, Uri fileUri) final int charOffset;
: super(null, charOffset, fileUri);
final Uri fileUri;
ProblemBuilder(this.name, this.builder, this.charOffset, this.fileUri);
get target => null; get target => null;
@ -309,10 +314,11 @@ abstract class ProblemBuilder extends Builder {
/// Represents a [builder] that's being accessed incorrectly. For example, an /// Represents a [builder] that's being accessed incorrectly. For example, an
/// attempt to write to a final field, or to read from a setter. /// attempt to write to a final field, or to read from a setter.
class AccessErrorBuilder extends ProblemBuilder { class AccessErrorBuilder extends ProblemBuilder {
AccessErrorBuilder(String name, Builder builder, int charOffset, Uri fileUri) AccessErrorBuilder(
String name, Declaration builder, int charOffset, Uri fileUri)
: super(name, builder, charOffset, fileUri); : super(name, builder, charOffset, fileUri);
Builder get parent => builder; Declaration get parent => builder;
bool get isFinal => builder.isFinal; bool get isFinal => builder.isFinal;
@ -338,8 +344,11 @@ class AccessErrorBuilder extends ProblemBuilder {
} }
class AmbiguousBuilder extends ProblemBuilder { class AmbiguousBuilder extends ProblemBuilder {
AmbiguousBuilder(String name, Builder builder, int charOffset, Uri fileUri) AmbiguousBuilder(
String name, Declaration builder, int charOffset, Uri fileUri)
: super(name, builder, charOffset, fileUri); : super(name, builder, charOffset, fileUri);
Declaration get parent => null;
Message get message => templateDuplicatedName.withArguments(name); Message get message => templateDuplicatedName.withArguments(name);
} }

View file

@ -211,7 +211,7 @@ class DietListener extends StackListener {
String name = pop(); String name = pop();
Token metadata = pop(); Token metadata = pop();
Builder typedefBuilder = lookupBuilder(typedefKeyword, null, name); Declaration typedefBuilder = lookupBuilder(typedefKeyword, null, name);
Typedef target = typedefBuilder.target; Typedef target = typedefBuilder.target;
var metadataConstants = parseMetadata(typedefBuilder, metadata); var metadataConstants = parseMetadata(typedefBuilder, metadata);
if (metadataConstants != null) { if (metadataConstants != null) {
@ -569,12 +569,15 @@ class DietListener extends StackListener {
void buildFields(int count, Token token, bool isTopLevel) { void buildFields(int count, Token token, bool isTopLevel) {
List<String> names = List<String> names =
popList(count, new List<String>.filled(count, null, growable: true)); popList(count, new List<String>.filled(count, null, growable: true));
Builder builder = lookupBuilder(token, null, names.first); Declaration declaration = lookupBuilder(token, null, names.first);
Token metadata = pop(); Token metadata = pop();
// TODO(paulberry): don't re-parse the field if we've already parsed it // TODO(paulberry): don't re-parse the field if we've already parsed it
// for type inference. // for type inference.
parseFields(createListener(builder, memberScope, builder.isInstanceMember), parseFields(
token, metadata, isTopLevel); createListener(declaration, memberScope, declaration.isInstanceMember),
token,
metadata,
isTopLevel);
} }
@override @override
@ -604,7 +607,7 @@ class DietListener extends StackListener {
assert(currentClass == null); assert(currentClass == null);
assert(memberScope == library.scope); assert(memberScope == library.scope);
Builder classBuilder = lookupBuilder(token, null, name); Declaration classBuilder = lookupBuilder(token, null, name);
Class target = classBuilder.target; Class target = classBuilder.target;
var metadataConstants = parseMetadata(classBuilder, metadata); var metadataConstants = parseMetadata(classBuilder, metadata);
if (metadataConstants != null) { if (metadataConstants != null) {
@ -651,10 +654,10 @@ class DietListener extends StackListener {
for (int i = 0; i < metadataAndValues.length; i += 2) { for (int i = 0; i < metadataAndValues.length; i += 2) {
Token metadata = metadataAndValues[i]; Token metadata = metadataAndValues[i];
String valueName = metadataAndValues[i + 1]; String valueName = metadataAndValues[i + 1];
Builder builder = enumBuilder.scope.local[valueName]; Declaration declaration = enumBuilder.scope.local[valueName];
if (metadata != null) { if (metadata != null) {
Field field = builder.target; Field field = declaration.target;
for (var annotation in parseMetadata(builder, metadata)) { for (var annotation in parseMetadata(declaration, metadata)) {
field.addAnnotation(annotation); field.addAnnotation(annotation);
} }
} }
@ -671,7 +674,7 @@ class DietListener extends StackListener {
String name = pop(); String name = pop();
Token metadata = pop(); Token metadata = pop();
Builder classBuilder = lookupBuilder(classKeyword, null, name); Declaration classBuilder = lookupBuilder(classKeyword, null, name);
Class target = classBuilder.target; Class target = classBuilder.target;
var metadataConstants = parseMetadata(classBuilder, metadata); var metadataConstants = parseMetadata(classBuilder, metadata);
if (metadataConstants != null) { if (metadataConstants != null) {
@ -754,9 +757,9 @@ class DietListener extends StackListener {
listener.checkEmpty(token.charOffset); listener.checkEmpty(token.charOffset);
} }
Builder lookupBuilder(Token token, Token getOrSet, String name) { Declaration lookupBuilder(Token token, Token getOrSet, String name) {
// TODO(ahe): Can I move this to Scope or ScopeBuilder? // TODO(ahe): Can I move this to Scope or ScopeBuilder?
Builder builder; Declaration declaration;
if (currentClass != null) { if (currentClass != null) {
if (uri != currentClass.fileUri) { if (uri != currentClass.fileUri) {
unexpected("$uri", "${currentClass.fileUri}", currentClass.charOffset, unexpected("$uri", "${currentClass.fileUri}", currentClass.charOffset,
@ -764,22 +767,22 @@ class DietListener extends StackListener {
} }
if (getOrSet != null && optional("set", getOrSet)) { if (getOrSet != null && optional("set", getOrSet)) {
builder = currentClass.scope.setters[name]; declaration = currentClass.scope.setters[name];
} else { } else {
builder = currentClass.scope.local[name]; declaration = currentClass.scope.local[name];
} }
} else if (getOrSet != null && optional("set", getOrSet)) { } else if (getOrSet != null && optional("set", getOrSet)) {
builder = library.scope.setters[name]; declaration = library.scope.setters[name];
} else { } else {
builder = library.scopeBuilder[name]; declaration = library.scopeBuilder[name];
} }
checkBuilder(token, builder, name); checkBuilder(token, declaration, name);
return builder; return declaration;
} }
Builder lookupConstructor(Token token, Object nameOrQualified) { Declaration lookupConstructor(Token token, Object nameOrQualified) {
assert(currentClass != null); assert(currentClass != null);
Builder builder; Declaration declaration;
String name; String name;
String suffix; String suffix;
if (nameOrQualified is QualifiedName) { if (nameOrQualified is QualifiedName) {
@ -789,22 +792,22 @@ class DietListener extends StackListener {
name = nameOrQualified; name = nameOrQualified;
suffix = name == currentClass.name ? "" : name; suffix = name == currentClass.name ? "" : name;
} }
builder = currentClass.constructors.local[suffix]; declaration = currentClass.constructors.local[suffix];
checkBuilder(token, builder, nameOrQualified); checkBuilder(token, declaration, nameOrQualified);
return builder; return declaration;
} }
void checkBuilder(Token token, Builder builder, Object name) { void checkBuilder(Token token, Declaration declaration, Object name) {
if (builder == null) { if (declaration == null) {
internalProblem(templateInternalProblemNotFound.withArguments("$name"), internalProblem(templateInternalProblemNotFound.withArguments("$name"),
token.charOffset, uri); token.charOffset, uri);
} }
if (builder.next != null) { if (declaration.next != null) {
deprecated_inputError(uri, token.charOffset, "Duplicated name: $name"); deprecated_inputError(uri, token.charOffset, "Duplicated name: $name");
} }
if (uri != builder.fileUri) { if (uri != declaration.fileUri) {
unexpected( unexpected("$uri", "${declaration.fileUri}", declaration.charOffset,
"$uri", "${builder.fileUri}", builder.charOffset, builder.fileUri); declaration.fileUri);
} }
} }

View file

@ -23,9 +23,9 @@ import '../fasta_codes.dart'
import '../kernel/kernel_builder.dart' import '../kernel/kernel_builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
ConstructorReferenceBuilder, ConstructorReferenceBuilder,
Declaration,
KernelClassBuilder, KernelClassBuilder,
KernelFieldBuilder, KernelFieldBuilder,
KernelFunctionBuilder, KernelFunctionBuilder,
@ -103,29 +103,29 @@ class SourceClassBuilder extends KernelClassBuilder {
Class get cls => origin.actualCls; Class get cls => origin.actualCls;
Class build(KernelLibraryBuilder library, LibraryBuilder coreLibrary) { Class build(KernelLibraryBuilder library, LibraryBuilder coreLibrary) {
void buildBuilders(String name, Builder builder) { void buildBuilders(String name, Declaration declaration) {
do { do {
if (builder.parent != this) { if (declaration.parent != this) {
unexpected( unexpected(
"$fileUri", "${builder.parent.fileUri}", charOffset, fileUri); "$fileUri", "${declaration.parent.fileUri}", charOffset, fileUri);
} else if (builder is KernelFieldBuilder) { } else if (declaration is KernelFieldBuilder) {
// TODO(ahe): It would be nice to have a common interface for the // TODO(ahe): It would be nice to have a common interface for the
// build method to avoid duplicating these two cases. // build method to avoid duplicating these two cases.
Member field = builder.build(library); Member field = declaration.build(library);
if (!builder.isPatch) { if (!declaration.isPatch) {
cls.addMember(field); cls.addMember(field);
} }
} else if (builder is KernelFunctionBuilder) { } else if (declaration is KernelFunctionBuilder) {
Member function = builder.build(library); Member function = declaration.build(library);
if (!builder.isPatch) { if (!declaration.isPatch) {
cls.addMember(function); cls.addMember(function);
} }
} else { } else {
unhandled("${builder.runtimeType}", "buildBuilders", unhandled("${declaration.runtimeType}", "buildBuilders",
builder.charOffset, builder.fileUri); declaration.charOffset, declaration.fileUri);
} }
builder = builder.next; declaration = declaration.next;
} while (builder != null); } while (declaration != null);
} }
scope.forEach(buildBuilders); scope.forEach(buildBuilders);
@ -148,8 +148,8 @@ class SourceClassBuilder extends KernelClassBuilder {
} }
} }
constructors.forEach((String name, Builder constructor) { constructors.forEach((String name, Declaration constructor) {
Builder member = scopeBuilder[name]; Declaration member = scopeBuilder[name];
if (member == null) return; if (member == null) return;
// TODO(ahe): Revisit these messages. It seems like the last two should // TODO(ahe): Revisit these messages. It seems like the last two should
// be `context` parameter to this message. // be `context` parameter to this message.
@ -169,8 +169,8 @@ class SourceClassBuilder extends KernelClassBuilder {
} }
}); });
scope.setters.forEach((String name, Builder setter) { scope.setters.forEach((String name, Declaration setter) {
Builder member = scopeBuilder[name]; Declaration member = scopeBuilder[name];
if (member == null || !member.isField || member.isFinal) return; if (member == null || !member.isField || member.isFinal) return;
if (member.isInstanceMember == setter.isInstanceMember) { if (member.isInstanceMember == setter.isInstanceMember) {
addProblem(templateConflictsWithMember.withArguments(name), addProblem(templateConflictsWithMember.withArguments(name),
@ -203,15 +203,15 @@ class SourceClassBuilder extends KernelClassBuilder {
@override @override
void prepareTopLevelInference( void prepareTopLevelInference(
SourceLibraryBuilder library, ClassBuilder currentClass) { SourceLibraryBuilder library, ClassBuilder currentClass) {
scope.forEach((name, builder) { scope.forEach((name, declaration) {
builder.prepareTopLevelInference(library, this); declaration.prepareTopLevelInference(library, this);
}); });
} }
@override @override
void instrumentTopLevelInference(Instrumentation instrumentation) { void instrumentTopLevelInference(Instrumentation instrumentation) {
scope.forEach((name, builder) { scope.forEach((name, declaration) {
builder.instrumentTopLevelInference(instrumentation); declaration.instrumentTopLevelInference(instrumentation);
}); });
} }
@ -224,11 +224,11 @@ class SourceClassBuilder extends KernelClassBuilder {
cls.annotations.forEach((m) => m.fileOffset = origin.cls.fileOffset); cls.annotations.forEach((m) => m.fileOffset = origin.cls.fileOffset);
int count = 0; int count = 0;
scope.forEach((String name, Builder builder) { scope.forEach((String name, Declaration declaration) {
count += builder.finishPatch(); count += declaration.finishPatch();
}); });
constructors.forEach((String name, Builder builder) { constructors.forEach((String name, Declaration declaration) {
count += builder.finishPatch(); count += declaration.finishPatch();
}); });
return count; return count;
} }

View file

@ -14,9 +14,9 @@ import '../../scanner/token.dart' show Token;
import '../builder/builder.dart' import '../builder/builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
ConstructorReferenceBuilder, ConstructorReferenceBuilder,
Declaration,
FormalParameterBuilder, FormalParameterBuilder,
FunctionTypeBuilder, FunctionTypeBuilder,
LibraryBuilder, LibraryBuilder,
@ -436,49 +436,49 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
TypeVariableBuilder addTypeVariable(String name, T bound, int charOffset); TypeVariableBuilder addTypeVariable(String name, T bound, int charOffset);
Builder addBuilder(String name, Builder builder, int charOffset) { Declaration addBuilder(String name, Declaration declaration, int charOffset) {
// TODO(ahe): Set the parent correctly here. Could then change the // TODO(ahe): Set the parent correctly here. Could then change the
// implementation of MemberBuilder.isTopLevel to test explicitly for a // implementation of MemberBuilder.isTopLevel to test explicitly for a
// LibraryBuilder. // LibraryBuilder.
if (currentDeclaration == libraryDeclaration) { if (currentDeclaration == libraryDeclaration) {
if (builder is MemberBuilder) { if (declaration is MemberBuilder) {
builder.parent = this; declaration.parent = this;
} else if (builder is TypeDeclarationBuilder) { } else if (declaration is TypeDeclarationBuilder) {
builder.parent = this; declaration.parent = this;
} else if (builder is PrefixBuilder) { } else if (declaration is PrefixBuilder) {
assert(builder.parent == this); assert(declaration.parent == this);
} else { } else {
return unhandled( return unhandled(
"${builder.runtimeType}", "addBuilder", charOffset, fileUri); "${declaration.runtimeType}", "addBuilder", charOffset, fileUri);
} }
} else { } else {
assert(currentDeclaration.parent == libraryDeclaration); assert(currentDeclaration.parent == libraryDeclaration);
} }
bool isConstructor = builder is ProcedureBuilder && bool isConstructor = declaration is ProcedureBuilder &&
(builder.isConstructor || builder.isFactory); (declaration.isConstructor || declaration.isFactory);
if (!isConstructor && if (!isConstructor &&
!builder.isSetter && !declaration.isSetter &&
name == currentDeclaration.name) { name == currentDeclaration.name) {
addCompileTimeError( addCompileTimeError(
messageMemberWithSameNameAsClass, charOffset, noLength, fileUri); messageMemberWithSameNameAsClass, charOffset, noLength, fileUri);
} }
Map<String, Builder> members = isConstructor Map<String, Declaration> members = isConstructor
? currentDeclaration.constructors ? currentDeclaration.constructors
: (builder.isSetter : (declaration.isSetter
? currentDeclaration.setters ? currentDeclaration.setters
: currentDeclaration.members); : currentDeclaration.members);
Builder existing = members[name]; Declaration existing = members[name];
builder.next = existing; declaration.next = existing;
if (builder is PrefixBuilder && existing is PrefixBuilder) { if (declaration is PrefixBuilder && existing is PrefixBuilder) {
assert(existing.next == null); assert(existing.next == null);
Builder deferred; Declaration deferred;
Builder other; Declaration other;
if (builder.deferred) { if (declaration.deferred) {
deferred = builder; deferred = declaration;
other = existing; other = existing;
} else if (existing.deferred) { } else if (existing.deferred) {
deferred = existing; deferred = existing;
other = builder; other = declaration;
} }
if (deferred != null) { if (deferred != null) {
addCompileTimeError( addCompileTimeError(
@ -493,20 +493,21 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
]); ]);
} }
return existing return existing
..exportScope.merge(builder.exportScope, ..exportScope.merge(declaration.exportScope,
(String name, Builder existing, Builder member) { (String name, Declaration existing, Declaration member) {
return buildAmbiguousBuilder(name, existing, member, charOffset); return computeAmbiguousDeclaration(
name, existing, member, charOffset);
}); });
} else if (isDuplicatedDefinition(existing, builder)) { } else if (isDuplicatedDefinition(existing, declaration)) {
addCompileTimeError(templateDuplicatedDefinition.withArguments(name), addCompileTimeError(templateDuplicatedDefinition.withArguments(name),
charOffset, noLength, fileUri); charOffset, noLength, fileUri);
} }
return members[name] = builder; return members[name] = declaration;
} }
bool isDuplicatedDefinition(Builder existing, Builder other) { bool isDuplicatedDefinition(Declaration existing, Declaration other) {
if (existing == null) return false; if (existing == null) return false;
Builder next = existing.next; Declaration next = existing.next;
if (next == null) { if (next == null) {
if (existing.isGetter && other.isSetter) return false; if (existing.isGetter && other.isSetter) return false;
if (existing.isSetter && other.isGetter) return false; if (existing.isSetter && other.isGetter) return false;
@ -523,28 +524,28 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
return true; return true;
} }
void buildBuilder(Builder builder, LibraryBuilder coreLibrary); void buildBuilder(Declaration declaration, LibraryBuilder coreLibrary);
R build(LibraryBuilder coreLibrary) { R build(LibraryBuilder coreLibrary) {
assert(implementationBuilders.isEmpty); assert(implementationBuilders.isEmpty);
canAddImplementationBuilders = true; canAddImplementationBuilders = true;
forEach((String name, Builder builder) { forEach((String name, Declaration declaration) {
do { do {
buildBuilder(builder, coreLibrary); buildBuilder(declaration, coreLibrary);
builder = builder.next; declaration = declaration.next;
} while (builder != null); } while (declaration != null);
}); });
for (List list in implementationBuilders) { for (List list in implementationBuilders) {
String name = list[0]; String name = list[0];
Builder builder = list[1]; Declaration declaration = list[1];
int charOffset = list[2]; int charOffset = list[2];
addBuilder(name, builder, charOffset); addBuilder(name, declaration, charOffset);
buildBuilder(builder, coreLibrary); buildBuilder(declaration, coreLibrary);
} }
canAddImplementationBuilders = false; canAddImplementationBuilders = false;
scope.setters.forEach((String name, Builder setter) { scope.setters.forEach((String name, Declaration setter) {
Builder member = scopeBuilder[name]; Declaration member = scopeBuilder[name];
if (member == null || !member.isField || member.isFinal) return; if (member == null || !member.isField || member.isFinal) return;
addCompileTimeError(templateConflictsWithMember.withArguments(name), addCompileTimeError(templateConflictsWithMember.withArguments(name),
setter.charOffset, noLength, fileUri); setter.charOffset, noLength, fileUri);
@ -560,9 +561,10 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
/// Currently, only anonymous mixins are using implementation builders (see /// Currently, only anonymous mixins are using implementation builders (see
/// [KernelMixinApplicationBuilder] /// [KernelMixinApplicationBuilder]
/// (../kernel/kernel_mixin_application_builder.dart)). /// (../kernel/kernel_mixin_application_builder.dart)).
void addImplementationBuilder(String name, Builder builder, int charOffset) { void addImplementationBuilder(
String name, Declaration declaration, int charOffset) {
assert(canAddImplementationBuilders, "$uri"); assert(canAddImplementationBuilders, "$uri");
implementationBuilders.add([name, builder, charOffset]); implementationBuilders.add([name, declaration, charOffset]);
} }
void validatePart() { void validatePart() {
@ -631,14 +633,14 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
-1, noLength, fileUri); -1, noLength, fileUri);
} }
} }
part.forEach((String name, Builder builder) { part.forEach((String name, Declaration declaration) {
if (builder.next != null) { if (declaration.next != null) {
// TODO(ahe): This shouldn't be necessary as setters have been added to // TODO(ahe): This shouldn't be necessary as setters have been added to
// their own scope. // their own scope.
assert(builder.next.next == null); assert(declaration.next.next == null);
addBuilder(name, builder.next, builder.next.charOffset); addBuilder(name, declaration.next, declaration.next.charOffset);
} }
addBuilder(name, builder, builder.charOffset); addBuilder(name, declaration, declaration.charOffset);
}); });
types.addAll(part.types); types.addAll(part.types);
constructorReferences.addAll(part.constructorReferences); constructorReferences.addAll(part.constructorReferences);
@ -660,20 +662,22 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
import.finalizeImports(this); import.finalizeImports(this);
} }
if (!explicitCoreImport) { if (!explicitCoreImport) {
loader.coreLibrary.exportScope.forEach((String name, Builder member) { loader.coreLibrary.exportScope.forEach((String name, Declaration member) {
addToScope(name, member, -1, true); addToScope(name, member, -1, true);
}); });
} }
} }
@override @override
void addToScope(String name, Builder member, int charOffset, bool isImport) { void addToScope(
Map<String, Builder> map = String name, Declaration member, int charOffset, bool isImport) {
Map<String, Declaration> map =
member.isSetter ? importScope.setters : importScope.local; member.isSetter ? importScope.setters : importScope.local;
Builder existing = map[name]; Declaration existing = map[name];
if (existing != null) { if (existing != null) {
if (existing != member) { if (existing != member) {
map[name] = buildAmbiguousBuilder(name, existing, member, charOffset, map[name] = computeAmbiguousDeclaration(
name, existing, member, charOffset,
isImport: isImport); isImport: isImport);
} }
} else { } else {
@ -700,7 +704,7 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
@override @override
int resolveConstructors(_) { int resolveConstructors(_) {
int count = 0; int count = 0;
forEach((String name, Builder member) { forEach((String name, Declaration member) {
count += member.resolveConstructors(this); count += member.resolveConstructors(this);
}); });
return count; return count;
@ -722,7 +726,7 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
@override @override
void prepareTopLevelInference( void prepareTopLevelInference(
SourceLibraryBuilder library, ClassBuilder currentClass) { SourceLibraryBuilder library, ClassBuilder currentClass) {
forEach((String name, Builder member) { forEach((String name, Declaration member) {
if (member is ClassBuilder) { if (member is ClassBuilder) {
// Classes are handled separately, in class hierarchy order. // Classes are handled separately, in class hierarchy order.
return; return;
@ -733,7 +737,7 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
@override @override
void instrumentTopLevelInference(Instrumentation instrumentation) { void instrumentTopLevelInference(Instrumentation instrumentation) {
forEach((String name, Builder member) { forEach((String name, Declaration member) {
member.instrumentTopLevelInference(instrumentation); member.instrumentTopLevelInference(instrumentation);
}); });
} }
@ -744,11 +748,11 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
class DeclarationBuilder<T extends TypeBuilder> { class DeclarationBuilder<T extends TypeBuilder> {
final DeclarationBuilder<T> parent; final DeclarationBuilder<T> parent;
final Map<String, Builder> members; final Map<String, Declaration> members;
final Map<String, Builder> constructors; final Map<String, Declaration> constructors;
final Map<String, Builder> setters; final Map<String, Declaration> setters;
final List<UnresolvedType<T>> types = <UnresolvedType<T>>[]; final List<UnresolvedType<T>> types = <UnresolvedType<T>>[];
@ -762,7 +766,8 @@ class DeclarationBuilder<T extends TypeBuilder> {
} }
DeclarationBuilder.library() DeclarationBuilder.library()
: this(<String, Builder>{}, <String, Builder>{}, null, "library", null); : this(<String, Declaration>{}, <String, Declaration>{}, null, "library",
null);
DeclarationBuilder createNested(String name, bool hasMembers) { DeclarationBuilder createNested(String name, bool hasMembers) {
return new DeclarationBuilder<T>( return new DeclarationBuilder<T>(

View file

@ -34,8 +34,8 @@ import '../../base/instrumentation.dart'
import '../builder/builder.dart' import '../builder/builder.dart'
show show
Builder,
ClassBuilder, ClassBuilder,
Declaration,
EnumBuilder, EnumBuilder,
LibraryBuilder, LibraryBuilder,
NamedTypeBuilder, NamedTypeBuilder,
@ -223,9 +223,10 @@ class SourceLoader<L> extends Loader<L> {
if (token == null) return null; if (token == null) return null;
DietListener dietListener = createDietListener(library); DietListener dietListener = createDietListener(library);
Builder parent = library; Declaration parent = library;
if (enclosingClass != null) { if (enclosingClass != null) {
Builder cls = dietListener.memberScope.lookup(enclosingClass, -1, null); Declaration cls =
dietListener.memberScope.lookup(enclosingClass, -1, null);
if (cls is ClassBuilder) { if (cls is ClassBuilder) {
parent = cls; parent = cls;
dietListener dietListener
@ -304,7 +305,7 @@ class SourceLoader<L> extends Loader<L> {
wasChanged = false; wasChanged = false;
for (SourceLibraryBuilder exported in both) { for (SourceLibraryBuilder exported in both) {
for (Export export in exported.exporters) { for (Export export in exported.exporters) {
exported.exportScope.forEach((String name, Builder member) { exported.exportScope.forEach((String name, Declaration member) {
if (export.addToExportScope(name, member)) { if (export.addToExportScope(name, member)) {
wasChanged = true; wasChanged = true;
} }
@ -333,15 +334,15 @@ class SourceLoader<L> extends Loader<L> {
// TODO(sigmund): should be `covarint SourceLibraryBuilder`. // TODO(sigmund): should be `covarint SourceLibraryBuilder`.
builders.forEach((Uri uri, dynamic l) { builders.forEach((Uri uri, dynamic l) {
SourceLibraryBuilder library = l; SourceLibraryBuilder library = l;
Set<Builder> members = new Set<Builder>(); Set<Declaration> members = new Set<Declaration>();
library.forEach((String name, Builder member) { library.forEach((String name, Declaration member) {
while (member != null) { while (member != null) {
members.add(member); members.add(member);
member = member.next; member = member.next;
} }
}); });
List<String> exports = <String>[]; List<String> exports = <String>[];
library.exportScope.forEach((String name, Builder member) { library.exportScope.forEach((String name, Declaration member) {
while (member != null) { while (member != null) {
if (!members.contains(member)) { if (!members.contains(member)) {
exports.add(name); exports.add(name);
@ -553,10 +554,11 @@ class SourceLoader<L> extends Loader<L> {
if (mixedInType != null) { if (mixedInType != null) {
bool isClassBuilder = false; bool isClassBuilder = false;
if (mixedInType is NamedTypeBuilder) { if (mixedInType is NamedTypeBuilder) {
var builder = mixedInType.builder; var builder = mixedInType.declaration;
if (builder is ClassBuilder) { if (builder is ClassBuilder) {
isClassBuilder = true; isClassBuilder = true;
for (Builder constructory in builder.constructors.local.values) { for (Declaration constructory
in builder.constructors.local.values) {
if (constructory.isConstructor && !constructory.isSynthetic) { if (constructory.isConstructor && !constructory.isSynthetic) {
cls.addCompileTimeError( cls.addCompileTimeError(
templateIllegalMixinDueToConstructors templateIllegalMixinDueToConstructors

View file

@ -6,7 +6,7 @@ library fasta.target_implementation;
import 'package:kernel/target/targets.dart' as backend show Target; import 'package:kernel/target/targets.dart' as backend show Target;
import 'builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; import 'builder/builder.dart' show Declaration, ClassBuilder, LibraryBuilder;
import 'compiler_context.dart' show CompilerContext; import 'compiler_context.dart' show CompilerContext;
@ -26,12 +26,12 @@ abstract class TargetImplementation extends Target {
final CompilerContext context = CompilerContext.current; final CompilerContext context = CompilerContext.current;
Builder cachedAbstractClassInstantiationError; Declaration cachedAbstractClassInstantiationError;
Builder cachedCompileTimeError; Declaration cachedCompileTimeError;
Builder cachedDuplicatedFieldInitializerError; Declaration cachedDuplicatedFieldInitializerError;
Builder cachedFallThroughError; Declaration cachedFallThroughError;
Builder cachedNativeAnnotation; Declaration cachedNativeAnnotation;
Builder cachedNativeExtensionAnnotation; Declaration cachedNativeExtensionAnnotation;
TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget) TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget)
: super(ticker); : super(ticker);
@ -60,7 +60,7 @@ abstract class TargetImplementation extends Target {
/// [AbstractClassInstantiationError] error. The constructor is expected to /// [AbstractClassInstantiationError] error. The constructor is expected to
/// accept a single argument of type String, which is the name of the /// accept a single argument of type String, which is the name of the
/// abstract class. /// abstract class.
Builder getAbstractClassInstantiationError(Loader loader) { Declaration getAbstractClassInstantiationError(Loader loader) {
if (cachedAbstractClassInstantiationError != null) { if (cachedAbstractClassInstantiationError != null) {
return cachedAbstractClassInstantiationError; return cachedAbstractClassInstantiationError;
} }
@ -71,7 +71,7 @@ abstract class TargetImplementation extends Target {
/// Returns a reference to the constructor used for creating a compile-time /// Returns a reference to the constructor used for creating a compile-time
/// error. The constructor is expected to accept a single argument of type /// error. The constructor is expected to accept a single argument of type
/// String, which is the compile-time error message. /// String, which is the compile-time error message.
Builder getCompileTimeError(Loader loader) { Declaration getCompileTimeError(Loader loader) {
if (cachedCompileTimeError != null) return cachedCompileTimeError; if (cachedCompileTimeError != null) return cachedCompileTimeError;
return cachedCompileTimeError = loader.coreLibrary return cachedCompileTimeError = loader.coreLibrary
.getConstructor("_CompileTimeError", bypassLibraryPrivacy: true); .getConstructor("_CompileTimeError", bypassLibraryPrivacy: true);
@ -80,7 +80,7 @@ abstract class TargetImplementation extends Target {
/// Returns a reference to the constructor used for creating a runtime error /// Returns a reference to the constructor used for creating a runtime error
/// when a final field is initialized twice. The constructor is expected to /// when a final field is initialized twice. The constructor is expected to
/// accept a single argument which is the name of the field. /// accept a single argument which is the name of the field.
Builder getDuplicatedFieldInitializerError(Loader loader) { Declaration getDuplicatedFieldInitializerError(Loader loader) {
if (cachedDuplicatedFieldInitializerError != null) { if (cachedDuplicatedFieldInitializerError != null) {
return cachedDuplicatedFieldInitializerError; return cachedDuplicatedFieldInitializerError;
} }
@ -92,7 +92,7 @@ abstract class TargetImplementation extends Target {
/// Returns a reference to the constructor used for creating `native` /// Returns a reference to the constructor used for creating `native`
/// annotations. The constructor is expected to accept a single argument of /// annotations. The constructor is expected to accept a single argument of
/// type String, which is the name of the native method. /// type String, which is the name of the native method.
Builder getNativeAnnotation(Loader loader) { Declaration getNativeAnnotation(Loader loader) {
if (cachedNativeAnnotation != null) return cachedNativeAnnotation; if (cachedNativeAnnotation != null) return cachedNativeAnnotation;
LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1); LibraryBuilder internal = loader.read(Uri.parse("dart:_internal"), -1);
return cachedNativeAnnotation = internal.getConstructor("ExternalName"); return cachedNativeAnnotation = internal.getConstructor("ExternalName");

View file

@ -29,7 +29,9 @@ static const field dynamic #errors = const <dynamic>["pkg/front_end/testcases/qu
lib.Missing method() {} lib.Missing method() {}
^", "pkg/front_end/testcases/qualified.dart:11:19: Error: Type 'lib.Missing' not found. ^", "pkg/front_end/testcases/qualified.dart:11:19: Error: Type 'lib.Missing' not found.
class Bad extends lib.Missing { class Bad extends lib.Missing {
^", "pkg/front_end/testcases/qualified.dart: Error: Couldn't find constructor 'WrongName'."]/* from null */; ^", "pkg/front_end/testcases/qualified.dart:13:11: Error: Couldn't find constructor 'WrongName'.
factory WrongName() {}
^"]/* from null */;
static method main() → dynamic { static method main() → dynamic {
new self::C::•<core::String>(); new self::C::•<core::String>();
new self::C::a<core::String>(); new self::C::a<core::String>();

View file

@ -35,7 +35,9 @@ static const field dynamic #errors = const <dynamic>["pkg/front_end/testcases/qu
lib.Missing method() {} lib.Missing method() {}
^", "pkg/front_end/testcases/qualified.dart:11:19: Error: Type 'lib.Missing' not found. ^", "pkg/front_end/testcases/qualified.dart:11:19: Error: Type 'lib.Missing' not found.
class Bad extends lib.Missing { class Bad extends lib.Missing {
^", "pkg/front_end/testcases/qualified.dart: Error: Couldn't find constructor 'WrongName'."]/* from null */; ^", "pkg/front_end/testcases/qualified.dart:13:11: Error: Couldn't find constructor 'WrongName'.
factory WrongName() {}
^"]/* from null */;
static method main() → dynamic { static method main() → dynamic {
new self::C::•<core::String>(); new self::C::•<core::String>();
new self::C::a<core::String>(); new self::C::a<core::String>();