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

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

Issue 2742333005: Move some of analyzer's code generation utilities into front_end. (Closed)
Patch Set: Created 3 years, 9 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
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 writes 16 * Each of the "builder" classes has a single `finish` method which writes
17 * the entity being built into the given FlatBuffer and returns the `Offset` 17 * the entity being built into the given FlatBuffer and returns the `Offset`
18 * reference to it. 18 * reference to it.
19 */ 19 */
20 library analyzer.tool.summary.generate; 20 library analyzer.tool.summary.generate;
21 21
22 import 'dart:convert'; 22 import 'dart:convert';
23 import 'dart:io' hide File; 23 import 'dart:io';
24 24
25 import 'package:analyzer/file_system/file_system.dart'; 25 import 'package:front_end/src/codegen/tools.dart';
26 import 'package:analyzer/file_system/physical_file_system.dart';
27 import 'package:analyzer/src/codegen/tools.dart';
28 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; 26 import 'package:front_end/src/fasta/scanner/string_scanner.dart';
29 import 'package:front_end/src/fasta/scanner/token.dart'; 27 import 'package:front_end/src/fasta/scanner/token.dart';
30 import 'package:path/path.dart'; 28 import 'package:path/path.dart';
31 29
32 import 'idl_model.dart' as idlModel; 30 import 'idl_model.dart' as idlModel;
33 import 'mini_ast.dart'; 31 import 'mini_ast.dart';
34 32
35 main() { 33 main() {
36 String script = Platform.script.toFilePath(windows: Platform.isWindows); 34 String script = Platform.script.toFilePath(windows: Platform.isWindows);
37 String pkgPath = normalize(join(dirname(script), '..', '..')); 35 String pkgPath = normalize(join(dirname(script), '..', '..'));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 */ 71 */
74 String _indentation = ''; 72 String _indentation = '';
75 73
76 /** 74 /**
77 * Semantic model of the "IDL" input file. 75 * Semantic model of the "IDL" input file.
78 */ 76 */
79 idlModel.Idl _idl; 77 idlModel.Idl _idl;
80 78
81 _CodeGenerator(String pkgPath) { 79 _CodeGenerator(String pkgPath) {
82 // Parse the input "IDL" file. 80 // Parse the input "IDL" file.
83 PhysicalResourceProvider provider = new PhysicalResourceProvider(
84 PhysicalResourceProvider.NORMALIZE_EOL_ALWAYS);
85 String idlPath = join(pkgPath, 'lib', 'src', 'summary', 'idl.dart'); 81 String idlPath = join(pkgPath, 'lib', 'src', 'summary', 'idl.dart');
86 File idlFile = provider.getFile(idlPath); 82 File idlFile = new File(idlPath);
87 String idlText = idlFile.readAsStringSync(); 83 String idlText =
84 idlFile.readAsStringSync().replaceAll(new RegExp('\r\n?'), '\n');
88 // Extract a description of the IDL and make sure it is valid. 85 // Extract a description of the IDL and make sure it is valid.
89 var scanner = new StringScanner(idlText, includeComments: true); 86 var scanner = new StringScanner(idlText, includeComments: true);
90 var startingToken = scanner.tokenize(); 87 var startingToken = scanner.tokenize();
91 var listener = new MiniAstBuilder(); 88 var listener = new MiniAstBuilder();
92 var parser = new MiniAstParser(listener); 89 var parser = new MiniAstParser(listener);
93 parser.parseUnit(startingToken); 90 parser.parseUnit(startingToken);
94 extractIdl(listener.compilationUnit); 91 extractIdl(listener.compilationUnit);
95 checkIdl(); 92 checkIdl();
96 } 93 }
97 94
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 Token token = comment.tokens.first; 1005 Token token = comment.tokens.first;
1009 return token.lexeme.split('\n').map((String line) { 1006 return token.lexeme.split('\n').map((String line) {
1010 line = line.trimLeft(); 1007 line = line.trimLeft();
1011 if (line.startsWith('*')) line = ' ' + line; 1008 if (line.startsWith('*')) line = ' ' + line;
1012 return line; 1009 return line;
1013 }).join('\n'); 1010 }).join('\n');
1014 } 1011 }
1015 return null; 1012 return null;
1016 } 1013 }
1017 } 1014 }
OLDNEW
« no previous file with comments | « pkg/analyzer/tool/summary/check_test.dart ('k') | pkg/analyzer/tool/task_dependency_graph/check_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698