mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 13:28:06 +02:00
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 <lionel.g.landwerlin@intel.com>
This commit is contained in:
parent
f6aa51103b
commit
121551bfdb
1 changed files with 21 additions and 3 deletions
|
|
@ -258,10 +258,23 @@ class VkEnum(object):
|
||||||
self.values = values or dict()
|
self.values = values or dict()
|
||||||
self.name_to_value = dict()
|
self.name_to_value = dict()
|
||||||
self.guard = None
|
self.guard = None
|
||||||
|
self.name_to_alias_list = {}
|
||||||
|
|
||||||
def add_value(self, name, value=None,
|
def add_value(self, name, value=None,
|
||||||
extnum=None, offset=None,
|
extnum=None, offset=None, alias=None,
|
||||||
error=False):
|
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
|
assert value is not None or extnum is not None
|
||||||
if value is None:
|
if value is None:
|
||||||
value = 1000000000 + (extnum - 1) * 1000 + offset
|
value = 1000000000 + (extnum - 1) * 1000 + offset
|
||||||
|
|
@ -274,14 +287,19 @@ class VkEnum(object):
|
||||||
elif len(self.values[value]) > len(name):
|
elif len(self.values[value]) > len(name):
|
||||||
self.values[value] = 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):
|
def add_value_from_xml(self, elem, extension=None):
|
||||||
self.extension = extension
|
self.extension = extension
|
||||||
if 'value' in elem.attrib:
|
if 'value' in elem.attrib:
|
||||||
self.add_value(elem.attrib['name'],
|
self.add_value(elem.attrib['name'],
|
||||||
value=int(elem.attrib['value'], base=0))
|
value=int(elem.attrib['value'], base=0))
|
||||||
elif 'alias' in elem.attrib:
|
elif 'alias' in elem.attrib:
|
||||||
self.add_value(elem.attrib['name'],
|
self.add_value(elem.attrib['name'], alias=elem.attrib['alias'])
|
||||||
value=self.name_to_value[elem.attrib['alias']])
|
|
||||||
else:
|
else:
|
||||||
error = 'dir' in elem.attrib and elem.attrib['dir'] == '-'
|
error = 'dir' in elem.attrib and elem.attrib['dir'] == '-'
|
||||||
if 'extnumber' in elem.attrib:
|
if 'extnumber' in elem.attrib:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue