[Mesa-dev] [PATCH 3/6] vulkan: enum generator: make registry more flexible

Dylan Baker dylan at pnwbakers.com
Thu Sep 21 17:25:22 UTC 2017


Quoting Jason Ekstrand (2017-09-21 08:32:20)
> From: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> 
> It will be used to store extension numbers as well.
> 
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
> ---
>  src/vulkan/util/gen_enum_to_str.py | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
> index efe5d4f..5281e89 100644
> --- a/src/vulkan/util/gen_enum_to_str.py
> +++ b/src/vulkan/util/gen_enum_to_str.py
> @@ -115,18 +115,18 @@ FOREIGN_ENUM_VALUES = [
>  ]
>  
>  
> -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):

This is pretty ugly and clunky. What about
__call__(self, name, **kwargs), and pass kwargs directly to the type?

>          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
>  
>  
> @@ -138,7 +138,7 @@ class VkEnum(object):
>          self.values = values or []
>  
>  
> -def parse_xml(efactory, filename):
> +def parse_xml(enum_factory, filename):
>      """Parse the XML file. Accumulate results into the efactory.
>  
>      This parser is a memory efficient iterative XML parser that returns a list
> @@ -157,15 +157,15 @@ def parse_xml(efactory, 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()
>  
> @@ -182,10 +182,10 @@ def main():
>  
>      args = parser.parse_args()
>  
> -    efactory = EnumFactory(VkEnum)
> +    enum_factory = NamedFactory(VkEnum)
>      for filename in args.xml_files:
> -        parse_xml(efactory, filename)
> -    enums=sorted(efactory.registry.values(), key=lambda e: e.name)
> +        parse_xml(enum_factory, filename)
> +    enums=sorted(enum_factory.registry.values(), key=lambda e: e.name)
>  
>      for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')),
>                              (H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:
> -- 
> 2.5.0.400.gff86faf
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170921/c7f040a8/attachment.sig>


More information about the mesa-dev mailing list