| 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 'package:front_end/src/fasta/scanner.dart' show Token; | 10 import 'package:front_end/src/fasta/scanner.dart' show Token; |
| 11 | 11 |
| 12 import '../common.dart'; | 12 import '../common.dart'; |
| 13 import '../diagnostics/messages.dart' show MessageTemplate; | 13 import '../diagnostics/messages.dart' show MessageTemplate; |
| 14 import '../elements/elements.dart' show ResolvedAst, ResolvedAstKind; | 14 import '../elements/elements.dart' |
| 15 show MemberElement, ResolvedAst, ResolvedAstKind; |
| 15 import '../js/js.dart' as js; | 16 import '../js/js.dart' as js; |
| 16 import '../js/js_source_mapping.dart'; | 17 import '../js/js_source_mapping.dart'; |
| 17 import '../tree/tree.dart' show Node; | 18 import '../tree/tree.dart' show Node; |
| 18 import 'source_file.dart'; | 19 import 'source_file.dart'; |
| 19 import 'source_information.dart'; | 20 import 'source_information.dart'; |
| 20 | 21 |
| 21 /// Source information that contains start source position and optionally an | 22 /// Source information that contains start source position and optionally an |
| 22 /// end source position. | 23 /// end source position. |
| 23 class StartEndSourceInformation extends SourceInformation { | 24 class StartEndSourceInformation extends SourceInformation { |
| 24 @override | 25 @override |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 String toString() { | 106 String toString() { |
| 106 return _computeText('${startPosition.sourceUri}'); | 107 return _computeText('${startPosition.sourceUri}'); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 class StartEndSourceInformationStrategy | 111 class StartEndSourceInformationStrategy |
| 111 extends JavaScriptSourceInformationStrategy { | 112 extends JavaScriptSourceInformationStrategy { |
| 112 const StartEndSourceInformationStrategy(); | 113 const StartEndSourceInformationStrategy(); |
| 113 | 114 |
| 114 @override | 115 @override |
| 115 SourceInformationBuilder createBuilderForContext(ResolvedAst resolvedAst) { | 116 SourceInformationBuilder createBuilderForContext(MemberElement member) { |
| 116 return new StartEndSourceInformationBuilder(resolvedAst); | 117 return new StartEndSourceInformationBuilder(member); |
| 117 } | 118 } |
| 118 | 119 |
| 119 @override | 120 @override |
| 120 SourceInformationProcessor createProcessor( | 121 SourceInformationProcessor createProcessor( |
| 121 SourceMapperProvider provider, SourceInformationReader reader) { | 122 SourceMapperProvider provider, SourceInformationReader reader) { |
| 122 return new StartEndSourceInformationProcessor(provider, reader); | 123 return new StartEndSourceInformationProcessor(provider, reader); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 class StartEndSourceInformationProcessor extends SourceInformationProcessor { | 127 class StartEndSourceInformationProcessor extends SourceInformationProcessor { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 } | 189 } |
| 189 | 190 |
| 190 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. | 191 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. |
| 191 class StartEndSourceInformationBuilder extends SourceInformationBuilder { | 192 class StartEndSourceInformationBuilder extends SourceInformationBuilder { |
| 192 final SourceFile sourceFile; | 193 final SourceFile sourceFile; |
| 193 final String name; | 194 final String name; |
| 194 | 195 |
| 195 StartEndSourceInformationBuilder(ResolvedAst resolvedAst) | 196 StartEndSourceInformationBuilder(MemberElement member) |
| 196 : sourceFile = computeSourceFile(resolvedAst), | 197 : sourceFile = computeSourceFile(member.resolvedAst), |
| 197 name = computeElementNameForSourceMaps(resolvedAst.element); | 198 name = computeElementNameForSourceMaps(member.resolvedAst.element); |
| 198 | 199 |
| 199 SourceInformation buildDeclaration(ResolvedAst resolvedAst) { | 200 SourceInformation buildDeclaration(MemberElement member) { |
| 200 return StartEndSourceInformation._computeSourceInformation(resolvedAst); | 201 return StartEndSourceInformation |
| 202 ._computeSourceInformation(member.resolvedAst); |
| 201 } | 203 } |
| 202 | 204 |
| 203 SourceLocation sourceFileLocationForToken(Token token) { | 205 SourceLocation sourceFileLocationForToken(Token token) { |
| 204 SourceLocation location = | 206 SourceLocation location = |
| 205 new OffsetSourceLocation(sourceFile, token.charOffset, name); | 207 new OffsetSourceLocation(sourceFile, token.charOffset, name); |
| 206 checkValidSourceFileLocation(location, sourceFile, token.charOffset); | 208 checkValidSourceFileLocation(location, sourceFile, token.charOffset); |
| 207 return location; | 209 return location; |
| 208 } | 210 } |
| 209 | 211 |
| 210 void checkValidSourceFileLocation( | 212 void checkValidSourceFileLocation( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 248 |
| 247 @override | 249 @override |
| 248 SourceInformation buildCall(Node receiver, Node call) { | 250 SourceInformation buildCall(Node receiver, Node call) { |
| 249 return buildGeneric(receiver); | 251 return buildGeneric(receiver); |
| 250 } | 252 } |
| 251 | 253 |
| 252 @override | 254 @override |
| 253 SourceInformation buildIf(Node node) => buildGeneric(node); | 255 SourceInformation buildIf(Node node) => buildGeneric(node); |
| 254 | 256 |
| 255 @override | 257 @override |
| 256 SourceInformationBuilder forContext(ResolvedAst resolvedAst, | 258 SourceInformationBuilder forContext(MemberElement member, |
| 257 {SourceInformation sourceInformation}) { | 259 {SourceInformation sourceInformation}) { |
| 258 return new StartEndSourceInformationBuilder(resolvedAst); | 260 return new StartEndSourceInformationBuilder(member); |
| 259 } | 261 } |
| 260 } | 262 } |
| OLD | NEW |