Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 } | 966 } |
| 967 } | 967 } |
| 968 if (classElement.superclass != compiler.coreLibrary.find(Types.OBJECT)) { | 968 if (classElement.superclass != compiler.coreLibrary.find(Types.OBJECT)) { |
| 969 compiler.unimplemented("ConstantHandler with super", node: node); | 969 compiler.unimplemented("ConstantHandler with super", node: node); |
| 970 } | 970 } |
| 971 return jsNewArguments; | 971 return jsNewArguments; |
| 972 } | 972 } |
| 973 | 973 |
| 974 if (!node.isConst()) error(node); | 974 if (!node.isConst()) error(node); |
| 975 | 975 |
| 976 FunctionElement constructor = elements[node.send]; | |
| 977 compiler.resolver.resolveMethodElement(constructor); | |
| 978 constructor = constructor.defaultImplementation; | |
| 979 | |
| 980 ClassElement classElement = constructor.enclosingElement; | |
| 976 // TODO(floitsch): get the type from somewhere. | 981 // TODO(floitsch): get the type from somewhere. |
|
ngeoffray
2012/03/18 13:56:04
Why is classElement.computeType(compiler) not suff
floitsch
2012/03/18 18:44:15
It doesn't take generic types into account. But be
| |
| 977 FunctionElement constructor = elements[node.send]; | 982 Type type = new SimpleType(classElement.name, classElement); |
| 978 ClassElement classElement = constructor.enclosingElement; | |
| 979 TreeElements constructorElements = | 983 TreeElements constructorElements = |
| 980 compiler.resolver.resolveMethodElement(constructor); | 984 compiler.resolver.resolveMethodElement(constructor); |
|
ngeoffray
2012/03/18 13:56:04
You could avoid calling resolveMethodElement twice
floitsch
2012/03/18 18:44:15
Done.
| |
| 981 FunctionExpression functionNode = constructor.parseNode(compiler); | 985 FunctionExpression functionNode = constructor.parseNode(compiler); |
| 982 NodeList initializerList = functionNode.initializers; | 986 NodeList initializerList = functionNode.initializers; |
| 983 FunctionParameters parameters = constructor.computeParameters(compiler); | 987 FunctionParameters parameters = constructor.computeParameters(compiler); |
| 984 | 988 |
| 985 Map<Element, Constant> fieldValues = new Map<Element, Constant>(); | 989 Map<Element, Constant> fieldValues = new Map<Element, Constant>(); |
| 986 Map<Element, Constant> constructorDefinitions = | 990 Map<Element, Constant> constructorDefinitions = |
| 987 new Map<Element, Constant>(); | 991 new Map<Element, Constant>(); |
| 988 | 992 |
| 989 assignArgumentsToParameters(parameters, constructorDefinitions, | 993 assignArgumentsToParameters(parameters, constructorDefinitions, |
| 990 fieldValues); | 994 fieldValues); |
| 991 CompileTimeConstantEvaluator initializerEvaluator = | 995 CompileTimeConstantEvaluator initializerEvaluator = |
| 992 new CompileTimeConstantEvaluator.insideConstructor( | 996 new CompileTimeConstantEvaluator.insideConstructor( |
| 993 constantHandler, constructorElements, compiler, | 997 constantHandler, constructorElements, compiler, |
| 994 constructorDefinitions); | 998 constructorDefinitions); |
| 995 if (initializerList !== null) { | 999 if (initializerList !== null) { |
| 996 Link<Node> initializers = functionNode.initializers.nodes; | 1000 Link<Node> initializers = functionNode.initializers.nodes; |
| 997 compileInitializers(initializers, | 1001 compileInitializers(initializers, |
| 998 initializerEvaluator, | 1002 initializerEvaluator, |
| 999 constructorElements, | 1003 constructorElements, |
| 1000 constructorDefinitions, | 1004 constructorDefinitions, |
| 1001 fieldValues); | 1005 fieldValues); |
| 1002 } | 1006 } |
| 1003 List<Constant> jsNewArguments = | 1007 List<Constant> jsNewArguments = |
| 1004 buildJsNewArguments(classElement, fieldValues); | 1008 buildJsNewArguments(classElement, fieldValues); |
| 1005 | 1009 |
| 1006 compiler.registerInstantiatedClass(classElement); | 1010 compiler.registerInstantiatedClass(classElement); |
| 1007 Type type = new SimpleType(classElement.name, classElement); | |
| 1008 Constant constant = new ConstructedConstant(type, jsNewArguments); | 1011 Constant constant = new ConstructedConstant(type, jsNewArguments); |
| 1009 constantHandler.registerCompileTimeConstant(constant); | 1012 constantHandler.registerCompileTimeConstant(constant); |
| 1010 return constant; | 1013 return constant; |
| 1011 } | 1014 } |
| 1012 | 1015 |
| 1013 error(Node node) { | 1016 error(Node node) { |
| 1014 // TODO(floitsch): get the list of constants that are currently compiled | 1017 // TODO(floitsch): get the list of constants that are currently compiled |
| 1015 // and present some kind of stack-trace. | 1018 // and present some kind of stack-trace. |
| 1016 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; | 1019 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; |
| 1017 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); | 1020 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); |
| 1018 } | 1021 } |
| 1019 } | 1022 } |
| OLD | NEW |