diff options
author | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 00:28:59 +0000 |
---|---|---|
committer | tsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 00:28:59 +0000 |
commit | 4abb6ccbed7578e5f303b836ea679778becc41eb (patch) | |
tree | cefbe1a831435478aba08aa5e0c06ecdbf0f08c6 /tools/json_schema_compiler | |
parent | 039e40d20c1b1b12fb37f075dab2ebb3f7835f98 (diff) | |
download | chromium_src-4abb6ccbed7578e5f303b836ea679778becc41eb.zip chromium_src-4abb6ccbed7578e5f303b836ea679778becc41eb.tar.gz chromium_src-4abb6ccbed7578e5f303b836ea679778becc41eb.tar.bz2 |
Use validating IPC enum macros in accessibility messages.
This is part of a long-running background task to remove the remaining uses of the unchecked IPC_ENUM_TRAITS() macro.
The most automated way to do this is to tweak the json_schema_compiler to generate these for us. We'd need to do something as currently the idl doesn't support providing values for the corresponding enum
BUG=246708
Review URL: https://codereview.chromium.org/143873021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler')
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 6 | ||||
-rw-r--r-- | tools/json_schema_compiler/h_generator.py | 22 |
2 files changed, 17 insertions, 11 deletions
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 244cbda..e0e8278 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -59,6 +59,12 @@ class CppTypeGenerator(object): """ return '%s_NONE' % self.FollowRef(type_).unix_name.upper() + def GetEnumLastValue(self, type_): + """Gets the enum value in the given model.Property indicating the last value + for the type. + """ + return '%s_LAST' % self.FollowRef(type_).unix_name.upper() + def GetEnumValue(self, type_, enum_value): """Gets the enum value of the given model.Property of the given type. diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py index 0a2dc89..bdbd8a2 100644 --- a/tools/json_schema_compiler/h_generator.py +++ b/tools/json_schema_compiler/h_generator.py @@ -138,14 +138,18 @@ class _Generator(object): return dependency_order def _GenerateEnumDeclaration(self, enum_name, type_): - """Generate the declaration of a C++ enum. + """Generate a code object with the declaration of a C++ enum. """ c = Code() c.Sblock('enum %s {' % enum_name) c.Append(self._type_helper.GetEnumNoneValue(type_) + ',') for value in type_.enum_values: - c.Append(self._type_helper.GetEnumValue(type_, value) + ',') - return c.Eblock('};') + current_enum_string = self._type_helper.GetEnumValue(type_, value) + c.Append(current_enum_string + ',') + c.Append('%s = %s,' % ( + self._type_helper.GetEnumLastValue(type_), current_enum_string)) + c.Eblock('};') + return c def _GenerateFields(self, props): """Generates the field declarations when declaring a type. @@ -205,19 +209,15 @@ class _Generator(object): elif type_.property_type == PropertyType.ENUM: if type_.description: c.Comment(type_.description) - c.Sblock('enum %(classname)s {') - c.Append('%s,' % self._type_helper.GetEnumNoneValue(type_)) - for value in type_.enum_values: - c.Append('%s,' % self._type_helper.GetEnumValue(type_, value)) + c.Cblock(self._GenerateEnumDeclaration(classname, type_)); # Top level enums are in a namespace scope so the methods shouldn't be # static. On the other hand, those declared inline (e.g. in an object) do. maybe_static = '' if is_toplevel else 'static ' - (c.Eblock('};') - .Append() + (c.Append() .Append('%sstd::string ToString(%s as_enum);' % - (maybe_static, classname)) + (maybe_static, classname)) .Append('%s%s Parse%s(const std::string& as_string);' % - (maybe_static, classname, classname)) + (maybe_static, classname, classname)) ) elif type_.property_type in (PropertyType.CHOICES, PropertyType.OBJECT): |