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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_python_generator.py

Issue 622593002: mojo: Allow circular dependencies between structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """Generates Python source files from a mojom.Module.""" 5 """Generates Python source files from a mojom.Module."""
6 6
7 import re 7 import re
8 from itertools import ifilter 8 from itertools import ifilter
9 9
10 import mojom.generate.generator as generator 10 import mojom.generate.generator as generator
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if mojom.IsFixedArrayKind(kind): 139 if mojom.IsFixedArrayKind(kind):
140 arguments.append('length=%d' % kind.length) 140 arguments.append('length=%d' % kind.length)
141 array_type = 'GenericArrayType' 141 array_type = 'GenericArrayType'
142 if kind.kind == mojom.BOOL: 142 if kind.kind == mojom.BOOL:
143 array_type = 'BooleanArrayType' 143 array_type = 'BooleanArrayType'
144 elif kind.kind in _kind_to_typecode_for_native_array: 144 elif kind.kind in _kind_to_typecode_for_native_array:
145 array_type = 'NativeArrayType' 145 array_type = 'NativeArrayType'
146 return '_descriptor.%s(%s)' % (array_type, ', '.join(arguments)) 146 return '_descriptor.%s(%s)' % (array_type, ', '.join(arguments))
147 147
148 if mojom.IsStructKind(kind): 148 if mojom.IsStructKind(kind):
149 arguments = [ GetStructClass(kind) ] 149 arguments = [ 'lambda: %s' % GetStructClass(kind) ]
150 if mojom.IsNullableKind(kind): 150 if mojom.IsNullableKind(kind):
151 arguments.append('nullable=True') 151 arguments.append('nullable=True')
152 return '_descriptor.StructType(%s)' % ', '.join(arguments) 152 return '_descriptor.StructType(%s)' % ', '.join(arguments)
153 153
154 if mojom.IsEnumKind(kind): 154 if mojom.IsEnumKind(kind):
155 return GetFieldType(mojom.INT32) 155 return GetFieldType(mojom.INT32)
156 156
157 return _kind_to_type.get(kind, '_descriptor.TYPE_NONE') 157 return _kind_to_type.get(kind, '_descriptor.TYPE_NONE')
158 158
159 def GetFieldDescriptor(packed_field): 159 def GetFieldDescriptor(packed_field):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 def GetImports(self): 282 def GetImports(self):
283 for each in self.module.imports: 283 for each in self.module.imports:
284 each['python_module'] = each['module_name'].replace('.mojom', '_mojom') 284 each['python_module'] = each['module_name'].replace('.mojom', '_mojom')
285 return self.module.imports 285 return self.module.imports
286 286
287 def GetJinjaParameters(self): 287 def GetJinjaParameters(self):
288 return { 288 return {
289 'lstrip_blocks': True, 289 'lstrip_blocks': True,
290 'trim_blocks': True, 290 'trim_blocks': True,
291 } 291 }
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl ('k') | mojo/python/tests/bindings_structs_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698