| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /** | 5 /** |
| 6 * This file contains code to generate serialization/deserialization logic for | 6 * This file contains code to generate serialization/deserialization logic for |
| 7 * summaries based on an "IDL" description of the summary format (written in | 7 * summaries based on an "IDL" description of the summary format (written in |
| 8 * stylized Dart). | 8 * stylized Dart). |
| 9 * | 9 * |
| 10 * For each class in the "IDL" input, two corresponding classes are generated: | 10 * For each class in the "IDL" input, two corresponding classes are generated: |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 String writeCode; | 456 String writeCode; |
| 457 if (fieldType.isList) { | 457 if (fieldType.isList) { |
| 458 condition = ' || $valueName.isEmpty'; | 458 condition = ' || $valueName.isEmpty'; |
| 459 if (_idl.classes.containsKey(fieldType.typeName)) { | 459 if (_idl.classes.containsKey(fieldType.typeName)) { |
| 460 String itemCode = 'b.finish(fbBuilder)'; | 460 String itemCode = 'b.finish(fbBuilder)'; |
| 461 String listCode = '$valueName.map((b) => $itemCode).toList()'; | 461 String listCode = '$valueName.map((b) => $itemCode).toList()'; |
| 462 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; | 462 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; |
| 463 } else if (_idl.enums.containsKey(fieldType.typeName)) { | 463 } else if (_idl.enums.containsKey(fieldType.typeName)) { |
| 464 String itemCode = 'b.index'; | 464 String itemCode = 'b.index'; |
| 465 String listCode = '$valueName.map((b) => $itemCode).toList()'; | 465 String listCode = '$valueName.map((b) => $itemCode).toList()'; |
| 466 writeCode = '$offsetName = fbBuilder.writeListUint32($listCode);'; | 466 writeCode = '$offsetName = fbBuilder.writeListUint8($listCode);'; |
| 467 } else if (fieldType.typeName == 'int') { | 467 } else if (fieldType.typeName == 'int') { |
| 468 writeCode = | 468 writeCode = |
| 469 '$offsetName = fbBuilder.writeListUint32($valueName);'; | 469 '$offsetName = fbBuilder.writeListUint32($valueName);'; |
| 470 } else if (fieldType.typeName == 'double') { | 470 } else if (fieldType.typeName == 'double') { |
| 471 writeCode = | 471 writeCode = |
| 472 '$offsetName = fbBuilder.writeListFloat64($valueName);'; | 472 '$offsetName = fbBuilder.writeListFloat64($valueName);'; |
| 473 } else { | 473 } else { |
| 474 assert(fieldType.typeName == 'String'); | 474 assert(fieldType.typeName == 'String'); |
| 475 String itemCode = 'fbBuilder.writeString(b)'; | 475 String itemCode = 'fbBuilder.writeString(b)'; |
| 476 String listCode = '$valueName.map((b) => $itemCode).toList()'; | 476 String listCode = '$valueName.map((b) => $itemCode).toList()'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 condition = '$offsetName != null'; | 508 condition = '$offsetName != null'; |
| 509 writeCode = 'fbBuilder.addOffset($index, $offsetName);'; | 509 writeCode = 'fbBuilder.addOffset($index, $offsetName);'; |
| 510 } else if (fieldType.typeName == 'bool') { | 510 } else if (fieldType.typeName == 'bool') { |
| 511 condition = '$valueName == true'; | 511 condition = '$valueName == true'; |
| 512 writeCode = 'fbBuilder.addBool($index, true);'; | 512 writeCode = 'fbBuilder.addBool($index, true);'; |
| 513 } else if (fieldType.typeName == 'int') { | 513 } else if (fieldType.typeName == 'int') { |
| 514 condition += ' && $valueName != ${defaultValue(fieldType, true)}'; | 514 condition += ' && $valueName != ${defaultValue(fieldType, true)}'; |
| 515 writeCode = 'fbBuilder.addUint32($index, $valueName);'; | 515 writeCode = 'fbBuilder.addUint32($index, $valueName);'; |
| 516 } else if (_idl.enums.containsKey(fieldType.typeName)) { | 516 } else if (_idl.enums.containsKey(fieldType.typeName)) { |
| 517 condition += ' && $valueName != ${defaultValue(fieldType, true)}'; | 517 condition += ' && $valueName != ${defaultValue(fieldType, true)}'; |
| 518 writeCode = 'fbBuilder.addUint32($index, $valueName.index);'; | 518 writeCode = 'fbBuilder.addUint8($index, $valueName.index);'; |
| 519 } | 519 } |
| 520 if (writeCode == null) { | 520 if (writeCode == null) { |
| 521 throw new UnimplementedError('Writing type ${fieldType.typeName}'); | 521 throw new UnimplementedError('Writing type ${fieldType.typeName}'); |
| 522 } | 522 } |
| 523 out('if ($condition) {'); | 523 out('if ($condition) {'); |
| 524 indent(() { | 524 indent(() { |
| 525 out(writeCode); | 525 out(writeCode); |
| 526 }); | 526 }); |
| 527 out('}'); | 527 out('}'); |
| 528 } | 528 } |
| 529 out('return fbBuilder.endTable();'); | 529 out('return fbBuilder.endTable();'); |
| 530 }); | 530 }); |
| 531 out('}'); | 531 out('}'); |
| 532 }); | 532 }); |
| 533 out('}'); | 533 out('}'); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void _generateEnumReader(idlModel.EnumDeclaration enm) { | 536 void _generateEnumReader(idlModel.EnumDeclaration enm) { |
| 537 String name = enm.name; | 537 String name = enm.name; |
| 538 String readerName = '_${name}Reader'; | 538 String readerName = '_${name}Reader'; |
| 539 out('class $readerName extends fb.Reader<${idlPrefix(name)}> {'); | 539 out('class $readerName extends fb.Reader<${idlPrefix(name)}> {'); |
| 540 indent(() { | 540 indent(() { |
| 541 out('const $readerName() : super();'); | 541 out('const $readerName() : super();'); |
| 542 out(); | 542 out(); |
| 543 out('@override'); | 543 out('@override'); |
| 544 out('int get size => 4;'); | 544 out('int get size => 1;'); |
| 545 out(); | 545 out(); |
| 546 out('@override'); | 546 out('@override'); |
| 547 out('${idlPrefix(name)} read(fb.BufferPointer bp) {'); | 547 out('${idlPrefix(name)} read(fb.BufferPointer bp) {'); |
| 548 indent(() { | 548 indent(() { |
| 549 out('int index = const fb.Uint32Reader().read(bp);'); | 549 out('int index = const fb.Uint8Reader().read(bp);'); |
| 550 out('return ${idlPrefix(name)}.values[index];'); | 550 out('return ${idlPrefix(name)}.values[index];'); |
| 551 }); | 551 }); |
| 552 out('}'); | 552 out('}'); |
| 553 }); | 553 }); |
| 554 out('}'); | 554 out('}'); |
| 555 } | 555 } |
| 556 | 556 |
| 557 void _generateImpl(idlModel.ClassDeclaration cls) { | 557 void _generateImpl(idlModel.ClassDeclaration cls) { |
| 558 String name = cls.name; | 558 String name = cls.name; |
| 559 String implName = '_${name}Impl'; | 559 String implName = '_${name}Impl'; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 return token.lexeme.split('\n').map((String line) { | 683 return token.lexeme.split('\n').map((String line) { |
| 684 if (line.startsWith(indent)) { | 684 if (line.startsWith(indent)) { |
| 685 line = line.substring(indent.length); | 685 line = line.substring(indent.length); |
| 686 } | 686 } |
| 687 return line; | 687 return line; |
| 688 }).join('\n'); | 688 }).join('\n'); |
| 689 } | 689 } |
| 690 return null; | 690 return null; |
| 691 } | 691 } |
| 692 } | 692 } |
| OLD | NEW |