[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 4/9] qapi: introduce IfPredicateList and IfAny
From: |
marcandre . lureau |
Subject: |
[PATCH v2 4/9] qapi: introduce IfPredicateList and IfAny |
Date: |
Thu, 5 Nov 2020 16:28:03 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Based on IfAll, introduce a base class IfPredicateList, and add IfAny
for 'any' conditions.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
scripts/qapi/common.py | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 01c4c0c878..8dc2824186 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -215,20 +215,32 @@ class IfOption(IfPredicate):
return self.option == other.option
-class IfAll(IfPredicate):
+class IfPredicateList(IfPredicate):
+ C_OP = ""
+
def __init__(self, pred_list: Sequence[IfPredicate]):
self.pred_list = pred_list
def cgen(self) -> str:
- return " && ".join([p.cgen() for p in self.pred_list])
+ op = " " + self.C_OP + " "
+ return "(%s)" % op.join([p.cgen() for p in self.pred_list])
def __bool__(self) -> bool:
return bool(self.pred_list)
def __repr__(self) -> str:
- return f"IfAll({self.pred_list})"
+ ty = type(self)
+ return f"{ty.__qualname__}({self.pred_list})"
def __eq__(self, other: object) -> bool:
- if not isinstance(other, IfAll):
+ if not isinstance(other, type(self)):
return False
return self.pred_list == other.pred_list
+
+
+class IfAll(IfPredicateList):
+ C_OP = "&&"
+
+
+class IfAny(IfPredicateList):
+ C_OP = "||"
--
2.29.0
- [PATCH v2 0/9] qapi: untie 'if' conditions from C preprocessor, marcandre . lureau, 2020/11/05
- [PATCH v2 1/9] qapi: replace List[str] by QAPISchemaIf, marcandre . lureau, 2020/11/05
- [PATCH v2 2/9] qapi: move gen_if/gen_endif to QAPIIfSchema, marcandre . lureau, 2020/11/05
- [PATCH v2 3/9] qapi: start building an 'if' predicate tree, marcandre . lureau, 2020/11/05
- [PATCH v2 4/9] qapi: introduce IfPredicateList and IfAny,
marcandre . lureau <=
- [PATCH v2 5/9] qapi: add IfNot, marcandre . lureau, 2020/11/05
- [PATCH v2 6/9] qapi: normalize 'if' condition to IfPredicate tree, marcandre . lureau, 2020/11/05
- [PATCH v2 7/9] qapi: convert 'if' C expressions to the new literal form, marcandre . lureau, 2020/11/05
- [PATCH v2 8/9] qapi: make 'if' condition strings simple identifiers, marcandre . lureau, 2020/11/05
- [PATCH v2 9/9] docs: update the documentation about schema configuration, marcandre . lureau, 2020/11/05