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

IDL compiler: Renames IdentifierIRMap to IRMap

IdentifierIRMap is a bit long name, and it turned out that
idenfiers don't play that important role.

IRMap is a clear and short name.

Also drops unused features of IRMap.

Bug: 839389
Change-Id: I1d325e9dd2e8421f2662357ebdd4c3e579f069f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768843
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690290}
parent 73d83b22
...@@ -19,12 +19,12 @@ web_idl/exposure.py ...@@ -19,12 +19,12 @@ web_idl/exposure.py
web_idl/extended_attribute.py web_idl/extended_attribute.py
web_idl/file_io.py web_idl/file_io.py
web_idl/function_like.py web_idl/function_like.py
web_idl/identifier_ir_map.py
web_idl/idl_compiler.py web_idl/idl_compiler.py
web_idl/idl_type.py web_idl/idl_type.py
web_idl/includes.py web_idl/includes.py
web_idl/interface.py web_idl/interface.py
web_idl/ir_builder.py web_idl/ir_builder.py
web_idl/ir_map.py
web_idl/literal_constant.py web_idl/literal_constant.py
web_idl/make_copy.py web_idl/make_copy.py
web_idl/namespace.py web_idl/namespace.py
......
...@@ -29,12 +29,12 @@ web_idl/exposure.py ...@@ -29,12 +29,12 @@ web_idl/exposure.py
web_idl/extended_attribute.py web_idl/extended_attribute.py
web_idl/file_io.py web_idl/file_io.py
web_idl/function_like.py web_idl/function_like.py
web_idl/identifier_ir_map.py
web_idl/idl_compiler.py web_idl/idl_compiler.py
web_idl/idl_type.py web_idl/idl_type.py
web_idl/includes.py web_idl/includes.py
web_idl/interface.py web_idl/interface.py
web_idl/ir_builder.py web_idl/ir_builder.py
web_idl/ir_map.py
web_idl/literal_constant.py web_idl/literal_constant.py
web_idl/make_copy.py web_idl/make_copy.py
web_idl/namespace.py web_idl/namespace.py
......
...@@ -7,7 +7,7 @@ from .composition_parts import WithComponent ...@@ -7,7 +7,7 @@ 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 .function_like import FunctionLike from .function_like import FunctionLike
from .identifier_ir_map import IdentifierIRMap 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
...@@ -16,7 +16,7 @@ class CallbackFunction(UserDefinedType, FunctionLike, WithExtendedAttributes, ...@@ -16,7 +16,7 @@ class CallbackFunction(UserDefinedType, FunctionLike, WithExtendedAttributes,
WithCodeGeneratorInfo, WithComponent, WithDebugInfo): WithCodeGeneratorInfo, WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-callback-functions""" """https://heycam.github.io/webidl/#idl-callback-functions"""
class IR(IdentifierIRMap.IR, FunctionLike.IR, WithExtendedAttributes, class IR(IRMap.IR, FunctionLike.IR, WithExtendedAttributes,
WithCodeGeneratorInfo, WithComponent, WithDebugInfo): WithCodeGeneratorInfo, WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
...@@ -26,10 +26,10 @@ class CallbackFunction(UserDefinedType, FunctionLike, WithExtendedAttributes, ...@@ -26,10 +26,10 @@ class CallbackFunction(UserDefinedType, FunctionLike, WithExtendedAttributes,
code_generator_info=None, code_generator_info=None,
component=None, component=None,
debug_info=None): debug_info=None):
IdentifierIRMap.IR.__init__( IRMap.IR.__init__(
self, self,
identifier=identifier, identifier=identifier,
kind=IdentifierIRMap.IR.Kind.CALLBACK_FUNCTION) kind=IRMap.IR.Kind.CALLBACK_FUNCTION)
FunctionLike.IR.__init__( FunctionLike.IR.__init__(
self, self,
identifier=identifier, identifier=identifier,
......
...@@ -8,7 +8,7 @@ from .composition_parts import WithCodeGeneratorInfo ...@@ -8,7 +8,7 @@ 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 .identifier_ir_map import IdentifierIRMap 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
...@@ -17,7 +17,7 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes, ...@@ -17,7 +17,7 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes,
WithCodeGeneratorInfo, WithComponent, WithDebugInfo): WithCodeGeneratorInfo, WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-interfaces""" """https://heycam.github.io/webidl/#idl-interfaces"""
class IR(IdentifierIRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(IRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
...@@ -25,10 +25,10 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes, ...@@ -25,10 +25,10 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes,
code_generator_info=None, code_generator_info=None,
component=None, component=None,
debug_info=None): debug_info=None):
IdentifierIRMap.IR.__init__( IRMap.IR.__init__(
self, self,
identifier=identifier, identifier=identifier,
kind=IdentifierIRMap.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, code_generator_info)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# 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.
from .identifier_ir_map import IdentifierIRMap from .ir_map import IRMap
from .idl_compiler import IdlCompiler from .idl_compiler import IdlCompiler
from .idl_type import IdlTypeFactory from .idl_type import IdlTypeFactory
from .ir_builder import load_and_register_idl_definitions from .ir_builder import load_and_register_idl_definitions
...@@ -21,7 +21,7 @@ def build_database(filepaths, report_error): ...@@ -21,7 +21,7 @@ def build_database(filepaths, report_error):
to terminate the program in this callback. to terminate the program in this callback.
""" """
ir_map = IdentifierIRMap() ir_map = IRMap()
ref_to_idl_type_factory = RefByIdFactory() ref_to_idl_type_factory = RefByIdFactory()
ref_to_idl_def_factory = RefByIdFactory() ref_to_idl_def_factory = RefByIdFactory()
idl_type_factory = IdlTypeFactory() idl_type_factory = IdlTypeFactory()
......
...@@ -8,7 +8,7 @@ from .composition_parts import WithDebugInfo ...@@ -8,7 +8,7 @@ from .composition_parts import WithDebugInfo
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 .identifier_ir_map import IdentifierIRMap from .ir_map import IRMap
from .idl_type import IdlType from .idl_type import IdlType
from .literal_constant import LiteralConstant from .literal_constant import LiteralConstant
from .make_copy import make_copy from .make_copy import make_copy
...@@ -20,7 +20,7 @@ class Dictionary(UserDefinedType, WithExtendedAttributes, ...@@ -20,7 +20,7 @@ class Dictionary(UserDefinedType, WithExtendedAttributes,
WithCodeGeneratorInfo, WithComponent, WithDebugInfo): WithCodeGeneratorInfo, WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-dictionaries""" """https://heycam.github.io/webidl/#idl-dictionaries"""
class IR(IdentifierIRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(IRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
...@@ -38,9 +38,9 @@ class Dictionary(UserDefinedType, WithExtendedAttributes, ...@@ -38,9 +38,9 @@ class Dictionary(UserDefinedType, WithExtendedAttributes,
isinstance(member, DictionaryMember.IR) isinstance(member, DictionaryMember.IR)
for member in own_members) for member in own_members)
kind = (IdentifierIRMap.IR.Kind.PARTIAL_DICTIONARY kind = (IRMap.IR.Kind.PARTIAL_DICTIONARY
if is_partial else IdentifierIRMap.IR.Kind.DICTIONARY) if is_partial else IRMap.IR.Kind.DICTIONARY)
IdentifierIRMap.IR.__init__(self, identifier=identifier, kind=kind) IRMap.IR.__init__(self, identifier=identifier, kind=kind)
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self, code_generator_info) WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithComponent.__init__( WithComponent.__init__(
......
...@@ -6,7 +6,7 @@ from .composition_parts import WithCodeGeneratorInfo ...@@ -6,7 +6,7 @@ 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 .identifier_ir_map import IdentifierIRMap 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
...@@ -15,7 +15,7 @@ class Enumeration(UserDefinedType, WithExtendedAttributes, ...@@ -15,7 +15,7 @@ class Enumeration(UserDefinedType, WithExtendedAttributes,
WithCodeGeneratorInfo, WithComponent, WithDebugInfo): WithCodeGeneratorInfo, WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-enums""" """https://heycam.github.io/webidl/#idl-enums"""
class IR(IdentifierIRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(IRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
...@@ -27,10 +27,8 @@ class Enumeration(UserDefinedType, WithExtendedAttributes, ...@@ -27,10 +27,8 @@ class Enumeration(UserDefinedType, WithExtendedAttributes,
assert isinstance(values, (list, tuple)) assert isinstance(values, (list, tuple))
assert all(isinstance(value, str) for value in values) assert all(isinstance(value, str) for value in values)
IdentifierIRMap.IR.__init__( IRMap.IR.__init__(
self, self, identifier=identifier, kind=IRMap.IR.Kind.ENUMERATION)
identifier=identifier,
kind=IdentifierIRMap.IR.Kind.ENUMERATION)
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self, code_generator_info) WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
......
...@@ -9,7 +9,7 @@ from .database import Database ...@@ -9,7 +9,7 @@ from .database import Database
from .database import DatabaseBody from .database import DatabaseBody
from .dictionary import Dictionary from .dictionary import Dictionary
from .enumeration import Enumeration from .enumeration import Enumeration
from .identifier_ir_map import IdentifierIRMap from .ir_map import IRMap
from .idl_type import IdlTypeFactory from .idl_type import IdlTypeFactory
from .interface import Interface from .interface import Interface
from .make_copy import make_copy from .make_copy import make_copy
...@@ -37,16 +37,14 @@ class IdlCompiler(object): ...@@ -37,16 +37,14 @@ class IdlCompiler(object):
2.1. y = process_and_update(x.copy()) 2.1. y = process_and_update(x.copy())
2.2. self._ir_map(phase=next_phase).add(y) 2.2. self._ir_map(phase=next_phase).add(y)
Note that an old IR for 'x' remains internally. See IdentifierIRMap for Note that an old IR for 'x' remains internally. See IRMap for the details.
the details.
""" """
def __init__(self, ir_map, ref_to_idl_def_factory, ref_to_idl_type_factory, def __init__(self, ir_map, ref_to_idl_def_factory, ref_to_idl_type_factory,
idl_type_factory, report_error): idl_type_factory, report_error):
""" """
Args: Args:
ir_map: IdentifierIRMap filled with the initial IRs of IDL ir_map: IRMap filled with the initial IRs of IDL definitions.
definitions.
ref_to_idl_def_factory: RefByIdFactory that created all references ref_to_idl_def_factory: RefByIdFactory that created all references
to UserDefinedType. to UserDefinedType.
ref_to_idl_type_factory: RefByIdFactory that created all references ref_to_idl_type_factory: RefByIdFactory that created all references
...@@ -58,7 +56,7 @@ class IdlCompiler(object): ...@@ -58,7 +56,7 @@ class IdlCompiler(object):
takes an error message of type str and return value is not used. takes an error message of type str and return value is not used.
It's okay to terminate the program in this callback. It's okay to terminate the program in this callback.
""" """
assert isinstance(ir_map, IdentifierIRMap) assert isinstance(ir_map, IRMap)
assert isinstance(ref_to_idl_def_factory, RefByIdFactory) assert isinstance(ref_to_idl_def_factory, RefByIdFactory)
assert isinstance(ref_to_idl_type_factory, RefByIdFactory) assert isinstance(ref_to_idl_type_factory, RefByIdFactory)
assert isinstance(idl_type_factory, IdlTypeFactory) assert isinstance(idl_type_factory, IdlTypeFactory)
...@@ -96,24 +94,21 @@ class IdlCompiler(object): ...@@ -96,24 +94,21 @@ class IdlCompiler(object):
return Database(self._db) return Database(self._db)
def _merge_partial_interfaces(self): def _merge_partial_interfaces(self):
old_interfaces = self._ir_map.find_by_kind( old_interfaces = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE)
IdentifierIRMap.IR.Kind.INTERFACE)
partial_interfaces = self._ir_map.find_by_kind( partial_interfaces = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.PARTIAL_INTERFACE) IRMap.IR.Kind.PARTIAL_INTERFACE)
old_mixins = self._ir_map.find_by_kind( old_mixins = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE_MIXIN)
IdentifierIRMap.IR.Kind.INTERFACE_MIXIN)
partial_mixins = self._ir_map.find_by_kind( partial_mixins = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.PARTIAL_INTERFACE_MIXIN) IRMap.IR.Kind.PARTIAL_INTERFACE_MIXIN)
self._ir_map.move_to_new_phase() self._ir_map.move_to_new_phase()
self._merge_interfaces(old_interfaces, partial_interfaces) self._merge_interfaces(old_interfaces, partial_interfaces)
self._merge_interfaces(old_mixins, partial_mixins) self._merge_interfaces(old_mixins, partial_mixins)
def _merge_partial_dictionaries(self): def _merge_partial_dictionaries(self):
old_dictionaries = self._ir_map.find_by_kind( old_dictionaries = self._ir_map.find_by_kind(IRMap.IR.Kind.DICTIONARY)
IdentifierIRMap.IR.Kind.DICTIONARY)
old_partial_dictionaries = self._ir_map.find_by_kind( old_partial_dictionaries = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.PARTIAL_DICTIONARY) IRMap.IR.Kind.PARTIAL_DICTIONARY)
self._ir_map.move_to_new_phase() self._ir_map.move_to_new_phase()
...@@ -129,10 +124,9 @@ class IdlCompiler(object): ...@@ -129,10 +124,9 @@ class IdlCompiler(object):
self._ir_map.add(new_dictionary) self._ir_map.add(new_dictionary)
def _merge_interface_mixins(self): def _merge_interface_mixins(self):
interfaces = self._ir_map.find_by_kind( interfaces = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE)
IdentifierIRMap.IR.Kind.INTERFACE)
interface_mixins = self._ir_map.find_by_kind( interface_mixins = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.INTERFACE_MIXIN) IRMap.IR.Kind.INTERFACE_MIXIN)
identifier_to_mixin_map = { identifier_to_mixin_map = {
identifier: [ identifier: [
...@@ -140,7 +134,7 @@ class IdlCompiler(object): ...@@ -140,7 +134,7 @@ class IdlCompiler(object):
for include in includes for include in includes
] ]
for identifier, includes in self._ir_map.find_by_kind( for identifier, includes in self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.INCLUDES).iteritems() IRMap.IR.Kind.INCLUDES).iteritems()
} }
self._ir_map.move_to_new_phase() self._ir_map.move_to_new_phase()
...@@ -171,8 +165,7 @@ class IdlCompiler(object): ...@@ -171,8 +165,7 @@ class IdlCompiler(object):
return [obj] + create_inheritance_stack( return [obj] + create_inheritance_stack(
table[obj.inherited.identifier], table) table[obj.inherited.identifier], table)
old_interfaces = self._ir_map.find_by_kind( old_interfaces = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE)
IdentifierIRMap.IR.Kind.INTERFACE)
self._ir_map.move_to_new_phase() self._ir_map.move_to_new_phase()
for old_interface in old_interfaces.itervalues(): for old_interface in old_interfaces.itervalues():
new_interface = make_copy(old_interface) new_interface = make_copy(old_interface)
...@@ -191,40 +184,36 @@ class IdlCompiler(object): ...@@ -191,40 +184,36 @@ class IdlCompiler(object):
def _create_public_objects(self): def _create_public_objects(self):
"""Creates public representations of compiled objects.""" """Creates public representations of compiled objects."""
interface_irs = self._ir_map.find_by_kind( interface_irs = self._ir_map.find_by_kind(IRMap.IR.Kind.INTERFACE)
IdentifierIRMap.IR.Kind.INTERFACE)
for ir in interface_irs.itervalues(): for ir in interface_irs.itervalues():
self._db.register(DatabaseBody.Kind.INTERFACE, Interface(ir)) self._db.register(DatabaseBody.Kind.INTERFACE, Interface(ir))
interface_mixin_irs = self._ir_map.find_by_kind( interface_mixin_irs = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.INTERFACE_MIXIN) IRMap.IR.Kind.INTERFACE_MIXIN)
for ir in interface_mixin_irs.itervalues(): for ir in interface_mixin_irs.itervalues():
self._db.register(DatabaseBody.Kind.INTERFACE_MIXIN, Interface(ir)) self._db.register(DatabaseBody.Kind.INTERFACE_MIXIN, Interface(ir))
dictionary_irs = self._ir_map.find_by_kind( dictionary_irs = self._ir_map.find_by_kind(IRMap.IR.Kind.DICTIONARY)
IdentifierIRMap.IR.Kind.DICTIONARY)
for ir in dictionary_irs.itervalues(): for ir in dictionary_irs.itervalues():
self._db.register(DatabaseBody.Kind.DICTIONARY, Dictionary(ir)) self._db.register(DatabaseBody.Kind.DICTIONARY, Dictionary(ir))
callback_interface_irs = self._ir_map.find_by_kind( callback_interface_irs = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.CALLBACK_INTERFACE) IRMap.IR.Kind.CALLBACK_INTERFACE)
for ir in callback_interface_irs.itervalues(): for ir in callback_interface_irs.itervalues():
self._db.register(DatabaseBody.Kind.CALLBACK_INTERFACE, self._db.register(DatabaseBody.Kind.CALLBACK_INTERFACE,
CallbackInterface(ir)) CallbackInterface(ir))
callback_function_irs = self._ir_map.find_by_kind( callback_function_irs = self._ir_map.find_by_kind(
IdentifierIRMap.IR.Kind.CALLBACK_FUNCTION) IRMap.IR.Kind.CALLBACK_FUNCTION)
for ir in callback_function_irs.itervalues(): for ir in callback_function_irs.itervalues():
self._db.register(DatabaseBody.Kind.CALLBACK_FUNCTION, self._db.register(DatabaseBody.Kind.CALLBACK_FUNCTION,
CallbackFunction(ir)) CallbackFunction(ir))
enum_irs = self._ir_map.find_by_kind( enum_irs = self._ir_map.find_by_kind(IRMap.IR.Kind.ENUMERATION)
IdentifierIRMap.IR.Kind.ENUMERATION)
for ir in enum_irs.itervalues(): for ir in enum_irs.itervalues():
self._db.register(DatabaseBody.Kind.ENUMERATION, Enumeration(ir)) self._db.register(DatabaseBody.Kind.ENUMERATION, Enumeration(ir))
typedef_irs = self._ir_map.find_by_kind( typedef_irs = self._ir_map.find_by_kind(IRMap.IR.Kind.TYPEDEF)
IdentifierIRMap.IR.Kind.TYPEDEF)
for ir in typedef_irs.itervalues(): for ir in typedef_irs.itervalues():
self._db.register(DatabaseBody.Kind.TYPEDEF, Typedef(ir)) self._db.register(DatabaseBody.Kind.TYPEDEF, Typedef(ir))
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
from .composition_parts import Identifier from .composition_parts import Identifier
from .composition_parts import WithComponent from .composition_parts import WithComponent
from .composition_parts import WithDebugInfo from .composition_parts import WithDebugInfo
from .identifier_ir_map import IdentifierIRMap from .ir_map import IRMap
class Includes(WithComponent, WithDebugInfo): class Includes(WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#include""" """https://heycam.github.io/webidl/#include"""
class IR(IdentifierIRMap.IR, WithComponent, WithDebugInfo): class IR(IRMap.IR, WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
interface_identifier, interface_identifier,
mixin_identifier, mixin_identifier,
...@@ -25,10 +25,10 @@ class Includes(WithComponent, WithDebugInfo): ...@@ -25,10 +25,10 @@ class Includes(WithComponent, WithDebugInfo):
# grouped by interface's identifier, for example, a group of mixins # grouped by interface's identifier, for example, a group of mixins
# are merged into an interface. So, the interface's identifier is # are merged into an interface. So, the interface's identifier is
# turned into this IR's identifier. # turned into this IR's identifier.
IdentifierIRMap.IR.__init__( IRMap.IR.__init__(
self, self,
identifier=interface_identifier, identifier=interface_identifier,
kind=IdentifierIRMap.IR.Kind.INCLUDES) kind=IRMap.IR.Kind.INCLUDES)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
......
...@@ -8,8 +8,8 @@ from .composition_parts import WithComponent ...@@ -8,8 +8,8 @@ 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 .constant import Constant
from .identifier_ir_map import IdentifierIRMap
from .idl_type import IdlType from .idl_type import IdlType
from .ir_map import IRMap
from .make_copy import make_copy from .make_copy import make_copy
from .operation import Operation from .operation import Operation
from .reference import RefById from .reference import RefById
...@@ -20,7 +20,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -20,7 +20,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-interfaces""" """https://heycam.github.io/webidl/#idl-interfaces"""
class IR(IdentifierIRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(IRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
...@@ -63,15 +63,15 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -63,15 +63,15 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
kind = None kind = None
if is_partial: if is_partial:
if is_mixin: if is_mixin:
kind = IdentifierIRMap.IR.Kind.PARTIAL_INTERFACE_MIXIN kind = IRMap.IR.Kind.PARTIAL_INTERFACE_MIXIN
else: else:
kind = IdentifierIRMap.IR.Kind.PARTIAL_INTERFACE kind = IRMap.IR.Kind.PARTIAL_INTERFACE
else: else:
if is_mixin: if is_mixin:
kind = IdentifierIRMap.IR.Kind.INTERFACE_MIXIN kind = IRMap.IR.Kind.INTERFACE_MIXIN
else: else:
kind = IdentifierIRMap.IR.Kind.INTERFACE kind = IRMap.IR.Kind.INTERFACE
IdentifierIRMap.IR.__init__(self, identifier=identifier, kind=kind) IRMap.IR.__init__(self, identifier=identifier, kind=kind)
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self, code_generator_info) WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithComponent.__init__( WithComponent.__init__(
......
...@@ -6,7 +6,7 @@ from .composition_parts import Identifier ...@@ -6,7 +6,7 @@ from .composition_parts import Identifier
from .composition_parts import WithIdentifier from .composition_parts import WithIdentifier
class IdentifierIRMap(object): class IRMap(object):
""" """
Manages an identifier-IR map, where IR is IdIRMap.IR. This class is Manages an identifier-IR map, where IR is IdIRMap.IR. This class is
designed to work together with IdlCompiler closely. See also designed to work together with IdlCompiler closely. See also
...@@ -96,8 +96,7 @@ class IdentifierIRMap(object): ...@@ -96,8 +96,7 @@ class IdentifierIRMap(object):
identifier for some kinds, e.g. partial interface and includes. identifier for some kinds, e.g. partial interface and includes.
This function returns True for such kinds. This function returns True for such kinds.
""" """
return IdentifierIRMap.IR.Kind.does_support_multiple_defs( return IRMap.IR.Kind.does_support_multiple_defs(self.kind)
self.kind)
def __init__(self): def __init__(self):
# IRs whose does_support_multiple_defs is False # IRs whose does_support_multiple_defs is False
...@@ -122,7 +121,7 @@ class IdentifierIRMap(object): ...@@ -122,7 +121,7 @@ class IdentifierIRMap(object):
Duplicated registration is not allowed. The registration must be for Duplicated registration is not allowed. The registration must be for
the first time. the first time.
""" """
assert isinstance(ir, IdentifierIRMap.IR), ir assert isinstance(ir, IRMap.IR), ir
# Assert |ir| doesn't yet exist in this map. # Assert |ir| doesn't yet exist in this map.
try: try:
if ir.does_support_multiple_defs: if ir.does_support_multiple_defs:
...@@ -140,7 +139,7 @@ class IdentifierIRMap(object): ...@@ -140,7 +139,7 @@ class IdentifierIRMap(object):
self.add(ir) self.add(ir)
def add(self, ir): def add(self, ir):
assert isinstance(ir, IdentifierIRMap.IR) assert isinstance(ir, IRMap.IR)
ir_map = (self._multiple_value_irs ir_map = (self._multiple_value_irs
if ir.does_support_multiple_defs else self._single_value_irs) if ir.does_support_multiple_defs else self._single_value_irs)
...@@ -162,34 +161,27 @@ class IdentifierIRMap(object): ...@@ -162,34 +161,27 @@ class IdentifierIRMap(object):
irs_per_kind[identifier].debug_info.location)) irs_per_kind[identifier].debug_info.location))
irs_per_kind[identifier] = ir irs_per_kind[identifier] = ir
def find_by_identifier(self, identifier, skip_current_phase=False): def find_by_identifier(self, identifier):
""" """
Returns the latest IR whose identifier is |identifier| and Returns the latest IR whose identifier is |identifier| and
does_support_multiple_defs is False. Raises KeyError, if not found. |does_support_multiple_defs| is False. Raises KeyError if not found.
If |skip_current_phase| is True, skips the current phase when looking
for the identifier.
""" """
assert isinstance(identifier, Identifier) assert isinstance(identifier, Identifier)
start_phase = self._current_phase - (1 if skip_current_phase else 0) for irs_per_phase in self._single_value_irs[self._current_phase::-1]:
for irs_per_phase in self._single_value_irs[start_phase::-1]:
for irs_per_kind in irs_per_phase.values(): for irs_per_kind in irs_per_phase.values():
if identifier in irs_per_kind: if identifier in irs_per_kind:
return irs_per_kind[identifier] return irs_per_kind[identifier]
raise KeyError(identifier) raise KeyError(identifier)
def find_by_kind(self, kind, skip_current_phase=False): def find_by_kind(self, kind):
""" """
Returns a map of identifier to IR(s) for the latest IRs of |kind|. Returns a map from identifiers to the latest IRs of |kind|. Returns an
empty map if not found.
If |skip_current_phase| is True, skips the current phase when looking
for the kind.
""" """
start_phase = self._current_phase - (1 if skip_current_phase else 0)
ir_map = (self._multiple_value_irs ir_map = (self._multiple_value_irs
if IdentifierIRMap.IR.Kind.does_support_multiple_defs(kind) if IRMap.IR.Kind.does_support_multiple_defs(kind) else
else self._single_value_irs) self._single_value_irs)
for irs_per_phase in ir_map[start_phase::-1]: for irs_per_phase in ir_map[self._current_phase::-1]:
if kind in irs_per_phase: if kind in irs_per_phase:
return irs_per_phase[kind] return irs_per_phase[kind]
return dict() return dict()
...@@ -9,14 +9,14 @@ from .composition_parts import WithComponent ...@@ -9,14 +9,14 @@ 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 .composition_parts import WithIdentifier from .composition_parts import WithIdentifier
from .identifier_ir_map import IdentifierIRMap from .ir_map import IRMap
class Namespace(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, class Namespace(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-namespaces""" """https://heycam.github.io/webidl/#idl-namespaces"""
class IR(IdentifierIRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo, class IR(IRMap.IR, WithExtendedAttributes, WithCodeGeneratorInfo,
WithComponent, WithDebugInfo): WithComponent, WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
...@@ -25,9 +25,9 @@ class Namespace(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -25,9 +25,9 @@ class Namespace(WithIdentifier, WithExtendedAttributes, WithCodeGeneratorInfo,
code_generator_info=None, code_generator_info=None,
component=None, component=None,
debug_info=None): debug_info=None):
kind = (IdentifierIRMap.IR.Kind.PARTIAL_NAMESPACE kind = (IRMap.IR.Kind.PARTIAL_NAMESPACE
if is_partial else IdentifierIRMap.IR.Kind.NAMESPACE) if is_partial else IRMap.IR.Kind.NAMESPACE)
IdentifierIRMap.IR.__init__(self, identifier=identifier, kind=kind) IRMap.IR.__init__(self, identifier=identifier, kind=kind)
WithExtendedAttributes.__init__(self, extended_attributes) WithExtendedAttributes.__init__(self, extended_attributes)
WithCodeGeneratorInfo.__init__(self, code_generator_info) WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
......
...@@ -6,7 +6,7 @@ from .composition_parts import WithCodeGeneratorInfo ...@@ -6,7 +6,7 @@ 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 WithIdentifier from .composition_parts import WithIdentifier
from .identifier_ir_map import IdentifierIRMap from .ir_map import IRMap
from .make_copy import make_copy from .make_copy import make_copy
...@@ -14,18 +14,15 @@ class Typedef(WithIdentifier, WithCodeGeneratorInfo, WithComponent, ...@@ -14,18 +14,15 @@ class Typedef(WithIdentifier, WithCodeGeneratorInfo, WithComponent,
WithDebugInfo): WithDebugInfo):
"""https://heycam.github.io/webidl/#idl-typedefs""" """https://heycam.github.io/webidl/#idl-typedefs"""
class IR(IdentifierIRMap.IR, WithCodeGeneratorInfo, WithComponent, class IR(IRMap.IR, WithCodeGeneratorInfo, WithComponent, WithDebugInfo):
WithDebugInfo):
def __init__(self, def __init__(self,
identifier, identifier,
idl_type, idl_type,
code_generator_info=None, code_generator_info=None,
component=None, component=None,
debug_info=None): debug_info=None):
IdentifierIRMap.IR.__init__( IRMap.IR.__init__(
self, self, identifier=identifier, kind=IRMap.IR.Kind.TYPEDEF)
identifier=identifier,
kind=IdentifierIRMap.IR.Kind.TYPEDEF)
WithCodeGeneratorInfo.__init__(self, code_generator_info) WithCodeGeneratorInfo.__init__(self, code_generator_info)
WithComponent.__init__(self, component) WithComponent.__init__(self, component)
WithDebugInfo.__init__(self, debug_info) WithDebugInfo.__init__(self, debug_info)
......
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