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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 Element jsArrayAdd; | 95 Element jsArrayAdd; |
96 Element jsStringSplit; | 96 Element jsStringSplit; |
97 Element jsStringToString; | 97 Element jsStringToString; |
98 Element jsStringOperatorAdd; | 98 Element jsStringOperatorAdd; |
99 Element objectEquals; | 99 Element objectEquals; |
100 | 100 |
101 ClassElement typeLiteralClass; | 101 ClassElement typeLiteralClass; |
102 ClassElement mapLiteralClass; | 102 ClassElement mapLiteralClass; |
103 ClassElement constMapLiteralClass; | 103 ClassElement constMapLiteralClass; |
104 ClassElement typeVariableClass; | 104 ClassElement typeVariableClass; |
| 105 Element mapLiteralConstructor; |
| 106 Element mapLiteralConstructorEmpty; |
105 | 107 |
106 ClassElement noSideEffectsClass; | 108 ClassElement noSideEffectsClass; |
107 ClassElement noThrowsClass; | 109 ClassElement noThrowsClass; |
108 ClassElement noInlineClass; | 110 ClassElement noInlineClass; |
109 ClassElement irRepresentationClass; | 111 ClassElement irRepresentationClass; |
110 | 112 |
111 Element getInterceptorMethod; | 113 Element getInterceptorMethod; |
112 Element interceptedNames; | 114 Element interceptedNames; |
113 | 115 |
114 /** | 116 /** |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 } else if (cls == compiler.functionClass) { | 723 } else if (cls == compiler.functionClass) { |
722 enqueueClass(enqueuer, compiler.closureClass, elements); | 724 enqueueClass(enqueuer, compiler.closureClass, elements); |
723 } else if (cls == compiler.mapClass) { | 725 } else if (cls == compiler.mapClass) { |
724 // The backend will use a literal list to initialize the entries | 726 // The backend will use a literal list to initialize the entries |
725 // of the map. | 727 // of the map. |
726 enqueueClass(enqueuer, compiler.listClass, elements); | 728 enqueueClass(enqueuer, compiler.listClass, elements); |
727 enqueueClass(enqueuer, mapLiteralClass, elements); | 729 enqueueClass(enqueuer, mapLiteralClass, elements); |
728 // For map literals, the dependency between the implementation class | 730 // For map literals, the dependency between the implementation class |
729 // and [Map] is not visible, so we have to add it manually. | 731 // and [Map] is not visible, so we have to add it manually. |
730 rti.registerRtiDependency(mapLiteralClass, cls); | 732 rti.registerRtiDependency(mapLiteralClass, cls); |
731 enqueueInResolution(getMapMaker(), elements); | |
732 } else if (cls == compiler.boundClosureClass) { | 733 } else if (cls == compiler.boundClosureClass) { |
733 // TODO(ngeoffray): Move the bound closure class in the | 734 // TODO(ngeoffray): Move the bound closure class in the |
734 // backend. | 735 // backend. |
735 enqueueClass(enqueuer, compiler.boundClosureClass, elements); | 736 enqueueClass(enqueuer, compiler.boundClosureClass, elements); |
736 } else if (Elements.isNativeOrExtendsNative(cls)) { | 737 } else if (Elements.isNativeOrExtendsNative(cls)) { |
737 enqueue(enqueuer, getNativeInterceptorMethod, elements); | 738 enqueue(enqueuer, getNativeInterceptorMethod, elements); |
738 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); | 739 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
739 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, elements); | 740 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, elements); |
| 741 } else if (cls == mapLiteralClass) { |
| 742 // For map literals, the dependency between the implementation class |
| 743 // and [Map] is not visible, so we have to add it manually. |
| 744 Element getFactory(String name, int arity) { |
| 745 // The constructor is on the patch class, but dart2js unit tests don't |
| 746 // have a patch class. |
| 747 ClassElement implementation = cls.patch != null ? cls.patch : cls; |
| 748 return implementation.lookupConstructor( |
| 749 new Selector.callConstructor( |
| 750 name, mapLiteralClass.getLibrary(), arity), |
| 751 (element) { |
| 752 compiler.internalError(mapLiteralClass, |
| 753 "Map literal class $mapLiteralClass missing " |
| 754 "'$name' constructor" |
| 755 " ${mapLiteralClass.constructors}"); |
| 756 }); |
| 757 } |
| 758 mapLiteralConstructor = getFactory('_literal', 1); |
| 759 mapLiteralConstructorEmpty = getFactory('_empty', 0); |
| 760 enqueueInResolution(mapLiteralConstructor, elements); |
| 761 enqueueInResolution(mapLiteralConstructorEmpty, elements); |
740 } | 762 } |
741 } | 763 } |
742 if (cls == compiler.closureClass) { | 764 if (cls == compiler.closureClass) { |
743 enqueue(enqueuer, | 765 enqueue(enqueuer, |
744 compiler.findHelper('closureFromTearOff'), | 766 compiler.findHelper('closureFromTearOff'), |
745 elements); | 767 elements); |
746 } | 768 } |
747 ClassElement result = null; | 769 ClassElement result = null; |
748 if (cls == compiler.stringClass || cls == jsStringClass) { | 770 if (cls == compiler.stringClass || cls == jsStringClass) { |
749 addInterceptors(jsStringClass, enqueuer, elements); | 771 addInterceptors(jsStringClass, enqueuer, elements); |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 } | 1463 } |
1442 | 1464 |
1443 Element getClosureConverter() { | 1465 Element getClosureConverter() { |
1444 return compiler.findHelper('convertDartClosureToJS'); | 1466 return compiler.findHelper('convertDartClosureToJS'); |
1445 } | 1467 } |
1446 | 1468 |
1447 Element getTraceFromException() { | 1469 Element getTraceFromException() { |
1448 return compiler.findHelper('getTraceFromException'); | 1470 return compiler.findHelper('getTraceFromException'); |
1449 } | 1471 } |
1450 | 1472 |
1451 Element getMapMaker() { | |
1452 return compiler.findHelper('makeLiteralMap'); | |
1453 } | |
1454 | |
1455 Element getSetRuntimeTypeInfo() { | 1473 Element getSetRuntimeTypeInfo() { |
1456 return compiler.findHelper('setRuntimeTypeInfo'); | 1474 return compiler.findHelper('setRuntimeTypeInfo'); |
1457 } | 1475 } |
1458 | 1476 |
1459 Element getGetRuntimeTypeInfo() { | 1477 Element getGetRuntimeTypeInfo() { |
1460 return compiler.findHelper('getRuntimeTypeInfo'); | 1478 return compiler.findHelper('getRuntimeTypeInfo'); |
1461 } | 1479 } |
1462 | 1480 |
1463 Element getGetTypeArgumentByIndex() { | 1481 Element getGetTypeArgumentByIndex() { |
1464 return compiler.findHelper('getTypeArgumentByIndex'); | 1482 return compiler.findHelper('getTypeArgumentByIndex'); |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 } | 1897 } |
1880 } | 1898 } |
1881 | 1899 |
1882 /// Records that [constant] is used by [user.element]. | 1900 /// Records that [constant] is used by [user.element]. |
1883 class Dependency { | 1901 class Dependency { |
1884 final Constant constant; | 1902 final Constant constant; |
1885 final TreeElements user; | 1903 final TreeElements user; |
1886 | 1904 |
1887 const Dependency(this.constant, this.user); | 1905 const Dependency(this.constant, this.user); |
1888 } | 1906 } |
1889 | |
OLD | NEW |