Skip to content

Commit

Permalink
IDL Compiler: Respect split of single/multi-value IR map.
Browse files Browse the repository at this point in the history
Minor refactoring of IdentifierIRMap.find_by_kind.

Bug: 839389
Change-Id: I60269a84db28d921d6a0ce8d537e37a623f884d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1681721
Reviewed-by: Hitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673302}
  • Loading branch information
yuki3 authored and Commit Bot committed Jun 28, 2019
1 parent 6894c69 commit d195986
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ class Kind(object):
PARTIAL_NAMESPACE = 'partial namespace'
TYPEDEF = 'typedef'

_MULTI_VALUE_KINDS = (
INCLUDES,
PARTIAL_DICTIONARY,
PARTIAL_INTERFACE,
PARTIAL_INTERFACE_MIXIN,
PARTIAL_NAMESPACE,
)

@classmethod
def does_support_multiple_defs(cls, kind):
return kind in cls._MULTI_VALUE_KINDS

def __init__(self, identifier, kind):
WithIdentifier.__init__(self, identifier)
self._kind = kind
Expand All @@ -83,13 +95,8 @@ def does_support_multiple_defs(self):
identifier for some kinds, e.g. partial interface and includes.
This function returns True for such kinds.
"""
return self.kind in (
IdentifierIRMap.IR.Kind.INCLUDES,
IdentifierIRMap.IR.Kind.PARTIAL_DICTIONARY,
IdentifierIRMap.IR.Kind.PARTIAL_INTERFACE,
IdentifierIRMap.IR.Kind.PARTIAL_INTERFACE_MIXIN,
IdentifierIRMap.IR.Kind.PARTIAL_NAMESPACE,
)
return IdentifierIRMap.IR.Kind.does_support_multiple_defs(
self.kind)

def __init__(self):
# IRs whose does_support_multiple_defs is False
Expand Down Expand Up @@ -173,9 +180,10 @@ def find_by_kind(self, kind, skip_current_phase=False):
for the kind.
"""
start_phase = self._current_phase - (1 if skip_current_phase else 0)
for phase in range(start_phase, -1, -1):
if kind in self._single_value_irs[phase]:
return self._single_value_irs[phase][kind]
if kind in self._multiple_value_irs[phase]:
return self._multiple_value_irs[phase][kind]
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 kind in irs_per_phase:
return irs_per_phase[kind]
return dict()

0 comments on commit d195986

Please sign in to comment.