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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 bool isDefaultNoSuchMethodImplementation(Element element) { | 390 bool isDefaultNoSuchMethodImplementation(Element element) { |
391 assert(element.name == Compiler.NO_SUCH_METHOD); | 391 assert(element.name == Compiler.NO_SUCH_METHOD); |
392 ClassElement classElement = element.enclosingClass; | 392 ClassElement classElement = element.enclosingClass; |
393 return classElement == compiler.objectClass; | 393 return classElement == compiler.objectClass; |
394 } | 394 } |
395 | 395 |
396 bool isInterceptorClass(ClassElement element) => false; | 396 bool isInterceptorClass(ClassElement element) => false; |
397 | 397 |
398 void registerStaticUse(Element element, Enqueuer enqueuer) {} | 398 void registerStaticUse(Element element, Enqueuer enqueuer) {} |
399 | 399 |
400 Future onLibraryLoaded(LibraryElement library, Uri uri) { | 400 /// This method is called immediately after the [LibraryElement] [library] has |
401 /// been created. | |
402 void onLibraryCreated(LibraryElement library) {} | |
403 | |
404 /// This method is called immediately after the [library] and its parts have | |
405 /// been scanned. | |
406 void onLibraryScanned(LibraryElement library) {} | |
407 | |
408 /// This method is called when all new libraries loaded through | |
409 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | |
410 /// have been computed. | |
411 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { | |
401 return new Future.value(); | 412 return new Future.value(); |
402 } | 413 } |
403 | 414 |
404 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed | 415 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed |
405 /// annotations. The arguments corresponds to the unions of the corresponding | 416 /// annotations. The arguments corresponds to the unions of the corresponding |
406 /// fields of the annotations. | 417 /// fields of the annotations. |
407 void registerMirrorUsage(Set<String> symbols, | 418 void registerMirrorUsage(Set<String> symbols, |
408 Set<Element> targets, | 419 Set<Element> targets, |
409 Set<Element> metaTargets) {} | 420 Set<Element> metaTargets) {} |
410 | 421 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 | 484 |
474 abstract class Compiler implements DiagnosticListener { | 485 abstract class Compiler implements DiagnosticListener { |
475 static final Uri DART_CORE = new Uri(scheme: 'dart', path: 'core'); | 486 static final Uri DART_CORE = new Uri(scheme: 'dart', path: 'core'); |
476 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); | 487 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); |
477 static final Uri DART_INTERCEPTORS = | 488 static final Uri DART_INTERCEPTORS = |
478 new Uri(scheme: 'dart', path: '_interceptors'); | 489 new Uri(scheme: 'dart', path: '_interceptors'); |
479 static final Uri DART_FOREIGN_HELPER = | 490 static final Uri DART_FOREIGN_HELPER = |
480 new Uri(scheme: 'dart', path: '_foreign_helper'); | 491 new Uri(scheme: 'dart', path: '_foreign_helper'); |
481 static final Uri DART_ISOLATE_HELPER = | 492 static final Uri DART_ISOLATE_HELPER = |
482 new Uri(scheme: 'dart', path: '_isolate_helper'); | 493 new Uri(scheme: 'dart', path: '_isolate_helper'); |
494 static final Uri DART_MIRRORS = new Uri(scheme: 'dart', path: 'mirrors'); | |
495 static final Uri DART_NATIVE_TYPED_DATA = | |
496 new Uri(scheme: 'dart', path: '_native_typed_data'); | |
497 static final Uri DART_INTERNAL = new Uri(scheme: 'dart', path: '_internal'); | |
498 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); | |
499 | |
500 // TODO(johnniwinther): Change to map from [Uri] to [LibraryElement]. | |
483 final Map<String, LibraryElement> libraries = | 501 final Map<String, LibraryElement> libraries = |
484 new Map<String, LibraryElement>(); | 502 new Map<String, LibraryElement>(); |
485 final Stopwatch totalCompileTime = new Stopwatch(); | 503 final Stopwatch totalCompileTime = new Stopwatch(); |
486 int nextFreeClassId = 0; | 504 int nextFreeClassId = 0; |
487 World world; | 505 World world; |
488 String assembledCode; | 506 String assembledCode; |
489 Types types; | 507 Types types; |
490 | 508 |
491 /** | 509 /** |
492 * Map from token to the first preceeding comment token. | 510 * Map from token to the first preceeding comment token. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 | 611 |
594 List<Uri> librariesToAnalyzeWhenRun; | 612 List<Uri> librariesToAnalyzeWhenRun; |
595 | 613 |
596 Tracer tracer; | 614 Tracer tracer; |
597 | 615 |
598 CompilerTask measuredTask; | 616 CompilerTask measuredTask; |
599 Element _currentElement; | 617 Element _currentElement; |
600 LibraryElement coreLibrary; | 618 LibraryElement coreLibrary; |
601 LibraryElement isolateLibrary; | 619 LibraryElement isolateLibrary; |
602 LibraryElement isolateHelperLibrary; | 620 LibraryElement isolateHelperLibrary; |
621 // TODO(johnniwinther): Move JavaScript specific libraries to the JavaScript | |
622 // backend. | |
603 LibraryElement jsHelperLibrary; | 623 LibraryElement jsHelperLibrary; |
604 LibraryElement interceptorsLibrary; | 624 LibraryElement interceptorsLibrary; |
605 LibraryElement foreignLibrary; | 625 LibraryElement foreignLibrary; |
606 | 626 |
607 LibraryElement mainApp; | 627 LibraryElement mainApp; |
608 FunctionElement mainFunction; | 628 FunctionElement mainFunction; |
609 | 629 |
610 /// Initialized when dart:mirrors is loaded. | 630 /// Initialized when dart:mirrors is loaded. |
611 LibraryElement mirrorsLibrary; | 631 LibraryElement mirrorsLibrary; |
612 | 632 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 | 810 |
791 bool hasCrashed = false; | 811 bool hasCrashed = false; |
792 | 812 |
793 /// Set by the backend if real reflection is detected in use of dart:mirrors. | 813 /// Set by the backend if real reflection is detected in use of dart:mirrors. |
794 bool disableTypeInferenceForMirrors = false; | 814 bool disableTypeInferenceForMirrors = false; |
795 | 815 |
796 Compiler({this.enableTypeAssertions: false, | 816 Compiler({this.enableTypeAssertions: false, |
797 this.enableUserAssertions: false, | 817 this.enableUserAssertions: false, |
798 this.trustTypeAnnotations: false, | 818 this.trustTypeAnnotations: false, |
799 this.enableConcreteTypeInference: false, | 819 this.enableConcreteTypeInference: false, |
800 this.disableTypeInferenceFlag: false, | 820 bool disableTypeInferenceFlag: false, |
801 this.maxConcreteTypeSize: 5, | 821 this.maxConcreteTypeSize: 5, |
802 this.enableMinification: false, | 822 this.enableMinification: false, |
803 this.enableNativeLiveTypeAnalysis: false, | 823 this.enableNativeLiveTypeAnalysis: false, |
804 bool emitJavaScript: true, | 824 bool emitJavaScript: true, |
805 bool generateSourceMap: true, | 825 bool generateSourceMap: true, |
806 bool analyzeAllFlag: false, | 826 bool analyzeAllFlag: false, |
807 bool analyzeOnly: false, | 827 bool analyzeOnly: false, |
808 this.analyzeMain: false, | 828 this.analyzeMain: false, |
809 bool analyzeSignaturesOnly: false, | 829 bool analyzeSignaturesOnly: false, |
810 this.preserveComments: false, | 830 this.preserveComments: false, |
811 this.verbose: false, | 831 this.verbose: false, |
812 this.sourceMapUri: null, | 832 this.sourceMapUri: null, |
813 this.outputUri: null, | 833 this.outputUri: null, |
814 this.buildId: UNDETERMINED_BUILD_ID, | 834 this.buildId: UNDETERMINED_BUILD_ID, |
815 this.terseDiagnostics: false, | 835 this.terseDiagnostics: false, |
816 this.disableDeferredLoading: false, | 836 this.disableDeferredLoading: false, |
817 this.dumpInfo: false, | 837 this.dumpInfo: false, |
818 this.showPackageWarnings: false, | 838 this.showPackageWarnings: false, |
819 this.useContentSecurityPolicy: false, | 839 this.useContentSecurityPolicy: false, |
820 this.suppressWarnings: false, | 840 this.suppressWarnings: false, |
821 outputProvider, | 841 outputProvider, |
822 List<String> strips: const []}) | 842 List<String> strips: const []}) |
823 : this.analyzeOnly = | 843 : this.disableTypeInferenceFlag = |
844 disableTypeInferenceFlag || !emitJavaScript, | |
845 this.analyzeOnly = | |
824 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, | 846 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, |
825 this.analyzeSignaturesOnly = analyzeSignaturesOnly, | 847 this.analyzeSignaturesOnly = analyzeSignaturesOnly, |
826 this.analyzeAllFlag = analyzeAllFlag, | 848 this.analyzeAllFlag = analyzeAllFlag, |
827 this.outputProvider = (outputProvider == null) | 849 this.outputProvider = (outputProvider == null) |
828 ? NullSink.outputProvider | 850 ? NullSink.outputProvider |
829 : outputProvider { | 851 : outputProvider { |
830 world = new World(this); | 852 world = new World(this); |
853 types = new Types(this); | |
831 tracer = new Tracer(this.outputProvider); | 854 tracer = new Tracer(this.outputProvider); |
832 | 855 |
833 closureMapping.ClosureNamer closureNamer; | 856 closureMapping.ClosureNamer closureNamer; |
834 if (emitJavaScript) { | 857 if (emitJavaScript) { |
835 js_backend.JavaScriptBackend jsBackend = | 858 js_backend.JavaScriptBackend jsBackend = |
836 new js_backend.JavaScriptBackend(this, generateSourceMap); | 859 new js_backend.JavaScriptBackend(this, generateSourceMap); |
837 closureNamer = jsBackend.namer; | 860 closureNamer = jsBackend.namer; |
838 backend = jsBackend; | 861 backend = jsBackend; |
839 } else { | 862 } else { |
840 closureNamer = new closureMapping.ClosureNamer(); | 863 closureNamer = new closureMapping.ClosureNamer(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 }).whenComplete(() { | 1002 }).whenComplete(() { |
980 tracer.close(); | 1003 tracer.close(); |
981 totalCompileTime.stop(); | 1004 totalCompileTime.stop(); |
982 }).then((_) { | 1005 }).then((_) { |
983 return !compilationFailed; | 1006 return !compilationFailed; |
984 }); | 1007 }); |
985 } | 1008 } |
986 | 1009 |
987 bool hasIsolateSupport() => isolateLibrary != null; | 1010 bool hasIsolateSupport() => isolateLibrary != null; |
988 | 1011 |
989 /** | 1012 /// This method is called immediately after the [LibraryElement] [library] has |
990 * This method is called before [library] import and export scopes have been | 1013 /// been created. |
991 * set up. | 1014 /// |
992 */ | 1015 /// Use this callback method to store references to specific libraries. |
993 Future onLibraryLoaded(LibraryElement library, Uri uri) { | 1016 /// Note that [library] has not been scanned yet, nor has its imports/exports |
994 if (uri == new Uri(scheme: 'dart', path: 'mirrors')) { | 1017 /// been resolved. |
1018 void onLibraryCreated(LibraryElement library) { | |
1019 Uri uri = library.canonicalUri; | |
1020 if (uri == DART_CORE) { | |
1021 coreLibrary = library; | |
1022 } else if (uri == DART_JS_HELPER) { | |
1023 jsHelperLibrary = library; | |
1024 } else if (uri == DART_INTERCEPTORS) { | |
1025 interceptorsLibrary = library; | |
1026 } else if (uri == DART_FOREIGN_HELPER) { | |
1027 foreignLibrary = library; | |
1028 } else if (uri == DART_ISOLATE_HELPER) { | |
1029 isolateHelperLibrary = library; | |
1030 } else if (uri == DART_NATIVE_TYPED_DATA) { | |
1031 typedDataLibrary = library; | |
1032 } else if (uri == DART_MIRRORS) { | |
995 mirrorsLibrary = library; | 1033 mirrorsLibrary = library; |
996 mirrorSystemClass = | |
997 findRequiredElement(library, 'MirrorSystem'); | |
998 mirrorsUsedClass = | |
999 findRequiredElement(library, 'MirrorsUsed'); | |
1000 } else if (uri == new Uri(scheme: 'dart', path: '_native_typed_data')) { | |
1001 typedDataLibrary = library; | |
1002 typedDataClass = | |
1003 findRequiredElement(library, 'NativeTypedData'); | |
1004 } else if (uri == new Uri(scheme: 'dart', path: '_internal')) { | |
1005 symbolImplementationClass = | |
1006 findRequiredElement(library, 'Symbol'); | |
1007 } else if (uri == new Uri(scheme: 'dart', path: 'async')) { | |
1008 deferredLibraryClass = | |
1009 findRequiredElement(library, 'DeferredLibrary'); | |
1010 } else if (isolateHelperLibrary == null | |
1011 && (uri == new Uri(scheme: 'dart', path: '_isolate_helper'))) { | |
1012 isolateHelperLibrary = library; | |
1013 } else if (foreignLibrary == null | |
1014 && (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) { | |
1015 foreignLibrary = library; | |
1016 } | 1034 } |
1017 return backend.onLibraryLoaded(library, uri); | 1035 backend.onLibraryCreated(library); |
1036 } | |
1037 | |
1038 /// This method is called immediately after the [library] and its parts have | |
1039 /// been scanned. | |
1040 /// | |
1041 /// Use this callback method to store references to specific member declared | |
1042 /// in certain libraries. Note that [library] has not been patched yet, nor | |
1043 /// has its imports/exports been resolved. | |
1044 void onLibraryScanned(LibraryElement library) { | |
1045 Uri uri = library.canonicalUri; | |
1046 if (uri == DART_CORE) { | |
1047 initializeCoreClasses(); | |
1048 identicalFunction = coreLibrary.find('identical'); | |
1049 } else if (uri == DART_JS_HELPER) { | |
1050 initializeHelperClasses(); | |
1051 assertMethod = jsHelperLibrary.find('assertHelper'); | |
1052 } else if (uri == DART_INTERNAL) { | |
1053 symbolImplementationClass = findRequiredElement(library, 'Symbol'); | |
1054 } else if (uri == DART_MIRRORS) { | |
1055 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); | |
1056 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); | |
1057 } else if (uri == DART_ASYNC) { | |
1058 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); | |
1059 } else if (uri == DART_NATIVE_TYPED_DATA) { | |
1060 typedDataClass = findRequiredElement(library, 'NativeTypedData'); | |
1061 } | |
1062 backend.onLibraryScanned(library); | |
1063 } | |
1064 | |
1065 /// This method is called when all new libraries loaded through | |
1066 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | |
1067 /// have been computed. | |
1068 /// | |
1069 /// [loadedLibraries] contains the newly loaded libraries. | |
1070 /// | |
1071 /// The method returns a [Future] allowing for the loading of additional | |
1072 /// libraries. | |
1073 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { | |
1074 return new Future.sync(() { | |
1075 if (!loadedLibraries.containsKey(DART_CORE)) return new Future.value(); | |
1076 | |
1077 functionClass.ensureResolved(this); | |
1078 functionApplyMethod = functionClass.lookupLocalMember('apply'); | |
1079 | |
1080 proxyConstant = | |
1081 resolver.constantCompiler.compileConstant(coreLibrary.find('proxy')); | |
1082 | |
1083 if (jsInvocationMirrorClass != null) { | |
1084 jsInvocationMirrorClass.ensureResolved(this); | |
1085 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | |
1086 } | |
1087 | |
1088 if (preserveComments) { | |
1089 return libraryLoader.loadLibrary(DART_MIRRORS) | |
1090 .then((LibraryElement libraryElement) { | |
1091 documentClass = libraryElement.find('Comment'); | |
1092 }); | |
1093 } | |
1094 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); | |
1018 } | 1095 } |
1019 | 1096 |
1020 Element findRequiredElement(LibraryElement library, String name) { | 1097 Element findRequiredElement(LibraryElement library, String name) { |
1021 var element = library.find(name); | 1098 var element = library.find(name); |
1022 if (element == null) { | 1099 if (element == null) { |
1023 internalError(library, | 1100 internalError(library, |
1024 "The library '${library.canonicalUri}' does not contain required " | 1101 "The library '${library.canonicalUri}' does not contain required " |
1025 "element: '$name'."); | 1102 "element: '$name'."); |
1026 } | 1103 } |
1027 return element; | 1104 return element; |
(...skipping 13 matching lines...) Expand all Loading... | |
1041 } else if (intClass == cls) { | 1118 } else if (intClass == cls) { |
1042 intEnvironment = intClass.lookupConstructor(fromEnvironmentSelector); | 1119 intEnvironment = intClass.lookupConstructor(fromEnvironmentSelector); |
1043 } else if (stringClass == cls) { | 1120 } else if (stringClass == cls) { |
1044 stringEnvironment = | 1121 stringEnvironment = |
1045 stringClass.lookupConstructor(fromEnvironmentSelector); | 1122 stringClass.lookupConstructor(fromEnvironmentSelector); |
1046 } else if (boolClass == cls) { | 1123 } else if (boolClass == cls) { |
1047 boolEnvironment = boolClass.lookupConstructor(fromEnvironmentSelector); | 1124 boolEnvironment = boolClass.lookupConstructor(fromEnvironmentSelector); |
1048 } | 1125 } |
1049 } | 1126 } |
1050 | 1127 |
1051 Future<LibraryElement> scanBuiltinLibrary(String filename); | 1128 void initializeCoreClasses() { |
1052 | |
1053 void initializeSpecialClasses() { | |
1054 final List missingCoreClasses = []; | 1129 final List missingCoreClasses = []; |
1055 ClassElement lookupCoreClass(String name) { | 1130 ClassElement lookupCoreClass(String name) { |
1056 ClassElement result = coreLibrary.find(name); | 1131 ClassElement result = coreLibrary.find(name); |
1057 if (result == null) { | 1132 if (result == null) { |
1058 missingCoreClasses.add(name); | 1133 missingCoreClasses.add(name); |
1059 } | 1134 } |
1060 return result; | 1135 return result; |
1061 } | 1136 } |
1062 objectClass = lookupCoreClass('Object'); | 1137 objectClass = lookupCoreClass('Object'); |
1063 boolClass = lookupCoreClass('bool'); | 1138 boolClass = lookupCoreClass('bool'); |
(...skipping 10 matching lines...) Expand all Loading... | |
1074 if (!missingCoreClasses.isEmpty) { | 1149 if (!missingCoreClasses.isEmpty) { |
1075 internalError(coreLibrary, | 1150 internalError(coreLibrary, |
1076 'dart:core library does not contain required classes: ' | 1151 'dart:core library does not contain required classes: ' |
1077 '$missingCoreClasses'); | 1152 '$missingCoreClasses'); |
1078 } | 1153 } |
1079 | 1154 |
1080 // The Symbol class may not exist during unit testing. | 1155 // The Symbol class may not exist during unit testing. |
1081 // TODO(ahe): It is possible that we have to require the presence | 1156 // TODO(ahe): It is possible that we have to require the presence |
1082 // of Symbol as we change how we implement noSuchMethod. | 1157 // of Symbol as we change how we implement noSuchMethod. |
1083 symbolClass = lookupCoreClass('Symbol'); | 1158 symbolClass = lookupCoreClass('Symbol'); |
1159 } | |
1084 | 1160 |
1161 void initializeHelperClasses() { | |
1085 final List missingHelperClasses = []; | 1162 final List missingHelperClasses = []; |
1086 ClassElement lookupHelperClass(String name) { | 1163 ClassElement lookupHelperClass(String name) { |
1087 ClassElement result = jsHelperLibrary.find(name); | 1164 ClassElement result = jsHelperLibrary.find(name); |
1088 if (result == null) { | 1165 if (result == null) { |
1089 missingHelperClasses.add(name); | 1166 missingHelperClasses.add(name); |
1090 } | 1167 } |
1091 return result; | 1168 return result; |
1092 } | 1169 } |
1093 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); | 1170 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); |
1094 boundClosureClass = lookupHelperClass('BoundClosure'); | 1171 boundClosureClass = lookupHelperClass('BoundClosure'); |
1095 closureClass = lookupHelperClass('Closure'); | 1172 closureClass = lookupHelperClass('Closure'); |
1096 if (!missingHelperClasses.isEmpty) { | 1173 if (!missingHelperClasses.isEmpty) { |
1097 internalError(jsHelperLibrary, | 1174 internalError(jsHelperLibrary, |
1098 'dart:_js_helper library does not contain required classes: ' | 1175 'dart:_js_helper library does not contain required classes: ' |
1099 '$missingHelperClasses'); | 1176 '$missingHelperClasses'); |
1100 } | 1177 } |
1101 | |
1102 if (types == null) { | |
1103 types = new Types(this); | |
1104 } | |
1105 backend.initializeHelperClasses(); | |
1106 | |
1107 proxyConstant = | |
1108 resolver.constantCompiler.compileConstant(coreLibrary.find('proxy')); | |
1109 } | 1178 } |
1110 | 1179 |
1111 Element _unnamedListConstructor; | 1180 Element _unnamedListConstructor; |
1112 Element get unnamedListConstructor { | 1181 Element get unnamedListConstructor { |
1113 if (_unnamedListConstructor != null) return _unnamedListConstructor; | 1182 if (_unnamedListConstructor != null) return _unnamedListConstructor; |
1114 Selector callConstructor = new Selector.callConstructor( | 1183 Selector callConstructor = new Selector.callConstructor( |
1115 "", listClass.library); | 1184 "", listClass.library); |
1116 return _unnamedListConstructor = | 1185 return _unnamedListConstructor = |
1117 listClass.lookupConstructor(callConstructor); | 1186 listClass.lookupConstructor(callConstructor); |
1118 } | 1187 } |
1119 | 1188 |
1120 Element _filledListConstructor; | 1189 Element _filledListConstructor; |
1121 Element get filledListConstructor { | 1190 Element get filledListConstructor { |
1122 if (_filledListConstructor != null) return _filledListConstructor; | 1191 if (_filledListConstructor != null) return _filledListConstructor; |
1123 Selector callConstructor = new Selector.callConstructor( | 1192 Selector callConstructor = new Selector.callConstructor( |
1124 "filled", listClass.library); | 1193 "filled", listClass.library); |
1125 return _filledListConstructor = | 1194 return _filledListConstructor = |
1126 listClass.lookupConstructor(callConstructor); | 1195 listClass.lookupConstructor(callConstructor); |
1127 } | 1196 } |
1128 | 1197 |
1129 Future scanBuiltinLibraries() { | |
1130 return scanBuiltinLibrary('_js_helper').then((LibraryElement library) { | |
1131 jsHelperLibrary = library; | |
1132 return scanBuiltinLibrary('_interceptors'); | |
1133 }).then((LibraryElement library) { | |
1134 interceptorsLibrary = library; | |
1135 | |
1136 assertMethod = jsHelperLibrary.find('assertHelper'); | |
1137 identicalFunction = coreLibrary.find('identical'); | |
1138 | |
1139 initializeSpecialClasses(); | |
1140 | |
1141 functionClass.ensureResolved(this); | |
1142 functionApplyMethod = | |
1143 functionClass.lookupLocalMember('apply'); | |
1144 jsInvocationMirrorClass.ensureResolved(this); | |
1145 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | |
1146 | |
1147 if (preserveComments) { | |
1148 var uri = new Uri(scheme: 'dart', path: 'mirrors'); | |
1149 return libraryLoader.loadLibrary(uri, null, uri).then( | |
1150 (LibraryElement libraryElement) { | |
1151 documentClass = libraryElement.find('Comment'); | |
1152 }); | |
1153 } | |
1154 }); | |
1155 } | |
1156 | |
1157 void importHelperLibrary(LibraryElement library) { | |
1158 if (jsHelperLibrary != null) { | |
1159 libraryLoader.importLibrary(library, jsHelperLibrary, null); | |
1160 } | |
1161 } | |
1162 | |
1163 /** | 1198 /** |
1164 * Get an [Uri] pointing to a patch for the dart: library with | 1199 * Get an [Uri] pointing to a patch for the dart: library with |
1165 * the given path. Returns null if there is no patch. | 1200 * the given path. Returns null if there is no patch. |
1166 */ | 1201 */ |
1167 Uri resolvePatchUri(String dartLibraryPath); | 1202 Uri resolvePatchUri(String dartLibraryPath); |
1168 | 1203 |
1169 Future runCompiler(Uri uri) { | 1204 Future runCompiler(Uri uri) { |
1170 // TODO(ahe): This prevents memory leaks when invoking the compiler | 1205 // TODO(ahe): This prevents memory leaks when invoking the compiler |
1171 // multiple times. Implement a better mechanism where we can store | 1206 // multiple times. Implement a better mechanism where we can store |
1172 // such caches in the compiler and get access to them through a | 1207 // such caches in the compiler and get access to them through a |
1173 // suitably maintained static reference to the current compiler. | 1208 // suitably maintained static reference to the current compiler. |
1174 StringToken.canonicalizedSubstrings.clear(); | 1209 StringToken.canonicalizedSubstrings.clear(); |
1175 Selector.canonicalizedValues.clear(); | 1210 Selector.canonicalizedValues.clear(); |
1176 TypedSelector.canonicalizedValues.clear(); | 1211 TypedSelector.canonicalizedValues.clear(); |
1177 | 1212 |
1178 assert(uri != null || analyzeOnly); | 1213 assert(uri != null || analyzeOnly); |
1179 return scanBuiltinLibraries().then((_) { | 1214 return new Future.sync(() { |
1180 if (librariesToAnalyzeWhenRun != null) { | 1215 if (librariesToAnalyzeWhenRun != null) { |
1181 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { | 1216 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { |
1182 log('Analyzing $libraryUri ($buildId)'); | 1217 log('Analyzing $libraryUri ($buildId)'); |
1183 return libraryLoader.loadLibrary(libraryUri, null, libraryUri); | 1218 return libraryLoader.loadLibrary(libraryUri); |
1184 }); | 1219 }); |
1185 } | 1220 } |
1186 }).then((_) { | 1221 }).then((_) { |
1187 if (uri != null) { | 1222 if (uri != null) { |
1188 if (analyzeOnly) { | 1223 if (analyzeOnly) { |
1189 log('Analyzing $uri ($buildId)'); | 1224 log('Analyzing $uri ($buildId)'); |
1190 } else { | 1225 } else { |
1191 log('Compiling $uri ($buildId)'); | 1226 log('Compiling $uri ($buildId)'); |
1192 } | 1227 } |
1193 return libraryLoader.loadLibrary(uri, null, uri) | 1228 return libraryLoader.loadLibrary(uri).then((LibraryElement library) { |
1194 .then((LibraryElement library) { | |
1195 mainApp = library; | 1229 mainApp = library; |
1196 }); | 1230 }); |
1197 } | 1231 } |
1198 }).then((_) { | 1232 }).then((_) { |
1199 compileLoadedLibraries(); | 1233 if (!compilationFailed) { |
1234 // TODO(johnniwinther): Reenable analysis of programs with load failures | |
1235 // when these are handled as erroneous libraries/compilation units. | |
ahe
2014/07/17 08:33:13
I guess it isn't clear how detrimental fatal error
Johnni Winther
2014/07/17 11:13:03
Can you file a bug on this and put me in it?
| |
1236 compileLoadedLibraries(); | |
1237 } | |
1200 }); | 1238 }); |
1201 } | 1239 } |
1202 | 1240 |
1203 /// Performs the compilation when all libraries have been loaded. | 1241 /// Performs the compilation when all libraries have been loaded. |
1204 void compileLoadedLibraries() { | 1242 void compileLoadedLibraries() { |
1205 Element main = null; | 1243 Element main = null; |
1206 if (mainApp != null) { | 1244 if (mainApp != null) { |
1207 main = mainApp.findExported(MAIN); | 1245 main = mainApp.findExported(MAIN); |
1208 if (main == null) { | 1246 if (main == null) { |
1209 if (!analyzeOnly) { | 1247 if (!analyzeOnly) { |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1952 static NullSink outputProvider(String name, String extension) { | 1990 static NullSink outputProvider(String name, String extension) { |
1953 return new NullSink('$name.$extension'); | 1991 return new NullSink('$name.$extension'); |
1954 } | 1992 } |
1955 } | 1993 } |
1956 | 1994 |
1957 /// Information about suppressed warnings and hints for a given library. | 1995 /// Information about suppressed warnings and hints for a given library. |
1958 class SuppressionInfo { | 1996 class SuppressionInfo { |
1959 int warnings = 0; | 1997 int warnings = 0; |
1960 int hints = 0; | 1998 int hints = 0; |
1961 } | 1999 } |
OLD | NEW |