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

Side by Side Diff: pkg/compiler/lib/src/kernel/element_map_impl.dart

Issue 2974663002: Compute source spans for IR nodes and J/K-elements (Closed)
Patch Set: Updated cf. comments Created 3 years, 5 months 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
OLDNEW
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
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 // TODO(johnniwinther): Use [ir.Location] directly as a [SourceSpan].
130 Uri uri;
131 int offset;
132 while (node != null) {
133 if (node.fileOffset != ir.TreeNode.noOffset) {
134 offset = node.fileOffset;
135 uri = Uri.parse(node.location.file);
136 break;
137 }
138 node = node.parent;
139 }
140 if (uri != null) {
141 return new SourceSpan(uri, offset, offset + 1);
142 }
143 return null;
144 }
145
146 SourceSpan getSourceSpan(Spannable spannable, Entity currentElement) {
147 SourceSpan fromSpannable(Spannable spannable) {
148 if (spannable is IndexedLibrary &&
149 spannable.libraryIndex < _libraryEnvs.length) {
150 LibraryEnv env = _libraryEnvs[spannable.libraryIndex];
151 return _getSourceSpanFromTreeNode(env.library);
152 } else if (spannable is IndexedClass &&
153 spannable.classIndex < _classEnvs.length) {
154 ClassEnv env = _classEnvs[spannable.classIndex];
155 return _getSourceSpanFromTreeNode(env.cls);
156 } else if (spannable is IndexedMember &&
157 spannable.memberIndex < _memberData.length) {
158 MemberData data = _memberData[spannable.memberIndex];
159 return _getSourceSpanFromTreeNode(data.node);
160 }
161 return null;
162 }
163
164 SourceSpan sourceSpan = fromSpannable(spannable);
165 sourceSpan ??= fromSpannable(currentElement);
166 return sourceSpan;
167 }
168
128 LibraryEntity lookupLibrary(Uri uri) { 169 LibraryEntity lookupLibrary(Uri uri) {
129 LibraryEnv libraryEnv = _env.lookupLibrary(uri); 170 LibraryEnv libraryEnv = _env.lookupLibrary(uri);
130 if (libraryEnv == null) return null; 171 if (libraryEnv == null) return null;
131 return _getLibrary(libraryEnv.library, libraryEnv); 172 return _getLibrary(libraryEnv.library, libraryEnv);
132 } 173 }
133 174
134 String _getLibraryName(IndexedLibrary library) { 175 String _getLibraryName(IndexedLibrary library) {
135 assert(checkFamily(library)); 176 assert(checkFamily(library));
136 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex]; 177 LibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex];
137 return libraryEnv.library.name ?? ''; 178 return libraryEnv.library.name ?? '';
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } 570 }
530 571
531 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) { 572 Iterable<InterfaceType> _getInterfaces(IndexedClass cls) {
532 assert(checkFamily(cls)); 573 assert(checkFamily(cls));
533 ClassData data = _classData[cls.classIndex]; 574 ClassData data = _classData[cls.classIndex];
534 _ensureSupertypes(cls, data); 575 _ensureSupertypes(cls, data);
535 return data.interfaces; 576 return data.interfaces;
536 } 577 }
537 578
538 Spannable _getSpannable(MemberEntity member, ir.Node node) { 579 Spannable _getSpannable(MemberEntity member, ir.Node node) {
539 return member; 580 SourceSpan sourceSpan;
581 if (node is ir.TreeNode) {
582 sourceSpan = _getSourceSpanFromTreeNode(node);
583 }
584 sourceSpan ??= getSourceSpan(member, null);
585 return sourceSpan;
540 } 586 }
541 587
542 ir.Member _getMemberNode(covariant IndexedMember member) { 588 ir.Member _getMemberNode(covariant IndexedMember member) {
543 assert(checkFamily(member)); 589 assert(checkFamily(member));
544 return _memberData[member.memberIndex].node; 590 return _memberData[member.memberIndex].node;
545 } 591 }
546 592
547 ir.Class _getClassNode(covariant IndexedClass cls) { 593 ir.Class _getClassNode(covariant IndexedClass cls) {
548 assert(checkFamily(cls)); 594 assert(checkFamily(cls));
549 return _classEnvs[cls.classIndex].cls; 595 return _classEnvs[cls.classIndex].cls;
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 @override 1971 @override
1926 ir.Member getMemberNode(MemberEntity member) { 1972 ir.Member getMemberNode(MemberEntity member) {
1927 return _getMemberNode(member); 1973 return _getMemberNode(member);
1928 } 1974 }
1929 1975
1930 @override 1976 @override
1931 ir.Class getClassNode(ClassEntity cls) { 1977 ir.Class getClassNode(ClassEntity cls) {
1932 return _getClassNode(cls); 1978 return _getClassNode(cls);
1933 } 1979 }
1934 } 1980 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_model/js_strategy.dart ('k') | pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698