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

Function expr_str

buildroot-external/scripts/kconfiglib.py:6101–6142  ·  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

6099
6100
6101def expr_str(expr, sc_expr_str_fn=standard_sc_expr_str):
6102 """
6103 Returns the string representation of the expression 'expr', as in a Kconfig
6104 file.
6105
6106 Passing subexpressions of expressions to this function works as expected.
6107
6108 sc_expr_str_fn (default: standard_sc_expr_str):
6109 This function is called for every symbol/choice (hence "sc") appearing in
6110 the expression, with the symbol/choice as the argument. It is expected to
6111 return a string to be used for the symbol/choice.
6112
6113 This can be used e.g. to turn symbols/choices into links when generating
6114 documentation, or for printing the value of each symbol/choice after it.
6115
6116 Note that quoted values are represented as constants symbols
6117 (Symbol.is_constant == True).
6118 """
6119 if expr.__class__ is not tuple:
6120 return sc_expr_str_fn(expr)
6121
6122 if expr[0] is AND:
6123 return "{} && {}".format(_parenthesize(expr[1], OR, sc_expr_str_fn),
6124 _parenthesize(expr[2], OR, sc_expr_str_fn))
6125
6126 if expr[0] is OR:
6127 # This turns A && B || C && D into "(A && B) || (C && D)", which is
6128 # redundant, but more readable
6129 return "{} || {}".format(_parenthesize(expr[1], AND, sc_expr_str_fn),
6130 _parenthesize(expr[2], AND, sc_expr_str_fn))
6131
6132 if expr[0] is NOT:
6133 if expr[1].__class__ is tuple:
6134 return "!({})".format(expr_str(expr[1], sc_expr_str_fn))
6135 return "!" + sc_expr_str_fn(expr[1]) # Symbol
6136
6137 # Relation
6138 #
6139 # Relation operands are always symbols (quoted strings are constant
6140 # symbols)
6141 return "{} {} {}".format(sc_expr_str_fn(expr[1]), REL_TO_STR[expr[0]],
6142 sc_expr_str_fn(expr[2]))
6143
6144
6145def expr_items(expr):

Callers 8

_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