| 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 options.add('--enable-async'); | |
| 42 | |
| 43 bool compilationFailed = false; | |
| 44 void internalDiagnosticHandler(Uri uri, int begin, int end, | |
| 45 String message, api.Diagnostic kind) { | |
| 46 if (kind == api.Diagnostic.ERROR || | |
| 47 kind == api.Diagnostic.CRASH) { | |
| 48 compilationFailed = true; | |
| 49 } | |
| 50 diagnosticHandler(uri, begin, end, message, kind); | |
| 51 } | |
| 52 | |
| 53 Compiler compiler = new apiimpl.Compiler(inputProvider, | |
| 54 null, | |
| 55 internalDiagnosticHandler, | |
| 56 libraryRoot, packageRoot, | |
| 57 options, | |
| 58 const {}); | |
| 59 compiler.librariesToAnalyzeWhenRun = libraries; | |
| 60 return compiler.run(null).then((bool success) { | |
| 61 if (success && !compilationFailed) { | |
| 62 return new Dart2JsMirrorSystem(compiler); | |
| 63 } else { | |
| 64 throw new StateError('Failed to create mirror system.'); | |
| 65 } | |
| 66 }); | |
| 67 } | |
| OLD | NEW |