| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 258 |
| 259 ObjectConstant(this.type); | 259 ObjectConstant(this.type); |
| 260 bool isObject() => true; | 260 bool isObject() => true; |
| 261 | 261 |
| 262 // TODO(1603): The class should be marked as abstract, but the VM doesn't | 262 // TODO(1603): The class should be marked as abstract, but the VM doesn't |
| 263 // currently allow this. | 263 // currently allow this. |
| 264 abstract int hashCode(); | 264 abstract int hashCode(); |
| 265 | 265 |
| 266 void _writeCanonicalizedJsCode(StringBuffer buffer, ConstantHandler handler) { | 266 void _writeCanonicalizedJsCode(StringBuffer buffer, ConstantHandler handler) { |
| 267 String name = handler.getNameForConstant(this); | 267 String name = handler.getNameForConstant(this); |
| 268 String isolatePrototype = "${handler.compiler.namer.ISOLATE}.prototype"; | 268 buffer.add(handler.compiler.namer.isolatePropertiesAccessForConstant(name)); |
| 269 buffer.add("$isolatePrototype.$name"); | |
| 270 } | 269 } |
| 271 } | 270 } |
| 272 | 271 |
| 273 class ListConstant extends ObjectConstant { | 272 class ListConstant extends ObjectConstant { |
| 274 final List<Constant> entries; | 273 final List<Constant> entries; |
| 275 int _hashCode; | 274 int _hashCode; |
| 276 | 275 |
| 277 ListConstant(Type type, this.entries) : super(type) { | 276 ListConstant(Type type, this.entries) : super(type) { |
| 278 // TODO(floitsch): create a better hash. | 277 // TODO(floitsch): create a better hash. |
| 279 int hash = 0; | 278 int hash = 0; |
| 280 for (Constant input in entries) hash ^= input.hashCode(); | 279 for (Constant input in entries) hash ^= input.hashCode(); |
| 281 _hashCode = hash; | 280 _hashCode = hash; |
| 282 } | 281 } |
| 283 bool isList() => true; | 282 bool isList() => true; |
| 284 | 283 |
| 285 void _writeJsCode(StringBuffer buffer, ConstantHandler handler) { | 284 void _writeJsCode(StringBuffer buffer, ConstantHandler handler) { |
| 286 // TODO(floitsch): we should not need to go through the compiler to make | 285 // TODO(floitsch): we should not need to go through the compiler to make |
| 287 // the list constant. | 286 // the list constant. |
| 288 String isolatePrototype = "${handler.compiler.namer.ISOLATE}.prototype"; | 287 buffer.add("${handler.compiler.namer.ISOLATE}.makeConstantList"); |
| 289 buffer.add("$isolatePrototype.makeConstantList"); | |
| 290 buffer.add("(["); | 288 buffer.add("(["); |
| 291 for (int i = 0; i < entries.length; i++) { | 289 for (int i = 0; i < entries.length; i++) { |
| 292 if (i != 0) buffer.add(", "); | 290 if (i != 0) buffer.add(", "); |
| 293 Constant entry = entries[i]; | 291 Constant entry = entries[i]; |
| 294 handler.writeConstant(buffer, entry); | 292 handler.writeConstant(buffer, entry); |
| 295 } | 293 } |
| 296 buffer.add("])"); | 294 buffer.add("])"); |
| 297 } | 295 } |
| 298 | 296 |
| 299 bool operator ==(var other) { | 297 bool operator ==(var other) { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 buffer.add(code.toRadixString(16)); | 684 buffer.add(code.toRadixString(16)); |
| 687 } | 685 } |
| 688 } else { | 686 } else { |
| 689 buffer.add(new String.fromCharCodes(<int>[code])); | 687 buffer.add(new String.fromCharCodes(<int>[code])); |
| 690 } | 688 } |
| 691 } | 689 } |
| 692 } | 690 } |
| 693 } | 691 } |
| 694 | 692 |
| 695 String getJsConstructor(ClassElement element) { | 693 String getJsConstructor(ClassElement element) { |
| 696 return compiler.namer.isolatePropertyAccess(element); | 694 return compiler.namer.isolatePropertiesAccess(element); |
| 697 } | 695 } |
| 698 } | 696 } |
| 699 | 697 |
| 700 class CompileTimeConstantEvaluator extends AbstractVisitor { | 698 class CompileTimeConstantEvaluator extends AbstractVisitor { |
| 701 final TreeElements elements; | 699 final TreeElements elements; |
| 702 final Compiler compiler; | 700 final Compiler compiler; |
| 703 | 701 |
| 704 CompileTimeConstantEvaluator(this.elements, this.compiler); | 702 CompileTimeConstantEvaluator(this.elements, this.compiler); |
| 705 | 703 |
| 706 Constant evaluate(Node node) { | 704 Constant evaluate(Node node) { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 Constant fieldValue = fieldValues[field]; | 1145 Constant fieldValue = fieldValues[field]; |
| 1148 if (fieldValue === null) { | 1146 if (fieldValue === null) { |
| 1149 // Use the default value. | 1147 // Use the default value. |
| 1150 fieldValue = compiler.compileVariable(field); | 1148 fieldValue = compiler.compileVariable(field); |
| 1151 } | 1149 } |
| 1152 jsNewArguments.add(fieldValue); | 1150 jsNewArguments.add(fieldValue); |
| 1153 }); | 1151 }); |
| 1154 return jsNewArguments; | 1152 return jsNewArguments; |
| 1155 } | 1153 } |
| 1156 } | 1154 } |
| OLD | NEW |