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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 arguments.append('nullable=True') | 138 arguments.append('nullable=True') |
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.IsMapKind(kind): |
| 149 arguments = [ |
| 150 GetFieldType(kind.key_kind), |
| 151 GetFieldType(kind.value_kind), |
| 152 ] |
| 153 if mojom.IsNullableKind(kind): |
| 154 arguments.append('nullable=True') |
| 155 return '_descriptor.MapType(%s)' % ', '.join(arguments) |
| 156 |
148 if mojom.IsStructKind(kind): | 157 if mojom.IsStructKind(kind): |
149 arguments = [ 'lambda: %s' % GetStructClass(kind) ] | 158 arguments = [ 'lambda: %s' % GetStructClass(kind) ] |
150 if mojom.IsNullableKind(kind): | 159 if mojom.IsNullableKind(kind): |
151 arguments.append('nullable=True') | 160 arguments.append('nullable=True') |
152 return '_descriptor.StructType(%s)' % ', '.join(arguments) | 161 return '_descriptor.StructType(%s)' % ', '.join(arguments) |
153 | 162 |
154 if mojom.IsEnumKind(kind): | 163 if mojom.IsEnumKind(kind): |
155 return GetFieldType(mojom.INT32) | 164 return GetFieldType(mojom.INT32) |
156 | 165 |
157 return _kind_to_type.get(kind, '_descriptor.TYPE_NONE') | 166 return _kind_to_type.get(kind, '_descriptor.TYPE_NONE') |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 def GetImports(self): | 291 def GetImports(self): |
283 for each in self.module.imports: | 292 for each in self.module.imports: |
284 each['python_module'] = each['module_name'].replace('.mojom', '_mojom') | 293 each['python_module'] = each['module_name'].replace('.mojom', '_mojom') |
285 return self.module.imports | 294 return self.module.imports |
286 | 295 |
287 def GetJinjaParameters(self): | 296 def GetJinjaParameters(self): |
288 return { | 297 return { |
289 'lstrip_blocks': True, | 298 'lstrip_blocks': True, |
290 'trim_blocks': True, | 299 'trim_blocks': True, |
291 } | 300 } |
OLD | NEW |