aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2021-08-04 12:31:04 +0400
committerMarkus Armbruster <armbru@redhat.com>2021-08-26 13:53:56 +0200
commit2b7d2145369f2ca55ded9045393bb860ee3f6745 (patch)
treebd4bb8b19ac3c6986202674717fefbef813c67a2 /scripts
parent8a156d89d15ec190ff519e7ecaaa0b85e1ff4a7b (diff)
downloadqemu-2b7d2145369f2ca55ded9045393bb860ee3f6745.zip
qemu-2b7d2145369f2ca55ded9045393bb860ee3f6745.tar.gz
qemu-2b7d2145369f2ca55ded9045393bb860ee3f6745.tar.bz2
qapi: add 'not' condition operation
For the sake of completeness, introduce the 'not' condition. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20210804083105.97531-10-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Long line broken in tests/qapi-schema/qapi-schema-test.json] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi/common.py4
-rw-r--r--scripts/qapi/expr.py7
2 files changed, 9 insertions, 2 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 63a2e50..3fb2fbe 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -207,6 +207,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) + ')'
@@ -220,6 +222,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) + ')'
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index f3ce10f..120b310 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -290,15 +290,18 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> 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 an array" % (oper, source))