From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
qemu-devel@nongnu.org,
"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>
Subject: Re: [PATCH v3 2/3] qapi: Do not generate empty enum
Date: Tue, 21 Mar 2023 20:00:25 +0100 [thread overview]
Message-ID: <87sfdyaq0m.fsf@pond.sub.org> (raw)
In-Reply-To: <d312145c-8af2-c8ca-ec45-4f6f060b3b07@linaro.org> ("Philippe Mathieu-Daudé"'s message of "Tue, 21 Mar 2023 15:48:12 +0100")
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> Can we meet half-way only generating the MAX definitions for
> unconditional enums, keeping the conditional ones as is?
>
> -- >8 --
> diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
> @@ -88,16 +88,18 @@ def gen_enum(name: str,
> members: List[QAPISchemaEnumMember],
> prefix: Optional[str] = None) -> str:
> assert members
> - # append automatically generated _MAX value
> - enum_members = members + [QAPISchemaEnumMember('_MAX', None)]
> -
> ret = mcgen('''
>
> typedef enum %(c_name)s {
> ''',
> c_name=c_name(name))
>
> - for memb in enum_members:
> + has_cond = any(memb.ifcond.is_present() for memb in members)
> + if has_cond:
> + # append automatically generated _MAX value
> + members += [QAPISchemaEnumMember('_MAX', None)]
> +
> + for memb in members:
> ret += memb.ifcond.gen_if()
> ret += mcgen('''
> %(c_enum)s,
> @@ -105,6 +107,13 @@ def gen_enum(name: str,
> c_enum=c_enum_const(name, memb.name, prefix))
> ret += memb.ifcond.gen_endif()
>
> + if not has_cond:
> + ret += mcgen('''
> +#define %(c_name)s %(c_length)s
> +''',
> + c_name=c_enum_const(name, '_MAX', prefix),
> + c_length=len(members))
> +
> ret += mcgen('''
> } %(c_name)s;
> ''',
> ---
I doubt the benefit "we need a silly case FOO__MAX only sometimes" is
worth the special case.
We could generate something like
#if [last_member's condition]
#define FOO__MAX (FOO_last_member + 1)
#elif [second_to_last_member's condition]
#define FOO__MAX (FOO_second_to_last_member + 1)
...
#else
#define FOO__MAX (FOO_last_unconditional_member + 1)
#endif
but whether that is worth the additional complexity seems doubtful, too.
next prev parent reply other threads:[~2023-03-21 19:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-15 11:28 [PATCH v3 0/3] qapi: Simplify enum generation Philippe Mathieu-Daudé
2023-03-15 11:28 ` [PATCH v3 1/3] scripts/git.orderfile: Display QAPI script changes before schema ones Philippe Mathieu-Daudé
2023-03-15 15:14 ` Philippe Mathieu-Daudé
2023-03-15 20:30 ` Juan Quintela
2023-03-15 11:28 ` [PATCH v3 2/3] qapi: Do not generate empty enum Philippe Mathieu-Daudé
2023-03-15 15:02 ` Richard Henderson
2023-03-16 12:31 ` Markus Armbruster
2023-03-16 13:54 ` Daniel P. Berrangé
2023-03-16 14:39 ` Juan Quintela
2023-03-16 14:42 ` Daniel P. Berrangé
2023-03-16 14:57 ` Markus Armbruster
2023-03-21 14:31 ` Philippe Mathieu-Daudé
2023-03-21 15:19 ` Daniel P. Berrangé
2023-03-21 21:43 ` Eric Blake
2023-03-22 5:45 ` Markus Armbruster
2023-03-21 14:48 ` Philippe Mathieu-Daudé
2023-03-21 19:00 ` Markus Armbruster [this message]
2023-03-15 11:28 ` [PATCH v3 3/3] qapi: Generate enum count as definition Philippe Mathieu-Daudé
2023-03-15 19:58 ` Dr. David Alan Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfdyaq0m.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=pavel.dovgaluk@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanb@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.