| 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'; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 if (other is! StartEndSourceInformation) return false; | 56 if (other is! StartEndSourceInformation) return false; |
| 57 return startPosition == other.startPosition && | 57 return startPosition == other.startPosition && |
| 58 endPosition == other.endPosition; | 58 endPosition == other.endPosition; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // TODO(johnniwinther): Inline this in | 61 // TODO(johnniwinther): Inline this in |
| 62 // [StartEndSourceInformationBuilder.buildDeclaration]. | 62 // [StartEndSourceInformationBuilder.buildDeclaration]. |
| 63 static StartEndSourceInformation _computeSourceInformation( | 63 static StartEndSourceInformation _computeSourceInformation( |
| 64 ResolvedAst resolvedAst) { | 64 ResolvedAst resolvedAst) { |
| 65 String name = computeElementNameForSourceMaps(resolvedAst.element); | 65 String name = computeElementNameForSourceMaps(resolvedAst.element); |
| 66 SourceFile sourceFile; | 66 SourceFile sourceFile = computeSourceFile(resolvedAst); |
| 67 int begin; | 67 int begin; |
| 68 int end; | 68 int end; |
| 69 if (resolvedAst.kind != ResolvedAstKind.PARSED) { | 69 if (resolvedAst.kind != ResolvedAstKind.PARSED) { |
| 70 // Synthesized node. Use the enclosing element for the location. | 70 // Synthesized node. Use the enclosing element for the location. |
| 71 sourceFile = resolvedAst.element.compilationUnit.script.file; | |
| 72 begin = end = resolvedAst.element.sourcePosition.begin; | 71 begin = end = resolvedAst.element.sourcePosition.begin; |
| 73 } else { | 72 } else { |
| 74 AstElement implementation = resolvedAst.element.implementation; | |
| 75 sourceFile = implementation.compilationUnit.script.file; | |
| 76 Node node = resolvedAst.node; | 73 Node node = resolvedAst.node; |
| 77 begin = node.getBeginToken().charOffset; | 74 begin = node.getBeginToken().charOffset; |
| 78 end = node.getEndToken().charOffset; | 75 end = node.getEndToken().charOffset; |
| 79 } | 76 } |
| 80 // TODO(johnniwinther): find the right sourceFile here and remove offset | 77 // TODO(johnniwinther): find the right sourceFile here and remove offset |
| 81 // checks below. | 78 // checks below. |
| 82 SourceLocation sourcePosition, endSourcePosition; | 79 SourceLocation sourcePosition, endSourcePosition; |
| 83 if (begin < sourceFile.length) { | 80 if (begin < sourceFile.length) { |
| 84 sourcePosition = new OffsetSourceLocation(sourceFile, begin, name); | 81 sourcePosition = new OffsetSourceLocation(sourceFile, begin, name); |
| 85 } | 82 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 109 String toString() { | 106 String toString() { |
| 110 return _computeText('${startPosition.sourceUri}'); | 107 return _computeText('${startPosition.sourceUri}'); |
| 111 } | 108 } |
| 112 } | 109 } |
| 113 | 110 |
| 114 class StartEndSourceInformationStrategy | 111 class StartEndSourceInformationStrategy |
| 115 extends JavaScriptSourceInformationStrategy { | 112 extends JavaScriptSourceInformationStrategy { |
| 116 const StartEndSourceInformationStrategy(); | 113 const StartEndSourceInformationStrategy(); |
| 117 | 114 |
| 118 @override | 115 @override |
| 119 SourceInformationBuilder createBuilderForContext(AstElement element) { | 116 SourceInformationBuilder createBuilderForContext(ResolvedAst resolvedAst) { |
| 120 return new StartEndSourceInformationBuilder(element); | 117 return new StartEndSourceInformationBuilder(resolvedAst); |
| 121 } | 118 } |
| 122 | 119 |
| 123 @override | 120 @override |
| 124 SourceInformationProcessor createProcessor(SourceMapper sourceMapper) { | 121 SourceInformationProcessor createProcessor(SourceMapper sourceMapper) { |
| 125 return new StartEndSourceInformationProcessor(sourceMapper); | 122 return new StartEndSourceInformationProcessor(sourceMapper); |
| 126 } | 123 } |
| 127 } | 124 } |
| 128 | 125 |
| 129 class StartEndSourceInformationProcessor extends SourceInformationProcessor { | 126 class StartEndSourceInformationProcessor extends SourceInformationProcessor { |
| 130 final SourceMapper sourceMapper; | 127 final SourceMapper sourceMapper; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 151 } | 148 } |
| 152 } | 149 } |
| 153 } | 150 } |
| 154 } | 151 } |
| 155 | 152 |
| 156 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. | 153 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. |
| 157 class StartEndSourceInformationBuilder extends SourceInformationBuilder { | 154 class StartEndSourceInformationBuilder extends SourceInformationBuilder { |
| 158 final SourceFile sourceFile; | 155 final SourceFile sourceFile; |
| 159 final String name; | 156 final String name; |
| 160 | 157 |
| 161 StartEndSourceInformationBuilder(AstElement element) | 158 StartEndSourceInformationBuilder(ResolvedAst resolvedAst) |
| 162 : sourceFile = element.compilationUnit.script.file, | 159 : sourceFile = computeSourceFile(resolvedAst), |
| 163 name = computeElementNameForSourceMaps(element); | 160 name = computeElementNameForSourceMaps(resolvedAst.element); |
| 164 | 161 |
| 165 SourceInformation buildDeclaration(ResolvedAst resolvedAst) { | 162 SourceInformation buildDeclaration(ResolvedAst resolvedAst) { |
| 166 return StartEndSourceInformation._computeSourceInformation(resolvedAst); | 163 return StartEndSourceInformation._computeSourceInformation(resolvedAst); |
| 167 } | 164 } |
| 168 | 165 |
| 169 SourceLocation sourceFileLocationForToken(Token token) { | 166 SourceLocation sourceFileLocationForToken(Token token) { |
| 170 SourceLocation location = | 167 SourceLocation location = |
| 171 new OffsetSourceLocation(sourceFile, token.charOffset, name); | 168 new OffsetSourceLocation(sourceFile, token.charOffset, name); |
| 172 checkValidSourceFileLocation(location, sourceFile, token.charOffset); | 169 checkValidSourceFileLocation(location, sourceFile, token.charOffset); |
| 173 return location; | 170 return location; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 209 |
| 213 @override | 210 @override |
| 214 SourceInformation buildCall(Node receiver, Node call) { | 211 SourceInformation buildCall(Node receiver, Node call) { |
| 215 return buildGeneric(receiver); | 212 return buildGeneric(receiver); |
| 216 } | 213 } |
| 217 | 214 |
| 218 @override | 215 @override |
| 219 SourceInformation buildIf(Node node) => buildGeneric(node); | 216 SourceInformation buildIf(Node node) => buildGeneric(node); |
| 220 | 217 |
| 221 @override | 218 @override |
| 222 SourceInformationBuilder forContext(AstElement element, | 219 SourceInformationBuilder forContext(ResolvedAst resolvedAst, |
| 223 {SourceInformation sourceInformation}) { | 220 {SourceInformation sourceInformation}) { |
| 224 return new StartEndSourceInformationBuilder(element); | 221 return new StartEndSourceInformationBuilder(resolvedAst); |
| 225 } | 222 } |
| 226 } | 223 } |
| OLD | NEW |