1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
14 struct symbol symbol_yes
= {
17 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
20 struct symbol symbol_mod
= {
23 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
26 struct symbol symbol_no
= {
29 .flags
= SYMBOL_CONST
|SYMBOL_VALID
,
32 static struct symbol symbol_empty
= {
35 .flags
= SYMBOL_VALID
,
38 struct symbol
*modules_sym
;
39 static tristate modules_val
;
40 static int sym_warnings
;
42 enum symbol_type
sym_get_type(struct symbol
*sym
)
44 enum symbol_type type
= sym
->type
;
46 if (type
== S_TRISTATE
) {
47 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
49 else if (modules_val
== no
)
55 const char *sym_type_name(enum symbol_type type
)
74 struct property
*sym_get_choice_prop(struct symbol
*sym
)
76 struct property
*prop
;
78 for_all_choices(sym
, prop
)
83 static struct property
*sym_get_default_prop(struct symbol
*sym
)
85 struct property
*prop
;
87 for_all_defaults(sym
, prop
) {
88 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
89 if (prop
->visible
.tri
!= no
)
95 struct property
*sym_get_range_prop(struct symbol
*sym
)
97 struct property
*prop
;
99 for_all_properties(sym
, prop
, P_RANGE
) {
100 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
101 if (prop
->visible
.tri
!= no
)
107 static long long sym_get_range_val(struct symbol
*sym
, int base
)
120 return strtoll(sym
->curr
.val
, NULL
, base
);
123 static void sym_validate_range(struct symbol
*sym
)
125 struct property
*prop
;
126 struct symbol
*range_sym
;
140 prop
= sym_get_range_prop(sym
);
143 val
= strtoll(sym
->curr
.val
, NULL
, base
);
144 range_sym
= prop
->expr
->left
.sym
;
145 val2
= sym_get_range_val(range_sym
, base
);
147 range_sym
= prop
->expr
->right
.sym
;
148 val2
= sym_get_range_val(range_sym
, base
);
152 sym
->curr
.val
= range_sym
->curr
.val
;
155 static void sym_set_changed(struct symbol
*sym
)
157 struct property
*prop
;
159 sym
->flags
|= SYMBOL_CHANGED
;
160 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
162 prop
->menu
->flags
|= MENU_CHANGED
;
166 static void sym_set_all_changed(void)
171 for_all_symbols(i
, sym
)
172 sym_set_changed(sym
);
175 static void sym_calc_visibility(struct symbol
*sym
)
177 struct property
*prop
;
178 struct symbol
*choice_sym
= NULL
;
181 /* any prompt visible? */
184 if (sym_is_choice_value(sym
))
185 choice_sym
= prop_get_symbol(sym_get_choice_prop(sym
));
187 for_all_prompts(sym
, prop
) {
188 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
190 * Tristate choice_values with visibility 'mod' are
191 * not visible if the corresponding choice's value is
194 if (choice_sym
&& sym
->type
== S_TRISTATE
&&
195 prop
->visible
.tri
== mod
&& choice_sym
->curr
.tri
== yes
)
196 prop
->visible
.tri
= no
;
198 tri
= EXPR_OR(tri
, prop
->visible
.tri
);
200 if (tri
== mod
&& (sym
->type
!= S_TRISTATE
|| modules_val
== no
))
202 if (sym
->visible
!= tri
) {
204 sym_set_changed(sym
);
206 if (sym_is_choice_value(sym
))
208 /* defaulting to "yes" if no explicit "depends on" are given */
210 if (sym
->dir_dep
.expr
)
211 tri
= expr_calc_value(sym
->dir_dep
.expr
);
212 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
214 if (sym
->dir_dep
.tri
!= tri
) {
215 sym
->dir_dep
.tri
= tri
;
216 sym_set_changed(sym
);
219 if (sym
->rev_dep
.expr
)
220 tri
= expr_calc_value(sym
->rev_dep
.expr
);
221 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
223 if (sym
->rev_dep
.tri
!= tri
) {
224 sym
->rev_dep
.tri
= tri
;
225 sym_set_changed(sym
);
228 if (sym
->implied
.expr
)
229 tri
= expr_calc_value(sym
->implied
.expr
);
230 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
232 if (sym
->implied
.tri
!= tri
) {
233 sym
->implied
.tri
= tri
;
234 sym_set_changed(sym
);
239 * Find the default symbol for a choice.
240 * First try the default values for the choice symbol
241 * Next locate the first visible choice value
242 * Return NULL if none was found
244 struct symbol
*sym_choice_default(struct symbol
*sym
)
246 struct symbol
*def_sym
;
247 struct property
*prop
;
250 /* any of the defaults visible? */
251 for_all_defaults(sym
, prop
) {
252 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
253 if (prop
->visible
.tri
== no
)
255 def_sym
= prop_get_symbol(prop
);
256 if (def_sym
->visible
!= no
)
260 /* just get the first visible value */
261 prop
= sym_get_choice_prop(sym
);
262 expr_list_for_each_sym(prop
->expr
, e
, def_sym
)
263 if (def_sym
->visible
!= no
)
266 /* failed to locate any defaults */
270 static struct symbol
*sym_calc_choice(struct symbol
*sym
)
272 struct symbol
*def_sym
;
273 struct property
*prop
;
277 /* first calculate all choice values' visibilities */
279 prop
= sym_get_choice_prop(sym
);
280 expr_list_for_each_sym(prop
->expr
, e
, def_sym
) {
281 sym_calc_visibility(def_sym
);
282 if (def_sym
->visible
!= no
)
283 flags
&= def_sym
->flags
;
286 sym
->flags
&= flags
| ~SYMBOL_DEF_USER
;
288 /* is the user choice visible? */
289 def_sym
= sym
->def
[S_DEF_USER
].val
;
290 if (def_sym
&& def_sym
->visible
!= no
)
293 def_sym
= sym_choice_default(sym
);
296 /* no choice? reset tristate value */
302 static void sym_warn_unmet_dep(struct symbol
*sym
)
304 struct gstr gs
= str_new();
307 "\nWARNING: unmet direct dependencies detected for %s\n",
310 " Depends on [%c]: ",
311 sym
->dir_dep
.tri
== mod
? 'm' : 'n');
312 expr_gstr_print(sym
->dir_dep
.expr
, &gs
);
313 str_printf(&gs
, "\n");
315 expr_gstr_print_revdep(sym
->rev_dep
.expr
, &gs
, yes
,
316 " Selected by [y]:\n");
317 expr_gstr_print_revdep(sym
->rev_dep
.expr
, &gs
, mod
,
318 " Selected by [m]:\n");
320 fputs(str_get(&gs
), stderr
);
324 void sym_calc_value(struct symbol
*sym
)
326 struct symbol_value newval
, oldval
;
327 struct property
*prop
;
334 if (sym
->flags
& SYMBOL_VALID
)
337 if (sym_is_choice_value(sym
) &&
338 sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
) {
339 sym
->flags
&= ~SYMBOL_NEED_SET_CHOICE_VALUES
;
340 prop
= sym_get_choice_prop(sym
);
341 sym_calc_value(prop_get_symbol(prop
));
344 werror
= getenv("KCONFIG_WERROR");
346 sym
->flags
|= SYMBOL_VALID
;
353 newval
= symbol_empty
.curr
;
357 newval
= symbol_no
.curr
;
360 sym
->curr
.val
= sym
->name
;
364 sym
->flags
&= ~SYMBOL_WRITE
;
366 sym_calc_visibility(sym
);
368 if (sym
->visible
!= no
)
369 sym
->flags
|= SYMBOL_WRITE
;
371 /* set default if recursively called */
374 switch (sym_get_type(sym
)) {
377 if (sym_is_choice_value(sym
) && sym
->visible
== yes
) {
378 prop
= sym_get_choice_prop(sym
);
379 newval
.tri
= (prop_get_symbol(prop
)->curr
.val
== sym
) ? yes
: no
;
381 if (sym
->visible
!= no
) {
382 /* if the symbol is visible use the user value
383 * if available, otherwise try the default value
385 if (sym_has_value(sym
)) {
386 newval
.tri
= EXPR_AND(sym
->def
[S_DEF_USER
].tri
,
391 if (sym
->rev_dep
.tri
!= no
)
392 sym
->flags
|= SYMBOL_WRITE
;
393 if (!sym_is_choice(sym
)) {
394 prop
= sym_get_default_prop(sym
);
396 newval
.tri
= EXPR_AND(expr_calc_value(prop
->expr
),
398 if (newval
.tri
!= no
)
399 sym
->flags
|= SYMBOL_WRITE
;
401 if (sym
->implied
.tri
!= no
) {
402 sym
->flags
|= SYMBOL_WRITE
;
403 newval
.tri
= EXPR_OR(newval
.tri
, sym
->implied
.tri
);
404 newval
.tri
= EXPR_AND(newval
.tri
,
409 if (sym
->dir_dep
.tri
< sym
->rev_dep
.tri
)
410 sym_warn_unmet_dep(sym
);
411 newval
.tri
= EXPR_OR(newval
.tri
, sym
->rev_dep
.tri
);
413 if (newval
.tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
419 if (sym
->visible
!= no
&& sym_has_value(sym
)) {
420 newval
.val
= sym
->def
[S_DEF_USER
].val
;
423 prop
= sym_get_default_prop(sym
);
425 struct symbol
*ds
= prop_get_symbol(prop
);
427 sym
->flags
|= SYMBOL_WRITE
;
429 newval
.val
= ds
->curr
.val
;
437 if (sym_warnings
&& werror
)
441 if (sym_is_choice(sym
) && newval
.tri
== yes
)
442 sym
->curr
.val
= sym_calc_choice(sym
);
443 sym_validate_range(sym
);
445 if (memcmp(&oldval
, &sym
->curr
, sizeof(oldval
))) {
446 sym_set_changed(sym
);
447 if (modules_sym
== sym
) {
448 sym_set_all_changed();
449 modules_val
= modules_sym
->curr
.tri
;
453 if (sym_is_choice(sym
)) {
454 struct symbol
*choice_sym
;
456 prop
= sym_get_choice_prop(sym
);
457 expr_list_for_each_sym(prop
->expr
, e
, choice_sym
) {
458 if ((sym
->flags
& SYMBOL_WRITE
) &&
459 choice_sym
->visible
!= no
)
460 choice_sym
->flags
|= SYMBOL_WRITE
;
461 if (sym
->flags
& SYMBOL_CHANGED
)
462 sym_set_changed(choice_sym
);
466 if (sym
->flags
& SYMBOL_NO_WRITE
)
467 sym
->flags
&= ~SYMBOL_WRITE
;
469 if (sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
)
470 set_all_choice_values(sym
);
473 void sym_clear_all_valid(void)
478 for_all_symbols(i
, sym
)
479 sym
->flags
&= ~SYMBOL_VALID
;
480 conf_set_changed(true);
481 sym_calc_value(modules_sym
);
484 bool sym_tristate_within_range(struct symbol
*sym
, tristate val
)
486 int type
= sym_get_type(sym
);
488 if (sym
->visible
== no
)
491 if (type
!= S_BOOLEAN
&& type
!= S_TRISTATE
)
494 if (type
== S_BOOLEAN
&& val
== mod
)
496 if (sym
->visible
<= sym
->rev_dep
.tri
)
498 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
500 return val
>= sym
->rev_dep
.tri
&& val
<= sym
->visible
;
503 bool sym_set_tristate_value(struct symbol
*sym
, tristate val
)
505 tristate oldval
= sym_get_tristate_value(sym
);
507 if (oldval
!= val
&& !sym_tristate_within_range(sym
, val
))
510 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
511 sym
->flags
|= SYMBOL_DEF_USER
;
512 sym_set_changed(sym
);
515 * setting a choice value also resets the new flag of the choice
516 * symbol and all other choice values.
518 if (sym_is_choice_value(sym
) && val
== yes
) {
519 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
520 struct property
*prop
;
523 cs
->def
[S_DEF_USER
].val
= sym
;
524 cs
->flags
|= SYMBOL_DEF_USER
;
525 prop
= sym_get_choice_prop(cs
);
526 for (e
= prop
->expr
; e
; e
= e
->left
.expr
) {
527 if (e
->right
.sym
->visible
!= no
)
528 e
->right
.sym
->flags
|= SYMBOL_DEF_USER
;
532 sym
->def
[S_DEF_USER
].tri
= val
;
534 sym_clear_all_valid();
539 tristate
sym_toggle_tristate_value(struct symbol
*sym
)
541 tristate oldval
, newval
;
543 oldval
= newval
= sym_get_tristate_value(sym
);
556 if (sym_set_tristate_value(sym
, newval
))
558 } while (oldval
!= newval
);
562 bool sym_string_valid(struct symbol
*sym
, const char *str
)
575 if (ch
== '0' && *str
!= 0)
577 while ((ch
= *str
++)) {
583 if (str
[0] == '0' && (str
[1] == 'x' || str
[1] == 'X'))
589 } while ((ch
= *str
++));
605 bool sym_string_within_range(struct symbol
*sym
, const char *str
)
607 struct property
*prop
;
612 return sym_string_valid(sym
, str
);
614 if (!sym_string_valid(sym
, str
))
616 prop
= sym_get_range_prop(sym
);
619 val
= strtoll(str
, NULL
, 10);
620 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 10) &&
621 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 10);
623 if (!sym_string_valid(sym
, str
))
625 prop
= sym_get_range_prop(sym
);
628 val
= strtoll(str
, NULL
, 16);
629 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 16) &&
630 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 16);
635 return sym_tristate_within_range(sym
, yes
);
637 return sym_tristate_within_range(sym
, mod
);
639 return sym_tristate_within_range(sym
, no
);
647 bool sym_set_string_value(struct symbol
*sym
, const char *newval
)
658 return sym_set_tristate_value(sym
, yes
);
660 return sym_set_tristate_value(sym
, mod
);
662 return sym_set_tristate_value(sym
, no
);
669 if (!sym_string_within_range(sym
, newval
))
672 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
673 sym
->flags
|= SYMBOL_DEF_USER
;
674 sym_set_changed(sym
);
677 oldval
= sym
->def
[S_DEF_USER
].val
;
678 size
= strlen(newval
) + 1;
679 if (sym
->type
== S_HEX
&& (newval
[0] != '0' || (newval
[1] != 'x' && newval
[1] != 'X'))) {
681 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
684 } else if (!oldval
|| strcmp(oldval
, newval
))
685 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
690 free((void *)oldval
);
691 sym_clear_all_valid();
697 * Find the default value associated to a symbol.
698 * For tristate symbol handle the modules=n case
699 * in which case "m" becomes "y".
700 * If the symbol does not have any default then fallback
701 * to the fixed default values.
703 const char *sym_get_string_default(struct symbol
*sym
)
705 struct property
*prop
;
710 sym_calc_visibility(sym
);
711 sym_calc_value(modules_sym
);
712 val
= symbol_no
.curr
.tri
;
713 str
= symbol_empty
.curr
.val
;
715 /* If symbol has a default value look it up */
716 prop
= sym_get_default_prop(sym
);
721 /* The visibility may limit the value from yes => mod */
722 val
= EXPR_AND(expr_calc_value(prop
->expr
), prop
->visible
.tri
);
726 * The following fails to handle the situation
727 * where a default value is further limited by
730 ds
= prop_get_symbol(prop
);
733 str
= (const char *)ds
->curr
.val
;
738 /* Handle select statements */
739 val
= EXPR_OR(val
, sym
->rev_dep
.tri
);
741 /* transpose mod to yes if modules are not enabled */
743 if (!sym_is_choice_value(sym
) && modules_sym
->curr
.tri
== no
)
746 /* transpose mod to yes if type is bool */
747 if (sym
->type
== S_BOOLEAN
&& val
== mod
)
750 /* adjust the default value if this symbol is implied by another */
751 if (val
< sym
->implied
.tri
)
752 val
= sym
->implied
.tri
;
759 case mod
: return "m";
760 case yes
: return "y";
773 const char *sym_get_string_value(struct symbol
*sym
)
780 val
= sym_get_tristate_value(sym
);
785 sym_calc_value(modules_sym
);
786 return (modules_sym
->curr
.tri
== no
) ? "n" : "m";
794 return (const char *)sym
->curr
.val
;
797 bool sym_is_changeable(struct symbol
*sym
)
799 return sym
->visible
> sym
->rev_dep
.tri
;
802 static unsigned strhash(const char *s
)
805 unsigned hash
= 2166136261U;
807 hash
= (hash
^ *s
) * 0x01000193;
811 struct symbol
*sym_lookup(const char *name
, int flags
)
813 struct symbol
*symbol
;
818 if (name
[0] && !name
[1]) {
820 case 'y': return &symbol_yes
;
821 case 'm': return &symbol_mod
;
822 case 'n': return &symbol_no
;
825 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
827 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
829 !strcmp(symbol
->name
, name
) &&
830 (flags
? symbol
->flags
& flags
831 : !(symbol
->flags
& (SYMBOL_CONST
|SYMBOL_CHOICE
))))
834 new_name
= xstrdup(name
);
840 symbol
= xmalloc(sizeof(*symbol
));
841 memset(symbol
, 0, sizeof(*symbol
));
842 symbol
->name
= new_name
;
843 symbol
->type
= S_UNKNOWN
;
844 symbol
->flags
= flags
;
846 symbol
->next
= symbol_hash
[hash
];
847 symbol_hash
[hash
] = symbol
;
852 struct symbol
*sym_find(const char *name
)
854 struct symbol
*symbol
= NULL
;
860 if (name
[0] && !name
[1]) {
862 case 'y': return &symbol_yes
;
863 case 'm': return &symbol_mod
;
864 case 'n': return &symbol_no
;
867 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
869 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
871 !strcmp(symbol
->name
, name
) &&
872 !(symbol
->flags
& SYMBOL_CONST
))
884 /* Compare matched symbols as thus:
885 * - first, symbols that match exactly
886 * - then, alphabetical sort
888 static int sym_rel_comp(const void *sym1
, const void *sym2
)
890 const struct sym_match
*s1
= sym1
;
891 const struct sym_match
*s2
= sym2
;
895 * - if matched length on symbol s1 is the length of that symbol,
896 * then this symbol should come first;
897 * - if matched length on symbol s2 is the length of that symbol,
898 * then this symbol should come first.
899 * Note: since the search can be a regexp, both symbols may match
900 * exactly; if this is the case, we can't decide which comes first,
901 * and we fallback to sorting alphabetically.
903 exact1
= (s1
->eo
- s1
->so
) == strlen(s1
->sym
->name
);
904 exact2
= (s2
->eo
- s2
->so
) == strlen(s2
->sym
->name
);
905 if (exact1
&& !exact2
)
907 if (!exact1
&& exact2
)
910 /* As a fallback, sort symbols alphabetically */
911 return strcmp(s1
->sym
->name
, s2
->sym
->name
);
914 struct symbol
**sym_re_search(const char *pattern
)
916 struct symbol
*sym
, **sym_arr
= NULL
;
917 struct sym_match
*sym_match_arr
= NULL
;
924 if (strlen(pattern
) == 0)
926 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_ICASE
))
929 for_all_symbols(i
, sym
) {
930 if (sym
->flags
& SYMBOL_CONST
|| !sym
->name
)
932 if (regexec(&re
, sym
->name
, 1, match
, 0))
937 tmp
= realloc(sym_match_arr
, size
* sizeof(struct sym_match
));
939 goto sym_re_search_free
;
943 /* As regexec returned 0, we know we have a match, so
944 * we can use match[0].rm_[se]o without further checks
946 sym_match_arr
[cnt
].so
= match
[0].rm_so
;
947 sym_match_arr
[cnt
].eo
= match
[0].rm_eo
;
948 sym_match_arr
[cnt
++].sym
= sym
;
951 qsort(sym_match_arr
, cnt
, sizeof(struct sym_match
), sym_rel_comp
);
952 sym_arr
= malloc((cnt
+1) * sizeof(struct symbol
*));
954 goto sym_re_search_free
;
955 for (i
= 0; i
< cnt
; i
++)
956 sym_arr
[i
] = sym_match_arr
[i
].sym
;
960 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
968 * When we check for recursive dependencies we use a stack to save
969 * current state so we can print out relevant info to user.
970 * The entries are located on the call stack so no need to free memory.
971 * Note insert() remove() must always match to properly clear the stack.
973 static struct dep_stack
{
974 struct dep_stack
*prev
, *next
;
976 struct property
*prop
;
980 static void dep_stack_insert(struct dep_stack
*stack
, struct symbol
*sym
)
982 memset(stack
, 0, sizeof(*stack
));
984 check_top
->next
= stack
;
985 stack
->prev
= check_top
;
990 static void dep_stack_remove(void)
992 check_top
= check_top
->prev
;
994 check_top
->next
= NULL
;
998 * Called when we have detected a recursive dependency.
999 * check_top point to the top of the stact so we use
1000 * the ->prev pointer to locate the bottom of the stack.
1002 static void sym_check_print_recursive(struct symbol
*last_sym
)
1004 struct dep_stack
*stack
;
1005 struct symbol
*sym
, *next_sym
;
1006 struct menu
*menu
= NULL
;
1007 struct property
*prop
;
1008 struct dep_stack cv_stack
;
1010 if (sym_is_choice_value(last_sym
)) {
1011 dep_stack_insert(&cv_stack
, last_sym
);
1012 last_sym
= prop_get_symbol(sym_get_choice_prop(last_sym
));
1015 for (stack
= check_top
; stack
!= NULL
; stack
= stack
->prev
)
1016 if (stack
->sym
== last_sym
)
1019 fprintf(stderr
, "unexpected recursive dependency error\n");
1023 for (; stack
; stack
= stack
->next
) {
1025 next_sym
= stack
->next
? stack
->next
->sym
: last_sym
;
1028 prop
= stack
->sym
->prop
;
1030 /* for choice values find the menu entry (used below) */
1031 if (sym_is_choice(sym
) || sym_is_choice_value(sym
)) {
1032 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1038 if (stack
->sym
== last_sym
)
1039 fprintf(stderr
, "%s:%d:error: recursive dependency detected!\n",
1040 prop
->file
->name
, prop
->lineno
);
1042 if (sym_is_choice(sym
)) {
1043 fprintf(stderr
, "%s:%d:\tchoice %s contains symbol %s\n",
1044 menu
->file
->name
, menu
->lineno
,
1045 sym
->name
? sym
->name
: "<choice>",
1046 next_sym
->name
? next_sym
->name
: "<choice>");
1047 } else if (sym_is_choice_value(sym
)) {
1048 fprintf(stderr
, "%s:%d:\tsymbol %s is part of choice %s\n",
1049 menu
->file
->name
, menu
->lineno
,
1050 sym
->name
? sym
->name
: "<choice>",
1051 next_sym
->name
? next_sym
->name
: "<choice>");
1052 } else if (stack
->expr
== &sym
->dir_dep
.expr
) {
1053 fprintf(stderr
, "%s:%d:\tsymbol %s depends on %s\n",
1054 prop
->file
->name
, prop
->lineno
,
1055 sym
->name
? sym
->name
: "<choice>",
1056 next_sym
->name
? next_sym
->name
: "<choice>");
1057 } else if (stack
->expr
== &sym
->rev_dep
.expr
) {
1058 fprintf(stderr
, "%s:%d:\tsymbol %s is selected by %s\n",
1059 prop
->file
->name
, prop
->lineno
,
1060 sym
->name
? sym
->name
: "<choice>",
1061 next_sym
->name
? next_sym
->name
: "<choice>");
1062 } else if (stack
->expr
== &sym
->implied
.expr
) {
1063 fprintf(stderr
, "%s:%d:\tsymbol %s is implied by %s\n",
1064 prop
->file
->name
, prop
->lineno
,
1065 sym
->name
? sym
->name
: "<choice>",
1066 next_sym
->name
? next_sym
->name
: "<choice>");
1067 } else if (stack
->expr
) {
1068 fprintf(stderr
, "%s:%d:\tsymbol %s %s value contains %s\n",
1069 prop
->file
->name
, prop
->lineno
,
1070 sym
->name
? sym
->name
: "<choice>",
1071 prop_get_type_name(prop
->type
),
1072 next_sym
->name
? next_sym
->name
: "<choice>");
1074 fprintf(stderr
, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1075 prop
->file
->name
, prop
->lineno
,
1076 sym
->name
? sym
->name
: "<choice>",
1077 prop_get_type_name(prop
->type
),
1078 next_sym
->name
? next_sym
->name
: "<choice>");
1083 "For a resolution refer to Documentation/kbuild/kconfig-language.rst\n"
1084 "subsection \"Kconfig recursive dependency limitations\"\n"
1087 if (check_top
== &cv_stack
)
1091 static struct symbol
*sym_check_expr_deps(struct expr
*e
)
1100 sym
= sym_check_expr_deps(e
->left
.expr
);
1103 return sym_check_expr_deps(e
->right
.expr
);
1105 return sym_check_expr_deps(e
->left
.expr
);
1112 sym
= sym_check_deps(e
->left
.sym
);
1115 return sym_check_deps(e
->right
.sym
);
1117 return sym_check_deps(e
->left
.sym
);
1121 fprintf(stderr
, "Oops! How to check %d?\n", e
->type
);
1125 /* return NULL when dependencies are OK */
1126 static struct symbol
*sym_check_sym_deps(struct symbol
*sym
)
1128 struct symbol
*sym2
;
1129 struct property
*prop
;
1130 struct dep_stack stack
;
1132 dep_stack_insert(&stack
, sym
);
1134 stack
.expr
= &sym
->dir_dep
.expr
;
1135 sym2
= sym_check_expr_deps(sym
->dir_dep
.expr
);
1139 stack
.expr
= &sym
->rev_dep
.expr
;
1140 sym2
= sym_check_expr_deps(sym
->rev_dep
.expr
);
1144 stack
.expr
= &sym
->implied
.expr
;
1145 sym2
= sym_check_expr_deps(sym
->implied
.expr
);
1151 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1152 if (prop
->type
== P_CHOICE
|| prop
->type
== P_SELECT
||
1153 prop
->type
== P_IMPLY
)
1156 sym2
= sym_check_expr_deps(prop
->visible
.expr
);
1159 if (prop
->type
!= P_DEFAULT
|| sym_is_choice(sym
))
1161 stack
.expr
= &prop
->expr
;
1162 sym2
= sym_check_expr_deps(prop
->expr
);
1174 static struct symbol
*sym_check_choice_deps(struct symbol
*choice
)
1176 struct symbol
*sym
, *sym2
;
1177 struct property
*prop
;
1179 struct dep_stack stack
;
1181 dep_stack_insert(&stack
, choice
);
1183 prop
= sym_get_choice_prop(choice
);
1184 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1185 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1187 choice
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1188 sym2
= sym_check_sym_deps(choice
);
1189 choice
->flags
&= ~SYMBOL_CHECK
;
1193 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1194 sym2
= sym_check_sym_deps(sym
);
1199 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1200 sym
->flags
&= ~SYMBOL_CHECK
;
1202 if (sym2
&& sym_is_choice_value(sym2
) &&
1203 prop_get_symbol(sym_get_choice_prop(sym2
)) == choice
)
1211 struct symbol
*sym_check_deps(struct symbol
*sym
)
1213 struct symbol
*sym2
;
1214 struct property
*prop
;
1216 if (sym
->flags
& SYMBOL_CHECK
) {
1217 sym_check_print_recursive(sym
);
1220 if (sym
->flags
& SYMBOL_CHECKED
)
1223 if (sym_is_choice_value(sym
)) {
1224 struct dep_stack stack
;
1226 /* for choice groups start the check with main choice symbol */
1227 dep_stack_insert(&stack
, sym
);
1228 prop
= sym_get_choice_prop(sym
);
1229 sym2
= sym_check_deps(prop_get_symbol(prop
));
1231 } else if (sym_is_choice(sym
)) {
1232 sym2
= sym_check_choice_deps(sym
);
1234 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1235 sym2
= sym_check_sym_deps(sym
);
1236 sym
->flags
&= ~SYMBOL_CHECK
;
1242 struct symbol
*prop_get_symbol(struct property
*prop
)
1244 if (prop
->expr
&& (prop
->expr
->type
== E_SYMBOL
||
1245 prop
->expr
->type
== E_LIST
))
1246 return prop
->expr
->left
.sym
;
1250 const char *prop_get_type_name(enum prop_type type
)