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

Side by Side Diff: lib/compiler/implementation/code_buffer.dart

Issue 10915122: Fix source locations for inlined and patched functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 3 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 | « no previous file | lib/compiler/implementation/js/printer.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class CodeBuffer implements StringBuffer { 5 class CodeBuffer implements StringBuffer {
6 StringBuffer buffer; 6 StringBuffer buffer;
7 List<SourceLocation> sourceLocations; 7 List<CodeBufferMarker> markers;
8 int lastBufferOffset = 0; 8 int lastBufferOffset = 0;
9 int mappedRangeCounter = 0; 9 int mappedRangeCounter = 0;
10 10
11 CodeBuffer() 11 CodeBuffer()
12 : buffer = new StringBuffer(), 12 : buffer = new StringBuffer(),
13 sourceLocations = new List<SourceLocation>(); 13 markers = new List<CodeBufferMarker>();
14 14
15 int get length => buffer.length; 15 int get length => buffer.length;
16 16
17 bool isEmpty() { 17 bool isEmpty() {
18 return buffer.isEmpty(); 18 return buffer.isEmpty();
19 } 19 }
20 20
21 /** 21 /**
22 * Converts [object] to a string and adds it to the buffer. If [object] is a 22 * Converts [object] to a string and adds it to the buffer. If [object] is a
23 * [CodeBuffer], adds its source locations to [sourceLocations]. 23 * [CodeBuffer], adds its markers to [markers].
24 */ 24 */
25 CodeBuffer add(var object) { 25 CodeBuffer add(var object) {
26 if (object is CodeBuffer) { 26 if (object is CodeBuffer) {
27 return addBuffer(object); 27 return addBuffer(object);
28 } 28 }
29 if (mappedRangeCounter == 0) setSourceLocation(null, null); 29 if (mappedRangeCounter == 0) setSourceLocation(null);
30 buffer.add(object.toString()); 30 buffer.add(object.toString());
31 return this; 31 return this;
32 } 32 }
33 33
34 CodeBuffer addBuffer(CodeBuffer other) { 34 CodeBuffer addBuffer(CodeBuffer other) {
35 if (other.sourceLocations.length > 0) { 35 if (other.markers.length > 0) {
36 SourceLocation firstMapping = other.sourceLocations[0]; 36 CodeBufferMarker firstMarker = other.markers[0];
37 int offsetDelta = 37 int offsetDelta =
38 buffer.length + firstMapping.offsetDelta - lastBufferOffset; 38 buffer.length + firstMarker.offsetDelta - lastBufferOffset;
39 sourceLocations.add(new SourceLocation(firstMapping.element, 39 markers.add(new CodeBufferMarker(offsetDelta,
40 firstMapping.token, 40 firstMarker.sourcePosition));
41 offsetDelta)); 41 for (int i = 1; i < other.markers.length; ++i) {
42 for (int i = 1; i < other.sourceLocations.length; ++i) { 42 markers.add(other.markers[i]);
43 sourceLocations.add(other.sourceLocations[i]);
44 } 43 }
45 lastBufferOffset = buffer.length + other.lastBufferOffset; 44 lastBufferOffset = buffer.length + other.lastBufferOffset;
46 } 45 }
47 buffer.add(other.toString()); 46 buffer.add(other.toString());
48 } 47 }
49 48
50 CodeBuffer addAll(Collection<Object> objects) { 49 CodeBuffer addAll(Collection<Object> objects) {
51 for (Object obj in objects) { 50 for (Object obj in objects) {
52 add(obj); 51 add(obj);
53 } 52 }
54 return this; 53 return this;
55 } 54 }
56 55
57 CodeBuffer addCharCode(int charCode) { 56 CodeBuffer addCharCode(int charCode) {
58 return add(new String.fromCharCodes([charCode])); 57 return add(new String.fromCharCodes([charCode]));
59 } 58 }
60 59
61 CodeBuffer clear() { 60 CodeBuffer clear() {
62 buffer.clear(); 61 buffer.clear();
63 sourceLocations.clear(); 62 markers.clear();
64 lastBufferOffset = 0; 63 lastBufferOffset = 0;
65 return this; 64 return this;
66 } 65 }
67 66
68 String toString() { 67 String toString() {
69 return buffer.toString(); 68 return buffer.toString();
70 } 69 }
71 70
72 void beginMappedRange() { 71 void beginMappedRange() {
73 ++mappedRangeCounter; 72 ++mappedRangeCounter;
74 } 73 }
75 74
76 void endMappedRange() { 75 void endMappedRange() {
77 assert(mappedRangeCounter > 0); 76 assert(mappedRangeCounter > 0);
78 --mappedRangeCounter; 77 --mappedRangeCounter;
79 } 78 }
80 79
81 void setSourceLocation(Element element, Token token) { 80 void setSourceLocation(var sourcePosition) {
82 int offsetDelta = buffer.length - lastBufferOffset; 81 int offsetDelta = buffer.length - lastBufferOffset;
83 sourceLocations.add(new SourceLocation(element, token, offsetDelta)); 82 markers.add(new CodeBufferMarker(offsetDelta, sourcePosition));
84 lastBufferOffset = buffer.length; 83 lastBufferOffset = buffer.length;
85 } 84 }
86 85
87 void forEachSourceLocation(void f(Element element, Token token, int offset)) { 86 void forEachSourceLocation(void f(int targetOffset, var sourcePosition)) {
88 int offset = 0; 87 int targetOffset = 0;
89 sourceLocations.forEach((sourceLocation) { 88 markers.forEach((marker) {
90 offset += sourceLocation.offsetDelta; 89 targetOffset += marker.offsetDelta;
91 f(sourceLocation.element, sourceLocation.token, offset); 90 f(targetOffset, marker.sourcePosition);
92 }); 91 });
93 } 92 }
94 } 93 }
95 94
96 class SourceLocation { 95 class CodeBufferMarker {
97 final Element element;
98 final Token token;
99 final int offsetDelta; 96 final int offsetDelta;
100 SourceLocation(this.element, this.token, this.offsetDelta); 97 final sourcePosition;
98
99 CodeBufferMarker(this.offsetDelta, this.sourcePosition);
101 } 100 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698