Commit 47ebf6af authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

IDL Compiler: Implement CallbackInterface in database

Adds a support for callback interfaces in Web IDL database.

Bug: 839389
Change-Id: Ic4911a18fa7abf0b0891f53bc3dc8de38dd48730
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1886073
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710261}
parent 0210016e
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import exceptions
from .code_generator_info import CodeGeneratorInfo from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo from .composition_parts import WithDebugInfo
from .composition_parts import WithExtendedAttributes from .composition_parts import WithExtendedAttributes
from .constant import Constant
from .operation import Operation
from .operation import OperationGroup
from .ir_map import IRMap from .ir_map import IRMap
from .make_copy import make_copy from .make_copy import make_copy
from .user_defined_type import UserDefinedType from .user_defined_type import UserDefinedType
...@@ -22,19 +24,39 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes, ...@@ -22,19 +24,39 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
constants=None,
operations=None,
extended_attributes=None, extended_attributes=None,
code_generator_info=None,
component=None, component=None,
debug_info=None): debug_info=None):
if constants is None:
constants = []
if operations is None:
operations = []
assert isinstance(constants, (list, tuple))
assert isinstance(operations, (list, tuple))
assert all(
isinstance(constant, Constant.IR) for constant in constants)
assert all(
isinstance(operation, Operation.IR)
for operation in operations)
IRMap.IR.__init__( IRMap.IR.__init__(
self, self,
identifier=identifier, identifier=identifier,
kind=IRMap.IR.Kind.CALLBACK_INTERFACE) kind=IRMap.IR.Kind.CALLBACK_INTERFACE)
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self, code_generator_info) WithCodeGeneratorInfo.__init__(self)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
self.attributes = []
self.constants = constants
self.operations = operations
self.operation_groups = []
self.constructors = []
self.constructor_groups = []
def __init__(self, ir): def __init__(self, ir):
assert isinstance(ir, CallbackInterface.IR) assert isinstance(ir, CallbackInterface.IR)
...@@ -45,23 +67,35 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes, ...@@ -45,23 +67,35 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes,
self, CodeGeneratorInfo(ir.code_generator_info)) self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components) WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info) WithDebugInfo.__init__(self, ir.debug_info)
self._constants = tuple([
Constant(constant_ir, owner=self) for constant_ir in ir.constants
])
self._operations = tuple([
Operation(operation_ir, owner=self)
for operation_ir in ir.operations
])
self._operation_groups = tuple([
OperationGroup(
operation_group_ir,
filter(lambda x: x.identifier == operation_group_ir.identifier,
self._operations),
owner=self) for operation_group_ir in ir.operation_groups
])
@property @property
def operation_groups(self): def constants(self):
""" """Returns constants."""
Returns a list of OperationGroup. Each OperationGroup may have an return self._constants
operation or a set of overloaded operations.
@return tuple(OperationGroup)
"""
raise exceptions.NotImplementedError()
@property @property
def constants(self): def operations(self):
""" """Returns operations."""
Returns a list of constants. return self._operations
@return tuple(Constant)
""" @property
raise exceptions.NotImplementedError() def operation_groups(self):
"""Returns groups of overloaded operations."""
return self._operation_groups
# UserDefinedType overrides # UserDefinedType overrides
@property @property
......
...@@ -277,7 +277,8 @@ class IdlCompiler(object): ...@@ -277,7 +277,8 @@ class IdlCompiler(object):
self._ir_map.add(new_interface) self._ir_map.add(new_interface)
def _group_overloaded_functions(self): def _group_overloaded_functions(self):
old_irs = self._ir_map.irs_of_kinds(IRMap.IR.Kind.INTERFACE, old_irs = self._ir_map.irs_of_kinds(IRMap.IR.Kind.CALLBACK_INTERFACE,
IRMap.IR.Kind.INTERFACE,
IRMap.IR.Kind.NAMESPACE) IRMap.IR.Kind.NAMESPACE)
self._ir_map.move_to_new_phase() self._ir_map.move_to_new_phase()
......
...@@ -302,9 +302,25 @@ class _IRBuilder(object): ...@@ -302,9 +302,25 @@ class _IRBuilder(object):
def _build_callback_interface(self, node): def _build_callback_interface(self, node):
assert node.GetProperty('CALLBACK') assert node.GetProperty('CALLBACK')
# TODO(peria): Build members and register them in |callback_interface|
child_nodes = list(node.GetChildren())
extended_attributes = self._take_extended_attributes(child_nodes)
members = map(self._build_interface_or_namespace_member, child_nodes)
constants = []
operations = []
for member in members:
if isinstance(member, Constant.IR):
constants.append(member)
elif isinstance(member, Operation.IR):
operations.append(member)
else:
assert False
return CallbackInterface.IR( return CallbackInterface.IR(
identifier=Identifier(node.GetName()), identifier=Identifier(node.GetName()),
constants=constants,
operations=operations,
extended_attributes=extended_attributes,
component=self._component, component=self._component,
debug_info=self._build_debug_info(node)) debug_info=self._build_debug_info(node))
......
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