| 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; |
| 11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
| 12 import '../apiimpl.dart' as apiimpl; | 12 import '../apiimpl.dart' as apiimpl; |
| 13 import '../scanner/scannerlib.dart' hide SourceString; | 13 import '../scanner/scannerlib.dart' hide SourceString; |
| 14 import '../resolution/resolution.dart' show Scope; | 14 import '../resolution/resolution.dart' show Scope; |
| 15 import '../dart2jslib.dart'; | 15 import '../dart2jslib.dart'; |
| 16 import '../dart_types.dart'; | 16 import '../dart_types.dart'; |
| 17 import '../source_file.dart'; | |
| 18 import '../tree/tree.dart'; | 17 import '../tree/tree.dart'; |
| 19 import '../util/util.dart' show Spannable, Link; | 18 import '../util/util.dart' show Spannable, Link; |
| 20 import '../util/characters.dart' show $CR, $LF; | 19 import '../util/characters.dart' show $CR, $LF; |
| 21 | 20 |
| 22 import 'mirrors.dart'; | 21 import 'mirrors.dart'; |
| 23 import 'mirrors_util.dart'; | 22 import 'mirrors_util.dart'; |
| 24 import 'util.dart'; | 23 import 'util.dart'; |
| 25 | 24 |
| 26 //------------------------------------------------------------------------------ | 25 //------------------------------------------------------------------------------ |
| 27 // Utility types and functions for the dart2js mirror system | 26 // Utility types and functions for the dart2js mirror system |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 | 626 |
| 628 class Dart2JsSourceLocation implements SourceLocation { | 627 class Dart2JsSourceLocation implements SourceLocation { |
| 629 final Script _script; | 628 final Script _script; |
| 630 final SourceSpan _span; | 629 final SourceSpan _span; |
| 631 int _line; | 630 int _line; |
| 632 int _column; | 631 int _column; |
| 633 | 632 |
| 634 Dart2JsSourceLocation(this._script, this._span); | 633 Dart2JsSourceLocation(this._script, this._span); |
| 635 | 634 |
| 636 int _computeLine() { | 635 int _computeLine() { |
| 637 var sourceFile = _script.file as SourceFile; | 636 var sourceFile = _script.file; |
| 638 if (sourceFile != null) { | 637 if (sourceFile != null) { |
| 639 return sourceFile.getLine(offset) + 1; | 638 return sourceFile.getLine(offset) + 1; |
| 640 } | 639 } |
| 641 var index = 0; | 640 var index = 0; |
| 642 var lineNumber = 0; | 641 var lineNumber = 0; |
| 643 while (index <= offset && index < sourceText.length) { | 642 while (index <= offset && index < sourceText.length) { |
| 644 index = sourceText.indexOf('\n', index) + 1; | 643 index = sourceText.indexOf('\n', index) + 1; |
| 645 if (index <= 0) break; | 644 if (index <= 0) break; |
| 646 lineNumber++; | 645 lineNumber++; |
| 647 } | 646 } |
| 648 return lineNumber; | 647 return lineNumber; |
| 649 } | 648 } |
| 650 | 649 |
| 651 int get line { | 650 int get line { |
| 652 if (_line == null) { | 651 if (_line == null) { |
| 653 _line = _computeLine(); | 652 _line = _computeLine(); |
| 654 } | 653 } |
| 655 return _line; | 654 return _line; |
| 656 } | 655 } |
| 657 | 656 |
| 658 int _computeColumn() { | 657 int _computeColumn() { |
| 659 if (length == 0) return 0; | 658 if (length == 0) return 0; |
| 660 | 659 |
| 661 var sourceFile = _script.file as SourceFile; | 660 var sourceFile = _script.file; |
| 662 if (sourceFile != null) { | 661 if (sourceFile != null) { |
| 663 return sourceFile.getColumn(sourceFile.getLine(offset), offset) + 1; | 662 return sourceFile.getColumn(sourceFile.getLine(offset), offset) + 1; |
| 664 } | 663 } |
| 665 int index = offset - 1; | 664 int index = offset - 1; |
| 666 var columnNumber = 0; | 665 var columnNumber = 0; |
| 667 while (0 <= index && index < sourceText.length) { | 666 while (0 <= index && index < sourceText.length) { |
| 668 columnNumber++; | 667 columnNumber++; |
| 669 var codeUnit = sourceText.codeUnitAt(index); | 668 var codeUnit = sourceText.codeUnitAt(index); |
| 670 if (codeUnit == $CR || codeUnit == $LF) { | 669 if (codeUnit == $CR || codeUnit == $LF) { |
| 671 break; | 670 break; |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 * | 1750 * |
| 1752 * All API in this class is experimental. | 1751 * All API in this class is experimental. |
| 1753 */ | 1752 */ |
| 1754 class BackDoor { | 1753 class BackDoor { |
| 1755 /// Return the compilation units comprising [library]. | 1754 /// Return the compilation units comprising [library]. |
| 1756 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { | 1755 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { |
| 1757 return library._library.compilationUnits.toList().map( | 1756 return library._library.compilationUnits.toList().map( |
| 1758 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); | 1757 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); |
| 1759 } | 1758 } |
| 1760 } | 1759 } |
| OLD | NEW |