Chromium Code Reviews| Index: mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
| diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
| index 77e92c5b8b2065c59ebb7453aa18b7b298cce3f9..53bf68bf3198eaec26ea5a0bd411256a3a3f3117 100644 |
| --- a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
| +++ b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
| @@ -18,7 +18,7 @@ def _MapTreeForType(func, tree, type_to_map): |
| _FIXED_ARRAY_REGEXP = re.compile(r'\[[0-9]+\]') |
| -def _MapKind(kind): |
| +def MapKind(kind): |
|
viettrungluu
2014/10/08 16:21:56
Is there a reason you're making this non-private?
Elliot Glaysher
2014/10/08 18:20:51
Because pylint won't let me upload the patch if I
viettrungluu
2014/10/08 18:22:51
Probably you should just suppress that pylint warn
Elliot Glaysher
2014/10/08 19:24:46
Done.
|
| map_to_kind = {'bool': 'b', |
| 'int8': 'i8', |
| 'int16': 'i16', |
| @@ -37,27 +37,31 @@ def _MapKind(kind): |
| 'handle<message_pipe>': 'h:m', |
| 'handle<shared_buffer>': 'h:s'} |
| if kind.endswith('?'): |
| - base_kind = _MapKind(kind[0:-1]) |
| + base_kind = MapKind(kind[0:-1]) |
| # NOTE: This doesn't rule out enum types. Those will be detected later, when |
| # cross-reference is established. |
| - reference_kinds = ('s', 'h', 'a', 'r', 'x') |
| + reference_kinds = ('m', 's', 'h', 'a', 'r', 'x') |
| if base_kind[0] not in reference_kinds: |
| raise Exception( |
| 'A type (spec "%s") cannot be made nullable' % base_kind) |
| return '?' + base_kind |
| + if kind.endswith('}'): |
| + lbracket = kind.rfind('{') |
| + value = kind[0:lbracket] |
| + return 'm[' + MapKind(kind[lbracket+1:-1]) + '][' + MapKind(value) + ']' |
| if kind.endswith('[]'): |
| typename = kind[0:-2] |
| if _FIXED_ARRAY_REGEXP.search(typename): |
| raise Exception('Arrays of fixed sized arrays not supported') |
| - return 'a:' + _MapKind(typename) |
| + return 'a:' + MapKind(typename) |
| if kind.endswith(']'): |
| lbracket = kind.rfind('[') |
| typename = kind[0:lbracket] |
| if typename.find('[') != -1: |
| raise Exception('Fixed sized arrays of arrays not supported') |
| - return 'a' + kind[lbracket+1:-1] + ':' + _MapKind(typename) |
| + return 'a' + kind[lbracket+1:-1] + ':' + MapKind(typename) |
| if kind.endswith('&'): |
| - return 'r:' + _MapKind(kind[0:-1]) |
| + return 'r:' + MapKind(kind[0:-1]) |
| if kind in map_to_kind: |
| return map_to_kind[kind] |
| return 'x:' + kind |
| @@ -83,7 +87,7 @@ def _EnumToDict(enum): |
| def _ConstToDict(const): |
| assert isinstance(const, ast.Const) |
| return {'name': const.name, |
| - 'kind': _MapKind(const.typename), |
| + 'kind': MapKind(const.typename), |
| 'value': const.value} |
| @@ -96,7 +100,7 @@ class _MojomBuilder(object): |
| def StructFieldToDict(struct_field): |
| assert isinstance(struct_field, ast.StructField) |
| return {'name': struct_field.name, |
| - 'kind': _MapKind(struct_field.typename), |
| + 'kind': MapKind(struct_field.typename), |
| 'ordinal': struct_field.ordinal.value \ |
| if struct_field.ordinal else None, |
| 'default': struct_field.default_value} |
| @@ -115,7 +119,7 @@ class _MojomBuilder(object): |
| def ParameterToDict(param): |
| assert isinstance(param, ast.Parameter) |
| return {'name': param.name, |
| - 'kind': _MapKind(param.typename), |
| + 'kind': MapKind(param.typename), |
| 'ordinal': param.ordinal.value if param.ordinal else None} |
| assert isinstance(method, ast.Method) |