| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 for constructor in interface.constructors: | 146 for constructor in interface.constructors: |
| 147 this_union_types.update(union_types_from(constructor.arguments)) | 147 this_union_types.update(union_types_from(constructor.arguments)) |
| 148 for constructor in interface.custom_constructors: | 148 for constructor in interface.custom_constructors: |
| 149 this_union_types.update(union_types_from(constructor.arguments)) | 149 this_union_types.update(union_types_from(constructor.arguments)) |
| 150 for callback_function in definitions.callback_functions.itervalues(): | 150 for callback_function in definitions.callback_functions.itervalues(): |
| 151 this_union_types.update(union_types_from(callback_function.arguments)) | 151 this_union_types.update(union_types_from(callback_function.arguments)) |
| 152 if callback_function.idl_type.is_union_type: | 152 if callback_function.idl_type.is_union_type: |
| 153 this_union_types.add(callback_function.idl_type) | 153 this_union_types.add(callback_function.idl_type) |
| 154 for dictionary in definitions.dictionaries.itervalues(): | 154 for dictionary in definitions.dictionaries.itervalues(): |
| 155 this_union_types.update(union_types_from(dictionary.members)) | 155 this_union_types.update(union_types_from(dictionary.members)) |
| 156 for idl_type in definitions.typedefs.itervalues(): |
| 157 if idl_type.is_union_type: |
| 158 this_union_types.add(idl_type) |
| 156 return this_union_types | 159 return this_union_types |
| 157 | 160 |
| 158 | 161 |
| 159 class InterfaceInfoCollector(object): | 162 class InterfaceInfoCollector(object): |
| 160 """A class that collects interface information from idl files.""" | 163 """A class that collects interface information from idl files.""" |
| 161 def __init__(self, cache_directory=None): | 164 def __init__(self, cache_directory=None): |
| 162 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) | 165 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) |
| 163 self.interfaces_info = {} | 166 self.interfaces_info = {} |
| 164 self.partial_interface_files = defaultdict(lambda: { | 167 self.partial_interface_files = defaultdict(lambda: { |
| 165 'full_paths': [], | 168 'full_paths': [], |
| 166 'include_paths': [], | 169 'include_paths': [], |
| 167 }) | 170 }) |
| 168 self.union_types = set() | 171 self.union_types = set() |
| 172 self.typedefs = {} |
| 169 | 173 |
| 170 def add_paths_to_partials_dict(self, partial_interface_name, full_path, | 174 def add_paths_to_partials_dict(self, partial_interface_name, full_path, |
| 171 include_paths): | 175 include_paths): |
| 172 paths_dict = self.partial_interface_files[partial_interface_name] | 176 paths_dict = self.partial_interface_files[partial_interface_name] |
| 173 paths_dict['full_paths'].append(full_path) | 177 paths_dict['full_paths'].append(full_path) |
| 174 paths_dict['include_paths'].extend(include_paths) | 178 paths_dict['include_paths'].extend(include_paths) |
| 175 | 179 |
| 176 def collect_info(self, idl_filename): | 180 def collect_info(self, idl_filename): |
| 177 """Reads an idl file and collects information which is required by the | 181 """Reads an idl file and collects information which is required by the |
| 178 binding code generation.""" | 182 binding code generation.""" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 197 'is_callback_interface': False, | 201 'is_callback_interface': False, |
| 198 'is_dictionary': True, | 202 'is_dictionary': True, |
| 199 'referenced_interfaces': None, | 203 'referenced_interfaces': None, |
| 200 } | 204 } |
| 201 else: | 205 else: |
| 202 raise Exception('IDL file must contain one interface or dictionary') | 206 raise Exception('IDL file must contain one interface or dictionary') |
| 203 | 207 |
| 204 this_union_types = collect_union_types_from_definitions(definitions) | 208 this_union_types = collect_union_types_from_definitions(definitions) |
| 205 self.union_types.update(this_union_types) | 209 self.union_types.update(this_union_types) |
| 206 | 210 |
| 211 self.typedefs.update(definitions.typedefs) |
| 212 |
| 207 extended_attributes = definition.extended_attributes | 213 extended_attributes = definition.extended_attributes |
| 208 implemented_as = extended_attributes.get('ImplementedAs') | 214 implemented_as = extended_attributes.get('ImplementedAs') |
| 209 full_path = os.path.realpath(idl_filename) | 215 full_path = os.path.realpath(idl_filename) |
| 210 this_include_path = None if 'NoImplHeader' in extended_attributes else i
nclude_path(idl_filename, implemented_as) | 216 this_include_path = None if 'NoImplHeader' in extended_attributes else i
nclude_path(idl_filename, implemented_as) |
| 211 if definition.is_partial: | 217 if definition.is_partial: |
| 212 # We don't create interface_info for partial interfaces, but | 218 # We don't create interface_info for partial interfaces, but |
| 213 # adds paths to another dict. | 219 # adds paths to another dict. |
| 214 partial_include_paths = [] | 220 partial_include_paths = [] |
| 215 if this_include_path: | 221 if this_include_path: |
| 216 partial_include_paths.append(this_include_path) | 222 partial_include_paths.append(this_include_path) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return { | 255 return { |
| 250 'interfaces_info': self.interfaces_info, | 256 'interfaces_info': self.interfaces_info, |
| 251 # Can't pickle defaultdict, convert to dict | 257 # Can't pickle defaultdict, convert to dict |
| 252 # FIXME: this should be included in get_component_info. | 258 # FIXME: this should be included in get_component_info. |
| 253 'partial_interface_files': dict(self.partial_interface_files), | 259 'partial_interface_files': dict(self.partial_interface_files), |
| 254 } | 260 } |
| 255 | 261 |
| 256 def get_component_info_as_dict(self): | 262 def get_component_info_as_dict(self): |
| 257 """Returns component wide information as a dict.""" | 263 """Returns component wide information as a dict.""" |
| 258 return { | 264 return { |
| 265 'typedefs': self.typedefs, |
| 259 'union_types': self.union_types, | 266 'union_types': self.union_types, |
| 260 } | 267 } |
| 261 | 268 |
| 262 | 269 |
| 263 ################################################################################ | 270 ################################################################################ |
| 264 | 271 |
| 265 def main(): | 272 def main(): |
| 266 options, args = parse_options() | 273 options, args = parse_options() |
| 267 | 274 |
| 268 # Static IDL files are passed in a file (generated at GYP time), due to OS | 275 # Static IDL files are passed in a file (generated at GYP time), due to OS |
| (...skipping 13 matching lines...) Expand all Loading... |
| 282 | 289 |
| 283 write_pickle_file(options.interfaces_info_file, | 290 write_pickle_file(options.interfaces_info_file, |
| 284 info_collector.get_info_as_dict(), | 291 info_collector.get_info_as_dict(), |
| 285 options.write_file_only_if_changed) | 292 options.write_file_only_if_changed) |
| 286 write_pickle_file(options.component_info_file, | 293 write_pickle_file(options.component_info_file, |
| 287 info_collector.get_component_info_as_dict(), | 294 info_collector.get_component_info_as_dict(), |
| 288 options.write_file_only_if_changed) | 295 options.write_file_only_if_changed) |
| 289 | 296 |
| 290 if __name__ == '__main__': | 297 if __name__ == '__main__': |
| 291 sys.exit(main()) | 298 sys.exit(main()) |
| OLD | NEW |