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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 kind = mojom.FixedArray(length, KindFromData(kinds, data[colon+1:], scope)) | 127 kind = mojom.FixedArray(length, KindFromData(kinds, data[colon+1:], scope)) |
128 else: | 128 else: |
129 kind = mojom.Kind(data) | 129 kind = mojom.Kind(data) |
130 | 130 |
131 kinds[data] = kind | 131 kinds[data] = kind |
132 return kind | 132 return kind |
133 | 133 |
134 def KindFromImport(original_kind, imported_from): | 134 def KindFromImport(original_kind, imported_from): |
135 """Used with 'import module' - clones the kind imported from the given | 135 """Used with 'import module' - clones the kind imported from the given |
136 module's namespace. Only used with Structs, Interfaces and Enums.""" | 136 module's namespace. Only used with Structs, Interfaces and Enums.""" |
137 kind = copy.deepcopy(original_kind) | 137 kind = copy.copy(original_kind) |
| 138 # |shared_definition| is used to store various properties (see |
| 139 # |AddSharedProperty()| in module.py), including |imported_from|. We don't |
| 140 # want the copy to share these with the original, so copy it if necessary. |
| 141 if hasattr(original_kind, 'shared_definition'): |
| 142 kind.shared_definition = copy.copy(original_kind.shared_definition) |
138 kind.imported_from = imported_from | 143 kind.imported_from = imported_from |
139 return kind | 144 return kind |
140 | 145 |
141 def ImportFromData(module, data): | 146 def ImportFromData(module, data): |
142 import_module = data['module'] | 147 import_module = data['module'] |
143 | 148 |
144 import_item = {} | 149 import_item = {} |
145 import_item['module_name'] = import_module.name | 150 import_item['module_name'] = import_module.name |
146 import_item['namespace'] = import_module.namespace | 151 import_item['namespace'] = import_module.namespace |
147 import_item['module'] = import_module | 152 import_item['module'] = import_module |
148 | 153 |
149 # Copy the struct kinds from our imports into the current module. | 154 # Copy the struct kinds from our imports into the current module. |
150 for kind in import_module.kinds.itervalues(): | 155 for kind in import_module.kinds.itervalues(): |
151 if (isinstance(kind, (mojom.Struct, mojom.Enum, mojom.Interface)) and | 156 if (isinstance(kind, (mojom.Struct, mojom.Enum, mojom.Interface)) and |
152 kind.imported_from is None): | 157 kind.imported_from is None): |
153 kind = KindFromImport(kind, import_item) | 158 kind = KindFromImport(kind, import_item) |
154 module.kinds[kind.spec] = kind | 159 module.kinds[kind.spec] = kind |
155 # Ditto for values. | 160 # Ditto for values. |
156 for value in import_module.values.itervalues(): | 161 for value in import_module.values.itervalues(): |
157 if value.imported_from is None: | 162 if value.imported_from is None: |
158 value = copy.deepcopy(value) | 163 # Values don't have shared definitions (since they're not nullable), so no |
| 164 # need to do anything special. |
| 165 value = copy.copy(value) |
159 value.imported_from = import_item | 166 value.imported_from = import_item |
160 module.values[value.GetSpec()] = value | 167 module.values[value.GetSpec()] = value |
161 | 168 |
162 return import_item | 169 return import_item |
163 | 170 |
164 def StructToData(struct): | 171 def StructToData(struct): |
165 return { | 172 return { |
166 istr(0, 'name'): struct.name, | 173 istr(0, 'name'): struct.name, |
167 istr(1, 'fields'): map(FieldToData, struct.fields) | 174 istr(1, 'fields'): map(FieldToData, struct.fields) |
168 } | 175 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 372 |
366 def OrderedModuleFromData(data): | 373 def OrderedModuleFromData(data): |
367 module = ModuleFromData(data) | 374 module = ModuleFromData(data) |
368 for interface in module.interfaces: | 375 for interface in module.interfaces: |
369 next_ordinal = 0 | 376 next_ordinal = 0 |
370 for method in interface.methods: | 377 for method in interface.methods: |
371 if method.ordinal is None: | 378 if method.ordinal is None: |
372 method.ordinal = next_ordinal | 379 method.ordinal = next_ordinal |
373 next_ordinal = method.ordinal + 1 | 380 next_ordinal = method.ordinal + 1 |
374 return module | 381 return module |
OLD | NEW |