qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: "Armbruster, Markus" <armbru@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v6 19/27] qapi: add 'if' on union members
Date: Sat, 8 Dec 2018 15:20:08 +0400	[thread overview]
Message-ID: <CAMxuvazcRTvbL-eF49F_grkyaHwjsta5qCb6i1tKNZT8H5O3bQ@mail.gmail.com> (raw)
In-Reply-To: <87efaua9wu.fsf@dusky.pond.sub.org>

Hi
On Thu, Dec 6, 2018 at 8:37 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> In the subject, s/ on / to /.
>
> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>
> > Add 'if' key to union members:
> >
> > { 'union': 'TestIfUnion', 'data':
> >     'mem': { 'type': 'str', 'if': 'COND'} }
> >
> > Generated code is not changed by this patch but with "qapi: add #if
> > conditions to generated code".
>
> My suggestion on PATCH 13's commit message applies.

ok

>
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  scripts/qapi/common.py                  | 17 +++++++++--------
> >  tests/qapi-schema/qapi-schema-test.json |  7 ++++++-
> >  tests/qapi-schema/qapi-schema-test.out  | 10 ++++++++++
> >  tests/qapi-schema/test-qapi.py          |  1 +
> >  4 files changed, 26 insertions(+), 9 deletions(-)
> >
> > diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> > index 13fbb28493..e1bd9a22ba 100644
> > --- a/scripts/qapi/common.py
> > +++ b/scripts/qapi/common.py
> > @@ -813,7 +813,7 @@ def check_union(expr, info):
> >      for (key, value) in members.items():
> >          check_name(info, "Member of union '%s'" % name, key)
> >          source = "member '%s' of union '%s'" % (key, name)
> > -        check_known_keys(info, source, value, ['type'], [])
> > +        check_known_keys(info, source, value, ['type'], ['if'])
> >          typ = value['type']
> >
> >          # Each value must name a known type
> > @@ -1496,8 +1496,8 @@ class QAPISchemaObjectTypeVariants(object):
> >  class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):
> >      role = 'branch'
> >
> > -    def __init__(self, name, typ):
> > -        QAPISchemaObjectTypeMember.__init__(self, name, typ, False)
> > +    def __init__(self, name, typ, ifcond=None):
> > +        QAPISchemaObjectTypeMember.__init__(self, name, typ, False, ifcond)
> >
> >
> >  class QAPISchemaAlternateType(QAPISchemaType):
> > @@ -1777,14 +1777,14 @@ class QAPISchema(object):
> >      def _make_variant(self, case, typ):
> >          return QAPISchemaObjectTypeVariant(case, typ)
> >
> > -    def _make_simple_variant(self, case, typ, info):
> > +    def _make_simple_variant(self, case, typ, ifcond, info):
> >          if isinstance(typ, list):
> >              assert len(typ) == 1
> >              typ = self._make_array_type(typ[0], info)
> >          typ = self._make_implicit_object_type(
> >              typ, info, None, self.lookup_type(typ),
> >              'wrapper', [self._make_member('data', typ, None, info)])
> > -        return QAPISchemaObjectTypeVariant(case, typ)
> > +        return QAPISchemaObjectTypeVariant(case, typ, ifcond)
> >
> >      def _def_union_type(self, expr, info, doc):
> >          name = expr['union']
> > @@ -1802,10 +1802,11 @@ class QAPISchema(object):
> >                          for (key, value) in data.items()]
> >              members = []
> >          else:
> > -            variants = [self._make_simple_variant(key, value['type'], info)
> > +            variants = [self._make_simple_variant(key, value['type'],
> > +                                                  value.get('if'), info)
> >                          for (key, value) in data.items()]
> > -            typ = self._make_implicit_enum_type(name, info, ifcond,
> > -                                                [v.name for v in variants])
> > +            enum = [{'name': v.name, 'if': v.ifcond} for v in variants]
> > +            typ = self._make_implicit_enum_type(name, info, ifcond, enum)
> >              tag_member = QAPISchemaObjectTypeMember('type', typ, False)
> >              members = [tag_member]
> >          self._def_entity(
> > diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
> > index 3bf440aab4..6d3c6c0b53 100644
> > --- a/tests/qapi-schema/qapi-schema-test.json
> > +++ b/tests/qapi-schema/qapi-schema-test.json
> > @@ -208,9 +208,14 @@
> >    [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
> >    'if': 'defined(TEST_IF_ENUM)' }
> >
> > -{ 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' },
> > +{ 'union': 'TestIfUnion', 'data':
> > +  { 'foo': 'TestStruct',
> > +    'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} },
>
> "Union Bar" sounds like a cocktail lounge in northeast US :)
>
> Back to serious: this is a simple union.  I'd prefer to test flat
> unions.  Changing TestIfUnion accordingly could be done either before
> this patch, or on top of this series, the latter not necessarily by
> you.  Your choice.

I prefer to defer

>
> >    'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
> >
> > +{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
> > +  'if': 'defined(TEST_IF_UNION)' }
> > +
>
> I'm feeling dense... why does this change belong to this patch?

Hmm, no strong reason, I'll make it a separate commit.
>
> >  { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct' },
> >    'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
> >
> > diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
> > index 71b84878c7..ac1069cf1f 100644
> > --- a/tests/qapi-schema/qapi-schema-test.out
> > +++ b/tests/qapi-schema/qapi-schema-test.out
> > @@ -278,12 +278,22 @@ object q_obj_TestStruct-wrapper
> >      member data: TestStruct optional=False
> >  enum TestIfUnionKind
> >      member foo
> > +    member union_bar
> > +        if ['defined(TEST_IF_UNION_BAR)']
> >      if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
> >  object TestIfUnion
> >      member type: TestIfUnionKind optional=False
> >      tag type
> >      case foo: q_obj_TestStruct-wrapper
> > +    case union_bar: q_obj_str-wrapper
> > +        if ['defined(TEST_IF_UNION_BAR)']
> >      if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
> > +object q_obj_TestIfUnionCmd-arg
> > +    member union_cmd_arg: TestIfUnion optional=False
> > +    if ['defined(TEST_IF_UNION)']
> > +command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None
> > +   gen=True success_response=True boxed=False oob=False preconfig=False
> > +    if ['defined(TEST_IF_UNION)']
> >  alternate TestIfAlternate
> >      tag type
> >      case foo: int
> > diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
> > index 69e40d87d2..d977e936c7 100644
> > --- a/tests/qapi-schema/test-qapi.py
> > +++ b/tests/qapi-schema/test-qapi.py
> > @@ -68,6 +68,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
> >              print('    tag %s' % variants.tag_member.name)
> >              for v in variants.variants:
> >                  print('    case %s: %s' % (v.name, v.type.name))
> > +                QAPISchemaTestVisitor._print_if(v.ifcond, 8)
> >
> >      @staticmethod
> >      def _print_if(ifcond, indent=4):

  reply	other threads:[~2018-12-08 11:20 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06 10:57 [Qemu-devel] [PATCH v6 00/27] qapi: add #if pre-processor conditions to generated code (part 2) Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 01/27] qmp-shell: learn to send commands with quoted arguments Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 02/27] json: remove useless return value from lexer/parser Marc-André Lureau
2018-07-08  6:09   ` Thomas Huth
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 03/27] tests: change /0.15/* tests to /qmp/* Marc-André Lureau
2018-07-08  6:05   ` Thomas Huth
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 04/27] qapi: Fix some pycodestyle-3 complaints Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 05/27] qapi: include osdep.h in type headers Marc-André Lureau
2018-12-04 15:23   ` Markus Armbruster
2018-12-04 15:32     ` Marc-André Lureau
2018-12-04 16:30       ` Eric Blake
2018-12-04 16:37       ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 06/27] qapi: do not define enumeration value explicitly Marc-André Lureau
2018-12-05 13:19   ` Markus Armbruster
2018-12-08 11:20     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 07/27] qapi: rename QAPISchemaEnumType.values to .members Marc-André Lureau
2018-12-05 13:42   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 08/27] qapi: change enum visitor and gen_enum* to take QAPISchemaMember Marc-André Lureau
2018-12-05 14:02   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 09/27] tests: print enum type members more like object type members Marc-André Lureau
2018-12-05 14:04   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 10/27] qapi: factor out checking for keys Marc-André Lureau
2018-12-05 16:26   ` Markus Armbruster
2018-12-07 11:26     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 11/27] qapi: improve reporting of unknown or missing keys Marc-André Lureau
2018-12-05 16:38   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 12/27] qapi: add a dictionnary form with 'name' key for enum members Marc-André Lureau
2018-12-05 18:02   ` Markus Armbruster
2018-12-08 11:20     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 13/27] qapi: add 'if' to " Marc-André Lureau
2018-12-05 18:29   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 14/27] qapi-event: add 'if' condition to implicit event enum Marc-André Lureau
2018-12-05 18:30   ` Markus Armbruster
2018-12-06 16:02     ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 15/27] qapi: rename allow_dict to allow_implicit Marc-André Lureau
2018-12-05 18:41   ` Markus Armbruster
2018-12-08 11:20     ` Marc-André Lureau
2018-12-10  8:50       ` Markus Armbruster
2018-12-10 11:15         ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 16/27] qapi: add a dictionary form with 'type' key for members Marc-André Lureau
2018-12-06 15:56   ` Markus Armbruster
2018-12-08 11:20     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 17/27] qapi: add 'if' to implicit struct members Marc-André Lureau
2018-12-06 16:11   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 18/27] qapi: add an error in case a discriminator is conditionnal Marc-André Lureau
2018-12-06 16:25   ` Markus Armbruster
2018-12-06 16:26     ` Markus Armbruster
2018-12-10 18:32     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 19/27] qapi: add 'if' on union members Marc-André Lureau
2018-12-06 16:37   ` Markus Armbruster
2018-12-08 11:20     ` Marc-André Lureau [this message]
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 20/27] qapi: add 'if' to alternate members Marc-André Lureau
2018-12-06 16:41   ` Markus Armbruster
2018-12-08 11:20     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 21/27] qapi: add #if conditions to generated code members Marc-André Lureau
2018-12-06 17:42   ` Markus Armbruster
2018-12-08 11:19     ` Marc-André Lureau
2018-12-10  7:17       ` Markus Armbruster
2018-12-10 10:11         ` Markus Armbruster
2018-12-10 11:17           ` Marc-André Lureau
2018-12-10 18:38           ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 22/27] docs: document schema configuration Marc-André Lureau
2018-12-06 18:14   ` Markus Armbruster
2018-12-08 11:19     ` Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 23/27] qapi: add 'If:' condition to enum values documentation Marc-André Lureau
2018-12-06 18:46   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 24/27] qapi: add 'If:' condition to struct members documentation Marc-André Lureau
2018-12-06 18:47   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 25/27] qapi: add condition to variants documentation Marc-André Lureau
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 26/27] qapi: add more conditions to SPICE Marc-André Lureau
2018-12-06 18:54   ` Markus Armbruster
2018-07-06 10:57 ` [Qemu-devel] [PATCH v6 27/27] qapi: add conditions to REPLICATION type/commands on the schema Marc-André Lureau
2018-12-06 18:55   ` Markus Armbruster
2018-10-02 20:56 ` [Qemu-devel] [PATCH v6 00/27] qapi: add #if pre-processor conditions to generated code (part 2) Marc-André Lureau
2018-11-08 12:22 ` Marc-André Lureau
2018-12-06 19:13 ` Markus Armbruster

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=CAMxuvazcRTvbL-eF49F_grkyaHwjsta5qCb6i1tKNZT8H5O3bQ@mail.gmail.com \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).