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

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

Issue 2110693002: Remove "_finished" assertion checks from summary codegen. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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') | no next file » | 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 537 }
538 538
539 void _generateBuilder(idlModel.ClassDeclaration cls) { 539 void _generateBuilder(idlModel.ClassDeclaration cls) {
540 String name = cls.name; 540 String name = cls.name;
541 String builderName = name + 'Builder'; 541 String builderName = name + 'Builder';
542 String mixinName = '_${name}Mixin'; 542 String mixinName = '_${name}Mixin';
543 List<String> constructorParams = <String>[]; 543 List<String> constructorParams = <String>[];
544 out('class $builderName extends Object with $mixinName ' 544 out('class $builderName extends Object with $mixinName '
545 'implements ${idlPrefix(name)} {'); 545 'implements ${idlPrefix(name)} {');
546 indent(() { 546 indent(() {
547 out('bool _finished = false;');
548 // Generate fields. 547 // Generate fields.
549 out();
550 for (idlModel.FieldDeclaration field in cls.fields) { 548 for (idlModel.FieldDeclaration field in cls.fields) {
551 String fieldName = field.name; 549 String fieldName = field.name;
552 idlModel.FieldType type = field.type; 550 idlModel.FieldType type = field.type;
553 String typeStr = encodedType(type); 551 String typeStr = encodedType(type);
554 out('$typeStr _$fieldName;'); 552 out('$typeStr _$fieldName;');
555 } 553 }
556 // Generate getters and setters. 554 // Generate getters and setters.
557 for (idlModel.FieldDeclaration field in cls.allFields) { 555 for (idlModel.FieldDeclaration field in cls.allFields) {
558 String fieldName = field.name; 556 String fieldName = field.name;
559 idlModel.FieldType fieldType = field.type; 557 idlModel.FieldType fieldType = field.type;
560 String typeStr = encodedType(fieldType); 558 String typeStr = encodedType(fieldType);
561 String def = defaultValue(fieldType, true); 559 String def = defaultValue(fieldType, true);
562 String defSuffix = def == null ? '' : ' ??= $def'; 560 String defSuffix = def == null ? '' : ' ??= $def';
563 out(); 561 out();
564 out('@override'); 562 out('@override');
565 if (field.isDeprecated) { 563 if (field.isDeprecated) {
566 out('$typeStr get $fieldName => $_throwDeprecated;'); 564 out('$typeStr get $fieldName => $_throwDeprecated;');
567 } else { 565 } else {
568 out('$typeStr get $fieldName => _$fieldName$defSuffix;'); 566 out('$typeStr get $fieldName => _$fieldName$defSuffix;');
569 out(); 567 out();
570 outDoc(field.documentation); 568 outDoc(field.documentation);
571 constructorParams.add('$typeStr $fieldName'); 569 constructorParams.add('$typeStr $fieldName');
572 out('void set $fieldName($typeStr _value) {'); 570 out('void set $fieldName($typeStr _value) {');
573 indent(() { 571 indent(() {
574 String stateFieldName = '_' + fieldName; 572 String stateFieldName = '_' + fieldName;
575 out('assert(!_finished);');
576 // Validate that int(s) are non-negative. 573 // Validate that int(s) are non-negative.
577 if (fieldType.typeName == 'int') { 574 if (fieldType.typeName == 'int') {
578 if (!fieldType.isList) { 575 if (!fieldType.isList) {
579 out('assert(_value == null || _value >= 0);'); 576 out('assert(_value == null || _value >= 0);');
580 } else { 577 } else {
581 out('assert(_value == null || _value.every((e) => e >= 0));'); 578 out('assert(_value == null || _value.every((e) => e >= 0));');
582 } 579 }
583 } 580 }
584 // Set the value. 581 // Set the value.
585 out('$stateFieldName = _value;'); 582 out('$stateFieldName = _value;');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 String fileId = cls.fileIdentifier == null 627 String fileId = cls.fileIdentifier == null
631 ? '' 628 ? ''
632 : ', ${quoted(cls.fileIdentifier)}'; 629 : ', ${quoted(cls.fileIdentifier)}';
633 out('return fbBuilder.finish(finish(fbBuilder)$fileId);'); 630 out('return fbBuilder.finish(finish(fbBuilder)$fileId);');
634 }); 631 });
635 out('}'); 632 out('}');
636 } 633 }
637 out(); 634 out();
638 out('fb.Offset finish(fb.Builder fbBuilder) {'); 635 out('fb.Offset finish(fb.Builder fbBuilder) {');
639 indent(() { 636 indent(() {
640 out('assert(!_finished);');
641 out('_finished = true;');
642 // Write objects and remember Offset(s). 637 // Write objects and remember Offset(s).
643 for (idlModel.FieldDeclaration field in cls.fields) { 638 for (idlModel.FieldDeclaration field in cls.fields) {
644 idlModel.FieldType fieldType = field.type; 639 idlModel.FieldType fieldType = field.type;
645 String offsetName = 'offset_' + field.name; 640 String offsetName = 'offset_' + field.name;
646 if (fieldType.isList || 641 if (fieldType.isList ||
647 fieldType.typeName == 'String' || 642 fieldType.typeName == 'String' ||
648 _idl.classes.containsKey(fieldType.typeName)) { 643 _idl.classes.containsKey(fieldType.typeName)) {
649 out('fb.Offset $offsetName;'); 644 out('fb.Offset $offsetName;');
650 } 645 }
651 } 646 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 return token.lexeme.split('\n').map((String line) { 933 return token.lexeme.split('\n').map((String line) {
939 if (line.startsWith(indent)) { 934 if (line.startsWith(indent)) {
940 line = line.substring(indent.length); 935 line = line.substring(indent.length);
941 } 936 }
942 return line; 937 return line;
943 }).join('\n'); 938 }).join('\n');
944 } 939 }
945 return null; 940 return null;
946 } 941 }
947 } 942 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698