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

Unified Diff: tools/json_to_struct/struct_generator.py

Issue 1209733002: Add the ability to code generated prepopulated static nested structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_to_struct/struct_generator.py
diff --git a/tools/json_to_struct/struct_generator.py b/tools/json_to_struct/struct_generator.py
index 501cb577e52d38eb6c01febb1ecc23b54c636e40..5849d82b4511d3124c669098c3713ac2aaf532bd 100644
--- a/tools/json_to_struct/struct_generator.py
+++ b/tools/json_to_struct/struct_generator.py
@@ -28,6 +28,8 @@ def GenerateField(field_info):
return 'const %s %s' % (field_info['ctype'], field)
elif type == 'array':
return _GenerateArrayField(field_info)
+ elif type == 'struct':
+ return 'const %s %s' % (field_info['type_name'], field)
else:
raise RuntimeError('Unknown field type "%s"' % type)
@@ -38,6 +40,14 @@ def GenerateStruct(type_name, schema):
lines = [];
lines.append('struct %s {' % type_name)
for field_info in schema:
+ if field_info['type'] == 'struct':
+ lines.insert(0, GenerateStruct(field_info['type_name'],
+ field_info['fields']))
+ elif (field_info['type'] == 'array'
+ and field_info['contents']['type'] == 'struct'):
+ contents = field_info['contents']
+ lines.insert(0, GenerateStruct(contents['type_name'],
+ contents['fields']))
lines.append(' ' + GenerateField(field_info) + ';')
lines.append('};');
return '\n'.join(lines) + '\n';
« 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