| 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 /** | 5 /** |
| 6 * Generates the code for all used classes in the program. Static fields (even | 6 * Generates the code for all used classes in the program. Static fields (even |
| 7 * in classes) are ignored, since they can be treated as non-class elements. | 7 * in classes) are ignored, since they can be treated as non-class elements. |
| 8 * | 8 * |
| 9 * The code for the containing (used) methods must exist in the [:universe:]. | 9 * The code for the containing (used) methods must exist in the [:universe:]. |
| 10 */ | 10 */ |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // (4) foo$3$c(a, b, c) => foo$4(a, b, c, null); | 100 // (4) foo$3$c(a, b, c) => foo$4(a, b, c, null); |
| 101 // (5) foo$3$d(a, b, d) => foo$4(a, b, null, d); | 101 // (5) foo$3$d(a, b, d) => foo$4(a, b, null, d); |
| 102 // (6) foo$4$c$d(a, b, c, d) => foo$4(a, b, c, d); | 102 // (6) foo$4$c$d(a, b, c, d) => foo$4(a, b, c, d); |
| 103 // (7) Same as (5). | 103 // (7) Same as (5). |
| 104 // | 104 // |
| 105 // We need to generate a stub for (5) because the order of the | 105 // We need to generate a stub for (5) because the order of the |
| 106 // stub arguments and the real method may be different. | 106 // stub arguments and the real method may be different. |
| 107 | 107 |
| 108 int count = 0; | 108 int count = 0; |
| 109 parameters.forEachParameter((Element element) { | 109 parameters.forEachParameter((Element element) { |
| 110 String jsName = JsNames.getValid('${element.name}'); | 110 String jsName = JsNames.getValid(element.name.slowToString()); |
| 111 if (count < positionalArgumentCount) { | 111 if (count < positionalArgumentCount) { |
| 112 parametersBuffer[count] = jsName; | 112 parametersBuffer[count] = jsName; |
| 113 argumentsBuffer[count] = jsName; | 113 argumentsBuffer[count] = jsName; |
| 114 } else { | 114 } else { |
| 115 int index = names.indexOf(element.name); | 115 int index = names.indexOf(element.name); |
| 116 if (index != -1) { | 116 if (index != -1) { |
| 117 // The order of the named arguments is not the same as the | 117 // The order of the named arguments is not the same as the |
| 118 // one in the real method (which is in Dart source order). | 118 // one in the real method (which is in Dart source order). |
| 119 argumentsBuffer[count] = jsName; | 119 argumentsBuffer[count] = jsName; |
| 120 parametersBuffer[selector.positionalArgumentCount + index] = jsName; | 120 parametersBuffer[selector.positionalArgumentCount + index] = jsName; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (superclass !== null) { | 227 if (superclass !== null) { |
| 228 generateClass(classElement.superclass, buffer, seenClasses); | 228 generateClass(classElement.superclass, buffer, seenClasses); |
| 229 } | 229 } |
| 230 | 230 |
| 231 if (classElement.isNative()) { | 231 if (classElement.isNative()) { |
| 232 nativeEmitter.generateNativeClass(classElement, buffer); | 232 nativeEmitter.generateNativeClass(classElement, buffer); |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 | 235 |
| 236 String className = namer.isolatePropertyAccess(classElement); | 236 String className = namer.isolatePropertyAccess(classElement); |
| 237 buffer.add('$className = function ${classElement.name}('); | 237 buffer.add('$className = function ${classElement.name.slowToString()}('); |
| 238 StringBuffer bodyBuffer = new StringBuffer(); | 238 StringBuffer bodyBuffer = new StringBuffer(); |
| 239 // If the class is never instantiated we still need to set it up for | 239 // If the class is never instantiated we still need to set it up for |
| 240 // inheritance purposes, but we can leave its JavaScript constructor empty. | 240 // inheritance purposes, but we can leave its JavaScript constructor empty. |
| 241 if (compiler.universe.instantiatedClasses.contains(classElement)) { | 241 if (compiler.universe.instantiatedClasses.contains(classElement)) { |
| 242 generateFieldInits(classElement, buffer, bodyBuffer); | 242 generateFieldInits(classElement, buffer, bodyBuffer); |
| 243 } | 243 } |
| 244 buffer.add(') {\n'); | 244 buffer.add(') {\n'); |
| 245 buffer.add(bodyBuffer); | 245 buffer.add(bodyBuffer); |
| 246 buffer.add('};\n'); | 246 buffer.add('};\n'); |
| 247 if (superclass !== null) { | 247 if (superclass !== null) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 buffer.add('}\n'); | 572 buffer.add('}\n'); |
| 573 } | 573 } |
| 574 | 574 |
| 575 compiler.universe.invokedNames.forEach((SourceString methodName, | 575 compiler.universe.invokedNames.forEach((SourceString methodName, |
| 576 Set<Selector> selectors) { | 576 Set<Selector> selectors) { |
| 577 if (objectClass.lookupLocalMember(methodName) === null | 577 if (objectClass.lookupLocalMember(methodName) === null |
| 578 && methodName != Namer.OPERATOR_EQUALS) { | 578 && methodName != Namer.OPERATOR_EQUALS) { |
| 579 for (Selector selector in selectors) { | 579 for (Selector selector in selectors) { |
| 580 String jsName = | 580 String jsName = |
| 581 namer.instanceMethodInvocationName(methodName, selector); | 581 namer.instanceMethodInvocationName(methodName, selector); |
| 582 generateMethod(methodName.stringValue, jsName, selector); | 582 generateMethod(methodName.slowToString(), jsName, selector); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 }); | 585 }); |
| 586 | 586 |
| 587 compiler.universe.invokedGetters.forEach((SourceString getterName) { | 587 compiler.universe.invokedGetters.forEach((SourceString getterName) { |
| 588 String jsName = namer.getterName(getterName); | 588 String jsName = namer.getterName(getterName); |
| 589 generateMethod('get $getterName', jsName, Selector.GETTER); | 589 generateMethod('get ${getterName.slowToString()}', jsName, |
| 590 Selector.GETTER); |
| 590 }); | 591 }); |
| 591 | 592 |
| 592 compiler.universe.invokedSetters.forEach((SourceString setterName) { | 593 compiler.universe.invokedSetters.forEach((SourceString setterName) { |
| 593 String jsName = namer.setterName(setterName); | 594 String jsName = namer.setterName(setterName); |
| 594 generateMethod('set $setterName', jsName, Selector.SETTER); | 595 generateMethod('set ${setterName.slowToString()}', jsName, |
| 596 Selector.SETTER); |
| 595 }); | 597 }); |
| 596 } | 598 } |
| 597 | 599 |
| 598 String assembleProgram() { | 600 String assembleProgram() { |
| 599 measure(() { | 601 measure(() { |
| 600 StringBuffer buffer = new StringBuffer(); | 602 StringBuffer buffer = new StringBuffer(); |
| 601 buffer.add('function ${namer.ISOLATE}() {'); | 603 buffer.add('function ${namer.ISOLATE}() {'); |
| 602 emitStaticNonFinalFieldInitializations(buffer); | 604 emitStaticNonFinalFieldInitializations(buffer); |
| 603 buffer.add('}\n\n'); | 605 buffer.add('}\n\n'); |
| 604 emitClasses(buffer); | 606 emitClasses(buffer); |
| 605 emitStaticFunctions(buffer); | 607 emitStaticFunctions(buffer); |
| 606 emitStaticFunctionGetters(buffer); | 608 emitStaticFunctionGetters(buffer); |
| 607 emitDynamicFunctionGetters(buffer); | 609 emitDynamicFunctionGetters(buffer); |
| 608 emitCallStubForGetters(buffer); | 610 emitCallStubForGetters(buffer); |
| 609 emitCompileTimeConstants(buffer); | 611 emitCompileTimeConstants(buffer); |
| 610 emitStaticFinalFieldInitializations(buffer); | 612 emitStaticFinalFieldInitializations(buffer); |
| 611 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 613 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 612 Element main = compiler.mainApp.find(Compiler.MAIN); | 614 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 613 buffer.add('${namer.isolateAccess(main)}();\n'); | 615 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 614 compiler.assembledCode = buffer.toString(); | 616 compiler.assembledCode = buffer.toString(); |
| 615 }); | 617 }); |
| 616 return compiler.assembledCode; | 618 return compiler.assembledCode; |
| 617 } | 619 } |
| 618 } | 620 } |
| OLD | NEW |