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

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

Issue 437643002: Support nullable types in mojom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # This module's classes provide an interface to mojo modules. Modules are 5 # This module's classes provide an interface to mojo modules. Modules are
6 # collections of interfaces and structs to be used by mojo ipc clients and 6 # collections of interfaces and structs to be used by mojo ipc clients and
7 # servers. 7 # servers.
8 # 8 #
9 # A simple interface would be created this way: 9 # A simple interface would be created this way:
10 # module = mojom.generate.module.Module('Foo') 10 # module = mojom.generate.module.Module('Foo')
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 120
121 class Array(Kind): 121 class Array(Kind):
122 def __init__(self, kind=None): 122 def __init__(self, kind=None):
123 self.kind = kind 123 self.kind = kind
124 if kind is not None: 124 if kind is not None:
125 Kind.__init__(self, 'a:' + kind.spec) 125 Kind.__init__(self, 'a:' + kind.spec)
126 else: 126 else:
127 Kind.__init__(self) 127 Kind.__init__(self)
128 128
129
129 class FixedArray(Kind): 130 class FixedArray(Kind):
130 def __init__(self, length, kind=None): 131 def __init__(self, length, kind=None):
131 self.kind = kind 132 self.kind = kind
132 self.length = length 133 self.length = length
133 if kind is not None: 134 if kind is not None:
134 Kind.__init__(self, 'a' + length + ':' + kind.spec) 135 Kind.__init__(self, 'a' + length + ':' + kind.spec)
135 else: 136 else:
136 Kind.__init__(self) 137 Kind.__init__(self)
137 138
139
138 class InterfaceRequest(Kind): 140 class InterfaceRequest(Kind):
139 def __init__(self, kind=None): 141 def __init__(self, kind=None):
140 self.kind = kind 142 self.kind = kind
141 if kind is not None: 143 if kind is not None:
142 Kind.__init__(self, 'r:' + kind.spec) 144 Kind.__init__(self, 'r:' + kind.spec)
143 else: 145 else:
144 Kind.__init__(self) 146 Kind.__init__(self)
145 147
146 148
147 class Parameter(object): 149 class Parameter(object):
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 self.name = name 206 self.name = name
205 self.imported_from = None 207 self.imported_from = None
206 if name is not None: 208 if name is not None:
207 spec = 'x:' + name 209 spec = 'x:' + name
208 else: 210 else:
209 spec = None 211 spec = None
210 Kind.__init__(self, spec) 212 Kind.__init__(self, spec)
211 self.fields = [] 213 self.fields = []
212 214
213 215
216 def SupportsNullable(kind):
217 if isinstance(kind, (Struct, Array, FixedArray, Interface, InterfaceRequest)):
218 return True
219
220 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
221 kind == DPPIPE or kind == MSGPIPE or kind == SHAREDBUFFER)
222
223
224 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
225 def __init__(self, kind=None):
226 Kind.__init__(self)
227 self.kind = None
228
229 if kind is not None:
230 self.SetKind(kind)
231 if kind.spec is not None:
232 self.spec = '?' + kind.spec
233
234 def SetKind(self, kind):
235 if not SupportsNullable(kind):
236 raise Exception(
237 'A type (spec "%s") cannot be made nullable' % kind.spec)
238 self.kind = kind
239
240
214 class Module(object): 241 class Module(object):
215 def __init__(self, name=None, namespace=None): 242 def __init__(self, name=None, namespace=None):
216 self.name = name 243 self.name = name
217 self.path = name 244 self.path = name
218 self.namespace = namespace 245 self.namespace = namespace
219 self.structs = [] 246 self.structs = []
220 self.interfaces = [] 247 self.interfaces = []
221 248
222 def AddInterface(self, name): 249 def AddInterface(self, name):
223 interface=Interface(name, module=self); 250 interface=Interface(name, module=self);
224 self.interfaces.append(interface) 251 self.interfaces.append(interface)
225 return interface 252 return interface
226 253
227 def AddStruct(self, name): 254 def AddStruct(self, name):
228 struct=Struct(name, module=self) 255 struct=Struct(name, module=self)
229 self.structs.append(struct) 256 self.structs.append(struct)
230 return struct 257 return struct
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698