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

Unified Diff: tools/json_schema_compiler/cpp_type_generator.py

Issue 10828407: JSON Schema Compiler supports Enums as types. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: added a todo comment 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
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/h_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/cpp_type_generator.py
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
index acaa52b1295d3462df45c454a4ad8a0a819c5443..95329c3f548614603df6fd0849879f852c57c086 100644
--- a/tools/json_schema_compiler/cpp_type_generator.py
+++ b/tools/json_schema_compiler/cpp_type_generator.py
@@ -98,15 +98,20 @@ class CppTypeGenerator(object):
"""Gets the enum value in the given model.Property indicating no value has
been set.
"""
- return '%s_NONE' % prop.unix_name.upper()
+ prop_name = prop.unix_name
+ if (self.IsEnumRef(prop)):
+ prop_name = self.GetCompiledType(prop).upper()
+ return '%s_NONE' % prop_name.upper()
def GetEnumValue(self, prop, enum_value):
"""Gets the enum value of the given model.Property of the given type.
e.g VAR_STRING
"""
- return '%s_%s' % (
- prop.unix_name.upper(), cpp_util.Classname(enum_value.upper()))
+ prop_name = prop.unix_name.upper()
+ if (self.IsEnumRef(prop)):
+ prop_name = self.GetCompiledType(prop).upper()
+ return '%s_%s' % (prop_name, cpp_util.Classname(enum_value.upper()))
def GetChoicesEnumType(self, prop):
"""Gets the type of the enum for the given model.Property.
@@ -189,7 +194,7 @@ class CppTypeGenerator(object):
# Enums aren't wrapped because C++ won't allow it. Optional enums have a
# NONE value generated instead.
- if wrap_optional and prop.optional and type_ != PropertyType.ENUM:
+ if wrap_optional and prop.optional and not self.IsEnumOrEnumRef(prop):
cpp_type = 'scoped_ptr<%s> ' % cpp_type
if pad_for_generics:
return cpp_type
@@ -263,6 +268,17 @@ class CppTypeGenerator(object):
return self._ResolveTypeNamespace(prop.ref_type).types.get(prop.ref_type,
None)
+ def IsEnumOrEnumRef(self, prop):
+ """Returns true if the property is an ENUM or a reference to an ENUM.
+ """
+ return self.GetReferencedProperty(prop).type_ == PropertyType.ENUM
+
+ def IsEnumRef(self, prop):
+ """Returns true if the property is a reference to an ENUM.
+ """
+ return (prop.type_ == PropertyType.REF and
+ self.GetReferencedProperty(prop).type_ == PropertyType.ENUM)
+
def _NamespaceTypeDependencies(self):
"""Returns a dict containing a mapping of model.Namespace to the C++ type
of type dependencies for self._namespace.
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/h_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698