summaryrefslogtreecommitdiff
path: root/examples/find_symbol.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-06-11 17:49:49 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-06-11 18:30:51 +0200
commit506e3fb211d22f62115ce83e9247266c5d87ea24 (patch)
tree86b41a341b3da5d527c5a85583cc9d46daebe294 /examples/find_symbol.py
parent330017a99cd7619c9eb1fe5fccbb02f5d9e7f6c5 (diff)
Add a function for getting all items in an expression
Handy e.g. when searching.
Diffstat (limited to 'examples/find_symbol.py')
-rw-r--r--examples/find_symbol.py19
1 files changed, 6 insertions, 13 deletions
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):
"""