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

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: 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/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 edfe79fc6707f616dd37923dcaf21bcee90baa11..fc28c60112b8f79f47a5dba679f671c127ecc7f1 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.
@@ -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):
Yoyo Zhou 2012/08/27 23:56:04 If you made this public, you wouldn't need to dupl
chebert 2012/08/28 21:31:14 Done.
+ """Returns true if the property is an ENUM or a reference to an ENUM.
Yoyo Zhou 2012/08/27 23:56:04 no
chebert 2012/08/28 21:31:14 Dang. I need to work on my editing. On 2012/08/27
+ """
+ return (self.GetReferencedProperty(prop).type_ == PropertyType.ENUM and
+ prop.type_ != PropertyType.ENUM)
Yoyo Zhou 2012/08/27 23:56:04 I'd put prop.type_ == PropertyType.REF here instea
chebert 2012/08/28 21:31:14 Done.
+
def _NamespaceTypeDependencies(self):
"""Returns a dict containing a mapping of model.Namespace to the C++ type
of type dependencies for self._namespace.

Powered by Google App Engine
This is Rietveld 408576698