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 mirrors_dart2js; | 5 library mirrors_dart2js; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection' show LinkedHashMap; | 8 import 'dart:collection' show LinkedHashMap; |
9 import 'dart:io' show Path; | |
10 import 'dart:uri'; | 9 import 'dart:uri'; |
11 | 10 |
12 import '../../compiler.dart' as api; | 11 import '../../compiler.dart' as api; |
13 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
14 import '../resolution/resolution.dart' show ResolverTask, ResolverVisitor; | |
15 import '../apiimpl.dart' as apiimpl; | 13 import '../apiimpl.dart' as apiimpl; |
16 import '../scanner/scannerlib.dart' hide SourceString; | 14 import '../scanner/scannerlib.dart' hide SourceString; |
17 import '../ssa/ssa.dart'; | |
18 import '../dart2jslib.dart'; | 15 import '../dart2jslib.dart'; |
19 import '../dart_types.dart'; | 16 import '../dart_types.dart'; |
20 import '../filenames.dart'; | |
21 import '../source_file.dart'; | 17 import '../source_file.dart'; |
22 import '../tree/tree.dart'; | 18 import '../tree/tree.dart'; |
23 import '../util/util.dart'; | 19 import '../util/util.dart' show Spannable, Link; |
24 import '../util/uri_extras.dart'; | 20 import '../util/characters.dart' show $CR, $LF; |
25 import '../dart2js.dart'; | |
26 import '../util/characters.dart'; | |
27 import '../source_file_provider.dart'; | |
28 | 21 |
29 import 'mirrors.dart'; | 22 import 'mirrors.dart'; |
30 import 'mirrors_util.dart'; | 23 import 'mirrors_util.dart'; |
31 import 'util.dart'; | 24 import 'util.dart'; |
32 | 25 |
33 //------------------------------------------------------------------------------ | 26 //------------------------------------------------------------------------------ |
34 // Utility types and functions for the dart2js mirror system | 27 // Utility types and functions for the dart2js mirror system |
35 //------------------------------------------------------------------------------ | 28 //------------------------------------------------------------------------------ |
36 | 29 |
37 bool _isPrivate(String name) { | 30 bool _isPrivate(String name) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 'or': '|', | 178 'or': '|', |
186 }; | 179 }; |
187 String newName = mapping[name]; | 180 String newName = mapping[name]; |
188 if (newName == null) { | 181 if (newName == null) { |
189 throw new Exception('Unhandled operator name: $name'); | 182 throw new Exception('Unhandled operator name: $name'); |
190 } | 183 } |
191 return newName; | 184 return newName; |
192 } | 185 } |
193 | 186 |
194 //------------------------------------------------------------------------------ | 187 //------------------------------------------------------------------------------ |
195 // Compilation implementation | 188 // Analysis entry point. |
196 //------------------------------------------------------------------------------ | 189 //------------------------------------------------------------------------------ |
197 | 190 |
198 // TODO(johnniwinther): Support client configurable providers. | |
199 | |
200 /** | |
201 * Returns a future that completes to a non-null String when [script] | |
202 * has been successfully compiled. | |
203 * | |
204 * TODO(johnniwinther): The method is deprecated but here to support [Path] | |
205 * which is used through dartdoc. | |
206 */ | |
207 Future<String> compile(Path script, | |
208 Path libraryRoot, | |
209 {Path packageRoot, | |
210 List<String> options: const <String>[], | |
211 api.DiagnosticHandler diagnosticHandler}) { | |
212 SourceFileProvider provider = new SourceFileProvider(); | |
213 if (diagnosticHandler == null) { | |
214 diagnosticHandler = | |
215 new FormattingDiagnosticHandler(provider).diagnosticHandler; | |
216 } | |
217 Uri scriptUri = currentDirectory.resolve(script.toString()); | |
218 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); | |
219 Uri packageUri = null; | |
220 if (packageRoot != null) { | |
221 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); | |
222 } | |
223 return api.compile(scriptUri, libraryUri, packageUri, | |
224 provider.readStringFromUri, diagnosticHandler, options); | |
225 } | |
226 | |
227 /** | 191 /** |
228 * Analyzes set of libraries and provides a mirror system which can be used for | 192 * Analyzes set of libraries and provides a mirror system which can be used for |
229 * static inspection of the source code. | 193 * static inspection of the source code. |
230 */ | 194 */ |
231 // TODO(johnniwinther): Move this to [compiler/compiler.dart] and rename to | 195 // TODO(johnniwinther): Move this to [compiler/compiler.dart]. |
232 // [:analyze:]. | 196 Future<MirrorSystem> analyze(List<Uri> libraries, |
233 Future<MirrorSystem> analyzeUri(List<Uri> libraries, | 197 Uri libraryRoot, |
234 Uri libraryRoot, | 198 Uri packageRoot, |
235 Uri packageRoot, | 199 api.CompilerInputProvider inputProvider, |
236 api.CompilerInputProvider inputProvider, | 200 api.DiagnosticHandler diagnosticHandler, |
237 api.DiagnosticHandler diagnosticHandler, | 201 [List<String> options = const <String>[]]) { |
238 [List<String> options = const <String>[]]) { | |
239 if (!libraryRoot.path.endsWith("/")) { | 202 if (!libraryRoot.path.endsWith("/")) { |
240 throw new ArgumentError("libraryRoot must end with a /"); | 203 throw new ArgumentError("libraryRoot must end with a /"); |
241 } | 204 } |
242 if (packageRoot != null && !packageRoot.path.endsWith("/")) { | 205 if (packageRoot != null && !packageRoot.path.endsWith("/")) { |
243 throw new ArgumentError("packageRoot must end with a /"); | 206 throw new ArgumentError("packageRoot must end with a /"); |
244 } | 207 } |
245 options = new List<String>.from(options); | 208 options = new List<String>.from(options); |
246 options.add('--analyze-only'); | 209 options.add('--analyze-only'); |
247 options.add('--analyze-signatures-only'); | 210 options.add('--analyze-signatures-only'); |
248 options.add('--analyze-all'); | 211 options.add('--analyze-all'); |
(...skipping 14 matching lines...) Expand all Loading... |
263 libraryRoot, packageRoot, options); | 226 libraryRoot, packageRoot, options); |
264 compiler.librariesToAnalyzeWhenRun = libraries; | 227 compiler.librariesToAnalyzeWhenRun = libraries; |
265 bool success = compiler.run(null); | 228 bool success = compiler.run(null); |
266 if (success && !compilationFailed) { | 229 if (success && !compilationFailed) { |
267 return new Future<MirrorSystem>.value(new Dart2JsMirrorSystem(compiler)); | 230 return new Future<MirrorSystem>.value(new Dart2JsMirrorSystem(compiler)); |
268 } else { | 231 } else { |
269 return new Future<MirrorSystem>.error('Failed to create mirror system.'); | 232 return new Future<MirrorSystem>.error('Failed to create mirror system.'); |
270 } | 233 } |
271 } | 234 } |
272 | 235 |
273 /** | |
274 * Analyzes set of libraries and provides a mirror system which can be used for | |
275 * static inspection of the source code. | |
276 */ | |
277 // TODO(johnniwinther): Move dart:io dependent parts outside | |
278 // dart2js_mirror.dart. | |
279 Future<MirrorSystem> analyze(List<Path> libraries, | |
280 Path libraryRoot, | |
281 {Path packageRoot, | |
282 List<String> options: const <String>[], | |
283 api.DiagnosticHandler diagnosticHandler}) { | |
284 SourceFileProvider provider = new SourceFileProvider(); | |
285 if (diagnosticHandler == null) { | |
286 diagnosticHandler = | |
287 new FormattingDiagnosticHandler(provider).diagnosticHandler; | |
288 } | |
289 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); | |
290 Uri packageUri = null; | |
291 if (packageRoot != null) { | |
292 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); | |
293 } | |
294 List<Uri> librariesUri = <Uri>[]; | |
295 for (Path library in libraries) { | |
296 librariesUri.add(currentDirectory.resolve(library.toString())); | |
297 } | |
298 return analyzeUri(librariesUri, libraryUri, packageUri, | |
299 provider.readStringFromUri, diagnosticHandler, options); | |
300 } | |
301 | |
302 //------------------------------------------------------------------------------ | 236 //------------------------------------------------------------------------------ |
303 // Dart2Js specific extensions of mirror interfaces | 237 // Dart2Js specific extensions of mirror interfaces |
304 //------------------------------------------------------------------------------ | 238 //------------------------------------------------------------------------------ |
305 | 239 |
306 abstract class Dart2JsMirror implements Mirror { | 240 abstract class Dart2JsMirror implements Mirror { |
307 Dart2JsMirrorSystem get mirrors; | 241 Dart2JsMirrorSystem get mirrors; |
308 } | 242 } |
309 | 243 |
310 abstract class Dart2JsDeclarationMirror extends Dart2JsMirror | 244 abstract class Dart2JsDeclarationMirror extends Dart2JsMirror |
311 implements DeclarationMirror { | 245 implements DeclarationMirror { |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1747 return new Future.value( | 1681 return new Future.value( |
1748 new Dart2JsStringConstantMirror.fromString(mirrors, text)); | 1682 new Dart2JsStringConstantMirror.fromString(mirrors, text)); |
1749 } else if (fieldName == 'trimmedText') { | 1683 } else if (fieldName == 'trimmedText') { |
1750 return new Future.value( | 1684 return new Future.value( |
1751 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); | 1685 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); |
1752 } | 1686 } |
1753 // TODO(johnniwinther): Which exception/error should be thrown here? | 1687 // TODO(johnniwinther): Which exception/error should be thrown here? |
1754 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1688 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1755 } | 1689 } |
1756 } | 1690 } |
OLD | NEW |