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

Side by Side Diff: tools/json_to_struct/struct_generator.py

Issue 11293291: Revert 167793 - Moving prepopulated search engines to a JSON file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « tools/json_to_struct/json_to_struct.py ('k') | tools/json_to_struct/struct_generator_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 def _GenerateArrayField(field_info):
6 """Generate a string defining an array field in a C structure.
7 """
8 contents = field_info['contents']
9 contents['field'] = '* ' + field_info['field']
10 if contents['type'] == 'array':
11 raise RuntimeError('Nested arrays are not supported.')
12 return (GenerateField(contents) + ';\n' +
13 ' const size_t %s_size') % field_info['field'];
14
15 def GenerateField(field_info):
16 """Generate a string defining a field of the type specified by
17 field_info['type'] in a C structure.
18 """
19 field = field_info['field']
20 type = field_info['type']
21 if type == 'int':
22 return 'const int %s' % field
23 elif type == 'string':
24 return 'const char* const %s' % field
25 elif type == 'string16':
26 return 'const wchar_t* const %s' % field
27 elif type == 'enum':
28 return 'const %s %s' % (field_info['ctype'], field)
29 elif type == 'array':
30 return _GenerateArrayField(field_info)
31 else:
32 raise RuntimeError('Unknown field type "%s"' % type)
33
34 def GenerateStruct(type_name, schema):
35 """Generate a string defining a structure containing the fields specified in
36 the schema list.
37 """
38 lines = [];
39 lines.append('struct %s {' % type_name)
40 for field_info in schema:
41 lines.append(' ' + GenerateField(field_info) + ';')
42 lines.append('};');
43 return '\n'.join(lines) + '\n';
OLDNEW
« no previous file with comments | « tools/json_to_struct/json_to_struct.py ('k') | tools/json_to_struct/struct_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698