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

Side by Side Diff: pkg/front_end/lib/src/incremental/format.dart

Issue 2936833003: Fix for mismatch between existing FileState data and UnlinkedUnit. (Closed)
Patch Set: Created 3 years, 6 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 | « no previous file | pkg/front_end/test/src/incremental/format_test.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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:typed_data' show Uint8List;
6
5 import 'package:front_end/src/base/flat_buffers.dart' as fb; 7 import 'package:front_end/src/base/flat_buffers.dart' as fb;
6 8
7 /// Unlinked information about a `show` or `hide` combinator in an import or 9 /// Unlinked information about a `show` or `hide` combinator in an import or
8 /// export directive. 10 /// export directive.
9 abstract class UnlinkedCombinator { 11 abstract class UnlinkedCombinator {
10 factory UnlinkedCombinator(List<int> bytes) { 12 factory UnlinkedCombinator(List<int> bytes) {
11 fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); 13 fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
12 return const _UnlinkedCombinatorReader().read(rootRef, 0); 14 return const _UnlinkedCombinatorReader().read(rootRef, 0);
13 } 15 }
14 16
15 /// List of names which are hidden. 17 /// Whether a `show` combinator.
18 bool get isShow;
19
20 /// List of names which are shown or hidden.
16 /// Empty if this is a `show` combinator. 21 /// Empty if this is a `show` combinator.
17 List<String> get hides; 22 List<String> get names;
18
19 /// List of names which are shown.
20 /// Empty if this is a `hide` combinator.
21 List<String> get shows;
22 } 23 }
23 24
24 /// Builder of [UnlinkedCombinator]s. 25 /// Builder of [UnlinkedCombinator]s.
25 class UnlinkedCombinatorBuilder { 26 class UnlinkedCombinatorBuilder {
26 List<String> _shows; 27 final bool _isShow;
27 List<String> _hides; 28 final List<String> _names;
28 29
29 UnlinkedCombinatorBuilder({List<String> shows, List<String> hides}) 30 UnlinkedCombinatorBuilder({bool isShow, List<String> names})
30 : _shows = shows, 31 : _isShow = isShow,
31 _hides = hides; 32 _names = names;
32
33 void set hides(List<String> value) {
34 this._hides = value;
35 }
36
37 void set shows(List<String> value) {
38 this._shows = value;
39 }
40 33
41 /// Finish building, and store into the [fbBuilder]. 34 /// Finish building, and store into the [fbBuilder].
42 fb.Offset finish(fb.Builder fbBuilder) { 35 fb.Offset finish(fb.Builder fbBuilder) {
43 fb.Offset offset_shows; 36 fb.Offset offset_names;
44 fb.Offset offset_hides; 37 if (!(_names == null || _names.isEmpty)) {
45 if (!(_shows == null || _shows.isEmpty)) { 38 offset_names = fbBuilder
46 offset_shows = fbBuilder 39 .writeList(_names.map((b) => fbBuilder.writeString(b)).toList());
47 .writeList(_shows.map((b) => fbBuilder.writeString(b)).toList());
48 }
49 if (!(_hides == null || _hides.isEmpty)) {
50 offset_hides = fbBuilder
51 .writeList(_hides.map((b) => fbBuilder.writeString(b)).toList());
52 } 40 }
53 fbBuilder.startTable(); 41 fbBuilder.startTable();
54 if (offset_shows != null) { 42 if (_isShow == true) {
55 fbBuilder.addOffset(0, offset_shows); 43 fbBuilder.addBool(0, _isShow);
56 } 44 }
57 if (offset_hides != null) { 45 if (offset_names != null) {
58 fbBuilder.addOffset(1, offset_hides); 46 fbBuilder.addOffset(1, offset_names);
59 } 47 }
60 return fbBuilder.endTable(); 48 return fbBuilder.endTable();
61 } 49 }
50
51 Uint8List toBytes() {
52 fb.Builder fbBuilder = new fb.Builder();
53 fb.Offset offset = finish(fbBuilder);
54 return fbBuilder.finish(offset);
55 }
62 } 56 }
63 57
64 /// Unlinked summary information about an import, export or part directive. 58 /// Unlinked summary information about an import, export or part directive.
65 abstract class UnlinkedNamespaceDirective { 59 abstract class UnlinkedNamespaceDirective {
66 factory UnlinkedNamespaceDirective(List<int> bytes) { 60 factory UnlinkedNamespaceDirective(List<int> bytes) {
67 fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); 61 fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
68 return const _UnlinkedNamespaceDirectiveReader().read(rootRef, 0); 62 return const _UnlinkedNamespaceDirectiveReader().read(rootRef, 0);
69 } 63 }
70 64
71 /// Combinators contained in the directive. 65 /// Combinators contained in the directive.
72 List<UnlinkedCombinator> get combinators; 66 List<UnlinkedCombinator> get combinators;
73 67
74 /// URI used in the directive. 68 /// URI used in the directive.
75 String get uri; 69 String get uri;
76 } 70 }
77 71
78 /// Builder of [UnlinkedNamespaceDirective]s. 72 /// Builder of [UnlinkedNamespaceDirective]s.
79 class UnlinkedNamespaceDirectiveBuilder { 73 class UnlinkedNamespaceDirectiveBuilder {
80 String _uri; 74 final String _uri;
81 List<UnlinkedCombinatorBuilder> _combinators; 75 final List<UnlinkedCombinatorBuilder> _combinators;
82 76
83 UnlinkedNamespaceDirectiveBuilder( 77 UnlinkedNamespaceDirectiveBuilder(
84 {String uri, List<UnlinkedCombinatorBuilder> combinators}) 78 {String uri, List<UnlinkedCombinatorBuilder> combinators})
85 : _uri = uri, 79 : _uri = uri,
86 _combinators = combinators; 80 _combinators = combinators;
87 81
88 void set combinators(List<UnlinkedCombinatorBuilder> value) {
89 this._combinators = value;
90 }
91
92 void set uri(String value) {
93 this._uri = value;
94 }
95
96 /// Finish building, and store into the [fbBuilder]. 82 /// Finish building, and store into the [fbBuilder].
97 fb.Offset finish(fb.Builder fbBuilder) { 83 fb.Offset finish(fb.Builder fbBuilder) {
98 fb.Offset offset_uri; 84 fb.Offset offset_uri;
99 fb.Offset offset_combinators; 85 fb.Offset offset_combinators;
100 if (!(_uri == null || _uri.isEmpty)) { 86 if (!(_uri == null || _uri.isEmpty)) {
101 offset_uri = fbBuilder.writeString(_uri); 87 offset_uri = fbBuilder.writeString(_uri);
102 } 88 }
103 if (!(_combinators == null || _combinators.isEmpty)) { 89 if (!(_combinators == null || _combinators.isEmpty)) {
104 offset_combinators = fbBuilder 90 offset_combinators = fbBuilder
105 .writeList(_combinators.map((b) => b.finish(fbBuilder)).toList()); 91 .writeList(_combinators.map((b) => b.finish(fbBuilder)).toList());
106 } 92 }
107 fbBuilder.startTable(); 93 fbBuilder.startTable();
108 fbBuilder.addOffset(0, offset_uri); 94 fbBuilder.addOffset(0, offset_uri);
109 fbBuilder.addOffset(1, offset_combinators); 95 fbBuilder.addOffset(1, offset_combinators);
110 return fbBuilder.endTable(); 96 return fbBuilder.endTable();
111 } 97 }
98
99 Uint8List toBytes() {
100 fb.Builder fbBuilder = new fb.Builder();
101 fb.Offset offset = finish(fbBuilder);
102 return fbBuilder.finish(offset);
103 }
112 } 104 }
113 105
114 abstract class UnlinkedUnit { 106 abstract class UnlinkedUnit {
115 factory UnlinkedUnit(List<int> bytes) { 107 factory UnlinkedUnit(List<int> bytes) {
116 fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes); 108 fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
117 return const _UnlinkedUnitReader().read(rootRef, 0); 109 return const _UnlinkedUnitReader().read(rootRef, 0);
118 } 110 }
119 111
120 /// API signature of the unit. 112 /// API signature of the unit.
121 /// It depends on all non-comment tokens outside the block bodies. 113 /// It depends on all non-comment tokens outside the block bodies.
122 List<int> get apiSignature; 114 List<int> get apiSignature;
123 115
124 /// Export directives in the compilation unit. 116 /// Export directives in the compilation unit.
125 List<UnlinkedNamespaceDirective> get exports; 117 List<UnlinkedNamespaceDirective> get exports;
126 118
127 /// Whether the unit has a mixin application. 119 /// Whether the unit has a mixin application.
128 bool get hasMixinApplication; 120 bool get hasMixinApplication;
129 121
130 /// Import directives in the compilation unit. 122 /// Import directives in the compilation unit.
131 List<UnlinkedNamespaceDirective> get imports; 123 List<UnlinkedNamespaceDirective> get imports;
132 124
133 /// Part directives in the compilation unit. 125 /// URIs of part directives in the compilation unit.
134 List<UnlinkedNamespaceDirective> get parts; 126 List<String> get parts;
135 } 127 }
136 128
137 /// Builder of [UnlinkedUnit]s. 129 /// Builder of [UnlinkedUnit]s.
138 class UnlinkedUnitBuilder { 130 class UnlinkedUnitBuilder {
139 List<int> _apiSignature; 131 final List<int> _apiSignature;
140 List<UnlinkedNamespaceDirectiveBuilder> _imports; 132 final List<UnlinkedNamespaceDirectiveBuilder> _imports;
141 List<UnlinkedNamespaceDirectiveBuilder> _exports; 133 final List<UnlinkedNamespaceDirectiveBuilder> _exports;
142 List<UnlinkedNamespaceDirectiveBuilder> _parts; 134 final List<String> _parts;
143 bool _hasMixinApplication; 135 final bool _hasMixinApplication;
144 136
145 UnlinkedUnitBuilder( 137 UnlinkedUnitBuilder(
146 {List<int> apiSignature, 138 {List<int> apiSignature,
147 List<UnlinkedNamespaceDirectiveBuilder> imports, 139 List<UnlinkedNamespaceDirectiveBuilder> imports,
148 List<UnlinkedNamespaceDirectiveBuilder> exports, 140 List<UnlinkedNamespaceDirectiveBuilder> exports,
149 List<UnlinkedNamespaceDirectiveBuilder> parts, 141 List<String> parts,
150 bool hasMixinApplication}) 142 bool hasMixinApplication})
151 : _apiSignature = apiSignature, 143 : _apiSignature = apiSignature,
152 _imports = imports, 144 _imports = imports,
153 _exports = exports, 145 _exports = exports,
154 _parts = parts, 146 _parts = parts,
155 _hasMixinApplication = hasMixinApplication; 147 _hasMixinApplication = hasMixinApplication;
156 148
157 void set exports(List<UnlinkedNamespaceDirectiveBuilder> value) {
158 this._exports = value;
159 }
160
161 void set hasMixinApplication(bool value) {
162 this._hasMixinApplication = value;
163 }
164
165 void set imports(List<UnlinkedNamespaceDirectiveBuilder> value) {
166 this._imports = value;
167 }
168
169 void set parts(List<UnlinkedNamespaceDirectiveBuilder> value) {
170 this._parts = value;
171 }
172
173 /// Finish building, and store into the [fbBuilder]. 149 /// Finish building, and store into the [fbBuilder].
174 fb.Offset finish(fb.Builder fbBuilder) { 150 fb.Offset finish(fb.Builder fbBuilder) {
175 fb.Offset offset_apiSignature; 151 fb.Offset offset_apiSignature;
176 fb.Offset offset_imports; 152 fb.Offset offset_imports;
177 fb.Offset offset_exports; 153 fb.Offset offset_exports;
178 fb.Offset offset_parts; 154 fb.Offset offset_parts;
179 if (!(_apiSignature == null || _apiSignature.isEmpty)) { 155 if (!(_apiSignature == null || _apiSignature.isEmpty)) {
180 offset_apiSignature = fbBuilder.writeListUint8(_apiSignature); 156 offset_apiSignature = fbBuilder.writeListUint8(_apiSignature);
181 } 157 }
182 if (!(_imports == null || _imports.isEmpty)) { 158 if (!(_imports == null || _imports.isEmpty)) {
183 offset_imports = fbBuilder 159 offset_imports = fbBuilder
184 .writeList(_imports.map((b) => b.finish(fbBuilder)).toList()); 160 .writeList(_imports.map((b) => b.finish(fbBuilder)).toList());
185 } 161 }
186 if (!(_exports == null || _exports.isEmpty)) { 162 if (!(_exports == null || _exports.isEmpty)) {
187 offset_exports = fbBuilder 163 offset_exports = fbBuilder
188 .writeList(_exports.map((b) => b.finish(fbBuilder)).toList()); 164 .writeList(_exports.map((b) => b.finish(fbBuilder)).toList());
189 } 165 }
190 if (!(_parts == null || _parts.isEmpty)) { 166 if (!(_parts == null || _parts.isEmpty)) {
191 offset_parts = 167 offset_parts = fbBuilder
192 fbBuilder.writeList(_parts.map((b) => b.finish(fbBuilder)).toList()); 168 .writeList(_parts.map((b) => fbBuilder.writeString(b)).toList());
193 } 169 }
194 fbBuilder.startTable(); 170 fbBuilder.startTable();
195 if (offset_apiSignature != null) { 171 if (offset_apiSignature != null) {
196 fbBuilder.addOffset(0, offset_apiSignature); 172 fbBuilder.addOffset(0, offset_apiSignature);
197 } 173 }
198 if (offset_imports != null) { 174 if (offset_imports != null) {
199 fbBuilder.addOffset(1, offset_imports); 175 fbBuilder.addOffset(1, offset_imports);
200 } 176 }
201 if (offset_exports != null) { 177 if (offset_exports != null) {
202 fbBuilder.addOffset(2, offset_exports); 178 fbBuilder.addOffset(2, offset_exports);
203 } 179 }
204 if (offset_parts != null) { 180 if (offset_parts != null) {
205 fbBuilder.addOffset(3, offset_parts); 181 fbBuilder.addOffset(3, offset_parts);
206 } 182 }
207 if (_hasMixinApplication == true) { 183 if (_hasMixinApplication == true) {
208 fbBuilder.addBool(4, _hasMixinApplication); 184 fbBuilder.addBool(4, _hasMixinApplication);
209 } 185 }
210 return fbBuilder.endTable(); 186 return fbBuilder.endTable();
211 } 187 }
188
189 Uint8List toBytes() {
190 fb.Builder fbBuilder = new fb.Builder();
191 fb.Offset offset = finish(fbBuilder);
192 return fbBuilder.finish(offset);
193 }
212 } 194 }
213 195
214 class _UnlinkedCombinatorImpl implements UnlinkedCombinator { 196 class _UnlinkedCombinatorImpl implements UnlinkedCombinator {
215 final fb.BufferContext _bc; 197 final fb.BufferContext _bc;
216 final int _bcOffset; 198 final int _bcOffset;
217 199
218 List<String> _shows; 200 bool _isShow;
219 List<String> _hides; 201 List<String> _names;
220 202
221 _UnlinkedCombinatorImpl(this._bc, this._bcOffset); 203 _UnlinkedCombinatorImpl(this._bc, this._bcOffset);
222 204
223 @override 205 @override
224 List<String> get hides { 206 bool get isShow {
225 _hides ??= const fb.ListReader<String>(const fb.StringReader()) 207 _isShow ??= const fb.BoolReader().vTableGet(_bc, _bcOffset, 0, false);
226 .vTableGet(_bc, _bcOffset, 1, const <String>[]); 208 return _isShow;
227 return _hides;
228 } 209 }
229 210
230 @override 211 @override
231 List<String> get shows { 212 List<String> get names {
232 _shows ??= const fb.ListReader<String>(const fb.StringReader()) 213 _names ??= const fb.ListReader<String>(const fb.StringReader())
233 .vTableGet(_bc, _bcOffset, 0, const <String>[]); 214 .vTableGet(_bc, _bcOffset, 1, const <String>[]);
234 return _shows; 215 return _names;
235 } 216 }
236 } 217 }
237 218
238 class _UnlinkedCombinatorReader 219 class _UnlinkedCombinatorReader
239 extends fb.TableReader<_UnlinkedCombinatorImpl> { 220 extends fb.TableReader<_UnlinkedCombinatorImpl> {
240 const _UnlinkedCombinatorReader(); 221 const _UnlinkedCombinatorReader();
241 222
242 @override 223 @override
243 _UnlinkedCombinatorImpl createObject(fb.BufferContext bc, int offset) => 224 _UnlinkedCombinatorImpl createObject(fb.BufferContext bc, int offset) =>
244 new _UnlinkedCombinatorImpl(bc, offset); 225 new _UnlinkedCombinatorImpl(bc, offset);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 new _UnlinkedNamespaceDirectiveImpl(bc, offset); 259 new _UnlinkedNamespaceDirectiveImpl(bc, offset);
279 } 260 }
280 261
281 class _UnlinkedUnitImpl implements UnlinkedUnit { 262 class _UnlinkedUnitImpl implements UnlinkedUnit {
282 final fb.BufferContext _bc; 263 final fb.BufferContext _bc;
283 final int _bcOffset; 264 final int _bcOffset;
284 265
285 List<int> _apiSignature; 266 List<int> _apiSignature;
286 List<UnlinkedNamespaceDirective> _imports; 267 List<UnlinkedNamespaceDirective> _imports;
287 List<UnlinkedNamespaceDirective> _exports; 268 List<UnlinkedNamespaceDirective> _exports;
288 List<UnlinkedNamespaceDirective> _parts; 269 List<String> _parts;
289 bool _hasMixinApplication; 270 bool _hasMixinApplication;
290 271
291 _UnlinkedUnitImpl(this._bc, this._bcOffset); 272 _UnlinkedUnitImpl(this._bc, this._bcOffset);
292 273
293 @override 274 @override
294 List<int> get apiSignature { 275 List<int> get apiSignature {
295 _apiSignature ??= 276 _apiSignature ??=
296 const fb.Uint8ListReader().vTableGet(_bc, _bcOffset, 0, const <int>[]); 277 const fb.Uint8ListReader().vTableGet(_bc, _bcOffset, 0, const <int>[]);
297 return _apiSignature; 278 return _apiSignature;
298 } 279 }
(...skipping 15 matching lines...) Expand all
314 295
315 @override 296 @override
316 List<UnlinkedNamespaceDirective> get imports { 297 List<UnlinkedNamespaceDirective> get imports {
317 _imports ??= const fb.ListReader<UnlinkedNamespaceDirective>( 298 _imports ??= const fb.ListReader<UnlinkedNamespaceDirective>(
318 const _UnlinkedNamespaceDirectiveReader()) 299 const _UnlinkedNamespaceDirectiveReader())
319 .vTableGet(_bc, _bcOffset, 1, const <UnlinkedNamespaceDirective>[]); 300 .vTableGet(_bc, _bcOffset, 1, const <UnlinkedNamespaceDirective>[]);
320 return _imports; 301 return _imports;
321 } 302 }
322 303
323 @override 304 @override
324 List<UnlinkedNamespaceDirective> get parts { 305 List<String> get parts {
325 _parts ??= const fb.ListReader<UnlinkedNamespaceDirective>( 306 _parts ??= const fb.ListReader<String>(const fb.StringReader())
326 const _UnlinkedNamespaceDirectiveReader()) 307 .vTableGet(_bc, _bcOffset, 3, const <String>[]);
327 .vTableGet(_bc, _bcOffset, 3, const <UnlinkedNamespaceDirective>[]);
328 return _parts; 308 return _parts;
329 } 309 }
330 } 310 }
331 311
332 class _UnlinkedUnitReader extends fb.TableReader<UnlinkedUnit> { 312 class _UnlinkedUnitReader extends fb.TableReader<UnlinkedUnit> {
333 const _UnlinkedUnitReader(); 313 const _UnlinkedUnitReader();
334 314
335 @override 315 @override
336 _UnlinkedUnitImpl createObject(fb.BufferContext bc, int offset) => 316 _UnlinkedUnitImpl createObject(fb.BufferContext bc, int offset) =>
337 new _UnlinkedUnitImpl(bc, offset); 317 new _UnlinkedUnitImpl(bc, offset);
338 } 318 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/test/src/incremental/format_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698