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 int recursive_is_error
;
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
;
140 prop
= sym_get_range_prop(sym
);
143 val
= strtoll(sym
->curr
.val
, NULL
, base
);
144 val2
= sym_get_range_val(prop
->expr
->left
.sym
, base
);
146 val2
= sym_get_range_val(prop
->expr
->right
.sym
, base
);
150 if (sym
->type
== S_INT
)
151 sprintf(str
, "%lld", val2
);
153 sprintf(str
, "0x%llx", val2
);
154 sym
->curr
.val
= xstrdup(str
);
157 static void sym_set_changed(struct symbol
*sym
)
159 struct property
*prop
;
161 sym
->flags
|= SYMBOL_CHANGED
;
162 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
164 prop
->menu
->flags
|= MENU_CHANGED
;
168 static void sym_set_all_changed(void)
173 for_all_symbols(i
, sym
)
174 sym_set_changed(sym
);
177 static void sym_calc_visibility(struct symbol
*sym
)
179 struct property
*prop
;
180 struct symbol
*choice_sym
= NULL
;
183 /* any prompt visible? */
186 if (sym_is_choice_value(sym
))
187 choice_sym
= prop_get_symbol(sym_get_choice_prop(sym
));
189 for_all_prompts(sym
, prop
) {
190 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
192 * Tristate choice_values with visibility 'mod' are
193 * not visible if the corresponding choice's value is
196 if (choice_sym
&& sym
->type
== S_TRISTATE
&&
197 prop
->visible
.tri
== mod
&& choice_sym
->curr
.tri
== yes
)
198 prop
->visible
.tri
= no
;
200 tri
= EXPR_OR(tri
, prop
->visible
.tri
);
202 if (tri
== mod
&& (sym
->type
!= S_TRISTATE
|| modules_val
== no
))
204 if (sym
->visible
!= tri
) {
206 sym_set_changed(sym
);
208 if (sym_is_choice_value(sym
))
210 /* defaulting to "yes" if no explicit "depends on" are given */
212 if (sym
->dir_dep
.expr
)
213 tri
= expr_calc_value(sym
->dir_dep
.expr
);
214 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
216 if (sym
->dir_dep
.tri
!= tri
) {
217 sym
->dir_dep
.tri
= tri
;
218 sym_set_changed(sym
);
221 if (sym
->rev_dep
.expr
)
222 tri
= expr_calc_value(sym
->rev_dep
.expr
);
223 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
225 if (sym
->rev_dep
.tri
!= tri
) {
226 sym
->rev_dep
.tri
= tri
;
227 sym_set_changed(sym
);
230 if (sym
->implied
.expr
)
231 tri
= expr_calc_value(sym
->implied
.expr
);
232 if (tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
234 if (sym
->implied
.tri
!= tri
) {
235 sym
->implied
.tri
= tri
;
236 sym_set_changed(sym
);
241 * Find the default symbol for a choice.
242 * First try the default values for the choice symbol
243 * Next locate the first visible choice value
244 * Return NULL if none was found
246 struct symbol
*sym_choice_default(struct symbol
*sym
)
248 struct symbol
*def_sym
;
249 struct property
*prop
;
252 /* any of the defaults visible? */
253 for_all_defaults(sym
, prop
) {
254 prop
->visible
.tri
= expr_calc_value(prop
->visible
.expr
);
255 if (prop
->visible
.tri
== no
)
257 def_sym
= prop_get_symbol(prop
);
258 if (def_sym
->visible
!= no
)
262 /* just get the first visible value */
263 prop
= sym_get_choice_prop(sym
);
264 expr_list_for_each_sym(prop
->expr
, e
, def_sym
)
265 if (def_sym
->visible
!= no
)
268 /* failed to locate any defaults */
272 static struct symbol
*sym_calc_choice(struct symbol
*sym
)
274 struct symbol
*def_sym
;
275 struct property
*prop
;
279 /* first calculate all choice values' visibilities */
281 prop
= sym_get_choice_prop(sym
);
282 expr_list_for_each_sym(prop
->expr
, e
, def_sym
) {
283 sym_calc_visibility(def_sym
);
284 if (def_sym
->visible
!= no
)
285 flags
&= def_sym
->flags
;
288 sym
->flags
&= flags
| ~SYMBOL_DEF_USER
;
290 /* is the user choice visible? */
291 def_sym
= sym
->def
[S_DEF_USER
].val
;
292 if (def_sym
&& def_sym
->visible
!= no
)
295 def_sym
= sym_choice_default(sym
);
298 /* no choice? reset tristate value */
304 void sym_calc_value(struct symbol
*sym
)
306 struct symbol_value newval
, oldval
;
307 struct property
*prop
;
313 if (sym
->flags
& SYMBOL_VALID
)
316 if (sym_is_choice_value(sym
) &&
317 sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
) {
318 sym
->flags
&= ~SYMBOL_NEED_SET_CHOICE_VALUES
;
319 prop
= sym_get_choice_prop(sym
);
320 sym_calc_value(prop_get_symbol(prop
));
323 sym
->flags
|= SYMBOL_VALID
;
331 newval
= symbol_empty
.curr
;
335 newval
= symbol_no
.curr
;
338 sym
->curr
.val
= sym
->name
;
342 sym
->flags
&= ~SYMBOL_WRITE
;
344 sym_calc_visibility(sym
);
346 if (sym
->visible
!= no
)
347 sym
->flags
|= SYMBOL_WRITE
;
349 /* set default if recursively called */
352 switch (sym_get_type(sym
)) {
355 if (sym_is_choice_value(sym
) && sym
->visible
== yes
) {
356 prop
= sym_get_choice_prop(sym
);
357 newval
.tri
= (prop_get_symbol(prop
)->curr
.val
== sym
) ? yes
: no
;
359 if (sym
->visible
!= no
) {
360 /* if the symbol is visible use the user value
361 * if available, otherwise try the default value
363 if (sym_has_value(sym
)) {
364 newval
.tri
= EXPR_AND(sym
->def
[S_DEF_USER
].tri
,
369 if (sym
->rev_dep
.tri
!= no
)
370 sym
->flags
|= SYMBOL_WRITE
;
371 if (!sym_is_choice(sym
)) {
372 prop
= sym_get_default_prop(sym
);
374 sym
->flags
|= SYMBOL_WRITE
;
375 newval
.tri
= EXPR_AND(expr_calc_value(prop
->expr
),
378 if (sym
->implied
.tri
!= no
) {
379 sym
->flags
|= SYMBOL_WRITE
;
380 newval
.tri
= EXPR_OR(newval
.tri
, sym
->implied
.tri
);
381 newval
.tri
= EXPR_AND(newval
.tri
,
386 if (sym
->dir_dep
.tri
== no
&& sym
->rev_dep
.tri
!= no
)
389 newval
.tri
= EXPR_OR(newval
.tri
, sym
->rev_dep
.tri
);
391 if (newval
.tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
397 if (sym
->visible
!= no
&& sym_has_value(sym
)) {
398 newval
.val
= sym
->def
[S_DEF_USER
].val
;
401 prop
= sym_get_default_prop(sym
);
403 struct symbol
*ds
= prop_get_symbol(prop
);
405 sym
->flags
|= SYMBOL_WRITE
;
407 newval
.val
= ds
->curr
.val
;
416 if (sym_is_choice(sym
) && newval
.tri
== yes
)
417 sym
->curr
.val
= sym_calc_choice(sym
);
418 sym_validate_range(sym
);
420 if (memcmp(&oldval
, &sym
->curr
, sizeof(oldval
))) {
421 sym_set_changed(sym
);
422 if (modules_sym
== sym
) {
423 sym_set_all_changed();
424 modules_val
= modules_sym
->curr
.tri
;
428 if (sym_is_choice(sym
)) {
429 struct symbol
*choice_sym
;
431 prop
= sym_get_choice_prop(sym
);
432 expr_list_for_each_sym(prop
->expr
, e
, choice_sym
) {
433 if ((sym
->flags
& SYMBOL_WRITE
) &&
434 choice_sym
->visible
!= no
)
435 choice_sym
->flags
|= SYMBOL_WRITE
;
436 if (sym
->flags
& SYMBOL_CHANGED
)
437 sym_set_changed(choice_sym
);
441 if (sym
->flags
& SYMBOL_NO_WRITE
)
442 sym
->flags
&= ~SYMBOL_WRITE
;
444 if (sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
)
445 set_all_choice_values(sym
);
448 void sym_clear_all_valid(void)
453 for_all_symbols(i
, sym
)
454 sym
->flags
&= ~SYMBOL_VALID
;
455 conf_set_changed(true);
456 sym_calc_value(modules_sym
);
459 bool sym_tristate_within_range(struct symbol
*sym
, tristate val
)
461 int type
= sym_get_type(sym
);
463 if (sym
->visible
== no
)
466 if (type
!= S_BOOLEAN
&& type
!= S_TRISTATE
)
469 if (type
== S_BOOLEAN
&& val
== mod
)
471 if (sym
->visible
<= sym
->rev_dep
.tri
)
473 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
475 return val
>= sym
->rev_dep
.tri
&& val
<= sym
->visible
;
478 bool sym_set_tristate_value(struct symbol
*sym
, tristate val
)
480 tristate oldval
= sym_get_tristate_value(sym
);
482 if (oldval
!= val
&& !sym_tristate_within_range(sym
, val
))
485 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
486 sym
->flags
|= SYMBOL_DEF_USER
;
487 sym_set_changed(sym
);
490 * setting a choice value also resets the new flag of the choice
491 * symbol and all other choice values.
493 if (sym_is_choice_value(sym
) && val
== yes
) {
494 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
495 struct property
*prop
;
498 cs
->def
[S_DEF_USER
].val
= sym
;
499 cs
->flags
|= SYMBOL_DEF_USER
;
500 prop
= sym_get_choice_prop(cs
);
501 for (e
= prop
->expr
; e
; e
= e
->left
.expr
) {
502 if (e
->right
.sym
->visible
!= no
)
503 e
->right
.sym
->flags
|= SYMBOL_DEF_USER
;
507 sym
->def
[S_DEF_USER
].tri
= val
;
509 sym_clear_all_valid();
514 tristate
sym_toggle_tristate_value(struct symbol
*sym
)
516 tristate oldval
, newval
;
518 oldval
= newval
= sym_get_tristate_value(sym
);
531 if (sym_set_tristate_value(sym
, newval
))
533 } while (oldval
!= newval
);
537 bool sym_string_valid(struct symbol
*sym
, const char *str
)
550 if (ch
== '0' && *str
!= 0)
552 while ((ch
= *str
++)) {
558 if (str
[0] == '0' && (str
[1] == 'x' || str
[1] == 'X'))
564 } while ((ch
= *str
++));
580 bool sym_string_within_range(struct symbol
*sym
, const char *str
)
582 struct property
*prop
;
587 return sym_string_valid(sym
, str
);
589 if (!sym_string_valid(sym
, str
))
591 prop
= sym_get_range_prop(sym
);
594 val
= strtoll(str
, NULL
, 10);
595 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 10) &&
596 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 10);
598 if (!sym_string_valid(sym
, str
))
600 prop
= sym_get_range_prop(sym
);
603 val
= strtoll(str
, NULL
, 16);
604 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 16) &&
605 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 16);
610 return sym_tristate_within_range(sym
, yes
);
612 return sym_tristate_within_range(sym
, mod
);
614 return sym_tristate_within_range(sym
, no
);
622 bool sym_set_string_value(struct symbol
*sym
, const char *newval
)
633 return sym_set_tristate_value(sym
, yes
);
635 return sym_set_tristate_value(sym
, mod
);
637 return sym_set_tristate_value(sym
, no
);
644 if (!sym_string_within_range(sym
, newval
))
647 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
648 sym
->flags
|= SYMBOL_DEF_USER
;
649 sym_set_changed(sym
);
652 oldval
= sym
->def
[S_DEF_USER
].val
;
653 size
= strlen(newval
) + 1;
654 if (sym
->type
== S_HEX
&& (newval
[0] != '0' || (newval
[1] != 'x' && newval
[1] != 'X'))) {
656 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
659 } else if (!oldval
|| strcmp(oldval
, newval
))
660 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
665 free((void *)oldval
);
666 sym_clear_all_valid();
672 * Find the default value associated to a symbol.
673 * For tristate symbol handle the modules=n case
674 * in which case "m" becomes "y".
675 * If the symbol does not have any default then fallback
676 * to the fixed default values.
678 const char *sym_get_string_default(struct symbol
*sym
)
680 struct property
*prop
;
685 sym_calc_visibility(sym
);
686 sym_calc_value(modules_sym
);
687 val
= symbol_no
.curr
.tri
;
688 str
= symbol_empty
.curr
.val
;
690 /* If symbol has a default value look it up */
691 prop
= sym_get_default_prop(sym
);
696 /* The visibility may limit the value from yes => mod */
697 val
= EXPR_AND(expr_calc_value(prop
->expr
), prop
->visible
.tri
);
701 * The following fails to handle the situation
702 * where a default value is further limited by
705 ds
= prop_get_symbol(prop
);
708 str
= (const char *)ds
->curr
.val
;
713 /* Handle select statements */
714 val
= EXPR_OR(val
, sym
->rev_dep
.tri
);
716 /* transpose mod to yes if modules are not enabled */
718 if (!sym_is_choice_value(sym
) && modules_sym
->curr
.tri
== no
)
721 /* transpose mod to yes if type is bool */
722 if (sym
->type
== S_BOOLEAN
&& val
== mod
)
725 /* adjust the default value if this symbol is implied by another */
726 if (val
< sym
->implied
.tri
)
727 val
= sym
->implied
.tri
;
734 case mod
: return "m";
735 case yes
: return "y";
748 const char *sym_get_string_value(struct symbol
*sym
)
755 val
= sym_get_tristate_value(sym
);
760 sym_calc_value(modules_sym
);
761 return (modules_sym
->curr
.tri
== no
) ? "n" : "m";
769 return (const char *)sym
->curr
.val
;
772 bool sym_is_changeable(struct symbol
*sym
)
774 return sym
->visible
> sym
->rev_dep
.tri
;
777 static unsigned strhash(const char *s
)
780 unsigned hash
= 2166136261U;
782 hash
= (hash
^ *s
) * 0x01000193;
786 struct symbol
*sym_lookup(const char *name
, int flags
)
788 struct symbol
*symbol
;
793 if (name
[0] && !name
[1]) {
795 case 'y': return &symbol_yes
;
796 case 'm': return &symbol_mod
;
797 case 'n': return &symbol_no
;
800 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
802 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
804 !strcmp(symbol
->name
, name
) &&
805 (flags
? symbol
->flags
& flags
806 : !(symbol
->flags
& (SYMBOL_CONST
|SYMBOL_CHOICE
))))
809 new_name
= xstrdup(name
);
815 symbol
= xmalloc(sizeof(*symbol
));
816 memset(symbol
, 0, sizeof(*symbol
));
817 symbol
->name
= new_name
;
818 symbol
->type
= S_UNKNOWN
;
819 symbol
->flags
= flags
;
821 symbol
->next
= symbol_hash
[hash
];
822 symbol_hash
[hash
] = symbol
;
827 struct symbol
*sym_find(const char *name
)
829 struct symbol
*symbol
= NULL
;
835 if (name
[0] && !name
[1]) {
837 case 'y': return &symbol_yes
;
838 case 'm': return &symbol_mod
;
839 case 'n': return &symbol_no
;
842 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
844 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
846 !strcmp(symbol
->name
, name
) &&
847 !(symbol
->flags
& SYMBOL_CONST
))
854 const char *sym_escape_string_value(const char *in
)
861 reslen
= strlen(in
) + strlen("\"\"") + 1;
865 l
= strcspn(p
, "\"\\");
875 res
= xmalloc(reslen
);
882 l
= strcspn(p
, "\"\\");
890 strncat(res
, p
++, 1);
902 /* Compare matched symbols as thus:
903 * - first, symbols that match exactly
904 * - then, alphabetical sort
906 static int sym_rel_comp(const void *sym1
, const void *sym2
)
908 const struct sym_match
*s1
= sym1
;
909 const struct sym_match
*s2
= sym2
;
913 * - if matched length on symbol s1 is the length of that symbol,
914 * then this symbol should come first;
915 * - if matched length on symbol s2 is the length of that symbol,
916 * then this symbol should come first.
917 * Note: since the search can be a regexp, both symbols may match
918 * exactly; if this is the case, we can't decide which comes first,
919 * and we fallback to sorting alphabetically.
921 exact1
= (s1
->eo
- s1
->so
) == strlen(s1
->sym
->name
);
922 exact2
= (s2
->eo
- s2
->so
) == strlen(s2
->sym
->name
);
923 if (exact1
&& !exact2
)
925 if (!exact1
&& exact2
)
928 /* As a fallback, sort symbols alphabetically */
929 return strcmp(s1
->sym
->name
, s2
->sym
->name
);
932 struct symbol
**sym_re_search(const char *pattern
)
934 struct symbol
*sym
, **sym_arr
= NULL
;
935 struct sym_match
*sym_match_arr
= NULL
;
942 if (strlen(pattern
) == 0)
944 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_ICASE
))
947 for_all_symbols(i
, sym
) {
948 if (sym
->flags
& SYMBOL_CONST
|| !sym
->name
)
950 if (regexec(&re
, sym
->name
, 1, match
, 0))
955 tmp
= realloc(sym_match_arr
, size
* sizeof(struct sym_match
));
957 goto sym_re_search_free
;
961 /* As regexec returned 0, we know we have a match, so
962 * we can use match[0].rm_[se]o without further checks
964 sym_match_arr
[cnt
].so
= match
[0].rm_so
;
965 sym_match_arr
[cnt
].eo
= match
[0].rm_eo
;
966 sym_match_arr
[cnt
++].sym
= sym
;
969 qsort(sym_match_arr
, cnt
, sizeof(struct sym_match
), sym_rel_comp
);
970 sym_arr
= malloc((cnt
+1) * sizeof(struct symbol
*));
972 goto sym_re_search_free
;
973 for (i
= 0; i
< cnt
; i
++)
974 sym_arr
[i
] = sym_match_arr
[i
].sym
;
978 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
986 * When we check for recursive dependencies we use a stack to save
987 * current state so we can print out relevant info to user.
988 * The entries are located on the call stack so no need to free memory.
989 * Note insert() remove() must always match to properly clear the stack.
991 static struct dep_stack
{
992 struct dep_stack
*prev
, *next
;
994 struct property
*prop
;
998 static void dep_stack_insert(struct dep_stack
*stack
, struct symbol
*sym
)
1000 memset(stack
, 0, sizeof(*stack
));
1002 check_top
->next
= stack
;
1003 stack
->prev
= check_top
;
1008 static void dep_stack_remove(void)
1010 check_top
= check_top
->prev
;
1012 check_top
->next
= NULL
;
1016 * Called when we have detected a recursive dependency.
1017 * check_top point to the top of the stact so we use
1018 * the ->prev pointer to locate the bottom of the stack.
1020 static void sym_check_print_recursive(struct symbol
*last_sym
)
1022 struct dep_stack
*stack
;
1023 struct symbol
*sym
, *next_sym
;
1024 struct menu
*menu
= NULL
;
1025 struct property
*prop
;
1026 struct dep_stack cv_stack
;
1028 if (sym_is_choice_value(last_sym
)) {
1029 dep_stack_insert(&cv_stack
, last_sym
);
1030 last_sym
= prop_get_symbol(sym_get_choice_prop(last_sym
));
1033 for (stack
= check_top
; stack
!= NULL
; stack
= stack
->prev
)
1034 if (stack
->sym
== last_sym
)
1037 fprintf(stderr
, "unexpected recursive dependency error\n");
1041 for (; stack
; stack
= stack
->next
) {
1043 next_sym
= stack
->next
? stack
->next
->sym
: last_sym
;
1046 prop
= stack
->sym
->prop
;
1048 /* for choice values find the menu entry (used below) */
1049 if (sym_is_choice(sym
) || sym_is_choice_value(sym
)) {
1050 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1056 if (stack
->sym
== last_sym
)
1057 fprintf(stderr
, "%s:%d:error: recursive dependency detected!\n",
1058 prop
->file
->name
, prop
->lineno
);
1060 if (sym_is_choice(sym
)) {
1061 fprintf(stderr
, "%s:%d:\tchoice %s contains symbol %s\n",
1062 menu
->file
->name
, menu
->lineno
,
1063 sym
->name
? sym
->name
: "<choice>",
1064 next_sym
->name
? next_sym
->name
: "<choice>");
1065 } else if (sym_is_choice_value(sym
)) {
1066 fprintf(stderr
, "%s:%d:\tsymbol %s is part of choice %s\n",
1067 menu
->file
->name
, menu
->lineno
,
1068 sym
->name
? sym
->name
: "<choice>",
1069 next_sym
->name
? next_sym
->name
: "<choice>");
1070 } else if (stack
->expr
== &sym
->dir_dep
.expr
) {
1071 fprintf(stderr
, "%s:%d:\tsymbol %s depends on %s\n",
1072 prop
->file
->name
, prop
->lineno
,
1073 sym
->name
? sym
->name
: "<choice>",
1074 next_sym
->name
? next_sym
->name
: "<choice>");
1075 } else if (stack
->expr
== &sym
->rev_dep
.expr
) {
1076 fprintf(stderr
, "%s:%d:\tsymbol %s is selected by %s\n",
1077 prop
->file
->name
, prop
->lineno
,
1078 sym
->name
? sym
->name
: "<choice>",
1079 next_sym
->name
? next_sym
->name
: "<choice>");
1080 } else if (stack
->expr
== &sym
->implied
.expr
) {
1081 fprintf(stderr
, "%s:%d:\tsymbol %s is implied by %s\n",
1082 prop
->file
->name
, prop
->lineno
,
1083 sym
->name
? sym
->name
: "<choice>",
1084 next_sym
->name
? next_sym
->name
: "<choice>");
1085 } else if (stack
->expr
) {
1086 fprintf(stderr
, "%s:%d:\tsymbol %s %s value contains %s\n",
1087 prop
->file
->name
, prop
->lineno
,
1088 sym
->name
? sym
->name
: "<choice>",
1089 prop_get_type_name(prop
->type
),
1090 next_sym
->name
? next_sym
->name
: "<choice>");
1092 fprintf(stderr
, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1093 prop
->file
->name
, prop
->lineno
,
1094 sym
->name
? sym
->name
: "<choice>",
1095 prop_get_type_name(prop
->type
),
1096 next_sym
->name
? next_sym
->name
: "<choice>");
1101 "For a resolution refer to Documentation/kbuild/kconfig-language.rst\n"
1102 "subsection \"Kconfig recursive dependency limitations\"\n"
1105 if (check_top
== &cv_stack
)
1109 static struct symbol
*sym_check_expr_deps(struct expr
*e
)
1118 sym
= sym_check_expr_deps(e
->left
.expr
);
1121 return sym_check_expr_deps(e
->right
.expr
);
1123 return sym_check_expr_deps(e
->left
.expr
);
1130 sym
= sym_check_deps(e
->left
.sym
);
1133 return sym_check_deps(e
->right
.sym
);
1135 return sym_check_deps(e
->left
.sym
);
1139 fprintf(stderr
, "Oops! How to check %d?\n", e
->type
);
1143 /* return NULL when dependencies are OK */
1144 static struct symbol
*sym_check_sym_deps(struct symbol
*sym
)
1146 struct symbol
*sym2
;
1147 struct property
*prop
;
1148 struct dep_stack stack
;
1150 dep_stack_insert(&stack
, sym
);
1152 stack
.expr
= &sym
->dir_dep
.expr
;
1153 sym2
= sym_check_expr_deps(sym
->dir_dep
.expr
);
1157 stack
.expr
= &sym
->rev_dep
.expr
;
1158 sym2
= sym_check_expr_deps(sym
->rev_dep
.expr
);
1162 stack
.expr
= &sym
->implied
.expr
;
1163 sym2
= sym_check_expr_deps(sym
->implied
.expr
);
1169 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1170 if (prop
->type
== P_CHOICE
|| prop
->type
== P_SELECT
||
1171 prop
->type
== P_IMPLY
)
1174 sym2
= sym_check_expr_deps(prop
->visible
.expr
);
1177 if (prop
->type
!= P_DEFAULT
|| sym_is_choice(sym
))
1179 stack
.expr
= &prop
->expr
;
1180 sym2
= sym_check_expr_deps(prop
->expr
);
1192 static struct symbol
*sym_check_choice_deps(struct symbol
*choice
)
1194 struct symbol
*sym
, *sym2
;
1195 struct property
*prop
;
1197 struct dep_stack stack
;
1199 dep_stack_insert(&stack
, choice
);
1201 prop
= sym_get_choice_prop(choice
);
1202 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1203 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1205 choice
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1206 sym2
= sym_check_sym_deps(choice
);
1207 choice
->flags
&= ~SYMBOL_CHECK
;
1211 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1212 sym2
= sym_check_sym_deps(sym
);
1217 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1218 sym
->flags
&= ~SYMBOL_CHECK
;
1220 if (sym2
&& sym_is_choice_value(sym2
) &&
1221 prop_get_symbol(sym_get_choice_prop(sym2
)) == choice
)
1229 struct symbol
*sym_check_deps(struct symbol
*sym
)
1231 struct symbol
*sym2
;
1232 struct property
*prop
;
1234 if (sym
->flags
& SYMBOL_CHECK
) {
1235 sym_check_print_recursive(sym
);
1238 if (sym
->flags
& SYMBOL_CHECKED
)
1241 if (sym_is_choice_value(sym
)) {
1242 struct dep_stack stack
;
1244 /* for choice groups start the check with main choice symbol */
1245 dep_stack_insert(&stack
, sym
);
1246 prop
= sym_get_choice_prop(sym
);
1247 sym2
= sym_check_deps(prop_get_symbol(prop
));
1249 } else if (sym_is_choice(sym
)) {
1250 sym2
= sym_check_choice_deps(sym
);
1252 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1253 sym2
= sym_check_sym_deps(sym
);
1254 sym
->flags
&= ~SYMBOL_CHECK
;
1257 if (!recursive_is_error
&& sym2
&& sym2
== sym
)
1263 struct symbol
*prop_get_symbol(struct property
*prop
)
1265 if (prop
->expr
&& (prop
->expr
->type
== E_SYMBOL
||
1266 prop
->expr
->type
== E_LIST
))
1267 return prop
->expr
->left
.sym
;
1271 const char *prop_get_type_name(enum prop_type type
)