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 import mojom | 5 import mojom |
6 | 6 |
7 # mojom_data provides a mechanism to turn mojom Modules to dictionaries and | 7 # mojom_data provides a mechanism to turn mojom Modules to dictionaries and |
8 # back again. This can be used to persist a mojom Module created progromatically | 8 # back again. This can be used to persist a mojom Module created progromatically |
9 # or to read a dictionary from code or a file. | 9 # or to read a dictionary from code or a file. |
10 # Example: | 10 # Example: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 kind.spec = data | 53 kind.spec = data |
54 kinds[data] = kind | 54 kinds[data] = kind |
55 return kind | 55 return kind |
56 | 56 |
57 def ImportFromData(module, data): | 57 def ImportFromData(module, data): |
58 import_module = data['module'] | 58 import_module = data['module'] |
59 | 59 |
60 import_item = {} | 60 import_item = {} |
61 import_item['module_name'] = import_module.name | 61 import_item['module_name'] = import_module.name |
62 import_item['namespace'] = import_module.namespace | 62 import_item['namespace'] = import_module.namespace |
| 63 import_item['module'] = import_module |
63 | 64 |
64 # Copy the struct kinds from our imports into the current module. | 65 # Copy the struct kinds from our imports into the current module. |
65 for kind in import_module.kinds.itervalues(): | 66 for kind in import_module.kinds.itervalues(): |
66 # TODO(mpcomplete): Handle enums | 67 # TODO(mpcomplete): Handle enums |
67 if isinstance(kind, mojom.Struct) and kind.imported_from is None: | 68 if isinstance(kind, mojom.Struct) and kind.imported_from is None: |
68 kind = mojom.Struct.CreateFromImport(kind, import_item) | 69 kind = mojom.Struct.CreateFromImport(kind, import_item) |
69 module.kinds[kind.spec] = kind | 70 module.kinds[kind.spec] = kind |
70 return import_item | 71 return import_item |
71 | 72 |
72 def StructToData(struct): | 73 def StructToData(struct): |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 def OrderedModuleFromData(data): | 211 def OrderedModuleFromData(data): |
211 module = ModuleFromData(data) | 212 module = ModuleFromData(data) |
212 next_interface_ordinal = 0 | 213 next_interface_ordinal = 0 |
213 for interface in module.interfaces: | 214 for interface in module.interfaces: |
214 next_ordinal = 0 | 215 next_ordinal = 0 |
215 for method in interface.methods: | 216 for method in interface.methods: |
216 if method.ordinal is None: | 217 if method.ordinal is None: |
217 method.ordinal = next_ordinal | 218 method.ordinal = next_ordinal |
218 next_ordinal = method.ordinal + 1 | 219 next_ordinal = method.ordinal + 1 |
219 return module | 220 return module |
OLD | NEW |