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

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

Issue 1081313003: Improve precision of JS printer callbacks (2nd try) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/io/code_output.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 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;
11 import '../js/js.dart' show JavaScriptNodeSourceInformation; 11 import '../js/js.dart' show JavaScriptNodeSourceInformation;
12 import 'code_output.dart';
13 import 'source_file.dart'; 12 import 'source_file.dart';
14 13
15 /// Interface for passing source information, for instance for use in source 14 /// Interface for passing source information, for instance for use in source
16 /// maps, through the backend. 15 /// maps, through the backend.
17 abstract class SourceInformation extends JavaScriptNodeSourceInformation { 16 abstract class SourceInformation extends JavaScriptNodeSourceInformation {
18 SourceSpan get sourceSpan; 17 SourceSpan get sourceSpan;
19 void beginMapping(CodeOutput output); 18
20 void endMapping(CodeOutput output); 19 /// The source location associated with the start of the JS node.
20 SourceLocation get startPosition;
21
22 /// The source location associated with the end of the JS node.
23 SourceLocation get endPosition;
21 } 24 }
22 25
23 /// Source information that contains start source position and optionally an 26 /// Source information that contains start source position and optionally an
24 /// end source position. 27 /// end source position.
25 class StartEndSourceInformation implements SourceInformation { 28 class StartEndSourceInformation implements SourceInformation {
26 final SourceLocation startPosition; 29 final SourceLocation startPosition;
27 final SourceLocation endPosition; 30 final SourceLocation endPosition;
28 31
29 StartEndSourceInformation(this.startPosition, [this.endPosition]); 32 StartEndSourceInformation(this.startPosition, [this.endPosition]);
30 33
31 SourceSpan get sourceSpan { 34 SourceSpan get sourceSpan {
32 Uri uri = startPosition.sourceUri; 35 Uri uri = startPosition.sourceUri;
33 int begin = startPosition.offset; 36 int begin = startPosition.offset;
34 int end = endPosition == null ? begin : endPosition.offset; 37 int end = endPosition == null ? begin : endPosition.offset;
35 return new SourceSpan(uri, begin, end); 38 return new SourceSpan(uri, begin, end);
36 } 39 }
37 40
38 void beginMapping(CodeBuffer output) {
39 output.beginMappedRange();
40 output.setSourceLocation(startPosition);
41 }
42
43 void endMapping(CodeBuffer output) {
44 if (endPosition != null) {
45 output.setSourceLocation(endPosition);
46 }
47 output.endMappedRange();
48 }
49
50 int get hashCode { 41 int get hashCode {
51 return (startPosition.hashCode * 17 + 42 return (startPosition.hashCode * 17 +
52 endPosition.hashCode * 19) 43 endPosition.hashCode * 19)
53 & 0x7FFFFFFF; 44 & 0x7FFFFFFF;
54 } 45 }
55 46
56 bool operator ==(other) { 47 bool operator ==(other) {
57 if (identical(this, other)) return true; 48 if (identical(this, other)) return true;
58 if (other is! StartEndSourceInformation) return false; 49 if (other is! StartEndSourceInformation) return false;
59 return startPosition == other.startPosition && 50 return startPosition == other.startPosition &&
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 95 }
105 } 96 }
106 97
107 /// [SourceInformation] that consists of an offset position into the source 98 /// [SourceInformation] that consists of an offset position into the source
108 /// code. 99 /// code.
109 class PositionSourceInformation implements SourceInformation { 100 class PositionSourceInformation implements SourceInformation {
110 final SourceLocation sourcePosition; 101 final SourceLocation sourcePosition;
111 102
112 PositionSourceInformation(this.sourcePosition); 103 PositionSourceInformation(this.sourcePosition);
113 104
114 @override 105 SourceLocation get startPosition => sourcePosition;
115 void beginMapping(CodeOutput output) { 106 SourceLocation get endPosition => null;
116 output.setSourceLocation(sourcePosition);
117 }
118
119 @override
120 void endMapping(CodeOutput output) {
121 // Do nothing.
122 }
123 107
124 SourceSpan get sourceSpan { 108 SourceSpan get sourceSpan {
125 Uri uri = sourcePosition.sourceUri; 109 Uri uri = sourcePosition.sourceUri;
126 int offset = sourcePosition.offset; 110 int offset = sourcePosition.offset;
127 return new SourceSpan(uri, offset, offset); 111 return new SourceSpan(uri, offset, offset);
128 } 112 }
129 113
130 int get hashCode { 114 int get hashCode {
131 return sourcePosition.hashCode * 17 & 0x7FFFFFFF; 115 return sourcePosition.hashCode * 17 & 0x7FFFFFFF;
132 } 116 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 TokenSourceLocation(SourceFile sourceFile, this.token, this.sourceName) 187 TokenSourceLocation(SourceFile sourceFile, this.token, this.sourceName)
204 : super(sourceFile); 188 : super(sourceFile);
205 189
206 @override 190 @override
207 int get offset => token.charOffset; 191 int get offset => token.charOffset;
208 192
209 String toString() { 193 String toString() {
210 return '${super.toString()}:$sourceName'; 194 return '${super.toString()}:$sourceName';
211 } 195 }
212 } 196 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/io/code_output.dart ('k') | pkg/compiler/lib/src/js/js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698