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>
This commit is contained in:
Marc-André Lureau 2021-08-04 12:31:04 +04:00 committed by Markus Armbruster
parent 8a156d89d1
commit 2b7d214536
10 changed files with 25 additions and 9 deletions

View file

@ -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))