| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library validation_input_parser; | 5 library validation_input_parser; |
| 6 | 6 |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 class ValidationParseResult { | 9 class ValidationParseResult { |
| 10 final Iterable<_Entry> _entries; | 10 final Iterable<_Entry> _entries; |
| 11 final int numHandles; | 11 final int numHandles; |
| 12 final ByteData data; | 12 final ByteData data; |
| 13 | 13 |
| 14 ValidationParseResult(this._entries, this.data, this.numHandles); | 14 ValidationParseResult(this._entries, this.data, this.numHandles); |
| 15 | 15 |
| 16 String toString() => _entries.map((e) => '$e').join('\n'); | 16 String toString() => _entries.map((e) => '$e').join('\n'); |
| 17 } | 17 } |
| 18 | 18 |
| 19 ValidationParseResult parse(String input) => | 19 ValidationParseResult parse(String input) => |
| 20 new _ValidationTestParser(input).parse(); | 20 new _ValidationTestParser(input).parse(); |
| 21 | 21 |
| 22 class ValidationParseError { | 22 class ValidationParseError { |
| 23 final String _message; | 23 final String _message; |
| 24 ValidationParseError(this._message); | 24 ValidationParseError(this._message); |
| 25 String toString() => _message; | 25 String toString() => _message; |
| 26 } | 26 } |
| 27 | 27 |
| 28 abstract class _Entry { | 28 abstract class _Entry { |
| 29 final int size; | 29 final int size; |
| 30 _Entry(this.size); |
| 30 void write(ByteData buffer, int offset, Map pointers); | 31 void write(ByteData buffer, int offset, Map pointers); |
| 31 } | 32 } |
| 32 | 33 |
| 33 class _UnsignedEntry implements _Entry { | 34 class _UnsignedEntry implements _Entry { |
| 34 final int size; | 35 final int size; |
| 35 final int value; | 36 final int value; |
| 36 | 37 |
| 37 _UnsignedEntry(this.size, this.value) { | 38 _UnsignedEntry(this.size, this.value) { |
| 38 if ((value >= (1 << (size * 8))) || (value < 0)) { | 39 if ((value >= (1 << (size * 8))) || (value < 0)) { |
| 39 throw new ValidationParseError('$value does not fit in a u$size'); | 40 throw new ValidationParseError('$value does not fit in a u$size'); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 try { | 429 try { |
| 429 var result = parse(input); | 430 var result = parse(input); |
| 430 assert(false); | 431 assert(false); |
| 431 } on ValidationParseError catch(e) { | 432 } on ValidationParseError catch(e) { |
| 432 // Pass. | 433 // Pass. |
| 433 } | 434 } |
| 434 } | 435 } |
| 435 } | 436 } |
| 436 } | 437 } |
| 437 | 438 |
| OLD | NEW |