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 dart2js.source_mirrors.analyze; | 5 library dart2js.source_mirrors.analyze; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'source_mirrors.dart'; | 9 import 'source_mirrors.dart'; |
10 import 'dart2js_mirrors.dart' show Dart2JsMirrorSystem; | 10 import 'dart2js_mirrors.dart' show Dart2JsMirrorSystem; |
11 import '../../compiler.dart' as api; | 11 import '../../compiler.dart' as api; |
12 import '../options.dart' show CompilerOptions; | 12 import '../options.dart' show CompilerOptions; |
13 import '../apiimpl.dart' as apiimpl; | 13 import '../apiimpl.dart' as apiimpl; |
14 import '../compiler.dart' show Compiler; | 14 import '../compiler.dart' show Compiler; |
15 import '../old_to_new_api.dart'; | 15 import '../old_to_new_api.dart'; |
16 | 16 |
17 //------------------------------------------------------------------------------ | 17 //------------------------------------------------------------------------------ |
18 // Analysis entry point. | 18 // Analysis entry point. |
19 //------------------------------------------------------------------------------ | 19 //------------------------------------------------------------------------------ |
20 | 20 |
21 /** | 21 /** |
22 * Analyzes set of libraries and provides a mirror system which can be used for | 22 * Analyzes set of libraries and provides a mirror system which can be used for |
23 * static inspection of the source code. | 23 * static inspection of the source code. |
24 */ | 24 */ |
25 // TODO(johnniwinther): Move this to [compiler/compiler.dart]. | 25 // TODO(johnniwinther): Move this to [compiler/compiler.dart]. |
26 Future<MirrorSystem> analyze(List<Uri> libraries, | 26 Future<MirrorSystem> analyze( |
27 Uri libraryRoot, | 27 List<Uri> libraries, |
28 Uri packageRoot, | 28 Uri libraryRoot, |
29 api.CompilerInputProvider inputProvider, | 29 Uri packageRoot, |
30 api.DiagnosticHandler diagnosticHandler, | 30 api.CompilerInputProvider inputProvider, |
31 [List<String> options = const <String>[], | 31 api.DiagnosticHandler diagnosticHandler, |
32 Uri packageConfig, | 32 [List<String> options = const <String>[], |
33 api.PackagesDiscoveryProvider findPackages]) { | 33 Uri packageConfig, |
| 34 api.PackagesDiscoveryProvider findPackages]) { |
34 if (!libraryRoot.path.endsWith("/")) { | 35 if (!libraryRoot.path.endsWith("/")) { |
35 throw new ArgumentError("libraryRoot must end with a /"); | 36 throw new ArgumentError("libraryRoot must end with a /"); |
36 } | 37 } |
37 if (packageRoot != null && !packageRoot.path.endsWith("/")) { | 38 if (packageRoot != null && !packageRoot.path.endsWith("/")) { |
38 throw new ArgumentError("packageRoot must end with a /"); | 39 throw new ArgumentError("packageRoot must end with a /"); |
39 } | 40 } |
40 options = new List<String>.from(options); | 41 options = new List<String>.from(options); |
41 options.add('--analyze-only'); | 42 options.add('--analyze-only'); |
42 options.add('--analyze-signatures-only'); | 43 options.add('--analyze-signatures-only'); |
43 options.add('--analyze-all'); | 44 options.add('--analyze-all'); |
44 options.add('--categories=Client,Server'); | 45 options.add('--categories=Client,Server'); |
45 options.add('--enable-async'); | 46 options.add('--enable-async'); |
46 options.add('--allow-native-extensions'); | 47 options.add('--allow-native-extensions'); |
47 | 48 |
48 bool compilationFailed = false; | 49 bool compilationFailed = false; |
49 void internalDiagnosticHandler(Uri uri, int begin, int end, | 50 void internalDiagnosticHandler( |
50 String message, api.Diagnostic kind) { | 51 Uri uri, int begin, int end, String message, api.Diagnostic kind) { |
51 if (kind == api.Diagnostic.ERROR || | 52 if (kind == api.Diagnostic.ERROR || kind == api.Diagnostic.CRASH) { |
52 kind == api.Diagnostic.CRASH) { | |
53 compilationFailed = true; | 53 compilationFailed = true; |
54 } | 54 } |
55 diagnosticHandler(uri, begin, end, message, kind); | 55 diagnosticHandler(uri, begin, end, message, kind); |
56 } | 56 } |
57 | 57 |
58 Compiler compiler = new apiimpl.CompilerImpl( | 58 Compiler compiler = new apiimpl.CompilerImpl( |
59 new LegacyCompilerInput(inputProvider), | 59 new LegacyCompilerInput(inputProvider), |
60 new LegacyCompilerOutput(), | 60 new LegacyCompilerOutput(), |
61 new LegacyCompilerDiagnostics(internalDiagnosticHandler), | 61 new LegacyCompilerDiagnostics(internalDiagnosticHandler), |
62 new CompilerOptions.parse( | 62 new CompilerOptions.parse( |
63 libraryRoot: libraryRoot, | 63 libraryRoot: libraryRoot, |
64 packageRoot: packageRoot, | 64 packageRoot: packageRoot, |
65 options: options, | 65 options: options, |
66 environment: const {}, | 66 environment: const {}, |
67 packageConfig: packageConfig, | 67 packageConfig: packageConfig, |
68 packagesDiscoveryProvider: findPackages)); | 68 packagesDiscoveryProvider: findPackages)); |
69 compiler.librariesToAnalyzeWhenRun = libraries; | 69 compiler.librariesToAnalyzeWhenRun = libraries; |
70 return compiler.run(null).then((bool success) { | 70 return compiler.run(null).then((bool success) { |
71 if (success && !compilationFailed) { | 71 if (success && !compilationFailed) { |
72 return new Dart2JsMirrorSystem(compiler); | 72 return new Dart2JsMirrorSystem(compiler); |
73 } else { | 73 } else { |
74 throw new StateError('Failed to create mirror system.'); | 74 throw new StateError('Failed to create mirror system.'); |
75 } | 75 } |
76 }); | 76 }); |
77 } | 77 } |
OLD | NEW |