From 7fb86fb511e2ff15c3a67f187713797f28b2e460 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 21 Sep 2017 08:26:06 -0700 Subject: [PATCH] vulkan/enum_to_str: Add support for aliases and new Vulkan versions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Samuel Iglesias Gonsálvez --- src/vulkan/util/gen_enum_to_str.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py index 6182055442f..bf883d5cb8f 100644 --- a/src/vulkan/util/gen_enum_to_str.py +++ b/src/vulkan/util/gen_enum_to_str.py @@ -152,28 +152,38 @@ class VkEnum(object): self.name = name # Maps numbers to names self.values = values or dict() + self.name_to_value = dict() def add_value(self, name, value=None, - extension=None, offset=None, + extnum=None, offset=None, error=False): - assert value is not None or extension is not None + assert value is not None or extnum is not None if value is None: - value = 1000000000 + (extension.number - 1) * 1000 + offset + value = 1000000000 + (extnum - 1) * 1000 + offset if error: value = -value + self.name_to_value[name] = value if value not in self.values: self.values[value] = name + elif len(self.values[value]) > len(name): + self.values[value] = name def add_value_from_xml(self, elem, extension=None): if 'value' in elem.attrib: self.add_value(elem.attrib['name'], value=int(elem.attrib['value'])) + elif 'alias' in elem.attrib: + self.add_value(elem.attrib['name'], + value=self.name_to_value[elem.attrib['alias']]) else: error = 'dir' in elem.attrib and elem.attrib['dir'] == '-' - print(elem.attrib['name']) + if 'extnumber' in elem.attrib: + extnum = int(elem.attrib['extnumber']) + else: + extnum = extension.number self.add_value(elem.attrib['name'], - extension=extension, + extnum=extnum, offset=int(elem.attrib['offset']), error=error) @@ -192,6 +202,11 @@ def parse_xml(enum_factory, ext_factory, filename): for value in enum_type.findall('./enum'): enum.add_value_from_xml(value) + for value in xml.findall('./feature/require/enum[@extends]'): + enum = enum_factory.get(value.attrib['extends']) + if enum is not None: + enum.add_value_from_xml(value) + for ext_elem in xml.findall('./extensions/extension[@supported="vulkan"]'): extension = ext_factory(ext_elem.attrib['name'], number=int(ext_elem.attrib['number'])) -- 2.30.2