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

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

Issue 1577663002: Remove BuilderContext from summary builders. (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/tool/summary/build_sdk_summary.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:
11 * - A class with the same name which represents deserialized summary data in 11 * - A class with the same name which represents deserialized summary data in
12 * memory. This class has read-only semantics. 12 * memory. This class has read-only semantics.
13 * - A "builder" class which can be used to generate serialized summary data. 13 * - A "builder" class which can be used to generate serialized summary data.
14 * This class has write-only semantics. 14 * This class has write-only semantics.
15 * 15 *
16 * Each of the "builder" classes has a single `finish` method which finalizes 16 * Each of the "builder" classes has a single `finish` method which writes
17 * the entity being built and returns it as an [Object]. This object should 17 * the entity being built into the given FlatBuffer and returns the `Offset`
18 * only be passed to other builders (or to [BuilderContext.getBuffer]); 18 * reference to it.
19 * otherwise the client should treat it as opaque, since it exposes
20 * implementation details of the underlying summary infrastructure.
21 */ 19 */
22 library analyzer.tool.summary.generate; 20 library analyzer.tool.summary.generate;
23 21
24 import 'dart:convert'; 22 import 'dart:convert';
25 import 'dart:io' hide File; 23 import 'dart:io' hide File;
26 24
27 import 'package:analyzer/analyzer.dart'; 25 import 'package:analyzer/analyzer.dart';
28 import 'package:analyzer/file_system/file_system.dart'; 26 import 'package:analyzer/file_system/file_system.dart';
29 import 'package:analyzer/file_system/physical_file_system.dart'; 27 import 'package:analyzer/file_system/physical_file_system.dart';
30 import 'package:analyzer/src/codegen/tools.dart'; 28 import 'package:analyzer/src/codegen/tools.dart';
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Generate fields. 300 // Generate fields.
303 out(); 301 out();
304 for (idlModel.FieldDeclaration field in cls.fields) { 302 for (idlModel.FieldDeclaration field in cls.fields) {
305 String fieldName = field.name; 303 String fieldName = field.name;
306 idlModel.FieldType type = field.type; 304 idlModel.FieldType type = field.type;
307 String typeStr = encodedType(type); 305 String typeStr = encodedType(type);
308 out('$typeStr _$fieldName;'); 306 out('$typeStr _$fieldName;');
309 } 307 }
310 // Generate constructor. 308 // Generate constructor.
311 out(); 309 out();
312 out('$builderName(base.BuilderContext context);'); 310 out('$builderName();');
313 // Generate setters. 311 // Generate setters.
314 for (idlModel.FieldDeclaration field in cls.fields) { 312 for (idlModel.FieldDeclaration field in cls.fields) {
315 String fieldName = field.name; 313 String fieldName = field.name;
316 String typeStr = encodedType(field.type); 314 String typeStr = encodedType(field.type);
317 out(); 315 out();
318 outDoc(field.documentation); 316 outDoc(field.documentation);
319 builderParams.add('$typeStr $fieldName'); 317 builderParams.add('$typeStr $fieldName');
320 out('void set $fieldName($typeStr _value) {'); 318 out('void set $fieldName($typeStr _value) {');
321 indent(() { 319 indent(() {
322 String stateFieldName = '_' + fieldName; 320 String stateFieldName = '_' + fieldName;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 out('}'); 422 out('}');
425 }); 423 });
426 out('}'); 424 out('}');
427 return builderParams; 425 return builderParams;
428 } 426 }
429 427
430 void _generateEncodeFunction( 428 void _generateEncodeFunction(
431 idlModel.ClassDeclaration cls, List<String> builderParams) { 429 idlModel.ClassDeclaration cls, List<String> builderParams) {
432 String className = cls.name; 430 String className = cls.name;
433 String builderName = className + 'Builder'; 431 String builderName = className + 'Builder';
434 out('$builderName encode$className(base.BuilderContext builderContext, {${bu ilderParams.join(', ')}}) {'); 432 out('$builderName encode$className({${builderParams.join(', ')}}) {');
435 indent(() { 433 indent(() {
436 out('$builderName builder = new $builderName(builderContext);'); 434 out('$builderName builder = new $builderName();');
437 for (idlModel.FieldDeclaration field in cls.fields) { 435 for (idlModel.FieldDeclaration field in cls.fields) {
438 String fieldName = field.name; 436 String fieldName = field.name;
439 out('builder.$fieldName = $fieldName;'); 437 out('builder.$fieldName = $fieldName;');
440 } 438 }
441 out('return builder;'); 439 out('return builder;');
442 }); 440 });
443 out('}'); 441 out('}');
444 } 442 }
445 443
446 void _generateInterface(idlModel.ClassDeclaration cls) { 444 void _generateInterface(idlModel.ClassDeclaration cls) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 return token.lexeme.split('\n').map((String line) { 557 return token.lexeme.split('\n').map((String line) {
560 if (line.startsWith(indent)) { 558 if (line.startsWith(indent)) {
561 line = line.substring(indent.length); 559 line = line.substring(indent.length);
562 } 560 }
563 return line; 561 return line;
564 }).join('\n'); 562 }).join('\n');
565 } 563 }
566 return null; 564 return null;
567 } 565 }
568 } 566 }
OLDNEW
« no previous file with comments | « pkg/analyzer/tool/summary/build_sdk_summary.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698