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

Unified Diff: third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/parse/translate.py

Issue 877993004: Revert "Update mojo sdk to rev 8d45c89c30b230843c5bd6dd0693a555750946c0" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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: third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
diff --git a/third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/parse/translate.py b/third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
index 8fbc86d154f1a1c115e2b5c23435e1d6bdc88825..88bd2698ade8e5a1e06e7f654187f877bef1a9c3 100644
--- a/third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
+++ b/third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
@@ -55,13 +55,9 @@ def _MapKind(kind):
return map_to_kind[kind]
return 'x:' + kind
-def _AddOptional(dictionary, key, value):
- if value is not None:
- dictionary[key] = value;
-
def _AttributeListToDict(attribute_list):
if attribute_list is None:
- return None
+ return {}
assert isinstance(attribute_list, ast.AttributeList)
# TODO(vtl): Check for duplicate keys here.
return dict([(attribute.key, attribute.value)
@@ -70,17 +66,12 @@ def _AttributeListToDict(attribute_list):
def _EnumToDict(enum):
def EnumValueToDict(enum_value):
assert isinstance(enum_value, ast.EnumValue)
- data = {'name': enum_value.name}
- _AddOptional(data, 'value', enum_value.value)
- _AddOptional(data, 'attributes',
- _AttributeListToDict(enum_value.attribute_list))
- return data
+ return {'name': enum_value.name,
+ 'value': enum_value.value}
assert isinstance(enum, ast.Enum)
- data = {'name': enum.name,
+ return {'name': enum.name,
'fields': map(EnumValueToDict, enum.enum_value_list)}
- _AddOptional(data, 'attributes', _AttributeListToDict(enum.attribute_list))
- return data
def _ConstToDict(const):
assert isinstance(const, ast.Const)
@@ -97,90 +88,71 @@ class _MojomBuilder(object):
def StructToDict(struct):
def StructFieldToDict(struct_field):
assert isinstance(struct_field, ast.StructField)
- data = {'name': struct_field.name,
- 'kind': _MapKind(struct_field.typename)}
- _AddOptional(data, 'ordinal',
- struct_field.ordinal.value
- if struct_field.ordinal else None)
- _AddOptional(data, 'default', struct_field.default_value)
- _AddOptional(data, 'attributes',
- _AttributeListToDict(struct_field.attribute_list))
- return data
+ return {'name': struct_field.name,
+ 'kind': _MapKind(struct_field.typename),
+ 'ordinal': struct_field.ordinal.value \
+ if struct_field.ordinal else None,
+ 'default': struct_field.default_value}
assert isinstance(struct, ast.Struct)
- data = {'name': struct.name,
+ return {'name': struct.name,
+ 'attributes': _AttributeListToDict(struct.attribute_list),
'fields': _MapTreeForType(StructFieldToDict, struct.body,
ast.StructField),
'enums': _MapTreeForType(_EnumToDict, struct.body, ast.Enum),
'constants': _MapTreeForType(_ConstToDict, struct.body,
ast.Const)}
- _AddOptional(data, 'attributes',
- _AttributeListToDict(struct.attribute_list))
- return data
def UnionToDict(union):
def UnionFieldToDict(union_field):
assert isinstance(union_field, ast.UnionField)
- data = {'name': union_field.name,
- 'kind': _MapKind(union_field.typename)}
- _AddOptional(data, 'ordinal',
- union_field.ordinal.value
- if union_field.ordinal else None)
- _AddOptional(data, 'attributes',
- _AttributeListToDict(union_field.attribute_list))
- return data
-
+ return {'name': union_field.name,
+ 'kind': _MapKind(union_field.typename),
+ 'ordinal': union_field.ordinal.value \
+ if union_field.ordinal else None}
assert isinstance(union, ast.Union)
- data = {'name': union.name,
+ return {'name': union.name,
'fields': _MapTreeForType(UnionFieldToDict, union.body,
ast.UnionField)}
- _AddOptional(data, 'attributes',
- _AttributeListToDict(union.attribute_list))
- return data
def InterfaceToDict(interface):
def MethodToDict(method):
def ParameterToDict(param):
assert isinstance(param, ast.Parameter)
- data = {'name': param.name,
- 'kind': _MapKind(param.typename)}
- _AddOptional(data, 'ordinal',
- param.ordinal.value if param.ordinal else None)
- _AddOptional(data, 'attributes',
- _AttributeListToDict(param.attribute_list))
- return data
+ return {'name': param.name,
+ 'kind': _MapKind(param.typename),
+ 'ordinal': param.ordinal.value if param.ordinal else None}
assert isinstance(method, ast.Method)
- data = {'name': method.name,
- 'parameters': map(ParameterToDict, method.parameter_list)}
+ rv = {'name': method.name,
+ 'parameters': map(ParameterToDict, method.parameter_list),
+ 'ordinal': method.ordinal.value if method.ordinal else None}
if method.response_parameter_list is not None:
- data['response_parameters'] = map(ParameterToDict,
- method.response_parameter_list)
- _AddOptional(data, 'ordinal',
- method.ordinal.value if method.ordinal else None)
- _AddOptional(data, 'attributes',
- _AttributeListToDict(method.attribute_list))
- return data
+ rv['response_parameters'] = map(ParameterToDict,
+ method.response_parameter_list)
+ return rv
assert isinstance(interface, ast.Interface)
- data = {'name': interface.name,
+ attributes = _AttributeListToDict(interface.attribute_list)
+ return {'name': interface.name,
+ 'attributes': attributes,
+ 'client': attributes.get('Client'),
'methods': _MapTreeForType(MethodToDict, interface.body,
ast.Method),
'enums': _MapTreeForType(_EnumToDict, interface.body, ast.Enum),
'constants': _MapTreeForType(_ConstToDict, interface.body,
ast.Const)}
- _AddOptional(data, 'attributes',
- _AttributeListToDict(interface.attribute_list))
- return data
assert isinstance(tree, ast.Mojom)
self.mojom['name'] = name
self.mojom['namespace'] = tree.module.name[1] if tree.module else ''
self.mojom['imports'] = \
[{'filename': imp.import_filename} for imp in tree.import_list]
+ self.mojom['attributes'] = \
+ _AttributeListToDict(tree.module.attribute_list) if tree.module else {}
self.mojom['structs'] = \
_MapTreeForType(StructToDict, tree.definition_list, ast.Struct)
- self.mojom['unions'] = \
+ self.mojom['union'] = \
_MapTreeForType(UnionToDict, tree.definition_list, ast.Union)
self.mojom['interfaces'] = \
_MapTreeForType(InterfaceToDict, tree.definition_list, ast.Interface)
@@ -188,9 +160,6 @@ class _MojomBuilder(object):
_MapTreeForType(_EnumToDict, tree.definition_list, ast.Enum)
self.mojom['constants'] = \
_MapTreeForType(_ConstToDict, tree.definition_list, ast.Const)
- _AddOptional(self.mojom, 'attributes',
- _AttributeListToDict(tree.module.attribute_list)
- if tree.module else None)
return self.mojom

Powered by Google App Engine
This is Rietveld 408576698