OLD | NEW |
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 # TODO(vtl): "data" is a pretty vague name. Rename it? | 5 # TODO(vtl): "data" is a pretty vague name. Rename it? |
6 | 6 |
7 import copy | 7 import copy |
8 | 8 |
9 import module as mojom | 9 import module as mojom |
10 | 10 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 struct.fields_data = [] | 218 struct.fields_data = [] |
219 else: | 219 else: |
220 struct.enums = map(lambda enum: | 220 struct.enums = map(lambda enum: |
221 EnumFromData(module, enum, struct), data['enums']) | 221 EnumFromData(module, enum, struct), data['enums']) |
222 struct.constants = map(lambda constant: | 222 struct.constants = map(lambda constant: |
223 ConstantFromData(module, constant, struct), data['constants']) | 223 ConstantFromData(module, constant, struct), data['constants']) |
224 # Stash fields data here temporarily. | 224 # Stash fields data here temporarily. |
225 struct.fields_data = data['fields'] | 225 struct.fields_data = data['fields'] |
226 struct.attributes = data.get('attributes') | 226 struct.attributes = data.get('attributes') |
227 | 227 |
228 # Enforce that a [native=True] attribute is set to make native-only struct | 228 # Enforce that a [Native=True] attribute is set to make native-only struct |
229 # declarations more explicit. | 229 # declarations more explicit. |
230 if struct.native_only: | 230 if struct.native_only: |
231 if not struct.attributes or not struct.attributes.get('native', False): | 231 if not struct.attributes or not struct.attributes.get('Native', False): |
232 raise Exception("Native-only struct declarations must include a " + | 232 raise Exception("Native-only struct declarations must include a " + |
233 "native=True attribute.") | 233 "Native=True attribute.") |
234 | 234 |
235 return struct | 235 return struct |
236 | 236 |
237 def UnionToData(union): | 237 def UnionToData(union): |
238 data = { | 238 data = { |
239 istr(0, 'name'): union.name, | 239 istr(0, 'name'): union.name, |
240 istr(1, 'fields'): map(FieldToData, union.fields) | 240 istr(1, 'fields'): map(FieldToData, union.fields) |
241 } | 241 } |
242 AddOptional(data, istr(2, 'attributes'), union.attributes) | 242 AddOptional(data, istr(2, 'attributes'), union.attributes) |
243 return data | 243 return data |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 493 |
494 def OrderedModuleFromData(data): | 494 def OrderedModuleFromData(data): |
495 module = ModuleFromData(data) | 495 module = ModuleFromData(data) |
496 for interface in module.interfaces: | 496 for interface in module.interfaces: |
497 next_ordinal = 0 | 497 next_ordinal = 0 |
498 for method in interface.methods: | 498 for method in interface.methods: |
499 if method.ordinal is None: | 499 if method.ordinal is None: |
500 method.ordinal = next_ordinal | 500 method.ordinal = next_ordinal |
501 next_ordinal = method.ordinal + 1 | 501 next_ordinal = method.ordinal + 1 |
502 return module | 502 return module |
OLD | NEW |