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

Unified Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 16549004: Add type arguments to constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
index ecc8645823df3bf0d40b733657bf6dc2bac1a783..a815e25a5d0bc0b093d8ec32a3b765fd3073a977 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -32,6 +32,9 @@ class ConstantHandler extends CompilerTask {
/** Caches the createRuntimeType function if registered. */
Element createRuntimeTypeFunction = null;
+ /** Caches the setRuntimeTypeInfo function if registered. */
+ Element setRuntimeTypeInfoFunction = null;
+
ConstantHandler(Compiler compiler, this.constantSystem,
{ bool this.isMetadata: false })
: initialVariableValues = new Map<VariableElement, dynamic>(),
@@ -43,21 +46,25 @@ class ConstantHandler extends CompilerTask {
String get name => 'ConstantHandler';
void registerCompileTimeConstant(Constant constant, TreeElements elements) {
- registerInstantiatedClass(constant.computeType(compiler).element, elements);
+ registerInstantiatedType(constant.computeType(compiler), elements);
if (constant.isFunction()) {
FunctionConstant function = constant;
registerGetOfStaticFunction(function.element);
} else if (constant.isInterceptor()) {
// An interceptor constant references the class's prototype chain.
InterceptorConstant interceptor = constant;
- registerInstantiatedClass(interceptor.dispatchedType.element, elements);
+ registerInstantiatedType(interceptor.dispatchedType, elements);
}
compiledConstants.add(constant);
}
- void registerInstantiatedClass(ClassElement element, TreeElements elements) {
+ void registerInstantiatedType(DartType type, TreeElements elements) {
if (isMetadata) return;
- compiler.enqueuer.codegen.registerInstantiatedClass(element, elements);
+ compiler.enqueuer.codegen.registerInstantiatedType(type, elements);
+ if (type is InterfaceType && !type.isRaw &&
ngeoffray 2013/06/19 19:55:48 nit: move !type.isRaw to a new line.
karlklose 2013/06/20 12:49:21 Done.
+ compiler.backend.needsRti(type.element)) {
+ registerSetRuntimeTypeInfoFunction();
+ }
}
void registerStaticUse(Element element) {
@@ -73,7 +80,14 @@ class ConstantHandler extends CompilerTask {
}
void registerStringInstance(TreeElements elements) {
- registerInstantiatedClass(compiler.stringClass, elements);
+ registerInstantiatedType(compiler.stringClass.rawType, elements);
+ }
+
+ void registerSetRuntimeTypeInfoFunction() {
+ if (setRuntimeTypeInfoFunction != null) return;
+ SourceString helperName = const SourceString('setRuntimeTypeInfo');
+ setRuntimeTypeInfoFunction = compiler.findHelper(helperName);
+ registerStaticUse(setRuntimeTypeInfoFunction);
}
void registerCreateRuntimeTypeFunction() {
@@ -318,17 +332,17 @@ class CompileTimeConstantEvaluator extends Visitor {
}
Constant visitLiteralBool(LiteralBool node) {
- handler.registerInstantiatedClass(compiler.boolClass, elements);
+ handler.registerInstantiatedType(compiler.boolClass.rawType, elements);
return constantSystem.createBool(node.value);
}
Constant visitLiteralDouble(LiteralDouble node) {
- handler.registerInstantiatedClass(compiler.doubleClass, elements);
+ handler.registerInstantiatedType(compiler.doubleClass.rawType, elements);
return constantSystem.createDouble(node.value);
}
Constant visitLiteralInt(LiteralInt node) {
- handler.registerInstantiatedClass(compiler.intClass, elements);
+ handler.registerInstantiatedType(compiler.intClass.rawType, elements);
return constantSystem.createInt(node.value);
}
@@ -342,9 +356,8 @@ class CompileTimeConstantEvaluator extends Visitor {
link = link.tail) {
arguments.add(evaluateConstant(link.head));
}
- // TODO(9476): get type parameters.
- compiler.listClass.computeType(compiler);
- DartType type = compiler.listClass.rawType;
+ DartType type = elements.getType(node);
+ handler.registerInstantiatedType(type, elements);
Constant constant = new ListConstant(type, arguments);
handler.registerCompileTimeConstant(constant, elements);
return constant;
@@ -379,9 +392,10 @@ class CompileTimeConstantEvaluator extends Visitor {
}
}
bool hasProtoKey = (protoValue != null);
- // TODO(9476): this should be a List<String> type.
- compiler.listClass.computeType(compiler);
- DartType keysType = compiler.listClass.rawType;
+ InterfaceType sourceType = elements.getType(node);
+ Link<DartType> arguments =
+ new Link<DartType>.fromList([compiler.stringClass.rawType]);
+ DartType keysType = new InterfaceType(compiler.listClass, arguments);
ListConstant keysList = new ListConstant(keysType, keys);
handler.registerCompileTimeConstant(keysList, elements);
SourceString className = hasProtoKey
@@ -389,9 +403,9 @@ class CompileTimeConstantEvaluator extends Visitor {
: MapConstant.DART_CLASS;
ClassElement classElement = compiler.jsHelperLibrary.find(className);
classElement.ensureResolved(compiler);
- // TODO(9476): copy over the generic type.
- DartType type = classElement.rawType;
- handler.registerInstantiatedClass(classElement, elements);
+ Link<DartType> typeArgument = sourceType.typeArguments.tail;
+ InterfaceType type = new InterfaceType(classElement, typeArgument);
+ handler.registerInstantiatedType(type, elements);
Constant constant = new MapConstant(type, keysList, values, protoValue);
handler.registerCompileTimeConstant(constant, elements);
return constant;
@@ -445,7 +459,7 @@ class CompileTimeConstantEvaluator extends Visitor {
Constant makeTypeConstant(Element element) {
DartType elementType = element.computeType(compiler).asRaw();
if (compiler.mirrorsEnabled) {
- handler.registerInstantiatedClass(element, elements);
+ handler.registerInstantiatedType(elementType, elements);
}
DartType constantType =
compiler.backend.typeImplementation.computeType(compiler);
@@ -649,7 +663,8 @@ class CompileTimeConstantEvaluator extends Visitor {
}
Send send = node.send;
- FunctionElement constructor = elements[send];
+ FunctionElement functionElement = elements[send];
+ FunctionElement constructor = functionElement;
ngeoffray 2013/06/19 19:55:48 Didn't you say you removed this?
karlklose 2013/06/20 12:49:21 It was needed to preserve the original constructor
// TODO(ahe): This is nasty: we must eagerly analyze the
// constructor to ensure the redirectionTarget has been computed
// correctly. Find a way to avoid this.
@@ -669,10 +684,13 @@ class CompileTimeConstantEvaluator extends Visitor {
evaluator.evaluateConstructorFieldValues(arguments);
List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement);
- handler.registerInstantiatedClass(classElement, elements);
- // TODO(9476): take generic types into account.
- classElement.computeType(compiler);
- DartType type = classElement.rawType;
+ InterfaceType type = elements.getType(node);
+ bool isRedirected = functionElement.isRedirectingFactory;
+ if (isRedirected) {
+ type = functionElement.computeTargetType(compiler, type);
+ }
+
+ handler.registerInstantiatedType(type, elements);
Constant constant = new ConstructedConstant(type, jsNewArguments);
handler.registerCompileTimeConstant(constant, elements);
return constant;

Powered by Google App Engine
This is Rietveld 408576698