qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [PATCH v6 11/11] qapi: make 'if' condition strings simple identifiers
Date: Wed, 4 Aug 2021 12:22:38 +0400	[thread overview]
Message-ID: <CAMxuvayzE=TLtzw2zhyugZ-fxnE_rORMzjOAy6uiXvQeQRsp+A@mail.gmail.com> (raw)
In-Reply-To: <87bl6er6q8.fsf@dusky.pond.sub.org>

[-- Attachment #1: Type: text/plain, Size: 2855 bytes --]

On Tue, Aug 3, 2021 at 5:35 PM Markus Armbruster <armbru@redhat.com> wrote:

> marcandre.lureau@redhat.com writes:
>
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > Change the 'if' condition strings to be C-agnostic and be simple
> > identifiers.
>
> This is less general, and that's okay, we're doing it for a purpose.
> But the commit message should mention / explain all this.
>

ok


> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > Tested-by: John Snow <jsnow@redhat.com>
> > ---
>
> [...]
>
> > diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> > index f8718e201b..0c718e43c9 100644
> > --- a/scripts/qapi/common.py
> > +++ b/scripts/qapi/common.py
> > @@ -218,7 +218,7 @@ def cgen_ifcond(ifcond: Union[str, Dict[str, Any]])
> -> str:
> >      if not ifcond:
> >          return ''
> >      if isinstance(ifcond, str):
> > -        return ifcond
> > +        return 'defined(' + ifcond + ')'
> >
> >      oper, operands = next(iter(ifcond.items()))
> >      if oper == 'not':
> > diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
> > index d2bd52c49f..d355cbc8c1 100644
> > --- a/scripts/qapi/expr.py
> > +++ b/scripts/qapi/expr.py
> > @@ -281,10 +281,10 @@ def check_if(expr: _JSONObject, info:
> QAPISourceInfo, source: str) -> None:
> >
> >      def _check_if(cond: Union[str, object]) -> None:
> >          if isinstance(cond, str):
> > -            if not cond.strip():
> > +            if not cond.isidentifier():
>
> This accepts *Python* identifiers:
>
>     $ python
>     Python 3.9.6 (default, Jul 16 2021, 00:00:00)
>     [...]
>     >>> 'André'.isidentifier()
>     True
>
> These may or may not work for the languages we generate.  Wouldn't
> restricting identifiers to something like /[A-Z][A-Z0-9_]*/ make more
> sense?
>
>
yes, works for me


> >                  raise QAPISemError(
> >                      info,
> > -                    "'if' condition '%s' of %s makes no sense"
> > +                    "'if' condition '%s' of %s is not a valid
> identifier"
> >                      % (cond, source))
> >              return
> >
> > diff --git a/tests/qapi-schema/alternate-branch-if-invalid.err
> b/tests/qapi-schema/alternate-branch-if-invalid.err
> > index d384929c51..03bad877a3 100644
> > --- a/tests/qapi-schema/alternate-branch-if-invalid.err
> > +++ b/tests/qapi-schema/alternate-branch-if-invalid.err
> > @@ -1,2 +1,2 @@
> >  alternate-branch-if-invalid.json: In alternate 'Alt':
> > -alternate-branch-if-invalid.json:2: 'if' condition ' ' of 'data' member
> 'branch' makes no sense
> > +alternate-branch-if-invalid.json:2: 'if' condition ' ' of 'data' member
> 'branch' is not a valid identifier
>
> [...]
>
>

[-- Attachment #2: Type: text/html, Size: 4483 bytes --]

  reply	other threads:[~2021-08-04  8:23 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 10:24 [PATCH v6 00/11] qapi: untie 'if' conditions from C preprocessor marcandre.lureau
2021-06-18 10:24 ` [PATCH v6 01/11] docs: update the documentation upfront about schema configuration marcandre.lureau
2021-07-12 14:07   ` Markus Armbruster
2021-06-18 10:24 ` [PATCH v6 02/11] qapi: wrap Sequence[str] in an object marcandre.lureau
2021-08-02  9:21   ` Markus Armbruster
2021-08-03 17:55     ` John Snow
2021-08-04  8:22     ` Marc-André Lureau
2021-08-05 10:44       ` Markus Armbruster
2021-08-06 11:19       ` Markus Armbruster
2021-06-18 10:24 ` [PATCH v6 03/11] qapi: add QAPISchemaIfCond.is_present() marcandre.lureau
2021-08-02  9:52   ` Markus Armbruster
2021-08-04  8:22     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 04/11] qapi: _make_enum_members() to work with pre-built QAPISchemaIfCond marcandre.lureau
2021-08-02 10:41   ` Markus Armbruster
2021-08-04  8:22     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 05/11] qapi: introduce QAPISchemaIfCond.cgen() marcandre.lureau
2021-08-02 14:46   ` Markus Armbruster
2021-08-03 11:19     ` Markus Armbruster
2021-08-03 11:20       ` Markus Armbruster
2021-08-03 11:23         ` Markus Armbruster
2021-08-04  8:23     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 06/11] qapidoc: introduce QAPISchemaIfCond.docgen() marcandre.lureau
2021-08-02 15:47   ` Markus Armbruster
2021-08-04  8:23     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 07/11] qapi: replace if condition list with dict {'all': [...]} marcandre.lureau
2021-08-03 13:05   ` Markus Armbruster
2021-08-04  8:23     ` Marc-André Lureau
2021-08-05 15:11     ` John Snow
2021-08-03 13:17   ` Markus Armbruster
2021-06-18 10:25 ` [PATCH v6 08/11] qapi: add 'any' condition marcandre.lureau
2021-08-03 13:20   ` Markus Armbruster
2021-06-18 10:25 ` [PATCH v6 09/11] qapi: convert 'if' C-expressions to the new syntax tree marcandre.lureau
2021-08-03 13:22   ` Markus Armbruster
2021-06-18 10:25 ` [PATCH v6 10/11] qapi: add 'not' condition operation marcandre.lureau
2021-06-18 10:25 ` [PATCH v6 11/11] qapi: make 'if' condition strings simple identifiers marcandre.lureau
2021-08-03 13:35   ` Markus Armbruster
2021-08-04  8:22     ` Marc-André Lureau [this message]
2021-08-03 13:44 ` [PATCH v6 00/11] qapi: untie 'if' conditions from C preprocessor Markus Armbruster
2021-08-04  8:25   ` Marc-André Lureau

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='CAMxuvayzE=TLtzw2zhyugZ-fxnE_rORMzjOAy6uiXvQeQRsp+A@mail.gmail.com' \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).