aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/symbol.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/symbol.c')
-rw-r--r--scripts/kconfig/symbol.c296
1 files changed, 263 insertions, 33 deletions
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 2e7a048e0cfc..1f8b305449db 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -205,6 +205,16 @@ static void sym_calc_visibility(struct symbol *sym)
205 } 205 }
206 if (sym_is_choice_value(sym)) 206 if (sym_is_choice_value(sym))
207 return; 207 return;
208 /* defaulting to "yes" if no explicit "depends on" are given */
209 tri = yes;
210 if (sym->dir_dep.expr)
211 tri = expr_calc_value(sym->dir_dep.expr);
212 if (tri == mod)
213 tri = yes;
214 if (sym->dir_dep.tri != tri) {
215 sym->dir_dep.tri = tri;
216 sym_set_changed(sym);
217 }
208 tri = no; 218 tri = no;
209 if (sym->rev_dep.expr) 219 if (sym->rev_dep.expr)
210 tri = expr_calc_value(sym->rev_dep.expr); 220 tri = expr_calc_value(sym->rev_dep.expr);
@@ -216,44 +226,63 @@ static void sym_calc_visibility(struct symbol *sym)
216 } 226 }
217} 227}
218 228
219static struct symbol *sym_calc_choice(struct symbol *sym) 229/*
230 * Find the default symbol for a choice.
231 * First try the default values for the choice symbol
232 * Next locate the first visible choice value
233 * Return NULL if none was found
234 */
235struct symbol *sym_choice_default(struct symbol *sym)
220{ 236{
221 struct symbol *def_sym; 237 struct symbol *def_sym;
222 struct property *prop; 238 struct property *prop;
223 struct expr *e; 239 struct expr *e;
224 240
225 /* is the user choice visible? */
226 def_sym = sym->def[S_DEF_USER].val;
227 if (def_sym) {
228 sym_calc_visibility(def_sym);
229 if (def_sym->visible != no)
230 return def_sym;
231 }
232
233 /* any of the defaults visible? */ 241 /* any of the defaults visible? */
234 for_all_defaults(sym, prop) { 242 for_all_defaults(sym, prop) {
235 prop->visible.tri = expr_calc_value(prop->visible.expr); 243 prop->visible.tri = expr_calc_value(prop->visible.expr);
236 if (prop->visible.tri == no) 244 if (prop->visible.tri == no)
237 continue; 245 continue;
238 def_sym = prop_get_symbol(prop); 246 def_sym = prop_get_symbol(prop);
239 sym_calc_visibility(def_sym);
240 if (def_sym->visible != no) 247 if (def_sym->visible != no)
241 return def_sym; 248 return def_sym;
242 } 249 }
243 250
244 /* just get the first visible value */ 251 /* just get the first visible value */
245 prop = sym_get_choice_prop(sym); 252 prop = sym_get_choice_prop(sym);
246 expr_list_for_each_sym(prop->expr, e, def_sym) { 253 expr_list_for_each_sym(prop->expr, e, def_sym)
247 sym_calc_visibility(def_sym);
248 if (def_sym->visible != no) 254 if (def_sym->visible != no)
249 return def_sym; 255 return def_sym;
250 }
251 256
252 /* no choice? reset tristate value */ 257 /* failed to locate any defaults */
253 sym->curr.tri = no;
254 return NULL; 258 return NULL;
255} 259}
256 260
261static struct symbol *sym_calc_choice(struct symbol *sym)
262{
263 struct symbol *def_sym;
264 struct property *prop;
265 struct expr *e;
266
267 /* first calculate all choice values' visibilities */
268 prop = sym_get_choice_prop(sym);
269 expr_list_for_each_sym(prop->expr, e, def_sym)
270 sym_calc_visibility(def_sym);
271
272 /* is the user choice visible? */
273 def_sym = sym->def[S_DEF_USER].val;
274 if (def_sym && def_sym->visible != no)
275 return def_sym;
276
277 def_sym = sym_choice_default(sym);
278
279 if (def_sym == NULL)
280 /* no choice? reset tristate value */
281 sym->curr.tri = no;
282
283 return def_sym;
284}
285
257void sym_calc_value(struct symbol *sym) 286void sym_calc_value(struct symbol *sym)
258{ 287{
259 struct symbol_value newval, oldval; 288 struct symbol_value newval, oldval;
@@ -321,6 +350,16 @@ void sym_calc_value(struct symbol *sym)
321 } 350 }
322 } 351 }
323 calc_newval: 352 calc_newval:
353#if 0
354 if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) {
355 fprintf(stderr, "warning: (");
356 expr_fprint(sym->rev_dep.expr, stderr);
357 fprintf(stderr, ") selects %s which has unmet direct dependencies (",
358 sym->name);
359 expr_fprint(sym->dir_dep.expr, stderr);
360 fprintf(stderr, ")\n");
361 }
362#endif
324 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); 363 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
325 } 364 }
326 if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN) 365 if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
@@ -365,12 +404,13 @@ void sym_calc_value(struct symbol *sym)
365 404
366 if (sym_is_choice(sym)) { 405 if (sym_is_choice(sym)) {
367 struct symbol *choice_sym; 406 struct symbol *choice_sym;
368 int flags = sym->flags & (SYMBOL_CHANGED | SYMBOL_WRITE);
369 407
370 prop = sym_get_choice_prop(sym); 408 prop = sym_get_choice_prop(sym);
371 expr_list_for_each_sym(prop->expr, e, choice_sym) { 409 expr_list_for_each_sym(prop->expr, e, choice_sym) {
372 choice_sym->flags |= flags; 410 if ((sym->flags & SYMBOL_WRITE) &&
373 if (flags & SYMBOL_CHANGED) 411 choice_sym->visible != no)
412 choice_sym->flags |= SYMBOL_WRITE;
413 if (sym->flags & SYMBOL_CHANGED)
374 sym_set_changed(choice_sym); 414 sym_set_changed(choice_sym);
375 } 415 }
376 } 416 }
@@ -623,6 +663,80 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
623 return true; 663 return true;
624} 664}
625 665
666/*
667 * Find the default value associated to a symbol.
668 * For tristate symbol handle the modules=n case
669 * in which case "m" becomes "y".
670 * If the symbol does not have any default then fallback
671 * to the fixed default values.
672 */
673const char *sym_get_string_default(struct symbol *sym)
674{
675 struct property *prop;
676 struct symbol *ds;
677 const char *str;
678 tristate val;
679
680 sym_calc_visibility(sym);
681 sym_calc_value(modules_sym);
682 val = symbol_no.curr.tri;
683 str = symbol_empty.curr.val;
684
685 /* If symbol has a default value look it up */
686 prop = sym_get_default_prop(sym);
687 if (prop != NULL) {
688 switch (sym->type) {
689 case S_BOOLEAN:
690 case S_TRISTATE:
691 /* The visibility imay limit the value from yes => mod */
692 val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri);
693 break;
694 default:
695 /*
696 * The following fails to handle the situation
697 * where a default value is further limited by
698 * the valid range.
699 */
700 ds = prop_get_symbol(prop);
701 if (ds != NULL) {
702 sym_calc_value(ds);
703 str = (const char *)ds->curr.val;
704 }
705 }
706 }
707
708 /* Handle select statements */
709 val = EXPR_OR(val, sym->rev_dep.tri);
710
711 /* transpose mod to yes if modules are not enabled */
712 if (val == mod)
713 if (!sym_is_choice_value(sym) && modules_sym->curr.tri == no)
714 val = yes;
715
716 /* transpose mod to yes if type is bool */
717 if (sym->type == S_BOOLEAN && val == mod)
718 val = yes;
719
720 switch (sym->type) {
721 case S_BOOLEAN:
722 case S_TRISTATE:
723 switch (val) {
724 case no: return "n";
725 case mod: return "m";
726 case yes: return "y";
727 }
728 case S_INT:
729 case S_HEX:
730 return str;
731 case S_STRING:
732 return str;
733 case S_OTHER:
734 case S_UNKNOWN:
735 break;
736 }
737 return "";
738}
739
626const char *sym_get_string_value(struct symbol *sym) 740const char *sym_get_string_value(struct symbol *sym)
627{ 741{
628 tristate val; 742 tristate val;
@@ -765,6 +879,112 @@ struct symbol **sym_re_search(const char *pattern)
765 return sym_arr; 879 return sym_arr;
766} 880}
767 881
882/*
883 * When we check for recursive dependencies we use a stack to save
884 * current state so we can print out relevant info to user.
885 * The entries are located on the call stack so no need to free memory.
886 * Note inser() remove() must always match to properly clear the stack.
887 */
888static struct dep_stack {
889 struct dep_stack *prev, *next;
890 struct symbol *sym;
891 struct property *prop;
892 struct expr *expr;
893} *check_top;
894
895static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
896{
897 memset(stack, 0, sizeof(*stack));
898 if (check_top)
899 check_top->next = stack;
900 stack->prev = check_top;
901 stack->sym = sym;
902 check_top = stack;
903}
904
905static void dep_stack_remove(void)
906{
907 check_top = check_top->prev;
908 if (check_top)
909 check_top->next = NULL;
910}
911
912/*
913 * Called when we have detected a recursive dependency.
914 * check_top point to the top of the stact so we use
915 * the ->prev pointer to locate the bottom of the stack.
916 */
917static void sym_check_print_recursive(struct symbol *last_sym)
918{
919 struct dep_stack *stack;
920 struct symbol *sym, *next_sym;
921 struct menu *menu = NULL;
922 struct property *prop;
923 struct dep_stack cv_stack;
924
925 if (sym_is_choice_value(last_sym)) {
926 dep_stack_insert(&cv_stack, last_sym);
927 last_sym = prop_get_symbol(sym_get_choice_prop(last_sym));
928 }
929
930 for (stack = check_top; stack != NULL; stack = stack->prev)
931 if (stack->sym == last_sym)
932 break;
933 if (!stack) {
934 fprintf(stderr, "unexpected recursive dependency error\n");
935 return;
936 }
937
938 for (; stack; stack = stack->next) {
939 sym = stack->sym;
940 next_sym = stack->next ? stack->next->sym : last_sym;
941 prop = stack->prop;
942 if (prop == NULL)
943 prop = stack->sym->prop;
944
945 /* for choice values find the menu entry (used below) */
946 if (sym_is_choice(sym) || sym_is_choice_value(sym)) {
947 for (prop = sym->prop; prop; prop = prop->next) {
948 menu = prop->menu;
949 if (prop->menu)
950 break;
951 }
952 }
953 if (stack->sym == last_sym)
954 fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
955 prop->file->name, prop->lineno);
956 if (stack->expr) {
957 fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
958 prop->file->name, prop->lineno,
959 sym->name ? sym->name : "<choice>",
960 prop_get_type_name(prop->type),
961 next_sym->name ? next_sym->name : "<choice>");
962 } else if (stack->prop) {
963 fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
964 prop->file->name, prop->lineno,
965 sym->name ? sym->name : "<choice>",
966 next_sym->name ? next_sym->name : "<choice>");
967 } else if (sym_is_choice(sym)) {
968 fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
969 menu->file->name, menu->lineno,
970 sym->name ? sym->name : "<choice>",
971 next_sym->name ? next_sym->name : "<choice>");
972 } else if (sym_is_choice_value(sym)) {
973 fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
974 menu->file->name, menu->lineno,
975 sym->name ? sym->name : "<choice>",
976 next_sym->name ? next_sym->name : "<choice>");
977 } else {
978 fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
979 prop->file->name, prop->lineno,
980 sym->name ? sym->name : "<choice>",
981 next_sym->name ? next_sym->name : "<choice>");
982 }
983 }
984
985 if (check_top == &cv_stack)
986 dep_stack_remove();
987}
768 988
769static struct symbol *sym_check_expr_deps(struct expr *e) 989static struct symbol *sym_check_expr_deps(struct expr *e)
770{ 990{
@@ -801,24 +1021,33 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
801{ 1021{
802 struct symbol *sym2; 1022 struct symbol *sym2;
803 struct property *prop; 1023 struct property *prop;
1024 struct dep_stack stack;
1025
1026 dep_stack_insert(&stack, sym);
804 1027
805 sym2 = sym_check_expr_deps(sym->rev_dep.expr); 1028 sym2 = sym_check_expr_deps(sym->rev_dep.expr);
806 if (sym2) 1029 if (sym2)
807 return sym2; 1030 goto out;
808 1031
809 for (prop = sym->prop; prop; prop = prop->next) { 1032 for (prop = sym->prop; prop; prop = prop->next) {
810 if (prop->type == P_CHOICE || prop->type == P_SELECT) 1033 if (prop->type == P_CHOICE || prop->type == P_SELECT)
811 continue; 1034 continue;
1035 stack.prop = prop;
812 sym2 = sym_check_expr_deps(prop->visible.expr); 1036 sym2 = sym_check_expr_deps(prop->visible.expr);
813 if (sym2) 1037 if (sym2)
814 break; 1038 break;
815 if (prop->type != P_DEFAULT || sym_is_choice(sym)) 1039 if (prop->type != P_DEFAULT || sym_is_choice(sym))
816 continue; 1040 continue;
1041 stack.expr = prop->expr;
817 sym2 = sym_check_expr_deps(prop->expr); 1042 sym2 = sym_check_expr_deps(prop->expr);
818 if (sym2) 1043 if (sym2)
819 break; 1044 break;
1045 stack.expr = NULL;
820 } 1046 }
821 1047
1048out:
1049 dep_stack_remove();
1050
822 return sym2; 1051 return sym2;
823} 1052}
824 1053
@@ -827,6 +1056,9 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
827 struct symbol *sym, *sym2; 1056 struct symbol *sym, *sym2;
828 struct property *prop; 1057 struct property *prop;
829 struct expr *e; 1058 struct expr *e;
1059 struct dep_stack stack;
1060
1061 dep_stack_insert(&stack, choice);
830 1062
831 prop = sym_get_choice_prop(choice); 1063 prop = sym_get_choice_prop(choice);
832 expr_list_for_each_sym(prop->expr, e, sym) 1064 expr_list_for_each_sym(prop->expr, e, sym)
@@ -840,10 +1072,8 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
840 1072
841 expr_list_for_each_sym(prop->expr, e, sym) { 1073 expr_list_for_each_sym(prop->expr, e, sym) {
842 sym2 = sym_check_sym_deps(sym); 1074 sym2 = sym_check_sym_deps(sym);
843 if (sym2) { 1075 if (sym2)
844 fprintf(stderr, " -> %s", sym->name);
845 break; 1076 break;
846 }
847 } 1077 }
848out: 1078out:
849 expr_list_for_each_sym(prop->expr, e, sym) 1079 expr_list_for_each_sym(prop->expr, e, sym)
@@ -853,6 +1083,8 @@ out:
853 prop_get_symbol(sym_get_choice_prop(sym2)) == choice) 1083 prop_get_symbol(sym_get_choice_prop(sym2)) == choice)
854 sym2 = choice; 1084 sym2 = choice;
855 1085
1086 dep_stack_remove();
1087
856 return sym2; 1088 return sym2;
857} 1089}
858 1090
@@ -862,18 +1094,20 @@ struct symbol *sym_check_deps(struct symbol *sym)
862 struct property *prop; 1094 struct property *prop;
863 1095
864 if (sym->flags & SYMBOL_CHECK) { 1096 if (sym->flags & SYMBOL_CHECK) {
865 fprintf(stderr, "%s:%d:error: found recursive dependency: %s", 1097 sym_check_print_recursive(sym);
866 sym->prop->file->name, sym->prop->lineno,
867 sym->name ? sym->name : "<choice>");
868 return sym; 1098 return sym;
869 } 1099 }
870 if (sym->flags & SYMBOL_CHECKED) 1100 if (sym->flags & SYMBOL_CHECKED)
871 return NULL; 1101 return NULL;
872 1102
873 if (sym_is_choice_value(sym)) { 1103 if (sym_is_choice_value(sym)) {
1104 struct dep_stack stack;
1105
874 /* for choice groups start the check with main choice symbol */ 1106 /* for choice groups start the check with main choice symbol */
1107 dep_stack_insert(&stack, sym);
875 prop = sym_get_choice_prop(sym); 1108 prop = sym_get_choice_prop(sym);
876 sym2 = sym_check_deps(prop_get_symbol(prop)); 1109 sym2 = sym_check_deps(prop_get_symbol(prop));
1110 dep_stack_remove();
877 } else if (sym_is_choice(sym)) { 1111 } else if (sym_is_choice(sym)) {
878 sym2 = sym_check_choice_deps(sym); 1112 sym2 = sym_check_choice_deps(sym);
879 } else { 1113 } else {
@@ -882,14 +1116,8 @@ struct symbol *sym_check_deps(struct symbol *sym)
882 sym->flags &= ~SYMBOL_CHECK; 1116 sym->flags &= ~SYMBOL_CHECK;
883 } 1117 }
884 1118
885 if (sym2) { 1119 if (sym2 && sym2 == sym)
886 fprintf(stderr, " -> %s", sym->name ? sym->name : "<choice>"); 1120 sym2 = NULL;
887 if (sym2 == sym) {
888 fprintf(stderr, "\n");
889 zconfnerrs++;
890 sym2 = NULL;
891 }
892 }
893 1121
894 return sym2; 1122 return sym2;
895} 1123}
@@ -943,6 +1171,8 @@ const char *prop_get_type_name(enum prop_type type)
943 return "select"; 1171 return "select";
944 case P_RANGE: 1172 case P_RANGE:
945 return "range"; 1173 return "range";
1174 case P_SYMBOL:
1175 return "symbol";
946 case P_UNKNOWN: 1176 case P_UNKNOWN:
947 break; 1177 break;
948 } 1178 }