OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (C) 2013 Google Inc. All rights reserved. | 3 # Copyright (C) 2013 Google Inc. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 41 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
42 """ | 42 """ |
43 | 43 |
44 from collections import defaultdict | 44 from collections import defaultdict |
45 import optparse | 45 import optparse |
46 import os | 46 import os |
47 import posixpath | 47 import posixpath |
48 import sys | 48 import sys |
49 | 49 |
50 from idl_definitions import Visitor | |
50 from idl_reader import IdlReader | 51 from idl_reader import IdlReader |
51 from utilities import get_file_contents, read_file_to_list, idl_filename_to_inte rface_name, idl_filename_to_component, write_pickle_file, get_interface_extended _attributes_from_idl, is_callback_interface_from_idl | 52 from utilities import get_file_contents, read_file_to_list, idl_filename_to_inte rface_name, idl_filename_to_component, write_pickle_file, get_interface_extended _attributes_from_idl, is_callback_interface_from_idl |
52 | 53 |
53 module_path = os.path.dirname(__file__) | 54 module_path = os.path.dirname(__file__) |
54 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) | 55 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) |
55 | 56 |
56 | 57 |
57 class IdlBadFilenameError(Exception): | 58 class IdlBadFilenameError(Exception): |
58 """Raised if an IDL filename disagrees with the interface name in the file." "" | 59 """Raised if an IDL filename disagrees with the interface name in the file." "" |
59 pass | 60 pass |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 | 125 |
125 | 126 |
126 def get_put_forward_interfaces_from_definition(definition): | 127 def get_put_forward_interfaces_from_definition(definition): |
127 return sorted(set(attribute.idl_type.base_type | 128 return sorted(set(attribute.idl_type.base_type |
128 for attribute in definition.attributes | 129 for attribute in definition.attributes |
129 if 'PutForwards' in attribute.extended_attributes)) | 130 if 'PutForwards' in attribute.extended_attributes)) |
130 | 131 |
131 | 132 |
132 def collect_union_types_from_definitions(definitions): | 133 def collect_union_types_from_definitions(definitions): |
133 """Traverse definitions and collect all union types.""" | 134 """Traverse definitions and collect all union types.""" |
135 class UnionTypeCollector(Visitor): | |
136 def collect(self, definitions): | |
137 self._union_types = set() | |
138 definitions.accept(self) | |
139 return self._union_types | |
134 | 140 |
135 def union_types_from(things): | 141 def visit_typed_object(self, typed_object): |
136 return (thing.idl_type for thing in things | 142 for attribute_name in typed_object.idl_type_attributes: |
137 if thing.idl_type.is_union_type) | 143 attribute = getattr(typed_object, attribute_name, None) |
144 if not attribute: | |
145 return | |
Jens Widell
2015/04/10 05:09:39
return => continue
bashi
2015/04/10 05:14:10
Done. Thanks for pointing this out!
| |
146 for idl_type in attribute.idl_types(): | |
147 if idl_type.is_union_type: | |
148 self._union_types.add(idl_type) | |
138 | 149 |
139 this_union_types = set() | 150 return UnionTypeCollector().collect(definitions) |
140 for interface in definitions.interfaces.itervalues(): | |
141 this_union_types.update(union_types_from(interface.attributes)) | |
142 for operation in interface.operations: | |
143 this_union_types.update(union_types_from(operation.arguments)) | |
144 if operation.idl_type.is_union_type: | |
145 this_union_types.add(operation.idl_type) | |
146 for constructor in interface.constructors: | |
147 this_union_types.update(union_types_from(constructor.arguments)) | |
148 for constructor in interface.custom_constructors: | |
149 this_union_types.update(union_types_from(constructor.arguments)) | |
150 for callback_function in definitions.callback_functions.itervalues(): | |
151 this_union_types.update(union_types_from(callback_function.arguments)) | |
152 if callback_function.idl_type.is_union_type: | |
153 this_union_types.add(callback_function.idl_type) | |
154 for dictionary in definitions.dictionaries.itervalues(): | |
155 this_union_types.update(union_types_from(dictionary.members)) | |
156 for typedef in definitions.typedefs.itervalues(): | |
157 if typedef.idl_type.is_union_type: | |
158 this_union_types.add(typedef.idl_type) | |
159 return this_union_types | |
160 | 151 |
161 | 152 |
162 class InterfaceInfoCollector(object): | 153 class InterfaceInfoCollector(object): |
163 """A class that collects interface information from idl files.""" | 154 """A class that collects interface information from idl files.""" |
164 def __init__(self, cache_directory=None): | 155 def __init__(self, cache_directory=None): |
165 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) | 156 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) |
166 self.interfaces_info = {} | 157 self.interfaces_info = {} |
167 self.partial_interface_files = defaultdict(lambda: { | 158 self.partial_interface_files = defaultdict(lambda: { |
168 'full_paths': [], | 159 'full_paths': [], |
169 'include_paths': [], | 160 'include_paths': [], |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 289 |
299 write_pickle_file(options.interfaces_info_file, | 290 write_pickle_file(options.interfaces_info_file, |
300 info_collector.get_info_as_dict(), | 291 info_collector.get_info_as_dict(), |
301 options.write_file_only_if_changed) | 292 options.write_file_only_if_changed) |
302 write_pickle_file(options.component_info_file, | 293 write_pickle_file(options.component_info_file, |
303 info_collector.get_component_info_as_dict(), | 294 info_collector.get_component_info_as_dict(), |
304 options.write_file_only_if_changed) | 295 options.write_file_only_if_changed) |
305 | 296 |
306 if __name__ == '__main__': | 297 if __name__ == '__main__': |
307 sys.exit(main()) | 298 sys.exit(main()) |
OLD | NEW |