| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 # TODO(yzshen): EnumToData() and ConstantToData() are missing. | 202 # TODO(yzshen): EnumToData() and ConstantToData() are missing. |
| 203 istr(2, 'enums'): [], | 203 istr(2, 'enums'): [], |
| 204 istr(3, 'constants'): [] | 204 istr(3, 'constants'): [] |
| 205 } | 205 } |
| 206 AddOptional(data, istr(4, 'attributes'), struct.attributes) | 206 AddOptional(data, istr(4, 'attributes'), struct.attributes) |
| 207 return data | 207 return data |
| 208 | 208 |
| 209 def StructFromData(module, data): | 209 def StructFromData(module, data): |
| 210 struct = mojom.Struct(module=module) | 210 struct = mojom.Struct(module=module) |
| 211 struct.name = data['name'] | 211 struct.name = data['name'] |
| 212 struct.native_only = data['native_only'] |
| 212 struct.spec = 'x:' + module.namespace + '.' + struct.name | 213 struct.spec = 'x:' + module.namespace + '.' + struct.name |
| 213 module.kinds[struct.spec] = struct | 214 module.kinds[struct.spec] = struct |
| 214 struct.enums = map(lambda enum: | 215 if struct.native_only: |
| 215 EnumFromData(module, enum, struct), data['enums']) | 216 struct.enums = [] |
| 216 struct.constants = map(lambda constant: | 217 struct.constants = [] |
| 217 ConstantFromData(module, constant, struct), data['constants']) | 218 struct.fields_data = [] |
| 218 # Stash fields data here temporarily. | 219 else: |
| 219 struct.fields_data = data['fields'] | 220 struct.enums = map(lambda enum: |
| 221 EnumFromData(module, enum, struct), data['enums']) |
| 222 struct.constants = map(lambda constant: |
| 223 ConstantFromData(module, constant, struct), data['constants']) |
| 224 # Stash fields data here temporarily. |
| 225 struct.fields_data = data['fields'] |
| 220 struct.attributes = data.get('attributes') | 226 struct.attributes = data.get('attributes') |
| 227 |
| 228 # Enforce that a [native=True] attribute is set to make native-only struct |
| 229 # declarations more explicit. |
| 230 if struct.native_only: |
| 231 if not struct.attributes or not struct.attributes.get('native', False): |
| 232 raise Exception("Native-only struct declarations must include a " + |
| 233 "native=True attribute.") |
| 234 |
| 221 return struct | 235 return struct |
| 222 | 236 |
| 223 def UnionToData(union): | 237 def UnionToData(union): |
| 224 data = { | 238 data = { |
| 225 istr(0, 'name'): union.name, | 239 istr(0, 'name'): union.name, |
| 226 istr(1, 'fields'): map(FieldToData, union.fields) | 240 istr(1, 'fields'): map(FieldToData, union.fields) |
| 227 } | 241 } |
| 228 AddOptional(data, istr(2, 'attributes'), union.attributes) | 242 AddOptional(data, istr(2, 'attributes'), union.attributes) |
| 229 return data | 243 return data |
| 230 | 244 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 493 |
| 480 def OrderedModuleFromData(data): | 494 def OrderedModuleFromData(data): |
| 481 module = ModuleFromData(data) | 495 module = ModuleFromData(data) |
| 482 for interface in module.interfaces: | 496 for interface in module.interfaces: |
| 483 next_ordinal = 0 | 497 next_ordinal = 0 |
| 484 for method in interface.methods: | 498 for method in interface.methods: |
| 485 if method.ordinal is None: | 499 if method.ordinal is None: |
| 486 method.ordinal = next_ordinal | 500 method.ordinal = next_ordinal |
| 487 next_ordinal = method.ordinal + 1 | 501 next_ordinal = method.ordinal + 1 |
| 488 return module | 502 return module |
| OLD | NEW |