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

Function expr_str

scripts/kconfig/kconfiglib.py:6172–6213  ·  view source on GitHub ↗

Returns the string representation of the expression 'expr', as in a Kconfig file. Passing subexpressions of expressions to this function works as expected. sc_expr_str_fn (default: standard_sc_expr_str): This function is called for every symbol/choice (hence "sc") appearing

(expr, sc_expr_str_fn=standard_sc_expr_str)

Source from the content-addressed store, hash-verified

6170
6171
6172def expr_str(expr, sc_expr_str_fn=standard_sc_expr_str):
6173 """
6174 Returns the string representation of the expression 'expr', as in a Kconfig
6175 file.
6176
6177 Passing subexpressions of expressions to this function works as expected.
6178
6179 sc_expr_str_fn (default: standard_sc_expr_str):
6180 This function is called for every symbol/choice (hence "sc") appearing in
6181 the expression, with the symbol/choice as the argument. It is expected to
6182 return a string to be used for the symbol/choice.
6183
6184 This can be used e.g. to turn symbols/choices into links when generating
6185 documentation, or for printing the value of each symbol/choice after it.
6186
6187 Note that quoted values are represented as constants symbols
6188 (Symbol.is_constant == True).
6189 """
6190 if expr.__class__ is not tuple:
6191 return sc_expr_str_fn(expr)
6192
6193 if expr[0] is AND:
6194 return "{} && {}".format(_parenthesize(expr[1], OR, sc_expr_str_fn),
6195 _parenthesize(expr[2], OR, sc_expr_str_fn))
6196
6197 if expr[0] is OR:
6198 # This turns A && B || C && D into "(A && B) || (C && D)", which is
6199 # redundant, but more readable
6200 return "{} || {}".format(_parenthesize(expr[1], AND, sc_expr_str_fn),
6201 _parenthesize(expr[2], AND, sc_expr_str_fn))
6202
6203 if expr[0] is NOT:
6204 if expr[1].__class__ is tuple:
6205 return "!({})".format(expr_str(expr[1], sc_expr_str_fn))
6206 return "!" + sc_expr_str_fn(expr[1]) # Symbol
6207
6208 # Relation
6209 #
6210 # Relation operands are always symbols (quoted strings are constant
6211 # symbols)
6212 return "{} {} {}".format(sc_expr_str_fn(expr[1]), REL_TO_STR[expr[0]],
6213 sc_expr_str_fn(expr[2]))
6214
6215
6216def expr_items(expr):

Callers 11

_expr_strFunction · 0.90
_expr_strFunction · 0.90
_check_sym_sanityMethod · 0.85
_check_choice_sanityMethod · 0.85
indent_add_condMethod · 0.85
_sym_choice_node_strMethod · 0.85
_parenthesizeFunction · 0.85
_found_dep_loopFunction · 0.85

Calls 1

_parenthesizeFunction · 0.85

Tested by

no test coverage detected