MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / expr_value

Function expr_value

scripts/kconfig/kconfiglib.py:6100–6154  ·  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

6098
6099
6100def expr_value(expr):
6101 """
6102 Evaluates the expression 'expr' to a tristate value. Returns 0 (n), 1 (m),
6103 or 2 (y).
6104
6105 'expr' must be an already-parsed expression from a Symbol, Choice, or
6106 MenuNode property. To evaluate an expression represented as a string, use
6107 Kconfig.eval_string().
6108
6109 Passing subexpressions of expressions to this function works as expected.
6110 """
6111 if expr.__class__ is not tuple:
6112 return expr.tri_value
6113
6114 if expr[0] is AND:
6115 v1 = expr_value(expr[1])
6116 # Short-circuit the n case as an optimization (~5% faster
6117 # allnoconfig.py and allyesconfig.py, as of writing)
6118 return 0 if not v1 else min(v1, expr_value(expr[2]))
6119
6120 if expr[0] is OR:
6121 v1 = expr_value(expr[1])
6122 # Short-circuit the y case as an optimization
6123 return 2 if v1 == 2 else max(v1, expr_value(expr[2]))
6124
6125 if expr[0] is NOT:
6126 return 2 - expr_value(expr[1])
6127
6128 # Relation
6129 #
6130 # Implements <, <=, >, >= comparisons as well. These were added to
6131 # kconfig in 31847b67 (kconfig: allow use of relations other than
6132 # (in)equality).
6133
6134 rel, v1, v2 = expr
6135
6136 # If both operands are strings...
6137 if v1.orig_type is STRING and v2.orig_type is STRING:
6138 # ...then compare them lexicographically
6139 comp = _strcmp(v1.str_value, v2.str_value)
6140 else:
6141 # Otherwise, try to compare them as numbers
6142 try:
6143 comp = _sym_to_num(v1) - _sym_to_num(v2)
6144 except ValueError:
6145 # Fall back on a lexicographic comparison if the operands don't
6146 # parse as numbers
6147 comp = _strcmp(v1.str_value, v2.str_value)
6148
6149 return 2*(comp == 0 if rel is EQUAL else
6150 comp != 0 if rel is UNEQUAL else
6151 comp < 0 if rel is LESS else
6152 comp <= 0 if rel is LESS_EQUAL else
6153 comp > 0 if rel is GREATER else
6154 comp >= 0)
6155
6156
6157def standard_sc_expr_str(sc):

Callers 15

_visibleFunction · 0.90
_changeableFunction · 0.90
_direct_dep_infoFunction · 0.90
_defaults_infoFunction · 0.90
_split_expr_infoFunction · 0.90
sisFunction · 0.90
_check_validFunction · 0.90
_range_infoFunction · 0.90
missing_depsFunction · 0.90
check_deprecatedFunction · 0.90
check_experimentalFunction · 0.90

Calls 2

_strcmpFunction · 0.85
_sym_to_numFunction · 0.85

Tested by

no test coverage detected