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