MCPcopy Index your code
hub / github.com/home-assistant/operating-system / expr_value

Function expr_value

buildroot-external/scripts/kconfiglib.py:6029–6083  ·  view source on GitHub ↗

Evaluates the expression 'expr' to a tristate value. Returns 0 (n), 1 (m), or 2 (y). 'expr' must be an already-parsed expression from a Symbol, Choice, or MenuNode property. To evaluate an expression represented as a string, use Kconfig.eval_string(). Passing subexpression

(expr)

Source from the content-addressed store, hash-verified

6027
6028
6029def expr_value(expr):
6030 """
6031 Evaluates the expression 'expr' to a tristate value. Returns 0 (n), 1 (m),
6032 or 2 (y).
6033
6034 'expr' must be an already-parsed expression from a Symbol, Choice, or
6035 MenuNode property. To evaluate an expression represented as a string, use
6036 Kconfig.eval_string().
6037
6038 Passing subexpressions of expressions to this function works as expected.
6039 """
6040 if expr.__class__ is not tuple:
6041 return expr.tri_value
6042
6043 if expr[0] is AND:
6044 v1 = expr_value(expr[1])
6045 # Short-circuit the n case as an optimization (~5% faster
6046 # allnoconfig.py and allyesconfig.py, as of writing)
6047 return 0 if not v1 else min(v1, expr_value(expr[2]))
6048
6049 if expr[0] is OR:
6050 v1 = expr_value(expr[1])
6051 # Short-circuit the y case as an optimization
6052 return 2 if v1 == 2 else max(v1, expr_value(expr[2]))
6053
6054 if expr[0] is NOT:
6055 return 2 - expr_value(expr[1])
6056
6057 # Relation
6058 #
6059 # Implements <, <=, >, >= comparisons as well. These were added to
6060 # kconfig in 31847b67 (kconfig: allow use of relations other than
6061 # (in)equality).
6062
6063 rel, v1, v2 = expr
6064
6065 # If both operands are strings...
6066 if v1.orig_type is STRING and v2.orig_type is STRING:
6067 # ...then compare them lexicographically
6068 comp = _strcmp(v1.str_value, v2.str_value)
6069 else:
6070 # Otherwise, try to compare them as numbers
6071 try:
6072 comp = _sym_to_num(v1) - _sym_to_num(v2)
6073 except ValueError:
6074 # Fall back on a lexicographic comparison if the operands don't
6075 # parse as numbers
6076 comp = _strcmp(v1.str_value, v2.str_value)
6077
6078 return 2*(comp == 0 if rel is EQUAL else
6079 comp != 0 if rel is UNEQUAL else
6080 comp < 0 if rel is LESS else
6081 comp <= 0 if rel is LESS_EQUAL else
6082 comp > 0 if rel is GREATER else
6083 comp >= 0)
6084
6085
6086def standard_sc_expr_str(sc):

Callers 13

defconfig_filenameMethod · 0.85
_config_contentsMethod · 0.85
_min_config_contentsMethod · 0.85
eval_stringMethod · 0.85
str_valueMethod · 0.85
tri_valueMethod · 0.85
__repr__Method · 0.85
_assignableMethod · 0.85
_str_defaultMethod · 0.85
__repr__Method · 0.85

Calls 2

_strcmpFunction · 0.85
_sym_to_numFunction · 0.85

Tested by

no test coverage detected