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

Unified Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1383503002: Add Resolution and Parsing interfaces for computeType, ensureResolved and parseNode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add TODOs. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/elements/modelx.dart
diff --git a/pkg/compiler/lib/src/elements/modelx.dart b/pkg/compiler/lib/src/elements/modelx.dart
index c576f8d0e59ca10b15793688dabbf8af8b1e46d8..f1d4c5bb04fe6dd1ea4afdecb656901fe57a8e12 100644
--- a/pkg/compiler/lib/src/elements/modelx.dart
+++ b/pkg/compiler/lib/src/elements/modelx.dart
@@ -4,6 +4,9 @@
library elements.modelx;
+import '../common/resolution.dart' show
+ Resolution,
+ Parsing;
import '../compiler.dart' show
Compiler;
import '../constants/constant_constructors.dart';
@@ -67,8 +70,8 @@ abstract class ElementX extends Element with ElementCommon {
Modifiers get modifiers => Modifiers.EMPTY;
- Node parseNode(DiagnosticListener listener) {
- listener.internalError(this,
+ Node parseNode(Parsing parsing) {
+ parsing.listener.internalError(this,
'parseNode not implemented on $this.');
return null;
}
@@ -312,8 +315,8 @@ class ErroneousElementX extends ElementX implements ErroneousElement {
bool get isRedirectingGenerative => unsupported();
bool get isRedirectingFactory => unsupported();
- computeSignature(compiler) => unsupported();
- computeType(compiler) => unsupported();
+ computeSignature(Resolution resolution) => unsupported();
+ computeType(Resolution resolution) => unsupported();
bool get hasFunctionSignature => false;
@@ -1281,7 +1284,7 @@ class PrefixElementX extends ElementX implements PrefixElement {
Element lookupLocalMember(String memberName) => importScope[memberName];
- DartType computeType(Compiler compiler) => const DynamicType();
+ DartType computeType(Resolution resolution) => const DynamicType();
Token get position => firstPosition;
@@ -1336,17 +1339,17 @@ class TypedefElementX extends ElementX
*/
FunctionSignature functionSignature;
- TypedefType computeType(Compiler compiler) {
+ TypedefType computeType(Resolution resolution) {
if (thisTypeCache != null) return thisTypeCache;
- Typedef node = parseNode(compiler);
- setThisAndRawTypes(compiler, createTypeVariables(node.typeParameters));
- ensureResolved(compiler);
+ Typedef node = parseNode(resolution.parsing);
+ setThisAndRawTypes(createTypeVariables(node.typeParameters));
+ ensureResolved(resolution);
return thisTypeCache;
}
- void ensureResolved(Compiler compiler) {
+ void ensureResolved(Resolution resolution) {
if (resolutionState == STATE_NOT_STARTED) {
- compiler.resolver.resolve(this);
+ resolution.resolveTypedef(this);
}
}
@@ -1358,10 +1361,10 @@ class TypedefElementX extends ElementX
return new TypeDeclarationScope(enclosingElement.buildScope(), this);
}
- void checkCyclicReference(Compiler compiler) {
+ void checkCyclicReference(Resolution resolution) {
if (hasBeenCheckedForCycles) return;
- var visitor = new TypedefCyclicVisitor(compiler, this);
- computeType(compiler).accept(visitor, null);
+ var visitor = new TypedefCyclicVisitor(resolution.listener, this);
+ computeType(resolution).accept(visitor, null);
hasBeenCheckedForCycles = true;
}
@@ -1409,11 +1412,11 @@ class VariableList implements DeclarationSite {
metadataInternal = metadata;
}
- VariableDefinitions parseNode(Element element, DiagnosticListener listener) {
+ VariableDefinitions parseNode(Element element, Parsing parsing) {
return definitions;
}
- DartType computeType(Element element, Compiler compiler) => type;
+ DartType computeType(Element element, Resolution resolution) => type;
}
abstract class ConstantVariableMixin implements VariableElement {
@@ -1492,10 +1495,10 @@ abstract class VariableElementX extends ElementX
return initializerCache;
}
- Node parseNode(DiagnosticListener listener) {
+ Node parseNode(Parsing parsing) {
if (definitionsCache != null) return definitionsCache;
- VariableDefinitions definitions = variables.parseNode(this, listener);
+ VariableDefinitions definitions = variables.parseNode(this, parsing);
createDefinitions(definitions);
return definitionsCache;
}
@@ -1535,14 +1538,12 @@ abstract class VariableElementX extends ElementX
}
}
- DartType computeType(Compiler compiler) {
+ DartType computeType(Resolution resolution) {
if (variables.type != null) return variables.type;
// Call [parseNode] to ensure that [definitionsCache] and [initializerCache]
// are set as a consequence of calling [computeType].
- return compiler.withCurrentElement(this, () {
- parseNode(compiler);
- return variables.computeType(this, compiler);
- });
+ parseNode(resolution.parsing);
+ return variables.computeType(this, resolution);
}
DartType get type {
@@ -1683,7 +1684,7 @@ class ErroneousFieldElementX extends ElementX
throw new UnsupportedError("copyWithEnclosing");
}
- DartType computeType(Compiler compiler) => type;
+ DartType computeType(Resolution resolution) => type;
}
/// [Element] for a parameter-like element.
@@ -1714,9 +1715,9 @@ class FormalElementX extends ElementX
Token get position => identifier.getBeginToken();
- Node parseNode(DiagnosticListener listener) => definitions;
+ Node parseNode(Parsing parsing) => definitions;
- DartType computeType(Compiler compiler) {
+ DartType computeType(Resolution resolution) {
assert(invariant(this, type != null,
message: "Parameter type has not been set for $this."));
return type;
@@ -1869,7 +1870,7 @@ class AbstractFieldElementX extends ElementX implements AbstractFieldElement {
throw "internal error: AbstractFieldElement has no type";
}
- Node parseNode(DiagnosticListener listener) {
+ Node parseNode(Parsing parsing) {
throw "internal error: AbstractFieldElement has no node";
}
@@ -1973,11 +1974,9 @@ abstract class BaseFunctionElementX
bool get hasFunctionSignature => functionSignatureCache != null;
- FunctionSignature computeSignature(Compiler compiler) {
+ FunctionSignature computeSignature(Resolution resolution) {
if (functionSignatureCache != null) return functionSignatureCache;
- compiler.withCurrentElement(this, () {
- functionSignatureCache = compiler.resolver.resolveSignature(this);
- });
+ functionSignatureCache = resolution.resolveSignature(this);
return functionSignatureCache;
}
@@ -1995,9 +1994,9 @@ abstract class BaseFunctionElementX
return list;
}
- FunctionType computeType(Compiler compiler) {
+ FunctionType computeType(Resolution resolution) {
if (typeCache != null) return typeCache;
- typeCache = computeSignature(compiler).type;
+ typeCache = computeSignature(resolution).type;
return typeCache;
}
@@ -2114,7 +2113,7 @@ class LocalFunctionElementX extends BaseFunctionElementX
bool get hasNode => true;
- FunctionExpression parseNode(DiagnosticListener listener) => node;
+ FunctionExpression parseNode(Parsing parsing) => node;
Token get position {
// Use the name as position if this is not an unnamed closure.
@@ -2235,12 +2234,10 @@ class DeferredLoaderGetterElementX extends GetterElementX
prefix,
false);
- FunctionSignature computeSignature(Compiler compiler) {
+ FunctionSignature computeSignature(Resolution resolution) {
if (functionSignatureCache != null) return functionSignature;
- compiler.withCurrentElement(this, () {
- DartType inner = new FunctionType(this);
- functionSignatureCache = new FunctionSignatureX(type: inner);
- });
+ functionSignatureCache =
+ new FunctionSignatureX(type: new FunctionType(this));
return functionSignatureCache;
}
@@ -2255,7 +2252,7 @@ class DeferredLoaderGetterElementX extends GetterElementX
// error messages.
Token get position => null;
- FunctionExpression parseNode(DiagnosticListener listener) => null;
+ FunctionExpression parseNode(Parsing parsing) => null;
bool get hasNode => false;
@@ -2286,8 +2283,8 @@ class ConstructorBodyElementX extends BaseFunctionElementX
bool get isInstanceMember => true;
- FunctionType computeType(Compiler compiler) {
- compiler.internalError(this, '$this.computeType.');
+ FunctionType computeType(Resolution resolution) {
+ resolution.listener.internalError(this, '$this.computeType.');
return null;
}
@@ -2335,7 +2332,7 @@ class SynthesizedConstructorElementX extends ConstructorElementX {
functionSignatureCache = new FunctionSignatureX(type: type);
}
- FunctionExpression parseNode(DiagnosticListener listener) => null;
+ FunctionExpression parseNode(Parsing parsing) => null;
bool get hasNode => false;
@@ -2355,15 +2352,15 @@ class SynthesizedConstructorElementX extends ConstructorElementX {
}
}
- FunctionSignature computeSignature(compiler) {
+ FunctionSignature computeSignature(Resolution resolution) {
if (functionSignatureCache != null) return functionSignatureCache;
if (definingConstructor.isErroneous) {
- return functionSignatureCache =
- compiler.objectClass.localLookup('').computeSignature(compiler);
+ typeCache = new FunctionType.synthesized(enclosingClass.thisType);
+ return functionSignatureCache = new FunctionSignatureX(type: type);
}
// TODO(johnniwinther): Ensure that the function signature (and with it the
// function type) substitutes type variables correctly.
- definingConstructor.computeType(compiler);
+ definingConstructor.computeType(resolution);
functionSignatureCache = definingConstructor.functionSignature;
typeCache = definingConstructor.type;
return functionSignatureCache;
@@ -2423,7 +2420,7 @@ abstract class TypeDeclarationElementX<T extends GenericType>
T createType(List<DartType> typeArguments);
- void setThisAndRawTypes(Compiler compiler, List<DartType> typeParameters) {
+ void setThisAndRawTypes(List<DartType> typeParameters) {
assert(invariant(this, thisTypeCache == null,
message: "This type has already been set on $this."));
assert(invariant(this, rawTypeCache == null,
@@ -2510,23 +2507,25 @@ abstract class BaseClassElementX extends ElementX
@override
bool get isEnumClass => false;
- InterfaceType computeType(Compiler compiler) {
+ InterfaceType computeType(Resolution resolution) {
if (isPatch) {
- origin.computeType(compiler);
+ origin.computeType(resolution);
thisTypeCache = origin.thisType;
rawTypeCache = origin.rawType;
} else if (thisTypeCache == null) {
- computeThisAndRawType(compiler, computeTypeParameters(compiler));
+ computeThisAndRawType(
+ resolution, computeTypeParameters(resolution.parsing));
}
return thisTypeCache;
}
- void computeThisAndRawType(Compiler compiler, List<DartType> typeVariables) {
+ void computeThisAndRawType(Resolution resolution,
+ List<DartType> typeVariables) {
if (thisTypeCache == null) {
if (origin == null) {
- setThisAndRawTypes(compiler, typeVariables);
+ setThisAndRawTypes(typeVariables);
} else {
- thisTypeCache = origin.computeType(compiler);
+ thisTypeCache = origin.computeType(resolution);
rawTypeCache = origin.rawType;
}
}
@@ -2537,7 +2536,7 @@ abstract class BaseClassElementX extends ElementX
return new InterfaceType(this, typeArguments);
}
- List<DartType> computeTypeParameters(Compiler compiler);
+ List<DartType> computeTypeParameters(Parsing parsing);
bool get isObject {
assert(invariant(this, isResolved,
@@ -2545,14 +2544,15 @@ abstract class BaseClassElementX extends ElementX
return supertype == null;
}
- void ensureResolved(Compiler compiler) {
+ void ensureResolved(Resolution resolution) {
if (resolutionState == STATE_NOT_STARTED) {
- compiler.resolver.resolveClass(this);
- compiler.world.registerClass(this);
+ resolution.resolveClass(this);
+ resolution.registerClass(this);
}
}
- void setDefaultConstructor(FunctionElement constructor, Compiler compiler);
+ void setDefaultConstructor(FunctionElement constructor,
+ DiagnosticListener listener);
void addBackendMember(Element member) {
// TODO(ngeoffray): Deprecate this method.
@@ -2679,13 +2679,14 @@ abstract class ClassElementX extends BaseClassElementX {
return false;
}
- void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
+ void setDefaultConstructor(FunctionElement constructor,
+ DiagnosticListener listener) {
// The default constructor, although synthetic, is part of a class' API.
- addMember(constructor, compiler);
+ addMember(constructor, listener);
}
- List<DartType> computeTypeParameters(Compiler compiler) {
- ClassNode node = parseNode(compiler);
+ List<DartType> computeTypeParameters(Parsing parsing) {
+ ClassNode node = parseNode(parsing);
return createTypeVariables(node.typeParameters);
}
@@ -2719,14 +2720,14 @@ class EnumClassElementX extends ClassElementX implements EnumClassElement {
bool get isEnumClass => true;
@override
- Node parseNode(Compiler compiler) => node;
+ Node parseNode(Parsing parsing) => node;
@override
accept(ElementVisitor visitor, arg) {
return visitor.visitEnumClassElement(this, arg);
}
- List<DartType> computeTypeParameters(Compiler compiler) => const <DartType>[];
+ List<DartType> computeTypeParameters(Parsing parsing) => const <DartType>[];
List<FieldElement> get enumValues {
assert(invariant(this, _enumValues != null,
@@ -2756,7 +2757,7 @@ class EnumConstructorElementX extends ConstructorElementX {
bool get hasNode => true;
@override
- FunctionExpression parseNode(Compiler compiler) => node;
+ FunctionExpression parseNode(Parsing parsing) => node;
}
class EnumMethodElementX extends MethodElementX {
@@ -2772,7 +2773,7 @@ class EnumMethodElementX extends MethodElementX {
bool get hasNode => true;
@override
- FunctionExpression parseNode(Compiler compiler) => node;
+ FunctionExpression parseNode(Parsing parsing) => node;
}
class EnumFormalElementX extends InitializingFormalElementX {
@@ -2826,7 +2827,7 @@ class MixinApplicationElementX extends BaseClassElementX
Token get position => node.getBeginToken();
- Node parseNode(DiagnosticListener listener) => node;
+ Node parseNode(Parsing parsing) => node;
FunctionElement lookupLocalConstructor(String name) {
for (Link<Element> link = constructors;
@@ -2865,12 +2866,13 @@ class MixinApplicationElementX extends BaseClassElementX
constructors = constructors.prepend(constructor);
}
- void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
+ void setDefaultConstructor(FunctionElement constructor,
+ DiagnosticListener listener) {
assert(!hasConstructor);
addConstructor(constructor);
}
- List<DartType> computeTypeParameters(Compiler compiler) {
+ List<DartType> computeTypeParameters(Parsing parsing) {
NamedMixinApplication named = node.asNamedMixinApplication();
if (named == null) {
throw new SpannableAssertionFailure(node,
@@ -2955,7 +2957,7 @@ class TypeVariableElementX extends ElementX with AstElementMixin
TypeDeclarationElement get typeDeclaration => enclosingElement;
- TypeVariableType computeType(compiler) => type;
+ TypeVariableType computeType(Resolution resolution) => type;
TypeVariableType get type {
assert(invariant(this, typeCache != null,
@@ -2971,7 +2973,7 @@ class TypeVariableElementX extends ElementX with AstElementMixin
bool get hasNode => true;
- Node parseNode(compiler) => node;
+ Node parseNode(Parsing parsing) => node;
Token get position => node.getBeginToken();
@@ -3023,18 +3025,18 @@ abstract class MetadataAnnotationX implements MetadataAnnotation {
MetadataAnnotationX([this.resolutionState = STATE_NOT_STARTED]);
- MetadataAnnotation ensureResolved(Compiler compiler) {
+ MetadataAnnotation ensureResolved(Resolution resolution) {
if (annotatedElement.isClass || annotatedElement.isTypedef) {
TypeDeclarationElement typeDeclaration = annotatedElement;
- typeDeclaration.ensureResolved(compiler);
+ typeDeclaration.ensureResolved(resolution);
}
if (resolutionState == STATE_NOT_STARTED) {
- compiler.resolver.resolveMetadataAnnotation(this);
+ resolution.resolveMetadataAnnotation(this);
}
return this;
}
- Node parseNode(DiagnosticListener listener);
+ Node parseNode(Parsing parsing);
String toString() => 'MetadataAnnotation($constant, $resolutionState)';
}
@@ -3045,7 +3047,7 @@ class ParameterMetadataAnnotation extends MetadataAnnotationX {
ParameterMetadataAnnotation(Metadata this.metadata);
- Node parseNode(DiagnosticListener listener) => metadata.expression;
+ Node parseNode(Parsing parsing) => metadata.expression;
Token get beginToken => metadata.getBeginToken();
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698