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; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 : this.constantSystem = constantSystem; | 67 : this.constantSystem = constantSystem; |
68 | 68 |
69 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { | 69 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { |
70 lib.forEachExport((Element e) { | 70 lib.forEachExport((Element e) { |
71 if (e.isFunction()) world.addToWorkList(e); | 71 if (e.isFunction()) world.addToWorkList(e); |
72 }); | 72 }); |
73 } | 73 } |
74 | 74 |
75 void enqueueHelpers(Enqueuer world); | 75 void enqueueHelpers(Enqueuer world); |
76 void codegen(WorkItem work); | 76 void codegen(WorkItem work); |
77 void processNativeClasses(Enqueuer world, | 77 |
78 Collection<LibraryElement> libraries); | 78 // The backend determines the native resolution enqueuer, with a no-op |
| 79 // default, so tools like dart2dart can ignore the native classes. |
| 80 native.NativeEnqueuer nativeResolutionEnqueuer(world) { |
| 81 return new native.NativeEnqueuer(); |
| 82 } |
| 83 native.NativeEnqueuer nativeCodegenEnqueuer(world) { |
| 84 return new native.NativeEnqueuer(); |
| 85 } |
| 86 |
79 void assembleProgram(); | 87 void assembleProgram(); |
80 List<CompilerTask> get tasks; | 88 List<CompilerTask> get tasks; |
81 | 89 |
82 // TODO(ahe,karlklose): rename this? | 90 // TODO(ahe,karlklose): rename this? |
83 void dumpInferredTypes() {} | 91 void dumpInferredTypes() {} |
84 | 92 |
85 ItemCompilationContext createItemCompilationContext() { | 93 ItemCompilationContext createItemCompilationContext() { |
86 return new ItemCompilationContext(); | 94 return new ItemCompilationContext(); |
87 } | 95 } |
88 | 96 |
89 SourceString getCheckedModeHelper(DartType type) => null; | 97 SourceString getCheckedModeHelper(DartType type) => null; |
90 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} | 98 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} |
91 | 99 |
92 Element getInterceptor(Selector selector); | 100 Element getInterceptor(Selector selector); |
93 } | 101 } |
94 | 102 |
95 abstract class Compiler implements DiagnosticListener { | 103 abstract class Compiler implements DiagnosticListener { |
96 final Map<String, LibraryElement> libraries; | 104 final Map<String, LibraryElement> libraries; |
97 int nextFreeClassId = 0; | 105 int nextFreeClassId = 0; |
98 World world; | 106 World world; |
99 String assembledCode; | 107 String assembledCode; |
100 Types types; | 108 Types types; |
101 | 109 |
102 final bool enableMinification; | 110 final bool enableMinification; |
103 final bool enableTypeAssertions; | 111 final bool enableTypeAssertions; |
104 final bool enableUserAssertions; | 112 final bool enableUserAssertions; |
105 final bool enableConcreteTypeInference; | 113 final bool enableConcreteTypeInference; |
106 final bool analyzeAll; | 114 final bool analyzeAll; |
| 115 final bool enableNativeLiveTypeAnalysis; |
107 | 116 |
108 bool disableInlining = false; | 117 bool disableInlining = false; |
109 | 118 |
110 final Tracer tracer; | 119 final Tracer tracer; |
111 | 120 |
112 CompilerTask measuredTask; | 121 CompilerTask measuredTask; |
113 Element _currentElement; | 122 Element _currentElement; |
114 LibraryElement coreLibrary; | 123 LibraryElement coreLibrary; |
115 LibraryElement isolateLibrary; | 124 LibraryElement isolateLibrary; |
116 LibraryElement jsHelperLibrary; | 125 LibraryElement jsHelperLibrary; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 213 |
205 bool compilationFailed = false; | 214 bool compilationFailed = false; |
206 | 215 |
207 bool hasCrashed = false; | 216 bool hasCrashed = false; |
208 | 217 |
209 Compiler({this.tracer: const Tracer(), | 218 Compiler({this.tracer: const Tracer(), |
210 this.enableTypeAssertions: false, | 219 this.enableTypeAssertions: false, |
211 this.enableUserAssertions: false, | 220 this.enableUserAssertions: false, |
212 this.enableConcreteTypeInference: false, | 221 this.enableConcreteTypeInference: false, |
213 this.enableMinification: false, | 222 this.enableMinification: false, |
| 223 this.enableNativeLiveTypeAnalysis: false, |
214 bool emitJavaScript: true, | 224 bool emitJavaScript: true, |
215 bool generateSourceMap: true, | 225 bool generateSourceMap: true, |
216 bool disallowUnsafeEval: false, | 226 bool disallowUnsafeEval: false, |
217 this.analyzeAll: false, | 227 this.analyzeAll: false, |
218 List<String> strips: const []}) | 228 List<String> strips: const []}) |
219 : libraries = new Map<String, LibraryElement>(), | 229 : libraries = new Map<String, LibraryElement>(), |
220 progress = new Stopwatch() { | 230 progress = new Stopwatch() { |
221 progress.start(); | 231 progress.start(); |
222 world = new World(this); | 232 world = new World(this); |
223 scanner = new ScannerTask(this); | 233 scanner = new ScannerTask(this); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 parameters.forEachParameter((Element parameter) { | 525 parameters.forEachParameter((Element parameter) { |
516 reportFatalError('main cannot have parameters', parameter); | 526 reportFatalError('main cannot have parameters', parameter); |
517 }); | 527 }); |
518 } | 528 } |
519 | 529 |
520 log('Resolving...'); | 530 log('Resolving...'); |
521 phase = PHASE_RESOLVING; | 531 phase = PHASE_RESOLVING; |
522 if (analyzeAll) libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); | 532 if (analyzeAll) libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); |
523 backend.enqueueHelpers(enqueuer.resolution); | 533 backend.enqueueHelpers(enqueuer.resolution); |
524 processQueue(enqueuer.resolution, main); | 534 processQueue(enqueuer.resolution, main); |
525 log('Resolved ${enqueuer.resolution.resolvedElements.length} elements.'); | 535 enqueuer.resolution.logSummary(log); |
526 | 536 |
527 if (compilationFailed) return; | 537 if (compilationFailed) return; |
528 | 538 |
529 log('Inferring types...'); | 539 log('Inferring types...'); |
530 typesTask.onResolutionComplete(main); | 540 typesTask.onResolutionComplete(main); |
531 | 541 |
532 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution | 542 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution |
533 // should know this. | 543 // should know this. |
534 world.populate(); | 544 world.populate(); |
535 | 545 |
536 log('Compiling...'); | 546 log('Compiling...'); |
537 phase = PHASE_COMPILING; | 547 phase = PHASE_COMPILING; |
538 processQueue(enqueuer.codegen, main); | 548 processQueue(enqueuer.codegen, main); |
539 log('Compiled ${codegenWorld.generatedCode.length} methods.'); | 549 enqueuer.codegen.logSummary(log); |
540 | 550 |
541 if (compilationFailed) return; | 551 if (compilationFailed) return; |
542 | 552 |
543 backend.assembleProgram(); | 553 backend.assembleProgram(); |
544 | 554 |
545 checkQueues(); | 555 checkQueues(); |
546 } | 556 } |
547 | 557 |
548 void fullyEnqueueLibrary(LibraryElement library) { | 558 void fullyEnqueueLibrary(LibraryElement library) { |
549 library.forEachLocalMember(fullyEnqueueTopLevelElement); | 559 library.forEachLocalMember(fullyEnqueueTopLevelElement); |
550 } | 560 } |
551 | 561 |
552 void fullyEnqueueTopLevelElement(Element element) { | 562 void fullyEnqueueTopLevelElement(Element element) { |
553 if (element.isClass()) { | 563 if (element.isClass()) { |
554 ClassElement cls = element; | 564 ClassElement cls = element; |
555 cls.ensureResolved(this); | 565 cls.ensureResolved(this); |
556 for (Element member in cls.localMembers) { | 566 for (Element member in cls.localMembers) { |
557 enqueuer.resolution.addToWorkList(member); | 567 enqueuer.resolution.addToWorkList(member); |
558 } | 568 } |
559 } else { | 569 } else { |
560 enqueuer.resolution.addToWorkList(element); | 570 enqueuer.resolution.addToWorkList(element); |
561 } | 571 } |
562 } | 572 } |
563 | 573 |
564 void processQueue(Enqueuer world, Element main) { | 574 void processQueue(Enqueuer world, Element main) { |
565 backend.processNativeClasses(world, libraries.values); | 575 world.nativeEnqueuer.processNativeClasses(libraries.values); |
566 world.addToWorkList(main); | 576 world.addToWorkList(main); |
567 progress.reset(); | 577 progress.reset(); |
568 world.forEach((WorkItem work) { | 578 world.forEach((WorkItem work) { |
569 withCurrentElement(work.element, () => work.run(this, world)); | 579 withCurrentElement(work.element, () => work.run(this, world)); |
570 }); | 580 }); |
571 world.queueIsClosed = true; | 581 world.queueIsClosed = true; |
572 if (compilationFailed) return; | 582 if (compilationFailed) return; |
573 assert(world.checkNoEnqueuedInvokedInstanceMethods()); | 583 assert(world.checkNoEnqueuedInvokedInstanceMethods()); |
574 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { | 584 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { |
575 backend.dumpInferredTypes(); | 585 backend.dumpInferredTypes(); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 924 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
915 // information on assertion errors. | 925 // information on assertion errors. |
916 if (condition is Function){ | 926 if (condition is Function){ |
917 condition = condition(); | 927 condition = condition(); |
918 } | 928 } |
919 if (spannable == null || !condition) { | 929 if (spannable == null || !condition) { |
920 throw new SpannableAssertionFailure(spannable, message); | 930 throw new SpannableAssertionFailure(spannable, message); |
921 } | 931 } |
922 return true; | 932 return true; |
923 } | 933 } |
OLD | NEW |