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 20 matching lines...) Expand all Loading... |
31 # } | 31 # } |
32 # test_module = data.ModuleFromData(test_dict) | 32 # test_module = data.ModuleFromData(test_dict) |
33 | 33 |
34 # Used to create a subclass of str that supports sorting by index, to make | 34 # Used to create a subclass of str that supports sorting by index, to make |
35 # pretty printing maintain the order. | 35 # pretty printing maintain the order. |
36 def istr(index, string): | 36 def istr(index, string): |
37 class IndexedString(str): | 37 class IndexedString(str): |
38 def __lt__(self, other): | 38 def __lt__(self, other): |
39 return self.__index__ < other.__index__ | 39 return self.__index__ < other.__index__ |
40 | 40 |
41 istr = IndexedString(string) | 41 rv = IndexedString(string) |
42 istr.__index__ = index | 42 rv.__index__ = index |
43 return istr | 43 return rv |
44 | 44 |
45 def LookupKind(kinds, spec, scope): | 45 def LookupKind(kinds, spec, scope): |
46 """Tries to find which Kind a spec refers to, given the scope in which its | 46 """Tries to find which Kind a spec refers to, given the scope in which its |
47 referenced. Starts checking from the narrowest scope to most general. For | 47 referenced. Starts checking from the narrowest scope to most general. For |
48 example, given a struct field like | 48 example, given a struct field like |
49 Foo.Bar x; | 49 Foo.Bar x; |
50 Foo.Bar could refer to the type 'Bar' in the 'Foo' namespace, or an inner | 50 Foo.Bar could refer to the type 'Bar' in the 'Foo' namespace, or an inner |
51 type 'Bar' in the struct 'Foo' in the current namespace. | 51 type 'Bar' in the struct 'Foo' in the current namespace. |
52 | 52 |
53 |scope| is a tuple that looks like (namespace, struct/interface), referring | 53 |scope| is a tuple that looks like (namespace, struct/interface), referring |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 del struct.fields_data | 343 del struct.fields_data |
344 for interface in module.interfaces: | 344 for interface in module.interfaces: |
345 interface.methods = map(lambda method: | 345 interface.methods = map(lambda method: |
346 MethodFromData(module, method, interface), interface.methods_data) | 346 MethodFromData(module, method, interface), interface.methods_data) |
347 del interface.methods_data | 347 del interface.methods_data |
348 | 348 |
349 return module | 349 return module |
350 | 350 |
351 def OrderedModuleFromData(data): | 351 def OrderedModuleFromData(data): |
352 module = ModuleFromData(data) | 352 module = ModuleFromData(data) |
353 next_interface_ordinal = 0 | |
354 for interface in module.interfaces: | 353 for interface in module.interfaces: |
355 next_ordinal = 0 | 354 next_ordinal = 0 |
356 for method in interface.methods: | 355 for method in interface.methods: |
357 if method.ordinal is None: | 356 if method.ordinal is None: |
358 method.ordinal = next_ordinal | 357 method.ordinal = next_ordinal |
359 next_ordinal = method.ordinal + 1 | 358 next_ordinal = method.ordinal + 1 |
360 return module | 359 return module |
OLD | NEW |