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 library dart2js.source_information; | 5 library dart2js.source_information; |
6 | 6 |
7 import '../dart2jslib.dart' show SourceSpan; | 7 import '../dart2jslib.dart' show SourceSpan; |
8 import '../elements/elements.dart' show AstElement; | 8 import '../elements/elements.dart' show AstElement; |
9 import '../scanner/scannerlib.dart' show Token; | 9 import '../scanner/scannerlib.dart' show Token; |
10 import '../tree/tree.dart' show Node; | 10 import '../tree/tree.dart' show Node; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 if (endToken.charOffset < sourceFile.length) { | 88 if (endToken.charOffset < sourceFile.length) { |
89 endSourcePosition = | 89 endSourcePosition = |
90 new TokenSourceLocation(sourceFile, endToken, name); | 90 new TokenSourceLocation(sourceFile, endToken, name); |
91 } | 91 } |
92 return new StartEndSourceInformation(sourcePosition, endSourcePosition); | 92 return new StartEndSourceInformation(sourcePosition, endSourcePosition); |
93 } | 93 } |
94 | 94 |
95 String toString() { | 95 String toString() { |
96 StringBuffer sb = new StringBuffer(); | 96 StringBuffer sb = new StringBuffer(); |
97 sb.write('${startPosition.sourceUri}:'); | 97 sb.write('${startPosition.sourceUri}:'); |
98 sb.write('[${startPosition.line},${startPosition.column}]'); | 98 sb.write('[${startPosition.line + 1},${startPosition.column + 1}]'); |
floitsch
2015/02/24 19:58:12
Is this just to make it easier to reason? That is,
Johnni Winther
2015/03/02 11:48:14
Done.
| |
99 if (endPosition != null) { | 99 if (endPosition != null) { |
100 sb.write('-[${endPosition.line},${endPosition.column}]'); | 100 sb.write('-[${endPosition.line + 1},${endPosition.column + 1}]'); |
101 } | 101 } |
102 return sb.toString(); | 102 return sb.toString(); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 /// [SourceInformation] that consists of an offset position into the source | |
107 /// code. | |
108 class PositionSourceInformation implements SourceInformation { | |
109 final SourceLocation sourcePosition; | |
110 | |
111 PositionSourceInformation(this.sourcePosition); | |
112 | |
113 @override | |
114 void beginMapping(CodeOutput output) { | |
115 output.setSourceLocation(sourcePosition); | |
116 } | |
117 | |
118 @override | |
119 void endMapping(CodeOutput output) { | |
120 // Do nothing. | |
121 } | |
122 | |
123 SourceSpan get sourceSpan { | |
124 Uri uri = sourcePosition.sourceUri; | |
125 int offset = sourcePosition.offset; | |
126 return new SourceSpan(uri, offset, offset); | |
127 } | |
128 | |
129 int get hashCode { | |
130 return sourcePosition.hashCode * 17 & 0x7FFFFFFF; | |
131 } | |
132 | |
133 bool operator ==(other) { | |
134 if (identical(this, other)) return true; | |
135 if (other is! PositionSourceInformation) return false; | |
136 return sourcePosition == other.sourcePosition; | |
137 } | |
138 | |
139 String toString() { | |
140 StringBuffer sb = new StringBuffer(); | |
141 sb.write('${sourcePosition.sourceUri}:'); | |
142 sb.write('[${sourcePosition.line + 1},${sourcePosition.column + 1}]'); | |
143 return sb.toString(); | |
144 } | |
145 } | |
146 | |
106 /// A location in a source file. | 147 /// A location in a source file. |
107 abstract class SourceLocation { | 148 abstract class SourceLocation { |
108 final SourceFile _sourceFile; | 149 final SourceFile _sourceFile; |
109 int _line; | 150 int _line; |
110 | 151 |
111 SourceLocation(this._sourceFile) { | 152 SourceLocation(this._sourceFile) { |
112 assert(isValid); | 153 assert(isValid); |
113 } | 154 } |
114 | 155 |
115 /// The absolute URI of the source file of this source location. | 156 /// The absolute URI of the source file of this source location. |
(...skipping 24 matching lines...) Expand all Loading... | |
140 } | 181 } |
141 | 182 |
142 bool operator ==(other) { | 183 bool operator ==(other) { |
143 if (identical(this, other)) return true; | 184 if (identical(this, other)) return true; |
144 if (other is! SourceLocation) return false; | 185 if (other is! SourceLocation) return false; |
145 return sourceUri == other.sourceUri && | 186 return sourceUri == other.sourceUri && |
146 offset == other.offset && | 187 offset == other.offset && |
147 sourceName == other.sourceName; | 188 sourceName == other.sourceName; |
148 } | 189 } |
149 | 190 |
150 String toString() => '${sourceUri}:[${line},${column}]'; | 191 String toString() => '${sourceUri}:[${line + 1},${column + 1}]'; |
151 } | 192 } |
152 | 193 |
153 class TokenSourceLocation extends SourceLocation { | 194 class TokenSourceLocation extends SourceLocation { |
154 final Token token; | 195 final Token token; |
155 final String sourceName; | 196 final String sourceName; |
156 | 197 |
157 TokenSourceLocation(SourceFile sourceFile, this.token, this.sourceName) | 198 TokenSourceLocation(SourceFile sourceFile, this.token, this.sourceName) |
158 : super(sourceFile); | 199 : super(sourceFile); |
159 | 200 |
160 @override | 201 @override |
161 int get offset => token.charOffset; | 202 int get offset => token.charOffset; |
162 | 203 |
163 String toString() { | 204 String toString() { |
164 return '${super.toString()}:$sourceName'; | 205 return '${super.toString()}:$sourceName'; |
165 } | 206 } |
166 } | 207 } |
OLD | NEW |