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

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

Issue 365993006: Mojo: bindings generator: Add AST types for attributes and attribute lists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 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: 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 cd186f406f355572f41be5ffc6a83bce0d031000..698f963c17eacef8633c0b91903e53a497900488 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py
@@ -51,19 +51,13 @@ def _MapKind(kind):
return map_to_kind[kind]
return 'x:' + kind
-def _MapAttributes(attributes):
- if not attributes:
+def _AttributeListToDict(attribute_list):
+ if attribute_list is None:
return {}
- return dict([(attribute[1], attribute[2])
- for attribute in attributes if attribute[0] == 'ATTRIBUTE'])
-
-def _GetAttribute(attributes, name):
- out = None
- if attributes:
- for attribute in attributes:
- if attribute[0] == 'ATTRIBUTE' and attribute[1] == name:
- out = attribute[2]
- return out
+ assert isinstance(attribute_list, ast.AttributeList)
+ # TODO(vtl): Check for duplicate keys here.
+ return dict([(attribute.key, attribute.value)
+ for attribute in attribute_list])
def _MapField(tree):
assert isinstance(tree[3], ast.Ordinal)
@@ -97,7 +91,7 @@ def _MapEnumField(tree):
def _MapStruct(tree):
struct = {}
struct['name'] = tree[1]
- struct['attributes'] = _MapAttributes(tree[2])
+ struct['attributes'] = _AttributeListToDict(tree[2])
struct['fields'] = _MapTree(_MapField, tree[3], 'FIELD')
struct['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM')
struct['constants'] = _MapTree(_MapConstant, tree[3], 'CONST')
@@ -106,7 +100,8 @@ def _MapStruct(tree):
def _MapInterface(tree):
interface = {}
interface['name'] = tree[1]
- interface['client'] = _GetAttribute(tree[2], 'Client')
+ interface['attributes'] = _AttributeListToDict(tree[2])
+ interface['client'] = interface['attributes'].get('Client')
interface['methods'] = _MapTree(_MapMethod, tree[3], 'METHOD')
interface['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM')
interface['constants'] = _MapTree(_MapConstant, tree[3], 'CONST')
@@ -129,7 +124,7 @@ def _MapModule(tree, name):
mojom = {}
mojom['name'] = name
mojom['namespace'] = tree[1]
- mojom['attributes'] = _MapAttributes(tree[2])
+ mojom['attributes'] = _AttributeListToDict(tree[2])
mojom['structs'] = _MapTree(_MapStruct, tree[3], 'STRUCT')
mojom['interfaces'] = _MapTree(_MapInterface, tree[3], 'INTERFACE')
mojom['enums'] = _MapTree(_MapEnum, tree[3], 'ENUM')

Powered by Google App Engine
This is Rietveld 408576698