| OLD | NEW |
| 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 Loading... |
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 def GetImports(self): | 281 def GetImports(self): |
| 282 for each in self.module.imports: | 282 for each in self.module.imports: |
| 283 each['python_module'] = each['module_name'].replace('.mojom', '_mojom') | 283 each['python_module'] = each['module_name'].replace('.mojom', '_mojom') |
| 284 return self.module.imports | 284 return self.module.imports |
| 285 | 285 |
| 286 def GetJinjaParameters(self): | 286 def GetJinjaParameters(self): |
| 287 return { | 287 return { |
| 288 'lstrip_blocks': True, | 288 'lstrip_blocks': True, |
| 289 'trim_blocks': True, | 289 'trim_blocks': True, |
| 290 } | 290 } |
| OLD | NEW |