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

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

Issue 12296011: Version 0.3.7.4 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 10 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
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 part of dart2js; 5 part of dart2js;
6 6
7 class CodeBuffer implements StringBuffer { 7 class CodeBuffer implements StringBuffer {
8 StringBuffer buffer; 8 StringBuffer buffer;
9 List<CodeBufferMarker> markers; 9 List<CodeBufferMarker> markers;
10 int lastBufferOffset = 0; 10 int lastBufferOffset = 0;
11 int mappedRangeCounter = 0; 11 int mappedRangeCounter = 0;
12 12
13 CodeBuffer() 13 CodeBuffer()
14 : buffer = new StringBuffer(), 14 : buffer = new StringBuffer(),
15 markers = new List<CodeBufferMarker>(); 15 markers = new List<CodeBufferMarker>();
16 16
17 int get length => buffer.length; 17 int get length => buffer.length;
18 18
19 bool get isEmpty { 19 bool get isEmpty {
20 return buffer.isEmpty; 20 return buffer.isEmpty;
21 } 21 }
22 22
23 CodeBuffer add(var object) {
24 write(object);
25 return this;
26 }
23 /** 27 /**
24 * Converts [object] to a string and adds it to the buffer. If [object] is a 28 * Converts [object] to a string and adds it to the buffer. If [object] is a
25 * [CodeBuffer], adds its markers to [markers]. 29 * [CodeBuffer], adds its markers to [markers].
26 */ 30 */
27 CodeBuffer add(var object) { 31 CodeBuffer write(var object) {
28 if (object is CodeBuffer) { 32 if (object is CodeBuffer) {
29 return addBuffer(object); 33 return addBuffer(object);
30 } 34 }
31 if (mappedRangeCounter == 0) setSourceLocation(null); 35 if (mappedRangeCounter == 0) setSourceLocation(null);
32 buffer.add(object.toString()); 36 buffer.add(object.toString());
33 return this; 37 return this;
34 } 38 }
35 39
40 CodeBuffer writeAll(Iterable<Object> objects) {
41 for (var object in objects) {
42 write(object);
43 }
44 return this;
45 }
46
47 CodeBuffer writeln(var object) {
48 return write(object).write("\n");
49 }
50
36 CodeBuffer addBuffer(CodeBuffer other) { 51 CodeBuffer addBuffer(CodeBuffer other) {
37 if (other.markers.length > 0) { 52 if (other.markers.length > 0) {
38 CodeBufferMarker firstMarker = other.markers[0]; 53 CodeBufferMarker firstMarker = other.markers[0];
39 int offsetDelta = 54 int offsetDelta =
40 buffer.length + firstMarker.offsetDelta - lastBufferOffset; 55 buffer.length + firstMarker.offsetDelta - lastBufferOffset;
41 markers.add(new CodeBufferMarker(offsetDelta, 56 markers.add(new CodeBufferMarker(offsetDelta,
42 firstMarker.sourcePosition)); 57 firstMarker.sourcePosition));
43 for (int i = 1; i < other.markers.length; ++i) { 58 for (int i = 1; i < other.markers.length; ++i) {
44 markers.add(other.markers[i]); 59 markers.add(other.markers[i]);
45 } 60 }
46 lastBufferOffset = buffer.length + other.lastBufferOffset; 61 lastBufferOffset = buffer.length + other.lastBufferOffset;
47 } 62 }
48 buffer.add(other.getText()); 63 buffer.add(other.getText());
49 }
50
51 CodeBuffer addAll(Iterable<Object> iterable) {
52 for (Object obj in iterable) {
53 add(obj);
54 }
55 return this; 64 return this;
56 } 65 }
57 66
58 CodeBuffer addCharCode(int charCode) { 67 CodeBuffer addAll(Iterable<Object> iterable) => writeAll(iterable);
59 return add(new String.fromCharCodes([charCode])); 68
69 CodeBuffer addCharCode(int charCode) => writeCharCode(charCode);
70
71 CodeBuffer writeCharCode(int charCode) {
72 return write(new String.fromCharCodes([charCode]));
60 } 73 }
61 74
62 CodeBuffer clear() { 75 CodeBuffer clear() {
63 buffer.clear(); 76 buffer.clear();
64 markers.clear(); 77 markers.clear();
65 lastBufferOffset = 0; 78 lastBufferOffset = 0;
66 return this; 79 return this;
67 } 80 }
68 81
69 String toString() { 82 String toString() {
(...skipping 27 matching lines...) Expand all
97 }); 110 });
98 } 111 }
99 } 112 }
100 113
101 class CodeBufferMarker { 114 class CodeBufferMarker {
102 final int offsetDelta; 115 final int offsetDelta;
103 final sourcePosition; 116 final sourcePosition;
104 117
105 CodeBufferMarker(this.offsetDelta, this.sourcePosition); 118 CodeBufferMarker(this.offsetDelta, this.sourcePosition);
106 } 119 }
OLDNEW
« no previous file with comments | « dart/sdk/lib/_collection_dev/list.dart ('k') | dart/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698