Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 dart2js.kernel.element_map; | 5 library dart2js.kernel.element_map; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 118 } |
| 119 | 119 |
| 120 LibraryEntity get _mainLibrary { | 120 LibraryEntity get _mainLibrary { |
| 121 return _env.mainMethod != null | 121 return _env.mainMethod != null |
| 122 ? _getLibrary(_env.mainMethod.enclosingLibrary) | 122 ? _getLibrary(_env.mainMethod.enclosingLibrary) |
| 123 : null; | 123 : null; |
| 124 } | 124 } |
| 125 | 125 |
| 126 Iterable<LibraryEntity> get _libraries; | 126 Iterable<LibraryEntity> get _libraries; |
| 127 | 127 |
| 128 SourceSpan _getSourceSpanFromTreeNode(ir.TreeNode node) { | |
| 129 ir.Location location; | |
|
Siggi Cherem (dart-lang)
2017/07/07 19:25:02
Let's store here just the Uri, and only use locati
Johnni Winther
2017/07/11 08:06:59
Done.
Siggi Cherem (dart-lang)
2017/07/11 19:04:55
I'd like to use package:source_span for this (mayb
| |
| 130 int offset; | |
| 131 while (node != null) { | |
| 132 if (node.fileOffset != ir.TreeNode.noOffset) { | |
| 133 offset = node.fileOffset; | |
| 134 location = node.location; | |
| 135 break; | |
| 136 } | |
| 137 node = node.parent; | |
| 138 } | |
| 139 if (location != null) { | |
| 140 return new SourceSpan(Uri.parse(location.file), offset, offset + 1); | |
| 141 } | |
| 142 return null; | |
| 143 } | |
| 144 | |
| 145 SourceSpan getSourceSpan(Spannable spannable, Entity currentElement) { | |
| 146 SourceSpan fromSpannable(Spannable spannable) { | |
| 147 if (spannable is IndexedLibrary && | |
| 148 spannable.libraryIndex < _libraryEnvs.length) { | |
| 149 LibraryEnv env = _libraryEnvs[spannable.libraryIndex]; | |
| 150 return _getSourceSpanFromTreeNode(env.library); | |
| 151 } else if (spannable is IndexedClass && | |
| 152 spannable.classIndex < _classEnvs.length) { | |
| 153 ClassEnv env = _classEnvs[spannable.classIndex]; | |
| 154 return _getSourceSpanFromTreeNode(env.cls); | |
| 155 } else if (spannable is IndexedMember && | |
| 156 spannable.memberIndex < _memberData.length) { | |
| 157 MemberData data = _memberData[spannable.memberIndex]; | |
| 158 return _getSourceSpanFromTreeNode(data.node); | |
|
Siggi Cherem (dart-lang)
2017/07/07 19:25:02
there is not a common interface for these in kerne
Johnni Winther
2017/07/11 08:06:59
They might, but MemberData.node might be a functio
| |
| 159 } | |
| 160 return null; | |
| 161 } | |
| 162 | |
| 163 SourceSpan sourceSpan = fromSpannable(spannable); | |
| 164 sourceSpan ??= fromSpannable(currentElement); | |
| 165 return sourceSpan; | |
| 166 } | |
| 167 | |
| 128 LibraryEntity lookupLibrary(Uri uri) { | 168 LibraryEntity lookupLibrary(Uri uri) { |
| 129 LibraryEnv libraryEnv = _env.lookupLibrary(uri); | 169 LibraryEnv libraryEnv = _env.lookupLibrary(uri); |
| 130 if (libraryEnv == null) return null; | 170 if (libraryEnv == null) return null; |
| 131 return _getLibrary(libraryEnv.library, libraryEnv); | 171 return _getLibrary(libraryEnv.library, libraryEnv); |
| 132 } | 172 } |
| 133 | 173 |
| 134 String _getLibraryName(IndexedLibrary library) { | 174 String _getLibraryName(IndexedLibrary library) { |
| 135 assert(checkFamily(library)); | 175 assert(checkFamily(library)); |
| 136 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; | 176 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; |
| 137 return libraryEnv.library.name ?? ''; | 177 return libraryEnv.library.name ?? ''; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 } | 569 } |
| 530 | 570 |
| 531 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { | 571 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { |
| 532 assert(checkFamily(cls)); | 572 assert(checkFamily(cls)); |
| 533 ClassData data = _classData[cls.classIndex]; | 573 ClassData data = _classData[cls.classIndex]; |
| 534 _ensureSupertypes(cls, data); | 574 _ensureSupertypes(cls, data); |
| 535 return data.interfaces; | 575 return data.interfaces; |
| 536 } | 576 } |
| 537 | 577 |
| 538 Spannable _getSpannable(MemberEntity member, ir.Node node) { | 578 Spannable _getSpannable(MemberEntity member, ir.Node node) { |
| 539 return member; | 579 SourceSpan sourceSpan; |
| 580 if (node is ir.TreeNode) { | |
| 581 sourceSpan = _getSourceSpanFromTreeNode(node); | |
| 582 } | |
| 583 sourceSpan ??= getSourceSpan(member, null); | |
| 584 return sourceSpan; | |
| 540 } | 585 } |
| 541 | 586 |
| 542 ir.Member _getMemberNode(covariant IndexedMember member) { | 587 ir.Member _getMemberNode(covariant IndexedMember member) { |
| 543 assert(checkFamily(member)); | 588 assert(checkFamily(member)); |
| 544 return _memberData[member.memberIndex].node; | 589 return _memberData[member.memberIndex].node; |
| 545 } | 590 } |
| 546 | 591 |
| 547 ir.Class _getClassNode(covariant IndexedClass cls) { | 592 ir.Class _getClassNode(covariant IndexedClass cls) { |
| 548 assert(checkFamily(cls)); | 593 assert(checkFamily(cls)); |
| 549 return _classEnvs[cls.classIndex].cls; | 594 return _classEnvs[cls.classIndex].cls; |
| (...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1925 @override | 1970 @override |
| 1926 ir.Member getMemberNode(MemberEntity member) { | 1971 ir.Member getMemberNode(MemberEntity member) { |
| 1927 return _getMemberNode(member); | 1972 return _getMemberNode(member); |
| 1928 } | 1973 } |
| 1929 | 1974 |
| 1930 @override | 1975 @override |
| 1931 ir.Class getClassNode(ClassEntity cls) { | 1976 ir.Class getClassNode(ClassEntity cls) { |
| 1932 return _getClassNode(cls); | 1977 return _getClassNode(cls); |
| 1933 } | 1978 } |
| 1934 } | 1979 } |
| OLD | NEW |