| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 * [extractIdl]). | 81 * [extractIdl]). |
| 82 */ | 82 */ |
| 83 void checkIdl() { | 83 void checkIdl() { |
| 84 _idl.classes.forEach((String name, idlModel.ClassDeclaration cls) { | 84 _idl.classes.forEach((String name, idlModel.ClassDeclaration cls) { |
| 85 for (idlModel.FieldDeclaration field in cls.fields) { | 85 for (idlModel.FieldDeclaration field in cls.fields) { |
| 86 String fieldName = field.name; | 86 String fieldName = field.name; |
| 87 idlModel.FieldType type = field.type; | 87 idlModel.FieldType type = field.type; |
| 88 if (type.isList) { | 88 if (type.isList) { |
| 89 if (_idl.classes.containsKey(type.typeName)) { | 89 if (_idl.classes.containsKey(type.typeName)) { |
| 90 // List of classes is ok | 90 // List of classes is ok |
| 91 } else if (_idl.enums.containsKey(type.typeName)) { |
| 92 // List of enums is ok |
| 91 } else if (type.typeName == 'int') { | 93 } else if (type.typeName == 'int') { |
| 92 // List of ints is ok | 94 // List of ints is ok |
| 95 } else if (type.typeName == 'double') { |
| 96 // List of doubles is ok |
| 93 } else if (type.typeName == 'String') { | 97 } else if (type.typeName == 'String') { |
| 94 // List of strings is ok | 98 // List of strings is ok |
| 95 } else { | 99 } else { |
| 96 throw new Exception( | 100 throw new Exception( |
| 97 '$name.$fieldName: illegal type (list of ${type.typeName})'); | 101 '$name.$fieldName: illegal type (list of ${type.typeName})'); |
| 98 } | 102 } |
| 99 } | 103 } |
| 100 } | 104 } |
| 101 }); | 105 }); |
| 102 } | 106 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 String valueName = '_' + field.name; | 368 String valueName = '_' + field.name; |
| 365 String offsetName = 'offset_' + field.name; | 369 String offsetName = 'offset_' + field.name; |
| 366 String condition; | 370 String condition; |
| 367 String writeCode; | 371 String writeCode; |
| 368 if (fieldType.isList) { | 372 if (fieldType.isList) { |
| 369 condition = ' || $valueName.isEmpty'; | 373 condition = ' || $valueName.isEmpty'; |
| 370 if (_idl.classes.containsKey(fieldType.typeName)) { | 374 if (_idl.classes.containsKey(fieldType.typeName)) { |
| 371 String itemCode = 'b.finish(fbBuilder)'; | 375 String itemCode = 'b.finish(fbBuilder)'; |
| 372 String listCode = '$valueName.map((b) => $itemCode).toList()'; | 376 String listCode = '$valueName.map((b) => $itemCode).toList()'; |
| 373 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; | 377 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; |
| 378 } else if (_idl.enums.containsKey(fieldType.typeName)) { |
| 379 String itemCode = 'b.index'; |
| 380 String listCode = '$valueName.map((b) => $itemCode).toList()'; |
| 381 writeCode = '$offsetName = fbBuilder.writeListInt32($listCode);'; |
| 374 } else if (fieldType.typeName == 'int') { | 382 } else if (fieldType.typeName == 'int') { |
| 375 writeCode = '$offsetName = fbBuilder.writeListInt32($valueName);'; | 383 writeCode = '$offsetName = fbBuilder.writeListInt32($valueName);'; |
| 384 } else if (fieldType.typeName == 'double') { |
| 385 writeCode = '$offsetName = fbBuilder.writeListFloat64($valueName);
'; |
| 376 } else { | 386 } else { |
| 377 assert(fieldType.typeName == 'String'); | 387 assert(fieldType.typeName == 'String'); |
| 378 String itemCode = 'fbBuilder.writeString(b)'; | 388 String itemCode = 'fbBuilder.writeString(b)'; |
| 379 String listCode = '$valueName.map((b) => $itemCode).toList()'; | 389 String listCode = '$valueName.map((b) => $itemCode).toList()'; |
| 380 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; | 390 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; |
| 381 } | 391 } |
| 382 } else if (fieldType.typeName == 'String') { | 392 } else if (fieldType.typeName == 'String') { |
| 383 writeCode = '$offsetName = fbBuilder.writeString($valueName);'; | 393 writeCode = '$offsetName = fbBuilder.writeString($valueName);'; |
| 384 } else if (_idl.classes.containsKey(fieldType.typeName)) { | 394 } else if (_idl.classes.containsKey(fieldType.typeName)) { |
| 385 writeCode = '$offsetName = $valueName.finish(fbBuilder);'; | 395 writeCode = '$offsetName = $valueName.finish(fbBuilder);'; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 String fieldName = field.name; | 499 String fieldName = field.name; |
| 490 idlModel.FieldType type = field.type; | 500 idlModel.FieldType type = field.type; |
| 491 String typeName = type.typeName; | 501 String typeName = type.typeName; |
| 492 // Prepare "readCode" + "def" | 502 // Prepare "readCode" + "def" |
| 493 String readCode; | 503 String readCode; |
| 494 String def = defaultValue(type); | 504 String def = defaultValue(type); |
| 495 if (type.isList) { | 505 if (type.isList) { |
| 496 if (typeName == 'int') { | 506 if (typeName == 'int') { |
| 497 String itemCode = 'const fb.Int32Reader()'; | 507 String itemCode = 'const fb.Int32Reader()'; |
| 498 readCode = 'const fb.ListReader<int>($itemCode)'; | 508 readCode = 'const fb.ListReader<int>($itemCode)'; |
| 509 } else if (typeName == 'double') { |
| 510 readCode = 'const fb.Float64ListReader()'; |
| 499 } else if (typeName == 'String') { | 511 } else if (typeName == 'String') { |
| 500 String itemCode = 'const fb.StringReader()'; | 512 String itemCode = 'const fb.StringReader()'; |
| 501 readCode = 'const fb.ListReader<String>($itemCode)'; | 513 readCode = 'const fb.ListReader<String>($itemCode)'; |
| 502 } else { | 514 } else if (_idl.classes.containsKey(typeName)) { |
| 503 String itemCode = '$typeName>(const _${typeName}Reader()'; | 515 String itemCode = '$typeName>(const _${typeName}Reader()'; |
| 504 readCode = 'const fb.ListReader<$itemCode)'; | 516 readCode = 'const fb.ListReader<$itemCode)'; |
| 517 } else { |
| 518 assert(_idl.enums.containsKey(typeName)); |
| 519 String itemCode = 'const _${typeName}Reader()'; |
| 520 readCode = 'const fb.ListReader<$typeName>($itemCode)'; |
| 505 } | 521 } |
| 506 } else if (typeName == 'bool') { | 522 } else if (typeName == 'bool') { |
| 507 readCode = 'const fb.BoolReader()'; | 523 readCode = 'const fb.BoolReader()'; |
| 508 } else if (typeName == 'int') { | 524 } else if (typeName == 'int') { |
| 509 readCode = 'const fb.Int32Reader()'; | 525 readCode = 'const fb.Int32Reader()'; |
| 510 } else if (typeName == 'String') { | 526 } else if (typeName == 'String') { |
| 511 readCode = 'const fb.StringReader()'; | 527 readCode = 'const fb.StringReader()'; |
| 512 } else if (_idl.enums.containsKey(typeName)) { | 528 } else if (_idl.enums.containsKey(typeName)) { |
| 513 readCode = 'const _${typeName}Reader()'; | 529 readCode = 'const _${typeName}Reader()'; |
| 514 } else if (_idl.classes.containsKey(typeName)) { | 530 } else if (_idl.classes.containsKey(typeName)) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return token.lexeme.split('\n').map((String line) { | 620 return token.lexeme.split('\n').map((String line) { |
| 605 if (line.startsWith(indent)) { | 621 if (line.startsWith(indent)) { |
| 606 line = line.substring(indent.length); | 622 line = line.substring(indent.length); |
| 607 } | 623 } |
| 608 return line; | 624 return line; |
| 609 }).join('\n'); | 625 }).join('\n'); |
| 610 } | 626 } |
| 611 return null; | 627 return null; |
| 612 } | 628 } |
| 613 } | 629 } |
| OLD | NEW |