Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart

Issue 11275097: Merge SourceLocation and Source (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/dartdoc/lib/src/dartdoc/comment_map.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:io'; 7 import 'dart:io';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import '../../../../../lib/compiler/compiler.dart' as diagnostics; 10 import '../../../../../lib/compiler/compiler.dart' as diagnostics;
11 import '../../../../../lib/compiler/implementation/elements/elements.dart'; 11 import '../../../../../lib/compiler/implementation/elements/elements.dart';
12 import '../../../../../lib/compiler/implementation/resolution/resolution.dart' 12 import '../../../../../lib/compiler/implementation/resolution/resolution.dart'
13 show ResolverTask, ResolverVisitor; 13 show ResolverTask, ResolverVisitor;
14 import '../../../../../lib/compiler/implementation/apiimpl.dart' as api; 14 import '../../../../../lib/compiler/implementation/apiimpl.dart' as api;
15 import '../../../../../lib/compiler/implementation/scanner/scannerlib.dart'; 15 import '../../../../../lib/compiler/implementation/scanner/scannerlib.dart';
16 import '../../../../../lib/compiler/implementation/ssa/ssa.dart'; 16 import '../../../../../lib/compiler/implementation/ssa/ssa.dart';
17 import '../../../../../lib/compiler/implementation/dart2jslib.dart'; 17 import '../../../../../lib/compiler/implementation/dart2jslib.dart';
18 import '../../../../../lib/compiler/implementation/filenames.dart'; 18 import '../../../../../lib/compiler/implementation/filenames.dart';
19 import '../../../../../lib/compiler/implementation/source_file.dart'; 19 import '../../../../../lib/compiler/implementation/source_file.dart';
20 import '../../../../../lib/compiler/implementation/tree/tree.dart'; 20 import '../../../../../lib/compiler/implementation/tree/tree.dart';
21 import '../../../../../lib/compiler/implementation/util/util.dart'; 21 import '../../../../../lib/compiler/implementation/util/util.dart';
22 import '../../../../../lib/compiler/implementation/util/uri_extras.dart'; 22 import '../../../../../lib/compiler/implementation/util/uri_extras.dart';
23 import '../../../../../lib/compiler/implementation/dart2js.dart'; 23 import '../../../../../lib/compiler/implementation/dart2js.dart';
24 import '../../../../../lib/compiler/implementation/util/characters.dart';
24 25
25 // TODO(rnystrom): Use "package:" URL (#4968). 26 // TODO(rnystrom): Use "package:" URL (#4968).
26 import '../../mirrors.dart'; 27 import '../../mirrors.dart';
27 import 'util.dart'; 28 import 'util.dart';
28 29
29 //------------------------------------------------------------------------------ 30 //------------------------------------------------------------------------------
30 // Utility types and functions for the dart2js mirror system 31 // Utility types and functions for the dart2js mirror system
31 //------------------------------------------------------------------------------ 32 //------------------------------------------------------------------------------
32 33
33 bool _isPrivate(String name) { 34 bool _isPrivate(String name) {
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 422
422 Dart2JsElementMirror(this.mirrors, this._element) { 423 Dart2JsElementMirror(this.mirrors, this._element) {
423 assert (mirrors !== null); 424 assert (mirrors !== null);
424 assert (_element !== null); 425 assert (_element !== null);
425 } 426 }
426 427
427 String get simpleName => _element.name.slowToString(); 428 String get simpleName => _element.name.slowToString();
428 429
429 String get displayName => simpleName; 430 String get displayName => simpleName;
430 431
431 SourceLocation get location => new Dart2JsLocation( 432 SourceLocation get location => new Dart2JsSourceLocation(
432 _element.getCompilationUnit().script, 433 _element.getCompilationUnit().script,
433 mirrors.compiler.spanFromElement(_element)); 434 mirrors.compiler.spanFromElement(_element));
434 435
435 String toString() => _element.toString(); 436 String toString() => _element.toString();
436 437
437 int get hashCode => qualifiedName.hashCode; 438 int get hashCode => qualifiedName.hashCode;
438 } 439 }
439 440
440 abstract class Dart2JsProxyMirror extends Dart2JsDeclarationMirror { 441 abstract class Dart2JsProxyMirror extends Dart2JsDeclarationMirror {
441 final Dart2JsMirrorSystem mirrors; 442 final Dart2JsMirrorSystem mirrors;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 611 }
611 } 612 }
612 613
613 Map<String, ClassMirror> get classes { 614 Map<String, ClassMirror> get classes {
614 _ensureClasses(); 615 _ensureClasses();
615 return new ImmutableMapWrapper<String, ClassMirror>(_classes); 616 return new ImmutableMapWrapper<String, ClassMirror>(_classes);
616 } 617 }
617 618
618 SourceLocation get location { 619 SourceLocation get location {
619 var script = _library.getCompilationUnit().script; 620 var script = _library.getCompilationUnit().script;
620 return new Dart2JsLocation( 621 return new Dart2JsSourceLocation(
621 script, 622 script,
622 new SourceSpan(script.uri, 0, script.text.length)); 623 new SourceSpan(script.uri, 0, script.text.length));
623 } 624 }
624 } 625 }
625 626
626 class Dart2JsLocation implements SourceLocation { 627 class Dart2JsSourceLocation implements SourceLocation {
627 Script _script; 628 final Script _script;
628 SourceSpan _span; 629 final SourceSpan _span;
629 630
630 Dart2JsLocation(this._script, this._span); 631 Dart2JsSourceLocation(this._script, this._span);
631 632
632 int get start => _span.begin; 633 int get line {
634 var sourceFile = _script.file is SourceFile;
kasperl 2012/11/01 10:13:29 I'd factor out the computation part into a compute
Johnni Winther 2012/11/01 12:01:58 Done.
635 if (sourceFile != null) {
636 return sourceFile.getLine(offset);
637 }
638 var index = 0;
639 var lineNumber = 0;
640 while (index < sourceText.length) {
641 lineNumber++;
642 index = sourceText.indexOf('\n', index) + 1;
kasperl 2012/11/01 10:13:29 I don't think this works on all platforms. I'd rec
Johnni Winther 2012/11/01 12:01:58 Done.
643 if (index <= 0) break;
644 }
645 return lineNumber;
646 }
633 647
634 int get end => _span.end; 648 int get column {
kasperl 2012/11/01 10:13:29 I'd factor out the computation part into a compute
Johnni Winther 2012/11/01 12:01:58 Done.
649 if (length == 0) return 0;
635 650
636 Source get source => new Dart2JsSource(_script); 651 var sourceFile = _script.file is SourceFile;
652 if (sourceFile != null) {
653 return sourceFile.getColumn(sourceFile.getLine(offset), offset);
654 }
637 655
638 String get text => _script.text.substring(start, end); 656 int index = offset-1;
kasperl 2012/11/01 10:13:29 offset - 1 (spacing)
Johnni Winther 2012/11/01 12:01:58 Done.
639 } 657 var columnNumber = 0;
658 while (0 <= index && index < sourceText.length) {
659 var charCode = sourceText.charCodeAt(index);
660 if (charCode == $CR || charCode == $LF) {
661 break;
662 }
663 index--;
664 columnNumber++;
665 }
666 return column;
kasperl 2012/11/01 10:13:29 Hmm. This looks broken. Isn't this self-recursive?
Johnni Winther 2012/11/01 12:01:58 Yes. Fixed.
640 667
641 class Dart2JsSource implements Source { 668 }
642 Script _script;
643 669
644 Dart2JsSource(this._script); 670 int get offset => _span.begin;
645 671
646 Uri get uri => _script.uri; 672 int get length => _span.end - _span.end;
647 673
648 String get text => _script.text; 674 String get text => _script.text.substring(_span.begin, _span.end);
675
676 Uri get sourceUri => _script.uri;
677
678 String get sourceText => _script.text;
649 } 679 }
650 680
651 class Dart2JsParameterMirror extends Dart2JsMemberMirror 681 class Dart2JsParameterMirror extends Dart2JsMemberMirror
652 implements ParameterMirror { 682 implements ParameterMirror {
653 final MethodMirror _method; 683 final MethodMirror _method;
654 final bool isOptional; 684 final bool isOptional;
655 final bool isNamed; 685 final bool isNamed;
656 686
657 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system, 687 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system,
658 MethodMirror method, 688 MethodMirror method,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 DeclarationMirror get owner => library; 787 DeclarationMirror get owner => library;
758 788
759 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; 789 String get qualifiedName => '${library.qualifiedName}.${simpleName}';
760 790
761 SourceLocation get location { 791 SourceLocation get location {
762 if (_class is PartialClassElement) { 792 if (_class is PartialClassElement) {
763 var node = _class.parseNode(mirrors.compiler); 793 var node = _class.parseNode(mirrors.compiler);
764 if (node !== null) { 794 if (node !== null) {
765 var script = _class.getCompilationUnit().script; 795 var script = _class.getCompilationUnit().script;
766 var span = mirrors.compiler.spanFromNode(node, script.uri); 796 var span = mirrors.compiler.spanFromNode(node, script.uri);
767 return new Dart2JsLocation(script, span); 797 return new Dart2JsSourceLocation(script, span);
768 } 798 }
769 } 799 }
770 return super.location; 800 return super.location;
771 } 801 }
772 802
773 void _ensureMembers() { 803 void _ensureMembers() {
774 if (_members == null) { 804 if (_members == null) {
775 _members = <String, Dart2JsMemberMirror>{}; 805 _members = <String, Dart2JsMemberMirror>{};
776 _class.forEachMember((_, e) { 806 _class.forEachMember((_, e) {
777 for (var member in _convertElementMemberToMemberMirrors(this, e)) { 807 for (var member in _convertElementMemberToMemberMirrors(this, e)) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 922
893 TypedefType get _typedef => _type; 923 TypedefType get _typedef => _type;
894 924
895 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; 925 String get qualifiedName => '${library.qualifiedName}.${simpleName}';
896 926
897 SourceLocation get location { 927 SourceLocation get location {
898 var node = _typedef.element.parseNode(_diagnosticListener); 928 var node = _typedef.element.parseNode(_diagnosticListener);
899 if (node !== null) { 929 if (node !== null) {
900 var script = _typedef.element.getCompilationUnit().script; 930 var script = _typedef.element.getCompilationUnit().script;
901 var span = mirrors.compiler.spanFromNode(node, script.uri); 931 var span = mirrors.compiler.spanFromNode(node, script.uri);
902 return new Dart2JsLocation(script, span); 932 return new Dart2JsSourceLocation(script, span);
903 } 933 }
904 return super.location; 934 return super.location;
905 } 935 }
906 936
907 LibraryMirror get library => _library; 937 LibraryMirror get library => _library;
908 938
909 bool get isTypedef => true; 939 bool get isTypedef => true;
910 940
911 List<TypeMirror> get typeArguments { 941 List<TypeMirror> get typeArguments {
912 throw new UnsupportedError( 942 throw new UnsupportedError(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 implements Dart2JsTypeMirror { 1046 implements Dart2JsTypeMirror {
1017 final DartType _type; 1047 final DartType _type;
1018 1048
1019 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type) 1049 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type)
1020 : super(system); 1050 : super(system);
1021 1051
1022 String get simpleName => _type.name.slowToString(); 1052 String get simpleName => _type.name.slowToString();
1023 1053
1024 SourceLocation get location { 1054 SourceLocation get location {
1025 var script = _type.element.getCompilationUnit().script; 1055 var script = _type.element.getCompilationUnit().script;
1026 return new Dart2JsLocation(script, 1056 return new Dart2JsSourceLocation(script,
1027 mirrors.compiler.spanFromElement(_type.element)); 1057 mirrors.compiler.spanFromElement(_type.element));
kasperl 2012/11/01 10:13:29 Indentation is off now.
Johnni Winther 2012/11/01 12:01:58 Done.
1028 } 1058 }
1029 1059
1030 DeclarationMirror get owner => library; 1060 DeclarationMirror get owner => library;
1031 1061
1032 LibraryMirror get library { 1062 LibraryMirror get library {
1033 return mirrors._getLibrary(_type.element.getLibrary()); 1063 return mirrors._getLibrary(_type.element.getLibrary());
1034 } 1064 }
1035 1065
1036 bool get isObject => false; 1066 bool get isObject => false;
1037 1067
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 1457
1428 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; 1458 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR;
1429 1459
1430 String get operatorName => _operatorName; 1460 String get operatorName => _operatorName;
1431 1461
1432 SourceLocation get location { 1462 SourceLocation get location {
1433 var node = _function.parseNode(_diagnosticListener); 1463 var node = _function.parseNode(_diagnosticListener);
1434 if (node !== null) { 1464 if (node !== null) {
1435 var script = _function.getCompilationUnit().script; 1465 var script = _function.getCompilationUnit().script;
1436 var span = mirrors.compiler.spanFromNode(node, script.uri); 1466 var span = mirrors.compiler.spanFromNode(node, script.uri);
1437 return new Dart2JsLocation(script, span); 1467 return new Dart2JsSourceLocation(script, span);
1438 } 1468 }
1439 return super.location; 1469 return super.location;
1440 } 1470 }
1441 1471
1442 } 1472 }
1443 1473
1444 class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror { 1474 class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror {
1445 Dart2JsContainerMirror _objectMirror; 1475 Dart2JsContainerMirror _objectMirror;
1446 VariableElement _variable; 1476 VariableElement _variable;
1447 1477
(...skipping 20 matching lines...) Expand all
1468 1498
1469 TypeMirror get type => _convertTypeToTypeMirror(mirrors, 1499 TypeMirror get type => _convertTypeToTypeMirror(mirrors,
1470 _variable.computeType(mirrors.compiler), 1500 _variable.computeType(mirrors.compiler),
1471 mirrors.compiler.types.dynamicType); 1501 mirrors.compiler.types.dynamicType);
1472 1502
1473 SourceLocation get location { 1503 SourceLocation get location {
1474 var script = _variable.getCompilationUnit().script; 1504 var script = _variable.getCompilationUnit().script;
1475 var node = _variable.variables.parseNode(_diagnosticListener); 1505 var node = _variable.variables.parseNode(_diagnosticListener);
1476 if (node !== null) { 1506 if (node !== null) {
1477 var span = mirrors.compiler.spanFromNode(node, script.uri); 1507 var span = mirrors.compiler.spanFromNode(node, script.uri);
1478 return new Dart2JsLocation(script, span); 1508 return new Dart2JsSourceLocation(script, span);
1479 } else { 1509 } else {
1480 var span = mirrors.compiler.spanFromElement(_variable); 1510 var span = mirrors.compiler.spanFromElement(_variable);
1481 return new Dart2JsLocation(script, span); 1511 return new Dart2JsSourceLocation(script, span);
1482 } 1512 }
1483 } 1513 }
1484 } 1514 }
1485 1515
OLDNEW
« no previous file with comments | « pkg/dartdoc/lib/src/dartdoc/comment_map.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698