| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 class InterfaceInfoCollector(object): | 162 class InterfaceInfoCollector(object): |
| 163 """A class that collects interface information from idl files.""" | 163 """A class that collects interface information from idl files.""" |
| 164 def __init__(self, cache_directory=None): | 164 def __init__(self, cache_directory=None): |
| 165 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) | 165 self.reader = IdlReader(interfaces_info=None, outputdir=cache_directory) |
| 166 self.interfaces_info = {} | 166 self.interfaces_info = {} |
| 167 self.partial_interface_files = defaultdict(lambda: { | 167 self.partial_interface_files = defaultdict(lambda: { |
| 168 'full_paths': [], | 168 'full_paths': [], |
| 169 'include_paths': [], | 169 'include_paths': [], |
| 170 }) | 170 }) |
| 171 self.enumerations = set() |
| 171 self.union_types = set() | 172 self.union_types = set() |
| 172 self.typedefs = {} | 173 self.typedefs = {} |
| 173 | 174 |
| 174 def add_paths_to_partials_dict(self, partial_interface_name, full_path, | 175 def add_paths_to_partials_dict(self, partial_interface_name, full_path, |
| 175 include_paths): | 176 include_paths): |
| 176 paths_dict = self.partial_interface_files[partial_interface_name] | 177 paths_dict = self.partial_interface_files[partial_interface_name] |
| 177 paths_dict['full_paths'].append(full_path) | 178 paths_dict['full_paths'].append(full_path) |
| 178 paths_dict['include_paths'].extend(include_paths) | 179 paths_dict['include_paths'].extend(include_paths) |
| 179 | 180 |
| 180 def collect_info(self, idl_filename): | 181 def collect_info(self, idl_filename): |
| (...skipping 19 matching lines...) Expand all Loading... |
| 200 interface_info = { | 201 interface_info = { |
| 201 'is_callback_interface': False, | 202 'is_callback_interface': False, |
| 202 'is_dictionary': True, | 203 'is_dictionary': True, |
| 203 'referenced_interfaces': None, | 204 'referenced_interfaces': None, |
| 204 } | 205 } |
| 205 else: | 206 else: |
| 206 raise Exception('IDL file must contain one interface or dictionary') | 207 raise Exception('IDL file must contain one interface or dictionary') |
| 207 | 208 |
| 208 this_union_types = collect_union_types_from_definitions(definitions) | 209 this_union_types = collect_union_types_from_definitions(definitions) |
| 209 self.union_types.update(this_union_types) | 210 self.union_types.update(this_union_types) |
| 210 | |
| 211 self.typedefs.update(definitions.typedefs) | 211 self.typedefs.update(definitions.typedefs) |
| 212 # Check enum duplication. |
| 213 for enum_name in definitions.enumerations.keys(): |
| 214 for defined_enum in self.enumerations: |
| 215 if defined_enum.name == enum_name: |
| 216 raise Exception('Enumeration %s has multiple definitions' %
enum_name) |
| 217 self.enumerations.update(definitions.enumerations.values()) |
| 212 | 218 |
| 213 extended_attributes = definition.extended_attributes | 219 extended_attributes = definition.extended_attributes |
| 214 implemented_as = extended_attributes.get('ImplementedAs') | 220 implemented_as = extended_attributes.get('ImplementedAs') |
| 215 full_path = os.path.realpath(idl_filename) | 221 full_path = os.path.realpath(idl_filename) |
| 216 this_include_path = None if 'NoImplHeader' in extended_attributes else i
nclude_path(idl_filename, implemented_as) | 222 this_include_path = None if 'NoImplHeader' in extended_attributes else i
nclude_path(idl_filename, implemented_as) |
| 217 if definition.is_partial: | 223 if definition.is_partial: |
| 218 # We don't create interface_info for partial interfaces, but | 224 # We don't create interface_info for partial interfaces, but |
| 219 # adds paths to another dict. | 225 # adds paths to another dict. |
| 220 partial_include_paths = [] | 226 partial_include_paths = [] |
| 221 if this_include_path: | 227 if this_include_path: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return { | 261 return { |
| 256 'interfaces_info': self.interfaces_info, | 262 'interfaces_info': self.interfaces_info, |
| 257 # Can't pickle defaultdict, convert to dict | 263 # Can't pickle defaultdict, convert to dict |
| 258 # FIXME: this should be included in get_component_info. | 264 # FIXME: this should be included in get_component_info. |
| 259 'partial_interface_files': dict(self.partial_interface_files), | 265 'partial_interface_files': dict(self.partial_interface_files), |
| 260 } | 266 } |
| 261 | 267 |
| 262 def get_component_info_as_dict(self): | 268 def get_component_info_as_dict(self): |
| 263 """Returns component wide information as a dict.""" | 269 """Returns component wide information as a dict.""" |
| 264 return { | 270 return { |
| 271 'enumerations': dict((enum.name, enum.values) |
| 272 for enum in self.enumerations), |
| 265 'typedefs': self.typedefs, | 273 'typedefs': self.typedefs, |
| 266 'union_types': self.union_types, | 274 'union_types': self.union_types, |
| 267 } | 275 } |
| 268 | 276 |
| 269 | 277 |
| 270 ################################################################################ | 278 ################################################################################ |
| 271 | 279 |
| 272 def main(): | 280 def main(): |
| 273 options, args = parse_options() | 281 options, args = parse_options() |
| 274 | 282 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 289 | 297 |
| 290 write_pickle_file(options.interfaces_info_file, | 298 write_pickle_file(options.interfaces_info_file, |
| 291 info_collector.get_info_as_dict(), | 299 info_collector.get_info_as_dict(), |
| 292 options.write_file_only_if_changed) | 300 options.write_file_only_if_changed) |
| 293 write_pickle_file(options.component_info_file, | 301 write_pickle_file(options.component_info_file, |
| 294 info_collector.get_component_info_as_dict(), | 302 info_collector.get_component_info_as_dict(), |
| 295 options.write_file_only_if_changed) | 303 options.write_file_only_if_changed) |
| 296 | 304 |
| 297 if __name__ == '__main__': | 305 if __name__ == '__main__': |
| 298 sys.exit(main()) | 306 sys.exit(main()) |
| OLD | NEW |