Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: pkg/compiler/lib/src/io/start_end_information.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/io/source_map_builder.dart ('k') | pkg/compiler/lib/src/js/js.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 import '../diagnostics/messages.dart' show MessageTemplate;
12 MessageTemplate; 12 import '../elements/elements.dart' show AstElement, LocalElement;
13 import '../elements/elements.dart' show
14 AstElement,
15 LocalElement;
16 import '../js/js.dart' as js; 13 import '../js/js.dart' as js;
17 import '../js/js_source_mapping.dart'; 14 import '../js/js_source_mapping.dart';
18 import '../tokens/token.dart' show Token; 15 import '../tokens/token.dart' show Token;
19 import '../tree/tree.dart' show Node, Send; 16 import '../tree/tree.dart' show Node, Send;
20 17
21 import 'source_file.dart'; 18 import 'source_file.dart';
22 import 'source_information.dart'; 19 import 'source_information.dart';
23 20
24 /// Source information that contains start source position and optionally an 21 /// Source information that contains start source position and optionally an
25 /// end source position. 22 /// end source position.
(...skipping 18 matching lines...) Expand all
44 @override 41 @override
45 SourceSpan get sourceSpan { 42 SourceSpan get sourceSpan {
46 Uri uri = startPosition.sourceUri; 43 Uri uri = startPosition.sourceUri;
47 int begin = startPosition.offset; 44 int begin = startPosition.offset;
48 int end = endPosition == null ? begin : endPosition.offset; 45 int end = endPosition == null ? begin : endPosition.offset;
49 return new SourceSpan(uri, begin, end); 46 return new SourceSpan(uri, begin, end);
50 } 47 }
51 48
52 int get hashCode { 49 int get hashCode {
53 return 0x7FFFFFFF & 50 return 0x7FFFFFFF &
54 (startPosition.hashCode * 17 + endPosition.hashCode * 19); 51 (startPosition.hashCode * 17 + endPosition.hashCode * 19);
55 } 52 }
56 53
57 bool operator ==(other) { 54 bool operator ==(other) {
58 if (identical(this, other)) return true; 55 if (identical(this, other)) return true;
59 if (other is! StartEndSourceInformation) return false; 56 if (other is! StartEndSourceInformation) return false;
60 return startPosition == other.startPosition && 57 return startPosition == other.startPosition &&
61 endPosition == other.endPosition; 58 endPosition == other.endPosition;
62 } 59 }
63 60
64 // TODO(johnniwinther): Inline this in 61 // TODO(johnniwinther): Inline this in
65 // [StartEndSourceInformationBuilder.buildDeclaration]. 62 // [StartEndSourceInformationBuilder.buildDeclaration].
66 static StartEndSourceInformation _computeSourceInformation( 63 static StartEndSourceInformation _computeSourceInformation(
67 AstElement element) { 64 AstElement element) {
68
69 AstElement implementation = element.implementation; 65 AstElement implementation = element.implementation;
70 SourceFile sourceFile = implementation.compilationUnit.script.file; 66 SourceFile sourceFile = implementation.compilationUnit.script.file;
71 String name = computeElementNameForSourceMaps(element); 67 String name = computeElementNameForSourceMaps(element);
72 Node node = implementation.node; 68 Node node = implementation.node;
73 Token beginToken; 69 Token beginToken;
74 Token endToken; 70 Token endToken;
75 if (node == null) { 71 if (node == null) {
76 // Synthesized node. Use the enclosing element for the location. 72 // Synthesized node. Use the enclosing element for the location.
77 beginToken = endToken = element.position; 73 beginToken = endToken = element.position;
78 } else { 74 } else {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 class StartEndSourceInformationProcessor extends SourceInformationProcessor { 129 class StartEndSourceInformationProcessor extends SourceInformationProcessor {
134 final SourceMapper sourceMapper; 130 final SourceMapper sourceMapper;
135 131
136 /// Used to track whether a terminating source location marker has been 132 /// Used to track whether a terminating source location marker has been
137 /// registered for the top-most node with source information. 133 /// registered for the top-most node with source information.
138 bool hasRegisteredRoot = false; 134 bool hasRegisteredRoot = false;
139 135
140 StartEndSourceInformationProcessor(this.sourceMapper); 136 StartEndSourceInformationProcessor(this.sourceMapper);
141 137
142 @override 138 @override
143 void onPositions(js.Node node, 139 void onPositions(
144 int startPosition, 140 js.Node node, int startPosition, int endPosition, int closingPosition) {
145 int endPosition,
146 int closingPosition) {
147 if (node.sourceInformation != null) { 141 if (node.sourceInformation != null) {
148 StartEndSourceInformation sourceInformation = node.sourceInformation; 142 StartEndSourceInformation sourceInformation = node.sourceInformation;
149 sourceMapper.register( 143 sourceMapper.register(
150 node, startPosition, sourceInformation.startPosition); 144 node, startPosition, sourceInformation.startPosition);
151 if (sourceInformation.endPosition != null) { 145 if (sourceInformation.endPosition != null) {
152 sourceMapper.register(node, endPosition, sourceInformation.endPosition); 146 sourceMapper.register(node, endPosition, sourceInformation.endPosition);
153 } 147 }
154 if (!hasRegisteredRoot) { 148 if (!hasRegisteredRoot) {
155 sourceMapper.register(node, endPosition, null); 149 sourceMapper.register(node, endPosition, null);
156 hasRegisteredRoot = true; 150 hasRegisteredRoot = true;
(...skipping 19 matching lines...) Expand all
176 SourceLocation location = 170 SourceLocation location =
177 new OffsetSourceLocation(sourceFile, token.charOffset, name); 171 new OffsetSourceLocation(sourceFile, token.charOffset, name);
178 checkValidSourceFileLocation(location, sourceFile, token.charOffset); 172 checkValidSourceFileLocation(location, sourceFile, token.charOffset);
179 return location; 173 return location;
180 } 174 }
181 175
182 void checkValidSourceFileLocation( 176 void checkValidSourceFileLocation(
183 SourceLocation location, SourceFile sourceFile, int offset) { 177 SourceLocation location, SourceFile sourceFile, int offset) {
184 if (!location.isValid) { 178 if (!location.isValid) {
185 throw MessageTemplate.TEMPLATES[MessageKind.INVALID_SOURCE_FILE_LOCATION] 179 throw MessageTemplate.TEMPLATES[MessageKind.INVALID_SOURCE_FILE_LOCATION]
186 .message( 180 .message({
187 {'offset': offset, 181 'offset': offset,
188 'fileName': sourceFile.filename, 182 'fileName': sourceFile.filename,
189 'length': sourceFile.length}); 183 'length': sourceFile.length
184 });
190 } 185 }
191 } 186 }
192 187
193 @override 188 @override
194 SourceInformation buildLoop(Node node) { 189 SourceInformation buildLoop(Node node) {
195 return new StartEndSourceInformation( 190 return new StartEndSourceInformation(
196 sourceFileLocationForToken(node.getBeginToken()), 191 sourceFileLocationForToken(node.getBeginToken()),
197 sourceFileLocationForToken(node.getEndToken())); 192 sourceFileLocationForToken(node.getEndToken()));
198 } 193 }
199 194
(...skipping 17 matching lines...) Expand all
217 212
218 @override 213 @override
219 SourceInformation buildCall(Node receiver, Node call) { 214 SourceInformation buildCall(Node receiver, Node call) {
220 return buildGeneric(receiver); 215 return buildGeneric(receiver);
221 } 216 }
222 217
223 @override 218 @override
224 SourceInformation buildIf(Node node) => buildGeneric(node); 219 SourceInformation buildIf(Node node) => buildGeneric(node);
225 220
226 @override 221 @override
227 SourceInformationBuilder forContext( 222 SourceInformationBuilder forContext(AstElement element,
228 AstElement element, {SourceInformation sourceInformation}) { 223 {SourceInformation sourceInformation}) {
229 return new StartEndSourceInformationBuilder(element); 224 return new StartEndSourceInformationBuilder(element);
230 } 225 }
231 } 226 }
232
233
234
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/io/source_map_builder.dart ('k') | pkg/compiler/lib/src/js/js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698