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