qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, "Eric Blake" <eblake@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	stefanha@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH v6 10/11] qapi: add 'not' condition operation
Date: Fri, 18 Jun 2021 14:25:06 +0400	[thread overview]
Message-ID: <20210618102507.3761128-11-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20210618102507.3761128-1-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

For the sake of completeness, introduce the 'not' condition.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi/common.py                  | 4 ++++
 scripts/qapi/expr.py                    | 7 +++++--
 tests/qapi-schema/bad-if.err            | 2 +-
 tests/qapi-schema/doc-good.json         | 3 ++-
 tests/qapi-schema/doc-good.out          | 1 +
 tests/qapi-schema/doc-good.txt          | 6 ++++++
 tests/qapi-schema/enum-if-invalid.err   | 2 +-
 tests/qapi-schema/qapi-schema-test.json | 2 +-
 tests/qapi-schema/qapi-schema-test.out  | 4 ++--
 9 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 018d2f6996..f8718e201b 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -207,6 +207,8 @@ def docgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> str:
         return ifcond
 
     oper, operands = next(iter(ifcond.items()))
+    if oper == 'not':
+        return '!' + docgen_ifcond(operands)
     oper = {'all': ' and ', 'any': ' or '}[oper]
     operands = [docgen_ifcond(o) for o in operands]
     return '(' + oper.join(operands) + ')'
@@ -219,6 +221,8 @@ def cgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> str:
         return ifcond
 
     oper, operands = next(iter(ifcond.items()))
+    if oper == 'not':
+        return '!' + cgen_ifcond(operands)
     oper = {'all': '&&', 'any': '||'}[oper]
     operands = [cgen_ifcond(o) for o in operands]
     return '(' + (') ' + oper + ' (').join(operands) + ')'
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index e10a803dc2..d2bd52c49f 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -296,15 +296,18 @@ def _check_if(cond: Union[str, object]) -> None:
             raise QAPISemError(
                 info,
                 "'if' condition dict of %s must have one key: "
-                "'all' or 'any'" % source)
+                "'all', 'any' or 'not" % source)
         check_keys(cond, info, "'if' condition", [],
-                   ["all", "any"])
+                   ["all", "any", "not"])
 
         oper, operands = next(iter(cond.items()))
         if not operands:
             raise QAPISemError(
                 info, "'if' condition [] of %s is useless" % source)
 
+        if oper == "not":
+            _check_if(operands)
+            return
         if oper in ("all", "any") and not isinstance(operands, list):
             raise QAPISemError(
                 info, "'%s' condition of %s must be a list" % (oper, source))
diff --git a/tests/qapi-schema/bad-if.err b/tests/qapi-schema/bad-if.err
index 3624e79b0c..454fbae387 100644
--- a/tests/qapi-schema/bad-if.err
+++ b/tests/qapi-schema/bad-if.err
@@ -1,3 +1,3 @@
 bad-if.json: In struct 'TestIfStruct':
 bad-if.json:2: 'if' condition has unknown key 'value'
-Valid keys are 'all', 'any'.
+Valid keys are 'all', 'any', 'not'.
diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json
index a67d4d9467..836fb1bdc4 100644
--- a/tests/qapi-schema/doc-good.json
+++ b/tests/qapi-schema/doc-good.json
@@ -125,7 +125,8 @@
 ##
 { 'alternate': 'Alternate',
   'features': [ 'alt-feat' ],
-  'data': { 'i': 'int', 'b': 'bool' } }
+  'data': { 'i': 'int', 'b': 'bool' },
+  'if': { 'not': 'IFNOT' } }
 
 ##
 # == Another subsection
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index c44c346ec8..a8871e8f99 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -51,6 +51,7 @@ alternate Alternate
     tag type
     case i: int
     case b: bool
+    if OrderedDict([('not', 'IFNOT')])
     feature alt-feat
 object q_obj_cmd-arg
     member arg1: int optional=False
diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt
index 251e9b746c..03c98c4182 100644
--- a/tests/qapi-schema/doc-good.txt
+++ b/tests/qapi-schema/doc-good.txt
@@ -171,6 +171,12 @@ Features
    a feature
 
 
+If
+~~
+
+"!IFNOT"
+
+
 Another subsection
 ==================
 
diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum-if-invalid.err
index b96d94c48a..3bb84075a9 100644
--- a/tests/qapi-schema/enum-if-invalid.err
+++ b/tests/qapi-schema/enum-if-invalid.err
@@ -1,3 +1,3 @@
 enum-if-invalid.json: In enum 'TestIfEnum':
 enum-if-invalid.json:2: 'if' condition has unknown key 'val'
-Valid keys are 'all', 'any'.
+Valid keys are 'all', 'any', 'not'.
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 252fd8cc86..a0f09b277e 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -244,7 +244,7 @@
   'if': { 'all': ['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)'] } }
 
 { 'command': 'test-if-alternate-cmd', 'data': { 'alt-cmd-arg': 'TestIfAlternate' },
-  'if': { 'all': ['defined(TEST_IF_ALT)'] } }
+  'if': { 'all': ['defined(TEST_IF_ALT)', {'not': 'defined(TEST_IF_NOT_ALT)'}] } }
 
 { 'command': 'test-if-cmd',
   'data': {
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index e5625f2542..df2c57de54 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -333,10 +333,10 @@ alternate TestIfAlternate
     if OrderedDict([('all', ['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)'])])
 object q_obj_test-if-alternate-cmd-arg
     member alt-cmd-arg: TestIfAlternate optional=False
-    if OrderedDict([('all', ['defined(TEST_IF_ALT)'])])
+    if OrderedDict([('all', ['defined(TEST_IF_ALT)', OrderedDict([('not', 'defined(TEST_IF_NOT_ALT)')])])])
 command test-if-alternate-cmd q_obj_test-if-alternate-cmd-arg -> None
     gen=True success_response=True boxed=False oob=False preconfig=False
-    if OrderedDict([('all', ['defined(TEST_IF_ALT)'])])
+    if OrderedDict([('all', ['defined(TEST_IF_ALT)', OrderedDict([('not', 'defined(TEST_IF_NOT_ALT)')])])])
 object q_obj_test-if-cmd-arg
     member foo: TestIfStruct optional=False
     member bar: TestIfEnum optional=False
-- 
2.29.0



  parent reply	other threads:[~2021-06-18 10:34 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 ` marcandre.lureau [this message]
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
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=20210618102507.3761128-11-marcandre.lureau@redhat.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).