| 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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
| 9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
| 10 * | 10 * |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 => r'$finishClasses'; | 128 => r'$finishClasses'; |
| 129 String get finishClassesName | 129 String get finishClassesName |
| 130 => '${namer.isolateName}.$finishClassesProperty'; | 130 => '${namer.isolateName}.$finishClassesProperty'; |
| 131 String get finishIsolateConstructorName | 131 String get finishIsolateConstructorName |
| 132 => '${namer.isolateName}.\$finishIsolateConstructor'; | 132 => '${namer.isolateName}.\$finishIsolateConstructor'; |
| 133 String get isolatePropertiesName | 133 String get isolatePropertiesName |
| 134 => '${namer.isolateName}.${namer.isolatePropertiesName}'; | 134 => '${namer.isolateName}.${namer.isolatePropertiesName}'; |
| 135 String get lazyInitializerName | 135 String get lazyInitializerName |
| 136 => '${namer.isolateName}.\$lazy'; | 136 => '${namer.isolateName}.\$lazy'; |
| 137 String get initName => 'init'; | 137 String get initName => 'init'; |
| 138 String get makeConstListProperty | |
| 139 => namer.getMappedInstanceName('makeConstantList'); | |
| 140 | 138 |
| 141 jsAst.FunctionDeclaration get generateAccessorFunction { | 139 jsAst.FunctionDeclaration get generateAccessorFunction { |
| 142 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; | 140 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; |
| 143 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; | 141 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; |
| 144 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); | 142 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); |
| 145 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); | 143 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); |
| 146 const RANGE3_ADJUST = | 144 const RANGE3_ADJUST = |
| 147 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); | 145 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); |
| 148 | 146 |
| 149 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; | 147 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 function ForceEfficientMap() {} | 531 function ForceEfficientMap() {} |
| 534 ForceEfficientMap.prototype = this; | 532 ForceEfficientMap.prototype = this; |
| 535 new ForceEfficientMap(); | 533 new ForceEfficientMap(); |
| 536 } | 534 } |
| 537 Isolate.prototype = oldIsolate.prototype; | 535 Isolate.prototype = oldIsolate.prototype; |
| 538 Isolate.prototype.constructor = Isolate; | 536 Isolate.prototype.constructor = Isolate; |
| 539 Isolate.${namer.isolatePropertiesName} = isolateProperties; | 537 Isolate.${namer.isolatePropertiesName} = isolateProperties; |
| 540 if (#) | 538 if (#) |
| 541 Isolate.$finishClassesProperty = oldIsolate.$finishClassesProperty; | 539 Isolate.$finishClassesProperty = oldIsolate.$finishClassesProperty; |
| 542 if (#) | 540 if (#) |
| 543 Isolate.$makeConstListProperty = oldIsolate.$makeConstListProperty; | 541 Isolate.makeConstantList = oldIsolate.makeConstantList; |
| 544 return Isolate; | 542 return Isolate; |
| 545 }''', | 543 }''', |
| 546 [ needsDefineClass, hasMakeConstantList ]); | 544 [ needsDefineClass, hasMakeConstantList ]); |
| 547 } | 545 } |
| 548 | 546 |
| 549 jsAst.Fun get lazyInitializerFunction { | 547 jsAst.Fun get lazyInitializerFunction { |
| 550 String isolate = namer.currentIsolate; | 548 String isolate = namer.currentIsolate; |
| 551 jsAst.Expression cyclicThrow = | 549 jsAst.Expression cyclicThrow = |
| 552 namer.elementAccess(backend.getCyclicThrowHelper()); | 550 namer.elementAccess(backend.getCyclicThrowHelper()); |
| 553 | 551 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); | 949 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); |
| 952 if (r != 0) return r; | 950 if (r != 0) return r; |
| 953 // Resolve collisions in the long name by using the constant name (i.e. JS | 951 // Resolve collisions in the long name by using the constant name (i.e. JS |
| 954 // name) which is unique. | 952 // name) which is unique. |
| 955 return namer.constantName(a).compareTo(namer.constantName(b)); | 953 return namer.constantName(a).compareTo(namer.constantName(b)); |
| 956 } | 954 } |
| 957 | 955 |
| 958 void emitMakeConstantListIfNotEmitted(CodeBuffer buffer) { | 956 void emitMakeConstantListIfNotEmitted(CodeBuffer buffer) { |
| 959 if (hasMakeConstantList) return; | 957 if (hasMakeConstantList) return; |
| 960 hasMakeConstantList = true; | 958 hasMakeConstantList = true; |
| 961 jsAst.Statement value = new jsAst.ExpressionStatement(new jsAst.Assignment( | 959 buffer |
| 962 new jsAst.PropertyAccess.field( | 960 ..write(namer.isolateName) |
| 963 new jsAst.VariableUse(namer.isolateName), | 961 ..write('''.makeConstantList = function(list) { |
| 964 makeConstListProperty), | 962 list.immutable\$list = $initName; |
| 965 js('''function(list) { | 963 list.fixed\$length = $initName; |
| 966 list.immutable\$list = $initName; | 964 return list; |
| 967 list.fixed\$length = $initName; | 965 }; |
| 968 return list; | 966 '''); |
| 969 }'''))); | |
| 970 buffer.write(jsAst.prettyPrint(value, compiler)); | |
| 971 } | 967 } |
| 972 | 968 |
| 973 /// Returns the code equivalent to: | 969 /// Returns the code equivalent to: |
| 974 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` | 970 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` |
| 975 String buildIsolateSetupClosure(CodeBuffer buffer, | 971 String buildIsolateSetupClosure(CodeBuffer buffer, |
| 976 Element appMain, | 972 Element appMain, |
| 977 Element isolateMain) { | 973 Element isolateMain) { |
| 978 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); | 974 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); |
| 979 // Since we pass the closurized version of the main method to | 975 // Since we pass the closurized version of the main method to |
| 980 // the isolate method, we must make sure that it exists. | 976 // the isolate method, we must make sure that it exists. |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1743 String sourceMap = sourceMapBuilder.build(); | 1739 String sourceMap = sourceMapBuilder.build(); |
| 1744 compiler.outputProvider(name, 'js.map') | 1740 compiler.outputProvider(name, 'js.map') |
| 1745 ..add(sourceMap) | 1741 ..add(sourceMap) |
| 1746 ..close(); | 1742 ..close(); |
| 1747 } | 1743 } |
| 1748 | 1744 |
| 1749 void registerReadTypeVariable(TypeVariableElement element) { | 1745 void registerReadTypeVariable(TypeVariableElement element) { |
| 1750 readTypeVariables.add(element); | 1746 readTypeVariables.add(element); |
| 1751 } | 1747 } |
| 1752 } | 1748 } |
| OLD | NEW |