Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 6 | #include <sys/types.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 7 | #include <ctype.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | #include <regex.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 11 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 12 | #include "lkc.h" |
| 13 | |
| 14 | struct symbol symbol_yes = { |
| 15 | .name = "y", |
| 16 | .curr = { "y", yes }, |
| 17 | .flags = SYMBOL_CONST|SYMBOL_VALID, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | struct symbol symbol_mod = { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 21 | .name = "m", |
| 22 | .curr = { "m", mod }, |
| 23 | .flags = SYMBOL_CONST|SYMBOL_VALID, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | struct symbol symbol_no = { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 27 | .name = "n", |
| 28 | .curr = { "n", no }, |
| 29 | .flags = SYMBOL_CONST|SYMBOL_VALID, |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | static struct symbol symbol_empty = { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 33 | .name = "", |
| 34 | .curr = { "", no }, |
| 35 | .flags = SYMBOL_VALID, |
| 36 | }; |
| 37 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 38 | struct symbol *modules_sym; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 39 | static tristate modules_val; |
Patrick Georgi | 0eab62b | 2023-11-20 19:49:29 +0100 | [diff] [blame] | 40 | static int sym_warnings; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 41 | |
| 42 | enum symbol_type sym_get_type(struct symbol *sym) |
| 43 | { |
| 44 | enum symbol_type type = sym->type; |
| 45 | |
| 46 | if (type == S_TRISTATE) { |
| 47 | if (sym_is_choice_value(sym) && sym->visible == yes) |
| 48 | type = S_BOOLEAN; |
| 49 | else if (modules_val == no) |
| 50 | type = S_BOOLEAN; |
| 51 | } |
| 52 | return type; |
| 53 | } |
| 54 | |
| 55 | const char *sym_type_name(enum symbol_type type) |
| 56 | { |
| 57 | switch (type) { |
| 58 | case S_BOOLEAN: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 59 | return "bool"; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 60 | case S_TRISTATE: |
| 61 | return "tristate"; |
| 62 | case S_INT: |
| 63 | return "integer"; |
| 64 | case S_HEX: |
| 65 | return "hex"; |
| 66 | case S_STRING: |
| 67 | return "string"; |
| 68 | case S_UNKNOWN: |
| 69 | return "unknown"; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 70 | } |
| 71 | return "???"; |
| 72 | } |
| 73 | |
| 74 | struct property *sym_get_choice_prop(struct symbol *sym) |
| 75 | { |
| 76 | struct property *prop; |
| 77 | |
| 78 | for_all_choices(sym, prop) |
| 79 | return prop; |
| 80 | return NULL; |
| 81 | } |
| 82 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 83 | static struct property *sym_get_default_prop(struct symbol *sym) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 84 | { |
| 85 | struct property *prop; |
| 86 | |
| 87 | for_all_defaults(sym, prop) { |
| 88 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
| 89 | if (prop->visible.tri != no) |
| 90 | return prop; |
| 91 | } |
| 92 | return NULL; |
| 93 | } |
| 94 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 95 | struct property *sym_get_range_prop(struct symbol *sym) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 96 | { |
| 97 | struct property *prop; |
| 98 | |
| 99 | for_all_properties(sym, prop, P_RANGE) { |
| 100 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
| 101 | if (prop->visible.tri != no) |
| 102 | return prop; |
| 103 | } |
| 104 | return NULL; |
| 105 | } |
| 106 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 107 | static long long sym_get_range_val(struct symbol *sym, int base) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 108 | { |
| 109 | sym_calc_value(sym); |
| 110 | switch (sym->type) { |
| 111 | case S_INT: |
| 112 | base = 10; |
| 113 | break; |
| 114 | case S_HEX: |
| 115 | base = 16; |
| 116 | break; |
| 117 | default: |
| 118 | break; |
| 119 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 120 | return strtoll(sym->curr.val, NULL, base); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void sym_validate_range(struct symbol *sym) |
| 124 | { |
| 125 | struct property *prop; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 126 | int base; |
| 127 | long long val, val2; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 128 | char str[64]; |
| 129 | |
| 130 | switch (sym->type) { |
| 131 | case S_INT: |
| 132 | base = 10; |
| 133 | break; |
| 134 | case S_HEX: |
| 135 | base = 16; |
| 136 | break; |
| 137 | default: |
| 138 | return; |
| 139 | } |
| 140 | prop = sym_get_range_prop(sym); |
| 141 | if (!prop) |
| 142 | return; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 143 | val = strtoll(sym->curr.val, NULL, base); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 144 | val2 = sym_get_range_val(prop->expr->left.sym, base); |
| 145 | if (val >= val2) { |
| 146 | val2 = sym_get_range_val(prop->expr->right.sym, base); |
| 147 | if (val <= val2) |
| 148 | return; |
| 149 | } |
| 150 | if (sym->type == S_INT) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 151 | sprintf(str, "%lld", val2); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 152 | else |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 153 | sprintf(str, "0x%llx", val2); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 154 | sym->curr.val = xstrdup(str); |
| 155 | } |
| 156 | |
| 157 | static void sym_set_changed(struct symbol *sym) |
| 158 | { |
| 159 | struct property *prop; |
| 160 | |
| 161 | sym->flags |= SYMBOL_CHANGED; |
| 162 | for (prop = sym->prop; prop; prop = prop->next) { |
| 163 | if (prop->menu) |
| 164 | prop->menu->flags |= MENU_CHANGED; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | static void sym_set_all_changed(void) |
| 169 | { |
| 170 | struct symbol *sym; |
| 171 | int i; |
| 172 | |
| 173 | for_all_symbols(i, sym) |
| 174 | sym_set_changed(sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void sym_calc_visibility(struct symbol *sym) |
| 178 | { |
| 179 | struct property *prop; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 180 | struct symbol *choice_sym = NULL; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 181 | tristate tri; |
| 182 | |
| 183 | /* any prompt visible? */ |
| 184 | tri = no; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 185 | |
| 186 | if (sym_is_choice_value(sym)) |
| 187 | choice_sym = prop_get_symbol(sym_get_choice_prop(sym)); |
| 188 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 189 | for_all_prompts(sym, prop) { |
| 190 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 191 | /* |
| 192 | * Tristate choice_values with visibility 'mod' are |
| 193 | * not visible if the corresponding choice's value is |
| 194 | * 'yes'. |
| 195 | */ |
| 196 | if (choice_sym && sym->type == S_TRISTATE && |
| 197 | prop->visible.tri == mod && choice_sym->curr.tri == yes) |
| 198 | prop->visible.tri = no; |
| 199 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 200 | tri = EXPR_OR(tri, prop->visible.tri); |
| 201 | } |
| 202 | if (tri == mod && (sym->type != S_TRISTATE || modules_val == no)) |
| 203 | tri = yes; |
| 204 | if (sym->visible != tri) { |
| 205 | sym->visible = tri; |
| 206 | sym_set_changed(sym); |
| 207 | } |
| 208 | if (sym_is_choice_value(sym)) |
| 209 | return; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 210 | /* defaulting to "yes" if no explicit "depends on" are given */ |
| 211 | tri = yes; |
| 212 | if (sym->dir_dep.expr) |
| 213 | tri = expr_calc_value(sym->dir_dep.expr); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 214 | if (tri == mod && sym_get_type(sym) == S_BOOLEAN) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 215 | tri = yes; |
| 216 | if (sym->dir_dep.tri != tri) { |
| 217 | sym->dir_dep.tri = tri; |
| 218 | sym_set_changed(sym); |
| 219 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 220 | tri = no; |
| 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) |
| 224 | tri = yes; |
| 225 | if (sym->rev_dep.tri != tri) { |
| 226 | sym->rev_dep.tri = tri; |
| 227 | sym_set_changed(sym); |
| 228 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 229 | tri = no; |
| 230 | if (sym->implied.expr) |
| 231 | tri = expr_calc_value(sym->implied.expr); |
| 232 | if (tri == mod && sym_get_type(sym) == S_BOOLEAN) |
| 233 | tri = yes; |
| 234 | if (sym->implied.tri != tri) { |
| 235 | sym->implied.tri = tri; |
| 236 | sym_set_changed(sym); |
| 237 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 240 | /* |
| 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 |
| 245 | */ |
| 246 | struct symbol *sym_choice_default(struct symbol *sym) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 247 | { |
| 248 | struct symbol *def_sym; |
| 249 | struct property *prop; |
| 250 | struct expr *e; |
| 251 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 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) |
| 256 | continue; |
| 257 | def_sym = prop_get_symbol(prop); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 258 | if (def_sym->visible != no) |
| 259 | return def_sym; |
| 260 | } |
| 261 | |
| 262 | /* just get the first visible value */ |
| 263 | prop = sym_get_choice_prop(sym); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 264 | expr_list_for_each_sym(prop->expr, e, def_sym) |
| 265 | if (def_sym->visible != no) |
| 266 | return def_sym; |
| 267 | |
| 268 | /* failed to locate any defaults */ |
| 269 | return NULL; |
| 270 | } |
| 271 | |
| 272 | static struct symbol *sym_calc_choice(struct symbol *sym) |
| 273 | { |
| 274 | struct symbol *def_sym; |
| 275 | struct property *prop; |
| 276 | struct expr *e; |
| 277 | int flags; |
| 278 | |
| 279 | /* first calculate all choice values' visibilities */ |
| 280 | flags = sym->flags; |
| 281 | prop = sym_get_choice_prop(sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 282 | expr_list_for_each_sym(prop->expr, e, def_sym) { |
| 283 | sym_calc_visibility(def_sym); |
| 284 | if (def_sym->visible != no) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 285 | flags &= def_sym->flags; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 288 | sym->flags &= flags | ~SYMBOL_DEF_USER; |
| 289 | |
| 290 | /* is the user choice visible? */ |
| 291 | def_sym = sym->def[S_DEF_USER].val; |
| 292 | if (def_sym && def_sym->visible != no) |
| 293 | return def_sym; |
| 294 | |
| 295 | def_sym = sym_choice_default(sym); |
| 296 | |
| 297 | if (def_sym == NULL) |
| 298 | /* no choice? reset tristate value */ |
| 299 | sym->curr.tri = no; |
| 300 | |
| 301 | return def_sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 304 | static void sym_warn_unmet_dep(struct symbol *sym) |
| 305 | { |
| 306 | struct gstr gs = str_new(); |
| 307 | |
| 308 | str_printf(&gs, |
| 309 | "\nWARNING: unmet direct dependencies detected for %s\n", |
| 310 | sym->name); |
| 311 | str_printf(&gs, |
| 312 | " Depends on [%c]: ", |
| 313 | sym->dir_dep.tri == mod ? 'm' : 'n'); |
| 314 | expr_gstr_print(sym->dir_dep.expr, &gs); |
| 315 | str_printf(&gs, "\n"); |
| 316 | |
| 317 | expr_gstr_print_revdep(sym->rev_dep.expr, &gs, yes, |
| 318 | " Selected by [y]:\n"); |
| 319 | expr_gstr_print_revdep(sym->rev_dep.expr, &gs, mod, |
| 320 | " Selected by [m]:\n"); |
| 321 | |
| 322 | fputs(str_get(&gs), stderr); |
Patrick Georgi | 0eab62b | 2023-11-20 19:49:29 +0100 | [diff] [blame] | 323 | sym_warnings++; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 326 | void sym_calc_value(struct symbol *sym) |
| 327 | { |
| 328 | struct symbol_value newval, oldval; |
| 329 | struct property *prop; |
Patrick Georgi | 0eab62b | 2023-11-20 19:49:29 +0100 | [diff] [blame] | 330 | const char *werror; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 331 | struct expr *e; |
| 332 | |
| 333 | if (!sym) |
| 334 | return; |
| 335 | |
| 336 | if (sym->flags & SYMBOL_VALID) |
| 337 | return; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 338 | |
| 339 | if (sym_is_choice_value(sym) && |
| 340 | sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES) { |
| 341 | sym->flags &= ~SYMBOL_NEED_SET_CHOICE_VALUES; |
| 342 | prop = sym_get_choice_prop(sym); |
| 343 | sym_calc_value(prop_get_symbol(prop)); |
| 344 | } |
| 345 | |
Patrick Georgi | 0eab62b | 2023-11-20 19:49:29 +0100 | [diff] [blame] | 346 | werror = getenv("KCONFIG_WERROR"); |
| 347 | sym_warnings = 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 348 | sym->flags |= SYMBOL_VALID; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 349 | oldval = sym->curr; |
| 350 | |
| 351 | switch (sym->type) { |
| 352 | case S_INT: |
| 353 | case S_HEX: |
| 354 | case S_STRING: |
| 355 | newval = symbol_empty.curr; |
| 356 | break; |
| 357 | case S_BOOLEAN: |
| 358 | case S_TRISTATE: |
| 359 | newval = symbol_no.curr; |
| 360 | break; |
| 361 | default: |
| 362 | sym->curr.val = sym->name; |
| 363 | sym->curr.tri = no; |
| 364 | return; |
| 365 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 366 | sym->flags &= ~SYMBOL_WRITE; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 367 | |
| 368 | sym_calc_visibility(sym); |
| 369 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 370 | if (sym->visible != no) |
| 371 | sym->flags |= SYMBOL_WRITE; |
| 372 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 373 | /* set default if recursively called */ |
| 374 | sym->curr = newval; |
| 375 | |
| 376 | switch (sym_get_type(sym)) { |
| 377 | case S_BOOLEAN: |
| 378 | case S_TRISTATE: |
| 379 | if (sym_is_choice_value(sym) && sym->visible == yes) { |
| 380 | prop = sym_get_choice_prop(sym); |
| 381 | newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no; |
| 382 | } else { |
| 383 | if (sym->visible != no) { |
| 384 | /* if the symbol is visible use the user value |
| 385 | * if available, otherwise try the default value |
| 386 | */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 387 | if (sym_has_value(sym)) { |
| 388 | newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri, |
| 389 | sym->visible); |
| 390 | goto calc_newval; |
| 391 | } |
| 392 | } |
| 393 | if (sym->rev_dep.tri != no) |
| 394 | sym->flags |= SYMBOL_WRITE; |
| 395 | if (!sym_is_choice(sym)) { |
| 396 | prop = sym_get_default_prop(sym); |
| 397 | if (prop) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 398 | newval.tri = EXPR_AND(expr_calc_value(prop->expr), |
| 399 | prop->visible.tri); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 400 | if (newval.tri != no) |
| 401 | sym->flags |= SYMBOL_WRITE; |
| 402 | } |
| 403 | if (sym->implied.tri != no) { |
| 404 | sym->flags |= SYMBOL_WRITE; |
| 405 | newval.tri = EXPR_OR(newval.tri, sym->implied.tri); |
| 406 | newval.tri = EXPR_AND(newval.tri, |
| 407 | sym->dir_dep.tri); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | calc_newval: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 411 | if (sym->dir_dep.tri < sym->rev_dep.tri) |
| 412 | sym_warn_unmet_dep(sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 413 | newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); |
| 414 | } |
| 415 | if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN) |
| 416 | newval.tri = yes; |
| 417 | break; |
| 418 | case S_STRING: |
| 419 | case S_HEX: |
| 420 | case S_INT: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 421 | if (sym->visible != no && sym_has_value(sym)) { |
| 422 | newval.val = sym->def[S_DEF_USER].val; |
| 423 | break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 424 | } |
| 425 | prop = sym_get_default_prop(sym); |
| 426 | if (prop) { |
| 427 | struct symbol *ds = prop_get_symbol(prop); |
| 428 | if (ds) { |
| 429 | sym->flags |= SYMBOL_WRITE; |
| 430 | sym_calc_value(ds); |
| 431 | newval.val = ds->curr.val; |
| 432 | } |
| 433 | } |
| 434 | break; |
| 435 | default: |
| 436 | ; |
| 437 | } |
| 438 | |
Patrick Georgi | 0eab62b | 2023-11-20 19:49:29 +0100 | [diff] [blame] | 439 | if (sym_warnings && werror) |
| 440 | exit(1); |
| 441 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 442 | sym->curr = newval; |
| 443 | if (sym_is_choice(sym) && newval.tri == yes) |
| 444 | sym->curr.val = sym_calc_choice(sym); |
| 445 | sym_validate_range(sym); |
| 446 | |
| 447 | if (memcmp(&oldval, &sym->curr, sizeof(oldval))) { |
| 448 | sym_set_changed(sym); |
| 449 | if (modules_sym == sym) { |
| 450 | sym_set_all_changed(); |
| 451 | modules_val = modules_sym->curr.tri; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | if (sym_is_choice(sym)) { |
| 456 | struct symbol *choice_sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 457 | |
| 458 | prop = sym_get_choice_prop(sym); |
| 459 | expr_list_for_each_sym(prop->expr, e, choice_sym) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 460 | if ((sym->flags & SYMBOL_WRITE) && |
| 461 | choice_sym->visible != no) |
| 462 | choice_sym->flags |= SYMBOL_WRITE; |
| 463 | if (sym->flags & SYMBOL_CHANGED) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 464 | sym_set_changed(choice_sym); |
| 465 | } |
| 466 | } |
Roman Zippel | 543aa7b | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 467 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 468 | if (sym->flags & SYMBOL_NO_WRITE) |
Roman Zippel | 543aa7b | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 469 | sym->flags &= ~SYMBOL_WRITE; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 470 | |
| 471 | if (sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES) |
| 472 | set_all_choice_values(sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | void sym_clear_all_valid(void) |
| 476 | { |
| 477 | struct symbol *sym; |
| 478 | int i; |
| 479 | |
| 480 | for_all_symbols(i, sym) |
| 481 | sym->flags &= ~SYMBOL_VALID; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 482 | conf_set_changed(true); |
| 483 | sym_calc_value(modules_sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | bool sym_tristate_within_range(struct symbol *sym, tristate val) |
| 487 | { |
| 488 | int type = sym_get_type(sym); |
| 489 | |
| 490 | if (sym->visible == no) |
| 491 | return false; |
| 492 | |
| 493 | if (type != S_BOOLEAN && type != S_TRISTATE) |
| 494 | return false; |
| 495 | |
| 496 | if (type == S_BOOLEAN && val == mod) |
| 497 | return false; |
| 498 | if (sym->visible <= sym->rev_dep.tri) |
| 499 | return false; |
| 500 | if (sym_is_choice_value(sym) && sym->visible == yes) |
| 501 | return val == yes; |
| 502 | return val >= sym->rev_dep.tri && val <= sym->visible; |
| 503 | } |
| 504 | |
| 505 | bool sym_set_tristate_value(struct symbol *sym, tristate val) |
| 506 | { |
| 507 | tristate oldval = sym_get_tristate_value(sym); |
| 508 | |
| 509 | if (oldval != val && !sym_tristate_within_range(sym, val)) |
| 510 | return false; |
| 511 | |
| 512 | if (!(sym->flags & SYMBOL_DEF_USER)) { |
| 513 | sym->flags |= SYMBOL_DEF_USER; |
| 514 | sym_set_changed(sym); |
| 515 | } |
| 516 | /* |
| 517 | * setting a choice value also resets the new flag of the choice |
| 518 | * symbol and all other choice values. |
| 519 | */ |
| 520 | if (sym_is_choice_value(sym) && val == yes) { |
| 521 | struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); |
| 522 | struct property *prop; |
| 523 | struct expr *e; |
| 524 | |
| 525 | cs->def[S_DEF_USER].val = sym; |
| 526 | cs->flags |= SYMBOL_DEF_USER; |
| 527 | prop = sym_get_choice_prop(cs); |
| 528 | for (e = prop->expr; e; e = e->left.expr) { |
| 529 | if (e->right.sym->visible != no) |
| 530 | e->right.sym->flags |= SYMBOL_DEF_USER; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | sym->def[S_DEF_USER].tri = val; |
| 535 | if (oldval != val) |
| 536 | sym_clear_all_valid(); |
| 537 | |
| 538 | return true; |
| 539 | } |
| 540 | |
| 541 | tristate sym_toggle_tristate_value(struct symbol *sym) |
| 542 | { |
| 543 | tristate oldval, newval; |
| 544 | |
| 545 | oldval = newval = sym_get_tristate_value(sym); |
| 546 | do { |
| 547 | switch (newval) { |
| 548 | case no: |
| 549 | newval = mod; |
| 550 | break; |
| 551 | case mod: |
| 552 | newval = yes; |
| 553 | break; |
| 554 | case yes: |
| 555 | newval = no; |
| 556 | break; |
| 557 | } |
| 558 | if (sym_set_tristate_value(sym, newval)) |
| 559 | break; |
| 560 | } while (oldval != newval); |
| 561 | return newval; |
| 562 | } |
| 563 | |
| 564 | bool sym_string_valid(struct symbol *sym, const char *str) |
| 565 | { |
| 566 | signed char ch; |
| 567 | |
| 568 | switch (sym->type) { |
| 569 | case S_STRING: |
| 570 | return true; |
| 571 | case S_INT: |
| 572 | ch = *str++; |
| 573 | if (ch == '-') |
| 574 | ch = *str++; |
| 575 | if (!isdigit(ch)) |
| 576 | return false; |
| 577 | if (ch == '0' && *str != 0) |
| 578 | return false; |
| 579 | while ((ch = *str++)) { |
| 580 | if (!isdigit(ch)) |
| 581 | return false; |
| 582 | } |
| 583 | return true; |
| 584 | case S_HEX: |
| 585 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) |
| 586 | str += 2; |
| 587 | ch = *str++; |
| 588 | do { |
| 589 | if (!isxdigit(ch)) |
| 590 | return false; |
| 591 | } while ((ch = *str++)); |
| 592 | return true; |
| 593 | case S_BOOLEAN: |
| 594 | case S_TRISTATE: |
| 595 | switch (str[0]) { |
| 596 | case 'y': case 'Y': |
| 597 | case 'm': case 'M': |
| 598 | case 'n': case 'N': |
| 599 | return true; |
| 600 | } |
| 601 | return false; |
| 602 | default: |
| 603 | return false; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | bool sym_string_within_range(struct symbol *sym, const char *str) |
| 608 | { |
| 609 | struct property *prop; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 610 | long long val; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 611 | |
| 612 | switch (sym->type) { |
| 613 | case S_STRING: |
| 614 | return sym_string_valid(sym, str); |
| 615 | case S_INT: |
| 616 | if (!sym_string_valid(sym, str)) |
| 617 | return false; |
| 618 | prop = sym_get_range_prop(sym); |
| 619 | if (!prop) |
| 620 | return true; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 621 | val = strtoll(str, NULL, 10); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 622 | return val >= sym_get_range_val(prop->expr->left.sym, 10) && |
| 623 | val <= sym_get_range_val(prop->expr->right.sym, 10); |
| 624 | case S_HEX: |
| 625 | if (!sym_string_valid(sym, str)) |
| 626 | return false; |
| 627 | prop = sym_get_range_prop(sym); |
| 628 | if (!prop) |
| 629 | return true; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 630 | val = strtoll(str, NULL, 16); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 631 | return val >= sym_get_range_val(prop->expr->left.sym, 16) && |
| 632 | val <= sym_get_range_val(prop->expr->right.sym, 16); |
| 633 | case S_BOOLEAN: |
| 634 | case S_TRISTATE: |
| 635 | switch (str[0]) { |
| 636 | case 'y': case 'Y': |
| 637 | return sym_tristate_within_range(sym, yes); |
| 638 | case 'm': case 'M': |
| 639 | return sym_tristate_within_range(sym, mod); |
| 640 | case 'n': case 'N': |
| 641 | return sym_tristate_within_range(sym, no); |
| 642 | } |
| 643 | return false; |
| 644 | default: |
| 645 | return false; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | bool sym_set_string_value(struct symbol *sym, const char *newval) |
| 650 | { |
| 651 | const char *oldval; |
| 652 | char *val; |
| 653 | int size; |
| 654 | |
| 655 | switch (sym->type) { |
| 656 | case S_BOOLEAN: |
| 657 | case S_TRISTATE: |
| 658 | switch (newval[0]) { |
| 659 | case 'y': case 'Y': |
| 660 | return sym_set_tristate_value(sym, yes); |
| 661 | case 'm': case 'M': |
| 662 | return sym_set_tristate_value(sym, mod); |
| 663 | case 'n': case 'N': |
| 664 | return sym_set_tristate_value(sym, no); |
| 665 | } |
| 666 | return false; |
| 667 | default: |
| 668 | ; |
| 669 | } |
| 670 | |
| 671 | if (!sym_string_within_range(sym, newval)) |
| 672 | return false; |
| 673 | |
| 674 | if (!(sym->flags & SYMBOL_DEF_USER)) { |
| 675 | sym->flags |= SYMBOL_DEF_USER; |
| 676 | sym_set_changed(sym); |
| 677 | } |
| 678 | |
| 679 | oldval = sym->def[S_DEF_USER].val; |
| 680 | size = strlen(newval) + 1; |
| 681 | if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) { |
| 682 | size += 2; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 683 | sym->def[S_DEF_USER].val = val = xmalloc(size); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 684 | *val++ = '0'; |
| 685 | *val++ = 'x'; |
| 686 | } else if (!oldval || strcmp(oldval, newval)) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 687 | sym->def[S_DEF_USER].val = val = xmalloc(size); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 688 | else |
| 689 | return true; |
| 690 | |
| 691 | strcpy(val, newval); |
| 692 | free((void *)oldval); |
| 693 | sym_clear_all_valid(); |
| 694 | |
| 695 | return true; |
| 696 | } |
| 697 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 698 | /* |
| 699 | * Find the default value associated to a symbol. |
| 700 | * For tristate symbol handle the modules=n case |
| 701 | * in which case "m" becomes "y". |
| 702 | * If the symbol does not have any default then fallback |
| 703 | * to the fixed default values. |
| 704 | */ |
| 705 | const char *sym_get_string_default(struct symbol *sym) |
| 706 | { |
| 707 | struct property *prop; |
| 708 | struct symbol *ds; |
| 709 | const char *str; |
| 710 | tristate val; |
| 711 | |
| 712 | sym_calc_visibility(sym); |
| 713 | sym_calc_value(modules_sym); |
| 714 | val = symbol_no.curr.tri; |
| 715 | str = symbol_empty.curr.val; |
| 716 | |
| 717 | /* If symbol has a default value look it up */ |
| 718 | prop = sym_get_default_prop(sym); |
| 719 | if (prop != NULL) { |
| 720 | switch (sym->type) { |
| 721 | case S_BOOLEAN: |
| 722 | case S_TRISTATE: |
| 723 | /* The visibility may limit the value from yes => mod */ |
| 724 | val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri); |
| 725 | break; |
| 726 | default: |
| 727 | /* |
| 728 | * The following fails to handle the situation |
| 729 | * where a default value is further limited by |
| 730 | * the valid range. |
| 731 | */ |
| 732 | ds = prop_get_symbol(prop); |
| 733 | if (ds != NULL) { |
| 734 | sym_calc_value(ds); |
| 735 | str = (const char *)ds->curr.val; |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | /* Handle select statements */ |
| 741 | val = EXPR_OR(val, sym->rev_dep.tri); |
| 742 | |
| 743 | /* transpose mod to yes if modules are not enabled */ |
| 744 | if (val == mod) |
| 745 | if (!sym_is_choice_value(sym) && modules_sym->curr.tri == no) |
| 746 | val = yes; |
| 747 | |
| 748 | /* transpose mod to yes if type is bool */ |
| 749 | if (sym->type == S_BOOLEAN && val == mod) |
| 750 | val = yes; |
| 751 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 752 | /* adjust the default value if this symbol is implied by another */ |
| 753 | if (val < sym->implied.tri) |
| 754 | val = sym->implied.tri; |
| 755 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 756 | switch (sym->type) { |
| 757 | case S_BOOLEAN: |
| 758 | case S_TRISTATE: |
| 759 | switch (val) { |
| 760 | case no: return "n"; |
| 761 | case mod: return "m"; |
| 762 | case yes: return "y"; |
| 763 | } |
| 764 | case S_INT: |
| 765 | case S_HEX: |
Krystian Hebel | 9ab3a1f | 2023-01-31 12:54:24 +0100 | [diff] [blame] | 766 | return str; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 767 | case S_STRING: |
| 768 | return str; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 769 | case S_UNKNOWN: |
| 770 | break; |
| 771 | } |
| 772 | return ""; |
| 773 | } |
| 774 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 775 | const char *sym_get_string_value(struct symbol *sym) |
| 776 | { |
| 777 | tristate val; |
| 778 | |
| 779 | switch (sym->type) { |
| 780 | case S_BOOLEAN: |
| 781 | case S_TRISTATE: |
| 782 | val = sym_get_tristate_value(sym); |
| 783 | switch (val) { |
| 784 | case no: |
| 785 | return "n"; |
| 786 | case mod: |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 787 | sym_calc_value(modules_sym); |
| 788 | return (modules_sym->curr.tri == no) ? "n" : "m"; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 789 | case yes: |
| 790 | return "y"; |
| 791 | } |
| 792 | break; |
| 793 | default: |
| 794 | ; |
| 795 | } |
| 796 | return (const char *)sym->curr.val; |
| 797 | } |
| 798 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 799 | bool sym_is_changeable(struct symbol *sym) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 800 | { |
| 801 | return sym->visible > sym->rev_dep.tri; |
| 802 | } |
| 803 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 804 | static unsigned strhash(const char *s) |
| 805 | { |
| 806 | /* fnv32 hash */ |
| 807 | unsigned hash = 2166136261U; |
| 808 | for (; *s; s++) |
| 809 | hash = (hash ^ *s) * 0x01000193; |
| 810 | return hash; |
| 811 | } |
| 812 | |
Roman Zippel | 543aa7b | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 813 | struct symbol *sym_lookup(const char *name, int flags) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 814 | { |
| 815 | struct symbol *symbol; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 816 | char *new_name; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 817 | int hash; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 818 | |
| 819 | if (name) { |
| 820 | if (name[0] && !name[1]) { |
| 821 | switch (name[0]) { |
| 822 | case 'y': return &symbol_yes; |
| 823 | case 'm': return &symbol_mod; |
| 824 | case 'n': return &symbol_no; |
| 825 | } |
| 826 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 827 | hash = strhash(name) % SYMBOL_HASHSIZE; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 828 | |
| 829 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 830 | if (symbol->name && |
| 831 | !strcmp(symbol->name, name) && |
Roman Zippel | 543aa7b | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 832 | (flags ? symbol->flags & flags |
| 833 | : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) |
| 834 | return symbol; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 835 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 836 | new_name = xstrdup(name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 837 | } else { |
| 838 | new_name = NULL; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 839 | hash = 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 842 | symbol = xmalloc(sizeof(*symbol)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 843 | memset(symbol, 0, sizeof(*symbol)); |
| 844 | symbol->name = new_name; |
| 845 | symbol->type = S_UNKNOWN; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 846 | symbol->flags = flags; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 847 | |
| 848 | symbol->next = symbol_hash[hash]; |
| 849 | symbol_hash[hash] = symbol; |
| 850 | |
| 851 | return symbol; |
| 852 | } |
| 853 | |
| 854 | struct symbol *sym_find(const char *name) |
| 855 | { |
| 856 | struct symbol *symbol = NULL; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 857 | int hash = 0; |
| 858 | |
| 859 | if (!name) |
| 860 | return NULL; |
| 861 | |
| 862 | if (name[0] && !name[1]) { |
| 863 | switch (name[0]) { |
| 864 | case 'y': return &symbol_yes; |
| 865 | case 'm': return &symbol_mod; |
| 866 | case 'n': return &symbol_no; |
| 867 | } |
| 868 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 869 | hash = strhash(name) % SYMBOL_HASHSIZE; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 870 | |
| 871 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 872 | if (symbol->name && |
| 873 | !strcmp(symbol->name, name) && |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 874 | !(symbol->flags & SYMBOL_CONST)) |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | return symbol; |
| 879 | } |
| 880 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 881 | struct sym_match { |
| 882 | struct symbol *sym; |
| 883 | off_t so, eo; |
| 884 | }; |
| 885 | |
| 886 | /* Compare matched symbols as thus: |
| 887 | * - first, symbols that match exactly |
| 888 | * - then, alphabetical sort |
| 889 | */ |
| 890 | static int sym_rel_comp(const void *sym1, const void *sym2) |
| 891 | { |
| 892 | const struct sym_match *s1 = sym1; |
| 893 | const struct sym_match *s2 = sym2; |
| 894 | int exact1, exact2; |
| 895 | |
| 896 | /* Exact match: |
| 897 | * - if matched length on symbol s1 is the length of that symbol, |
| 898 | * then this symbol should come first; |
| 899 | * - if matched length on symbol s2 is the length of that symbol, |
| 900 | * then this symbol should come first. |
| 901 | * Note: since the search can be a regexp, both symbols may match |
| 902 | * exactly; if this is the case, we can't decide which comes first, |
| 903 | * and we fallback to sorting alphabetically. |
| 904 | */ |
| 905 | exact1 = (s1->eo - s1->so) == strlen(s1->sym->name); |
| 906 | exact2 = (s2->eo - s2->so) == strlen(s2->sym->name); |
| 907 | if (exact1 && !exact2) |
| 908 | return -1; |
| 909 | if (!exact1 && exact2) |
| 910 | return 1; |
| 911 | |
| 912 | /* As a fallback, sort symbols alphabetically */ |
| 913 | return strcmp(s1->sym->name, s2->sym->name); |
| 914 | } |
| 915 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 916 | struct symbol **sym_re_search(const char *pattern) |
| 917 | { |
| 918 | struct symbol *sym, **sym_arr = NULL; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 919 | struct sym_match *sym_match_arr = NULL; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 920 | int i, cnt, size; |
| 921 | regex_t re; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 922 | regmatch_t match[1]; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 923 | |
| 924 | cnt = size = 0; |
| 925 | /* Skip if empty */ |
| 926 | if (strlen(pattern) == 0) |
| 927 | return NULL; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 928 | if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE)) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 929 | return NULL; |
| 930 | |
| 931 | for_all_symbols(i, sym) { |
| 932 | if (sym->flags & SYMBOL_CONST || !sym->name) |
| 933 | continue; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 934 | if (regexec(&re, sym->name, 1, match, 0)) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 935 | continue; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 936 | if (cnt >= size) { |
| 937 | void *tmp; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 938 | size += 16; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 939 | tmp = realloc(sym_match_arr, size * sizeof(struct sym_match)); |
| 940 | if (!tmp) |
| 941 | goto sym_re_search_free; |
| 942 | sym_match_arr = tmp; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 943 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 944 | sym_calc_value(sym); |
| 945 | /* As regexec returned 0, we know we have a match, so |
| 946 | * we can use match[0].rm_[se]o without further checks |
| 947 | */ |
| 948 | sym_match_arr[cnt].so = match[0].rm_so; |
| 949 | sym_match_arr[cnt].eo = match[0].rm_eo; |
| 950 | sym_match_arr[cnt++].sym = sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 951 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 952 | if (sym_match_arr) { |
| 953 | qsort(sym_match_arr, cnt, sizeof(struct sym_match), sym_rel_comp); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 954 | sym_arr = malloc((cnt+1) * sizeof(struct symbol *)); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 955 | if (!sym_arr) |
| 956 | goto sym_re_search_free; |
| 957 | for (i = 0; i < cnt; i++) |
| 958 | sym_arr[i] = sym_match_arr[i].sym; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 959 | sym_arr[cnt] = NULL; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 960 | } |
| 961 | sym_re_search_free: |
| 962 | /* sym_match_arr can be NULL if no match, but free(NULL) is OK */ |
| 963 | free(sym_match_arr); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 964 | regfree(&re); |
| 965 | |
| 966 | return sym_arr; |
| 967 | } |
| 968 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 969 | /* |
| 970 | * When we check for recursive dependencies we use a stack to save |
| 971 | * current state so we can print out relevant info to user. |
| 972 | * The entries are located on the call stack so no need to free memory. |
| 973 | * Note insert() remove() must always match to properly clear the stack. |
| 974 | */ |
| 975 | static struct dep_stack { |
| 976 | struct dep_stack *prev, *next; |
| 977 | struct symbol *sym; |
| 978 | struct property *prop; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 979 | struct expr **expr; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 980 | } *check_top; |
| 981 | |
| 982 | static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym) |
| 983 | { |
| 984 | memset(stack, 0, sizeof(*stack)); |
| 985 | if (check_top) |
| 986 | check_top->next = stack; |
| 987 | stack->prev = check_top; |
| 988 | stack->sym = sym; |
| 989 | check_top = stack; |
| 990 | } |
| 991 | |
| 992 | static void dep_stack_remove(void) |
| 993 | { |
| 994 | check_top = check_top->prev; |
| 995 | if (check_top) |
| 996 | check_top->next = NULL; |
| 997 | } |
| 998 | |
| 999 | /* |
| 1000 | * Called when we have detected a recursive dependency. |
| 1001 | * check_top point to the top of the stact so we use |
| 1002 | * the ->prev pointer to locate the bottom of the stack. |
| 1003 | */ |
| 1004 | static void sym_check_print_recursive(struct symbol *last_sym) |
| 1005 | { |
| 1006 | struct dep_stack *stack; |
| 1007 | struct symbol *sym, *next_sym; |
| 1008 | struct menu *menu = NULL; |
| 1009 | struct property *prop; |
| 1010 | struct dep_stack cv_stack; |
| 1011 | |
| 1012 | if (sym_is_choice_value(last_sym)) { |
| 1013 | dep_stack_insert(&cv_stack, last_sym); |
| 1014 | last_sym = prop_get_symbol(sym_get_choice_prop(last_sym)); |
| 1015 | } |
| 1016 | |
| 1017 | for (stack = check_top; stack != NULL; stack = stack->prev) |
| 1018 | if (stack->sym == last_sym) |
| 1019 | break; |
| 1020 | if (!stack) { |
| 1021 | fprintf(stderr, "unexpected recursive dependency error\n"); |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | for (; stack; stack = stack->next) { |
| 1026 | sym = stack->sym; |
| 1027 | next_sym = stack->next ? stack->next->sym : last_sym; |
| 1028 | prop = stack->prop; |
| 1029 | if (prop == NULL) |
| 1030 | prop = stack->sym->prop; |
| 1031 | |
| 1032 | /* for choice values find the menu entry (used below) */ |
| 1033 | if (sym_is_choice(sym) || sym_is_choice_value(sym)) { |
| 1034 | for (prop = sym->prop; prop; prop = prop->next) { |
| 1035 | menu = prop->menu; |
| 1036 | if (prop->menu) |
| 1037 | break; |
| 1038 | } |
| 1039 | } |
| 1040 | if (stack->sym == last_sym) |
| 1041 | fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", |
| 1042 | prop->file->name, prop->lineno); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1043 | |
| 1044 | if (sym_is_choice(sym)) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1045 | fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", |
| 1046 | menu->file->name, menu->lineno, |
| 1047 | sym->name ? sym->name : "<choice>", |
| 1048 | next_sym->name ? next_sym->name : "<choice>"); |
| 1049 | } else if (sym_is_choice_value(sym)) { |
| 1050 | fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", |
| 1051 | menu->file->name, menu->lineno, |
| 1052 | sym->name ? sym->name : "<choice>", |
| 1053 | next_sym->name ? next_sym->name : "<choice>"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1054 | } else if (stack->expr == &sym->dir_dep.expr) { |
| 1055 | fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", |
| 1056 | prop->file->name, prop->lineno, |
| 1057 | sym->name ? sym->name : "<choice>", |
| 1058 | next_sym->name ? next_sym->name : "<choice>"); |
| 1059 | } else if (stack->expr == &sym->rev_dep.expr) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1060 | fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", |
| 1061 | prop->file->name, prop->lineno, |
| 1062 | sym->name ? sym->name : "<choice>", |
| 1063 | next_sym->name ? next_sym->name : "<choice>"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1064 | } else if (stack->expr == &sym->implied.expr) { |
| 1065 | fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n", |
| 1066 | prop->file->name, prop->lineno, |
| 1067 | sym->name ? sym->name : "<choice>", |
| 1068 | next_sym->name ? next_sym->name : "<choice>"); |
| 1069 | } else if (stack->expr) { |
| 1070 | fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", |
| 1071 | prop->file->name, prop->lineno, |
| 1072 | sym->name ? sym->name : "<choice>", |
| 1073 | prop_get_type_name(prop->type), |
| 1074 | next_sym->name ? next_sym->name : "<choice>"); |
| 1075 | } else { |
| 1076 | fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n", |
| 1077 | prop->file->name, prop->lineno, |
| 1078 | sym->name ? sym->name : "<choice>", |
| 1079 | prop_get_type_name(prop->type), |
| 1080 | next_sym->name ? next_sym->name : "<choice>"); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1084 | fprintf(stderr, |
| 1085 | "For a resolution refer to Documentation/kbuild/kconfig-language.rst\n" |
| 1086 | "subsection \"Kconfig recursive dependency limitations\"\n" |
| 1087 | "\n"); |
| 1088 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1089 | if (check_top == &cv_stack) |
| 1090 | dep_stack_remove(); |
| 1091 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1092 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1093 | static struct symbol *sym_check_expr_deps(struct expr *e) |
| 1094 | { |
| 1095 | struct symbol *sym; |
| 1096 | |
| 1097 | if (!e) |
| 1098 | return NULL; |
| 1099 | switch (e->type) { |
| 1100 | case E_OR: |
| 1101 | case E_AND: |
| 1102 | sym = sym_check_expr_deps(e->left.expr); |
| 1103 | if (sym) |
| 1104 | return sym; |
| 1105 | return sym_check_expr_deps(e->right.expr); |
| 1106 | case E_NOT: |
| 1107 | return sym_check_expr_deps(e->left.expr); |
| 1108 | case E_EQUAL: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1109 | case E_GEQ: |
| 1110 | case E_GTH: |
| 1111 | case E_LEQ: |
| 1112 | case E_LTH: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1113 | case E_UNEQUAL: |
| 1114 | sym = sym_check_deps(e->left.sym); |
| 1115 | if (sym) |
| 1116 | return sym; |
| 1117 | return sym_check_deps(e->right.sym); |
| 1118 | case E_SYMBOL: |
| 1119 | return sym_check_deps(e->left.sym); |
| 1120 | default: |
| 1121 | break; |
| 1122 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1123 | fprintf(stderr, "Oops! How to check %d?\n", e->type); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1124 | return NULL; |
| 1125 | } |
| 1126 | |
| 1127 | /* return NULL when dependencies are OK */ |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1128 | static struct symbol *sym_check_sym_deps(struct symbol *sym) |
| 1129 | { |
| 1130 | struct symbol *sym2; |
| 1131 | struct property *prop; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1132 | struct dep_stack stack; |
| 1133 | |
| 1134 | dep_stack_insert(&stack, sym); |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1135 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1136 | stack.expr = &sym->dir_dep.expr; |
| 1137 | sym2 = sym_check_expr_deps(sym->dir_dep.expr); |
| 1138 | if (sym2) |
| 1139 | goto out; |
| 1140 | |
| 1141 | stack.expr = &sym->rev_dep.expr; |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1142 | sym2 = sym_check_expr_deps(sym->rev_dep.expr); |
| 1143 | if (sym2) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1144 | goto out; |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1145 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1146 | stack.expr = &sym->implied.expr; |
| 1147 | sym2 = sym_check_expr_deps(sym->implied.expr); |
| 1148 | if (sym2) |
| 1149 | goto out; |
| 1150 | |
| 1151 | stack.expr = NULL; |
| 1152 | |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1153 | for (prop = sym->prop; prop; prop = prop->next) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1154 | if (prop->type == P_CHOICE || prop->type == P_SELECT || |
| 1155 | prop->type == P_IMPLY) |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1156 | continue; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1157 | stack.prop = prop; |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1158 | sym2 = sym_check_expr_deps(prop->visible.expr); |
| 1159 | if (sym2) |
| 1160 | break; |
| 1161 | if (prop->type != P_DEFAULT || sym_is_choice(sym)) |
| 1162 | continue; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1163 | stack.expr = &prop->expr; |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1164 | sym2 = sym_check_expr_deps(prop->expr); |
| 1165 | if (sym2) |
| 1166 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1167 | stack.expr = NULL; |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1168 | } |
| 1169 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1170 | out: |
| 1171 | dep_stack_remove(); |
| 1172 | |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1173 | return sym2; |
| 1174 | } |
| 1175 | |
| 1176 | static struct symbol *sym_check_choice_deps(struct symbol *choice) |
| 1177 | { |
| 1178 | struct symbol *sym, *sym2; |
| 1179 | struct property *prop; |
| 1180 | struct expr *e; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1181 | struct dep_stack stack; |
| 1182 | |
| 1183 | dep_stack_insert(&stack, choice); |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1184 | |
| 1185 | prop = sym_get_choice_prop(choice); |
| 1186 | expr_list_for_each_sym(prop->expr, e, sym) |
| 1187 | sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 1188 | |
| 1189 | choice->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 1190 | sym2 = sym_check_sym_deps(choice); |
| 1191 | choice->flags &= ~SYMBOL_CHECK; |
| 1192 | if (sym2) |
| 1193 | goto out; |
| 1194 | |
| 1195 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 1196 | sym2 = sym_check_sym_deps(sym); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1197 | if (sym2) |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1198 | break; |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1199 | } |
| 1200 | out: |
| 1201 | expr_list_for_each_sym(prop->expr, e, sym) |
| 1202 | sym->flags &= ~SYMBOL_CHECK; |
| 1203 | |
| 1204 | if (sym2 && sym_is_choice_value(sym2) && |
| 1205 | prop_get_symbol(sym_get_choice_prop(sym2)) == choice) |
| 1206 | sym2 = choice; |
| 1207 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1208 | dep_stack_remove(); |
| 1209 | |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1210 | return sym2; |
| 1211 | } |
| 1212 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1213 | struct symbol *sym_check_deps(struct symbol *sym) |
| 1214 | { |
| 1215 | struct symbol *sym2; |
| 1216 | struct property *prop; |
| 1217 | |
| 1218 | if (sym->flags & SYMBOL_CHECK) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1219 | sym_check_print_recursive(sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1220 | return sym; |
| 1221 | } |
| 1222 | if (sym->flags & SYMBOL_CHECKED) |
| 1223 | return NULL; |
| 1224 | |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1225 | if (sym_is_choice_value(sym)) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1226 | struct dep_stack stack; |
| 1227 | |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1228 | /* for choice groups start the check with main choice symbol */ |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1229 | dep_stack_insert(&stack, sym); |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1230 | prop = sym_get_choice_prop(sym); |
| 1231 | sym2 = sym_check_deps(prop_get_symbol(prop)); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1232 | dep_stack_remove(); |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1233 | } else if (sym_is_choice(sym)) { |
| 1234 | sym2 = sym_check_choice_deps(sym); |
| 1235 | } else { |
| 1236 | sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 1237 | sym2 = sym_check_sym_deps(sym); |
| 1238 | sym->flags &= ~SYMBOL_CHECK; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1239 | } |
Roman Zippel | 330bb6a | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1240 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1241 | return sym2; |
| 1242 | } |
| 1243 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1244 | struct symbol *prop_get_symbol(struct property *prop) |
| 1245 | { |
| 1246 | if (prop->expr && (prop->expr->type == E_SYMBOL || |
| 1247 | prop->expr->type == E_LIST)) |
| 1248 | return prop->expr->left.sym; |
| 1249 | return NULL; |
| 1250 | } |
| 1251 | |
| 1252 | const char *prop_get_type_name(enum prop_type type) |
| 1253 | { |
| 1254 | switch (type) { |
| 1255 | case P_PROMPT: |
| 1256 | return "prompt"; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1257 | case P_COMMENT: |
| 1258 | return "comment"; |
| 1259 | case P_MENU: |
| 1260 | return "menu"; |
| 1261 | case P_DEFAULT: |
| 1262 | return "default"; |
| 1263 | case P_CHOICE: |
| 1264 | return "choice"; |
| 1265 | case P_SELECT: |
| 1266 | return "select"; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1267 | case P_IMPLY: |
| 1268 | return "imply"; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1269 | case P_RANGE: |
| 1270 | return "range"; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1271 | case P_SYMBOL: |
| 1272 | return "symbol"; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1273 | case P_UNKNOWN: |
| 1274 | break; |
| 1275 | } |
| 1276 | return "unknown"; |
| 1277 | } |