Index: bindings/scripts/interface_dependency_resolver.py |
diff --git a/bindings/scripts/interface_dependency_resolver.py b/bindings/scripts/interface_dependency_resolver.py |
index 7bf3b05c0598a715152d0b5e5ce6038479a9afae..79b28ea133445b94448cf0229d84f171bfa38196 100644 |
--- a/bindings/scripts/interface_dependency_resolver.py |
+++ b/bindings/scripts/interface_dependency_resolver.py |
@@ -37,16 +37,17 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler#TOC |
""" |
import os.path |
+from utilities import idl_filename_to_component, is_valid_component_dependency |
# The following extended attributes can be applied to a dependency interface, |
# and are then applied to the individual members when merging. |
# Note that this moves the extended attribute from the interface to the member, |
# which changes the semantics and yields different code than the same extended |
# attribute on the main interface. |
-DEPENDENCY_EXTENDED_ATTRIBUTES = set([ |
+DEPENDENCY_EXTENDED_ATTRIBUTES = frozenset([ |
'Conditional', |
- 'PerContextEnabled', |
'RuntimeEnabled', |
+ 'TypeChecking', |
]) |
@@ -114,52 +115,134 @@ class InterfaceDependencyResolver(object): |
definitions, |
component, |
target_interface, |
- interface_info['dependencies_full_paths'], |
+ interface_info['dependencies_full_paths'] + |
+ interface_info['dependencies_other_component_full_paths'], |
self.reader) |
for referenced_interface_name in interface_info['referenced_interfaces']: |
referenced_definitions = self.reader.read_idl_definitions( |
self.interfaces_info[referenced_interface_name]['full_path']) |
- if component not in referenced_definitions: |
- raise Exception('This definitions: %s is defined in %s ' |
- 'but reference interface:%s is not defined ' |
- 'in %s' % (definitions.idl_name, |
- component, |
- referenced_interface_name, |
- component)) |
+ for referenced_component in referenced_definitions: |
+ if not is_valid_component_dependency(component, referenced_component): |
+ raise Exception('This definitions: %s is defined in %s ' |
+ 'but reference interface:%s is defined ' |
+ 'in %s' % (definitions.idl_name, |
+ component, |
+ referenced_interface_name, |
+ referenced_component)) |
+ |
+ resolved_definitions[component].update(referenced_definitions[component]) |
- resolved_definitions[component].update(referenced_definitions[component]) |
return resolved_definitions |
def merge_interface_dependencies(definitions, component, target_interface, dependency_idl_filenames, reader): |
"""Merge dependencies ('partial interface' and 'implements') in dependency_idl_filenames into target_interface. |
- No return: modifies target_interface in place. |
+ Args: |
+ definitions: IdlDefinitions object, modified in place |
+ component: |
+ string, describing where the above definitions are defined, |
+ 'core' or 'modules'. See KNOWN_COMPONENTS in utilities.py |
+ target_interface: IdlInterface object, modified in place |
+ dependency_idl_filenames: |
+ Idl filenames which depend on the above definitions. |
+ reader: IdlReader object. |
+ Returns: |
+ A dictionary whose key is component and value is IdlDefinitions |
+ object whose dependency is resolved. |
""" |
+ resolved_definitions = {component: definitions} |
# Sort so order consistent, so can compare output from run to run. |
for dependency_idl_filename in sorted(dependency_idl_filenames): |
dependency_definitions = reader.read_idl_file(dependency_idl_filename) |
- # FIXME(crbug.com/358074): should not merge core definitions with |
- # modules definitions. |
+ dependency_component = idl_filename_to_component(dependency_idl_filename) |
+ |
dependency_interface = next(dependency_definitions.interfaces.itervalues()) |
dependency_interface_basename, _ = os.path.splitext(os.path.basename(dependency_idl_filename)) |
transfer_extended_attributes(dependency_interface, |
dependency_interface_basename) |
- definitions.update(dependency_definitions) # merges partial interfaces |
- if not dependency_interface.is_partial: |
+ |
+ # We need to use different checkdeps here for partial interface and |
+ # inheritance. |
+ if dependency_interface.is_partial: |
+ # Case: dependency_interface is a partial interface of |
+ # target_interface. |
+ # So, |
+ # - A partial interface defined in modules can update |
+ # the original interface defined in core. |
+ # However, |
+ # - A partial interface defined in core cannot update |
+ # the original interface defined in modules. |
+ if not is_valid_component_dependency(dependency_component, component): |
+ raise Exception('The partial interface:%s in %s cannot update ' |
+ 'the original interface:%s in %s' % (dependency_interface.name, |
+ dependency_component, |
+ target_interface.name, |
+ component)) |
+ |
+ if dependency_component in resolved_definitions: |
+ # When merging a new partial interfaces, should not overwrite |
+ # ImpelemntedAs extended attributes in merged partial |
+ # interface. |
+ # See also the below "if 'ImplementedAs' not in ... " line's |
+ # comment. |
+ dependency_interface.extended_attributes.pop('ImplementedAs', None) |
+ resolved_definitions[dependency_component].update(dependency_definitions) |
+ continue |
+ |
+ dependency_interface.extended_attributes.update(target_interface.extended_attributes) |
+ assert target_interface == definitions.interfaces[dependency_interface.name] |
+ # A partial interface should use its original interface's |
+ # ImplementedAs. If the original interface doesn't have, |
+ # remove ImplementedAs defined in the partial interface. |
+ # Because partial interface needs the original interface's |
+ # cpp class to obtain partial interface's cpp class. |
+ # e.g.. V8WindowPartial.cpp: |
+ # DOMWindow* impl = V8Window::toImpl(holder); |
+ # RawPtr<...> cppValue(DOMWindowQuota::webkitStorageInfo(impl)); |
+ # TODO(tasak): remove ImplementedAs extended attributes |
+ # from all partial interfaces. Instead, rename all cpp/header |
+ # files correctly. ImplementedAs should not be allowed in |
+ # partial interfaces. |
+ if 'ImplementedAs' not in target_interface.extended_attributes: |
+ dependency_interface.extended_attributes.pop('ImplementedAs', None) |
+ dependency_interface.original_interface = target_interface |
+ target_interface.partial_interfaces.append(dependency_interface) |
+ resolved_definitions[dependency_component] = dependency_definitions |
+ else: |
+ # Case: target_interface implements dependency_interface. |
+ # So, |
+ # - An interface defined in modules can implement some interface |
+ # defined in core. |
+ # In this case, we need "NoInterfaceObject" extended attribute. |
+ # However, |
+ # - An interface defined in core cannot implement any interface |
+ # defined in modules. |
+ if not is_valid_component_dependency(component, dependency_component): |
+ raise Exception('The interface:%s in %s cannot implement ' |
+ 'the interface:%s in %s.' % (dependency_interface.name, |
+ dependency_component, |
+ target_interface.name, |
+ component)) |
+ |
+ if component != dependency_component and 'NoInterfaceObject' not in dependency_interface.extended_attributes: |
+ raise Exception('The interface:%s in %s cannot implement ' |
+ 'the interface:%s in %s because of ' |
+ 'missing NoInterfaceObject.' % (dependency_interface.name, |
+ dependency_component, |
+ target_interface.name, |
+ component)) |
+ |
+ resolved_definitions[component].update(dependency_definitions) # merges partial interfaces |
# Implemented interfaces (non-partial dependencies) are also merged |
# into the target interface, so Code Generator can just iterate |
# over one list (and not need to handle 'implements' itself). |
target_interface.merge(dependency_interface) |
- # FIXME: Currently, this function just returns one IdlDefinitions |
- # instance. However, for partial interface modularization, we need to |
- # make this function return multiple definitions, i.e. |
- # { 'core': ..., 'modules': ... }. |
- return {component: definitions} |
+ return resolved_definitions |
def transfer_extended_attributes(dependency_interface, dependency_interface_basename): |
@@ -211,9 +294,14 @@ def transfer_extended_attributes(dependency_interface, dependency_interface_base |
dependency_interface.extended_attributes.get( |
'ImplementedAs', dependency_interface_basename)) |
+ def update_attributes(attributes, extras): |
+ for key, value in extras.items(): |
+ if key not in attributes: |
+ attributes[key] = value |
+ |
for attribute in dependency_interface.attributes: |
- attribute.extended_attributes.update(merged_extended_attributes) |
+ update_attributes(attribute.extended_attributes, merged_extended_attributes) |
for constant in dependency_interface.constants: |
- constant.extended_attributes.update(merged_extended_attributes) |
+ update_attributes(constant.extended_attributes, merged_extended_attributes) |
for operation in dependency_interface.operations: |
- operation.extended_attributes.update(merged_extended_attributes) |
+ update_attributes(operation.extended_attributes, merged_extended_attributes) |