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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 def KindToData(kind): | 80 def KindToData(kind): |
81 return kind.spec | 81 return kind.spec |
82 | 82 |
83 def KindFromData(kinds, data, scope): | 83 def KindFromData(kinds, data, scope): |
84 kind = LookupKind(kinds, data, scope) | 84 kind = LookupKind(kinds, data, scope) |
85 if kind: | 85 if kind: |
86 return kind | 86 return kind |
87 if data.startswith('a:'): | 87 if data.startswith('a:'): |
88 kind = mojom.Array() | 88 kind = mojom.Array() |
89 kind.kind = KindFromData(kinds, data[2:], scope) | 89 kind.kind = KindFromData(kinds, data[2:], scope) |
| 90 elif data.startswith('r:'): |
| 91 kind = mojom.InterfaceRequest() |
| 92 kind.kind = KindFromData(kinds, data[2:], scope) |
90 else: | 93 else: |
91 kind = mojom.Kind() | 94 kind = mojom.Kind() |
92 kind.spec = data | 95 kind.spec = data |
93 kinds[data] = kind | 96 kinds[data] = kind |
94 return kind | 97 return kind |
95 | 98 |
96 def KindFromImport(original_kind, imported_from): | 99 def KindFromImport(original_kind, imported_from): |
97 """Used with 'import module' - clones the kind imported from the | 100 """Used with 'import module' - clones the kind imported from the given |
98 given module's namespace. Only used with Structs and Enums.""" | 101 module's namespace. Only used with Structs, Interfaces and Enums.""" |
99 kind = copy.deepcopy(original_kind) | 102 kind = copy.deepcopy(original_kind) |
100 kind.imported_from = imported_from | 103 kind.imported_from = imported_from |
101 return kind | 104 return kind |
102 | 105 |
103 def ImportFromData(module, data): | 106 def ImportFromData(module, data): |
104 import_module = data['module'] | 107 import_module = data['module'] |
105 | 108 |
106 import_item = {} | 109 import_item = {} |
107 import_item['module_name'] = import_module.name | 110 import_item['module_name'] = import_module.name |
108 import_item['namespace'] = import_module.namespace | 111 import_item['namespace'] = import_module.namespace |
109 import_item['module'] = import_module | 112 import_item['module'] = import_module |
110 | 113 |
111 # Copy the struct kinds from our imports into the current module. | 114 # Copy the struct kinds from our imports into the current module. |
112 for kind in import_module.kinds.itervalues(): | 115 for kind in import_module.kinds.itervalues(): |
113 if (isinstance(kind, (mojom.Struct, mojom.Enum)) and | 116 if (isinstance(kind, (mojom.Struct, mojom.Enum, mojom.Interface)) and |
114 kind.imported_from is None): | 117 kind.imported_from is None): |
115 kind = KindFromImport(kind, import_item) | 118 kind = KindFromImport(kind, import_item) |
116 module.kinds[kind.spec] = kind | 119 module.kinds[kind.spec] = kind |
117 # Ditto for values. | 120 # Ditto for values. |
118 for value in import_module.values.itervalues(): | 121 for value in import_module.values.itervalues(): |
119 if value.imported_from is None: | 122 if value.imported_from is None: |
120 value = copy.deepcopy(value) | 123 value = copy.deepcopy(value) |
121 value.imported_from = import_item | 124 value.imported_from = import_item |
122 module.values[value.GetSpec()] = value | 125 module.values[value.GetSpec()] = value |
123 | 126 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 def OrderedModuleFromData(data): | 344 def OrderedModuleFromData(data): |
342 module = ModuleFromData(data) | 345 module = ModuleFromData(data) |
343 next_interface_ordinal = 0 | 346 next_interface_ordinal = 0 |
344 for interface in module.interfaces: | 347 for interface in module.interfaces: |
345 next_ordinal = 0 | 348 next_ordinal = 0 |
346 for method in interface.methods: | 349 for method in interface.methods: |
347 if method.ordinal is None: | 350 if method.ordinal is None: |
348 method.ordinal = next_ordinal | 351 method.ordinal = next_ordinal |
349 next_ordinal = method.ordinal + 1 | 352 next_ordinal = method.ordinal + 1 |
350 return module | 353 return module |
OLD | NEW |