Commit 9abe68fb authored by nbarth@chromium.org's avatar nbarth@chromium.org

Clean up compute_interfaces_info.py

This is the compute_interfaces_info.py side of the post-split cleanup.
This finishes the build factoring.
(Still need to add more caching for speed and some more use
of Jinja for clarity, but mostly done with build.)

Two notable changes:
* We only need to store *inherited* extended attributes, not all extended
 attributes (in auxiliary variable; needed more for event interfaces, gone now).
 This simplifies the inheritance resolution, and reduces duplication.

* Always include the same keys in the info dict, even if the value is empty.
 This simplifies both setting (since no test) and use:
 instead of having "if key in dict and dict[key]..."
 we can just have "if dict[key]".
 It also helps consistency, since we were doing it 2 ways before.

BUG=341748
R=haraken

Review URL: https://codereview.chromium.org/183853024

git-svn-id: svn://svn.chromium.org/blink/trunk@168610 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 64aa1a55
......@@ -89,7 +89,7 @@ class CodeGeneratorV8(object):
v8_types.set_ancestors(dict(
(interface_name, interface_info['ancestors'])
for interface_name, interface_info in interfaces_info.iteritems()
if 'ancestors' in interface_info))
if interface_info['ancestors']))
v8_types.set_callback_interfaces(set(
interface_name
for interface_name, interface_info in interfaces_info.iteritems()
......@@ -97,12 +97,11 @@ class CodeGeneratorV8(object):
v8_types.set_implemented_as_interfaces(dict(
(interface_name, interface_info['implemented_as'])
for interface_name, interface_info in interfaces_info.iteritems()
if 'implemented_as' in interface_info))
if interface_info['implemented_as']))
v8_types.set_will_be_garbage_collected_types(set(
interface_name
for interface_name, interface_info in interfaces_info.iteritems()
if 'inherited_extended_attributes' in interface_info and
'WillBeGarbageCollected' in interface_info['inherited_extended_attributes']))
if 'WillBeGarbageCollected' in interface_info['inherited_extended_attributes']))
def generate_code(self, definitions, interface_name):
"""Returns .h/.cpp code as (header_text, cpp_text)."""
......
......@@ -98,7 +98,7 @@ interfaces_info = {}
# Auxiliary variables (not visible to future build steps)
partial_interface_files = {}
parent_interfaces = {}
extended_attributes_by_interface = {} # interface name -> extended attributes
inherited_extended_attributes_by_interface = {} # interface name -> extended attributes
class IdlInterfaceFileNotFoundError(Exception):
......@@ -174,7 +174,9 @@ def compute_individual_info(idl_filename):
interfaces_info[interface_name] = {
'full_path': full_path,
'implemented_as': implemented_as,
'implements_interfaces': get_implemented_interfaces_from_idl(idl_file_contents, interface_name),
'include_path': this_include_path,
'is_callback_interface': is_callback_interface_from_idl(idl_file_contents),
# Interfaces that are referenced (used as types) and that we introspect
# during code generation (beyond interface-level data ([ImplementedAs],
......@@ -184,50 +186,37 @@ def compute_individual_info(idl_filename):
# should be minimized; currently only targets of [PutForwards].
'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_contents),
}
if this_include_path:
interfaces_info[interface_name]['include_path'] = this_include_path
if implemented_as:
interfaces_info[interface_name]['implemented_as'] = implemented_as
# Record auxiliary information
extended_attributes_by_interface[interface_name] = extended_attributes
# Record inheritance information
inherited_extended_attributes_by_interface[interface_name] = dict(
(key, value)
for key, value in extended_attributes.iteritems()
if key in INHERITED_EXTENDED_ATTRIBUTES)
parent = get_parent_interface(idl_file_contents)
if parent:
parent_interfaces[interface_name] = parent
def compute_inheritance_info(interface_name):
"""Computes inheritance information, namely ancestors and inherited extended attributes."""
interface_info = interfaces_info[interface_name]
interface_extended_attributes = extended_attributes_by_interface[interface_name]
inherited_extended_attributes = dict(
(key, value)
for key, value in interface_extended_attributes.iteritems()
if key in INHERITED_EXTENDED_ATTRIBUTES)
"""Compute inheritance information, namely ancestors and inherited extended attributes."""
def generate_ancestors(interface_name):
while interface_name in parent_interfaces:
interface_name = parent_interfaces[interface_name]
yield interface_name
ancestors = list(generate_ancestors(interface_name))
if not ancestors:
if inherited_extended_attributes:
interface_info['inherited_extended_attributes'] = inherited_extended_attributes
return
interface_info['ancestors'] = ancestors
inherited_extended_attributes = inherited_extended_attributes_by_interface[interface_name]
for ancestor in ancestors:
# Extended attributes are missing if an ancestor is an interface that
# we're not processing, namely real IDL files if only processing test
# IDL files.
ancestor_extended_attributes = extended_attributes_by_interface.get(ancestor, {})
inherited_extended_attributes.update(dict(
(key, value)
for key, value in ancestor_extended_attributes.iteritems()
if key in INHERITED_EXTENDED_ATTRIBUTES))
if inherited_extended_attributes:
interface_info['inherited_extended_attributes'] = inherited_extended_attributes
# Ancestors may not be present, notably if an ancestor is a generated
# IDL file and we are running this script from run-bindings-tests,
# where we don't generate these files.
ancestor_extended_attributes = inherited_extended_attributes_by_interface.get(ancestor, {})
inherited_extended_attributes.update(ancestor_extended_attributes)
interfaces_info[interface_name].update({
'ancestors': ancestors,
'inherited_extended_attributes': inherited_extended_attributes,
})
def compute_interfaces_info(idl_files):
......@@ -259,16 +248,16 @@ def compute_interfaces_info(idl_files):
implemented_interfaces_include_paths = [
interfaces_info[interface]['include_path']
for interface in implemented_interfaces
if 'include_path' in interfaces_info[interface]]
if interfaces_info[interface]['include_path']]
except KeyError as key_name:
raise IdlInterfaceFileNotFoundError('Could not find the IDL file where the following implemented interface is defined: %s' % key_name)
interface_info['dependencies_full_paths'] = (
partial_interfaces_full_paths +
implemented_interfaces_full_paths)
interface_info['dependencies_include_paths'] = (
partial_interfaces_include_paths +
implemented_interfaces_include_paths)
interface_info.update({
'dependencies_full_paths': (partial_interfaces_full_paths +
implemented_interfaces_full_paths),
'dependencies_include_paths': (partial_interfaces_include_paths +
implemented_interfaces_include_paths),
})
################################################################################
......
......@@ -82,7 +82,7 @@ def write_event_interfaces_file(interfaces_info, destination_filename, only_if_c
interface_name
for interface_name, interface_info in interfaces_info.iteritems()
if (interface_name == 'Event' or
('ancestors' in interface_info and
(interface_info['ancestors'] and
interface_info['ancestors'][-1] == 'Event')))
def extended_attribute_string(name, value):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment