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

Unified Diff: build/android/gyp/java_cpp_enum.py

Issue 636773002: Extended java_cpp_enum to parse enums with set values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page_info_dialog_shell_only_v2
Patch Set: Indentation fix Created 6 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/java_cpp_enum.py
diff --git a/build/android/gyp/java_cpp_enum.py b/build/android/gyp/java_cpp_enum.py
index ad0974232a07da5cd3d3aad28ef546853d095fae..6a1d5c1e4c39fa54a1c1b2550356a162c2dcb173 100755
--- a/build/android/gyp/java_cpp_enum.py
+++ b/build/android/gyp/java_cpp_enum.py
@@ -36,22 +36,22 @@ class EnumDefinition(object):
assert self.entries
def _AssignEntryIndices(self):
- # Supporting the same set enum value assignments the compiler does is rather
- # complicated, so we limit ourselves to these cases:
- # - all the enum constants have values assigned,
- # - enum constants reference other enum constants or have no value assigned.
-
+ # Enums, if given no value, are given the value of the previous enum + 1.
if not all(self.entries.values()):
- index = 0
+ prev_enum_value = -1
for key, value in self.entries.iteritems():
if not value:
- self.entries[key] = index
- index = index + 1
+ self.entries[key] = prev_enum_value + 1
elif value in self.entries:
self.entries[key] = self.entries[value]
else:
- raise Exception('You can only reference other enum constants unless '
- 'you assign values to all of the constants.')
+ try:
+ self.entries[key] = int(value)
+ except ValueError:
+ raise Exception('Could not interpret integer from enum value "%s" '
+ 'for key %s.' % (value, key))
+ prev_enum_value = self.entries[key]
+
def _StripPrefix(self):
if not self.prefix_to_strip:
@@ -69,7 +69,7 @@ class HeaderParser(object):
single_line_comment_re = re.compile(r'\s*//')
multi_line_comment_start_re = re.compile(r'\s*/\*')
enum_start_re = re.compile(r'^\s*enum\s+(\w+)\s+{\s*$')
- enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?\s*$')
+ enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?')
enum_end_re = re.compile(r'^\s*}\s*;\s*$')
generator_directive_re = re.compile(
r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*([\.\w]+)$')
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698