diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-06-11 17:49:49 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-06-11 18:30:51 +0200 |
| commit | 506e3fb211d22f62115ce83e9247266c5d87ea24 (patch) | |
| tree | 86b41a341b3da5d527c5a85583cc9d46daebe294 /kconfiglib.py | |
| parent | 330017a99cd7619c9eb1fe5fccbb02f5d9e7f6c5 (diff) | |
Add a function for getting all items in an expression
Handy e.g. when searching.
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index cee793e..82edcb6 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4422,6 +4422,30 @@ def expr_str(expr): _REL_TO_STR[expr[0]], expr_str(expr[2])) +def expr_items(expr): + """ + Returns a set() of all items (symbols and choices) that appear in the + expression 'expr'. + """ + + deps = set() + + def rec(subexpr): + if not isinstance(subexpr, tuple): + # Symbol or choice + deps.add(subexpr) + + elif subexpr[0] == NOT: + rec(subexpr[1]) + + else: + # AND, OR, or relation + rec(subexpr[1]) + rec(subexpr[2]) + + rec(expr) + return deps + def split_expr(expr, op): """ Returns a list containing the top-level AND or OR operands in the |
