1 // SPDX-License-Identifier: GPL-2.0
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
;
41 enum symbol_type
sym_get_type(struct symbol
*sym
)
43 enum symbol_type type
= sym
->type
;
45 if (type
== S_TRISTATE
) {
46 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
48 else if (modules_val
== no
)
54 const char *sym_type_name(enum symbol_type type
)
73 struct property
*sym_get_choice_prop(struct symbol
*sym
)
75 struct property
*prop
;
77 for_all_choices(sym
, prop
)
82 static struct property
*sym_get_default_prop(struct symbol
*sym
)
84 struct property
*prop
;
86 for_all_defaults(sym
, prop
) {
87 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
88 if (prop
->visible
.tri
!= no
)
94 struct property
*sym_get_range_prop(struct symbol
*sym
)
96 struct property
*prop
;
98 for_all_properties(sym
, prop
, P_RANGE
) {
99 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
100 if (prop
->visible
.tri
!= no
)
106 static long long sym_get_range_val(struct symbol
*sym
, int base
)
119 return strtoll(sym
->curr
.val
, NULL
, base
);
122 static void sym_validate_range(struct symbol
*sym
)
124 struct property
*prop
;
125 struct symbol
*range_sym
;
139 prop
= sym_get_range_prop(sym
);
142 val
= strtoll(sym
->curr
.val
, NULL
, base
);
143 range_sym
= prop
->expr
->left
.sym
;
144 val2
= sym_get_range_val(range_sym
, base
);
146 range_sym
= prop
->expr
->right
.sym
;
147 val2
= sym_get_range_val(range_sym
, base
);
151 sym
->curr
.val
= range_sym
->curr
.val
;
154 static void sym_set_changed(struct symbol
*sym
)
156 struct property
*prop
;
158 sym
->flags
|= SYMBOL_CHANGED
;
159 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
161 prop
->menu
->flags
|= MENU_CHANGED
;
165 static void sym_set_all_changed(void)
170 for_all_symbols(i
, sym
)
171 sym_set_changed(sym
);
174 static void sym_calc_visibility(struct symbol
*sym
)
176 struct property
*prop
;
177 struct symbol
*choice_sym
= NULL
;
180 /* any prompt visible? */
183 if (sym_is_choice_value(sym
))
184 choice_sym
= prop_get_symbol(sym_get_choice_prop(sym
));
186 for_all_prompts(sym
, prop
) {
187 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
189 * Tristate choice_values with visibility 'mod' are
190 * not visible if the corresponding choice's value is
193 if (choice_sym
&& sym
->type
== S_TRISTATE
&&
194 prop
->visible
.tri
== mod
&& choice_sym
->curr
.tri
== yes
)
195 prop
->visible
.tri
= no
;
197 tri
= EXPR_OR(tri
, prop
->visible
.tri
);
199 if (tri
== mod
&& (sym
->type
!= S_TRISTATE
|| modules_val
== no
))
201 if (sym
->visible
!= tri
) {
203 sym_set_changed(sym
);
205 if (sym_is_choice_value(sym
))
207 /* defaulting to "yes" if no explicit "depends on" are given */
209 if (sym
->dir_dep
.expr
)
210 tri
= expr_calc_value(sym
->dir_dep
.expr
);
211 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
213 if (sym
->dir_dep
.tri
!= tri
) {
214 sym
->dir_dep
.tri
= tri
;
215 sym_set_changed(sym
);
218 if (sym
->rev_dep
.expr
)
219 tri
= expr_calc_value(sym
->rev_dep
.expr
);
220 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
222 if (sym
->rev_dep
.tri
!= tri
) {
223 sym
->rev_dep
.tri
= tri
;
224 sym_set_changed(sym
);
227 if (sym
->implied
.expr
)
228 tri
= expr_calc_value(sym
->implied
.expr
);
229 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
231 if (sym
->implied
.tri
!= tri
) {
232 sym
->implied
.tri
= tri
;
233 sym_set_changed(sym
);
238 * Find the default symbol for a choice.
239 * First try the default values for the choice symbol
240 * Next locate the first visible choice value
241 * Return NULL if none was found
243 struct symbol
*sym_choice_default(struct symbol
*sym
)
245 struct symbol
*def_sym
;
246 struct property
*prop
;
249 /* any of the defaults visible? */
250 for_all_defaults(sym
, prop
) {
251 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
252 if (prop
->visible
.tri
== no
)
254 def_sym
= prop_get_symbol(prop
);
255 if (def_sym
->visible
!= no
)
259 /* just get the first visible value */
260 prop
= sym_get_choice_prop(sym
);
261 expr_list_for_each_sym(prop
->expr
, e
, def_sym
)
262 if (def_sym
->visible
!= no
)
265 /* failed to locate any defaults */
269 static struct symbol
*sym_calc_choice(struct symbol
*sym
)
271 struct symbol
*def_sym
;
272 struct property
*prop
;
276 /* first calculate all choice values' visibilities */
278 prop
= sym_get_choice_prop(sym
);
279 expr_list_for_each_sym(prop
->expr
, e
, def_sym
) {
280 sym_calc_visibility(def_sym
);
281 if (def_sym
->visible
!= no
)
282 flags
&= def_sym
->flags
;
285 sym
->flags
&= flags
| ~SYMBOL_DEF_USER
;
287 /* is the user choice visible? */
288 def_sym
= sym
->def
[S_DEF_USER
].val
;
289 if (def_sym
&& def_sym
->visible
!= no
)
292 def_sym
= sym_choice_default(sym
);
295 /* no choice? reset tristate value */
301 static void sym_warn_unmet_dep(struct symbol
*sym
)
303 struct gstr gs
= str_new();
306 "\nWARNING: unmet direct dependencies detected for %s\n",
309 " Depends on [%c]: ",
310 sym
->dir_dep
.tri
== mod
? 'm' : 'n');
311 expr_gstr_print(sym
->dir_dep
.expr
, &gs
);
312 str_printf(&gs
, "\n");
314 expr_gstr_print_revdep(sym
->rev_dep
.expr
, &gs
, yes
,
315 " Selected by [y]:\n");
316 expr_gstr_print_revdep(sym
->rev_dep
.expr
, &gs
, mod
,
317 " Selected by [m]:\n");
319 fputs(str_get(&gs
), stderr
);
322 void sym_calc_value(struct symbol
*sym
)
324 struct symbol_value newval
, oldval
;
325 struct property
*prop
;
331 if (sym
->flags
& SYMBOL_VALID
)
334 if (sym_is_choice_value(sym
) &&
335 sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
) {
336 sym
->flags
&= ~SYMBOL_NEED_SET_CHOICE_VALUES
;
337 prop
= sym_get_choice_prop(sym
);
338 sym_calc_value(prop_get_symbol(prop
));
341 sym
->flags
|= SYMBOL_VALID
;
349 newval
= symbol_empty
.curr
;
353 newval
= symbol_no
.curr
;
356 sym
->curr
.val
= sym
->name
;
360 sym
->flags
&= ~SYMBOL_WRITE
;
362 sym_calc_visibility(sym
);
364 if (sym
->visible
!= no
)
365 sym
->flags
|= SYMBOL_WRITE
;
367 /* set default if recursively called */
370 switch (sym_get_type(sym
)) {
373 if (sym_is_choice_value(sym
) && sym
->visible
== yes
) {
374 prop
= sym_get_choice_prop(sym
);
375 newval
.tri
= (prop_get_symbol(prop
)->curr
.val
== sym
) ? yes
: no
;
377 if (sym
->visible
!= no
) {
378 /* if the symbol is visible use the user value
379 * if available, otherwise try the default value
381 if (sym_has_value(sym
)) {
382 newval
.tri
= EXPR_AND(sym
->def
[S_DEF_USER
].tri
,
387 if (sym
->rev_dep
.tri
!= no
)
388 sym
->flags
|= SYMBOL_WRITE
;
389 if (!sym_is_choice(sym
)) {
390 prop
= sym_get_default_prop(sym
);
392 newval
.tri
= EXPR_AND(expr_calc_value(prop
->expr
),
394 if (newval
.tri
!= no
)
395 sym
->flags
|= SYMBOL_WRITE
;
397 if (sym
->implied
.tri
!= no
) {
398 sym
->flags
|= SYMBOL_WRITE
;
399 newval
.tri
= EXPR_OR(newval
.tri
, sym
->implied
.tri
);
400 newval
.tri
= EXPR_AND(newval
.tri
,
405 if (sym
->dir_dep
.tri
< sym
->rev_dep
.tri
)
406 sym_warn_unmet_dep(sym
);
407 newval
.tri
= EXPR_OR(newval
.tri
, sym
->rev_dep
.tri
);
409 if (newval
.tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
415 if (sym
->visible
!= no
&& sym_has_value(sym
)) {
416 newval
.val
= sym
->def
[S_DEF_USER
].val
;
419 prop
= sym_get_default_prop(sym
);
421 struct symbol
*ds
= prop_get_symbol(prop
);
423 sym
->flags
|= SYMBOL_WRITE
;
425 newval
.val
= ds
->curr
.val
;
434 if (sym_is_choice(sym
) && newval
.tri
== yes
)
435 sym
->curr
.val
= sym_calc_choice(sym
);
436 sym_validate_range(sym
);
438 if (memcmp(&oldval
, &sym
->curr
, sizeof(oldval
))) {
439 sym_set_changed(sym
);
440 if (modules_sym
== sym
) {
441 sym_set_all_changed();
442 modules_val
= modules_sym
->curr
.tri
;
446 if (sym_is_choice(sym
)) {
447 struct symbol
*choice_sym
;
449 prop
= sym_get_choice_prop(sym
);
450 expr_list_for_each_sym(prop
->expr
, e
, choice_sym
) {
451 if ((sym
->flags
& SYMBOL_WRITE
) &&
452 choice_sym
->visible
!= no
)
453 choice_sym
->flags
|= SYMBOL_WRITE
;
454 if (sym
->flags
& SYMBOL_CHANGED
)
455 sym_set_changed(choice_sym
);
459 if (sym
->flags
& SYMBOL_NO_WRITE
)
460 sym
->flags
&= ~SYMBOL_WRITE
;
462 if (sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
)
463 set_all_choice_values(sym
);
466 void sym_clear_all_valid(void)
471 for_all_symbols(i
, sym
)
472 sym
->flags
&= ~SYMBOL_VALID
;
473 conf_set_changed(true);
474 sym_calc_value(modules_sym
);
477 bool sym_tristate_within_range(struct symbol
*sym
, tristate val
)
479 int type
= sym_get_type(sym
);
481 if (sym
->visible
== no
)
484 if (type
!= S_BOOLEAN
&& type
!= S_TRISTATE
)
487 if (type
== S_BOOLEAN
&& val
== mod
)
489 if (sym
->visible
<= sym
->rev_dep
.tri
)
491 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
493 return val
>= sym
->rev_dep
.tri
&& val
<= sym
->visible
;
496 bool sym_set_tristate_value(struct symbol
*sym
, tristate val
)
498 tristate oldval
= sym_get_tristate_value(sym
);
500 if (oldval
!= val
&& !sym_tristate_within_range(sym
, val
))
503 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
504 sym
->flags
|= SYMBOL_DEF_USER
;
505 sym_set_changed(sym
);
508 * setting a choice value also resets the new flag of the choice
509 * symbol and all other choice values.
511 if (sym_is_choice_value(sym
) && val
== yes
) {
512 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
513 struct property
*prop
;
516 cs
->def
[S_DEF_USER
].val
= sym
;
517 cs
->flags
|= SYMBOL_DEF_USER
;
518 prop
= sym_get_choice_prop(cs
);
519 for (e
= prop
->expr
; e
; e
= e
->left
.expr
) {
520 if (e
->right
.sym
->visible
!= no
)
521 e
->right
.sym
->flags
|= SYMBOL_DEF_USER
;
525 sym
->def
[S_DEF_USER
].tri
= val
;
527 sym_clear_all_valid();
532 tristate
sym_toggle_tristate_value(struct symbol
*sym
)
534 tristate oldval
, newval
;
536 oldval
= newval
= sym_get_tristate_value(sym
);
549 if (sym_set_tristate_value(sym
, newval
))
551 } while (oldval
!= newval
);
555 bool sym_string_valid(struct symbol
*sym
, const char *str
)
568 if (ch
== '0' && *str
!= 0)
570 while ((ch
= *str
++)) {
576 if (str
[0] == '0' && (str
[1] == 'x' || str
[1] == 'X'))
582 } while ((ch
= *str
++));
598 bool sym_string_within_range(struct symbol
*sym
, const char *str
)
600 struct property
*prop
;
605 return sym_string_valid(sym
, str
);
607 if (!sym_string_valid(sym
, str
))
609 prop
= sym_get_range_prop(sym
);
612 val
= strtoll(str
, NULL
, 10);
613 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 10) &&
614 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 10);
616 if (!sym_string_valid(sym
, str
))
618 prop
= sym_get_range_prop(sym
);
621 val
= strtoll(str
, NULL
, 16);
622 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 16) &&
623 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 16);
628 return sym_tristate_within_range(sym
, yes
);
630 return sym_tristate_within_range(sym
, mod
);
632 return sym_tristate_within_range(sym
, no
);
640 bool sym_set_string_value(struct symbol
*sym
, const char *newval
)
651 return sym_set_tristate_value(sym
, yes
);
653 return sym_set_tristate_value(sym
, mod
);
655 return sym_set_tristate_value(sym
, no
);
662 if (!sym_string_within_range(sym
, newval
))
665 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
666 sym
->flags
|= SYMBOL_DEF_USER
;
667 sym_set_changed(sym
);
670 oldval
= sym
->def
[S_DEF_USER
].val
;
671 size
= strlen(newval
) + 1;
672 if (sym
->type
== S_HEX
&& (newval
[0] != '0' || (newval
[1] != 'x' && newval
[1] != 'X'))) {
674 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
677 } else if (!oldval
|| strcmp(oldval
, newval
))
678 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
683 free((void *)oldval
);
684 sym_clear_all_valid();
690 * Find the default value associated to a symbol.
691 * For tristate symbol handle the modules=n case
692 * in which case "m" becomes "y".
693 * If the symbol does not have any default then fallback
694 * to the fixed default values.
696 const char *sym_get_string_default(struct symbol
*sym
)
698 struct property
*prop
;
703 sym_calc_visibility(sym
);
704 sym_calc_value(modules_sym
);
705 val
= symbol_no
.curr
.tri
;
706 str
= symbol_empty
.curr
.val
;
708 /* If symbol has a default value look it up */
709 prop
= sym_get_default_prop(sym
);
714 /* The visibility may limit the value from yes => mod */
715 val
= EXPR_AND(expr_calc_value(prop
->expr
), prop
->visible
.tri
);
719 * The following fails to handle the situation
720 * where a default value is further limited by
723 ds
= prop_get_symbol(prop
);
726 str
= (const char *)ds
->curr
.val
;
731 /* Handle select statements */
732 val
= EXPR_OR(val
, sym
->rev_dep
.tri
);
734 /* transpose mod to yes if modules are not enabled */
736 if (!sym_is_choice_value(sym
) && modules_sym
->curr
.tri
== no
)
739 /* transpose mod to yes if type is bool */
740 if (sym
->type
== S_BOOLEAN
&& val
== mod
)
743 /* adjust the default value if this symbol is implied by another */
744 if (val
< sym
->implied
.tri
)
745 val
= sym
->implied
.tri
;
752 case mod
: return "m";
753 case yes
: return "y";
766 const char *sym_get_string_value(struct symbol
*sym
)
773 val
= sym_get_tristate_value(sym
);
778 sym_calc_value(modules_sym
);
779 return (modules_sym
->curr
.tri
== no
) ? "n" : "m";
787 return (const char *)sym
->curr
.val
;
790 bool sym_is_changeable(struct symbol
*sym
)
792 return sym
->visible
> sym
->rev_dep
.tri
;
795 static unsigned strhash(const char *s
)
798 unsigned hash
= 2166136261U;
800 hash
= (hash
^ *s
) * 0x01000193;
804 struct symbol
*sym_lookup(const char *name
, int flags
)
806 struct symbol
*symbol
;
811 if (name
[0] && !name
[1]) {
813 case 'y': return &symbol_yes
;
814 case 'm': return &symbol_mod
;
815 case 'n': return &symbol_no
;
818 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
820 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
822 !strcmp(symbol
->name
, name
) &&
823 (flags
? symbol
->flags
& flags
824 : !(symbol
->flags
& (SYMBOL_CONST
|SYMBOL_CHOICE
))))
827 new_name
= xstrdup(name
);
833 symbol
= xmalloc(sizeof(*symbol
));
834 memset(symbol
, 0, sizeof(*symbol
));
835 symbol
->name
= new_name
;
836 symbol
->type
= S_UNKNOWN
;
837 symbol
->flags
= flags
;
839 symbol
->next
= symbol_hash
[hash
];
840 symbol_hash
[hash
] = symbol
;
845 struct symbol
*sym_find(const char *name
)
847 struct symbol
*symbol
= NULL
;
853 if (name
[0] && !name
[1]) {
855 case 'y': return &symbol_yes
;
856 case 'm': return &symbol_mod
;
857 case 'n': return &symbol_no
;
860 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
862 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
864 !strcmp(symbol
->name
, name
) &&
865 !(symbol
->flags
& SYMBOL_CONST
))
877 /* Compare matched symbols as thus:
878 * - first, symbols that match exactly
879 * - then, alphabetical sort
881 static int sym_rel_comp(const void *sym1
, const void *sym2
)
883 const struct sym_match
*s1
= sym1
;
884 const struct sym_match
*s2
= sym2
;
888 * - if matched length on symbol s1 is the length of that symbol,
889 * then this symbol should come first;
890 * - if matched length on symbol s2 is the length of that symbol,
891 * then this symbol should come first.
892 * Note: since the search can be a regexp, both symbols may match
893 * exactly; if this is the case, we can't decide which comes first,
894 * and we fallback to sorting alphabetically.
896 exact1
= (s1
->eo
- s1
->so
) == strlen(s1
->sym
->name
);
897 exact2
= (s2
->eo
- s2
->so
) == strlen(s2
->sym
->name
);
898 if (exact1
&& !exact2
)
900 if (!exact1
&& exact2
)
903 /* As a fallback, sort symbols alphabetically */
904 return strcmp(s1
->sym
->name
, s2
->sym
->name
);
907 struct symbol
**sym_re_search(const char *pattern
)
909 struct symbol
*sym
, **sym_arr
= NULL
;
910 struct sym_match
*sym_match_arr
= NULL
;
917 if (strlen(pattern
) == 0)
919 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_ICASE
))
922 for_all_symbols(i
, sym
) {
923 if (sym
->flags
& SYMBOL_CONST
|| !sym
->name
)
925 if (regexec(&re
, sym
->name
, 1, match
, 0))
930 tmp
= realloc(sym_match_arr
, size
* sizeof(struct sym_match
));
932 goto sym_re_search_free
;
936 /* As regexec returned 0, we know we have a match, so
937 * we can use match[0].rm_[se]o without further checks
939 sym_match_arr
[cnt
].so
= match
[0].rm_so
;
940 sym_match_arr
[cnt
].eo
= match
[0].rm_eo
;
941 sym_match_arr
[cnt
++].sym
= sym
;
944 qsort(sym_match_arr
, cnt
, sizeof(struct sym_match
), sym_rel_comp
);
945 sym_arr
= malloc((cnt
+1) * sizeof(struct symbol
*));
947 goto sym_re_search_free
;
948 for (i
= 0; i
< cnt
; i
++)
949 sym_arr
[i
] = sym_match_arr
[i
].sym
;
953 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
961 * When we check for recursive dependencies we use a stack to save
962 * current state so we can print out relevant info to user.
963 * The entries are located on the call stack so no need to free memory.
964 * Note insert() remove() must always match to properly clear the stack.
966 static struct dep_stack
{
967 struct dep_stack
*prev
, *next
;
969 struct property
*prop
;
973 static void dep_stack_insert(struct dep_stack
*stack
, struct symbol
*sym
)
975 memset(stack
, 0, sizeof(*stack
));
977 check_top
->next
= stack
;
978 stack
->prev
= check_top
;
983 static void dep_stack_remove(void)
985 check_top
= check_top
->prev
;
987 check_top
->next
= NULL
;
991 * Called when we have detected a recursive dependency.
992 * check_top point to the top of the stact so we use
993 * the ->prev pointer to locate the bottom of the stack.
995 static void sym_check_print_recursive(struct symbol
*last_sym
)
997 struct dep_stack
*stack
;
998 struct symbol
*sym
, *next_sym
;
999 struct menu
*menu
= NULL
;
1000 struct property
*prop
;
1001 struct dep_stack cv_stack
;
1003 if (sym_is_choice_value(last_sym
)) {
1004 dep_stack_insert(&cv_stack
, last_sym
);
1005 last_sym
= prop_get_symbol(sym_get_choice_prop(last_sym
));
1008 for (stack
= check_top
; stack
!= NULL
; stack
= stack
->prev
)
1009 if (stack
->sym
== last_sym
)
1012 fprintf(stderr
, "unexpected recursive dependency error\n");
1016 for (; stack
; stack
= stack
->next
) {
1018 next_sym
= stack
->next
? stack
->next
->sym
: last_sym
;
1021 prop
= stack
->sym
->prop
;
1023 /* for choice values find the menu entry (used below) */
1024 if (sym_is_choice(sym
) || sym_is_choice_value(sym
)) {
1025 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1031 if (stack
->sym
== last_sym
)
1032 fprintf(stderr
, "%s:%d:error: recursive dependency detected!\n",
1033 prop
->file
->name
, prop
->lineno
);
1035 if (sym_is_choice(sym
)) {
1036 fprintf(stderr
, "%s:%d:\tchoice %s contains symbol %s\n",
1037 menu
->file
->name
, menu
->lineno
,
1038 sym
->name
? sym
->name
: "<choice>",
1039 next_sym
->name
? next_sym
->name
: "<choice>");
1040 } else if (sym_is_choice_value(sym
)) {
1041 fprintf(stderr
, "%s:%d:\tsymbol %s is part of choice %s\n",
1042 menu
->file
->name
, menu
->lineno
,
1043 sym
->name
? sym
->name
: "<choice>",
1044 next_sym
->name
? next_sym
->name
: "<choice>");
1045 } else if (stack
->expr
== &sym
->dir_dep
.expr
) {
1046 fprintf(stderr
, "%s:%d:\tsymbol %s depends on %s\n",
1047 prop
->file
->name
, prop
->lineno
,
1048 sym
->name
? sym
->name
: "<choice>",
1049 next_sym
->name
? next_sym
->name
: "<choice>");
1050 } else if (stack
->expr
== &sym
->rev_dep
.expr
) {
1051 fprintf(stderr
, "%s:%d:\tsymbol %s is selected by %s\n",
1052 prop
->file
->name
, prop
->lineno
,
1053 sym
->name
? sym
->name
: "<choice>",
1054 next_sym
->name
? next_sym
->name
: "<choice>");
1055 } else if (stack
->expr
== &sym
->implied
.expr
) {
1056 fprintf(stderr
, "%s:%d:\tsymbol %s is implied by %s\n",
1057 prop
->file
->name
, prop
->lineno
,
1058 sym
->name
? sym
->name
: "<choice>",
1059 next_sym
->name
? next_sym
->name
: "<choice>");
1060 } else if (stack
->expr
) {
1061 fprintf(stderr
, "%s:%d:\tsymbol %s %s value contains %s\n",
1062 prop
->file
->name
, prop
->lineno
,
1063 sym
->name
? sym
->name
: "<choice>",
1064 prop_get_type_name(prop
->type
),
1065 next_sym
->name
? next_sym
->name
: "<choice>");
1067 fprintf(stderr
, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1068 prop
->file
->name
, prop
->lineno
,
1069 sym
->name
? sym
->name
: "<choice>",
1070 prop_get_type_name(prop
->type
),
1071 next_sym
->name
? next_sym
->name
: "<choice>");
1076 "For a resolution refer to Documentation/kbuild/kconfig-language.rst\n"
1077 "subsection \"Kconfig recursive dependency limitations\"\n"
1080 if (check_top
== &cv_stack
)
1084 static struct symbol
*sym_check_expr_deps(struct expr
*e
)
1093 sym
= sym_check_expr_deps(e
->left
.expr
);
1096 return sym_check_expr_deps(e
->right
.expr
);
1098 return sym_check_expr_deps(e
->left
.expr
);
1105 sym
= sym_check_deps(e
->left
.sym
);
1108 return sym_check_deps(e
->right
.sym
);
1110 return sym_check_deps(e
->left
.sym
);
1114 fprintf(stderr
, "Oops! How to check %d?\n", e
->type
);
1118 /* return NULL when dependencies are OK */
1119 static struct symbol
*sym_check_sym_deps(struct symbol
*sym
)
1121 struct symbol
*sym2
;
1122 struct property
*prop
;
1123 struct dep_stack stack
;
1125 dep_stack_insert(&stack
, sym
);
1127 stack
.expr
= &sym
->dir_dep
.expr
;
1128 sym2
= sym_check_expr_deps(sym
->dir_dep
.expr
);
1132 stack
.expr
= &sym
->rev_dep
.expr
;
1133 sym2
= sym_check_expr_deps(sym
->rev_dep
.expr
);
1137 stack
.expr
= &sym
->implied
.expr
;
1138 sym2
= sym_check_expr_deps(sym
->implied
.expr
);
1144 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1145 if (prop
->type
== P_CHOICE
|| prop
->type
== P_SELECT
||
1146 prop
->type
== P_IMPLY
)
1149 sym2
= sym_check_expr_deps(prop
->visible
.expr
);
1152 if (prop
->type
!= P_DEFAULT
|| sym_is_choice(sym
))
1154 stack
.expr
= &prop
->expr
;
1155 sym2
= sym_check_expr_deps(prop
->expr
);
1167 static struct symbol
*sym_check_choice_deps(struct symbol
*choice
)
1169 struct symbol
*sym
, *sym2
;
1170 struct property
*prop
;
1172 struct dep_stack stack
;
1174 dep_stack_insert(&stack
, choice
);
1176 prop
= sym_get_choice_prop(choice
);
1177 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1178 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1180 choice
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1181 sym2
= sym_check_sym_deps(choice
);
1182 choice
->flags
&= ~SYMBOL_CHECK
;
1186 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1187 sym2
= sym_check_sym_deps(sym
);
1192 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1193 sym
->flags
&= ~SYMBOL_CHECK
;
1195 if (sym2
&& sym_is_choice_value(sym2
) &&
1196 prop_get_symbol(sym_get_choice_prop(sym2
)) == choice
)
1204 struct symbol
*sym_check_deps(struct symbol
*sym
)
1206 struct symbol
*sym2
;
1207 struct property
*prop
;
1209 if (sym
->flags
& SYMBOL_CHECK
) {
1210 sym_check_print_recursive(sym
);
1213 if (sym
->flags
& SYMBOL_CHECKED
)
1216 if (sym_is_choice_value(sym
)) {
1217 struct dep_stack stack
;
1219 /* for choice groups start the check with main choice symbol */
1220 dep_stack_insert(&stack
, sym
);
1221 prop
= sym_get_choice_prop(sym
);
1222 sym2
= sym_check_deps(prop_get_symbol(prop
));
1224 } else if (sym_is_choice(sym
)) {
1225 sym2
= sym_check_choice_deps(sym
);
1227 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1228 sym2
= sym_check_sym_deps(sym
);
1229 sym
->flags
&= ~SYMBOL_CHECK
;
1235 struct symbol
*prop_get_symbol(struct property
*prop
)
1237 if (prop
->expr
&& (prop
->expr
->type
== E_SYMBOL
||
1238 prop
->expr
->type
== E_LIST
))
1239 return prop
->expr
->left
.sym
;
1243 const char *prop_get_type_name(enum prop_type type
)