Commit 1ea718e1 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Support WithOwnerMixin.owner_mixin

Bug: 839389
Change-Id: I1837515ed902100be67c0dc74440f50d25002420
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1942594
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720416}
parent ae2e3478
...@@ -10,17 +10,19 @@ from .composition_parts import WithExposure ...@@ -10,17 +10,19 @@ from .composition_parts import WithExposure
from .composition_parts import WithExtendedAttributes from .composition_parts import WithExtendedAttributes
from .composition_parts import WithIdentifier from .composition_parts import WithIdentifier
from .composition_parts import WithOwner from .composition_parts import WithOwner
from .composition_parts import WithOwnerMixin
from .exposure import Exposure from .exposure import Exposure
from .idl_type import IdlType from .idl_type import IdlType
from .make_copy import make_copy from .make_copy import make_copy
class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithOwner, WithComponent, WithDebugInfo): WithExposure, WithOwner, WithOwnerMixin, WithComponent,
WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-attributes""" """https://heycam.github.io/webidl/#idl-attributes"""
class IR(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithComponent, WithDebugInfo): WithExposure, WithOwnerMixin, WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
idl_type, idl_type,
...@@ -39,6 +41,7 @@ class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -39,6 +41,7 @@ class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self) WithCodeGeneratorInfo.__init__(self)
WithExposure.__init__(self) WithExposure.__init__(self)
WithOwnerMixin.__init__(self)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
...@@ -56,6 +59,7 @@ class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -56,6 +59,7 @@ class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithCodeGeneratorInfo.__init__(self, ir, readonly=True) WithCodeGeneratorInfo.__init__(self, ir, readonly=True)
WithExposure.__init__(self, ir, readonly=True) WithExposure.__init__(self, ir, readonly=True)
WithOwner.__init__(self, owner) WithOwner.__init__(self, owner)
WithOwnerMixin.__init__(self, ir)
WithComponent.__init__(self, ir, readonly=True) WithComponent.__init__(self, ir, readonly=True)
WithDebugInfo.__init__(self, ir) WithDebugInfo.__init__(self, ir)
......
...@@ -218,3 +218,31 @@ class WithOwner(object): ...@@ -218,3 +218,31 @@ class WithOwner(object):
@property @property
def owner(self): def owner(self):
return self._owner return self._owner
class WithOwnerMixin(object):
"""Implements |owner_mixin| as a readonly attribute."""
def __init__(self, owner_mixin=None):
if isinstance(owner_mixin, WithOwnerMixin):
owner_mixin = owner_mixin._owner_mixin
# In Python2, we need to avoid circular imports.
from .reference import RefById
assert owner_mixin is None or isinstance(owner_mixin, RefById)
self._owner_mixin = owner_mixin
@property
def owner_mixin(self):
"""
Returns the interface mixin object where this construct was originally
defined.
"""
return self._owner_mixin.target_object if self._owner_mixin else None
def set_owner_mixin(self, mixin):
# In Python2, we need to avoid circular imports.
from .reference import RefById
assert isinstance(mixin, RefById)
assert self._owner_mixin is None
self._owner_mixin = mixin
...@@ -10,6 +10,7 @@ from .composition_parts import WithExposure ...@@ -10,6 +10,7 @@ from .composition_parts import WithExposure
from .composition_parts import WithExtendedAttributes from .composition_parts import WithExtendedAttributes
from .composition_parts import WithIdentifier from .composition_parts import WithIdentifier
from .composition_parts import WithOwner from .composition_parts import WithOwner
from .composition_parts import WithOwnerMixin
from .exposure import Exposure from .exposure import Exposure
from .idl_type import IdlType from .idl_type import IdlType
from .literal_constant import LiteralConstant from .literal_constant import LiteralConstant
...@@ -17,11 +18,12 @@ from .make_copy import make_copy ...@@ -17,11 +18,12 @@ from .make_copy import make_copy
class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithOwner, WithComponent, WithDebugInfo): WithExposure, WithOwner, WithOwnerMixin, WithComponent,
WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-constants""" """https://heycam.github.io/webidl/#idl-constants"""
class IR(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithComponent, WithDebugInfo): WithExposure, WithOwnerMixin, WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
idl_type, idl_type,
...@@ -36,6 +38,7 @@ class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -36,6 +38,7 @@ class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self) WithCodeGeneratorInfo.__init__(self)
WithExposure.__init__(self) WithExposure.__init__(self)
WithOwnerMixin.__init__(self)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
...@@ -51,6 +54,7 @@ class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -51,6 +54,7 @@ class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithCodeGeneratorInfo.__init__(self, ir, readonly=True) WithCodeGeneratorInfo.__init__(self, ir, readonly=True)
WithExposure.__init__(self, ir, readonly=True) WithExposure.__init__(self, ir, readonly=True)
WithOwner.__init__(self, owner) WithOwner.__init__(self, owner)
WithOwnerMixin.__init__(self, ir)
WithComponent.__init__(self, ir, readonly=True) WithComponent.__init__(self, ir, readonly=True)
WithDebugInfo.__init__(self, ir) WithDebugInfo.__init__(self, ir)
......
...@@ -10,6 +10,7 @@ from .composition_parts import WithDebugInfo ...@@ -10,6 +10,7 @@ from .composition_parts import WithDebugInfo
from .composition_parts import WithExposure from .composition_parts import WithExposure
from .composition_parts import WithExtendedAttributes from .composition_parts import WithExtendedAttributes
from .composition_parts import WithOwner from .composition_parts import WithOwner
from .composition_parts import WithOwnerMixin
from .exposure import Exposure from .exposure import Exposure
from .function_like import FunctionLike from .function_like import FunctionLike
from .function_like import OverloadGroup from .function_like import OverloadGroup
...@@ -17,11 +18,12 @@ from .make_copy import make_copy ...@@ -17,11 +18,12 @@ from .make_copy import make_copy
class Constructor(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo, class Constructor(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithOwner, WithComponent, WithDebugInfo): WithExposure, WithOwner, WithOwnerMixin, WithComponent,
WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-constructors""" """https://heycam.github.io/webidl/#idl-constructors"""
class IR(FunctionLike.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(FunctionLike.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithComponent, WithDebugInfo): WithExposure, WithOwnerMixin, WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
arguments, arguments,
return_type, return_type,
...@@ -36,6 +38,7 @@ class Constructor(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -36,6 +38,7 @@ class Constructor(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self) WithCodeGeneratorInfo.__init__(self)
WithExposure.__init__(self) WithExposure.__init__(self)
WithOwnerMixin.__init__(self)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
...@@ -47,6 +50,7 @@ class Constructor(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -47,6 +50,7 @@ class Constructor(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo,
WithCodeGeneratorInfo.__init__(self, ir, readonly=True) WithCodeGeneratorInfo.__init__(self, ir, readonly=True)
WithExposure.__init__(self, ir, readonly=True) WithExposure.__init__(self, ir, readonly=True)
WithOwner.__init__(self, owner) WithOwner.__init__(self, owner)
WithOwnerMixin.__init__(self, ir)
WithComponent.__init__(self, ir, readonly=True) WithComponent.__init__(self, ir, readonly=True)
WithDebugInfo.__init__(self, ir) WithDebugInfo.__init__(self, ir)
......
...@@ -81,6 +81,7 @@ class IdlCompiler(object): ...@@ -81,6 +81,7 @@ class IdlCompiler(object):
self._merge_partial_interface_likes() self._merge_partial_interface_likes()
self._merge_partial_dictionaries() self._merge_partial_dictionaries()
# Merge mixins. # Merge mixins.
self._set_owner_mixin_of_mixin_members()
self._merge_interface_mixins() self._merge_interface_mixins()
# Process inheritances. # Process inheritances.
...@@ -221,6 +222,19 @@ class IdlCompiler(object): ...@@ -221,6 +222,19 @@ class IdlCompiler(object):
new_dictionary.own_members.extend( new_dictionary.own_members.extend(
make_copy(partial_dictionary.own_members)) make_copy(partial_dictionary.own_members))
def _set_owner_mixin_of_mixin_members(self):
mixins = self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE_MIXIN)
self._ir_map.move_to_new_phase()
for old_ir in mixins:
new_ir = make_copy(old_ir)
self._ir_map.add(new_ir)
ref_to_mixin = self._ref_to_idl_def_factory.create(
new_ir.identifier)
for member in new_ir.iter_all_members():
member.set_owner_mixin(ref_to_mixin)
def _merge_interface_mixins(self): def _merge_interface_mixins(self):
interfaces = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE) interfaces = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE)
mixins = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE_MIXIN) mixins = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE_MIXIN)
......
...@@ -10,6 +10,7 @@ from .composition_parts import WithDebugInfo ...@@ -10,6 +10,7 @@ from .composition_parts import WithDebugInfo
from .composition_parts import WithExposure from .composition_parts import WithExposure
from .composition_parts import WithExtendedAttributes from .composition_parts import WithExtendedAttributes
from .composition_parts import WithOwner from .composition_parts import WithOwner
from .composition_parts import WithOwnerMixin
from .exposure import Exposure from .exposure import Exposure
from .function_like import FunctionLike from .function_like import FunctionLike
from .function_like import OverloadGroup from .function_like import OverloadGroup
...@@ -18,11 +19,12 @@ from .make_copy import make_copy ...@@ -18,11 +19,12 @@ from .make_copy import make_copy
class Operation(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo, class Operation(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithOwner, WithComponent, WithDebugInfo): WithExposure, WithOwner, WithOwnerMixin, WithComponent,
WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-operations""" """https://heycam.github.io/webidl/#idl-operations"""
class IR(FunctionLike.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(FunctionLike.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExposure, WithComponent, WithDebugInfo): WithExposure, WithOwnerMixin, WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
arguments, arguments,
...@@ -40,6 +42,7 @@ class Operation(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -40,6 +42,7 @@ class Operation(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo,
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self) WithCodeGeneratorInfo.__init__(self)
WithExposure.__init__(self) WithExposure.__init__(self)
WithOwnerMixin.__init__(self)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
...@@ -53,6 +56,7 @@ class Operation(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -53,6 +56,7 @@ class Operation(FunctionLike, WithExtendedAttributes, WithCodeGeneratorInfo,
WithCodeGeneratorInfo.__init__(self, ir, readonly=True) WithCodeGeneratorInfo.__init__(self, ir, readonly=True)
WithExposure.__init__(self, ir, readonly=True) WithExposure.__init__(self, ir, readonly=True)
WithOwner.__init__(self, owner) WithOwner.__init__(self, owner)
WithOwnerMixin.__init__(self, ir)
WithComponent.__init__(self, ir, readonly=True) WithComponent.__init__(self, ir, readonly=True)
WithDebugInfo.__init__(self, ir) WithDebugInfo.__init__(self, ir)
......
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