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

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

Issue 1544213002: Introduce code to generate UnlinkedPublicNamespace directly from an AST. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 12 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') | pkg/analyzer/tool/summary/idl.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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 out('// Copyright (c) 2015, the Dart project authors. Please see the AUTHOR S file'); 240 out('// Copyright (c) 2015, the Dart project authors. Please see the AUTHOR S file');
241 out('// for details. All rights reserved. Use of this source code is governe d by a'); 241 out('// for details. All rights reserved. Use of this source code is governe d by a');
242 out('// BSD-style license that can be found in the LICENSE file.'); 242 out('// BSD-style license that can be found in the LICENSE file.');
243 out('//'); 243 out('//');
244 out('// This file has been automatically generated. Please do not edit it m anually.'); 244 out('// This file has been automatically generated. Please do not edit it m anually.');
245 out('// To regenerate the file, use the script "pkg/analyzer/tool/generate_f iles".'); 245 out('// To regenerate the file, use the script "pkg/analyzer/tool/generate_f iles".');
246 out(); 246 out();
247 out('library analyzer.src.summary.format;'); 247 out('library analyzer.src.summary.format;');
248 out(); 248 out();
249 out("import 'dart:convert';"); 249 out("import 'dart:convert';");
250 out("import 'builder.dart' as builder;"); 250 out("import 'base.dart' as base;");
251 out(); 251 out();
252 _idl.enums.forEach((String name, idlModel.EnumDeclaration enm) { 252 _idl.enums.forEach((String name, idlModel.EnumDeclaration enm) {
253 out('enum $name {'); 253 out('enum $name {');
254 indent(() { 254 indent(() {
255 for (String value in enm.values) { 255 for (String value in enm.values) {
256 out('$value,'); 256 out('$value,');
257 } 257 }
258 }); 258 });
259 out('}'); 259 out('}');
260 out(); 260 out();
261 }); 261 });
262 _idl.classes.forEach((String name, idlModel.ClassDeclaration cls) { 262 _idl.classes.forEach((String name, idlModel.ClassDeclaration cls) {
263 out('class $name {'); 263 out('class $name extends base.SummaryClass {');
264 indent(() { 264 indent(() {
265 cls.fields.forEach((String fieldName, idlModel.FieldType type) { 265 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
266 out('${dartType(type)} _$fieldName;'); 266 out('${dartType(type)} _$fieldName;');
267 }); 267 });
268 out(); 268 out();
269 out('$name.fromJson(Map json)'); 269 out('$name.fromJson(Map json)');
270 indent(() { 270 indent(() {
271 List<String> initializers = <String>[]; 271 List<String> initializers = <String>[];
272 cls.fields.forEach((String fieldName, idlModel.FieldType type) { 272 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
273 String convert = 'json[${quoted(fieldName)}]'; 273 String convert = 'json[${quoted(fieldName)}]';
(...skipping 13 matching lines...) Expand all
287 } 287 }
288 initializers.add('_$fieldName = $convert'); 288 initializers.add('_$fieldName = $convert');
289 }); 289 });
290 for (int i = 0; i < initializers.length; i++) { 290 for (int i = 0; i < initializers.length; i++) {
291 String prefix = i == 0 ? ': ' : ' '; 291 String prefix = i == 0 ? ': ' : ' ';
292 String suffix = i == initializers.length - 1 ? ';' : ','; 292 String suffix = i == initializers.length - 1 ? ';' : ',';
293 out('$prefix${initializers[i]}$suffix'); 293 out('$prefix${initializers[i]}$suffix');
294 } 294 }
295 }); 295 });
296 out(); 296 out();
297 out('@override');
298 out('Map<String, Object> toMap() => {');
299 indent(() {
300 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
301 out('${quoted(fieldName)}: $fieldName,');
302 });
303 });
304 out('};');
305 out();
297 if (cls.isTopLevel) { 306 if (cls.isTopLevel) {
298 out('$name.fromBuffer(List<int> buffer) : this.fromJson(JSON.decode(UT F8.decode(buffer)));'); 307 out('$name.fromBuffer(List<int> buffer) : this.fromJson(JSON.decode(UT F8.decode(buffer)));');
299 out(); 308 out();
300 } 309 }
301 cls.fields.forEach((String fieldName, idlModel.FieldType type) { 310 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
302 String def = defaultValue(type); 311 String def = defaultValue(type);
303 String defaultSuffix = def == null ? '' : ' ?? $def'; 312 String defaultSuffix = def == null ? '' : ' ?? $def';
304 out('${dartType(type)} get $fieldName => _$fieldName$defaultSuffix;'); 313 out('${dartType(type)} get $fieldName => _$fieldName$defaultSuffix;');
305 }); 314 });
306 }); 315 });
307 out('}'); 316 out('}');
308 out(); 317 out();
309 List<String> builderParams = <String>[]; 318 List<String> builderParams = <String>[];
310 out('class ${name}Builder {'); 319 out('class ${name}Builder {');
311 indent(() { 320 indent(() {
312 out('final Map _json = {};'); 321 out('final Map _json = {};');
313 out(); 322 out();
314 out('bool _finished = false;'); 323 out('bool _finished = false;');
315 out(); 324 out();
316 out('${name}Builder(builder.BuilderContext context);'); 325 out('${name}Builder(base.BuilderContext context);');
317 cls.fields.forEach((String fieldName, idlModel.FieldType type) { 326 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
318 out(); 327 out();
319 String conversion = '_value'; 328 String conversion = '_value';
320 String condition = ''; 329 String condition = '';
321 if (type.isList) { 330 if (type.isList) {
322 if (_idl.classes.containsKey(type.typeName)) { 331 if (_idl.classes.containsKey(type.typeName)) {
323 conversion = '$conversion.map((b) => b.finish()).toList()'; 332 conversion = '$conversion.map((b) => b.finish()).toList()';
324 } else { 333 } else {
325 conversion = '$conversion.toList()'; 334 conversion = '$conversion.toList()';
326 } 335 }
(...skipping 29 matching lines...) Expand all
356 out('Map finish() {'); 365 out('Map finish() {');
357 indent(() { 366 indent(() {
358 out('assert(!_finished);'); 367 out('assert(!_finished);');
359 out('_finished = true;'); 368 out('_finished = true;');
360 out('return _json;'); 369 out('return _json;');
361 }); 370 });
362 out('}'); 371 out('}');
363 }); 372 });
364 out('}'); 373 out('}');
365 out(); 374 out();
366 out('${name}Builder encode$name(builder.BuilderContext builderContext, {${ builderParams.join(', ')}}) {'); 375 out('${name}Builder encode$name(base.BuilderContext builderContext, {${bui lderParams.join(', ')}}) {');
367 indent(() { 376 indent(() {
368 out('${name}Builder builder = new ${name}Builder(builderContext);'); 377 out('${name}Builder builder = new ${name}Builder(builderContext);');
369 cls.fields.forEach((String fieldName, idlModel.FieldType type) { 378 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
370 out('builder.$fieldName = $fieldName;'); 379 out('builder.$fieldName = $fieldName;');
371 }); 380 });
372 out('return builder;'); 381 out('return builder;');
373 }); 382 });
374 out('}'); 383 out('}');
375 out(); 384 out();
376 }); 385 });
377 } 386 }
378 387
379 /** 388 /**
380 * Enclose [s] in quotes, escaping as necessary. 389 * Enclose [s] in quotes, escaping as necessary.
381 */ 390 */
382 String quoted(String s) { 391 String quoted(String s) {
383 return JSON.encode(s); 392 return JSON.encode(s);
384 } 393 }
385 } 394 }
OLDNEW
« no previous file with comments | « pkg/analyzer/tool/summary/build_sdk_summary.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698