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