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

Unified Diff: mojo/public/tools/bindings/pylib/mojom/generate/module.py

Issue 611633002: mojom: Add associative arrays to the mojom language. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved test classes to their own shared file. 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
Index: mojo/public/tools/bindings/pylib/mojom/generate/module.py
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/module.py b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
index 7ae7a8321c774040b9f5668f3919a649bcff0688..4f87b35e6a3ff5c650b43ad1ccfdb6164f5b2d9d 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
@@ -228,6 +228,33 @@ class FixedArray(ReferenceKind):
self.length = length
+class Map(ReferenceKind):
+ ReferenceKind.AddSharedProperty('key_kind')
+ ReferenceKind.AddSharedProperty('value_kind')
+
+ def __init__(self, key_kind=None, value_kind=None):
+ if (key_kind is not None and value_kind is not None):
+ ReferenceKind.__init__(self,
+ 'm[' + key_kind.spec + '][' + value_kind.spec +
+ ']')
+ if IsNullableKind(key_kind):
+ raise Exception("Nullable kinds can not be keys in maps.")
+ if IsStructKind(key_kind):
+ # TODO(erg): It would sometimes be nice if we could key on struct
+ # values. However, what happens if the struct has a handle in it? Or
+ # non-copyable data like an array?
+ raise Exception("Structs can not be keys in maps.")
+ if IsAnyHandleKind(key_kind):
+ raise Exception("Handles can not be keys in maps.")
+ if IsAnyArrayKind(key_kind):
+ raise Exception("Arrays can not be keys in maps.")
+ else:
+ ReferenceKind.__init__(self)
+
+ self.key_kind = key_kind
+ self.value_kind = value_kind
+
+
class InterfaceRequest(ReferenceKind):
ReferenceKind.AddSharedProperty('kind')
@@ -399,8 +426,13 @@ def IsAnyArrayKind(kind):
return IsArrayKind(kind) or IsFixedArrayKind(kind)
+def IsMapKind(kind):
+ return isinstance(kind, Map)
+
+
def IsObjectKind(kind):
- return IsStructKind(kind) or IsAnyArrayKind(kind) or IsStringKind(kind)
+ return (IsStructKind(kind) or IsAnyArrayKind(kind) or IsStringKind(kind) or
+ IsMapKind(kind))
def IsNonInterfaceHandleKind(kind):
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/data.py ('k') | mojo/public/tools/bindings/pylib/mojom/generate/pack.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698