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

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 10828407: JSON Schema Compiler supports Enums as types. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: more testing of optional enums Created 8 years, 4 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_schema_compiler/h_generator.py
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index e1d9f48b0fa3de3ebefb51f377e172fa6c2eb78d..ae38a6a55c3a07a49a674dde3b241c34e54e33ca 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -158,9 +158,12 @@ class HGenerator(object):
for prop in self._cpp_type_generator.ExpandParams(props):
if prop.description:
c.Comment(prop.description)
+ prop_name = prop.unix_name
Yoyo Zhou 2012/08/27 23:56:04 Is this needed?
chebert 2012/08/28 21:31:14 Done.
+ wrap_optional = not self._cpp_type_generator.IsEnumOrEnumRef(prop)
Yoyo Zhou 2012/08/27 23:56:04 Can you document the reason for this in a comment?
chebert 2012/08/28 21:31:14 Better yet, I will just get rid of it. On 2012/08/
(c.Append('%s %s;' % (
- self._cpp_type_generator.GetCompiledType(prop, wrap_optional=True),
- prop.unix_name))
+ self._cpp_type_generator.GetCompiledType(prop,
+ wrap_optional=wrap_optional),
+ prop_name))
.Append()
)
return c
@@ -189,6 +192,17 @@ class HGenerator(object):
if type_.description:
c.Comment(type_.description)
c.Append('typedef std::string %(classname)s;')
+ elif type_.type_ == PropertyType.ENUM:
+ if type_.description:
+ c.Comment(type_.description)
+ c.Sblock('enum %(classname)s {')
+ for value in type_.enum_values:
+ c.Append('%s_%s,' % (classname.upper(), value.upper()))
+ (c.Eblock('};')
+ .Append()
+ .Append('scoped_ptr<base::Value> CreateEnumValue(%s %s);' %
+ (classname, classname.lower()))
+ )
else:
if type_.description:
c.Comment(type_.description)

Powered by Google App Engine
This is Rietveld 408576698