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
;
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 void sym_calc_value(struct symbol
*sym
)
304 struct symbol_value newval
, oldval
;
305 struct property
*prop
;
311 if (sym
->flags
& SYMBOL_VALID
)
314 if (sym_is_choice_value(sym
) &&
315 sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
) {
316 sym
->flags
&= ~SYMBOL_NEED_SET_CHOICE_VALUES
;
317 prop
= sym_get_choice_prop(sym
);
318 sym_calc_value(prop_get_symbol(prop
));
321 sym
->flags
|= SYMBOL_VALID
;
329 newval
= symbol_empty
.curr
;
333 newval
= symbol_no
.curr
;
336 sym
->curr
.val
= sym
->name
;
340 sym
->flags
&= ~SYMBOL_WRITE
;
342 sym_calc_visibility(sym
);
344 if (sym
->visible
!= no
)
345 sym
->flags
|= SYMBOL_WRITE
;
347 /* set default if recursively called */
350 switch (sym_get_type(sym
)) {
353 if (sym_is_choice_value(sym
) && sym
->visible
== yes
) {
354 prop
= sym_get_choice_prop(sym
);
355 newval
.tri
= (prop_get_symbol(prop
)->curr
.val
== sym
) ? yes
: no
;
357 if (sym
->visible
!= no
) {
358 /* if the symbol is visible use the user value
359 * if available, otherwise try the default value
361 if (sym_has_value(sym
)) {
362 newval
.tri
= EXPR_AND(sym
->def
[S_DEF_USER
].tri
,
367 if (sym
->rev_dep
.tri
!= no
)
368 sym
->flags
|= SYMBOL_WRITE
;
369 if (!sym_is_choice(sym
)) {
370 prop
= sym_get_default_prop(sym
);
372 sym
->flags
|= SYMBOL_WRITE
;
373 newval
.tri
= EXPR_AND(expr_calc_value(prop
->expr
),
376 if (sym
->implied
.tri
!= no
) {
377 sym
->flags
|= SYMBOL_WRITE
;
378 newval
.tri
= EXPR_OR(newval
.tri
, sym
->implied
.tri
);
379 newval
.tri
= EXPR_AND(newval
.tri
,
384 if (sym
->dir_dep
.tri
== no
&& sym
->rev_dep
.tri
!= no
)
387 newval
.tri
= EXPR_OR(newval
.tri
, sym
->rev_dep
.tri
);
389 if (newval
.tri
== mod
&& sym_get_type(sym
) == S_BOOLEAN
)
395 if (sym
->visible
!= no
&& sym_has_value(sym
)) {
396 newval
.val
= sym
->def
[S_DEF_USER
].val
;
399 prop
= sym_get_default_prop(sym
);
401 struct symbol
*ds
= prop_get_symbol(prop
);
403 sym
->flags
|= SYMBOL_WRITE
;
405 newval
.val
= ds
->curr
.val
;
414 if (sym_is_choice(sym
) && newval
.tri
== yes
)
415 sym
->curr
.val
= sym_calc_choice(sym
);
416 sym_validate_range(sym
);
418 if (memcmp(&oldval
, &sym
->curr
, sizeof(oldval
))) {
419 sym_set_changed(sym
);
420 if (modules_sym
== sym
) {
421 sym_set_all_changed();
422 modules_val
= modules_sym
->curr
.tri
;
426 if (sym_is_choice(sym
)) {
427 struct symbol
*choice_sym
;
429 prop
= sym_get_choice_prop(sym
);
430 expr_list_for_each_sym(prop
->expr
, e
, choice_sym
) {
431 if ((sym
->flags
& SYMBOL_WRITE
) &&
432 choice_sym
->visible
!= no
)
433 choice_sym
->flags
|= SYMBOL_WRITE
;
434 if (sym
->flags
& SYMBOL_CHANGED
)
435 sym_set_changed(choice_sym
);
439 if (sym
->flags
& SYMBOL_NO_WRITE
)
440 sym
->flags
&= ~SYMBOL_WRITE
;
442 if (sym
->flags
& SYMBOL_NEED_SET_CHOICE_VALUES
)
443 set_all_choice_values(sym
);
446 void sym_clear_all_valid(void)
451 for_all_symbols(i
, sym
)
452 sym
->flags
&= ~SYMBOL_VALID
;
453 conf_set_changed(true);
454 sym_calc_value(modules_sym
);
457 bool sym_tristate_within_range(struct symbol
*sym
, tristate val
)
459 int type
= sym_get_type(sym
);
461 if (sym
->visible
== no
)
464 if (type
!= S_BOOLEAN
&& type
!= S_TRISTATE
)
467 if (type
== S_BOOLEAN
&& val
== mod
)
469 if (sym
->visible
<= sym
->rev_dep
.tri
)
471 if (sym_is_choice_value(sym
) && sym
->visible
== yes
)
473 return val
>= sym
->rev_dep
.tri
&& val
<= sym
->visible
;
476 bool sym_set_tristate_value(struct symbol
*sym
, tristate val
)
478 tristate oldval
= sym_get_tristate_value(sym
);
480 if (oldval
!= val
&& !sym_tristate_within_range(sym
, val
))
483 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
484 sym
->flags
|= SYMBOL_DEF_USER
;
485 sym_set_changed(sym
);
488 * setting a choice value also resets the new flag of the choice
489 * symbol and all other choice values.
491 if (sym_is_choice_value(sym
) && val
== yes
) {
492 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
493 struct property
*prop
;
496 cs
->def
[S_DEF_USER
].val
= sym
;
497 cs
->flags
|= SYMBOL_DEF_USER
;
498 prop
= sym_get_choice_prop(cs
);
499 for (e
= prop
->expr
; e
; e
= e
->left
.expr
) {
500 if (e
->right
.sym
->visible
!= no
)
501 e
->right
.sym
->flags
|= SYMBOL_DEF_USER
;
505 sym
->def
[S_DEF_USER
].tri
= val
;
507 sym_clear_all_valid();
512 tristate
sym_toggle_tristate_value(struct symbol
*sym
)
514 tristate oldval
, newval
;
516 oldval
= newval
= sym_get_tristate_value(sym
);
529 if (sym_set_tristate_value(sym
, newval
))
531 } while (oldval
!= newval
);
535 bool sym_string_valid(struct symbol
*sym
, const char *str
)
548 if (ch
== '0' && *str
!= 0)
550 while ((ch
= *str
++)) {
556 if (str
[0] == '0' && (str
[1] == 'x' || str
[1] == 'X'))
562 } while ((ch
= *str
++));
578 bool sym_string_within_range(struct symbol
*sym
, const char *str
)
580 struct property
*prop
;
585 return sym_string_valid(sym
, str
);
587 if (!sym_string_valid(sym
, str
))
589 prop
= sym_get_range_prop(sym
);
592 val
= strtoll(str
, NULL
, 10);
593 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 10) &&
594 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 10);
596 if (!sym_string_valid(sym
, str
))
598 prop
= sym_get_range_prop(sym
);
601 val
= strtoll(str
, NULL
, 16);
602 return val
>= sym_get_range_val(prop
->expr
->left
.sym
, 16) &&
603 val
<= sym_get_range_val(prop
->expr
->right
.sym
, 16);
608 return sym_tristate_within_range(sym
, yes
);
610 return sym_tristate_within_range(sym
, mod
);
612 return sym_tristate_within_range(sym
, no
);
620 bool sym_set_string_value(struct symbol
*sym
, const char *newval
)
631 return sym_set_tristate_value(sym
, yes
);
633 return sym_set_tristate_value(sym
, mod
);
635 return sym_set_tristate_value(sym
, no
);
642 if (!sym_string_within_range(sym
, newval
))
645 if (!(sym
->flags
& SYMBOL_DEF_USER
)) {
646 sym
->flags
|= SYMBOL_DEF_USER
;
647 sym_set_changed(sym
);
650 oldval
= sym
->def
[S_DEF_USER
].val
;
651 size
= strlen(newval
) + 1;
652 if (sym
->type
== S_HEX
&& (newval
[0] != '0' || (newval
[1] != 'x' && newval
[1] != 'X'))) {
654 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
657 } else if (!oldval
|| strcmp(oldval
, newval
))
658 sym
->def
[S_DEF_USER
].val
= val
= xmalloc(size
);
663 free((void *)oldval
);
664 sym_clear_all_valid();
670 * Find the default value associated to a symbol.
671 * For tristate symbol handle the modules=n case
672 * in which case "m" becomes "y".
673 * If the symbol does not have any default then fallback
674 * to the fixed default values.
676 const char *sym_get_string_default(struct symbol
*sym
)
678 struct property
*prop
;
683 sym_calc_visibility(sym
);
684 sym_calc_value(modules_sym
);
685 val
= symbol_no
.curr
.tri
;
686 str
= symbol_empty
.curr
.val
;
688 /* If symbol has a default value look it up */
689 prop
= sym_get_default_prop(sym
);
694 /* The visibility may limit the value from yes => mod */
695 val
= EXPR_AND(expr_calc_value(prop
->expr
), prop
->visible
.tri
);
699 * The following fails to handle the situation
700 * where a default value is further limited by
703 ds
= prop_get_symbol(prop
);
706 str
= (const char *)ds
->curr
.val
;
711 /* Handle select statements */
712 val
= EXPR_OR(val
, sym
->rev_dep
.tri
);
714 /* transpose mod to yes if modules are not enabled */
716 if (!sym_is_choice_value(sym
) && modules_sym
->curr
.tri
== no
)
719 /* transpose mod to yes if type is bool */
720 if (sym
->type
== S_BOOLEAN
&& val
== mod
)
723 /* adjust the default value if this symbol is implied by another */
724 if (val
< sym
->implied
.tri
)
725 val
= sym
->implied
.tri
;
732 case mod
: return "m";
733 case yes
: return "y";
746 const char *sym_get_string_value(struct symbol
*sym
)
753 val
= sym_get_tristate_value(sym
);
758 sym_calc_value(modules_sym
);
759 return (modules_sym
->curr
.tri
== no
) ? "n" : "m";
767 return (const char *)sym
->curr
.val
;
770 bool sym_is_changeable(struct symbol
*sym
)
772 return sym
->visible
> sym
->rev_dep
.tri
;
775 static unsigned strhash(const char *s
)
778 unsigned hash
= 2166136261U;
780 hash
= (hash
^ *s
) * 0x01000193;
784 struct symbol
*sym_lookup(const char *name
, int flags
)
786 struct symbol
*symbol
;
791 if (name
[0] && !name
[1]) {
793 case 'y': return &symbol_yes
;
794 case 'm': return &symbol_mod
;
795 case 'n': return &symbol_no
;
798 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
800 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
802 !strcmp(symbol
->name
, name
) &&
803 (flags
? symbol
->flags
& flags
804 : !(symbol
->flags
& (SYMBOL_CONST
|SYMBOL_CHOICE
))))
807 new_name
= xstrdup(name
);
813 symbol
= xmalloc(sizeof(*symbol
));
814 memset(symbol
, 0, sizeof(*symbol
));
815 symbol
->name
= new_name
;
816 symbol
->type
= S_UNKNOWN
;
817 symbol
->flags
= flags
;
819 symbol
->next
= symbol_hash
[hash
];
820 symbol_hash
[hash
] = symbol
;
825 struct symbol
*sym_find(const char *name
)
827 struct symbol
*symbol
= NULL
;
833 if (name
[0] && !name
[1]) {
835 case 'y': return &symbol_yes
;
836 case 'm': return &symbol_mod
;
837 case 'n': return &symbol_no
;
840 hash
= strhash(name
) % SYMBOL_HASHSIZE
;
842 for (symbol
= symbol_hash
[hash
]; symbol
; symbol
= symbol
->next
) {
844 !strcmp(symbol
->name
, name
) &&
845 !(symbol
->flags
& SYMBOL_CONST
))
857 /* Compare matched symbols as thus:
858 * - first, symbols that match exactly
859 * - then, alphabetical sort
861 static int sym_rel_comp(const void *sym1
, const void *sym2
)
863 const struct sym_match
*s1
= sym1
;
864 const struct sym_match
*s2
= sym2
;
868 * - if matched length on symbol s1 is the length of that symbol,
869 * then this symbol should come first;
870 * - if matched length on symbol s2 is the length of that symbol,
871 * then this symbol should come first.
872 * Note: since the search can be a regexp, both symbols may match
873 * exactly; if this is the case, we can't decide which comes first,
874 * and we fallback to sorting alphabetically.
876 exact1
= (s1
->eo
- s1
->so
) == strlen(s1
->sym
->name
);
877 exact2
= (s2
->eo
- s2
->so
) == strlen(s2
->sym
->name
);
878 if (exact1
&& !exact2
)
880 if (!exact1
&& exact2
)
883 /* As a fallback, sort symbols alphabetically */
884 return strcmp(s1
->sym
->name
, s2
->sym
->name
);
887 struct symbol
**sym_re_search(const char *pattern
)
889 struct symbol
*sym
, **sym_arr
= NULL
;
890 struct sym_match
*sym_match_arr
= NULL
;
897 if (strlen(pattern
) == 0)
899 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_ICASE
))
902 for_all_symbols(i
, sym
) {
903 if (sym
->flags
& SYMBOL_CONST
|| !sym
->name
)
905 if (regexec(&re
, sym
->name
, 1, match
, 0))
910 tmp
= realloc(sym_match_arr
, size
* sizeof(struct sym_match
));
912 goto sym_re_search_free
;
916 /* As regexec returned 0, we know we have a match, so
917 * we can use match[0].rm_[se]o without further checks
919 sym_match_arr
[cnt
].so
= match
[0].rm_so
;
920 sym_match_arr
[cnt
].eo
= match
[0].rm_eo
;
921 sym_match_arr
[cnt
++].sym
= sym
;
924 qsort(sym_match_arr
, cnt
, sizeof(struct sym_match
), sym_rel_comp
);
925 sym_arr
= malloc((cnt
+1) * sizeof(struct symbol
*));
927 goto sym_re_search_free
;
928 for (i
= 0; i
< cnt
; i
++)
929 sym_arr
[i
] = sym_match_arr
[i
].sym
;
933 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
941 * When we check for recursive dependencies we use a stack to save
942 * current state so we can print out relevant info to user.
943 * The entries are located on the call stack so no need to free memory.
944 * Note insert() remove() must always match to properly clear the stack.
946 static struct dep_stack
{
947 struct dep_stack
*prev
, *next
;
949 struct property
*prop
;
953 static void dep_stack_insert(struct dep_stack
*stack
, struct symbol
*sym
)
955 memset(stack
, 0, sizeof(*stack
));
957 check_top
->next
= stack
;
958 stack
->prev
= check_top
;
963 static void dep_stack_remove(void)
965 check_top
= check_top
->prev
;
967 check_top
->next
= NULL
;
971 * Called when we have detected a recursive dependency.
972 * check_top point to the top of the stact so we use
973 * the ->prev pointer to locate the bottom of the stack.
975 static void sym_check_print_recursive(struct symbol
*last_sym
)
977 struct dep_stack
*stack
;
978 struct symbol
*sym
, *next_sym
;
979 struct menu
*menu
= NULL
;
980 struct property
*prop
;
981 struct dep_stack cv_stack
;
983 if (sym_is_choice_value(last_sym
)) {
984 dep_stack_insert(&cv_stack
, last_sym
);
985 last_sym
= prop_get_symbol(sym_get_choice_prop(last_sym
));
988 for (stack
= check_top
; stack
!= NULL
; stack
= stack
->prev
)
989 if (stack
->sym
== last_sym
)
992 fprintf(stderr
, "unexpected recursive dependency error\n");
996 for (; stack
; stack
= stack
->next
) {
998 next_sym
= stack
->next
? stack
->next
->sym
: last_sym
;
1001 prop
= stack
->sym
->prop
;
1003 /* for choice values find the menu entry (used below) */
1004 if (sym_is_choice(sym
) || sym_is_choice_value(sym
)) {
1005 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1011 if (stack
->sym
== last_sym
)
1012 fprintf(stderr
, "%s:%d:error: recursive dependency detected!\n",
1013 prop
->file
->name
, prop
->lineno
);
1015 if (sym_is_choice(sym
)) {
1016 fprintf(stderr
, "%s:%d:\tchoice %s contains symbol %s\n",
1017 menu
->file
->name
, menu
->lineno
,
1018 sym
->name
? sym
->name
: "<choice>",
1019 next_sym
->name
? next_sym
->name
: "<choice>");
1020 } else if (sym_is_choice_value(sym
)) {
1021 fprintf(stderr
, "%s:%d:\tsymbol %s is part of choice %s\n",
1022 menu
->file
->name
, menu
->lineno
,
1023 sym
->name
? sym
->name
: "<choice>",
1024 next_sym
->name
? next_sym
->name
: "<choice>");
1025 } else if (stack
->expr
== &sym
->dir_dep
.expr
) {
1026 fprintf(stderr
, "%s:%d:\tsymbol %s depends on %s\n",
1027 prop
->file
->name
, prop
->lineno
,
1028 sym
->name
? sym
->name
: "<choice>",
1029 next_sym
->name
? next_sym
->name
: "<choice>");
1030 } else if (stack
->expr
== &sym
->rev_dep
.expr
) {
1031 fprintf(stderr
, "%s:%d:\tsymbol %s is selected by %s\n",
1032 prop
->file
->name
, prop
->lineno
,
1033 sym
->name
? sym
->name
: "<choice>",
1034 next_sym
->name
? next_sym
->name
: "<choice>");
1035 } else if (stack
->expr
== &sym
->implied
.expr
) {
1036 fprintf(stderr
, "%s:%d:\tsymbol %s is implied by %s\n",
1037 prop
->file
->name
, prop
->lineno
,
1038 sym
->name
? sym
->name
: "<choice>",
1039 next_sym
->name
? next_sym
->name
: "<choice>");
1040 } else if (stack
->expr
) {
1041 fprintf(stderr
, "%s:%d:\tsymbol %s %s value contains %s\n",
1042 prop
->file
->name
, prop
->lineno
,
1043 sym
->name
? sym
->name
: "<choice>",
1044 prop_get_type_name(prop
->type
),
1045 next_sym
->name
? next_sym
->name
: "<choice>");
1047 fprintf(stderr
, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1048 prop
->file
->name
, prop
->lineno
,
1049 sym
->name
? sym
->name
: "<choice>",
1050 prop_get_type_name(prop
->type
),
1051 next_sym
->name
? next_sym
->name
: "<choice>");
1056 "For a resolution refer to Documentation/kbuild/kconfig-language.rst\n"
1057 "subsection \"Kconfig recursive dependency limitations\"\n"
1060 if (check_top
== &cv_stack
)
1064 static struct symbol
*sym_check_expr_deps(struct expr
*e
)
1073 sym
= sym_check_expr_deps(e
->left
.expr
);
1076 return sym_check_expr_deps(e
->right
.expr
);
1078 return sym_check_expr_deps(e
->left
.expr
);
1085 sym
= sym_check_deps(e
->left
.sym
);
1088 return sym_check_deps(e
->right
.sym
);
1090 return sym_check_deps(e
->left
.sym
);
1094 fprintf(stderr
, "Oops! How to check %d?\n", e
->type
);
1098 /* return NULL when dependencies are OK */
1099 static struct symbol
*sym_check_sym_deps(struct symbol
*sym
)
1101 struct symbol
*sym2
;
1102 struct property
*prop
;
1103 struct dep_stack stack
;
1105 dep_stack_insert(&stack
, sym
);
1107 stack
.expr
= &sym
->dir_dep
.expr
;
1108 sym2
= sym_check_expr_deps(sym
->dir_dep
.expr
);
1112 stack
.expr
= &sym
->rev_dep
.expr
;
1113 sym2
= sym_check_expr_deps(sym
->rev_dep
.expr
);
1117 stack
.expr
= &sym
->implied
.expr
;
1118 sym2
= sym_check_expr_deps(sym
->implied
.expr
);
1124 for (prop
= sym
->prop
; prop
; prop
= prop
->next
) {
1125 if (prop
->type
== P_CHOICE
|| prop
->type
== P_SELECT
||
1126 prop
->type
== P_IMPLY
)
1129 sym2
= sym_check_expr_deps(prop
->visible
.expr
);
1132 if (prop
->type
!= P_DEFAULT
|| sym_is_choice(sym
))
1134 stack
.expr
= &prop
->expr
;
1135 sym2
= sym_check_expr_deps(prop
->expr
);
1147 static struct symbol
*sym_check_choice_deps(struct symbol
*choice
)
1149 struct symbol
*sym
, *sym2
;
1150 struct property
*prop
;
1152 struct dep_stack stack
;
1154 dep_stack_insert(&stack
, choice
);
1156 prop
= sym_get_choice_prop(choice
);
1157 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1158 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1160 choice
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1161 sym2
= sym_check_sym_deps(choice
);
1162 choice
->flags
&= ~SYMBOL_CHECK
;
1166 expr_list_for_each_sym(prop
->expr
, e
, sym
) {
1167 sym2
= sym_check_sym_deps(sym
);
1172 expr_list_for_each_sym(prop
->expr
, e
, sym
)
1173 sym
->flags
&= ~SYMBOL_CHECK
;
1175 if (sym2
&& sym_is_choice_value(sym2
) &&
1176 prop_get_symbol(sym_get_choice_prop(sym2
)) == choice
)
1184 struct symbol
*sym_check_deps(struct symbol
*sym
)
1186 struct symbol
*sym2
;
1187 struct property
*prop
;
1189 if (sym
->flags
& SYMBOL_CHECK
) {
1190 sym_check_print_recursive(sym
);
1193 if (sym
->flags
& SYMBOL_CHECKED
)
1196 if (sym_is_choice_value(sym
)) {
1197 struct dep_stack stack
;
1199 /* for choice groups start the check with main choice symbol */
1200 dep_stack_insert(&stack
, sym
);
1201 prop
= sym_get_choice_prop(sym
);
1202 sym2
= sym_check_deps(prop_get_symbol(prop
));
1204 } else if (sym_is_choice(sym
)) {
1205 sym2
= sym_check_choice_deps(sym
);
1207 sym
->flags
|= (SYMBOL_CHECK
| SYMBOL_CHECKED
);
1208 sym2
= sym_check_sym_deps(sym
);
1209 sym
->flags
&= ~SYMBOL_CHECK
;
1212 if (!recursive_is_error
&& sym2
&& sym2
== sym
)
1218 struct symbol
*prop_get_symbol(struct property
*prop
)
1220 if (prop
->expr
&& (prop
->expr
->type
== E_SYMBOL
||
1221 prop
->expr
->type
== E_LIST
))
1222 return prop
->expr
->left
.sym
;
1226 const char *prop_get_type_name(enum prop_type type
)