| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 "The parameter sentinel constant does not need specific JS code"); | 44 "The parameter sentinel constant does not need specific JS code"); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) { | 47 void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) { |
| 48 buffer.add(handler.compiler.namer.CURRENT_ISOLATE); | 48 buffer.add(handler.compiler.namer.CURRENT_ISOLATE); |
| 49 } | 49 } |
| 50 | 50 |
| 51 List<Constant> getDependencies() => const <Constant>[]; | 51 List<Constant> getDependencies() => const <Constant>[]; |
| 52 | 52 |
| 53 // Just use a randome value. | 53 // Just use a randome value. |
| 54 int hashCode() => 9264297841582447; | 54 int hashCode() => 926429784158; |
| 55 | 55 |
| 56 bool isSentinel() => true; | 56 bool isSentinel() => true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 class FunctionConstant extends Constant { | 59 class FunctionConstant extends Constant { |
| 60 Element element; | 60 Element element; |
| 61 | 61 |
| 62 FunctionConstant(this.element); | 62 FunctionConstant(this.element); |
| 63 | 63 |
| 64 bool isFunction() => true; | 64 bool isFunction() => true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 76 | 76 |
| 77 void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) { | 77 void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) { |
| 78 handler.compiler.internalError( | 78 handler.compiler.internalError( |
| 79 "A constant function does not need specific JS code"); | 79 "A constant function does not need specific JS code"); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) { | 82 void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) { |
| 83 buffer.add(handler.compiler.namer.isolatePropertiesAccess(element)); | 83 buffer.add(handler.compiler.namer.isolatePropertiesAccess(element)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 int hashCode() => element.hashCode(); | 86 int hashCode() => (17 * element.hashCode()) & 0x7fffffff; |
| 87 } | 87 } |
| 88 | 88 |
| 89 class PrimitiveConstant extends Constant { | 89 class PrimitiveConstant extends Constant { |
| 90 abstract get value; | 90 abstract get value; |
| 91 const PrimitiveConstant(); | 91 const PrimitiveConstant(); |
| 92 bool isPrimitive() => true; | 92 bool isPrimitive() => true; |
| 93 | 93 |
| 94 bool operator ==(var other) { | 94 bool operator ==(var other) { |
| 95 if (other is !PrimitiveConstant) return false; | 95 if (other is !PrimitiveConstant) return false; |
| 96 PrimitiveConstant otherPrimitive = other; | 96 PrimitiveConstant otherPrimitive = other; |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 DartType keysType = null; | 910 DartType keysType = null; |
| 911 ListConstant keysList = new ListConstant(keysType, keys); | 911 ListConstant keysList = new ListConstant(keysType, keys); |
| 912 compiler.constantHandler.registerCompileTimeConstant(keysList); | 912 compiler.constantHandler.registerCompileTimeConstant(keysList); |
| 913 SourceString className = hasProtoKey | 913 SourceString className = hasProtoKey |
| 914 ? MapConstant.DART_PROTO_CLASS | 914 ? MapConstant.DART_PROTO_CLASS |
| 915 : MapConstant.DART_CLASS; | 915 : MapConstant.DART_CLASS; |
| 916 ClassElement classElement = compiler.jsHelperLibrary.find(className); | 916 ClassElement classElement = compiler.jsHelperLibrary.find(className); |
| 917 classElement.ensureResolved(compiler); | 917 classElement.ensureResolved(compiler); |
| 918 // TODO(floitsch): copy over the generic type. | 918 // TODO(floitsch): copy over the generic type. |
| 919 DartType type = new InterfaceType(classElement); | 919 DartType type = new InterfaceType(classElement); |
| 920 compiler.registerInstantiatedClass(classElement); | 920 compiler.enqueuer.codegen.registerInstantiatedClass(classElement); |
| 921 Constant constant = new MapConstant(type, keysList, values, protoValue); | 921 Constant constant = new MapConstant(type, keysList, values, protoValue); |
| 922 compiler.constantHandler.registerCompileTimeConstant(constant); | 922 compiler.constantHandler.registerCompileTimeConstant(constant); |
| 923 return constant; | 923 return constant; |
| 924 } | 924 } |
| 925 | 925 |
| 926 Constant visitLiteralNull(LiteralNull node) { | 926 Constant visitLiteralNull(LiteralNull node) { |
| 927 return new NullConstant(); | 927 return new NullConstant(); |
| 928 } | 928 } |
| 929 | 929 |
| 930 Constant visitLiteralString(LiteralString node) { | 930 Constant visitLiteralString(LiteralString node) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 Selector selector = elements.getSelector(send); | 1143 Selector selector = elements.getSelector(send); |
| 1144 List<Constant> arguments = | 1144 List<Constant> arguments = |
| 1145 evaluateArgumentsToConstructor(selector, send.arguments, constructor); | 1145 evaluateArgumentsToConstructor(selector, send.arguments, constructor); |
| 1146 ConstructorEvaluator evaluator = | 1146 ConstructorEvaluator evaluator = |
| 1147 new ConstructorEvaluator(constructor, compiler); | 1147 new ConstructorEvaluator(constructor, compiler); |
| 1148 evaluator.evaluateConstructorFieldValues(arguments); | 1148 evaluator.evaluateConstructorFieldValues(arguments); |
| 1149 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); | 1149 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); |
| 1150 | 1150 |
| 1151 compiler.registerInstantiatedClass(classElement); | 1151 compiler.enqueuer.codegen.registerInstantiatedClass(classElement); |
| 1152 // TODO(floitsch): take generic types into account. | 1152 // TODO(floitsch): take generic types into account. |
| 1153 DartType type = classElement.computeType(compiler); | 1153 DartType type = classElement.computeType(compiler); |
| 1154 Constant constant = new ConstructedConstant(type, jsNewArguments); | 1154 Constant constant = new ConstructedConstant(type, jsNewArguments); |
| 1155 compiler.constantHandler.registerCompileTimeConstant(constant); | 1155 compiler.constantHandler.registerCompileTimeConstant(constant); |
| 1156 return constant; | 1156 return constant; |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 Constant visitParenthesizedExpression(ParenthesizedExpression node) { | 1159 Constant visitParenthesizedExpression(ParenthesizedExpression node) { |
| 1160 return node.expression.accept(this); | 1160 return node.expression.accept(this); |
| 1161 } | 1161 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 Constant fieldValue = fieldValues[field]; | 1328 Constant fieldValue = fieldValues[field]; |
| 1329 if (fieldValue === null) { | 1329 if (fieldValue === null) { |
| 1330 // Use the default value. | 1330 // Use the default value. |
| 1331 fieldValue = compiler.compileConstant(field); | 1331 fieldValue = compiler.compileConstant(field); |
| 1332 } | 1332 } |
| 1333 jsNewArguments.add(fieldValue); | 1333 jsNewArguments.add(fieldValue); |
| 1334 }); | 1334 }); |
| 1335 return jsNewArguments; | 1335 return jsNewArguments; |
| 1336 } | 1336 } |
| 1337 } | 1337 } |
| OLD | NEW |