summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-10-06 05:16:12 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-10-06 05:39:38 +0200
commite6b6b5fe8e8097615ff9423a1d00996f279cb95e (patch)
treeeb0e857bb662f9ab87c16cc6a3c43e1d70266892
parentd83b9fd2061cbc59d6d112078104891493b9c0f0 (diff)
Clean up naming in expr_value()
Reuse the v1/v2 naming for the operands for the relation case, and call the relation variable 'rel' instead of 'op'. Piggy-back removal of the 'res' variable. Just as readable without it. Indirectly strips some locals.
-rw-r--r--kconfiglib.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 1239292..45630ff 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -5162,29 +5162,27 @@ def expr_value(expr):
# kconfig in 31847b67 (kconfig: allow use of relations other than
# (in)equality).
- oper, op1, op2 = expr
+ rel, v1, v2 = expr
# If both operands are strings...
- if op1.orig_type is STRING and op2.orig_type is STRING:
+ if v1.orig_type is STRING and v2.orig_type is STRING:
# ...then compare them lexicographically
- comp = _strcmp(op1.str_value, op2.str_value)
+ comp = _strcmp(v1.str_value, v2.str_value)
else:
# Otherwise, try to compare them as numbers
try:
- comp = _sym_to_num(op1) - _sym_to_num(op2)
+ comp = _sym_to_num(v1) - _sym_to_num(v2)
except ValueError:
# Fall back on a lexicographic comparison if the operands don't
# parse as numbers
- comp = _strcmp(op1.str_value, op2.str_value)
-
- if oper is EQUAL: res = comp == 0
- elif oper is UNEQUAL: res = comp != 0
- elif oper is LESS: res = comp < 0
- elif oper is LESS_EQUAL: res = comp <= 0
- elif oper is GREATER: res = comp > 0
- elif oper is GREATER_EQUAL: res = comp >= 0
-
- return 2*res
+ comp = _strcmp(v1.str_value, v2.str_value)
+
+ if rel is EQUAL: return 2*(comp == 0)
+ elif rel is UNEQUAL: return 2*(comp != 0)
+ elif rel is LESS: return 2*(comp < 0)
+ elif rel is LESS_EQUAL: return 2*(comp <= 0)
+ elif rel is GREATER: return 2*(comp > 0)
+ elif rel is GREATER_EQUAL: return 2*(comp >= 0)
_internal_error("Internal error while evaluating expression: "
"unknown operation {}.".format(expr[0]))