Commit 787c73db authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Implement proxying at ReferenceType

Bug: 839389
Change-Id: Ibdf190e9f5d670fc9a26e8fda1cca71646ee74cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1700107Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678599}
parent 66900ea8
...@@ -27,7 +27,7 @@ class Proxy(object): ...@@ -27,7 +27,7 @@ class Proxy(object):
|self|. If None, no attribute has priority over own attributes. |self|. If None, no attribute has priority over own attributes.
""" """
if target_attrs is not None: if target_attrs is not None:
assert isinstance(target_attrs, (tuple, list)) assert isinstance(target_attrs, (list, set, tuple))
assert all(isinstance(attr, str) for attr in target_attrs) assert all(isinstance(attr, str) for attr in target_attrs)
self._target_object = target_object self._target_object = target_object
self._target_attrs = target_attrs self._target_attrs = target_attrs
...@@ -53,6 +53,26 @@ class Proxy(object): ...@@ -53,6 +53,26 @@ class Proxy(object):
return getattr(target_object, attribute) return getattr(target_object, attribute)
return object.__getattribute__(self, attribute) return object.__getattribute__(self, attribute)
@staticmethod
def get_all_attributes(target_class):
"""
Returns all the attributes of |target_class| including its ancestors'
attributes. Protected attributes (starting with an underscore,
including two underscores) are excluded.
"""
def collect_attrs_recursively(target_class):
attrs_sets = [set(vars(target_class).keys())]
for base_class in target_class.__bases__:
attrs_sets.append(collect_attrs_recursively(base_class))
return set.union(*attrs_sets)
assert isinstance(target_class, type)
return sorted([
attr for attr in collect_attrs_recursively(target_class)
if not attr.startswith('_')
])
def set_target_object(self, target_object): def set_target_object(self, target_object):
assert self._target_object is None assert self._target_object is None
assert isinstance(target_object, object) assert isinstance(target_object, object)
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
# found in the LICENSE file. # found in the LICENSE file.
import exceptions import exceptions
from blinkbuild.name_style_converter import NameStyleConverter from blinkbuild.name_style_converter import NameStyleConverter
from .common import WithCodeGeneratorInfo from .common import WithCodeGeneratorInfo
from .common import WithDebugInfo from .common import WithDebugInfo
from .common import WithExtendedAttributes from .common import WithExtendedAttributes
...@@ -378,6 +380,11 @@ class ReferenceType(IdlType, WithIdentifier, Proxy): ...@@ -378,6 +380,11 @@ class ReferenceType(IdlType, WithIdentifier, Proxy):
identifier may be resolved to a TypedefType. identifier may be resolved to a TypedefType.
""" """
_attrs_to_be_proxied = set(Proxy.get_all_attributes(IdlType)).difference(
# attributes not to be proxied
set(('code_generator_info', 'debug_info', 'extended_attributes',
'is_optional')))
def __init__(self, def __init__(self,
ref_to_idl_type, ref_to_idl_type,
is_optional=False, is_optional=False,
...@@ -392,8 +399,10 @@ class ReferenceType(IdlType, WithIdentifier, Proxy): ...@@ -392,8 +399,10 @@ class ReferenceType(IdlType, WithIdentifier, Proxy):
code_generator_info=code_generator_info, code_generator_info=code_generator_info,
debug_info=debug_info) debug_info=debug_info)
WithIdentifier.__init__(self, ref_to_idl_type.identifier) WithIdentifier.__init__(self, ref_to_idl_type.identifier)
# TODO(yukishiino): Set appropriate attributes to proxy. Proxy.__init__(
Proxy.__init__(self, target_object=ref_to_idl_type) self,
target_object=ref_to_idl_type,
target_attrs_with_priority=ReferenceType._attrs_to_be_proxied)
class DefinitionType(IdlType, WithIdentifier): class DefinitionType(IdlType, WithIdentifier):
......
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