OLD | NEW |
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 library dart2js.code_output; | 5 library dart2js.code_output; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'source_information.dart'; | 9 import 'source_information.dart'; |
10 | 10 |
11 class CodeOutputMarker { | 11 class CodeOutputMarker { |
12 final int offsetDelta; | 12 final int offsetDelta; |
13 final SourceFileLocation sourcePosition; | 13 final SourceLocation sourcePosition; |
14 | 14 |
15 CodeOutputMarker(this.offsetDelta, this.sourcePosition); | 15 CodeOutputMarker(this.offsetDelta, this.sourcePosition); |
16 } | 16 } |
17 | 17 |
18 abstract class CodeOutputListener { | 18 abstract class CodeOutputListener { |
19 void onText(String text); | 19 void onText(String text); |
20 void onDone(int length); | 20 void onDone(int length); |
21 } | 21 } |
22 | 22 |
23 abstract class CodeOutput { | 23 abstract class CodeOutput { |
(...skipping 12 matching lines...) Expand all Loading... |
36 int get length; | 36 int get length; |
37 | 37 |
38 /// Returns `true` if this output has been closed. | 38 /// Returns `true` if this output has been closed. |
39 bool get isClosed; | 39 bool get isClosed; |
40 | 40 |
41 /// Closes the output. Further writes will cause a [StateError]. | 41 /// Closes the output. Further writes will cause a [StateError]. |
42 void close(); | 42 void close(); |
43 | 43 |
44 /// Applies [f] to every marker in this output. | 44 /// Applies [f] to every marker in this output. |
45 void forEachSourceLocation(void f(int targetOffset, | 45 void forEachSourceLocation(void f(int targetOffset, |
46 SourceFileLocation sourceLocation)); | 46 SourceLocation sourceLocation)); |
47 } | 47 } |
48 | 48 |
49 abstract class AbstractCodeOutput extends CodeOutput { | 49 abstract class AbstractCodeOutput extends CodeOutput { |
50 List<CodeOutputMarker> markers = new List<CodeOutputMarker>(); | 50 List<CodeOutputMarker> markers = new List<CodeOutputMarker>(); |
51 int lastBufferOffset = 0; | 51 int lastBufferOffset = 0; |
52 int mappedRangeCounter = 0; | 52 int mappedRangeCounter = 0; |
53 bool isClosed = false; | 53 bool isClosed = false; |
54 | 54 |
55 void _addInternal(String text); | 55 void _addInternal(String text); |
56 | 56 |
(...skipping 27 matching lines...) Expand all Loading... |
84 | 84 |
85 void beginMappedRange() { | 85 void beginMappedRange() { |
86 ++mappedRangeCounter; | 86 ++mappedRangeCounter; |
87 } | 87 } |
88 | 88 |
89 void endMappedRange() { | 89 void endMappedRange() { |
90 assert(mappedRangeCounter > 0); | 90 assert(mappedRangeCounter > 0); |
91 --mappedRangeCounter; | 91 --mappedRangeCounter; |
92 } | 92 } |
93 | 93 |
94 void setSourceLocation(SourceFileLocation sourcePosition) { | 94 void setSourceLocation(SourceLocation sourcePosition) { |
95 if (sourcePosition == null) { | 95 if (sourcePosition == null) { |
96 if (markers.length > 0 && markers.last.sourcePosition == null) return; | 96 if (markers.length > 0 && markers.last.sourcePosition == null) return; |
97 } | 97 } |
98 int offsetDelta = length - lastBufferOffset; | 98 int offsetDelta = length - lastBufferOffset; |
99 markers.add(new CodeOutputMarker(offsetDelta, sourcePosition)); | 99 markers.add(new CodeOutputMarker(offsetDelta, sourcePosition)); |
100 lastBufferOffset = length; | 100 lastBufferOffset = length; |
101 } | 101 } |
102 | 102 |
103 void forEachSourceLocation(void f(int targetOffset, var sourcePosition)) { | 103 void forEachSourceLocation(void f(int targetOffset, var sourcePosition)) { |
104 int targetOffset = 0; | 104 int targetOffset = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 void close() { | 157 void close() { |
158 output.close(); | 158 output.close(); |
159 super.close(); | 159 super.close(); |
160 if (_listeners != null) { | 160 if (_listeners != null) { |
161 _listeners.forEach((listener) => listener.onDone(length)); | 161 _listeners.forEach((listener) => listener.onDone(length)); |
162 } | 162 } |
163 } | 163 } |
164 } | 164 } |
OLD | NEW |