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

Side by Side Diff: pkg/analyzer/tool/summary/generate.dart

Issue 1615453002: Use Uint32 for `int` in IDL. (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 | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/tool/summary/idl.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) 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 String writeCode; 381 String writeCode;
382 if (fieldType.isList) { 382 if (fieldType.isList) {
383 condition = ' || $valueName.isEmpty'; 383 condition = ' || $valueName.isEmpty';
384 if (_idl.classes.containsKey(fieldType.typeName)) { 384 if (_idl.classes.containsKey(fieldType.typeName)) {
385 String itemCode = 'b.finish(fbBuilder)'; 385 String itemCode = 'b.finish(fbBuilder)';
386 String listCode = '$valueName.map((b) => $itemCode).toList()'; 386 String listCode = '$valueName.map((b) => $itemCode).toList()';
387 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; 387 writeCode = '$offsetName = fbBuilder.writeList($listCode);';
388 } else if (_idl.enums.containsKey(fieldType.typeName)) { 388 } else if (_idl.enums.containsKey(fieldType.typeName)) {
389 String itemCode = 'b.index'; 389 String itemCode = 'b.index';
390 String listCode = '$valueName.map((b) => $itemCode).toList()'; 390 String listCode = '$valueName.map((b) => $itemCode).toList()';
391 writeCode = '$offsetName = fbBuilder.writeListInt32($listCode);'; 391 writeCode = '$offsetName = fbBuilder.writeListUint32($listCode);';
392 } else if (fieldType.typeName == 'int') { 392 } else if (fieldType.typeName == 'int') {
393 writeCode = '$offsetName = fbBuilder.writeListInt32($valueName);'; 393 writeCode = '$offsetName = fbBuilder.writeListUint32($valueName);' ;
394 } else if (fieldType.typeName == 'double') { 394 } else if (fieldType.typeName == 'double') {
395 writeCode = '$offsetName = fbBuilder.writeListFloat64($valueName); '; 395 writeCode = '$offsetName = fbBuilder.writeListFloat64($valueName); ';
396 } else { 396 } else {
397 assert(fieldType.typeName == 'String'); 397 assert(fieldType.typeName == 'String');
398 String itemCode = 'fbBuilder.writeString(b)'; 398 String itemCode = 'fbBuilder.writeString(b)';
399 String listCode = '$valueName.map((b) => $itemCode).toList()'; 399 String listCode = '$valueName.map((b) => $itemCode).toList()';
400 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; 400 writeCode = '$offsetName = fbBuilder.writeList($listCode);';
401 } 401 }
402 } else if (fieldType.typeName == 'String') { 402 } else if (fieldType.typeName == 'String') {
403 writeCode = '$offsetName = fbBuilder.writeString($valueName);'; 403 writeCode = '$offsetName = fbBuilder.writeString($valueName);';
(...skipping 23 matching lines...) Expand all
427 fieldType.typeName == 'String' || 427 fieldType.typeName == 'String' ||
428 _idl.classes.containsKey(fieldType.typeName)) { 428 _idl.classes.containsKey(fieldType.typeName)) {
429 String offsetName = 'offset_' + field.name; 429 String offsetName = 'offset_' + field.name;
430 condition = '$offsetName != null'; 430 condition = '$offsetName != null';
431 writeCode = 'fbBuilder.addOffset($index, $offsetName);'; 431 writeCode = 'fbBuilder.addOffset($index, $offsetName);';
432 } else if (fieldType.typeName == 'bool') { 432 } else if (fieldType.typeName == 'bool') {
433 condition = '$valueName == true'; 433 condition = '$valueName == true';
434 writeCode = 'fbBuilder.addBool($index, true);'; 434 writeCode = 'fbBuilder.addBool($index, true);';
435 } else if (fieldType.typeName == 'int') { 435 } else if (fieldType.typeName == 'int') {
436 condition += ' && $valueName != ${defaultValue(fieldType)}'; 436 condition += ' && $valueName != ${defaultValue(fieldType)}';
437 writeCode = 'fbBuilder.addInt32($index, $valueName);'; 437 writeCode = 'fbBuilder.addUint32($index, $valueName);';
438 } else if (_idl.enums.containsKey(fieldType.typeName)) { 438 } else if (_idl.enums.containsKey(fieldType.typeName)) {
439 condition += ' && $valueName != ${defaultValue(fieldType)}'; 439 condition += ' && $valueName != ${defaultValue(fieldType)}';
440 writeCode = 'fbBuilder.addInt32($index, $valueName.index);'; 440 writeCode = 'fbBuilder.addUint32($index, $valueName.index);';
441 } 441 }
442 if (writeCode == null) { 442 if (writeCode == null) {
443 throw new UnimplementedError('Writing type ${fieldType.typeName}'); 443 throw new UnimplementedError('Writing type ${fieldType.typeName}');
444 } 444 }
445 out('if ($condition) {'); 445 out('if ($condition) {');
446 indent(() { 446 indent(() {
447 out(writeCode); 447 out(writeCode);
448 }); 448 });
449 out('}'); 449 out('}');
450 }); 450 });
(...skipping 22 matching lines...) Expand all
473 out('class $readerName extends fb.Reader<$name> {'); 473 out('class $readerName extends fb.Reader<$name> {');
474 indent(() { 474 indent(() {
475 out('const $readerName() : super();'); 475 out('const $readerName() : super();');
476 out(); 476 out();
477 out('@override'); 477 out('@override');
478 out('int get size => 4;'); 478 out('int get size => 4;');
479 out(); 479 out();
480 out('@override'); 480 out('@override');
481 out('$name read(fb.BufferPointer bp) {'); 481 out('$name read(fb.BufferPointer bp) {');
482 indent(() { 482 indent(() {
483 out('int index = const fb.Int32Reader().read(bp);'); 483 out('int index = const fb.Uint32Reader().read(bp);');
484 out('return $name.values[index];'); 484 out('return $name.values[index];');
485 }); 485 });
486 out('}'); 486 out('}');
487 }); 487 });
488 out('}'); 488 out('}');
489 } 489 }
490 490
491 void _generateImpl(idlModel.ClassDeclaration cls) { 491 void _generateImpl(idlModel.ClassDeclaration cls) {
492 String name = cls.name; 492 String name = cls.name;
493 String implName = '_${name}Impl'; 493 String implName = '_${name}Impl';
(...skipping 13 matching lines...) Expand all
507 // Write getters. 507 // Write getters.
508 cls.fields.asMap().forEach((index, field) { 508 cls.fields.asMap().forEach((index, field) {
509 String fieldName = field.name; 509 String fieldName = field.name;
510 idlModel.FieldType type = field.type; 510 idlModel.FieldType type = field.type;
511 String typeName = type.typeName; 511 String typeName = type.typeName;
512 // Prepare "readCode" + "def" 512 // Prepare "readCode" + "def"
513 String readCode; 513 String readCode;
514 String def = defaultValue(type); 514 String def = defaultValue(type);
515 if (type.isList) { 515 if (type.isList) {
516 if (typeName == 'int') { 516 if (typeName == 'int') {
517 String itemCode = 'const fb.Int32Reader()'; 517 String itemCode = 'const fb.Uint32Reader()';
518 readCode = 'const fb.ListReader<int>($itemCode)'; 518 readCode = 'const fb.ListReader<int>($itemCode)';
519 } else if (typeName == 'double') { 519 } else if (typeName == 'double') {
520 readCode = 'const fb.Float64ListReader()'; 520 readCode = 'const fb.Float64ListReader()';
521 } else if (typeName == 'String') { 521 } else if (typeName == 'String') {
522 String itemCode = 'const fb.StringReader()'; 522 String itemCode = 'const fb.StringReader()';
523 readCode = 'const fb.ListReader<String>($itemCode)'; 523 readCode = 'const fb.ListReader<String>($itemCode)';
524 } else if (_idl.classes.containsKey(typeName)) { 524 } else if (_idl.classes.containsKey(typeName)) {
525 String itemCode = '$typeName>(const _${typeName}Reader()'; 525 String itemCode = '$typeName>(const _${typeName}Reader()';
526 readCode = 'const fb.ListReader<$itemCode)'; 526 readCode = 'const fb.ListReader<$itemCode)';
527 } else { 527 } else {
528 assert(_idl.enums.containsKey(typeName)); 528 assert(_idl.enums.containsKey(typeName));
529 String itemCode = 'const _${typeName}Reader()'; 529 String itemCode = 'const _${typeName}Reader()';
530 readCode = 'const fb.ListReader<$typeName>($itemCode)'; 530 readCode = 'const fb.ListReader<$typeName>($itemCode)';
531 } 531 }
532 } else if (typeName == 'bool') { 532 } else if (typeName == 'bool') {
533 readCode = 'const fb.BoolReader()'; 533 readCode = 'const fb.BoolReader()';
534 } else if (typeName == 'int') { 534 } else if (typeName == 'int') {
535 readCode = 'const fb.Int32Reader()'; 535 readCode = 'const fb.Uint32Reader()';
536 } else if (typeName == 'String') { 536 } else if (typeName == 'String') {
537 readCode = 'const fb.StringReader()'; 537 readCode = 'const fb.StringReader()';
538 } else if (_idl.enums.containsKey(typeName)) { 538 } else if (_idl.enums.containsKey(typeName)) {
539 readCode = 'const _${typeName}Reader()'; 539 readCode = 'const _${typeName}Reader()';
540 } else if (_idl.classes.containsKey(typeName)) { 540 } else if (_idl.classes.containsKey(typeName)) {
541 readCode = 'const _${typeName}Reader()'; 541 readCode = 'const _${typeName}Reader()';
542 } 542 }
543 assert(readCode != null); 543 assert(readCode != null);
544 // Write the getter implementation. 544 // Write the getter implementation.
545 out(); 545 out();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 return token.lexeme.split('\n').map((String line) { 630 return token.lexeme.split('\n').map((String line) {
631 if (line.startsWith(indent)) { 631 if (line.startsWith(indent)) {
632 line = line.substring(indent.length); 632 line = line.substring(indent.length);
633 } 633 }
634 return line; 634 return line;
635 }).join('\n'); 635 }).join('\n');
636 } 636 }
637 return null; 637 return null;
638 } 638 }
639 } 639 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698