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 c55b85e2e3313667dfaafb2bde993cbc12570ea2..c69a72610a39a2aa7f9d8d1959116d0542999d7a 100644 |
--- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py |
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py |
@@ -126,6 +126,7 @@ class Array(Kind): |
else: |
Kind.__init__(self) |
+ |
class FixedArray(Kind): |
def __init__(self, length, kind=None): |
self.kind = kind |
@@ -135,6 +136,7 @@ class FixedArray(Kind): |
else: |
Kind.__init__(self) |
+ |
class InterfaceRequest(Kind): |
def __init__(self, kind=None): |
self.kind = kind |
@@ -211,6 +213,31 @@ class Enum(Kind): |
self.fields = [] |
+def SupportsNullable(kind): |
+ if isinstance(kind, (Struct, Array, FixedArray, Interface, InterfaceRequest)): |
+ return True |
+ |
+ return (kind == STRING or kind == HANDLE or kind == DCPIPE or |
darin (slow to review)
2014/08/03 05:57:58
what does it mean for a handle-type to be nullable
yzshen1
2014/08/03 08:27:46
I think for a handle type, nullable means it could
|
+ kind == DPPIPE or kind == MSGPIPE or kind == SHAREDBUFFER) |
+ |
+ |
+class Nullable(Kind): |
darin (slow to review)
2014/08/03 05:57:58
I'm kind of surprised to see Nullable as a subclas
yzshen1
2014/08/03 08:27:46
I agree that it should be redesigned. The biggest
|
+ def __init__(self, kind=None): |
+ Kind.__init__(self) |
+ self.kind = None |
+ |
+ if kind is not None: |
+ self.SetKind(kind) |
+ if kind.spec is not None: |
+ self.spec = '?' + kind.spec |
+ |
+ def SetKind(self, kind): |
+ if not SupportsNullable(kind): |
+ raise Exception( |
+ 'A type (spec "%s") cannot be made nullable' % kind.spec) |
+ self.kind = kind |
+ |
+ |
class Module(object): |
def __init__(self, name=None, namespace=None): |
self.name = name |