Chromium Code Reviews| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 final bool enableMinification; | 186 final bool enableMinification; |
| 187 final bool enableTypeAssertions; | 187 final bool enableTypeAssertions; |
| 188 final bool enableUserAssertions; | 188 final bool enableUserAssertions; |
| 189 final bool enableConcreteTypeInference; | 189 final bool enableConcreteTypeInference; |
| 190 /** | 190 /** |
| 191 * The maximum size of a concrete type before it widens to dynamic during | 191 * The maximum size of a concrete type before it widens to dynamic during |
| 192 * concrete type inference. | 192 * concrete type inference. |
| 193 */ | 193 */ |
| 194 final int maxConcreteTypeSize; | 194 final int maxConcreteTypeSize; |
| 195 final bool analyzeAll; | 195 final bool analyzeAll; |
| 196 final bool analyzeOnly; | |
| 196 final bool enableNativeLiveTypeAnalysis; | 197 final bool enableNativeLiveTypeAnalysis; |
| 197 final bool rejectDeprecatedFeatures; | 198 final bool rejectDeprecatedFeatures; |
| 198 final bool checkDeprecationInSdk; | 199 final bool checkDeprecationInSdk; |
| 199 | 200 |
| 200 /** | 201 /** |
| 201 * If [:true:], comment tokens are collected in [commentMap] during scanning. | 202 * If [:true:], comment tokens are collected in [commentMap] during scanning. |
| 202 */ | 203 */ |
| 203 final bool preserveComments; | 204 final bool preserveComments; |
| 204 | 205 |
| 205 bool disableInlining = false; | 206 bool disableInlining = false; |
| 206 | 207 |
| 208 List<Uri> librariesToAnalyzeWhenRun; | |
| 209 | |
| 207 final Tracer tracer; | 210 final Tracer tracer; |
| 208 | 211 |
| 209 CompilerTask measuredTask; | 212 CompilerTask measuredTask; |
| 210 Element _currentElement; | 213 Element _currentElement; |
| 211 LibraryElement coreLibrary; | 214 LibraryElement coreLibrary; |
| 212 LibraryElement isolateLibrary; | 215 LibraryElement isolateLibrary; |
| 213 LibraryElement isolateHelperLibrary; | 216 LibraryElement isolateHelperLibrary; |
| 214 LibraryElement jsHelperLibrary; | 217 LibraryElement jsHelperLibrary; |
| 215 LibraryElement interceptorsLibrary; | 218 LibraryElement interceptorsLibrary; |
| 216 LibraryElement foreignLibrary; | 219 LibraryElement foreignLibrary; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 this.enableTypeAssertions: false, | 320 this.enableTypeAssertions: false, |
| 318 this.enableUserAssertions: false, | 321 this.enableUserAssertions: false, |
| 319 this.enableConcreteTypeInference: false, | 322 this.enableConcreteTypeInference: false, |
| 320 this.maxConcreteTypeSize: 5, | 323 this.maxConcreteTypeSize: 5, |
| 321 this.enableMinification: false, | 324 this.enableMinification: false, |
| 322 this.enableNativeLiveTypeAnalysis: false, | 325 this.enableNativeLiveTypeAnalysis: false, |
| 323 bool emitJavaScript: true, | 326 bool emitJavaScript: true, |
| 324 bool generateSourceMap: true, | 327 bool generateSourceMap: true, |
| 325 bool disallowUnsafeEval: false, | 328 bool disallowUnsafeEval: false, |
| 326 this.analyzeAll: false, | 329 this.analyzeAll: false, |
| 330 this.analyzeOnly: false, | |
| 327 this.rejectDeprecatedFeatures: false, | 331 this.rejectDeprecatedFeatures: false, |
| 328 this.checkDeprecationInSdk: false, | 332 this.checkDeprecationInSdk: false, |
| 329 this.preserveComments: false, | 333 this.preserveComments: false, |
| 330 List<String> strips: const []}) | 334 List<String> strips: const []}) |
| 331 : libraries = new Map<String, LibraryElement>(), | 335 : libraries = new Map<String, LibraryElement>(), |
| 332 progress = new Stopwatch() { | 336 progress = new Stopwatch() { |
| 333 progress.start(); | 337 progress.start(); |
| 334 world = new World(this); | 338 world = new World(this); |
| 335 | 339 |
| 336 closureMapping.ClosureNamer closureNamer; | 340 closureMapping.ClosureNamer closureNamer; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 if (libraryName == 'dart:isolate' | 631 if (libraryName == 'dart:isolate' |
| 628 || libraryName == 'dart:html' | 632 || libraryName == 'dart:html' |
| 629 // TODO(floitsch): create a separate async-helper library instead of | 633 // TODO(floitsch): create a separate async-helper library instead of |
| 630 // importing the isolate-library just for TimerImpl. | 634 // importing the isolate-library just for TimerImpl. |
| 631 || libraryName == 'dart:async') { | 635 || libraryName == 'dart:async') { |
| 632 importIsolateHelperLibrary(library); | 636 importIsolateHelperLibrary(library); |
| 633 } | 637 } |
| 634 } | 638 } |
| 635 | 639 |
| 636 void runCompiler(Uri uri) { | 640 void runCompiler(Uri uri) { |
| 637 log('compiling $uri ($BUILD_ID)'); | 641 assert(uri != null || analyzeOnly); |
| 638 scanBuiltinLibraries(); | 642 scanBuiltinLibraries(); |
| 639 mainApp = libraryLoader.loadLibrary(uri, null, uri); | 643 if (librariesToAnalyzeWhenRun != null) { |
| 644 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | |
| 645 log('analyzing $libraryUri ($BUILD_ID)'); | |
| 646 libraryLoader.loadLibrary(libraryUri, null, libraryUri); | |
| 647 } | |
| 648 } | |
| 649 if (uri != null) { | |
| 650 if (analyzeOnly) { | |
| 651 log('analyzing $uri ($BUILD_ID)'); | |
| 652 } else { | |
| 653 log('compiling $uri ($BUILD_ID)'); | |
| 654 } | |
| 655 mainApp = libraryLoader.loadLibrary(uri, null, uri); | |
| 656 } | |
| 640 libraries.forEach((_, library) { | 657 libraries.forEach((_, library) { |
| 641 maybeEnableJSHelper(library); | 658 maybeEnableJSHelper(library); |
| 642 maybeEnableIsolateHelper(library); | 659 maybeEnableIsolateHelper(library); |
| 643 }); | 660 }); |
| 644 final Element main = mainApp.find(MAIN); | 661 Element main = null; |
| 645 if (main == null) { | 662 if (mainApp != null) { |
| 646 reportFatalError('Could not find $MAIN', mainApp); | 663 main = mainApp.find(MAIN); |
| 647 } else { | 664 if (main == null) { |
| 648 if (!main.isFunction()) reportFatalError('main is not a function', main); | 665 if (!analyzeOnly) { |
| 649 FunctionElement mainMethod = main; | 666 // Allow analyze only of libraries with no main. |
| 650 FunctionSignature parameters = mainMethod.computeSignature(this); | 667 reportFatalError('Could not find $MAIN', mainApp); |
| 651 parameters.forEachParameter((Element parameter) { | 668 } else if (!analyzeAll) { |
| 652 reportFatalError('main cannot have parameters', parameter); | 669 reportFatalError( |
| 653 }); | 670 "Could not find $MAIN. " |
| 671 "No source will be analyzed. " | |
| 672 "Use '--analyze-all' to analyze all code in the library.", | |
| 673 mainApp); | |
|
Johnni Winther
2013/01/24 10:06:15
This will allow us to analyze dart:core from the c
| |
| 674 } | |
| 675 } else { | |
| 676 if (!main.isFunction()) { | |
| 677 reportFatalError('main is not a function', main); | |
| 678 } | |
| 679 FunctionElement mainMethod = main; | |
| 680 FunctionSignature parameters = mainMethod.computeSignature(this); | |
| 681 parameters.forEachParameter((Element parameter) { | |
| 682 reportFatalError('main cannot have parameters', parameter); | |
| 683 }); | |
| 684 } | |
| 654 } | 685 } |
| 655 | 686 |
| 656 log('Resolving...'); | 687 log('Resolving...'); |
| 657 phase = PHASE_RESOLVING; | 688 phase = PHASE_RESOLVING; |
| 658 if (analyzeAll) libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); | 689 if (analyzeAll) { |
| 690 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); | |
| 691 } | |
| 659 backend.enqueueHelpers(enqueuer.resolution); | 692 backend.enqueueHelpers(enqueuer.resolution); |
| 660 processQueue(enqueuer.resolution, main); | 693 processQueue(enqueuer.resolution, main); |
| 661 enqueuer.resolution.logSummary(log); | 694 enqueuer.resolution.logSummary(log); |
| 662 | 695 |
| 663 if (compilationFailed) return; | 696 if (compilationFailed) return; |
| 697 if (analyzeOnly) return; | |
| 698 assert(main != null); | |
| 664 | 699 |
| 665 log('Inferring types...'); | 700 log('Inferring types...'); |
| 666 typesTask.onResolutionComplete(main); | 701 typesTask.onResolutionComplete(main); |
| 667 | 702 |
| 668 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution | 703 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution |
| 669 // should know this. | 704 // should know this. |
| 670 world.populate(); | 705 world.populate(); |
| 671 | 706 |
| 672 log('Compiling...'); | 707 log('Compiling...'); |
| 673 phase = PHASE_COMPILING; | 708 phase = PHASE_COMPILING; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 693 | 728 |
| 694 void fullyEnqueueLibrary(LibraryElement library) { | 729 void fullyEnqueueLibrary(LibraryElement library) { |
| 695 library.forEachLocalMember(fullyEnqueueTopLevelElement); | 730 library.forEachLocalMember(fullyEnqueueTopLevelElement); |
| 696 } | 731 } |
| 697 | 732 |
| 698 void fullyEnqueueTopLevelElement(Element element) { | 733 void fullyEnqueueTopLevelElement(Element element) { |
| 699 if (element.isClass()) { | 734 if (element.isClass()) { |
| 700 ClassElement cls = element; | 735 ClassElement cls = element; |
| 701 cls.ensureResolved(this); | 736 cls.ensureResolved(this); |
| 702 cls.forEachLocalMember(enqueuer.resolution.addToWorkList); | 737 cls.forEachLocalMember(enqueuer.resolution.addToWorkList); |
| 738 } else if (element.isTypedef()) { | |
| 739 TypedefElement typdef = element; | |
| 740 typdef.computeType(this); | |
| 703 } else { | 741 } else { |
| 704 enqueuer.resolution.addToWorkList(element); | 742 enqueuer.resolution.addToWorkList(element); |
| 705 } | 743 } |
| 706 } | 744 } |
| 707 | 745 |
| 708 void processQueue(Enqueuer world, Element main) { | 746 void processQueue(Enqueuer world, Element main) { |
| 709 world.nativeEnqueuer.processNativeClasses(libraries.values); | 747 world.nativeEnqueuer.processNativeClasses(libraries.values); |
| 710 world.addToWorkList(main); | 748 if (main != null) { |
| 749 world.addToWorkList(main); | |
| 750 } | |
| 711 progress.reset(); | 751 progress.reset(); |
| 712 world.forEach((WorkItem work) { | 752 world.forEach((WorkItem work) { |
| 713 withCurrentElement(work.element, () => work.run(this, world)); | 753 withCurrentElement(work.element, () => work.run(this, world)); |
| 714 }); | 754 }); |
| 715 world.queueIsClosed = true; | 755 world.queueIsClosed = true; |
| 716 if (compilationFailed) return; | 756 if (compilationFailed) return; |
| 717 assert(world.checkNoEnqueuedInvokedInstanceMethods()); | 757 assert(world.checkNoEnqueuedInvokedInstanceMethods()); |
| 718 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { | 758 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { |
| 719 backend.dumpInferredTypes(); | 759 backend.dumpInferredTypes(); |
| 720 } | 760 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1079 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 1119 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 1080 // information on assertion errors. | 1120 // information on assertion errors. |
| 1081 if (condition is Function){ | 1121 if (condition is Function){ |
| 1082 condition = condition(); | 1122 condition = condition(); |
| 1083 } | 1123 } |
| 1084 if (spannable == null || !condition) { | 1124 if (spannable == null || !condition) { |
| 1085 throw new SpannableAssertionFailure(spannable, message); | 1125 throw new SpannableAssertionFailure(spannable, message); |
| 1086 } | 1126 } |
| 1087 return true; | 1127 return true; |
| 1088 } | 1128 } |
| OLD | NEW |