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

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

Issue 1605763007: Validate that int values that we write to summaries are >= 0. (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/test/generated/resolver_test.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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 out(); 305 out();
306 for (idlModel.FieldDeclaration field in cls.fields) { 306 for (idlModel.FieldDeclaration field in cls.fields) {
307 String fieldName = field.name; 307 String fieldName = field.name;
308 idlModel.FieldType type = field.type; 308 idlModel.FieldType type = field.type;
309 String typeStr = encodedType(type); 309 String typeStr = encodedType(type);
310 out('$typeStr _$fieldName;'); 310 out('$typeStr _$fieldName;');
311 } 311 }
312 // Generate getters and setters. 312 // Generate getters and setters.
313 for (idlModel.FieldDeclaration field in cls.fields) { 313 for (idlModel.FieldDeclaration field in cls.fields) {
314 String fieldName = field.name; 314 String fieldName = field.name;
315 String typeStr = encodedType(field.type); 315 idlModel.FieldType fieldType = field.type;
316 String def = defaultValue(field.type); 316 String typeStr = encodedType(fieldType);
317 String def = defaultValue(fieldType);
317 String defSuffix = def == null ? '' : ' ?? $def'; 318 String defSuffix = def == null ? '' : ' ?? $def';
318 out(); 319 out();
319 out('@override'); 320 out('@override');
320 out('${dartType(field.type)} get $fieldName => _$fieldName$defSuffix;'); 321 out('${dartType(fieldType)} get $fieldName => _$fieldName$defSuffix;');
321 out(); 322 out();
322 outDoc(field.documentation); 323 outDoc(field.documentation);
323 constructorParams.add('$typeStr $fieldName'); 324 constructorParams.add('$typeStr $fieldName');
324 out('void set $fieldName($typeStr _value) {'); 325 out('void set $fieldName($typeStr _value) {');
325 indent(() { 326 indent(() {
326 String stateFieldName = '_' + fieldName; 327 String stateFieldName = '_' + fieldName;
327 out('assert(!_finished);'); 328 out('assert(!_finished);');
329 // Validate that int(s) are non-negative.
330 if (fieldType.typeName == 'int') {
331 if (!fieldType.isList) {
332 out('assert(_value == null || _value >= 0);');
333 } else {
334 out('assert(_value == null || _value.every((e) => e >= 0));');
335 }
336 }
337 // Set the value.
328 out('$stateFieldName = _value;'); 338 out('$stateFieldName = _value;');
329 }); 339 });
330 out('}'); 340 out('}');
331 } 341 }
332 // Generate constructor. 342 // Generate constructor.
333 out(); 343 out();
334 out('$builderName({${constructorParams.join(', ')}})'); 344 out('$builderName({${constructorParams.join(', ')}})');
335 for (int i = 0; i < cls.fields.length; i++) { 345 for (int i = 0; i < cls.fields.length; i++) {
336 idlModel.FieldDeclaration field = cls.fields[i]; 346 idlModel.FieldDeclaration field = cls.fields[i];
337 String prefix = i == 0 ? ' : ' : ' '; 347 String prefix = i == 0 ? ' : ' : ' ';
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 return token.lexeme.split('\n').map((String line) { 630 return token.lexeme.split('\n').map((String line) {
621 if (line.startsWith(indent)) { 631 if (line.startsWith(indent)) {
622 line = line.substring(indent.length); 632 line = line.substring(indent.length);
623 } 633 }
624 return line; 634 return line;
625 }).join('\n'); 635 }).join('\n');
626 } 636 }
627 return null; 637 return null;
628 } 638 }
629 } 639 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698