[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/13] qapi: Avoid redundant parens in code generated for conditio
From: |
Markus Armbruster |
Subject: |
[PULL 08/13] qapi: Avoid redundant parens in code generated for conditionals |
Date: |
Fri, 3 Sep 2021 21:32:04 +0200 |
Commit 6cc2e4817f "qapi: introduce QAPISchemaIfCond.cgen()" caused a
minor regression: redundant parenthesis. Subsequent commits
eliminated of many of them, but not all. Get rid of the rest now.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210831123809.1107782-8-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
scripts/qapi/common.py | 10 ++++++----
tests/qapi-schema/doc-good.txt | 6 +++---
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index df92cff852..c7ccc7cec7 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -205,24 +205,26 @@ def gen_ifcond(ifcond: Optional[Union[str, Dict[str,
Any]]],
cond_fmt: str, not_fmt: str,
all_operator: str, any_operator: str) -> str:
- def do_gen(ifcond: Union[str, Dict[str, Any]]):
+ def do_gen(ifcond: Union[str, Dict[str, Any]], need_parens: bool):
if isinstance(ifcond, str):
return cond_fmt % ifcond
assert isinstance(ifcond, dict) and len(ifcond) == 1
if 'not' in ifcond:
- return not_fmt % do_gen(ifcond['not'])
+ return not_fmt % do_gen(ifcond['not'], True)
if 'all' in ifcond:
gen = gen_infix(all_operator, ifcond['all'])
else:
gen = gen_infix(any_operator, ifcond['any'])
+ if need_parens:
+ gen = '(' + gen + ')'
return gen
def gen_infix(operator: str, operands: Sequence[Any]) -> str:
- return '(' + operator.join([do_gen(o) for o in operands]) + ')'
+ return operator.join([do_gen(o, True) for o in operands])
if not ifcond:
return ''
- return do_gen(ifcond)
+ return do_gen(ifcond, False)
def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str:
diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt
index 85a370831f..75f51a6fc1 100644
--- a/tests/qapi-schema/doc-good.txt
+++ b/tests/qapi-schema/doc-good.txt
@@ -79,7 +79,7 @@ Members
If
~~
-"(IFALL1 and IFALL2)"
+"IFALL1 and IFALL2"
"Variant1" (Object)
@@ -120,8 +120,8 @@ Members
The members of "Base"
The members of "Variant1" when "base1" is ""one""
-The members of "Variant2" when "base1" is ""two"" (**If: **"(IFONE or
-IFTWO)")
+The members of "Variant2" when "base1" is ""two"" (**If: **"IFONE or
+IFTWO")
Features
~~~~~~~~
--
2.31.1
- [PULL 00/13] QAPI patches patches for 2021-09-03, Markus Armbruster, 2021/09/03
- [PULL 01/13] qapi: Set boolean value correctly in examples, Markus Armbruster, 2021/09/03
- [PULL 06/13] qapi: Fix C code generation for 'if', Markus Armbruster, 2021/09/03
- [PULL 10/13] qapi: Use re.fullmatch() where appropriate, Markus Armbruster, 2021/09/03
- [PULL 04/13] tests/qapi-schema: Correct two 'if' conditionals, Markus Armbruster, 2021/09/03
- [PULL 03/13] qapi: Simplify how QAPISchemaIfCond represents "no condition", Markus Armbruster, 2021/09/03
- [PULL 05/13] tests/qapi-schema: Demonstrate broken C code for 'if', Markus Armbruster, 2021/09/03
- [PULL 08/13] qapi: Avoid redundant parens in code generated for conditionals,
Markus Armbruster <=
- [PULL 12/13] qapi: Tweak error messages for missing / conflicting meta-type, Markus Armbruster, 2021/09/03
- [PULL 11/13] tests/qapi-schema: Hide OrderedDict in test output, Markus Armbruster, 2021/09/03
- [PULL 02/13] qapi: Simplify QAPISchemaIfCond's interface for generating C, Markus Armbruster, 2021/09/03
- [PULL 13/13] qapi: Tweak error messages for unknown / conflicting 'if' keys, Markus Armbruster, 2021/09/03
- [PULL 07/13] qapi: Factor common recursion out of cgen_ifcond(), docgen_ifcond(), Markus Armbruster, 2021/09/03
- [PULL 09/13] qapi: Use "not COND" instead of "!COND" for generated documentation, Markus Armbruster, 2021/09/03
- Re: [PULL 00/13] QAPI patches patches for 2021-09-03, Peter Maydell, 2021/09/05