summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-08-25 04:10:29 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-08-25 04:11:03 +0200
commit2e0f51734a30441869280b1107471cae6e087981 (patch)
tree3b32657519c1b12a4092897d08dc16c93cf0068b
parent1c2c4ae83e78d3450e313aba53628497643adfb8 (diff)
Clean up expr_str() a bit
- Test in the order AND, OR, NOT, like in other places. This matches the frequency too. - Use 'not isinstance(expr, tuple)', which is a bit faster than isinstance(expr, (Symbol, Choice)).
-rw-r--r--kconfiglib.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 3d46630..3a25c73 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -5028,14 +5028,9 @@ def expr_str(expr, sc_expr_str_fn=standard_sc_expr_str):
Note that quoted values are represented as constants symbols
(Symbol.is_constant == True).
"""
- if isinstance(expr, (Symbol, Choice)):
+ if not isinstance(expr, tuple):
return sc_expr_str_fn(expr)
- if expr[0] == NOT:
- if isinstance(expr[1], tuple):
- return "!({})".format(expr_str(expr[1], sc_expr_str_fn))
- return "!" + sc_expr_str_fn(expr[1]) # Symbol
-
if expr[0] == AND:
return "{} && {}".format(_parenthesize(expr[1], OR, sc_expr_str_fn),
_parenthesize(expr[2], OR, sc_expr_str_fn))
@@ -5046,6 +5041,11 @@ def expr_str(expr, sc_expr_str_fn=standard_sc_expr_str):
return "{} || {}".format(_parenthesize(expr[1], AND, sc_expr_str_fn),
_parenthesize(expr[2], AND, sc_expr_str_fn))
+ if expr[0] == NOT:
+ if isinstance(expr[1], tuple):
+ return "!({})".format(expr_str(expr[1], sc_expr_str_fn))
+ return "!" + sc_expr_str_fn(expr[1]) # Symbol
+
# Relation
#
# Relation operands are always symbols (quoted strings are constant