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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 checkNativeAnnotation(compiler, element); | 421 checkNativeAnnotation(compiler, element); |
422 } | 422 } |
423 }); | 423 }); |
424 } | 424 } |
425 return new Future.value(); | 425 return new Future.value(); |
426 } | 426 } |
427 | 427 |
428 /// This method is called when all new libraries loaded through | 428 /// This method is called when all new libraries loaded through |
429 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 429 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
430 /// have been computed. | 430 /// have been computed. |
431 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { | 431 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
432 return new Future.value(); | 432 return new Future.value(); |
433 } | 433 } |
434 | 434 |
435 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed | 435 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed |
436 /// annotations. The arguments corresponds to the unions of the corresponding | 436 /// annotations. The arguments corresponds to the unions of the corresponding |
437 /// fields of the annotations. | 437 /// fields of the annotations. |
438 void registerMirrorUsage(Set<String> symbols, | 438 void registerMirrorUsage(Set<String> symbols, |
439 Set<Element> targets, | 439 Set<Element> targets, |
440 Set<Element> metaTargets) {} | 440 Set<Element> metaTargets) {} |
441 | 441 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 final Selector symbolValidatedConstructorSelector = new Selector.call( | 896 final Selector symbolValidatedConstructorSelector = new Selector.call( |
897 'validated', null, 1); | 897 'validated', null, 1); |
898 final Selector fromEnvironmentSelector = new Selector.callConstructor( | 898 final Selector fromEnvironmentSelector = new Selector.callConstructor( |
899 'fromEnvironment', null, 2); | 899 'fromEnvironment', null, 2); |
900 | 900 |
901 bool enabledNoSuchMethod = false; | 901 bool enabledNoSuchMethod = false; |
902 bool enabledRuntimeType = false; | 902 bool enabledRuntimeType = false; |
903 bool enabledFunctionApply = false; | 903 bool enabledFunctionApply = false; |
904 bool enabledInvokeOn = false; | 904 bool enabledInvokeOn = false; |
905 bool hasIsolateSupport = false; | 905 bool hasIsolateSupport = false; |
906 final bool enableExperimentalMirrors; | |
906 | 907 |
907 Stopwatch progress; | 908 Stopwatch progress; |
908 | 909 |
909 bool get shouldPrintProgress { | 910 bool get shouldPrintProgress { |
910 return verbose && progress.elapsedMilliseconds > 500; | 911 return verbose && progress.elapsedMilliseconds > 500; |
911 } | 912 } |
912 | 913 |
913 static const int PHASE_SCANNING = 0; | 914 static const int PHASE_SCANNING = 0; |
914 static const int PHASE_RESOLVING = 1; | 915 static const int PHASE_RESOLVING = 1; |
915 static const int PHASE_DONE_RESOLVING = 2; | 916 static const int PHASE_DONE_RESOLVING = 2; |
(...skipping 26 matching lines...) Expand all Loading... | |
942 this.verbose: false, | 943 this.verbose: false, |
943 this.sourceMapUri: null, | 944 this.sourceMapUri: null, |
944 this.outputUri: null, | 945 this.outputUri: null, |
945 this.buildId: UNDETERMINED_BUILD_ID, | 946 this.buildId: UNDETERMINED_BUILD_ID, |
946 this.terseDiagnostics: false, | 947 this.terseDiagnostics: false, |
947 this.dumpInfo: false, | 948 this.dumpInfo: false, |
948 this.showPackageWarnings: false, | 949 this.showPackageWarnings: false, |
949 this.useContentSecurityPolicy: false, | 950 this.useContentSecurityPolicy: false, |
950 this.suppressWarnings: false, | 951 this.suppressWarnings: false, |
951 bool hasIncrementalSupport: false, | 952 bool hasIncrementalSupport: false, |
953 this.enableExperimentalMirrors: false, | |
952 api.CompilerOutputProvider outputProvider, | 954 api.CompilerOutputProvider outputProvider, |
953 List<String> strips: const []}) | 955 List<String> strips: const []}) |
954 : this.disableTypeInferenceFlag = | 956 : this.disableTypeInferenceFlag = |
955 disableTypeInferenceFlag || !emitJavaScript, | 957 disableTypeInferenceFlag || !emitJavaScript, |
956 this.analyzeOnly = | 958 this.analyzeOnly = |
957 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, | 959 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, |
958 this.analyzeSignaturesOnly = analyzeSignaturesOnly, | 960 this.analyzeSignaturesOnly = analyzeSignaturesOnly, |
959 this.analyzeAllFlag = analyzeAllFlag, | 961 this.analyzeAllFlag = analyzeAllFlag, |
960 this.hasIncrementalSupport = hasIncrementalSupport, | 962 this.hasIncrementalSupport = hasIncrementalSupport, |
961 cacheStrategy = new CacheStrategy(hasIncrementalSupport), | 963 cacheStrategy = new CacheStrategy(hasIncrementalSupport), |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 } | 1187 } |
1186 | 1188 |
1187 /// This method is called when all new libraries loaded through | 1189 /// This method is called when all new libraries loaded through |
1188 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 1190 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
1189 /// have been computed. | 1191 /// have been computed. |
1190 /// | 1192 /// |
1191 /// [loadedLibraries] contains the newly loaded libraries. | 1193 /// [loadedLibraries] contains the newly loaded libraries. |
1192 /// | 1194 /// |
1193 /// The method returns a [Future] allowing for the loading of additional | 1195 /// The method returns a [Future] allowing for the loading of additional |
1194 /// libraries. | 1196 /// libraries. |
1195 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { | 1197 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
1196 return new Future.sync(() { | 1198 return new Future.sync(() { |
1197 if (!loadedLibraries.containsKey(DART_CORE)) return new Future.value(); | 1199 if (!loadedLibraries.containsLibrary(DART_CORE)) { |
1200 return new Future.value(); | |
floitsch
2014/09/22 20:52:59
return null is the same, since we are already in a
Johnni Winther
2014/11/12 13:06:26
Done.
| |
1201 } | |
1202 if (!enableExperimentalMirrors && | |
1203 loadedLibraries.containsLibrary(DART_MIRRORS)) { | |
1204 Uri rootUri = loadedLibraries.rootUri; | |
1205 Set<String> importChains = new Set<String>(); | |
1206 loadedLibraries.forEachImportChain( | |
floitsch
2014/09/22 20:52:59
I would make this a function on LoadedLibraries:
Johnni Winther
2014/11/12 13:06:26
Added a TODO. We need to store the libraries for i
| |
1207 (LibraryElement library, Link<Uri> importChainReversed) { | |
1208 if (library.canonicalUri != DART_MIRRORS) return; | |
1209 Link<CodeLocation> compactImportChain = const Link<CodeLocation>(); | |
1210 CodeLocation currentCodeLocation = new UriLocation(DART_MIRRORS); | |
1211 compactImportChain = compactImportChain.prepend(currentCodeLocation); | |
1212 for (Link<Uri> link = importChainReversed; | |
1213 !link.isEmpty; | |
1214 link = link.tail) { | |
1215 Uri uri = link.head; | |
1216 if (!currentCodeLocation.inSameLocation(uri)) { | |
1217 currentCodeLocation = | |
1218 verbose ? new UriLocation(uri) : new CodeLocation(uri); | |
1219 compactImportChain = | |
1220 compactImportChain.prepend(currentCodeLocation); | |
1221 } | |
1222 } | |
1223 importChains.add(compactImportChain.map((CodeLocation codeLocation) { | |
1224 return codeLocation.relativize(rootUri); | |
1225 }).join(' => ')); | |
1226 }); | |
1227 reportWarning(NO_LOCATION_SPANNABLE, | |
1228 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, | |
1229 {'importChain': importChains.join( | |
1230 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); | |
1231 } | |
1198 | 1232 |
1199 functionClass.ensureResolved(this); | 1233 functionClass.ensureResolved(this); |
1200 functionApplyMethod = functionClass.lookupLocalMember('apply'); | 1234 functionApplyMethod = functionClass.lookupLocalMember('apply'); |
1201 | 1235 |
1202 proxyConstant = | 1236 proxyConstant = |
1203 resolver.constantCompiler.compileConstant(coreLibrary.find('proxy')); | 1237 resolver.constantCompiler.compileConstant(coreLibrary.find('proxy')); |
1204 | 1238 |
1205 // TODO(johnniwinther): Move this to the JavaScript backend. | 1239 // TODO(johnniwinther): Move this to the JavaScript backend. |
1206 LibraryElement jsHelperLibrary = | 1240 LibraryElement jsHelperLibrary = loadedLibraries.getLibrary( |
1207 loadedLibraries[js_backend.JavaScriptBackend.DART_JS_HELPER]; | 1241 js_backend.JavaScriptBackend.DART_JS_HELPER); |
1208 if (jsHelperLibrary != null) { | 1242 if (jsHelperLibrary != null) { |
1209 patchConstant = resolver.constantCompiler.compileConstant( | 1243 patchConstant = resolver.constantCompiler.compileConstant( |
1210 jsHelperLibrary.find('patch')); | 1244 jsHelperLibrary.find('patch')); |
1211 } | 1245 } |
1212 | 1246 |
1213 if (preserveComments) { | 1247 if (preserveComments) { |
1214 return libraryLoader.loadLibrary(DART_MIRRORS) | 1248 return libraryLoader.loadLibrary(DART_MIRRORS) |
1215 .then((LibraryElement libraryElement) { | 1249 .then((LibraryElement libraryElement) { |
1216 documentClass = libraryElement.find('Comment'); | 1250 documentClass = libraryElement.find('Comment'); |
1217 }); | 1251 }); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1927 /// canonical URI starts with 'package:foo/' is in user code. | 1961 /// canonical URI starts with 'package:foo/' is in user code. |
1928 /// | 1962 /// |
1929 /// If an entrypoint URI uses another scheme than 'package' then every library | 1963 /// If an entrypoint URI uses another scheme than 'package' then every library |
1930 /// with that scheme is in user code. For instance, an entry point URI is | 1964 /// with that scheme is in user code. For instance, an entry point URI is |
1931 /// 'file:///foo.dart' then every library whose canonical URI scheme is | 1965 /// 'file:///foo.dart' then every library whose canonical URI scheme is |
1932 /// 'file' is in user code. | 1966 /// 'file' is in user code. |
1933 /// | 1967 /// |
1934 /// If [assumeInUserCode] is `true`, [element] is assumed to be in user code | 1968 /// If [assumeInUserCode] is `true`, [element] is assumed to be in user code |
1935 /// if no entrypoints have been set. | 1969 /// if no entrypoints have been set. |
1936 bool inUserCode(Element element, {bool assumeInUserCode: false}) { | 1970 bool inUserCode(Element element, {bool assumeInUserCode: false}) { |
1937 List<Uri> entrypoints = <Uri>[]; | 1971 if (element == null) return false; |
1972 Iterable<CodeLocation> userCodeLocations = | |
1973 computeUserCodeLocations(assumeInUserCode: assumeInUserCode); | |
1974 Uri libraryUri = element.library.canonicalUri; | |
1975 return userCodeLocations.any( | |
1976 (CodeLocation codeLocation) => codeLocation.inSameLocation(libraryUri)); | |
1977 } | |
1978 | |
1979 Iterable<CodeLocation> computeUserCodeLocations( | |
1980 {bool assumeInUserCode: false}) { | |
1981 List<CodeLocation> userCodeLocations = <CodeLocation>[]; | |
1938 if (mainApp != null) { | 1982 if (mainApp != null) { |
1939 entrypoints.add(mainApp.canonicalUri); | 1983 userCodeLocations.add(new CodeLocation(mainApp.canonicalUri)); |
1940 } | 1984 } |
1941 if (librariesToAnalyzeWhenRun != null) { | 1985 if (librariesToAnalyzeWhenRun != null) { |
1942 entrypoints.addAll(librariesToAnalyzeWhenRun); | 1986 userCodeLocations.addAll(librariesToAnalyzeWhenRun.map( |
1987 (Uri uri) => new CodeLocation(uri))); | |
1943 } | 1988 } |
1944 if (entrypoints.isEmpty && assumeInUserCode) { | 1989 if (userCodeLocations.isEmpty && assumeInUserCode) { |
1945 // Assume in user code since [mainApp] has not been set yet. | 1990 // Assume in user code since [mainApp] has not been set yet. |
1946 return true; | 1991 userCodeLocations.add(const AnyLocation()); |
1947 } | 1992 } |
1948 if (element == null) return false; | 1993 return userCodeLocations; |
1949 Uri libraryUri = element.library.canonicalUri; | |
1950 if (libraryUri.scheme == 'package') { | |
1951 for (Uri uri in entrypoints) { | |
1952 if (uri.scheme != 'package') continue; | |
1953 int slashPos = libraryUri.path.indexOf('/'); | |
1954 if (slashPos != -1) { | |
1955 String packageName = libraryUri.path.substring(0, slashPos + 1); | |
1956 if (uri.path.startsWith(packageName)) { | |
1957 return true; | |
1958 } | |
1959 } else { | |
1960 if (libraryUri.path == uri.path) { | |
1961 return true; | |
1962 } | |
1963 } | |
1964 } | |
1965 } else { | |
1966 for (Uri uri in entrypoints) { | |
1967 if (libraryUri.scheme == uri.scheme) return true; | |
1968 } | |
1969 } | |
1970 return false; | |
1971 } | 1994 } |
1972 | 1995 |
1973 /// Return a canonical URI for the source of [element]. | 1996 /// Return a canonical URI for the source of [element]. |
1974 /// | 1997 /// |
1975 /// For a package library with canonical URI 'package:foo/bar/baz.dart' the | 1998 /// For a package library with canonical URI 'package:foo/bar/baz.dart' the |
1976 /// return URI is 'package:foo'. For non-package libraries the returned URI is | 1999 /// return URI is 'package:foo'. For non-package libraries the returned URI is |
1977 /// the canonical URI of the library itself. | 2000 /// the canonical URI of the library itself. |
1978 Uri getCanonicalUri(Element element) { | 2001 Uri getCanonicalUri(Element element) { |
1979 if (element == null) return null; | 2002 if (element == null) return null; |
1980 Uri libraryUri = element.library.canonicalUri; | 2003 Uri libraryUri = element.library.canonicalUri; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2129 int warnings = 0; | 2152 int warnings = 0; |
2130 int hints = 0; | 2153 int hints = 0; |
2131 } | 2154 } |
2132 | 2155 |
2133 class GenericTask extends CompilerTask { | 2156 class GenericTask extends CompilerTask { |
2134 final String name; | 2157 final String name; |
2135 | 2158 |
2136 GenericTask(this.name, Compiler compiler) | 2159 GenericTask(this.name, Compiler compiler) |
2137 : super(compiler); | 2160 : super(compiler); |
2138 } | 2161 } |
2162 | |
2163 /// [CodeLocation] divides uris into different classes. | |
2164 /// | |
2165 /// These are used to group uris from user code, platform libraries and | |
2166 /// packages. | |
2167 abstract class CodeLocation { | |
2168 /// Returns `true` if [uri] is in this code location. | |
2169 bool inSameLocation(Uri uri); | |
2170 | |
2171 /// Returns the uri of this location relative to [baseUri]. | |
2172 String relativize(Uri baseUri); | |
2173 | |
2174 factory CodeLocation(Uri uri) { | |
2175 if (uri.scheme == 'package') { | |
2176 int slashPos = uri.path.indexOf('/'); | |
2177 if (slashPos != -1) { | |
2178 String packageName = uri.path.substring(0, slashPos); | |
2179 return new PackageLocation(packageName); | |
2180 } else { | |
2181 return new UriLocation(uri); | |
2182 } | |
2183 } else { | |
2184 return new SchemeLocation(uri); | |
2185 } | |
2186 } | |
2187 } | |
2188 | |
2189 /// A code location defined by the scheme of the uri. | |
2190 /// | |
2191 /// Used for non-package uris, such as 'dart', 'file', and 'http'. | |
2192 class SchemeLocation implements CodeLocation { | |
2193 final Uri uri; | |
2194 | |
2195 SchemeLocation(this.uri); | |
2196 | |
2197 bool inSameLocation(Uri uri) { | |
2198 return this.uri.scheme == uri.scheme; | |
2199 } | |
2200 | |
2201 String relativize(Uri baseUri) { | |
2202 return uri_extras.relativize(baseUri, uri, false); | |
2203 } | |
2204 } | |
2205 | |
2206 /// A code location defined by the package name. | |
2207 /// | |
2208 /// Used for package uris, separated by their `package names`, that is, the | |
2209 /// 'foo' of 'package:foo/bar.dart'. | |
2210 class PackageLocation implements CodeLocation { | |
2211 final String packageName; | |
2212 | |
2213 PackageLocation(this.packageName); | |
2214 | |
2215 bool inSameLocation(Uri uri) { | |
2216 return uri.scheme == 'package' && uri.path.startsWith('$packageName/'); | |
2217 } | |
2218 | |
2219 String relativize(Uri baseUri) => 'package:$packageName'; | |
2220 } | |
2221 | |
2222 /// A code location defined by the whole uri. | |
2223 /// | |
2224 /// Used for package uris with no package name. For instance 'package:foo.dart'. | |
2225 class UriLocation implements CodeLocation { | |
2226 final Uri uri; | |
2227 | |
2228 UriLocation(this.uri); | |
2229 | |
2230 bool inSameLocation(Uri uri) => this.uri == uri; | |
2231 | |
2232 String relativize(Uri baseUri) { | |
2233 return uri_extras.relativize(baseUri, uri, false); | |
2234 } | |
2235 } | |
2236 | |
2237 /// A code location that contains any uri. | |
2238 class AnyLocation implements CodeLocation { | |
2239 const AnyLocation(); | |
2240 | |
2241 bool inSameLocation(Uri uri) => true; | |
2242 | |
2243 String relativize(Uri baseUri) => '$baseUri'; | |
2244 } | |
OLD | NEW |