Chromium Code Reviews| Index: Source/bindings/scripts/interface_dependency_resolver.py |
| diff --git a/Source/bindings/scripts/interface_dependency_resolver.py b/Source/bindings/scripts/interface_dependency_resolver.py |
| index 79b28ea133445b94448cf0229d84f171bfa38196..e643e19d0b7ec407a3708466504c17c0d7988ad8 100644 |
| --- a/Source/bindings/scripts/interface_dependency_resolver.py |
| +++ b/Source/bindings/scripts/interface_dependency_resolver.py |
| @@ -119,6 +119,8 @@ class InterfaceDependencyResolver(object): |
| interface_info['dependencies_other_component_full_paths'], |
| self.reader) |
| + inherit_unforgeable_attributes(resolved_definitions, self.interfaces_info) |
| + |
| for referenced_interface_name in interface_info['referenced_interfaces']: |
| referenced_definitions = self.reader.read_idl_definitions( |
| self.interfaces_info[referenced_interface_name]['full_path']) |
| @@ -305,3 +307,47 @@ def transfer_extended_attributes(dependency_interface, dependency_interface_base |
| update_attributes(constant.extended_attributes, merged_extended_attributes) |
| for operation in dependency_interface.operations: |
| update_attributes(operation.extended_attributes, merged_extended_attributes) |
| + |
| + |
| +def inherit_unforgeable_attributes(resolved_definitions, interfaces_info): |
| + """Inherits [Unforgeable] attributes and updates the arguments accordingly. |
| + |
| + For each interface in |resolved_definitions|, collects all [Unforgeable] |
| + attributes in ancestor interfaces in the same component and adds them to |
| + the interface. 'referenced_interfaces' and 'cpp_includes' in |
| + |interfaces_info| are updated accordingly. |
| + """ |
| + def collect_unforgeable_attributes_in_ancestors(interface_name, component, unforgeable_attributes=None, referenced_interfaces=None, cpp_includes=None): |
| + if unforgeable_attributes is None: |
| + unforgeable_attributes = [] |
| + if referenced_interfaces is None: |
| + referenced_interfaces = [] |
| + if cpp_includes is None: |
| + cpp_includes = set() |
| + if not interface_name: |
| + return unforgeable_attributes, referenced_interfaces, cpp_includes |
| + interface = interfaces_info[interface_name] |
| + attrs = interface.get('unforgeable_attributes', {}).get(component, []) |
| + unforgeable_attributes.extend(attrs) |
| + referenced = [attr.idl_type.base_type for attr in attrs |
| + if attr.idl_type.base_type in |
| + interface.get('referenced_interfaces', [])] |
| + referenced_interfaces.extend(referenced) |
| + cpp_includes.update(interface.get('cpp_includes', {}).get(component, {})) |
| + return collect_unforgeable_attributes_in_ancestors( |
|
bashi
2015/07/28 00:38:47
How about merge-and-return recursive results (unfo
Yuki
2015/07/29 08:16:24
Done.
|
| + interface.get('parent'), component, |
| + unforgeable_attributes, referenced_interfaces, cpp_includes) |
| + |
| + for component, definitions in resolved_definitions.iteritems(): |
| + for interface_name, interface in definitions.interfaces.iteritems(): |
|
bashi
2015/07/28 00:38:47
Help me understand: len(definitions.interfaces) co
Yuki
2015/07/29 08:16:24
For some interfaces, it's greater than one.
It see
bashi
2015/07/29 09:24:33
As chatted offline, this could be executed multipl
Yuki
2015/07/29 09:32:38
I've updated the code so that we don't add any dup
|
| + interface_info = interfaces_info[interface_name] |
| + inherited_unforgeable_attributes, referenced_interfaces, cpp_includes = collect_unforgeable_attributes_in_ancestors(interface_info.get('parent'), component) |
| + interface.attributes.extend(inherited_unforgeable_attributes) |
| + referenced_interfaces.extend(interface_info.get('referenced_interfaces', [])) |
| + interface_info['referenced_interfaces'] = sorted(set(referenced_interfaces)) |
| + cpp_includes.update(interface_info.get('cpp_includes', {}).get(component, set())) |
| + if 'cpp_includes' not in interface_info: |
| + interface_info['cpp_includes'] = {} |
| + if component not in interface_info['cpp_includes']: |
| + interface_info['cpp_includes'][component] = set() |
| + interface_info['cpp_includes'][component].update(cpp_includes) |