[Mesa-dev] [PATCH 04/15] vulkan: enum generator: make registry more flexible
Lionel Landwerlin
lionel.g.landwerlin at intel.com
Fri Sep 15 14:10:56 UTC 2017
It will be used to store extension numbers as well.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
src/vulkan/util/gen_enum_to_str.py | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
index d09e256965f..28bfbfde235 100644
--- a/src/vulkan/util/gen_enum_to_str.py
+++ b/src/vulkan/util/gen_enum_to_str.py
@@ -98,19 +98,18 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\
#endif"""),
output_encoding='utf-8')
-
-class EnumFactory(object):
+class NamedFactory(object):
"""Factory for creating enums."""
def __init__(self, type_):
self.registry = {}
self.type = type_
- def __call__(self, name):
+ def __call__(self, *args):
try:
- return self.registry[name]
+ return self.registry[args[0]]
except KeyError:
- n = self.registry[name] = self.type(name)
+ n = self.registry[args[0]] = self.type(*args)
return n
@@ -128,7 +127,7 @@ def xml_parser(filename):
This parser is a memory efficient iterative XML parser that returns a list
of VkEnum objects.
"""
- efactory = EnumFactory(VkEnum)
+ enum_factory = NamedFactory(VkEnum)
with open(filename, 'rb') as f:
context = iter(et.iterparse(f, events=('start', 'end')))
@@ -142,19 +141,19 @@ def xml_parser(filename):
if event == 'end' and elem.tag == 'enums':
type_ = elem.attrib.get('type')
if type_ == 'enum':
- enum = efactory(elem.attrib['name'])
+ enum = enum_factory(elem.attrib['name'])
enum.values.extend([e.attrib['name'] for e in elem
if e.tag == 'enum'])
elif event == 'end' and elem.tag == 'extension':
if elem.attrib['supported'] != 'vulkan':
continue
for e in elem.findall('.//enum[@extends][@offset]'):
- enum = efactory(e.attrib['extends'])
- enum.values.append(e.attrib['name'])
+ enum = enum_factory(e.attrib['extends'])
+ enum.values.append(e.attrib['name'],)
root.clear()
- return efactory.registry.values()
+ return enum_factory.registry.values()
def main():
--
2.14.1
More information about the mesa-dev
mailing list