Chromium Code Reviews| 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..06383d41a030f49d67b38fe112707bef13982d2a 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,21 @@ 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); |
| } |
| void registerStaticUse(Element element) { |
| @@ -73,7 +76,14 @@ class ConstantHandler extends CompilerTask { |
| } |
| void registerStringInstance(TreeElements elements) { |
| - registerInstantiatedClass(compiler.stringClass, elements); |
| + registerInstantiatedType(compiler.stringClass.rawType, elements); |
| + } |
| + |
| + void registerSetRuntimeTypeInfoFunction() { |
| + if (setRuntimeTypeInfoFunction != null) return; |
|
ngeoffray
2013/06/17 09:15:03
In non-checked mode, how do you make sure this hel
karlklose
2013/06/19 15:29:05
Added a check.
|
| + SourceString helperName = const SourceString('setRuntimeTypeInfo'); |
| + setRuntimeTypeInfoFunction = compiler.findHelper(helperName); |
| + registerStaticUse(setRuntimeTypeInfoFunction); |
| } |
| void registerCreateRuntimeTypeFunction() { |
| @@ -318,17 +328,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 +352,11 @@ 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); |
| + if (!type.isRaw) { |
| + handler.registerSetRuntimeTypeInfoFunction(); |
|
ngeoffray
2013/06/17 09:15:03
Move this check to [registerInstantiatedType]?
karlklose
2013/06/19 15:29:05
Done.
|
| + } |
| Constant constant = new ListConstant(type, arguments); |
| handler.registerCompileTimeConstant(constant, elements); |
| return constant; |
| @@ -379,9 +391,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 +402,12 @@ 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); |
| + if (!type.isRaw) { |
|
ngeoffray
2013/06/17 09:15:03
Ditto.
karlklose
2013/06/19 15:29:05
Done.
|
| + handler.registerSetRuntimeTypeInfoFunction(); |
| + } |
| Constant constant = new MapConstant(type, keysList, values, protoValue); |
| handler.registerCompileTimeConstant(constant, elements); |
| return constant; |
| @@ -445,7 +461,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 +665,8 @@ class CompileTimeConstantEvaluator extends Visitor { |
| } |
| Send send = node.send; |
| - FunctionElement constructor = elements[send]; |
| + FunctionElement functionElement = elements[send]; |
| + FunctionElement constructor = functionElement; |
|
ngeoffray
2013/06/17 09:15:03
What is this double assignment for? If line 678 ch
karlklose
2013/06/19 15:29:05
Yes, this is left-over code. Removed.
|
| // 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 +686,16 @@ 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); |
| + if (type is InterfaceType && !type.isRaw) { |
| + handler.registerSetRuntimeTypeInfoFunction(); |
| + } |
| Constant constant = new ConstructedConstant(type, jsNewArguments); |
| handler.registerCompileTimeConstant(constant, elements); |
| return constant; |