Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 This library computes interface dependencies (partial interfaces and | 31 This library computes interface dependencies (partial interfaces and |
| 32 implements), reads the dependency files, and merges them to the IdlDefinitions | 32 implements), reads the dependency files, and merges them to the IdlDefinitions |
| 33 for the main IDL file, producing an IdlDefinitions object representing the | 33 for the main IDL file, producing an IdlDefinitions object representing the |
| 34 entire interface. | 34 entire interface. |
| 35 | 35 |
| 36 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler#TOC -Dependency-resolution | 36 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler#TOC -Dependency-resolution |
| 37 """ | 37 """ |
| 38 | 38 |
| 39 import os.path | 39 import os.path |
| 40 from utilities import idl_filename_to_component, is_valid_component_dependency | 40 from utilities import idl_filename_to_component, is_valid_component_dependency, merge_dict_recursively |
| 41 | 41 |
| 42 # The following extended attributes can be applied to a dependency interface, | 42 # The following extended attributes can be applied to a dependency interface, |
| 43 # and are then applied to the individual members when merging. | 43 # and are then applied to the individual members when merging. |
| 44 # Note that this moves the extended attribute from the interface to the member, | 44 # Note that this moves the extended attribute from the interface to the member, |
| 45 # which changes the semantics and yields different code than the same extended | 45 # which changes the semantics and yields different code than the same extended |
| 46 # attribute on the main interface. | 46 # attribute on the main interface. |
| 47 DEPENDENCY_EXTENDED_ATTRIBUTES = frozenset([ | 47 DEPENDENCY_EXTENDED_ATTRIBUTES = frozenset([ |
| 48 'Conditional', | 48 'Conditional', |
| 49 'RuntimeEnabled', | 49 'RuntimeEnabled', |
| 50 'TypeChecking', | 50 'TypeChecking', |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 interface_info['inherited_extended_attributes']) | 112 interface_info['inherited_extended_attributes']) |
| 113 | 113 |
| 114 resolved_definitions = merge_interface_dependencies( | 114 resolved_definitions = merge_interface_dependencies( |
| 115 definitions, | 115 definitions, |
| 116 component, | 116 component, |
| 117 target_interface, | 117 target_interface, |
| 118 interface_info['dependencies_full_paths'] + | 118 interface_info['dependencies_full_paths'] + |
| 119 interface_info['dependencies_other_component_full_paths'], | 119 interface_info['dependencies_other_component_full_paths'], |
| 120 self.reader) | 120 self.reader) |
| 121 | 121 |
| 122 inherit_unforgeable_attributes(resolved_definitions, self.interfaces_inf o) | |
| 123 | |
| 122 for referenced_interface_name in interface_info['referenced_interfaces'] : | 124 for referenced_interface_name in interface_info['referenced_interfaces'] : |
| 123 referenced_definitions = self.reader.read_idl_definitions( | 125 referenced_definitions = self.reader.read_idl_definitions( |
| 124 self.interfaces_info[referenced_interface_name]['full_path']) | 126 self.interfaces_info[referenced_interface_name]['full_path']) |
| 125 | 127 |
| 126 for referenced_component in referenced_definitions: | 128 for referenced_component in referenced_definitions: |
| 127 if not is_valid_component_dependency(component, referenced_compo nent): | 129 if not is_valid_component_dependency(component, referenced_compo nent): |
| 128 raise Exception('This definitions: %s is defined in %s ' | 130 raise Exception('This definitions: %s is defined in %s ' |
| 129 'but reference interface:%s is defined ' | 131 'but reference interface:%s is defined ' |
| 130 'in %s' % (definitions.idl_name, | 132 'in %s' % (definitions.idl_name, |
| 131 component, | 133 component, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 for key, value in extras.items(): | 300 for key, value in extras.items(): |
| 299 if key not in attributes: | 301 if key not in attributes: |
| 300 attributes[key] = value | 302 attributes[key] = value |
| 301 | 303 |
| 302 for attribute in dependency_interface.attributes: | 304 for attribute in dependency_interface.attributes: |
| 303 update_attributes(attribute.extended_attributes, merged_extended_attribu tes) | 305 update_attributes(attribute.extended_attributes, merged_extended_attribu tes) |
| 304 for constant in dependency_interface.constants: | 306 for constant in dependency_interface.constants: |
| 305 update_attributes(constant.extended_attributes, merged_extended_attribut es) | 307 update_attributes(constant.extended_attributes, merged_extended_attribut es) |
| 306 for operation in dependency_interface.operations: | 308 for operation in dependency_interface.operations: |
| 307 update_attributes(operation.extended_attributes, merged_extended_attribu tes) | 309 update_attributes(operation.extended_attributes, merged_extended_attribu tes) |
| 310 | |
| 311 | |
| 312 def inherit_unforgeable_attributes(resolved_definitions, interfaces_info): | |
| 313 """Inherits [Unforgeable] attributes and updates the arguments accordingly. | |
| 314 | |
| 315 For each interface in |resolved_definitions|, collects all [Unforgeable] | |
| 316 attributes in ancestor interfaces in the same component and adds them to | |
| 317 the interface. 'referenced_interfaces' and 'cpp_includes' in | |
| 318 |interfaces_info| are updated accordingly. | |
| 319 """ | |
| 320 def collect_unforgeable_attributes_in_ancestors(interface_name, component): | |
| 321 if not interface_name: | |
| 322 # unforgeable_attributes, referenced_interfaces, cpp_includes | |
| 323 return [], [], set() | |
| 324 interface = interfaces_info[interface_name] | |
| 325 unforgeable_attributes, referenced_interfaces, cpp_includes = collect_un forgeable_attributes_in_ancestors(interface.get('parent'), component) | |
| 326 this_unforgeable = interface.get('unforgeable_attributes', {}).get(compo nent, []) | |
| 327 unforgeable_attributes.extend(this_unforgeable) | |
| 328 this_referenced = [attr.idl_type.base_type for attr in this_unforgeable | |
| 329 if attr.idl_type.base_type in | |
| 330 interface.get('referenced_interfaces', [])] | |
| 331 referenced_interfaces.extend(this_referenced) | |
| 332 cpp_includes.update(interface.get('cpp_includes', {}).get(component, {}) ) | |
| 333 return unforgeable_attributes, referenced_interfaces, cpp_includes | |
| 334 | |
| 335 for component, definitions in resolved_definitions.iteritems(): | |
| 336 for interface_name, interface in definitions.interfaces.iteritems(): | |
| 337 interface_info = interfaces_info[interface_name] | |
| 338 inherited_unforgeable_attributes, referenced_interfaces, cpp_include s = collect_unforgeable_attributes_in_ancestors(interface_info.get('parent'), co mponent) | |
| 339 # This loop may process the same interface many times, so it's | |
| 340 # possible that we're adding the same attributes twice or more. | |
| 341 # So check if there is a duplicate. | |
| 342 for attr in inherited_unforgeable_attributes: | |
| 343 if attr not in interface.attributes: | |
| 344 interface.attributes.append(attr) | |
| 345 referenced_interfaces.extend(interface_info.get('referenced_interfac es', [])) | |
| 346 interface_info['referenced_interfaces'] = sorted(set(referenced_inte rfaces)) | |
|
tasak
2015/07/29 12:56:45
Just my perfornal preference. I would like to avoi
Yuki
2015/08/03 02:02:13
Very good point. It seems we may need redesign of
| |
| 347 merge_dict_recursively(interface_info, | |
| 348 {'cpp_includes': {component: cpp_includes}}) | |
| OLD | NEW |