From 506e3fb211d22f62115ce83e9247266c5d87ea24 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 11 Jun 2018 17:49:49 +0200 Subject: Add a function for getting all items in an expression Handy e.g. when searching. --- kconfiglib.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'kconfiglib.py') 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 -- cgit v1.2.3