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

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: Created 5 years, 6 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
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..ea592f06a93cd19e435a50dcf037eeda113e0a49 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 == 'object':
beaudoin 2015/07/06 16:01:12 Would 'struct' be better than 'object' given that
danduong 2015/07/08 23:07:03 Done.
+ 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'] == 'object':
+ lines.insert(0, GenerateStruct(field_info['type_name'],
+ field_info['fields']))
+ elif (field_info['type'] == 'array'
+ and field_info['contents']['type'] == 'object'):
+ 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';

Powered by Google App Engine
This is Rietveld 408576698