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 library leg_apiimpl; | 5 library leg_apiimpl; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:package_config/packages.dart'; | 10 import 'package:package_config/packages.dart'; |
11 import 'package:package_config/packages_file.dart' as pkgs; | 11 import 'package:package_config/packages_file.dart' as pkgs; |
12 import 'package:package_config/src/packages_impl.dart' | 12 import 'package:package_config/src/packages_impl.dart' show |
13 show NonFilePackagesDirectoryPackages, MapPackages; | 13 MapPackages, |
14 import 'package:package_config/src/util.dart' show checkValidPackageUri; | 14 NonFilePackagesDirectoryPackages; |
| 15 import 'package:package_config/src/util.dart' show |
| 16 checkValidPackageUri; |
15 import 'package:sdk_library_metadata/libraries.dart' hide LIBRARIES; | 17 import 'package:sdk_library_metadata/libraries.dart' hide LIBRARIES; |
16 import 'package:sdk_library_metadata/libraries.dart' as library_info show LIBRAR
IES; | 18 import 'package:sdk_library_metadata/libraries.dart' as library_info show |
| 19 LIBRARIES; |
17 | 20 |
18 import '../compiler_new.dart' as api; | 21 import '../compiler_new.dart' as api; |
19 import 'dart2jslib.dart' as leg; | 22 import 'common/tasks.dart' show |
| 23 GenericTask; |
| 24 import 'compiler.dart' as leg; |
| 25 import 'diagnostics/source_span.dart' show |
| 26 SourceSpan; |
| 27 import 'diagnostics/spannable.dart' show |
| 28 NO_LOCATION_SPANNABLE, |
| 29 Spannable; |
20 import 'elements/elements.dart' as elements; | 30 import 'elements/elements.dart' as elements; |
21 import 'io/source_file.dart'; | 31 import 'io/source_file.dart'; |
22 import 'messages.dart'; | 32 import 'messages.dart'; |
23 import 'script.dart'; | 33 import 'script.dart'; |
24 import 'tree/tree.dart' as tree; | 34 import 'tree/tree.dart' as tree; |
25 import 'util/util.dart' show | |
26 NO_LOCATION_SPANNABLE, | |
27 Spannable; | |
28 | 35 |
29 const bool forceIncrementalSupport = | 36 const bool forceIncrementalSupport = |
30 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); | 37 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); |
31 | 38 |
32 class Compiler extends leg.Compiler { | 39 class Compiler extends leg.Compiler { |
33 api.CompilerInput provider; | 40 api.CompilerInput provider; |
34 api.CompilerDiagnostics handler; | 41 api.CompilerDiagnostics handler; |
35 final Uri libraryRoot; | 42 final Uri libraryRoot; |
36 final Uri packageConfig; | 43 final Uri packageConfig; |
37 final Uri packageRoot; | 44 final Uri packageRoot; |
38 final api.PackagesDiscoveryProvider packagesDiscoveryProvider; | 45 final api.PackagesDiscoveryProvider packagesDiscoveryProvider; |
39 Packages packages; | 46 Packages packages; |
40 List<String> options; | 47 List<String> options; |
41 Map<String, dynamic> environment; | 48 Map<String, dynamic> environment; |
42 bool mockableLibraryUsed = false; | 49 bool mockableLibraryUsed = false; |
43 final Set<String> allowedLibraryCategories; | 50 final Set<String> allowedLibraryCategories; |
44 | 51 |
45 leg.GenericTask userHandlerTask; | 52 GenericTask userHandlerTask; |
46 leg.GenericTask userProviderTask; | 53 GenericTask userProviderTask; |
47 leg.GenericTask userPackagesDiscoveryTask; | 54 GenericTask userPackagesDiscoveryTask; |
48 | 55 |
49 Compiler(this.provider, | 56 Compiler(this.provider, |
50 api.CompilerOutput outputProvider, | 57 api.CompilerOutput outputProvider, |
51 this.handler, | 58 this.handler, |
52 this.libraryRoot, | 59 this.libraryRoot, |
53 this.packageRoot, | 60 this.packageRoot, |
54 List<String> options, | 61 List<String> options, |
55 this.environment, | 62 this.environment, |
56 [this.packageConfig, | 63 [this.packageConfig, |
57 this.packagesDiscoveryProvider]) | 64 this.packagesDiscoveryProvider]) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 suppressWarnings: hasOption(options, '--suppress-warnings'), | 113 suppressWarnings: hasOption(options, '--suppress-warnings'), |
107 fatalWarnings: hasOption(options, '--fatal-warnings'), | 114 fatalWarnings: hasOption(options, '--fatal-warnings'), |
108 enableExperimentalMirrors: | 115 enableExperimentalMirrors: |
109 hasOption(options, '--enable-experimental-mirrors'), | 116 hasOption(options, '--enable-experimental-mirrors'), |
110 generateCodeWithCompileTimeErrors: | 117 generateCodeWithCompileTimeErrors: |
111 hasOption(options, '--generate-code-with-compile-time-errors'), | 118 hasOption(options, '--generate-code-with-compile-time-errors'), |
112 testMode: hasOption(options, '--test-mode'), | 119 testMode: hasOption(options, '--test-mode'), |
113 allowNativeExtensions: | 120 allowNativeExtensions: |
114 hasOption(options, '--allow-native-extensions')) { | 121 hasOption(options, '--allow-native-extensions')) { |
115 tasks.addAll([ | 122 tasks.addAll([ |
116 userHandlerTask = new leg.GenericTask('Diagnostic handler', this), | 123 userHandlerTask = new GenericTask('Diagnostic handler', this), |
117 userProviderTask = new leg.GenericTask('Input provider', this), | 124 userProviderTask = new GenericTask('Input provider', this), |
118 userPackagesDiscoveryTask = | 125 userPackagesDiscoveryTask = |
119 new leg.GenericTask('Package discovery', this), | 126 new GenericTask('Package discovery', this), |
120 ]); | 127 ]); |
121 if (libraryRoot == null) { | 128 if (libraryRoot == null) { |
122 throw new ArgumentError("[libraryRoot] is null."); | 129 throw new ArgumentError("[libraryRoot] is null."); |
123 } | 130 } |
124 if (!libraryRoot.path.endsWith("/")) { | 131 if (!libraryRoot.path.endsWith("/")) { |
125 throw new ArgumentError("[libraryRoot] must end with a /."); | 132 throw new ArgumentError("[libraryRoot] must end with a /."); |
126 } | 133 } |
127 if (packageRoot != null && packageConfig != null) { | 134 if (packageRoot != null && packageConfig != null) { |
128 throw new ArgumentError("Only one of [packageRoot] or [packageConfig] " | 135 throw new ArgumentError("Only one of [packageRoot] or [packageConfig] " |
129 "may be given."); | 136 "may be given."); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 'Relative uri $readableUri provided to readScript(Uri).'); | 233 'Relative uri $readableUri provided to readScript(Uri).'); |
227 } | 234 } |
228 | 235 |
229 // We need to store the current element since we are reporting read errors | 236 // We need to store the current element since we are reporting read errors |
230 // asynchronously and therefore need to restore the current element for | 237 // asynchronously and therefore need to restore the current element for |
231 // [node] to be valid. | 238 // [node] to be valid. |
232 elements.Element element = currentElement; | 239 elements.Element element = currentElement; |
233 void reportReadError(exception) { | 240 void reportReadError(exception) { |
234 if (element == null || node == null) { | 241 if (element == null || node == null) { |
235 reportError( | 242 reportError( |
236 new leg.SourceSpan(readableUri, 0, 0), | 243 new SourceSpan(readableUri, 0, 0), |
237 MessageKind.READ_SELF_ERROR, | 244 MessageKind.READ_SELF_ERROR, |
238 {'uri': readableUri, 'exception': exception}); | 245 {'uri': readableUri, 'exception': exception}); |
239 } else { | 246 } else { |
240 withCurrentElement(element, () { | 247 withCurrentElement(element, () { |
241 reportError( | 248 reportError( |
242 node, | 249 node, |
243 MessageKind.READ_SCRIPT_ERROR, | 250 MessageKind.READ_SCRIPT_ERROR, |
244 {'uri': readableUri, 'exception': exception}); | 251 {'uri': readableUri, 'exception': exception}); |
245 }); | 252 }); |
246 } | 253 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 log('Total compile-time ${total}msec;' | 426 log('Total compile-time ${total}msec;' |
420 ' unaccounted ${total - cumulated}msec'); | 427 ' unaccounted ${total - cumulated}msec'); |
421 return success; | 428 return success; |
422 }); | 429 }); |
423 }); | 430 }); |
424 } | 431 } |
425 | 432 |
426 void reportDiagnostic(Spannable node, | 433 void reportDiagnostic(Spannable node, |
427 Message message, | 434 Message message, |
428 api.Diagnostic kind) { | 435 api.Diagnostic kind) { |
429 leg.SourceSpan span = spanFromSpannable(node); | 436 SourceSpan span = spanFromSpannable(node); |
430 if (identical(kind, api.Diagnostic.ERROR) | 437 if (identical(kind, api.Diagnostic.ERROR) |
431 || identical(kind, api.Diagnostic.CRASH) | 438 || identical(kind, api.Diagnostic.CRASH) |
432 || (fatalWarnings && identical(kind, api.Diagnostic.WARNING))) { | 439 || (fatalWarnings && identical(kind, api.Diagnostic.WARNING))) { |
433 compilationFailed = true; | 440 compilationFailed = true; |
434 } | 441 } |
435 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For | 442 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For |
436 // instance in the [Types] constructor in typechecker.dart. | 443 // instance in the [Types] constructor in typechecker.dart. |
437 if (span == null || span.uri == null) { | 444 if (span == null || span.uri == null) { |
438 callUserHandler(message, null, null, null, '$message', kind); | 445 callUserHandler(message, null, null, null, '$message', kind); |
439 } else { | 446 } else { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 print('$message: ${tryToString(exception)}'); | 491 print('$message: ${tryToString(exception)}'); |
485 print(tryToString(stackTrace)); | 492 print(tryToString(stackTrace)); |
486 } | 493 } |
487 | 494 |
488 fromEnvironment(String name) => environment[name]; | 495 fromEnvironment(String name) => environment[name]; |
489 | 496 |
490 LibraryInfo lookupLibraryInfo(String libraryName) { | 497 LibraryInfo lookupLibraryInfo(String libraryName) { |
491 return library_info.LIBRARIES[libraryName]; | 498 return library_info.LIBRARIES[libraryName]; |
492 } | 499 } |
493 } | 500 } |
OLD | NEW |