OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Source information system that maps spans of Dart AST nodes to spans of | 5 /// Source information system that maps spans of Dart AST nodes to spans of |
6 /// JavaScript nodes. | 6 /// JavaScript nodes. |
7 | 7 |
8 library dart2js.source_information.start_end; | 8 library dart2js.source_information.start_end; |
9 | 9 |
10 import '../common.dart'; | 10 import '../common.dart'; |
11 import '../diagnostics/messages.dart' show MessageTemplate; | 11 import '../diagnostics/messages.dart' show MessageTemplate; |
12 import '../elements/elements.dart' show AstElement, ResolvedAst, ResolvedAstKind
; | 12 import '../elements/elements.dart' |
| 13 show AstElement, ResolvedAst, ResolvedAstKind; |
13 import '../js/js.dart' as js; | 14 import '../js/js.dart' as js; |
14 import '../js/js_source_mapping.dart'; | 15 import '../js/js_source_mapping.dart'; |
15 import '../tokens/token.dart' show Token; | 16 import '../tokens/token.dart' show Token; |
16 import '../tree/tree.dart' show Node; | 17 import '../tree/tree.dart' show Node; |
17 import 'source_file.dart'; | 18 import 'source_file.dart'; |
18 import 'source_information.dart'; | 19 import 'source_information.dart'; |
19 | 20 |
20 /// Source information that contains start source position and optionally an | 21 /// Source information that contains start source position and optionally an |
21 /// end source position. | 22 /// end source position. |
22 class StartEndSourceInformation extends SourceInformation { | 23 class StartEndSourceInformation extends SourceInformation { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 AstElement implementation = resolvedAst.element.implementation; | 74 AstElement implementation = resolvedAst.element.implementation; |
74 sourceFile = implementation.compilationUnit.script.file; | 75 sourceFile = implementation.compilationUnit.script.file; |
75 Node node = resolvedAst.node; | 76 Node node = resolvedAst.node; |
76 begin = node.getBeginToken().charOffset; | 77 begin = node.getBeginToken().charOffset; |
77 end = node.getEndToken().charOffset; | 78 end = node.getEndToken().charOffset; |
78 } | 79 } |
79 // TODO(johnniwinther): find the right sourceFile here and remove offset | 80 // TODO(johnniwinther): find the right sourceFile here and remove offset |
80 // checks below. | 81 // checks below. |
81 SourceLocation sourcePosition, endSourcePosition; | 82 SourceLocation sourcePosition, endSourcePosition; |
82 if (begin < sourceFile.length) { | 83 if (begin < sourceFile.length) { |
83 sourcePosition = | 84 sourcePosition = new OffsetSourceLocation(sourceFile, begin, name); |
84 new OffsetSourceLocation(sourceFile, begin, name); | |
85 } | 85 } |
86 if (end < sourceFile.length) { | 86 if (end < sourceFile.length) { |
87 endSourcePosition = new OffsetSourceLocation(sourceFile, end, name); | 87 endSourcePosition = new OffsetSourceLocation(sourceFile, end, name); |
88 } | 88 } |
89 return new StartEndSourceInformation(sourcePosition, endSourcePosition); | 89 return new StartEndSourceInformation(sourcePosition, endSourcePosition); |
90 } | 90 } |
91 | 91 |
92 /// Create a textual representation of the source information using [uriText] | 92 /// Create a textual representation of the source information using [uriText] |
93 /// as the Uri representation. | 93 /// as the Uri representation. |
94 String _computeText(String uriText) { | 94 String _computeText(String uriText) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 @override | 218 @override |
219 SourceInformation buildIf(Node node) => buildGeneric(node); | 219 SourceInformation buildIf(Node node) => buildGeneric(node); |
220 | 220 |
221 @override | 221 @override |
222 SourceInformationBuilder forContext(AstElement element, | 222 SourceInformationBuilder forContext(AstElement element, |
223 {SourceInformation sourceInformation}) { | 223 {SourceInformation sourceInformation}) { |
224 return new StartEndSourceInformationBuilder(element); | 224 return new StartEndSourceInformationBuilder(element); |
225 } | 225 } |
226 } | 226 } |
OLD | NEW |