[Mesa-dev] [PATCH 04/15] vulkan: enum generator: make registry more flexible
Jason Ekstrand
jason at jlekstrand.net
Fri Sep 15 21:27:50 UTC 2017
On Fri, Sep 15, 2017 at 7:10 AM, Lionel Landwerlin <
lionel.g.landwerlin at intel.com> wrote:
> 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'],)
>
There's an extra comma here I don't think you need.
>
> root.clear()
>
> - return efactory.registry.values()
> + return enum_factory.registry.values()
>
>
> def main():
> --
> 2.14.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170915/459687e9/attachment.html>
More information about the mesa-dev
mailing list