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 | 9 |
10 import '../../compiler.dart' as api; | 10 import '../../compiler.dart' as api; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 compilationFailed = true; | 220 compilationFailed = true; |
221 } | 221 } |
222 diagnosticHandler(uri, begin, end, message, kind); | 222 diagnosticHandler(uri, begin, end, message, kind); |
223 } | 223 } |
224 | 224 |
225 Compiler compiler = new apiimpl.Compiler(inputProvider, | 225 Compiler compiler = new apiimpl.Compiler(inputProvider, |
226 null, | 226 null, |
227 internalDiagnosticHandler, | 227 internalDiagnosticHandler, |
228 libraryRoot, packageRoot, options); | 228 libraryRoot, packageRoot, options); |
229 compiler.librariesToAnalyzeWhenRun = libraries; | 229 compiler.librariesToAnalyzeWhenRun = libraries; |
230 bool success = compiler.run(null); | 230 return compiler.run(null).then((bool success) { |
231 if (success && !compilationFailed) { | 231 if (success && !compilationFailed) { |
232 return new Future<MirrorSystem>.value(new Dart2JsMirrorSystem(compiler)); | 232 return new Dart2JsMirrorSystem(compiler); |
233 } else { | 233 } else { |
234 return new Future<MirrorSystem>.error('Failed to create mirror system.'); | 234 throw new StateError('Failed to create mirror system.'); |
235 } | 235 } |
| 236 }); |
236 } | 237 } |
237 | 238 |
238 //------------------------------------------------------------------------------ | 239 //------------------------------------------------------------------------------ |
239 // Dart2Js specific extensions of mirror interfaces | 240 // Dart2Js specific extensions of mirror interfaces |
240 //------------------------------------------------------------------------------ | 241 //------------------------------------------------------------------------------ |
241 | 242 |
242 abstract class Dart2JsMirror implements Mirror { | 243 abstract class Dart2JsMirror implements Mirror { |
243 Dart2JsMirrorSystem get mirrors; | 244 Dart2JsMirrorSystem get mirrors; |
244 } | 245 } |
245 | 246 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 376 |
376 DeclarationMirror lookupInScope(String name) { | 377 DeclarationMirror lookupInScope(String name) { |
377 // TODO(11653): Support lookup of constructors. | 378 // TODO(11653): Support lookup of constructors. |
378 Scope scope = _element.buildScope(); | 379 Scope scope = _element.buildScope(); |
379 Element result; | 380 Element result; |
380 int index = name.indexOf('.'); | 381 int index = name.indexOf('.'); |
381 if (index != -1) { | 382 if (index != -1) { |
382 // Lookup [: prefix.id :]. | 383 // Lookup [: prefix.id :]. |
383 String prefix = name.substring(0, index); | 384 String prefix = name.substring(0, index); |
384 String id = name.substring(index+1); | 385 String id = name.substring(index+1); |
385 result = scope.lookup(new SourceString(prefix)); | 386 result = scope.lookup(new SourceString(prefix)); |
386 if (result != null && result.isPrefix()) { | 387 if (result != null && result.isPrefix()) { |
387 PrefixElement prefix = result; | 388 PrefixElement prefix = result; |
388 result = prefix.lookupLocalMember(new SourceString(id)); | 389 result = prefix.lookupLocalMember(new SourceString(id)); |
389 } else { | 390 } else { |
390 result = null; | 391 result = null; |
391 } | 392 } |
392 } else { | 393 } else { |
393 // Lookup [: id :]. | 394 // Lookup [: id :]. |
394 result = scope.lookup(new SourceString(name)); | 395 result = scope.lookup(new SourceString(name)); |
395 } | 396 } |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 * | 1751 * |
1751 * All API in this class is experimental. | 1752 * All API in this class is experimental. |
1752 */ | 1753 */ |
1753 class BackDoor { | 1754 class BackDoor { |
1754 /// Return the compilation units comprising [library]. | 1755 /// Return the compilation units comprising [library]. |
1755 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { | 1756 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { |
1756 return library._library.compilationUnits.toList().map( | 1757 return library._library.compilationUnits.toList().map( |
1757 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); | 1758 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); |
1758 } | 1759 } |
1759 } | 1760 } |
OLD | NEW |