Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: Source/bindings/scripts/compute_interfaces_info_individual.py

Issue 1257613003: bindings: Supports inheritance of [Unforgeable] attributes as accessor-type properties. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Made inherit_unforgeable_attributes more robust. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/compute_interfaces_info_individual.py
diff --git a/Source/bindings/scripts/compute_interfaces_info_individual.py b/Source/bindings/scripts/compute_interfaces_info_individual.py
index b052e14c162dae0010d6865a4e4441e7d8e3d2fa..fe9095850bf63afe8383b82e1de14e90feb35215 100755
--- a/Source/bindings/scripts/compute_interfaces_info_individual.py
+++ b/Source/bindings/scripts/compute_interfaces_info_individual.py
@@ -47,9 +47,10 @@ import os
import posixpath
import sys
+from idl_compiler import idl_filename_to_interface_name
from idl_definitions import Visitor
from idl_reader import IdlReader
-from utilities import get_file_contents, read_file_to_list, idl_filename_to_interface_name, idl_filename_to_component, write_pickle_file, get_interface_extended_attributes_from_idl, is_callback_interface_from_idl
+from utilities import get_file_contents, read_file_to_list, idl_filename_to_interface_name, idl_filename_to_component, write_pickle_file, get_interface_extended_attributes_from_idl, is_callback_interface_from_idl, merge_dict_recursively
module_path = os.path.dirname(__file__)
source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
@@ -100,8 +101,7 @@ def include_path(idl_filename, implemented_as=None):
relative_dir = relative_dir_posix(idl_filename)
# IDL file basename is used even if only a partial interface file
- idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
- cpp_class_name = implemented_as or idl_file_basename
+ cpp_class_name = implemented_as or idl_filename_to_interface_name(idl_filename)
return posixpath.join(relative_dir, cpp_class_name + '.h')
@@ -130,6 +130,13 @@ def get_put_forward_interfaces_from_definition(definition):
if 'PutForwards' in attribute.extended_attributes))
+def get_unforgeable_attributes_from_definition(definition):
+ if 'Unforgeable' in definition.extended_attributes:
+ return sorted(definition.attributes)
+ return sorted(attribute for attribute in definition.attributes
+ if 'Unforgeable' in attribute.extended_attributes)
+
+
def collect_union_types_from_definitions(definitions):
"""Traverse definitions and collect all union types."""
class UnionTypeCollector(Visitor):
@@ -172,6 +179,34 @@ class InterfaceInfoCollector(object):
def collect_info(self, idl_filename):
"""Reads an idl file and collects information which is required by the
binding code generation."""
+ def collect_unforgeable_attributes(definition, idl_filename):
+ """Collects [Unforgeable] attributes so that we can define them on
+ sub-interfaces later. The resulting structure is as follows.
+ interfaces_info[interface_name] = {
+ 'unforgeable_attributes': {
+ 'core': [IdlAttribute, ...],
+ 'modules': [IdlAttribute, ...],
+ },
+ ...
+ }
+ """
+ interface_info = {}
+ unforgeable_attributes = get_unforgeable_attributes_from_definition(definition)
+ if not unforgeable_attributes:
+ return interface_info
+
+ if definition.is_partial:
+ interface_basename = idl_filename_to_interface_name(idl_filename)
+ # TODO(yukishiino): [PartialInterfaceImplementedAs] is treated
+ # in interface_dependency_resolver.transfer_extended_attributes.
+ # Come up with a better way to keep them consistent.
+ for attr in unforgeable_attributes:
+ attr.extended_attributes['PartialInterfaceImplementedAs'] = definition.extended_attributes.get('ImplementedAs', interface_basename)
+ component = idl_filename_to_component(idl_filename)
+ interface_info['unforgeable_attributes'] = {}
+ interface_info['unforgeable_attributes'][component] = unforgeable_attributes
+ return interface_info
+
definitions = self.reader.read_idl_file(idl_filename)
this_union_types = collect_union_types_from_definitions(definitions)
@@ -208,6 +243,15 @@ class InterfaceInfoCollector(object):
else:
return
+ if definition.name not in self.interfaces_info:
+ self.interfaces_info[definition.name] = {}
+
+ # Remember [Unforgeable] attributes.
+ if definitions.interfaces:
+ merge_dict_recursively(self.interfaces_info[definition.name],
+ collect_unforgeable_attributes(definition, idl_filename))
+
+ component = idl_filename_to_component(idl_filename)
extended_attributes = definition.extended_attributes
implemented_as = extended_attributes.get('ImplementedAs')
full_path = os.path.realpath(idl_filename)
@@ -219,10 +263,22 @@ class InterfaceInfoCollector(object):
if this_include_path:
partial_include_paths.append(this_include_path)
if this_union_types:
- component = idl_filename_to_component(idl_filename)
partial_include_paths.append(
'bindings/%s/v8/UnionTypes%s.h' % (component, component.capitalize()))
self.add_paths_to_partials_dict(definition.name, full_path, partial_include_paths)
+ # Collects C++ header paths which should be included from generated
+ # .cpp files. The resulting structure is as follows.
+ # interfaces_info[interface_name] = {
+ # 'cpp_includes': {
+ # 'core': set(['core/foo/Foo.h', ...]),
+ # 'modules': set(['modules/bar/Bar.h', ...]),
+ # },
+ # ...
+ # }
+ if this_include_path:
+ merge_dict_recursively(
+ self.interfaces_info[definition.name],
+ {'cpp_includes': {component: set([this_include_path])}})
return
# 'implements' statements can be included in either the file for the
@@ -246,7 +302,7 @@ class InterfaceInfoCollector(object):
'parent': definition.parent,
'relative_dir': relative_dir_posix(idl_filename),
})
- self.interfaces_info[definition.name] = interface_info
+ merge_dict_recursively(self.interfaces_info[definition.name], interface_info)
def get_info_as_dict(self):
"""Returns info packaged as a dict."""

Powered by Google App Engine
This is Rietveld 408576698