Commit f1e3b640 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Implement mutable and immutable CodeGeneratorInfo

Implements CodeGeneratorInfo{,Mutable} as immutable and mutable
information for bindings generators respectively.

Bug: 839389
Change-Id: Ia872b2f5aa5fd2b80a122f006ced06dae0b596c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768480
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690294}
parent 65f87ce1
......@@ -9,6 +9,7 @@ web_idl/ast_group.py
web_idl/attribute.py
web_idl/callback_function.py
web_idl/callback_interface.py
web_idl/code_generator_info.py
web_idl/composition_parts.py
web_idl/constant.py
web_idl/database.py
......
......@@ -19,6 +19,7 @@ web_idl/ast_group.py
web_idl/attribute.py
web_idl/callback_function.py
web_idl/callback_interface.py
web_idl/code_generator_info.py
web_idl/composition_parts.py
web_idl/constant.py
web_idl/database.py
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -52,7 +53,8 @@ class Attribute(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
ir = make_copy(ir)
WithIdentifier.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithOwner.__init__(self, owner)
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -47,7 +48,8 @@ class CallbackFunction(UserDefinedType, FunctionLike, WithExtendedAttributes,
UserDefinedType.__init__(self, ir.identifier)
FunctionLike.__init__(self, ir)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
......@@ -4,6 +4,7 @@
import exceptions
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -40,7 +41,8 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes,
ir = make_copy(ir)
UserDefinedType.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# The list of attributes that CodeGeneratorInfo supports. CodeGeneratorInfo's
# attributes are auto-generated from this list because they're boilerplated.
_CODE_GENERATOR_INFO_ATTRIBUTES = (
'property_implemented_as',
'receiver_implemented_as',
)
_CGI_ATTRS = tuple([
# attribute name (_foo of self._foo), getter name, setter name
('_{}'.format(attr), '{}'.format(attr), 'set_{}'.format(attr))
for attr in _CODE_GENERATOR_INFO_ATTRIBUTES
])
class CodeGeneratorInfo(object):
"""A bag of properties to be used by bindings code generators."""
def __init__(self, other=None):
"""
Initializes a new object.
If |other| is not None, initializes the new object as a copy of |other|.
If |other| is None, initializes the new object as empty.
"""
assert other is None or isinstance(other, CodeGeneratorInfo)
if other is None:
for attr_name, _, _ in _CGI_ATTRS:
setattr(self, attr_name, None)
else:
for attr_name, _, _ in _CGI_ATTRS:
setattr(self, attr_name, getattr(other, attr_name))
@staticmethod
def make_getter(attr_name):
@property
def getter(self):
return getattr(self, attr_name)
return getter
class CodeGeneratorInfoMutable(CodeGeneratorInfo):
"""Another version of CodeGeneratorInfo that supports setters."""
@staticmethod
def make_setter(attr_name):
def setter(self, value):
setattr(self, attr_name, value)
return setter
def __getstate__(self):
assert False, "CodeGeneratorInfoMutable must not be pickled."
def __setstate__(self, state):
assert False, "CodeGeneratorInfoMutable must not be pickled."
for attr_name, getter_name, setter_name in _CGI_ATTRS:
setattr(CodeGeneratorInfo, getter_name,
CodeGeneratorInfo.make_getter(attr_name))
setattr(CodeGeneratorInfoMutable, setter_name,
CodeGeneratorInfoMutable.make_setter(attr_name))
CodeGeneratorInfo.make_getter = None
CodeGeneratorInfoMutable.make_setter = None
......@@ -2,8 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .extended_attribute import ExtendedAttributes
from .code_generator_info import CodeGeneratorInfo
from .code_generator_info import CodeGeneratorInfoMutable
from .exposure import Exposure
from .extended_attribute import ExtendedAttributes
class Identifier(str):
......@@ -35,17 +37,14 @@ class WithExtendedAttributes(object):
return self._extended_attributes
class CodeGeneratorInfo(dict):
"""A bag of properties to be used by bindings code generators"""
class WithCodeGeneratorInfo(object):
"""Implements |code_generator_info| as a readonly attribute."""
def __init__(self, code_generator_info=None):
assert (code_generator_info is None
or isinstance(code_generator_info, CodeGeneratorInfo))
self._code_generator_info = code_generator_info or CodeGeneratorInfo()
self._code_generator_info = (code_generator_info
or CodeGeneratorInfoMutable())
@property
def code_generator_info(self):
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -47,7 +48,8 @@ class Constant(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
ir = make_copy(ir)
WithIdentifier.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithOwner.__init__(self, owner)
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -58,7 +59,8 @@ class Dictionary(UserDefinedType, WithExtendedAttributes,
ir = make_copy(ir)
UserDefinedType.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......@@ -141,7 +143,8 @@ class DictionaryMember(WithIdentifier, WithExtendedAttributes,
ir = make_copy(ir)
WithIdentifier.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithOwner.__init__(self, owner)
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -42,7 +43,8 @@ class Enumeration(UserDefinedType, WithExtendedAttributes,
ir = make_copy(ir)
UserDefinedType.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
......@@ -7,7 +7,6 @@ import functools
from blinkbuild.name_style_converter import NameStyleConverter
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithDebugInfo
from .composition_parts import WithExtendedAttributes
from .composition_parts import WithIdentifier
......@@ -110,7 +109,7 @@ class IdlTypeFactory(object):
return idl_type
class IdlType(WithExtendedAttributes, WithCodeGeneratorInfo, WithDebugInfo):
class IdlType(WithExtendedAttributes, WithDebugInfo):
"""
Represents a 'type' in Web IDL.
......@@ -130,13 +129,11 @@ class IdlType(WithExtendedAttributes, WithCodeGeneratorInfo, WithDebugInfo):
def __init__(self,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(is_optional, bool)
assert pass_key is _IDL_TYPE_PASS_KEY
WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithDebugInfo.__init__(self, debug_info)
self._is_optional = is_optional
......@@ -428,7 +425,6 @@ class SimpleType(IdlType):
name,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert name in SimpleType._VALID_TYPES, (
......@@ -437,7 +433,6 @@ class SimpleType(IdlType):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
self._name = name
......@@ -507,14 +502,12 @@ class ReferenceType(IdlType, WithIdentifier, Proxy):
_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')))
set(('debug_info', 'extended_attributes', 'is_optional')))
def __init__(self,
ref_to_idl_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(ref_to_idl_type, RefById)
......@@ -522,7 +515,6 @@ class ReferenceType(IdlType, WithIdentifier, Proxy):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
WithIdentifier.__init__(self, ref_to_idl_type.identifier)
......@@ -550,13 +542,11 @@ class DefinitionType(IdlType, WithIdentifier):
def __init__(self,
user_defined_type,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(user_defined_type, UserDefinedType)
IdlType.__init__(
self,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
WithIdentifier.__init__(self, user_defined_type.identifier)
......@@ -620,13 +610,11 @@ class TypedefType(IdlType, WithIdentifier):
def __init__(self,
typedef,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(typedef, Typedef)
IdlType.__init__(
self,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
WithIdentifier.__init__(self, typedef.identifier)
......@@ -674,7 +662,6 @@ class _ArrayLikeType(IdlType):
element_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(element_type, IdlType)
......@@ -682,7 +669,6 @@ class _ArrayLikeType(IdlType):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
self._element_type = element_type
......@@ -711,7 +697,6 @@ class SequenceType(_ArrayLikeType):
element_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
_ArrayLikeType.__init__(
......@@ -719,7 +704,6 @@ class SequenceType(_ArrayLikeType):
element_type,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
......@@ -746,7 +730,6 @@ class FrozenArrayType(_ArrayLikeType):
element_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
_ArrayLikeType.__init__(
......@@ -754,7 +737,6 @@ class FrozenArrayType(_ArrayLikeType):
element_type,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
......@@ -779,13 +761,11 @@ class VariadicType(_ArrayLikeType):
def __init__(self,
element_type,
code_generator_info=None,
debug_info=None,
pass_key=None):
_ArrayLikeType.__init__(
self,
element_type,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
......@@ -816,7 +796,6 @@ class RecordType(IdlType):
value_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(key_type, IdlType)
......@@ -825,7 +804,6 @@ class RecordType(IdlType):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
self._key_type = key_type
......@@ -874,7 +852,6 @@ class PromiseType(IdlType):
result_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(result_type, IdlType)
......@@ -882,7 +859,6 @@ class PromiseType(IdlType):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
self._result_type = result_type
......@@ -929,7 +905,6 @@ class UnionType(IdlType):
member_types,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(member_types, (list, tuple))
......@@ -938,7 +913,6 @@ class UnionType(IdlType):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
self._member_types = tuple(member_types)
......@@ -1016,7 +990,6 @@ class NullableType(IdlType):
inner_type,
is_optional=False,
extended_attributes=None,
code_generator_info=None,
debug_info=None,
pass_key=None):
assert isinstance(inner_type, IdlType)
......@@ -1024,7 +997,6 @@ class NullableType(IdlType):
self,
is_optional=is_optional,
extended_attributes=extended_attributes,
code_generator_info=code_generator_info,
debug_info=debug_info,
pass_key=pass_key)
self._inner_type = inner_type
......
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
from .attribute import Attribute
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -95,7 +96,8 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
ir = make_copy(ir)
UserDefinedType.__init__(self, ir.identifier)
WithExtendedAttributes.__init__(self, ir.extended_attributes)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......@@ -213,13 +215,12 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
return True
class Iterable(WithCodeGeneratorInfo, WithDebugInfo):
class Iterable(WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-iterable"""
def __init__(self,
key_type=None,
value_type=None,
code_generator_info=None,
debug_info=None):
assert key_type is None or isinstance(key_type, IdlType)
# iterable is declared in either form of
......@@ -229,7 +230,6 @@ class Iterable(WithCodeGeneratorInfo, WithDebugInfo):
# to be consistent with the format of IDL.
assert isinstance(value_type, IdlType), "value_type must be specified"
WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithDebugInfo.__init__(self, debug_info)
self._key_type = key_type
......@@ -246,20 +246,18 @@ class Iterable(WithCodeGeneratorInfo, WithDebugInfo):
return self._value_type
class Maplike(WithCodeGeneratorInfo, WithDebugInfo):
class Maplike(WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-maplike"""
def __init__(self,
key_type,
value_type,
is_readonly=False,
code_generator_info=None,
debug_info=None):
assert isinstance(key_type, IdlType)
assert isinstance(value_type, IdlType)
assert isinstance(is_readonly, bool)
WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithDebugInfo.__init__(self, debug_info)
self._key_type = key_type
......@@ -291,18 +289,16 @@ class Maplike(WithCodeGeneratorInfo, WithDebugInfo):
return self._is_readonly
class Setlike(WithCodeGeneratorInfo, WithDebugInfo):
class Setlike(WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-setlike"""
def __init__(self,
value_type,
is_readonly=False,
code_generator_info=None,
debug_info=None):
assert isinstance(value_type, IdlType)
assert isinstance(is_readonly, bool)
WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithDebugInfo.__init__(self, debug_info)
self._value_type = value_type
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .code_generator_info import CodeGeneratorInfo
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
......@@ -34,7 +35,8 @@ class Typedef(WithIdentifier, WithCodeGeneratorInfo, WithComponent,
ir = make_copy(ir)
WithIdentifier.__init__(self, ir.identifier)
WithCodeGeneratorInfo.__init__(self, ir.code_generator_info)
WithCodeGeneratorInfo.__init__(
self, CodeGeneratorInfo(ir.code_generator_info))
WithComponent.__init__(self, components=ir.components)
WithDebugInfo.__init__(self, ir.debug_info)
......
......@@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from .composition_parts import WithCodeGeneratorInfo
from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo
from .composition_parts import WithIdentifier
......@@ -10,8 +9,7 @@ from .idl_type import IdlType
from .typedef import Typedef
class Union(WithIdentifier, WithCodeGeneratorInfo, WithComponent,
WithDebugInfo):
class Union(WithIdentifier, WithComponent, WithDebugInfo):
"""
Union class makes a group of union types with the same flattened member
types and the same result whether it includes a nullable type or not.
......@@ -79,7 +77,6 @@ class Union(WithIdentifier, WithCodeGeneratorInfo, WithComponent,
idl_type.apply_to_all_composing_elements(collect_components)
WithIdentifier.__init__(self, identifier)
WithCodeGeneratorInfo.__init__(self)
WithComponent.__init__(self, components=sorted(components))
WithDebugInfo.__init__(self)
......
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