From: Jason Ekstrand Date: Wed, 26 Jun 2019 18:35:54 +0000 (-0500) Subject: vulkan/enum_to_str: Handle out-of-order aliases X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=121551bfdb07786c8e26b712d87c8564bda556b4;p=mesa.git vulkan/enum_to_str: Handle out-of-order aliases The current code can only handle enum aliases if the original enum is declared first followed by the alias as we walk the XML in a linear fashion. This commit allows us to handle aliases where the alias declaration comes before the thing it's aliasing. Reviewed-by: Lionel Landwerlin --- diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py index b65bc7f7ef6..035aa02a172 100644 --- a/src/vulkan/util/gen_enum_to_str.py +++ b/src/vulkan/util/gen_enum_to_str.py @@ -258,10 +258,23 @@ class VkEnum(object): self.values = values or dict() self.name_to_value = dict() self.guard = None + self.name_to_alias_list = {} def add_value(self, name, value=None, - extnum=None, offset=None, + extnum=None, offset=None, alias=None, error=False): + if alias is not None: + assert value is None and offset is None + if alias not in self.name_to_value: + # We don't have this alias yet. Just record the alias and + # we'll deal with it later. + alias_list = self.name_to_alias_list.get(alias, []) + alias_list.append(name); + return + + # Use the value from the alias + value = self.name_to_value[alias] + assert value is not None or extnum is not None if value is None: value = 1000000000 + (extnum - 1) * 1000 + offset @@ -274,14 +287,19 @@ class VkEnum(object): elif len(self.values[value]) > len(name): self.values[value] = name + # Now that the value has been fully added, resolve aliases, if any. + if name in self.name_to_alias_list: + for alias in self.name_to_alias_list[name]: + add_value(alias, value) + del self.name_to_alias_list[name] + def add_value_from_xml(self, elem, extension=None): self.extension = extension if 'value' in elem.attrib: self.add_value(elem.attrib['name'], value=int(elem.attrib['value'], base=0)) elif 'alias' in elem.attrib: - self.add_value(elem.attrib['name'], - value=self.name_to_value[elem.attrib['alias']]) + self.add_value(elem.attrib['name'], alias=elem.attrib['alias']) else: error = 'dir' in elem.attrib and elem.attrib['dir'] == '-' if 'extnumber' in elem.attrib: