[Mesa-dev] [PATCH 3/5] vulkan: enum generator: make registry more flexible
Lionel Landwerlin
lionel.g.landwerlin at intel.com
Wed Jun 28 16:18:38 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 bf001b14582..91613b5436a 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.13.2
More information about the mesa-dev
mailing list