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