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 mapping that attempts a semantic mapping between | 5 /// Source information system mapping that attempts a semantic mapping between |
6 /// offsets of JavaScript code points to offsets of Dart code points. | 6 /// offsets of JavaScript code points to offsets of Dart code points. |
7 | 7 |
8 library dart2js.source_information.position; | 8 library dart2js.source_information.position; |
9 | 9 |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return _computeText('${closingPosition.sourceUri}'); | 94 return _computeText('${closingPosition.sourceUri}'); |
95 } | 95 } |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 class PositionSourceInformationStrategy | 99 class PositionSourceInformationStrategy |
100 implements JavaScriptSourceInformationStrategy { | 100 implements JavaScriptSourceInformationStrategy { |
101 const PositionSourceInformationStrategy(); | 101 const PositionSourceInformationStrategy(); |
102 | 102 |
103 @override | 103 @override |
104 SourceInformationBuilder createBuilderForContext(AstElement element) { | 104 SourceInformationBuilder createBuilderForContext(ResolvedAst resolvedAst) { |
105 return new PositionSourceInformationBuilder(element); | 105 return new PositionSourceInformationBuilder(resolvedAst); |
106 } | 106 } |
107 | 107 |
108 @override | 108 @override |
109 SourceInformationProcessor createProcessor(SourceMapper mapper) { | 109 SourceInformationProcessor createProcessor(SourceMapper mapper) { |
110 return new PositionSourceInformationProcessor(mapper); | 110 return new PositionSourceInformationProcessor(mapper); |
111 } | 111 } |
112 | 112 |
113 @override | 113 @override |
114 void onComplete() {} | 114 void onComplete() {} |
115 | 115 |
(...skipping 18 matching lines...) Expand all Loading... |
134 List<SourceLocation> get sourceLocations => const <SourceLocation>[]; | 134 List<SourceLocation> get sourceLocations => const <SourceLocation>[]; |
135 | 135 |
136 @override | 136 @override |
137 SourceSpan get sourceSpan => new SourceSpan(null, null, null); | 137 SourceSpan get sourceSpan => new SourceSpan(null, null, null); |
138 } | 138 } |
139 | 139 |
140 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. | 140 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. |
141 class PositionSourceInformationBuilder implements SourceInformationBuilder { | 141 class PositionSourceInformationBuilder implements SourceInformationBuilder { |
142 final SourceFile sourceFile; | 142 final SourceFile sourceFile; |
143 final String name; | 143 final String name; |
144 final AstElement element; | 144 final ResolvedAst resolvedAst; |
145 | 145 |
146 PositionSourceInformationBuilder(AstElement element) | 146 PositionSourceInformationBuilder(ResolvedAst resolvedAst) |
147 : this.element = element, | 147 : this.resolvedAst = resolvedAst, |
148 sourceFile = element.implementation.compilationUnit.script.file, | 148 sourceFile = computeSourceFile(resolvedAst), |
149 name = computeElementNameForSourceMaps(element); | 149 name = computeElementNameForSourceMaps(resolvedAst.element); |
150 | 150 |
151 SourceInformation buildDeclaration(ResolvedAst resolvedAst) { | 151 SourceInformation buildDeclaration(ResolvedAst resolvedAst) { |
152 if (resolvedAst.kind != ResolvedAstKind.PARSED) { | 152 if (resolvedAst.kind != ResolvedAstKind.PARSED) { |
153 SourceSpan span = resolvedAst.element.sourcePosition; | 153 SourceSpan span = resolvedAst.element.sourcePosition; |
154 return new PositionSourceInformation( | 154 return new PositionSourceInformation( |
155 new OffsetSourceLocation(sourceFile, span.begin, name)); | 155 new OffsetSourceLocation(sourceFile, span.begin, name)); |
156 } else { | 156 } else { |
157 return new PositionSourceInformation( | 157 return new PositionSourceInformation( |
158 new OffsetSourceLocation( | 158 new OffsetSourceLocation( |
159 sourceFile, resolvedAst.node.getBeginToken().charOffset, name), | 159 sourceFile, resolvedAst.node.getBeginToken().charOffset, name), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 SourceInformation buildIf(Node node) => buildBegin(node); | 231 SourceInformation buildIf(Node node) => buildBegin(node); |
232 | 232 |
233 @override | 233 @override |
234 SourceInformation buildThrow(Node node) => buildBegin(node); | 234 SourceInformation buildThrow(Node node) => buildBegin(node); |
235 | 235 |
236 @override | 236 @override |
237 SourceInformation buildAssignment(Node node) => buildBegin(node); | 237 SourceInformation buildAssignment(Node node) => buildBegin(node); |
238 | 238 |
239 @override | 239 @override |
240 SourceInformation buildVariableDeclaration() { | 240 SourceInformation buildVariableDeclaration() { |
241 if (element.hasNode) { | 241 if (resolvedAst.kind == ResolvedAstKind.PARSED) { |
242 Node node = element.node; | 242 Node body = resolvedAst.body; |
243 if (node is FunctionExpression) { | 243 if (body != null) { |
244 return buildBegin(node.body); | 244 return buildBegin(body); |
245 } else if (element.isField) { | |
246 FieldElement field = element; | |
247 if (field.initializer != null) { | |
248 return buildBegin(field.initializer); | |
249 } | |
250 } | 245 } |
251 // TODO(johnniwinther): Are there other cases? | 246 // TODO(johnniwinther): Are there other cases? |
252 } | 247 } |
253 return null; | 248 return null; |
254 } | 249 } |
255 | 250 |
256 @override | 251 @override |
257 SourceInformationBuilder forContext(AstElement element) { | 252 SourceInformationBuilder forContext(ResolvedAst resolvedAst) { |
258 return new PositionSourceInformationBuilder(element); | 253 return new PositionSourceInformationBuilder(resolvedAst); |
259 } | 254 } |
260 | 255 |
261 @override | 256 @override |
262 SourceInformation buildForeignCode(Node node) => buildBegin(node); | 257 SourceInformation buildForeignCode(Node node) => buildBegin(node); |
263 | 258 |
264 @override | 259 @override |
265 SourceInformation buildStringInterpolation(Node node) => buildBegin(node); | 260 SourceInformation buildStringInterpolation(Node node) => buildBegin(node); |
266 | 261 |
267 @override | 262 @override |
268 SourceInformation buildForInIterator(Node node) => buildBegin(node); | 263 SourceInformation buildForInIterator(Node node) => buildBegin(node); |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1277 |
1283 @override | 1278 @override |
1284 CodePosition operator [](js.Node node) { | 1279 CodePosition operator [](js.Node node) { |
1285 CodePosition codePosition = codePositions[node]; | 1280 CodePosition codePosition = codePositions[node]; |
1286 if (codePosition == null) { | 1281 if (codePosition == null) { |
1287 coverage.registerNodesWithoutOffset(node); | 1282 coverage.registerNodesWithoutOffset(node); |
1288 } | 1283 } |
1289 return codePosition; | 1284 return codePosition; |
1290 } | 1285 } |
1291 } | 1286 } |
OLD | NEW |