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@xxxxxxxxxx> --- scripts/kconfig/expr.c | 22 ++++++++++++++++------ scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index 81ebf8108ca7..9d517b897378 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -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; } diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 4a9a23b1b7e1..edfe3046d050 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -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); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 61c442d84aef..d5898cd6aeb8 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -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; -- 2.42.0.869.gea05f2083d-goog