| 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(LoadedLibraries loadedLibraries) { | 431 Future onLibrariesLoaded(Map<Uri, LibraryElement> 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 final Selector symbolValidatedConstructorSelector = new Selector.call( | 914 final Selector symbolValidatedConstructorSelector = new Selector.call( |
| 915 'validated', null, 1); | 915 'validated', null, 1); |
| 916 final Selector fromEnvironmentSelector = new Selector.callConstructor( | 916 final Selector fromEnvironmentSelector = new Selector.callConstructor( |
| 917 'fromEnvironment', null, 2); | 917 'fromEnvironment', null, 2); |
| 918 | 918 |
| 919 bool enabledNoSuchMethod = false; | 919 bool enabledNoSuchMethod = false; |
| 920 bool enabledRuntimeType = false; | 920 bool enabledRuntimeType = false; |
| 921 bool enabledFunctionApply = false; | 921 bool enabledFunctionApply = false; |
| 922 bool enabledInvokeOn = false; | 922 bool enabledInvokeOn = false; |
| 923 bool hasIsolateSupport = false; | 923 bool hasIsolateSupport = false; |
| 924 final bool enableExperimentalMirrors; | |
| 925 | 924 |
| 926 Stopwatch progress; | 925 Stopwatch progress; |
| 927 | 926 |
| 928 bool get shouldPrintProgress { | 927 bool get shouldPrintProgress { |
| 929 return verbose && progress.elapsedMilliseconds > 500; | 928 return verbose && progress.elapsedMilliseconds > 500; |
| 930 } | 929 } |
| 931 | 930 |
| 932 static const int PHASE_SCANNING = 0; | 931 static const int PHASE_SCANNING = 0; |
| 933 static const int PHASE_RESOLVING = 1; | 932 static const int PHASE_RESOLVING = 1; |
| 934 static const int PHASE_DONE_RESOLVING = 2; | 933 static const int PHASE_DONE_RESOLVING = 2; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 963 this.verbose: false, | 962 this.verbose: false, |
| 964 this.sourceMapUri: null, | 963 this.sourceMapUri: null, |
| 965 this.outputUri: null, | 964 this.outputUri: null, |
| 966 this.buildId: UNDETERMINED_BUILD_ID, | 965 this.buildId: UNDETERMINED_BUILD_ID, |
| 967 this.terseDiagnostics: false, | 966 this.terseDiagnostics: false, |
| 968 this.dumpInfo: false, | 967 this.dumpInfo: false, |
| 969 this.showPackageWarnings: false, | 968 this.showPackageWarnings: false, |
| 970 this.useContentSecurityPolicy: false, | 969 this.useContentSecurityPolicy: false, |
| 971 this.suppressWarnings: false, | 970 this.suppressWarnings: false, |
| 972 bool hasIncrementalSupport: false, | 971 bool hasIncrementalSupport: false, |
| 973 this.enableExperimentalMirrors: false, | |
| 974 this.enableAsyncAwait: false, | 972 this.enableAsyncAwait: false, |
| 975 this.enableEnums: false, | 973 this.enableEnums: false, |
| 976 api.CompilerOutputProvider outputProvider, | 974 api.CompilerOutputProvider outputProvider, |
| 977 List<String> strips: const []}) | 975 List<String> strips: const []}) |
| 978 : this.disableTypeInferenceFlag = | 976 : this.disableTypeInferenceFlag = |
| 979 disableTypeInferenceFlag || !emitJavaScript, | 977 disableTypeInferenceFlag || !emitJavaScript, |
| 980 this.analyzeOnly = | 978 this.analyzeOnly = |
| 981 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, | 979 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, |
| 982 this.analyzeSignaturesOnly = analyzeSignaturesOnly, | 980 this.analyzeSignaturesOnly = analyzeSignaturesOnly, |
| 983 this.analyzeAllFlag = analyzeAllFlag, | 981 this.analyzeAllFlag = analyzeAllFlag, |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 } | 1216 } |
| 1219 | 1217 |
| 1220 /// This method is called when all new libraries loaded through | 1218 /// This method is called when all new libraries loaded through |
| 1221 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 1219 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
| 1222 /// have been computed. | 1220 /// have been computed. |
| 1223 /// | 1221 /// |
| 1224 /// [loadedLibraries] contains the newly loaded libraries. | 1222 /// [loadedLibraries] contains the newly loaded libraries. |
| 1225 /// | 1223 /// |
| 1226 /// The method returns a [Future] allowing for the loading of additional | 1224 /// The method returns a [Future] allowing for the loading of additional |
| 1227 /// libraries. | 1225 /// libraries. |
| 1228 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 1226 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { |
| 1229 return new Future.sync(() { | 1227 return new Future.sync(() { |
| 1230 if (!loadedLibraries.containsLibrary(DART_CORE)) { | 1228 if (!loadedLibraries.containsKey(DART_CORE)) return new Future.value(); |
| 1231 return null; | |
| 1232 } | |
| 1233 if (!enableExperimentalMirrors && | |
| 1234 loadedLibraries.containsLibrary(DART_MIRRORS)) { | |
| 1235 // TODO(johnniwinther): Move computation of dependencies to the library | |
| 1236 // loader. | |
| 1237 Uri rootUri = loadedLibraries.rootUri; | |
| 1238 Set<String> importChains = new Set<String>(); | |
| 1239 loadedLibraries.forEachImportChain( | |
| 1240 (LibraryElement library, Link<Uri> importChainReversed) { | |
| 1241 if (library.canonicalUri != DART_MIRRORS) return; | |
| 1242 Link<CodeLocation> compactImportChain = const Link<CodeLocation>(); | |
| 1243 CodeLocation currentCodeLocation = new UriLocation(DART_MIRRORS); | |
| 1244 compactImportChain = compactImportChain.prepend(currentCodeLocation); | |
| 1245 for (Link<Uri> link = importChainReversed; | |
| 1246 !link.isEmpty; | |
| 1247 link = link.tail) { | |
| 1248 Uri uri = link.head; | |
| 1249 if (!currentCodeLocation.inSameLocation(uri)) { | |
| 1250 currentCodeLocation = | |
| 1251 verbose ? new UriLocation(uri) : new CodeLocation(uri); | |
| 1252 compactImportChain = | |
| 1253 compactImportChain.prepend(currentCodeLocation); | |
| 1254 } | |
| 1255 } | |
| 1256 importChains.add(compactImportChain.map((CodeLocation codeLocation) { | |
| 1257 return codeLocation.relativize(rootUri); | |
| 1258 }).join(' => ')); | |
| 1259 }); | |
| 1260 reportWarning(NO_LOCATION_SPANNABLE, | |
| 1261 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, | |
| 1262 {'importChain': importChains.join( | |
| 1263 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); | |
| 1264 } | |
| 1265 | 1229 |
| 1266 functionClass.ensureResolved(this); | 1230 functionClass.ensureResolved(this); |
| 1267 functionApplyMethod = functionClass.lookupLocalMember('apply'); | 1231 functionApplyMethod = functionClass.lookupLocalMember('apply'); |
| 1268 | 1232 |
| 1269 proxyConstant = | 1233 proxyConstant = |
| 1270 resolver.constantCompiler.compileConstant( | 1234 resolver.constantCompiler.compileConstant( |
| 1271 coreLibrary.find('proxy')).value; | 1235 coreLibrary.find('proxy')).value; |
| 1272 | 1236 |
| 1273 // TODO(johnniwinther): Move this to the JavaScript backend. | 1237 // TODO(johnniwinther): Move this to the JavaScript backend. |
| 1274 LibraryElement jsHelperLibrary = loadedLibraries.getLibrary( | 1238 LibraryElement jsHelperLibrary = |
| 1275 js_backend.JavaScriptBackend.DART_JS_HELPER); | 1239 loadedLibraries[js_backend.JavaScriptBackend.DART_JS_HELPER]; |
| 1276 if (jsHelperLibrary != null) { | 1240 if (jsHelperLibrary != null) { |
| 1277 patchConstant = resolver.constantCompiler.compileConstant( | 1241 patchConstant = resolver.constantCompiler.compileConstant( |
| 1278 jsHelperLibrary.find('patch')).value; | 1242 jsHelperLibrary.find('patch')).value; |
| 1279 } | 1243 } |
| 1280 | 1244 |
| 1281 if (preserveComments) { | 1245 if (preserveComments) { |
| 1282 return libraryLoader.loadLibrary(DART_MIRRORS) | 1246 return libraryLoader.loadLibrary(DART_MIRRORS) |
| 1283 .then((LibraryElement libraryElement) { | 1247 .then((LibraryElement libraryElement) { |
| 1284 documentClass = libraryElement.find('Comment'); | 1248 documentClass = libraryElement.find('Comment'); |
| 1285 }); | 1249 }); |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 /// canonical URI starts with 'package:foo/' is in user code. | 1956 /// canonical URI starts with 'package:foo/' is in user code. |
| 1993 /// | 1957 /// |
| 1994 /// If an entrypoint URI uses another scheme than 'package' then every library | 1958 /// If an entrypoint URI uses another scheme than 'package' then every library |
| 1995 /// with that scheme is in user code. For instance, an entry point URI is | 1959 /// with that scheme is in user code. For instance, an entry point URI is |
| 1996 /// 'file:///foo.dart' then every library whose canonical URI scheme is | 1960 /// 'file:///foo.dart' then every library whose canonical URI scheme is |
| 1997 /// 'file' is in user code. | 1961 /// 'file' is in user code. |
| 1998 /// | 1962 /// |
| 1999 /// If [assumeInUserCode] is `true`, [element] is assumed to be in user code | 1963 /// If [assumeInUserCode] is `true`, [element] is assumed to be in user code |
| 2000 /// if no entrypoints have been set. | 1964 /// if no entrypoints have been set. |
| 2001 bool inUserCode(Element element, {bool assumeInUserCode: false}) { | 1965 bool inUserCode(Element element, {bool assumeInUserCode: false}) { |
| 2002 if (element == null) return false; | 1966 List<Uri> entrypoints = <Uri>[]; |
| 2003 Iterable<CodeLocation> userCodeLocations = | |
| 2004 computeUserCodeLocations(assumeInUserCode: assumeInUserCode); | |
| 2005 Uri libraryUri = element.library.canonicalUri; | |
| 2006 return userCodeLocations.any( | |
| 2007 (CodeLocation codeLocation) => codeLocation.inSameLocation(libraryUri)); | |
| 2008 } | |
| 2009 | |
| 2010 Iterable<CodeLocation> computeUserCodeLocations( | |
| 2011 {bool assumeInUserCode: false}) { | |
| 2012 List<CodeLocation> userCodeLocations = <CodeLocation>[]; | |
| 2013 if (mainApp != null) { | 1967 if (mainApp != null) { |
| 2014 userCodeLocations.add(new CodeLocation(mainApp.canonicalUri)); | 1968 entrypoints.add(mainApp.canonicalUri); |
| 2015 } | 1969 } |
| 2016 if (librariesToAnalyzeWhenRun != null) { | 1970 if (librariesToAnalyzeWhenRun != null) { |
| 2017 userCodeLocations.addAll(librariesToAnalyzeWhenRun.map( | 1971 entrypoints.addAll(librariesToAnalyzeWhenRun); |
| 2018 (Uri uri) => new CodeLocation(uri))); | |
| 2019 } | 1972 } |
| 2020 if (userCodeLocations.isEmpty && assumeInUserCode) { | 1973 if (entrypoints.isEmpty && assumeInUserCode) { |
| 2021 // Assume in user code since [mainApp] has not been set yet. | 1974 // Assume in user code since [mainApp] has not been set yet. |
| 2022 userCodeLocations.add(const AnyLocation()); | 1975 return true; |
| 2023 } | 1976 } |
| 2024 return userCodeLocations; | 1977 if (element == null) return false; |
| 1978 Uri libraryUri = element.library.canonicalUri; |
| 1979 if (libraryUri.scheme == 'package') { |
| 1980 for (Uri uri in entrypoints) { |
| 1981 if (uri.scheme != 'package') continue; |
| 1982 int slashPos = libraryUri.path.indexOf('/'); |
| 1983 if (slashPos != -1) { |
| 1984 String packageName = libraryUri.path.substring(0, slashPos + 1); |
| 1985 if (uri.path.startsWith(packageName)) { |
| 1986 return true; |
| 1987 } |
| 1988 } else { |
| 1989 if (libraryUri.path == uri.path) { |
| 1990 return true; |
| 1991 } |
| 1992 } |
| 1993 } |
| 1994 } else { |
| 1995 for (Uri uri in entrypoints) { |
| 1996 if (libraryUri.scheme == uri.scheme) return true; |
| 1997 } |
| 1998 } |
| 1999 return false; |
| 2025 } | 2000 } |
| 2026 | 2001 |
| 2027 /// Return a canonical URI for the source of [element]. | 2002 /// Return a canonical URI for the source of [element]. |
| 2028 /// | 2003 /// |
| 2029 /// For a package library with canonical URI 'package:foo/bar/baz.dart' the | 2004 /// For a package library with canonical URI 'package:foo/bar/baz.dart' the |
| 2030 /// return URI is 'package:foo'. For non-package libraries the returned URI is | 2005 /// return URI is 'package:foo'. For non-package libraries the returned URI is |
| 2031 /// the canonical URI of the library itself. | 2006 /// the canonical URI of the library itself. |
| 2032 Uri getCanonicalUri(Element element) { | 2007 Uri getCanonicalUri(Element element) { |
| 2033 if (element == null) return null; | 2008 if (element == null) return null; |
| 2034 Uri libraryUri = element.library.canonicalUri; | 2009 Uri libraryUri = element.library.canonicalUri; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2206 int warnings = 0; | 2181 int warnings = 0; |
| 2207 int hints = 0; | 2182 int hints = 0; |
| 2208 } | 2183 } |
| 2209 | 2184 |
| 2210 class GenericTask extends CompilerTask { | 2185 class GenericTask extends CompilerTask { |
| 2211 final String name; | 2186 final String name; |
| 2212 | 2187 |
| 2213 GenericTask(this.name, Compiler compiler) | 2188 GenericTask(this.name, Compiler compiler) |
| 2214 : super(compiler); | 2189 : super(compiler); |
| 2215 } | 2190 } |
| 2216 | |
| 2217 /// [CodeLocation] divides uris into different classes. | |
| 2218 /// | |
| 2219 /// These are used to group uris from user code, platform libraries and | |
| 2220 /// packages. | |
| 2221 abstract class CodeLocation { | |
| 2222 /// Returns `true` if [uri] is in this code location. | |
| 2223 bool inSameLocation(Uri uri); | |
| 2224 | |
| 2225 /// Returns the uri of this location relative to [baseUri]. | |
| 2226 String relativize(Uri baseUri); | |
| 2227 | |
| 2228 factory CodeLocation(Uri uri) { | |
| 2229 if (uri.scheme == 'package') { | |
| 2230 int slashPos = uri.path.indexOf('/'); | |
| 2231 if (slashPos != -1) { | |
| 2232 String packageName = uri.path.substring(0, slashPos); | |
| 2233 return new PackageLocation(packageName); | |
| 2234 } else { | |
| 2235 return new UriLocation(uri); | |
| 2236 } | |
| 2237 } else { | |
| 2238 return new SchemeLocation(uri); | |
| 2239 } | |
| 2240 } | |
| 2241 } | |
| 2242 | |
| 2243 /// A code location defined by the scheme of the uri. | |
| 2244 /// | |
| 2245 /// Used for non-package uris, such as 'dart', 'file', and 'http'. | |
| 2246 class SchemeLocation implements CodeLocation { | |
| 2247 final Uri uri; | |
| 2248 | |
| 2249 SchemeLocation(this.uri); | |
| 2250 | |
| 2251 bool inSameLocation(Uri uri) { | |
| 2252 return this.uri.scheme == uri.scheme; | |
| 2253 } | |
| 2254 | |
| 2255 String relativize(Uri baseUri) { | |
| 2256 return uri_extras.relativize(baseUri, uri, false); | |
| 2257 } | |
| 2258 } | |
| 2259 | |
| 2260 /// A code location defined by the package name. | |
| 2261 /// | |
| 2262 /// Used for package uris, separated by their `package names`, that is, the | |
| 2263 /// 'foo' of 'package:foo/bar.dart'. | |
| 2264 class PackageLocation implements CodeLocation { | |
| 2265 final String packageName; | |
| 2266 | |
| 2267 PackageLocation(this.packageName); | |
| 2268 | |
| 2269 bool inSameLocation(Uri uri) { | |
| 2270 return uri.scheme == 'package' && uri.path.startsWith('$packageName/'); | |
| 2271 } | |
| 2272 | |
| 2273 String relativize(Uri baseUri) => 'package:$packageName'; | |
| 2274 } | |
| 2275 | |
| 2276 /// A code location defined by the whole uri. | |
| 2277 /// | |
| 2278 /// Used for package uris with no package name. For instance 'package:foo.dart'. | |
| 2279 class UriLocation implements CodeLocation { | |
| 2280 final Uri uri; | |
| 2281 | |
| 2282 UriLocation(this.uri); | |
| 2283 | |
| 2284 bool inSameLocation(Uri uri) => this.uri == uri; | |
| 2285 | |
| 2286 String relativize(Uri baseUri) { | |
| 2287 return uri_extras.relativize(baseUri, uri, false); | |
| 2288 } | |
| 2289 } | |
| 2290 | |
| 2291 /// A code location that contains any uri. | |
| 2292 class AnyLocation implements CodeLocation { | |
| 2293 const AnyLocation(); | |
| 2294 | |
| 2295 bool inSameLocation(Uri uri) => true; | |
| 2296 | |
| 2297 String relativize(Uri baseUri) => '$baseUri'; | |
| 2298 } | |
| OLD | NEW |