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

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

Issue 1617123002: Generate documentation for enumeration values. (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_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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 119
120 /** 120 /**
121 * Generate a Dart expression representing the default value for a field 121 * Generate a Dart expression representing the default value for a field
122 * having the given [type], or `null` if there is no default value. 122 * having the given [type], or `null` if there is no default value.
123 */ 123 */
124 String defaultValue(idlModel.FieldType type) { 124 String defaultValue(idlModel.FieldType type) {
125 if (type.isList) { 125 if (type.isList) {
126 return 'const <${type.typeName}>[]'; 126 return 'const <${type.typeName}>[]';
127 } else if (_idl.enums.containsKey(type.typeName)) { 127 } else if (_idl.enums.containsKey(type.typeName)) {
128 return '${type.typeName}.${_idl.enums[type.typeName].values[0]}'; 128 return '${type.typeName}.${_idl.enums[type.typeName].values[0].name}';
129 } else if (type.typeName == 'int') { 129 } else if (type.typeName == 'int') {
130 return '0'; 130 return '0';
131 } else if (type.typeName == 'String') { 131 } else if (type.typeName == 'String') {
132 return "''"; 132 return "''";
133 } else if (type.typeName == 'bool') { 133 } else if (type.typeName == 'bool') {
134 return 'false'; 134 return 'false';
135 } else { 135 } else {
136 return null; 136 return null;
137 } 137 }
138 } 138 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } else { 197 } else {
198 throw new Exception('Unexpected class member `$classMember`'); 198 throw new Exception('Unexpected class member `$classMember`');
199 } 199 }
200 } 200 }
201 } else if (decl is EnumDeclaration) { 201 } else if (decl is EnumDeclaration) {
202 String doc = _getNodeDoc(lineInfo, decl); 202 String doc = _getNodeDoc(lineInfo, decl);
203 idlModel.EnumDeclaration enm = 203 idlModel.EnumDeclaration enm =
204 new idlModel.EnumDeclaration(doc, decl.name.name); 204 new idlModel.EnumDeclaration(doc, decl.name.name);
205 _idl.enums[enm.name] = enm; 205 _idl.enums[enm.name] = enm;
206 for (EnumConstantDeclaration constDecl in decl.constants) { 206 for (EnumConstantDeclaration constDecl in decl.constants) {
207 enm.values.add(constDecl.name.name); 207 String doc = _getNodeDoc(lineInfo, constDecl);
208 enm.values
209 .add(new idlModel.EnumValueDeclaration(doc, constDecl.name.name));
208 } 210 }
209 } else if (decl is TopLevelVariableDeclaration) { 211 } else if (decl is TopLevelVariableDeclaration) {
210 // Ignore top level variable declarations; they are present just to make 212 // Ignore top level variable declarations; they are present just to make
211 // the IDL analyze without warnings. 213 // the IDL analyze without warnings.
212 } else { 214 } else {
213 throw new Exception('Unexpected declaration `$decl`'); 215 throw new Exception('Unexpected declaration `$decl`');
214 } 216 }
215 } 217 }
216 } 218 }
217 219
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 condition = ' || $valueName.isEmpty'; 385 condition = ' || $valueName.isEmpty';
384 if (_idl.classes.containsKey(fieldType.typeName)) { 386 if (_idl.classes.containsKey(fieldType.typeName)) {
385 String itemCode = 'b.finish(fbBuilder)'; 387 String itemCode = 'b.finish(fbBuilder)';
386 String listCode = '$valueName.map((b) => $itemCode).toList()'; 388 String listCode = '$valueName.map((b) => $itemCode).toList()';
387 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; 389 writeCode = '$offsetName = fbBuilder.writeList($listCode);';
388 } else if (_idl.enums.containsKey(fieldType.typeName)) { 390 } else if (_idl.enums.containsKey(fieldType.typeName)) {
389 String itemCode = 'b.index'; 391 String itemCode = 'b.index';
390 String listCode = '$valueName.map((b) => $itemCode).toList()'; 392 String listCode = '$valueName.map((b) => $itemCode).toList()';
391 writeCode = '$offsetName = fbBuilder.writeListUint32($listCode);'; 393 writeCode = '$offsetName = fbBuilder.writeListUint32($listCode);';
392 } else if (fieldType.typeName == 'int') { 394 } else if (fieldType.typeName == 'int') {
393 writeCode = '$offsetName = fbBuilder.writeListUint32($valueName);' ; 395 writeCode =
396 '$offsetName = fbBuilder.writeListUint32($valueName);';
394 } else if (fieldType.typeName == 'double') { 397 } else if (fieldType.typeName == 'double') {
395 writeCode = '$offsetName = fbBuilder.writeListFloat64($valueName); '; 398 writeCode =
399 '$offsetName = fbBuilder.writeListFloat64($valueName);';
396 } else { 400 } else {
397 assert(fieldType.typeName == 'String'); 401 assert(fieldType.typeName == 'String');
398 String itemCode = 'fbBuilder.writeString(b)'; 402 String itemCode = 'fbBuilder.writeString(b)';
399 String listCode = '$valueName.map((b) => $itemCode).toList()'; 403 String listCode = '$valueName.map((b) => $itemCode).toList()';
400 writeCode = '$offsetName = fbBuilder.writeList($listCode);'; 404 writeCode = '$offsetName = fbBuilder.writeList($listCode);';
401 } 405 }
402 } else if (fieldType.typeName == 'String') { 406 } else if (fieldType.typeName == 'String') {
403 writeCode = '$offsetName = fbBuilder.writeString($valueName);'; 407 writeCode = '$offsetName = fbBuilder.writeString($valueName);';
404 } else if (_idl.classes.containsKey(fieldType.typeName)) { 408 } else if (_idl.classes.containsKey(fieldType.typeName)) {
405 writeCode = '$offsetName = $valueName.finish(fbBuilder);'; 409 writeCode = '$offsetName = $valueName.finish(fbBuilder);';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 out('}'); 457 out('}');
454 }); 458 });
455 out('}'); 459 out('}');
456 } 460 }
457 461
458 void _generateEnum(idlModel.EnumDeclaration enm) { 462 void _generateEnum(idlModel.EnumDeclaration enm) {
459 String name = enm.name; 463 String name = enm.name;
460 outDoc(enm.documentation); 464 outDoc(enm.documentation);
461 out('enum $name {'); 465 out('enum $name {');
462 indent(() { 466 indent(() {
463 for (String value in enm.values) { 467 for (idlModel.EnumValueDeclaration value in enm.values) {
464 out('$value,'); 468 outDoc(value.documentation);
469 if (enm.values.last == value) {
470 out('${value.name}');
471 } else {
472 out('${value.name},');
473 out();
474 }
465 } 475 }
466 }); 476 });
467 out('}'); 477 out('}');
468 } 478 }
469 479
470 void _generateEnumReader(idlModel.EnumDeclaration enm) { 480 void _generateEnumReader(idlModel.EnumDeclaration enm) {
471 String name = enm.name; 481 String name = enm.name;
472 String readerName = '_${name}Reader'; 482 String readerName = '_${name}Reader';
473 out('class $readerName extends fb.Reader<$name> {'); 483 out('class $readerName extends fb.Reader<$name> {');
474 indent(() { 484 indent(() {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 return token.lexeme.split('\n').map((String line) { 640 return token.lexeme.split('\n').map((String line) {
631 if (line.startsWith(indent)) { 641 if (line.startsWith(indent)) {
632 line = line.substring(indent.length); 642 line = line.substring(indent.length);
633 } 643 }
634 return line; 644 return line;
635 }).join('\n'); 645 }).join('\n');
636 } 646 }
637 return null; 647 return null;
638 } 648 }
639 } 649 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/tool/summary/idl_model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698