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

Side by Side Diff: pkg/analyzer/lib/src/summary/flat_buffers.dart

Issue 1571593002: Support for Int64 and fix for the root reference. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/analyzer/test/src/summary/flat_buffers_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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer.src.summary.flat_buffers; 5 library analyzer.src.summary.flat_buffers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:typed_data'; 9 import 'dart:typed_data';
10 10
(...skipping 20 matching lines...) Expand all
31 @override 31 @override
32 String toString() => _offset.toString(); 32 String toString() => _offset.toString();
33 33
34 BufferPointer _advance(int delta) { 34 BufferPointer _advance(int delta) {
35 return new BufferPointer._(_buffer, _offset + delta); 35 return new BufferPointer._(_buffer, _offset + delta);
36 } 36 }
37 37
38 int _getInt32([int delta = 0]) => 38 int _getInt32([int delta = 0]) =>
39 _buffer.getInt32(_offset + delta, Endianness.LITTLE_ENDIAN); 39 _buffer.getInt32(_offset + delta, Endianness.LITTLE_ENDIAN);
40 40
41 int _getInt64([int delta = 0]) =>
42 _buffer.getInt64(_offset + delta, Endianness.LITTLE_ENDIAN);
43
41 int _getInt8([int delta = 0]) => _buffer.getInt8(_offset + delta); 44 int _getInt8([int delta = 0]) => _buffer.getInt8(_offset + delta);
42 45
43 int _getUint16([int delta = 0]) => 46 int _getUint16([int delta = 0]) =>
44 _buffer.getUint16(_offset + delta, Endianness.LITTLE_ENDIAN); 47 _buffer.getUint16(_offset + delta, Endianness.LITTLE_ENDIAN);
45 48
46 int _getUint32([int delta = 0]) => 49 int _getUint32([int delta = 0]) =>
47 _buffer.getUint32(_offset + delta, Endianness.LITTLE_ENDIAN); 50 _buffer.getUint32(_offset + delta, Endianness.LITTLE_ENDIAN);
48 51
49 /** 52 /**
50 * If the [byteList] is already a [Uint8List] return it. 53 * If the [byteList] is already a [Uint8List] return it.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 105 }
103 if (value != def) { 106 if (value != def) {
104 int size = 4; 107 int size = 4;
105 _prepare(size, 1); 108 _prepare(size, 1);
106 _trackField(field); 109 _trackField(field);
107 _setInt32AtTail(_buf, _tail, value); 110 _setInt32AtTail(_buf, _tail, value);
108 } 111 }
109 } 112 }
110 113
111 /** 114 /**
115 * Add the [field] with the given 64-bit signed integer [value]. The field is
116 * not added if the [value] is equal to [def].
117 */
118 void addInt64(int field, int value, [int def]) {
119 if (_currentVTableBuilder == null) {
120 throw new StateError('Start a table before adding values.');
121 }
122 if (value != def) {
123 int size = 8;
124 _prepare(size, 1);
125 _trackField(field);
126 _setInt64AtTail(_buf, _tail, value);
127 }
128 }
129
130 /**
112 * Add the [field] with the given 8-bit signed integer [value]. The field is 131 * Add the [field] with the given 8-bit signed integer [value]. The field is
113 * not added if the [value] is equal to [def]. 132 * not added if the [value] is equal to [def].
114 */ 133 */
115 void addInt8(int field, int value, [int def]) { 134 void addInt8(int field, int value, [int def]) {
116 if (_currentVTableBuilder == null) { 135 if (_currentVTableBuilder == null) {
117 throw new StateError('Start a table before adding values.'); 136 throw new StateError('Start a table before adding values.');
118 } 137 }
119 if (value != def) { 138 if (value != def) {
120 int size = 1; 139 int size = 1;
121 _prepare(size, 1); 140 _prepare(size, 1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return new Offset(tableTail); 181 return new Offset(tableTail);
163 } 182 }
164 183
165 /** 184 /**
166 * Finish off the creation of the buffer. The given [offset] is used as the 185 * Finish off the creation of the buffer. The given [offset] is used as the
167 * root object offset, and usually references directly or indirectly every 186 * root object offset, and usually references directly or indirectly every
168 * written object. 187 * written object.
169 */ 188 */
170 Uint8List finish(Offset offset) { 189 Uint8List finish(Offset offset) {
171 _prepare(4, 1); 190 _prepare(4, 1);
172 _setUint32AtTail(_buf, _tail, _tail - offset._tail);
173 int alignedTail = _tail + ((-_tail) % _maxAlign); 191 int alignedTail = _tail + ((-_tail) % _maxAlign);
192 _setUint32AtTail(_buf, alignedTail, alignedTail - offset._tail);
Paul Berry 2016/01/08 18:11:18 This won't work either. Consider the case where _
scheglov 2016/01/08 18:39:07 Done.
174 return _buf.buffer.asUint8List(_buf.lengthInBytes - alignedTail); 193 return _buf.buffer.asUint8List(_buf.lengthInBytes - alignedTail);
175 } 194 }
176 195
177 /** 196 /**
178 * This is a low-level method, it should not be invoked by clients. 197 * This is a low-level method, it should not be invoked by clients.
179 */ 198 */
180 Uint8List lowFinish() { 199 Uint8List lowFinish() {
181 int alignedTail = _tail + ((-_tail) % _maxAlign); 200 int alignedTail = _tail + ((-_tail) % _maxAlign);
182 return _buf.buffer.asUint8List(_buf.lengthInBytes - alignedTail); 201 return _buf.buffer.asUint8List(_buf.lengthInBytes - alignedTail);
183 } 202 }
(...skipping 11 matching lines...) Expand all
195 * This is a low-level method, it should not be invoked by clients. 214 * This is a low-level method, it should not be invoked by clients.
196 */ 215 */
197 void lowWriteUint32(int value) { 216 void lowWriteUint32(int value) {
198 _prepare(4, 1); 217 _prepare(4, 1);
199 _setUint32AtTail(_buf, _tail, value); 218 _setUint32AtTail(_buf, _tail, value);
200 } 219 }
201 220
202 /** 221 /**
203 * This is a low-level method, it should not be invoked by clients. 222 * This is a low-level method, it should not be invoked by clients.
204 */ 223 */
224 void lowWriteUint64(int value) {
225 _prepare(8, 1);
226 _setUint64AtTail(_buf, _tail, value);
227 }
228
229 /**
230 * This is a low-level method, it should not be invoked by clients.
231 */
205 void lowWriteUint8(int value) { 232 void lowWriteUint8(int value) {
206 _prepare(1, 1); 233 _prepare(1, 1);
207 _buf.setUint8(_buf.lengthInBytes - _tail, value); 234 _buf.setUint8(_buf.lengthInBytes - _tail, value);
208 } 235 }
209 236
210 /** 237 /**
211 * Reset the builder and make it ready for filling a new buffer. 238 * Reset the builder and make it ready for filling a new buffer.
212 */ 239 */
213 void reset() { 240 void reset() {
214 _buf = new ByteData(initialSize); 241 _buf = new ByteData(initialSize);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 * Record the offset of the given [field]. 337 * Record the offset of the given [field].
311 */ 338 */
312 void _trackField(int field) { 339 void _trackField(int field) {
313 _currentVTableBuilder.addField(field, _tail); 340 _currentVTableBuilder.addField(field, _tail);
314 } 341 }
315 342
316 static void _setInt32AtTail(ByteData _buf, int tail, int x) { 343 static void _setInt32AtTail(ByteData _buf, int tail, int x) {
317 _buf.setInt32(_buf.lengthInBytes - tail, x, Endianness.LITTLE_ENDIAN); 344 _buf.setInt32(_buf.lengthInBytes - tail, x, Endianness.LITTLE_ENDIAN);
318 } 345 }
319 346
347 static void _setInt64AtTail(ByteData _buf, int tail, int x) {
348 _buf.setInt64(_buf.lengthInBytes - tail, x, Endianness.LITTLE_ENDIAN);
349 }
350
320 static void _setUint32AtTail(ByteData _buf, int tail, int x) { 351 static void _setUint32AtTail(ByteData _buf, int tail, int x) {
321 _buf.setUint32(_buf.lengthInBytes - tail, x, Endianness.LITTLE_ENDIAN); 352 _buf.setUint32(_buf.lengthInBytes - tail, x, Endianness.LITTLE_ENDIAN);
322 } 353 }
354
355 static void _setUint64AtTail(ByteData _buf, int tail, int x) {
356 _buf.setUint64(_buf.lengthInBytes - tail, x, Endianness.LITTLE_ENDIAN);
357 }
323 } 358 }
324 359
325 /** 360 /**
326 * The reader of 32-bit signed integers. 361 * The reader of 32-bit signed integers.
327 */ 362 */
328 class Int32Reader extends Reader<int> { 363 class Int32Reader extends Reader<int> {
329 const Int32Reader() : super(); 364 const Int32Reader() : super();
330 365
331 @override 366 @override
332 int get size => 2; 367 int get size => 4;
333 368
334 @override 369 @override
335 int read(BufferPointer bp) => bp._getInt32(); 370 int read(BufferPointer bp) => bp._getInt32();
336 } 371 }
337 372
338 /** 373 /**
374 * The reader of 64-bit signed integers.
375 */
376 class Int64Reader extends Reader<int> {
377 const Int64Reader() : super();
378
379 @override
380 int get size => 8;
381
382 @override
383 int read(BufferPointer bp) => bp._getInt64();
384 }
385
386 /**
339 * The reader of 8-bit signed integers. 387 * The reader of 8-bit signed integers.
340 */ 388 */
341 class Int8Reader extends Reader<int> { 389 class Int8Reader extends Reader<int> {
342 const Int8Reader() : super(); 390 const Int8Reader() : super();
343 391
344 @override 392 @override
345 int get size => 1; 393 int get size => 1;
346 394
347 @override 395 @override
348 int read(BufferPointer bp) => bp._getInt8(); 396 int read(BufferPointer bp) => bp._getInt8();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); 548 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN);
501 bufOffset += 2; 549 bufOffset += 2;
502 // Field offsets. 550 // Field offsets.
503 for (int fieldTail in fieldTails) { 551 for (int fieldTail in fieldTails) {
504 int fieldOffset = fieldTail == null ? 0 : tableTail - fieldTail; 552 int fieldOffset = fieldTail == null ? 0 : tableTail - fieldTail;
505 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); 553 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN);
506 bufOffset += 2; 554 bufOffset += 2;
507 } 555 }
508 } 556 }
509 } 557 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698