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

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

Issue 1828973002: Add the --build-summary-exclude-informative flag. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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/idl.dart ('k') | pkg/analyzer/tool/summary/idl_model.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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 type.typeArguments != null && 276 type.typeArguments != null &&
277 type.typeArguments.arguments.length == 1) { 277 type.typeArguments.arguments.length == 1) {
278 isList = true; 278 isList = true;
279 type = type.typeArguments.arguments[0]; 279 type = type.typeArguments.arguments[0];
280 } 280 }
281 if (type.typeArguments != null) { 281 if (type.typeArguments != null) {
282 throw new Exception('Cannot handle type arguments in `$type`'); 282 throw new Exception('Cannot handle type arguments in `$type`');
283 } 283 }
284 int id; 284 int id;
285 bool isDeprecated = false; 285 bool isDeprecated = false;
286 bool isInformative = false;
286 for (Annotation annotation in classMember.metadata) { 287 for (Annotation annotation in classMember.metadata) {
287 if (annotation.name.name == 'Id') { 288 if (annotation.name.name == 'Id') {
288 if (id != null) { 289 if (id != null) {
289 throw new Exception( 290 throw new Exception(
290 'Duplicate @id annotation ($classMember)'); 291 'Duplicate @id annotation ($classMember)');
291 } 292 }
292 if (annotation.arguments.arguments.length != 1) { 293 if (annotation.arguments.arguments.length != 1) {
293 throw new Exception( 294 throw new Exception(
294 '@Id must be passed exactly one argument ($desc)'); 295 '@Id must be passed exactly one argument ($desc)');
295 } 296 }
296 Expression expression = annotation.arguments.arguments[0]; 297 Expression expression = annotation.arguments.arguments[0];
297 if (expression is IntegerLiteral) { 298 if (expression is IntegerLiteral) {
298 id = expression.value; 299 id = expression.value;
299 } else { 300 } else {
300 throw new Exception( 301 throw new Exception(
301 '@Id parameter must be an integer literal ($desc)'); 302 '@Id parameter must be an integer literal ($desc)');
302 } 303 }
303 } else if (annotation.name.name == 'deprecated') { 304 } else if (annotation.name.name == 'deprecated') {
304 if (annotation.arguments != null) { 305 if (annotation.arguments != null) {
305 throw new Exception('@deprecated does not take args ($desc)'); 306 throw new Exception('@deprecated does not take args ($desc)');
306 } 307 }
307 isDeprecated = true; 308 isDeprecated = true;
309 } else if (annotation.name.name == 'informative') {
310 isInformative = true;
308 } 311 }
309 } 312 }
310 if (id == null) { 313 if (id == null) {
311 throw new Exception('Missing @id annotation ($desc)'); 314 throw new Exception('Missing @id annotation ($desc)');
312 } 315 }
313 String doc = _getNodeDoc(lineInfo, classMember); 316 String doc = _getNodeDoc(lineInfo, classMember);
314 idlModel.FieldType fieldType = 317 idlModel.FieldType fieldType =
315 new idlModel.FieldType(type.name.name, isList); 318 new idlModel.FieldType(type.name.name, isList);
316 cls.allFields.add(new idlModel.FieldDeclaration( 319 cls.allFields.add(new idlModel.FieldDeclaration(
317 doc, classMember.name.name, fieldType, id, isDeprecated)); 320 doc,
321 classMember.name.name,
322 fieldType,
323 id,
324 isDeprecated,
325 isInformative));
318 } else if (classMember is ConstructorDeclaration && 326 } else if (classMember is ConstructorDeclaration &&
319 classMember.name.name == 'fromBuffer') { 327 classMember.name.name == 'fromBuffer') {
320 // Ignore `fromBuffer` declarations; they simply forward to the 328 // Ignore `fromBuffer` declarations; they simply forward to the
321 // read functions generated by [_generateReadFunction]. 329 // read functions generated by [_generateReadFunction].
322 } else { 330 } else {
323 throw new Exception('Unexpected class member `$classMember`'); 331 throw new Exception('Unexpected class member `$classMember`');
324 } 332 }
325 } 333 }
326 } else if (decl is EnumDeclaration) { 334 } else if (decl is EnumDeclaration) {
327 String doc = _getNodeDoc(lineInfo, decl); 335 String doc = _getNodeDoc(lineInfo, decl);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // Generate constructor. 590 // Generate constructor.
583 out(); 591 out();
584 out('$builderName({${constructorParams.join(', ')}})'); 592 out('$builderName({${constructorParams.join(', ')}})');
585 List<idlModel.FieldDeclaration> fields = cls.fields.toList(); 593 List<idlModel.FieldDeclaration> fields = cls.fields.toList();
586 for (int i = 0; i < fields.length; i++) { 594 for (int i = 0; i < fields.length; i++) {
587 idlModel.FieldDeclaration field = fields[i]; 595 idlModel.FieldDeclaration field = fields[i];
588 String prefix = i == 0 ? ' : ' : ' '; 596 String prefix = i == 0 ? ' : ' : ' ';
589 String suffix = i == fields.length - 1 ? ';' : ','; 597 String suffix = i == fields.length - 1 ? ';' : ',';
590 out('${prefix}_${field.name} = ${field.name}$suffix'); 598 out('${prefix}_${field.name} = ${field.name}$suffix');
591 } 599 }
600 // Generate flushInformative().
601 {
602 out();
603 out('/**');
604 out(' * Flush [informative] data recursively.');
605 out(' */');
606 out('void flushInformative() {');
607 indent(() {
608 for (idlModel.FieldDeclaration field in cls.fields) {
609 idlModel.FieldType fieldType = field.type;
610 String valueName = '_' + field.name;
611 if (field.isInformative) {
612 out('$valueName = null;');
613 } else if (_idl.classes.containsKey(fieldType.typeName)) {
614 if (fieldType.isList) {
615 out('$valueName?.forEach((b) => b.flushInformative());');
616 } else {
617 out('$valueName?.flushInformative();');
618 }
619 }
620 }
621 });
622 out('}');
623 }
592 // Generate finish. 624 // Generate finish.
593 if (cls.isTopLevel) { 625 if (cls.isTopLevel) {
594 out(); 626 out();
595 out('List<int> toBuffer() {'); 627 out('List<int> toBuffer() {');
596 indent(() { 628 indent(() {
597 out('fb.Builder fbBuilder = new fb.Builder();'); 629 out('fb.Builder fbBuilder = new fb.Builder();');
598 String fileId = cls.fileIdentifier == null 630 String fileId = cls.fileIdentifier == null
599 ? '' 631 ? ''
600 : ', ${quoted(cls.fileIdentifier)}'; 632 : ', ${quoted(cls.fileIdentifier)}';
601 out('return fbBuilder.finish(finish(fbBuilder)$fileId);'); 633 out('return fbBuilder.finish(finish(fbBuilder)$fileId);');
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 return token.lexeme.split('\n').map((String line) { 937 return token.lexeme.split('\n').map((String line) {
906 if (line.startsWith(indent)) { 938 if (line.startsWith(indent)) {
907 line = line.substring(indent.length); 939 line = line.substring(indent.length);
908 } 940 }
909 return line; 941 return line;
910 }).join('\n'); 942 }).join('\n');
911 } 943 }
912 return null; 944 return null;
913 } 945 }
914 } 946 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/tool/summary/idl_model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698