Commit 091aa33e authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

IDL Compiler: Sort dictionary members

The order of dictionary members are defined to be sorted in alphabetical
order.  This CL adds a phase to do it in IDL compiler.


Bug: 839389
Change-Id: Ic5f59af8aced0de50318ba45f3398d0b1a878de1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1943779Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720401}
parent e9115d25
...@@ -167,7 +167,7 @@ def make_fill_with_own_dict_members_def(cg_context): ...@@ -167,7 +167,7 @@ def make_fill_with_own_dict_members_def(cg_context):
T = TextNode T = TextNode
dictionary = cg_context.dictionary dictionary = cg_context.dictionary
own_members = sorted(dictionary.own_members, key=lambda m: m.identifier) own_members = dictionary.own_members
func_name = _format( func_name = _format(
"{_1}::FillWithOwnMembers", _1=blink_class_name(dictionary)) "{_1}::FillWithOwnMembers", _1=blink_class_name(dictionary))
...@@ -249,7 +249,7 @@ def make_fill_dict_members_def(cg_context): ...@@ -249,7 +249,7 @@ def make_fill_dict_members_def(cg_context):
dictionary = cg_context.dictionary dictionary = cg_context.dictionary
class_name = blink_class_name(dictionary) class_name = blink_class_name(dictionary)
own_members = sorted(dictionary.own_members, key=lambda m: m.identifier) own_members = dictionary.own_members
required_own_members = list( required_own_members = list(
member for member in own_members if member.is_required) member for member in own_members if member.is_required)
...@@ -306,7 +306,7 @@ def make_fill_dict_members_internal_def(cg_context): ...@@ -306,7 +306,7 @@ def make_fill_dict_members_internal_def(cg_context):
T = TextNode T = TextNode
dictionary = cg_context.dictionary dictionary = cg_context.dictionary
own_members = sorted(dictionary.own_members, key=lambda m: m.identifier) own_members = dictionary.own_members
class_name = blink_class_name(dictionary) class_name = blink_class_name(dictionary)
func_name = _format("{_1}::FillMembersInternal", _1=class_name) func_name = _format("{_1}::FillMembersInternal", _1=class_name)
...@@ -397,7 +397,7 @@ def make_dict_trace_def(cg_context): ...@@ -397,7 +397,7 @@ def make_dict_trace_def(cg_context):
T = TextNode T = TextNode
dictionary = cg_context.dictionary dictionary = cg_context.dictionary
own_members = sorted(dictionary.own_members, key=lambda m: m.identifier) own_members = dictionary.own_members
class_name = blink_class_name(dictionary) class_name = blink_class_name(dictionary)
func_def = FunctionDefinitionNode( func_def = FunctionDefinitionNode(
...@@ -446,7 +446,7 @@ def generate_dictionaries(web_idl_database, output_dirs): ...@@ -446,7 +446,7 @@ def generate_dictionaries(web_idl_database, output_dirs):
make_dict_trace_def(cg_context), make_dict_trace_def(cg_context),
]) ])
for member in sorted(dictionary.own_members, key=lambda x: x.identifier): for member in dictionary.own_members:
code_node.extend([ code_node.extend([
make_dict_member_get_def(cg_context.make_copy(dict_member=member)), make_dict_member_get_def(cg_context.make_copy(dict_member=member)),
make_dict_member_has_def(cg_context.make_copy(dict_member=member)), make_dict_member_has_def(cg_context.make_copy(dict_member=member)),
......
...@@ -85,8 +85,7 @@ class Dictionary(UserDefinedType, WithExtendedAttributes, ...@@ -85,8 +85,7 @@ class Dictionary(UserDefinedType, WithExtendedAttributes,
""" """
Returns own dictionary members. Inherited members are not included. Returns own dictionary members. Inherited members are not included.
Note that members are not sorted alphabetically. The order should be Members are sorted by their identifiers alphabetically.
the declaration order.
""" """
return self._own_members return self._own_members
...@@ -100,9 +99,9 @@ class Dictionary(UserDefinedType, WithExtendedAttributes, ...@@ -100,9 +99,9 @@ class Dictionary(UserDefinedType, WithExtendedAttributes,
def collect_inherited_members(dictionary): def collect_inherited_members(dictionary):
if dictionary is None: if dictionary is None:
return [] return ()
return (collect_inherited_members(dictionary.inherited) + sorted( return (collect_inherited_members(dictionary.inherited) +
dictionary.own_members, key=lambda member: member.identifier)) dictionary.own_members)
return tuple(collect_inherited_members(self)) return tuple(collect_inherited_members(self))
......
...@@ -90,6 +90,8 @@ class IdlCompiler(object): ...@@ -90,6 +90,8 @@ class IdlCompiler(object):
self._group_overloaded_functions() self._group_overloaded_functions()
self._calculate_group_exposure() self._calculate_group_exposure()
self._sort_dictionary_members()
# Updates on IRs are finished. Create API objects. # Updates on IRs are finished. Create API objects.
self._create_public_objects() self._create_public_objects()
...@@ -357,6 +359,18 @@ class IdlCompiler(object): ...@@ -357,6 +359,18 @@ class IdlCompiler(object):
])) ]))
group.exposure.set_only_in_secure_contexts(flag_names) group.exposure.set_only_in_secure_contexts(flag_names)
def _sort_dictionary_members(self):
"""Sorts dictionary members in alphabetical order."""
old_irs = self._ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY)
self._ir_map.move_to_new_phase()
for old_ir in old_irs:
new_ir = make_copy(old_ir)
self._ir_map.add(new_ir)
new_ir.own_members.sort(key=lambda x: x.identifier)
def _create_public_objects(self): def _create_public_objects(self):
"""Creates public representations of compiled objects.""" """Creates public representations of compiled objects."""
for ir in self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE): for ir in self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE):
......
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