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. --- examples/find_symbol.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/find_symbol.py b/examples/find_symbol.py index 55e6345..adc4d73 100644 --- a/examples/find_symbol.py +++ b/examples/find_symbol.py @@ -59,7 +59,7 @@ # config OPROFILE # ... (tons more lines) -from kconfiglib import Kconfig, Symbol, Choice, MENU, COMMENT, NOT +from kconfiglib import Kconfig, Symbol, expr_items, Choice, MENU, COMMENT, NOT import sys def expr_contains_sym(expr, sym_name): @@ -70,18 +70,11 @@ def expr_contains_sym(expr, sym_name): Note that "foo" is represented as a constant symbol, like in the C implementation. """ - # Choice symbols have a Choice instance propagated to the conditions of - # their properties, so we need this test rather than - # isinstance(expr, Symbol) - if not isinstance(expr, tuple): - return expr.name == sym_name - - if expr[0] == NOT: - return expr_contains_sym(expr[1], sym_name) - - # AND, OR, or relation - return expr_contains_sym(expr[1], sym_name) or \ - expr_contains_sym(expr[2], sym_name) + for item in expr_items(expr): + if item.name == sym_name: + return True + + return False def sc_references_sym(sc, sym_name): """ -- cgit v1.2.3