Chromium Code Reviews| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 conversion = '$conversion.index'; | 325 conversion = '$conversion.index'; |
| 326 condition = ' || _value == ${defaultValue(type)}'; | 326 condition = ' || _value == ${defaultValue(type)}'; |
| 327 } else if (_idl.classes.containsKey(type.typeName)) { | 327 } else if (_idl.classes.containsKey(type.typeName)) { |
| 328 conversion = '$conversion.finish()'; | 328 conversion = '$conversion.finish()'; |
| 329 } | 329 } |
| 330 builderParams.add('${encodedType(type)} $fieldName'); | 330 builderParams.add('${encodedType(type)} $fieldName'); |
| 331 out('void set $fieldName(${encodedType(type)} _value) {'); | 331 out('void set $fieldName(${encodedType(type)} _value) {'); |
| 332 indent(() { | 332 indent(() { |
| 333 out('assert(!_finished);'); | 333 out('assert(!_finished);'); |
| 334 out('assert(!_json.containsKey(${quoted(fieldName)}));'); | 334 out('assert(!_json.containsKey(${quoted(fieldName)}));'); |
| 335 out('if (_value != null$condition) {'); | 335 out('if (!(_value == null$condition)) {'); |
|
Brian Wilkerson
2015/12/18 18:16:10
The case where there is no default value got uglie
| |
| 336 indent(() { | 336 indent(() { |
| 337 out('_json[${quoted(fieldName)}] = $conversion;'); | 337 out('_json[${quoted(fieldName)}] = $conversion;'); |
| 338 }); | 338 }); |
| 339 out('}'); | 339 out('}'); |
| 340 }); | 340 }); |
| 341 out('}'); | 341 out('}'); |
| 342 }); | 342 }); |
| 343 if (cls.isTopLevel) { | 343 if (cls.isTopLevel) { |
| 344 out(); | 344 out(); |
| 345 out('List<int> toBuffer() => UTF8.encode(JSON.encode(finish()));'); | 345 out('List<int> toBuffer() => UTF8.encode(JSON.encode(finish()));'); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 368 }); | 368 }); |
| 369 } | 369 } |
| 370 | 370 |
| 371 /** | 371 /** |
| 372 * Enclose [s] in quotes, escaping as necessary. | 372 * Enclose [s] in quotes, escaping as necessary. |
| 373 */ | 373 */ |
| 374 String quoted(String s) { | 374 String quoted(String s) { |
| 375 return JSON.encode(s); | 375 return JSON.encode(s); |
| 376 } | 376 } |
| 377 } | 377 } |
| OLD | NEW |