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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 (implement.left_interface, implement.right_interface, definition _name)) | 123 (implement.left_interface, implement.right_interface, definition _name)) |
123 return left_interfaces, right_interfaces | 124 return left_interfaces, right_interfaces |
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 class UnionTypeCollector(Visitor): |
Jens Widell
2015/04/08 09:35:19
I guess we could have kept a collect_union_types_f
bashi
2015/04/10 00:05:14
Done.
| |
133 """Traverse definitions and collect all union types.""" | 134 """Traverse definitions and collect all union types.""" |
134 | 135 |
135 def union_types_from(things): | 136 def collect(self, definitions): |
136 return (thing.idl_type for thing in things | 137 self._union_types = set() |
137 if thing.idl_type.is_union_type) | 138 definitions.accept(self) |
139 return self._union_types | |
138 | 140 |
139 this_union_types = set() | 141 def visit_typed_object(self, typed_object): |
140 for interface in definitions.interfaces.itervalues(): | 142 try: |
141 this_union_types.update(union_types_from(interface.attributes)) | 143 idl_type = getattr(typed_object, 'idl_type') |
Jens Widell
2015/04/08 09:35:19
It would be better to use typed_object.idl_type_at
bashi
2015/04/10 00:05:14
Done.
| |
142 for operation in interface.operations: | 144 except AttributeError: |
143 this_union_types.update(union_types_from(operation.arguments)) | 145 return |
144 if operation.idl_type.is_union_type: | 146 if not idl_type: |
145 this_union_types.add(operation.idl_type) | 147 return |
146 for constructor in interface.constructors: | 148 if idl_type.is_union_type: |
147 this_union_types.update(union_types_from(constructor.arguments)) | 149 self._union_types.add(idl_type) |
148 for constructor in interface.custom_constructors: | 150 if idl_type.element_type and idl_type.element_type.is_union_type: |
Jens Widell
2015/04/08 09:35:19
I think it would be better to have a process_type(
bashi
2015/04/10 00:05:14
Good suggestion. I added idl_types() to IdlTypeBas
| |
149 this_union_types.update(union_types_from(constructor.arguments)) | 151 self._union_types.add(idl_type.element_type) |
150 for callback_function in definitions.callback_functions.itervalues(): | 152 if idl_type.inner_type and idl_type.inner_type.is_union_type: |
151 this_union_types.update(union_types_from(callback_function.arguments)) | 153 self._union_types.add(idl_type.inner_type) |
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 | 154 |
161 | 155 |
162 class InterfaceInfoCollector(object): | 156 class InterfaceInfoCollector(object): |
163 """A class that collects interface information from idl files.""" | 157 """A class that collects interface information from idl files.""" |
164 def __init__(self, cache_directory=None): | 158 def __init__(self, cache_directory=None): |
165 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) | 159 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) |
166 self.interfaces_info = {} | 160 self.interfaces_info = {} |
167 self.partial_interface_files = defaultdict(lambda: { | 161 self.partial_interface_files = defaultdict(lambda: { |
168 'full_paths': [], | 162 'full_paths': [], |
169 'include_paths': [], | 163 'include_paths': [], |
170 }) | 164 }) |
171 self.enumerations = set() | 165 self.enumerations = set() |
172 self.union_types = set() | 166 self.union_types = set() |
173 self.typedefs = {} | 167 self.typedefs = {} |
174 | 168 |
175 def add_paths_to_partials_dict(self, partial_interface_name, full_path, | 169 def add_paths_to_partials_dict(self, partial_interface_name, full_path, |
176 include_paths): | 170 include_paths): |
177 paths_dict = self.partial_interface_files[partial_interface_name] | 171 paths_dict = self.partial_interface_files[partial_interface_name] |
178 paths_dict['full_paths'].append(full_path) | 172 paths_dict['full_paths'].append(full_path) |
179 paths_dict['include_paths'].extend(include_paths) | 173 paths_dict['include_paths'].extend(include_paths) |
180 | 174 |
181 def collect_info(self, idl_filename): | 175 def collect_info(self, idl_filename): |
182 """Reads an idl file and collects information which is required by the | 176 """Reads an idl file and collects information which is required by the |
183 binding code generation.""" | 177 binding code generation.""" |
184 definitions = self.reader.read_idl_file(idl_filename) | 178 definitions = self.reader.read_idl_file(idl_filename) |
185 | 179 |
186 this_union_types = collect_union_types_from_definitions(definitions) | 180 this_union_types = UnionTypeCollector().collect(definitions) |
187 self.union_types.update(this_union_types) | 181 self.union_types.update(this_union_types) |
188 self.typedefs.update(definitions.typedefs) | 182 self.typedefs.update(definitions.typedefs) |
189 # Check enum duplication. | 183 # Check enum duplication. |
190 for enum_name in definitions.enumerations.keys(): | 184 for enum_name in definitions.enumerations.keys(): |
191 for defined_enum in self.enumerations: | 185 for defined_enum in self.enumerations: |
192 if defined_enum.name == enum_name: | 186 if defined_enum.name == enum_name: |
193 raise Exception('Enumeration %s has multiple definitions' % enum_name) | 187 raise Exception('Enumeration %s has multiple definitions' % enum_name) |
194 self.enumerations.update(definitions.enumerations.values()) | 188 self.enumerations.update(definitions.enumerations.values()) |
195 | 189 |
196 if definitions.interfaces: | 190 if definitions.interfaces: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 292 |
299 write_pickle_file(options.interfaces_info_file, | 293 write_pickle_file(options.interfaces_info_file, |
300 info_collector.get_info_as_dict(), | 294 info_collector.get_info_as_dict(), |
301 options.write_file_only_if_changed) | 295 options.write_file_only_if_changed) |
302 write_pickle_file(options.component_info_file, | 296 write_pickle_file(options.component_info_file, |
303 info_collector.get_component_info_as_dict(), | 297 info_collector.get_component_info_as_dict(), |
304 options.write_file_only_if_changed) | 298 options.write_file_only_if_changed) |
305 | 299 |
306 if __name__ == '__main__': | 300 if __name__ == '__main__': |
307 sys.exit(main()) | 301 sys.exit(main()) |
OLD | NEW |