Chromium Code Reviews| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 (implement.left_interface, implement.right_interface, definition _name)) | 123 (implement.left_interface, implement.right_interface, definition _name)) |
| 124 return left_interfaces, right_interfaces | 124 return left_interfaces, right_interfaces |
| 125 | 125 |
| 126 | 126 |
| 127 def get_put_forward_interfaces_from_definition(definition): | 127 def get_put_forward_interfaces_from_definition(definition): |
| 128 return sorted(set(attribute.idl_type.base_type | 128 return sorted(set(attribute.idl_type.base_type |
| 129 for attribute in definition.attributes | 129 for attribute in definition.attributes |
| 130 if 'PutForwards' in attribute.extended_attributes)) | 130 if 'PutForwards' in attribute.extended_attributes)) |
| 131 | 131 |
| 132 | 132 |
| 133 def get_unforgeable_attributes_from_definition(definition): | |
| 134 return sorted(set(attribute for attribute in definition.attributes | |
|
bashi
2015/07/28 00:38:47
nit: I slightly prefer:
if 'Unforgeable' in defin
Yuki
2015/07/29 08:16:24
Done.
| |
| 135 if 'Unforgeable' in attribute.extended_attributes or | |
| 136 'Unforgeable' in definition.extended_attributes)) | |
| 137 | |
| 138 | |
| 133 def collect_union_types_from_definitions(definitions): | 139 def collect_union_types_from_definitions(definitions): |
| 134 """Traverse definitions and collect all union types.""" | 140 """Traverse definitions and collect all union types.""" |
| 135 class UnionTypeCollector(Visitor): | 141 class UnionTypeCollector(Visitor): |
| 136 def collect(self, definitions): | 142 def collect(self, definitions): |
| 137 self._union_types = set() | 143 self._union_types = set() |
| 138 definitions.accept(self) | 144 definitions.accept(self) |
| 139 return self._union_types | 145 return self._union_types |
| 140 | 146 |
| 141 def visit_typed_object(self, typed_object): | 147 def visit_typed_object(self, typed_object): |
| 142 for attribute_name in typed_object.idl_type_attributes: | 148 for attribute_name in typed_object.idl_type_attributes: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 elif definitions.dictionaries: | 207 elif definitions.dictionaries: |
| 202 definition = next(definitions.dictionaries.itervalues()) | 208 definition = next(definitions.dictionaries.itervalues()) |
| 203 interface_info = { | 209 interface_info = { |
| 204 'is_callback_interface': False, | 210 'is_callback_interface': False, |
| 205 'is_dictionary': True, | 211 'is_dictionary': True, |
| 206 'referenced_interfaces': None, | 212 'referenced_interfaces': None, |
| 207 } | 213 } |
| 208 else: | 214 else: |
| 209 return | 215 return |
| 210 | 216 |
| 217 if definition.name not in self.interfaces_info: | |
| 218 self.interfaces_info[definition.name] = {} | |
|
bashi
2015/07/28 00:38:46
Why do you need this? Can't we just use |interface
Yuki
2015/07/29 08:16:24
Before my change, we didn't update interfaces_info
bashi
2015/07/29 09:24:33
Got it.
| |
| 219 | |
| 220 # Collects [Unforgeable] attributes so that we can define them on | |
| 221 # sub-interfaces. The resulting structure is as follows. | |
| 222 # interfaces_info[interface_name] = { | |
|
bashi
2015/07/28 00:38:46
(BTW, I'm not a big fun of {'core': ..., 'modules'
Yuki
2015/07/29 08:16:24
Acknowledged.
| |
| 223 # 'unforgeable_attributes': { | |
| 224 # 'core': [IdlAttribute, ...], | |
| 225 # 'modules': [IdlAttribute, ...], | |
| 226 # }, | |
| 227 # ... | |
| 228 # } | |
|
bashi
2015/07/28 00:38:47
Can we factor out this block as a method?
Yuki
2015/07/29 08:16:24
Done.
| |
| 229 component = idl_filename_to_component(idl_filename) | |
| 230 if definitions.interfaces: | |
| 231 unforgeable_attributes = get_unforgeable_attributes_from_definition( definition) | |
| 232 if definition.is_partial: | |
| 233 interface_basename, _ = os.path.splitext(os.path.basename(idl_fi lename)) | |
|
bashi
2015/07/28 00:38:46
idl_filename_to_interface_name(idl_filename)
Yuki
2015/07/29 08:16:24
Done.
| |
| 234 for attr in unforgeable_attributes: | |
| 235 attr.extended_attributes['PartialInterfaceImplementedAs'] = definition.extended_attributes.get('ImplementedAs', interface_basename) | |
|
bashi
2015/07/28 00:38:46
We have similar logic in transfer_extended_attribu
Yuki
2015/07/29 08:16:24
Done.
| |
| 236 if unforgeable_attributes: | |
| 237 info = self.interfaces_info[definition.name] | |
| 238 if 'unforgeable_attributes' not in info: | |
| 239 info['unforgeable_attributes'] = {} | |
| 240 if component not in info['unforgeable_attributes']: | |
| 241 info['unforgeable_attributes'][component] = [] | |
| 242 info['unforgeable_attributes'][component].extend(unforgeable_att ributes) | |
| 243 | |
| 211 extended_attributes = definition.extended_attributes | 244 extended_attributes = definition.extended_attributes |
| 212 implemented_as = extended_attributes.get('ImplementedAs') | 245 implemented_as = extended_attributes.get('ImplementedAs') |
| 213 full_path = os.path.realpath(idl_filename) | 246 full_path = os.path.realpath(idl_filename) |
| 214 this_include_path = None if 'NoImplHeader' in extended_attributes else i nclude_path(idl_filename, implemented_as) | 247 this_include_path = None if 'NoImplHeader' in extended_attributes else i nclude_path(idl_filename, implemented_as) |
| 215 if definition.is_partial: | 248 if definition.is_partial: |
| 216 # We don't create interface_info for partial interfaces, but | 249 # We don't create interface_info for partial interfaces, but |
| 217 # adds paths to another dict. | 250 # adds paths to another dict. |
| 218 partial_include_paths = [] | 251 partial_include_paths = [] |
| 219 if this_include_path: | 252 if this_include_path: |
| 220 partial_include_paths.append(this_include_path) | 253 partial_include_paths.append(this_include_path) |
| 221 if this_union_types: | 254 if this_union_types: |
| 222 component = idl_filename_to_component(idl_filename) | |
| 223 partial_include_paths.append( | 255 partial_include_paths.append( |
| 224 'bindings/%s/v8/UnionTypes%s.h' % (component, component.capi talize())) | 256 'bindings/%s/v8/UnionTypes%s.h' % (component, component.capi talize())) |
| 225 self.add_paths_to_partials_dict(definition.name, full_path, partial_ include_paths) | 257 self.add_paths_to_partials_dict(definition.name, full_path, partial_ include_paths) |
| 258 # Collects C++ header paths which should be included from generated | |
| 259 # .cpp files. The resulting structure is as follows. | |
| 260 # interfaces_info[interface_name] = { | |
| 261 # 'cpp_includes': { | |
| 262 # 'core': set(['core/foo/Foo.h', ...]), | |
| 263 # 'modules': set(['modules/bar/Bar.h', ...]), | |
| 264 # }, | |
| 265 # ... | |
| 266 # } | |
| 267 if this_include_path: | |
| 268 info = self.interfaces_info[definition.name] | |
| 269 if 'cpp_includes' not in info: | |
| 270 info['cpp_includes'] = {} | |
| 271 if component not in info['cpp_includes']: | |
| 272 info['cpp_includes'][component] = set() | |
| 273 info['cpp_includes'][component].add(this_include_path) | |
| 226 return | 274 return |
| 227 | 275 |
| 228 # 'implements' statements can be included in either the file for the | 276 # 'implements' statements can be included in either the file for the |
| 229 # implement*ing* interface (lhs of 'implements') or implement*ed* interf ace | 277 # implement*ing* interface (lhs of 'implements') or implement*ed* interf ace |
| 230 # (rhs of 'implements'). Store both for now, then merge to implement*ing * | 278 # (rhs of 'implements'). Store both for now, then merge to implement*ing * |
| 231 # interface later. | 279 # interface later. |
| 232 left_interfaces, right_interfaces = get_implements_from_definitions( | 280 left_interfaces, right_interfaces = get_implements_from_definitions( |
| 233 definitions, definition.name) | 281 definitions, definition.name) |
| 234 | 282 |
| 235 interface_info.update({ | 283 interface_info.update({ |
| 236 'extended_attributes': extended_attributes, | 284 'extended_attributes': extended_attributes, |
| 237 'full_path': full_path, | 285 'full_path': full_path, |
| 238 'has_union_types': bool(this_union_types), | 286 'has_union_types': bool(this_union_types), |
| 239 'implemented_as': implemented_as, | 287 'implemented_as': implemented_as, |
| 240 'implemented_by_interfaces': left_interfaces, | 288 'implemented_by_interfaces': left_interfaces, |
| 241 'implements_interfaces': right_interfaces, | 289 'implements_interfaces': right_interfaces, |
| 242 'include_path': this_include_path, | 290 'include_path': this_include_path, |
|
bashi
2015/07/28 00:38:46
Can we remove this?
Yuki
2015/07/29 08:16:24
No, not at this moment.
'include_path' is require
bashi
2015/07/29 09:24:33
I see. Thanks for the explanation.
| |
| 243 # FIXME: temporary private field, while removing old treatement of | 291 # FIXME: temporary private field, while removing old treatement of |
| 244 # 'implements': http://crbug.com/360435 | 292 # 'implements': http://crbug.com/360435 |
| 245 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterfa ce' in extended_attributes, | 293 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterfa ce' in extended_attributes, |
| 246 'parent': definition.parent, | 294 'parent': definition.parent, |
| 247 'relative_dir': relative_dir_posix(idl_filename), | 295 'relative_dir': relative_dir_posix(idl_filename), |
| 248 }) | 296 }) |
| 249 self.interfaces_info[definition.name] = interface_info | 297 self.interfaces_info[definition.name].update(interface_info) |
| 250 | 298 |
| 251 def get_info_as_dict(self): | 299 def get_info_as_dict(self): |
| 252 """Returns info packaged as a dict.""" | 300 """Returns info packaged as a dict.""" |
| 253 return { | 301 return { |
| 254 'interfaces_info': self.interfaces_info, | 302 'interfaces_info': self.interfaces_info, |
| 255 # Can't pickle defaultdict, convert to dict | 303 # Can't pickle defaultdict, convert to dict |
| 256 # FIXME: this should be included in get_component_info. | 304 # FIXME: this should be included in get_component_info. |
| 257 'partial_interface_files': dict(self.partial_interface_files), | 305 'partial_interface_files': dict(self.partial_interface_files), |
| 258 } | 306 } |
| 259 | 307 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 289 | 337 |
| 290 write_pickle_file(options.interfaces_info_file, | 338 write_pickle_file(options.interfaces_info_file, |
| 291 info_collector.get_info_as_dict(), | 339 info_collector.get_info_as_dict(), |
| 292 options.write_file_only_if_changed) | 340 options.write_file_only_if_changed) |
| 293 write_pickle_file(options.component_info_file, | 341 write_pickle_file(options.component_info_file, |
| 294 info_collector.get_component_info_as_dict(), | 342 info_collector.get_component_info_as_dict(), |
| 295 options.write_file_only_if_changed) | 343 options.write_file_only_if_changed) |
| 296 | 344 |
| 297 if __name__ == '__main__': | 345 if __name__ == '__main__': |
| 298 sys.exit(main()) | 346 sys.exit(main()) |
| OLD | NEW |