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

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

Issue 705093005: Add C++11 enum class support to the Java enum class generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 | build/android/gyp/java_cpp_enum_tests.py » ('j') | 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 8ae5f36becf0d374ed1d741b61f6192eb81fe3b4..b10e7c541a12358aea15804eb98f37bf64a09426 100755
--- a/build/android/gyp/java_cpp_enum.py
+++ b/build/android/gyp/java_cpp_enum.py
@@ -13,14 +13,21 @@ import sys
from util import build_utils
+# List of C++ types that are compatible with the Java code generated by this
+# script.
+ENUM_FIXED_TYPE_WHITELIST = ['char', 'unsigned char',
+ 'short', 'unsigned short',
+ 'int', 'int8_t', 'int16_t', 'int32_t', 'uint8_t', 'uint16_t']
+
class EnumDefinition(object):
def __init__(self, original_enum_name=None, class_name_override=None,
- enum_package=None, entries=None):
+ enum_package=None, entries=None, fixed_type=None):
self.original_enum_name = original_enum_name
self.class_name_override = class_name_override
self.enum_package = enum_package
self.entries = collections.OrderedDict(entries or [])
self.prefix_to_strip = None
+ self.fixed_type = fixed_type
def AppendEntry(self, key, value):
if key in self.entries:
@@ -40,6 +47,9 @@ class EnumDefinition(object):
assert self.class_name
assert self.enum_package
assert self.entries
+ if self.fixed_type and self.fixed_type not in ENUM_FIXED_TYPE_WHITELIST:
+ raise Exception('Fixed type %s for enum %s not whitelisted.' %
+ (self.fixed_type, self.class_name))
def _AssignEntryIndices(self):
# Enums, if given no value, are given the value of the previous enum + 1.
@@ -110,12 +120,17 @@ class DirectiveSet(object):
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]+))?,?')
enum_end_re = re.compile(r'^\s*}\s*;\.*$')
generator_directive_re = re.compile(
r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*([\.\w]+)$')
+ optional_class_or_struct_re = r'(class|struct)?'
+ enum_name_re = r'(\w+)'
+ optional_fixed_type_re = r'(\:\s*(\w+\s*\w+?))?'
+ enum_start_re = re.compile(r'^\s*enum\s+' + optional_class_or_struct_re +
+ '\s*' + enum_name_re + '\s*' + optional_fixed_type_re + '\s*{\s*$')
+
def __init__(self, lines):
self._lines = lines
self._enum_definitions = []
@@ -162,7 +177,8 @@ class HeaderParser(object):
if self._generator_directives.empty:
return
self._current_definition = EnumDefinition(
- original_enum_name=enum_start.groups()[0])
+ original_enum_name=enum_start.groups()[1],
+ fixed_type=enum_start.groups()[3])
self._in_enum = True
elif generator_directive:
directive_name = generator_directive.groups()[0]
« no previous file with comments | « no previous file | build/android/gyp/java_cpp_enum_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698