Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: dart/frog/leg/emitter.dart

Issue 9813012: Add "mock" compilation feature to dart2js and use it to improve test coverage. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 String currentIsolate = "${namer.CURRENT_ISOLATE}"; 646 String currentIsolate = "${namer.CURRENT_ISOLATE}";
647 String mainEnsureGetter = ''; 647 String mainEnsureGetter = '';
648 // Since we pass the closurized version of the main method to 648 // Since we pass the closurized version of the main method to
649 // the isolate method, we must make sure that it exists. 649 // the isolate method, we must make sure that it exists.
650 if (!compiler.universe.staticFunctionsNeedingGetter.contains(appMain)) { 650 if (!compiler.universe.staticFunctionsNeedingGetter.contains(appMain)) {
651 String invocationName = 651 String invocationName =
652 "${namer.closureInvocationName(Selector.INVOCATION_0)}"; 652 "${namer.closureInvocationName(Selector.INVOCATION_0)}";
653 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess"; 653 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess";
654 } 654 }
655 655
656 // TODO(ngeoffray): These globals are currently required by the isolate 656 // TODO(ngeoffray): These globals are currently required by the isolate
657 // library, but since leg already generates code on an Isolate object, they 657 // library, but since leg already generates code on an Isolate object, they
658 // are not really needed. We should remove them once Leg replaces Frog. 658 // are not really needed. We should remove them once Leg replaces Frog.
659 return """ 659 return """
660 var \$globalThis = $currentIsolate; 660 var \$globalThis = $currentIsolate;
661 var \$globalState; 661 var \$globalState;
662 var \$globals; 662 var \$globals;
663 function \$static_init(){}; 663 function \$static_init(){};
664 664
665 function \$initGlobals(context) { 665 function \$initGlobals(context) {
666 context.isolateStatics = new ${namer.ISOLATE}(); 666 context.isolateStatics = new ${namer.ISOLATE}();
667 } 667 }
668 function \$setGlobals(context) { 668 function \$setGlobals(context) {
669 $currentIsolate = context.isolateStatics; 669 $currentIsolate = context.isolateStatics;
670 \$globalThis = $currentIsolate; 670 \$globalThis = $currentIsolate;
671 } 671 }
672 $mainEnsureGetter 672 $mainEnsureGetter
673 ${namer.isolateAccess(isolateMain)}($mainAccess);"""; 673 ${namer.isolateAccess(isolateMain)}($mainAccess);""";
674 } 674 }
675 675
676 emitMain(StringBuffer buffer) {
677 if (compiler.isMockCompilation) return;
678 Element main = compiler.mainApp.find(Compiler.MAIN);
679 if (compiler.isolateLibrary != null) {
680 Element isolateMain =
681 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE);
682 buffer.add(buildIsolateSetup(main, isolateMain));
683 } else {
684 buffer.add('${namer.isolateAccess(main)}();\n');
685 }
686 }
687
676 String assembleProgram() { 688 String assembleProgram() {
677 measure(() { 689 measure(() {
678 StringBuffer buffer = new StringBuffer(); 690 StringBuffer buffer = new StringBuffer();
679 buffer.add('function ${namer.ISOLATE}() {'); 691 buffer.add('function ${namer.ISOLATE}() {');
680 emitStaticNonFinalFieldInitializations(buffer); 692 emitStaticNonFinalFieldInitializations(buffer);
681 buffer.add('}\n\n'); 693 buffer.add('}\n\n');
682 emitClasses(buffer); 694 emitClasses(buffer);
683 emitStaticFunctions(buffer); 695 emitStaticFunctions(buffer);
684 emitStaticFunctionGetters(buffer); 696 emitStaticFunctionGetters(buffer);
685 emitCompileTimeConstants(buffer); 697 emitCompileTimeConstants(buffer);
686 emitStaticFinalFieldInitializations(buffer); 698 emitStaticFinalFieldInitializations(buffer);
687 nativeEmitter.emitDynamicDispatchMetadata(buffer); 699 nativeEmitter.emitDynamicDispatchMetadata(buffer);
688 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 700 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
689 Element main = compiler.mainApp.find(Compiler.MAIN); 701 emitMain(buffer);
690 if (compiler.isolateLibrary != null) {
691 Element isolateMain =
692 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE);
693 buffer.add(buildIsolateSetup(main, isolateMain));
694 } else {
695 buffer.add('${namer.isolateAccess(main)}();\n');
696 }
697 compiler.assembledCode = buffer.toString(); 702 compiler.assembledCode = buffer.toString();
698 }); 703 });
699 return compiler.assembledCode; 704 return compiler.assembledCode;
700 } 705 }
701 } 706 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698