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

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

Issue 1420053011: Introduce code to generate summaries from an element model. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove more unnecessary TODOs. Created 5 years, 1 month 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
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 150
151 /** 151 /**
152 * Process the AST in [idlParsed] and store the resulting semantic model in 152 * Process the AST in [idlParsed] and store the resulting semantic model in
153 * [_idl]. Also perform some error checking. 153 * [_idl]. Also perform some error checking.
154 */ 154 */
155 void extractIdl(CompilationUnit idlParsed) { 155 void extractIdl(CompilationUnit idlParsed) {
156 _idl = new idlModel.Idl(); 156 _idl = new idlModel.Idl();
157 for (CompilationUnitMember decl in idlParsed.declarations) { 157 for (CompilationUnitMember decl in idlParsed.declarations) {
158 if (decl is ClassDeclaration) { 158 if (decl is ClassDeclaration) {
159 idlModel.ClassDeclaration cls = new idlModel.ClassDeclaration(); 159 bool isTopLevel = false;
160 for (Annotation annotation in decl.metadata) {
161 if (annotation.arguments == null &&
162 annotation.name.name == 'topLevel') {
163 isTopLevel = true;
164 }
165 }
166 idlModel.ClassDeclaration cls =
167 new idlModel.ClassDeclaration(isTopLevel);
160 _idl.classes[decl.name.name] = cls; 168 _idl.classes[decl.name.name] = cls;
161 for (ClassMember classMember in decl.members) { 169 for (ClassMember classMember in decl.members) {
162 if (classMember is FieldDeclaration) { 170 if (classMember is FieldDeclaration) {
163 TypeName type = classMember.fields.type; 171 TypeName type = classMember.fields.type;
164 bool isList = false; 172 bool isList = false;
165 if (type.name.name == 'List' && 173 if (type.name.name == 'List' &&
166 type.typeArguments != null && 174 type.typeArguments != null &&
167 type.typeArguments.arguments.length == 1) { 175 type.typeArguments.arguments.length == 1) {
168 isList = true; 176 isList = true;
169 type = type.typeArguments.arguments[0]; 177 type = type.typeArguments.arguments[0];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 checkIdl(); 237 checkIdl();
230 out('// Copyright (c) 2015, the Dart project authors. Please see the AUTHOR S file'); 238 out('// Copyright (c) 2015, the Dart project authors. Please see the AUTHOR S file');
231 out('// for details. All rights reserved. Use of this source code is governe d by a'); 239 out('// for details. All rights reserved. Use of this source code is governe d by a');
232 out('// BSD-style license that can be found in the LICENSE file.'); 240 out('// BSD-style license that can be found in the LICENSE file.');
233 out('//'); 241 out('//');
234 out('// This file has been automatically generated. Please do not edit it m anually.'); 242 out('// This file has been automatically generated. Please do not edit it m anually.');
235 out('// To regenerate the file, use the script "pkg/analyzer/tool/generate_f iles".'); 243 out('// To regenerate the file, use the script "pkg/analyzer/tool/generate_f iles".');
236 out(); 244 out();
237 out('library analyzer.src.summary.format;'); 245 out('library analyzer.src.summary.format;');
238 out(); 246 out();
247 out("import 'dart:convert';");
239 out("import 'builder.dart' as builder;"); 248 out("import 'builder.dart' as builder;");
240 out(); 249 out();
241 _idl.enums.forEach((String name, idlModel.EnumDeclaration enm) { 250 _idl.enums.forEach((String name, idlModel.EnumDeclaration enm) {
242 out('enum $name {'); 251 out('enum $name {');
243 indent(() { 252 indent(() {
244 for (String value in enm.values) { 253 for (String value in enm.values) {
245 out('$value,'); 254 out('$value,');
246 } 255 }
247 }); 256 });
248 out('}'); 257 out('}');
(...skipping 25 matching lines...) Expand all
274 } 283 }
275 initializers.add('_$fieldName = $convert'); 284 initializers.add('_$fieldName = $convert');
276 }); 285 });
277 for (int i = 0; i < initializers.length; i++) { 286 for (int i = 0; i < initializers.length; i++) {
278 String prefix = i == 0 ? ': ' : ' '; 287 String prefix = i == 0 ? ': ' : ' ';
279 String suffix = i == initializers.length - 1 ? ';' : ','; 288 String suffix = i == initializers.length - 1 ? ';' : ',';
280 out('$prefix${initializers[i]}$suffix'); 289 out('$prefix${initializers[i]}$suffix');
281 } 290 }
282 }); 291 });
283 out(); 292 out();
293 if (cls.isTopLevel) {
294 out('$name.fromBuffer(List<int> buffer) : this.fromJson(JSON.decode(UT F8.decode(buffer)));');
295 out();
296 }
284 cls.fields.forEach((String fieldName, idlModel.FieldType type) { 297 cls.fields.forEach((String fieldName, idlModel.FieldType type) {
285 String def = defaultValue(type); 298 String def = defaultValue(type);
286 String defaultSuffix = def == null ? '' : ' ?? $def'; 299 String defaultSuffix = def == null ? '' : ' ?? $def';
287 out('${dartType(type)} get $fieldName => _$fieldName$defaultSuffix;'); 300 out('${dartType(type)} get $fieldName => _$fieldName$defaultSuffix;');
288 }); 301 });
289 }); 302 });
290 out('}'); 303 out('}');
291 out(); 304 out();
292 List<String> builderParams = <String>[]; 305 List<String> builderParams = <String>[];
293 out('class ${name}Builder {'); 306 out('class ${name}Builder {');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 }); 349 });
337 } 350 }
338 351
339 /** 352 /**
340 * Enclose [s] in quotes, escaping as necessary. 353 * Enclose [s] in quotes, escaping as necessary.
341 */ 354 */
342 String quoted(String s) { 355 String quoted(String s) {
343 return JSON.encode(s); 356 return JSON.encode(s);
344 } 357 }
345 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698