@@ -876,25 +876,35 @@ int expr_contains_symbol(struct expr *dep, struct symbol *sym)
return 0;
}
-bool expr_depends_symbol(struct expr *dep, struct symbol *sym)
+static bool sym_depends_symbol(struct symbol *hay, struct symbol *needle, bool recurse) {
+ if (!hay)
+ return false;
+ if (hay == needle)
+ return true;
+ if (recurse)
+ return expr_depends_symbol(hay->dir_dep.expr, needle, recurse);
+ return false;
+}
+
+bool expr_depends_symbol(struct expr *dep, struct symbol *sym, bool recurse)
{
if (!dep)
return false;
switch (dep->type) {
case E_AND:
- return expr_depends_symbol(dep->left.expr, sym) ||
- expr_depends_symbol(dep->right.expr, sym);
+ return expr_depends_symbol(dep->left.expr, sym, recurse) ||
+ expr_depends_symbol(dep->right.expr, sym, recurse);
case E_SYMBOL:
- return dep->left.sym == sym;
+ return sym_depends_symbol(dep->left.sym, sym, recurse);
case E_EQUAL:
- if (dep->left.sym == sym) {
+ if (sym_depends_symbol(dep->left.sym, sym, recurse)) {
if (dep->right.sym == &symbol_yes || dep->right.sym == &symbol_mod)
return true;
}
break;
case E_UNEQUAL:
- if (dep->left.sym == sym) {
+ if (sym_depends_symbol(dep->left.sym, sym, recurse)) {
if (dep->right.sym == &symbol_no)
return true;
}
@@ -299,7 +299,7 @@ struct expr *expr_trans_bool(struct expr *e);
struct expr *expr_eliminate_dups(struct expr *e);
struct expr *expr_transform(struct expr *e);
int expr_contains_symbol(struct expr *dep, struct symbol *sym);
-bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
+bool expr_depends_symbol(struct expr *dep, struct symbol *sym, bool recurse);
struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
void expr_fprint(struct expr *e, FILE *out);
@@ -443,7 +443,7 @@ void menu_finalize(struct menu *parent)
if (!expr_contains_symbol(dep, sym))
/* No dependency, quit */
break;
- if (expr_depends_symbol(dep, sym))
+ if (expr_depends_symbol(dep, sym, false))
/* Absolute dependency, put in submenu */
goto next;
Adds optional recursion support to expr_depends_symbol. If recurse is set to true, it will recurse through other defined symbols' dependencies to determine if the expression hard-depends on the provided argument through an multi-step dependency. Signed-off-by: Matthew Maurer <mmaurer@google.com> --- scripts/kconfig/expr.c | 22 ++++++++++++++++------ scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-)