Lines Matching refs:self

867     def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,  argument
947 self._init(filename, warn, warn_to_stderr, encoding)
959 def _init(self, filename, warn, warn_to_stderr, encoding): argument
962 self._encoding = encoding
964 self.srctree = os.getenv("srctree", "")
968 self._srctree_prefix = realpath(self.srctree) + os.sep
970 self.warn = warn
971 self.warn_to_stderr = warn_to_stderr
972 self.warn_assign_undef = os.getenv("KCONFIG_WARN_UNDEF_ASSIGN") == "y"
973 self.warn_assign_override = True
974 self.warn_assign_redun = True
975 self._warn_assign_no_prompt = True
977 self.warnings = []
979 self.config_prefix = os.getenv("CONFIG_", "CONFIG_")
981 self._set_match = _re_match(self.config_prefix + r"([^=]+)=(.*)")
982 self._unset_match = _re_match(r"# {}([^ ]+) is not set".format(
983 self.config_prefix))
985 self.config_header = os.getenv("KCONFIG_CONFIG_HEADER", "")
986 self.header_header = os.getenv("KCONFIG_AUTOHEADER_HEADER", "")
988 self.syms = {}
989 self.const_syms = {}
990 self.defined_syms = []
991 self.missing_syms = []
992 self.named_choices = {}
993 self.choices = []
994 self.menus = []
995 self.comments = []
999 sym.kconfig = self
1005 self.const_syms[nmy] = sym
1007 self.n = self.const_syms["n"]
1008 self.m = self.const_syms["m"]
1009 self.y = self.const_syms["y"]
1013 sym = self.const_syms[nmy]
1014 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
1017 self.variables = {}
1020 self._functions = {
1031 self._functions.update(
1041 self._parsing_kconfigs = True
1043 self.modules = self._lookup_sym("MODULES")
1044 self.defconfig_list = None
1046 self.top_node = MenuNode()
1047 self.top_node.kconfig = self
1048 self.top_node.item = MENU
1049 self.top_node.is_menuconfig = True
1050 self.top_node.visibility = self.y
1051 self.top_node.prompt = ("Main menu", self.y)
1052 self.top_node.parent = None
1053 self.top_node.dep = self.y
1054 self.top_node.filename = filename
1055 self.top_node.linenr = 1
1056 self.top_node.include_path = ()
1061 self.kconfig_filenames = [filename]
1062 self.env_vars = set()
1066 self._filestack = []
1067 self._include_path = ()
1070 self.filename = filename
1071 self.linenr = 0
1076 self._reuse_tokens = False
1080 self._readline = self._open(join(self.srctree, filename), "r").readline
1085 self._parse_block(None, self.top_node, self.top_node).next = None
1086 self.top_node.list = self.top_node.next
1087 self.top_node.next = None
1089 _decoding_error(e, self.filename)
1093 self._readline.__self__.close()
1095 self._parsing_kconfigs = False
1098 self._finalize_node(self.top_node, self.y)
1099 for s in self.syms.values():
1100 self._finalize_sym(s)
1102 self.unique_defined_syms = _ordered_unique(self.defined_syms)
1103 self.unique_choices = _ordered_unique(self.choices)
1106 self._check_sym_sanity()
1107 self._check_choice_sanity()
1114 self._check_undef_syms()
1117 self._build_dep()
1121 for sym in self.unique_defined_syms:
1126 self._add_choice_deps()
1129 def mainmenu_text(self): argument
1133 return self.top_node.prompt[0]
1136 def defconfig_filename(self): argument
1140 if self.defconfig_list:
1141 for filename, cond in self.defconfig_list.defaults:
1144 with self._open_config(filename.str_value) as f:
1151 def load_config(self, filename=None, replace=True, verbose=None): argument
1221 not exists(join(self.srctree, filename)):
1222 defconfig = self.defconfig_filename
1236 self._warn_assign_no_prompt = False
1241 self._load_config(filename, replace)
1245 self._warn_assign_no_prompt = True
1249 def _load_config(self, filename, replace): argument
1250 with self._open_config(filename) as f:
1252 self.missing_syms = []
1260 for sym in self.unique_defined_syms:
1263 for choice in self.unique_choices:
1267 set_match = self._set_match
1268 unset_match = self._unset_match
1269 get_sym = self.syms.get
1280 self._undef_assign(name, val, filename, linenr)
1290 self._warn("'{}' is not a valid value for the {} "
1308 self._warn("both m and y assigned to symbols "
1318 self._warn("malformed string literal in "
1334 self._warn("ignoring malformed line '{}'"
1343 self._undef_assign(name, "n", filename, linenr)
1354 self._assigned_twice(sym, val, filename, linenr)
1362 for sym in self.unique_defined_syms:
1366 for choice in self.unique_choices:
1370 def _undef_assign(self, name, val, filename, linenr): argument
1373 self.missing_syms.append((name, val))
1374 if self.warn_assign_undef:
1375 self._warn(
1379 def _assigned_twice(self, sym, new_val, filename, linenr): argument
1392 if self.warn_assign_redun:
1393 self._warn(msg, filename, linenr)
1394 elif self.warn_assign_override:
1395 self._warn(msg, filename, linenr)
1397 def load_allconfig(self, filename): argument
1417 load_allconfig(self, filename)
1419 def write_autoconf(self, filename=None, header=None): argument
1458 if self._write_if_changed(filename, self._autoconf_contents(header)):
1462 def _autoconf_contents(self, header): argument
1467 header = self.header_header
1472 for sym in self.unique_defined_syms:
1486 .format(self.config_prefix, sym.name))
1489 .format(self.config_prefix, sym.name))
1493 .format(self.config_prefix, sym.name, escape(val)))
1501 .format(self.config_prefix, sym.name, val))
1505 def write_config(self, filename=None, header=None, save_old=True, argument
1572 contents = self._config_contents(header)
1573 if self._contents_eq(filename, contents):
1579 with self._open(filename, "w") as f:
1584 def _config_contents(self, header): argument
1595 for sym in self.unique_defined_syms:
1599 header = self.config_header
1607 node = self.top_node
1621 node is not self.top_node:
1659 def write_min_config(self, filename, header=None): argument
1692 if self._write_if_changed(filename, self._min_config_contents(header)):
1696 def _min_config_contents(self, header): argument
1701 header = self.config_header
1706 for sym in self.unique_defined_syms:
1733 def sync_deps(self, path): argument
1799 self._load_old_vals(path)
1801 for sym in self.unique_defined_syms:
1840 self._write_old_vals(path)
1842 def _load_old_vals(self, path): argument
1850 for sym in self.unique_defined_syms:
1854 auto_conf = self._open(join(path, "auto.conf"), "r")
1863 match = self._set_match(line)
1870 if name in self.syms:
1871 sym = self.syms[name]
1879 self.syms[name]._old_val = val
1885 def _write_old_vals(self, path): argument
1895 self._write_if_changed(
1897 self._old_vals_contents())
1899 def _old_vals_contents(self): argument
1904 sym.config_string for sym in self.unique_defined_syms
1908 def node_iter(self, unique_syms=False): argument
1932 for sym in self.unique_defined_syms:
1935 node = self.top_node
1959 def eval_string(self, s): argument
1982 self.filename = None
1984 self._tokens = self._tokenize("if " + s)
1986 self._line = s
1987 self._tokens_i = 1 # Skip the 'if' token
1989 return expr_value(self._expect_expr_and_eol())
1991 def unset_values(self): argument
1996 self._warn_assign_no_prompt = False
2001 for sym in self.unique_defined_syms:
2004 for choice in self.unique_choices:
2007 self._warn_assign_no_prompt = True
2009 def enable_warnings(self): argument
2014 self.warn = True
2016 def disable_warnings(self): argument
2021 self.warn = False
2023 def enable_stderr_warnings(self): argument
2028 self.warn_to_stderr = True
2030 def disable_stderr_warnings(self): argument
2035 self.warn_to_stderr = False
2037 def enable_undef_warnings(self): argument
2042 self.warn_assign_undef = True
2044 def disable_undef_warnings(self): argument
2049 self.warn_assign_undef = False
2051 def enable_override_warnings(self): argument
2056 self.warn_assign_override = True
2058 def disable_override_warnings(self): argument
2063 self.warn_assign_override = False
2065 def enable_redun_warnings(self): argument
2070 self.warn_assign_redun = True
2072 def disable_redun_warnings(self): argument
2077 self.warn_assign_redun = False
2079 def __repr__(self): argument
2088 "configuration with {} symbols".format(len(self.syms)),
2089 'main menu prompt "{}"'.format(self.mainmenu_text),
2090 "srctree is current directory" if not self.srctree else
2091 'srctree "{}"'.format(self.srctree),
2092 'config symbol prefix "{}"'.format(self.config_prefix),
2093 "warnings " + status(self.warn),
2094 "printing of warnings to stderr " + status(self.warn_to_stderr),
2096 status(self.warn_assign_undef),
2098 status(self.warn_assign_override),
2100 status(self.warn_assign_redun)
2112 def _open_config(self, filename): argument
2118 return self._open(filename, "r")
2123 return self._open(join(self.srctree, filename), "r")
2135 "set to '{}'".format(self.srctree) if self.srctree
2138 def _enter_file(self, filename): argument
2148 if filename.startswith(self._srctree_prefix):
2151 rel_filename = filename[len(self._srctree_prefix):]
2156 self.kconfig_filenames.append(rel_filename)
2172 self._filestack.append((self._include_path, self._readline))
2176 self._include_path += ((self.filename, self.linenr),)
2179 for name, _ in self._include_path:
2185 .format(self.filename, self.linenr, rel_filename,
2187 for name, linenr in self._include_path)))
2190 self._readline = self._open(filename, "r").readline
2195 .format(self.filename, self.linenr, filename,
2196 self._line.strip(),
2199 self.filename = rel_filename
2200 self.linenr = 0
2202 def _leave_file(self): argument
2207 self.filename, self.linenr = self._include_path[-1]
2209 self._readline.__self__.close() # __self__ fetches the 'file' object
2210 self._include_path, self._readline = self._filestack.pop()
2212 def _next_line(self): argument
2218 if self._reuse_tokens:
2219 self._reuse_tokens = False
2227 line = self._readline()
2230 self.linenr += 1
2234 line = line[:-2] + self._readline()
2235 self.linenr += 1
2237 self._tokens = self._tokenize(line)
2240 self._tokens_i = 1
2244 def _line_after_help(self, line): argument
2255 line = line[:-2] + self._readline()
2256 self.linenr += 1
2258 self._tokens = self._tokenize(line)
2259 self._reuse_tokens = True
2261 def _write_if_changed(self, filename, contents): argument
2274 if self._contents_eq(filename, contents):
2276 with self._open(filename, "w") as f:
2280 def _contents_eq(self, filename, contents): argument
2285 with self._open(filename, "r") as f:
2298 def _lookup_sym(self, name): argument
2303 if name in self.syms:
2304 return self.syms[name]
2307 sym.kconfig = self
2311 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
2313 if self._parsing_kconfigs:
2314 self.syms[name] = sym
2316 self._warn("no symbol {} in configuration".format(name))
2320 def _lookup_const_sym(self, name): argument
2323 if name in self.const_syms:
2324 return self.const_syms[name]
2327 sym.kconfig = self
2331 sym.rev_dep = sym.weak_rev_dep = sym.direct_dep = self.n
2333 if self._parsing_kconfigs:
2334 self.const_syms[name] = sym
2338 def _tokenize(self, s): argument
2350 self._line = s # Used for error reporting
2357 self._parse_error("unknown token at start of line")
2374 self._parse_assignment(s)
2408 name, s, i = self._expand_name(s, i)
2412 token = self.const_syms[name] if name in STR_TO_TRI else \
2413 self._lookup_sym(name)
2429 self._warn("style: quotes recommended around '{}' in '{}'"
2430 .format(name, self._line.strip()),
2431 self.filename, self.linenr)
2449 self._parse_error("unterminated string")
2454 s, end_i = self._expand_str(s, i)
2474 else self._lookup_const_sym(val)
2528 self._parse_error("unknown tokens in line")
2550 def _expect_sym(self): argument
2551 token = self._tokens[self._tokens_i]
2552 self._tokens_i += 1
2555 self._parse_error("expected symbol")
2559 def _expect_nonconst_sym(self): argument
2562 token = self._tokens[1]
2563 self._tokens_i = 2
2566 self._parse_error("expected nonconstant symbol")
2570 def _expect_str_and_eol(self): argument
2571 token = self._tokens[self._tokens_i]
2572 self._tokens_i += 1
2575 self._parse_error("expected string")
2577 if self._tokens[self._tokens_i] is not None:
2578 self._trailing_tokens_error()
2582 def _expect_expr_and_eol(self): argument
2583 expr = self._parse_expr(True)
2585 if self._tokens[self._tokens_i] is not None:
2586 self._trailing_tokens_error()
2590 def _check_token(self, token): argument
2593 if self._tokens[self._tokens_i] is token:
2594 self._tokens_i += 1
2602 def _parse_assignment(self, s): argument
2614 s, i = self._expand_macro(s, i, ())
2630 self._parse_error("syntax error")
2635 if name in self.variables:
2637 var = self.variables[name]
2641 var.kconfig = self
2644 self.variables[name] = var
2656 var.value = self._expand_whole(val, ())
2661 self._expand_whole(val, ()))
2663 def _expand_whole(self, s, args): argument
2675 s, i = self._expand_macro(s, i, args)
2678 def _expand_name(self, s, i): argument
2685 s, end_i = self._expand_name_iter(s, i)
2691 self._parse_error("macro expanded to blank string")
2699 def _expand_name_iter(self, s, i): argument
2710 s, i = self._expand_macro(s, match.start(), ())
2712 def _expand_str(self, s, i): argument
2724 self._parse_error("unterminated string")
2739 s, i = self._expand_macro(s, match.start(), ())
2745 def _expand_macro(self, s, i, args): argument
2763 self._parse_error("missing end parenthesis in macro expansion")
2790 res += self._fn_val(new_args)
2805 s, i = self._expand_macro(s, match.start(), args)
2807 def _fn_val(self, args): argument
2814 if fn in self.variables:
2815 var = self.variables[fn]
2820 self._parse_error("Preprocessor variable {} recursively "
2825 self._parse_error("Preprocessor function {} seems stuck "
2829 res = self._expand_whole(self.variables[fn].value, args)
2833 if fn in self._functions:
2836 py_fn, min_arg, max_arg = self._functions[fn]
2850 .format(self.filename, self.linenr, fn,
2853 return py_fn(self, *args)
2857 self.env_vars.add(fn)
2866 def _make_and(self, e1, e2): argument
2869 if e1 is self.y:
2872 if e2 is self.y:
2875 if e1 is self.n or e2 is self.n:
2876 return self.n
2880 def _make_or(self, e1, e2): argument
2883 if e1 is self.n:
2886 if e2 is self.n:
2889 if e1 is self.y or e2 is self.y:
2890 return self.y
2894 def _parse_block(self, end_token, parent, prev): argument
2917 while self._next_line():
2918 t0 = self._tokens[0]
2922 sym = self._tokens[1]
2925 self._parse_error("missing or bad symbol name")
2927 if self._tokens[2] is not None:
2928 self._trailing_tokens_error()
2930 self.defined_syms.append(sym)
2933 node.kconfig = self
2939 node.filename = self.filename
2940 node.linenr = self.linenr
2941 node.include_path = self._include_path
2945 self._parse_props(node)
2949 node.dep != self.y or
2953 self._parse_error("configdefault can only contain `default`")
2956 self._warn("the menuconfig symbol {} has no prompt"
2972 pattern = self._expect_str_and_eol()
2976 pattern = join(dirname(self.filename), pattern)
2986 filenames = sorted(iglob(join(self._srctree_prefix, pattern)))
2994 .format(self.filename, self.linenr, pattern,
2995 self._line.strip(),
2996 "set to '{}'".format(self.srctree)
2997 if self.srctree else "unset or blank"))
3000 self._enter_file(filename)
3001 prev = self._parse_block(None, parent, prev)
3002 self._leave_file()
3008 if self._tokens[1] is not None:
3009 self._trailing_tokens_error()
3018 node.dep = self._expect_expr_and_eol()
3020 self._parse_block(_T_ENDIF, node, node)
3027 node.kconfig = self
3030 node.prompt = (self._expect_str_and_eol(), self.y)
3031 node.visibility = self.y
3033 node.filename = self.filename
3034 node.linenr = self.linenr
3035 node.include_path = self._include_path
3037 self.menus.append(node)
3039 self._parse_props(node)
3040 self._parse_block(_T_ENDMENU, node, node)
3047 node.kconfig = self
3050 node.prompt = (self._expect_str_and_eol(), self.y)
3053 node.filename = self.filename
3054 node.linenr = self.linenr
3055 node.include_path = self._include_path
3057 self.comments.append(node)
3059 self._parse_props(node)
3064 if self._tokens[1] is None:
3066 choice.direct_dep = self.n
3069 name = self._expect_str_and_eol()
3070 choice = self.named_choices.get(name)
3074 choice.direct_dep = self.n
3075 self.named_choices[name] = choice
3077 self.choices.append(choice)
3080 node.kconfig = choice.kconfig = self
3085 node.filename = self.filename
3086 node.linenr = self.linenr
3087 node.include_path = self._include_path
3091 self._parse_props(node)
3092 self._parse_block(_T_ENDCHOICE, node, node)
3098 self.top_node.prompt = (self._expect_str_and_eol(), self.y)
3103 self._parse_error(
3117 self.filename))
3121 def _parse_cond(self): argument
3125 expr = self._parse_expr(True) if self._check_token(_T_IF) else self.y
3127 if self._tokens[self._tokens_i] is not None:
3128 self._trailing_tokens_error()
3132 def _parse_props(self, node): argument
3151 node.dep = self.y
3153 while self._next_line():
3154 t0 = self._tokens[0]
3158 self._set_type(node.item, t0)
3159 if self._tokens[1] is not None:
3160 self._parse_prompt(node)
3163 if not self._check_token(_T_ON):
3164 self._parse_error("expected 'on' after 'depends'")
3166 node.dep = self._make_and(node.dep,
3167 self._expect_expr_and_eol())
3170 self._parse_help(node)
3174 self._parse_error("only symbols can select")
3176 node.selects.append((self._expect_nonconst_sym(),
3177 self._parse_cond()))
3184 node.defaults.append((self._parse_expr(False),
3185 self._parse_cond()))
3188 self._set_type(node.item, _DEF_TOKEN_TO_TYPE[t0])
3189 node.defaults.append((self._parse_expr(False),
3190 self._parse_cond()))
3193 self._parse_prompt(node)
3196 node.ranges.append((self._expect_sym(), self._expect_sym(),
3197 self._parse_cond()))
3201 self._parse_error("only symbols can imply")
3203 node.implies.append((self._expect_nonconst_sym(),
3204 self._parse_cond()))
3207 if not self._check_token(_T_IF):
3208 self._parse_error("expected 'if' after 'visible'")
3210 node.visibility = self._make_and(node.visibility,
3211 self._expect_expr_and_eol())
3214 if self._check_token(_T_ENV):
3215 if not self._check_token(_T_EQUAL):
3216 self._parse_error("expected '=' after 'env'")
3218 env_var = self._expect_str_and_eol()
3223 (self._lookup_const_sym(os.environ[env_var]),
3224 self.y))
3226 self._warn("{1} has 'option env=\"{0}\"', "
3229 self.filename, self.linenr)
3232 self._warn("Kconfiglib expands environment variables "
3239 self.filename, self.linenr)
3241 elif self._check_token(_T_DEFCONFIG_LIST):
3242 if not self.defconfig_list:
3243 self.defconfig_list = node.item
3245 self._warn("'option defconfig_list' set on multiple "
3247 "used.".format(self.defconfig_list.name,
3249 self.filename, self.linenr)
3251 elif self._check_token(_T_MODULES):
3257 if node.item is not self.modules:
3258 self._warn("the 'modules' option is not supported. "
3266 self.filename, self.linenr)
3268 elif self._check_token(_T_ALLNOCONFIG_Y):
3270 self._parse_error("the 'allnoconfig_y' option is only "
3276 self._parse_error("unrecognized option")
3280 self._parse_error('"optional" is only valid for choices')
3286 self._reuse_tokens = True
3289 def _set_type(self, sc, new_type): argument
3294 self._warn("{} defined with multiple types, {} will be used"
3299 def _parse_prompt(self, node): argument
3305 self._warn(node.item.name_and_loc +
3308 prompt = self._tokens[1]
3309 self._tokens_i = 2
3312 self._parse_error("expected prompt string")
3315 self._warn(node.item.name_and_loc +
3322 node.prompt = (prompt, self._parse_cond())
3324 def _parse_help(self, node): argument
3326 self._warn(node.item.name_and_loc + " defined with more than "
3330 readline = self._readline
3337 self.linenr += 1
3339 self._empty_help(node, line)
3352 self._empty_help(node, line)
3376 self.linenr += len_(lines)
3379 self._line_after_help(line)
3381 def _empty_help(self, node, line): argument
3382 self._warn(node.item.name_and_loc +
3386 self._line_after_help(line)
3388 def _parse_expr(self, transform_m): argument
3421 and_expr = self._parse_and_expr(transform_m)
3426 return and_expr if not self._check_token(_T_OR) else \
3427 (OR, and_expr, self._parse_expr(transform_m))
3429 def _parse_and_expr(self, transform_m): argument
3430 factor = self._parse_factor(transform_m)
3435 return factor if not self._check_token(_T_AND) else \
3436 (AND, factor, self._parse_and_expr(transform_m))
3438 def _parse_factor(self, transform_m): argument
3439 token = self._tokens[self._tokens_i]
3440 self._tokens_i += 1
3445 if self._tokens[self._tokens_i] not in _RELATIONS:
3450 if transform_m and token is self.m:
3451 return (AND, self.m, self.modules)
3459 self._tokens_i += 1
3460 return (self._tokens[self._tokens_i - 1], token,
3461 self._expect_sym())
3465 return (token, self._parse_factor(transform_m))
3468 expr_parse = self._parse_expr(transform_m)
3469 if self._check_token(_T_CLOSE_PAREN):
3472 self._parse_error("malformed expression")
3478 def _build_dep(self): argument
3492 for sym in self.unique_defined_syms:
3527 for choice in self.unique_choices:
3539 def _add_choice_deps(self): argument
3549 for choice in self.unique_choices:
3553 def _invalidate_all(self): argument
3557 for sym in self.unique_defined_syms:
3560 for choice in self.unique_choices:
3567 def _finalize_sym(self, sym): argument
3581 default = (d[0], self._make_and(sym.direct_dep, d[1]))
3585 def _finalize_node(self, node, visible_if): argument
3612 self._add_props_to_sym(node)
3620 self._finalize_node(cur.next, visible_if)
3635 visible_if = self._make_and(visible_if, node.visibility)
3641 self._propagate_deps(node, visible_if)
3646 self._finalize_node(cur, visible_if)
3661 choice.direct_dep = self._make_or(choice.direct_dep, node.dep)
3666 def _propagate_deps(self, node, visible_if): argument
3680 dep = cur.dep = self._make_and(cur.dep, basedep)
3686 self._make_and(
3688 self._make_and(visible_if, dep)))
3692 cur.defaults = [(default, self._make_and(cond, dep))
3697 cur.ranges = [(low, high, self._make_and(cond, dep))
3702 cur.selects = [(target, self._make_and(cond, dep))
3707 cur.implies = [(target, self._make_and(cond, dep))
3714 self._make_and(cur.prompt[1], dep))
3718 def _add_props_to_sym(self, node): argument
3739 sym.direct_dep = self._make_or(sym.direct_dep, node.dep)
3748 target.rev_dep = self._make_or(
3750 self._make_and(sym, cond))
3755 target.weak_rev_dep = self._make_or(
3757 self._make_and(sym, cond))
3763 def _check_sym_sanity(self): argument
3778 for sym in self.unique_defined_syms:
3785 self._warn("{} selects the {} symbol {}, which is not "
3793 self._warn("{} implies the {} symbol {}, which is not "
3815 self._warn("style: quotes recommended around "
3820 self._warn("the {0} symbol {1} has a non-{0} default {2}"
3826 self._warn("the {} symbol {} has selects or implies"
3831 self._warn("{} defined without a type"
3837 self._warn(
3846 self._warn("the {0} symbol {1} has a non-{0} "
3853 def _check_choice_sanity(self): argument
3866 self._warn(msg)
3868 for choice in self.unique_choices:
3870 self._warn("{} defined with type {}"
3878 self._warn(choice.name_and_loc + " defined without a prompt")
3887 self._warn("the default selection {} of {} is not "
3894 self._warn("default on the choice symbol {} will have "
3907 self._warn("the choice symbol {} has no prompt"
3911 self._warn("the choice symbol {} is defined with a "
3915 def _parse_error(self, msg): argument
3917 "" if self.filename is None else
3918 "{}:{}: ".format(self.filename, self.linenr),
3919 self._line.strip(), msg))
3921 def _trailing_tokens_error(self): argument
3922 self._parse_error("extra tokens at end of line")
3924 def _open(self, filename, mode): argument
3959 open(filename, mode, encoding=self._encoding)
3961 def _check_undef_syms(self): argument
3988 for sym in (self.syms.viewvalues if _IS_PY2 else self.syms.values)():
4000 for node in self.node_iter():
4004 self._warn(msg)
4006 def _warn(self, msg, filename=None, linenr=None): argument
4009 if not self.warn:
4016 self.warnings.append(msg)
4017 if self.warn_to_stderr:
4312 def type(self): argument
4316 if self.orig_type is TRISTATE and \
4317 (self.choice and self.choice.tri_value == 2 or
4318 not self.kconfig.modules.tri_value):
4322 return self.orig_type
4325 def str_value(self): argument
4329 if self._cached_str_val is not None:
4330 return self._cached_str_val
4332 if self.orig_type in _BOOL_TRISTATE:
4334 self._cached_str_val = TRI_TO_STR[self.tri_value]
4335 return self._cached_str_val
4340 if not self.orig_type: # UNKNOWN
4341 self._cached_str_val = self.name
4342 return self.name
4347 vis = self.visibility
4349 self._write_to_conf = vis != 0
4351 if self.orig_type in _INT_HEX:
4357 base = _TYPE_TO_BASE[self.orig_type]
4360 for low_expr, high_expr, cond in self.ranges:
4379 if vis and self.user_value:
4380 user_val = int(self.user_value, base)
4383 self.kconfig._warn(
4387 .format(num2str(user_val), TYPE_TO_STR[self.orig_type],
4388 self.name_and_loc,
4394 val = self.user_value
4403 for sym, cond in self.defaults:
4405 has_default = self._write_to_conf = True
4430 if self.orig_type is INT else \
4435 self.kconfig._warn(
4438 .format(val_num, self.name_and_loc,
4442 elif self.orig_type is STRING:
4443 if vis and self.user_value is not None:
4445 val = self.user_value
4448 for sym, cond in self.defaults:
4451 self._write_to_conf = True
4459 if self.env_var is not None or self is self.kconfig.defconfig_list:
4460 self._write_to_conf = False
4462 self._cached_str_val = val
4466 def tri_value(self): argument
4470 if self._cached_tri_val is not None:
4471 return self._cached_tri_val
4473 if self.orig_type not in _BOOL_TRISTATE:
4474 if self.orig_type: # != UNKNOWN
4476 self.kconfig._warn(
4479 .format(TYPE_TO_STR[self.orig_type], self.name_and_loc))
4481 self._cached_tri_val = 0
4486 vis = self.visibility
4487 self._write_to_conf = vis != 0
4491 if not self.choice:
4494 if vis and self.user_value is not None:
4496 val = min(self.user_value, vis)
4502 for default, cond in self.defaults:
4507 self._write_to_conf = True
4512 dep_val = expr_value(self.weak_rev_dep)
4513 if dep_val and expr_value(self.direct_dep):
4515 self._write_to_conf = True
4518 dep_val = expr_value(self.rev_dep)
4520 if expr_value(self.direct_dep) < dep_val:
4521 self._warn_select_unsatisfied_deps()
4524 self._write_to_conf = True
4529 (self.type is BOOL or expr_value(self.weak_rev_dep) == 2):
4536 val = 2 if self.choice.selection is self else 0
4538 elif vis and self.user_value:
4542 self._cached_tri_val = val
4546 def assignable(self): argument
4550 if self._cached_assignable is None:
4551 self._cached_assignable = self._assignable()
4552 return self._cached_assignable
4555 def visibility(self): argument
4559 if self._cached_vis is None:
4560 self._cached_vis = _visibility(self)
4561 return self._cached_vis
4564 def config_string(self): argument
4570 val = self.str_value
4571 if not self._write_to_conf:
4574 if self.orig_type in _BOOL_TRISTATE:
4576 .format(self.kconfig.config_prefix, self.name, val) \
4579 .format(self.kconfig.config_prefix, self.name)
4581 if self.orig_type in _INT_HEX:
4583 .format(self.kconfig.config_prefix, self.name, val)
4587 .format(self.kconfig.config_prefix, self.name, escape(val))
4590 def name_and_loc(self): argument
4594 return self.name + " " + _locs(self)
4596 def set_value(self, value): argument
4636 if self.orig_type in _BOOL_TRISTATE and value in STR_TO_TRI:
4646 if value == self.user_value and not self.choice:
4647 self._was_set = True
4651 if not (self.orig_type is BOOL and value in (2, 0) or
4652 self.orig_type is TRISTATE and value in TRI_TO_STR or
4654 (self.orig_type is STRING or
4655 self.orig_type is INT and _is_base_n(value, 10) or
4656 self.orig_type is HEX and _is_base_n(value, 16)
4660 self.kconfig._warn(
4665 self.name_and_loc, TYPE_TO_STR[self.orig_type]))
4669 self.user_value = value
4670 self._was_set = True
4672 if self.choice and value == 2:
4677 self.choice.user_selection = self
4678 self.choice._was_set = True
4679 self.choice._rec_invalidate()
4681 self._rec_invalidate_if_has_prompt()
4685 def unset_value(self): argument
4690 if self.user_value is not None:
4691 self.user_value = None
4692 self._rec_invalidate_if_has_prompt()
4695 def referenced(self): argument
4699 return {item for node in self.nodes for item in node.referenced}
4702 def orig_defaults(self): argument
4706 return [d for node in self.nodes for d in node.orig_defaults]
4709 def orig_selects(self): argument
4713 return [s for node in self.nodes for s in node.orig_selects]
4716 def orig_implies(self): argument
4720 return [i for node in self.nodes for i in node.orig_implies]
4723 def orig_ranges(self): argument
4727 return [r for node in self.nodes for r in node.orig_ranges]
4729 def __repr__(self): argument
4735 fields = ["symbol " + self.name, TYPE_TO_STR[self.type]]
4738 for node in self.nodes:
4743 add("value " + (self.str_value if self.orig_type in _BOOL_TRISTATE
4744 else '"{}"'.format(self.str_value)))
4746 if not self.is_constant:
4749 if self.user_value is not None:
4751 add("user value " + (TRI_TO_STR[self.user_value]
4752 if self.orig_type in _BOOL_TRISTATE
4753 else '"{}"'.format(self.user_value)))
4755 add("visibility " + TRI_TO_STR[self.visibility])
4757 if self.choice:
4760 if self.is_allnoconfig_y:
4763 if self is self.kconfig.defconfig_list:
4766 if self.env_var is not None:
4767 add("from environment variable " + self.env_var)
4769 if self is self.kconfig.modules:
4772 add("direct deps " + TRI_TO_STR[expr_value(self.direct_dep)])
4774 if self.nodes:
4775 for node in self.nodes:
4778 add("constant" if self.is_constant else "undefined")
4782 def __str__(self): argument
4796 return self.custom_str(standard_sc_expr_str)
4798 def custom_str(self, sc_expr_str_fn): argument
4804 for node in self.nodes)
4810 def __init__(self): argument
4826 self.orig_type = self._visited = 0
4828 self.nodes = []
4830 self.defaults = []
4831 self.selects = []
4832 self.implies = []
4833 self.ranges = []
4835 self.user_value = \
4836 self.choice = \
4837 self.env_var = \
4838 self._cached_str_val = self._cached_tri_val = self._cached_vis = \
4839 self._cached_assignable = None
4844 self.is_allnoconfig_y = \
4845 self._was_set = \
4846 self._write_to_conf = False
4849 self._dependents = set()
4851 def _assignable(self): argument
4854 if self.orig_type not in _BOOL_TRISTATE:
4859 vis = self.visibility
4863 rev_dep_val = expr_value(self.rev_dep)
4866 if self.choice:
4870 if self.type is BOOL or expr_value(self.weak_rev_dep) == 2:
4879 if self.type is BOOL or expr_value(self.weak_rev_dep) == 2:
4888 return (0, 1) if expr_value(self.weak_rev_dep) != 2 else (0, 2)
4897 def _invalidate(self): argument
4900 self._cached_str_val = self._cached_tri_val = self._cached_vis = \
4901 self._cached_assignable = None
4903 def _rec_invalidate(self): argument
4906 if self is self.kconfig.modules:
4908 self.kconfig._invalidate_all()
4910 self._invalidate()
4912 for item in self._dependents:
4934 def _rec_invalidate_if_has_prompt(self): argument
4947 for node in self.nodes:
4949 self._rec_invalidate()
4952 if self.kconfig._warn_assign_no_prompt:
4953 self.kconfig._warn(self.name_and_loc + " has no prompt, meaning "
4956 def _str_default(self): argument
4962 if self.orig_type in _BOOL_TRISTATE:
4966 if not self.choice:
4967 for default, cond in self.defaults:
4973 val = max(expr_value(self.rev_dep),
4974 expr_value(self.weak_rev_dep),
4979 if val == 1 and self.type is BOOL:
4984 if self.orig_type: # STRING/INT/HEX
4985 for default, cond in self.defaults:
4991 def _warn_select_unsatisfied_deps(self): argument
4999 .format(self.name_and_loc, expr_str(self.direct_dep),
5000 TRI_TO_STR[expr_value(self.direct_dep)],
5001 TRI_TO_STR[expr_value(self.rev_dep)])
5004 for select in split_expr(self.rev_dep, OR):
5005 if expr_value(select) <= expr_value(self.direct_dep):
5027 self.kconfig._warn(msg)
5212 def type(self): argument
5216 if self.orig_type is TRISTATE and not self.kconfig.modules.tri_value:
5218 return self.orig_type
5221 def str_value(self): argument
5225 return TRI_TO_STR[self.tri_value]
5228 def tri_value(self): argument
5235 val = 0 if self.is_optional else 1
5237 if self.user_value is not None:
5238 val = max(val, self.user_value)
5242 val = min(val, self.visibility)
5245 return 2 if val == 1 and self.type is BOOL else val
5248 def assignable(self): argument
5252 if self._cached_assignable is None:
5253 self._cached_assignable = self._assignable()
5254 return self._cached_assignable
5257 def visibility(self): argument
5261 if self._cached_vis is None:
5262 self._cached_vis = _visibility(self)
5263 return self._cached_vis
5266 def name_and_loc(self): argument
5271 return standard_sc_expr_str(self) + " " + _locs(self)
5274 def selection(self): argument
5278 if self._cached_selection is _NO_CACHED_SELECTION:
5279 self._cached_selection = self._selection()
5280 return self._cached_selection
5282 def set_value(self, value): argument
5298 if value == self.user_value:
5301 self._was_set = True
5304 if not (self.orig_type is BOOL and value in (2, 0) or
5305 self.orig_type is TRISTATE and value in TRI_TO_STR):
5308 self.kconfig._warn(
5313 self.name_and_loc, TYPE_TO_STR[self.orig_type]))
5317 self.user_value = value
5318 self._was_set = True
5319 self._rec_invalidate()
5323 def unset_value(self): argument
5328 if self.user_value is not None or self.user_selection:
5329 self.user_value = self.user_selection = None
5330 self._rec_invalidate()
5333 def referenced(self): argument
5337 return {item for node in self.nodes for item in node.referenced}
5340 def orig_defaults(self): argument
5344 return [d for node in self.nodes for d in node.orig_defaults]
5346 def __repr__(self): argument
5351 fields = ["choice " + self.name if self.name else "choice",
5352 TYPE_TO_STR[self.type]]
5355 for node in self.nodes:
5359 add("mode " + self.str_value)
5361 if self.user_value is not None:
5362 add('user mode {}'.format(TRI_TO_STR[self.user_value]))
5364 if self.selection:
5365 add("{} selected".format(self.selection.name))
5367 if self.user_selection:
5369 .format(self.user_selection.name)
5371 if self.selection is not self.user_selection:
5376 add("visibility " + TRI_TO_STR[self.visibility])
5378 if self.is_optional:
5381 for node in self.nodes:
5386 def __str__(self): argument
5397 return self.custom_str(standard_sc_expr_str)
5399 def custom_str(self, sc_expr_str_fn): argument
5405 for node in self.nodes)
5411 def __init__(self): argument
5423 self.orig_type = self._visited = 0
5425 self.nodes = []
5427 self.syms = []
5428 self.defaults = []
5430 self.name = \
5431 self.user_value = self.user_selection = \
5432 self._cached_vis = self._cached_assignable = None
5434 self._cached_selection = _NO_CACHED_SELECTION
5438 self.is_constant = self.is_optional = False
5441 self._dependents = set()
5443 def _assignable(self): argument
5448 vis = self.visibility
5454 if not self.is_optional:
5455 return (2,) if self.type is BOOL else (1, 2)
5456 return (0, 2) if self.type is BOOL else (0, 1, 2)
5460 return (0, 1) if self.is_optional else (1,)
5462 def _selection(self): argument
5467 if self.tri_value != 2:
5472 if self.user_selection and self.user_selection.visibility:
5473 return self.user_selection
5476 return self._selection_from_defaults()
5478 def _selection_from_defaults(self): argument
5480 for sym, cond in self.defaults:
5486 for sym in self.syms:
5493 def _invalidate(self): argument
5494 self._cached_vis = self._cached_assignable = None
5495 self._cached_selection = _NO_CACHED_SELECTION
5497 def _rec_invalidate(self): argument
5500 self._invalidate()
5502 for item in self._dependents:
5672 def __init__(self): argument
5676 self.defaults = []
5677 self.selects = []
5678 self.implies = []
5679 self.ranges = []
5682 def orig_prompt(self): argument
5686 if not self.prompt:
5688 return (self.prompt[0], self._strip_dep(self.prompt[1]))
5691 def orig_defaults(self): argument
5695 return [(default, self._strip_dep(cond))
5696 for default, cond in self.defaults]
5699 def orig_selects(self): argument
5703 return [(select, self._strip_dep(cond))
5704 for select, cond in self.selects]
5707 def orig_implies(self): argument
5711 return [(imply, self._strip_dep(cond))
5712 for imply, cond in self.implies]
5715 def orig_ranges(self): argument
5719 return [(low, high, self._strip_dep(cond))
5720 for low, high, cond in self.ranges]
5723 def referenced(self): argument
5729 res = expr_items(self.dep)
5731 if self.prompt:
5732 res |= expr_items(self.prompt[1])
5734 if self.item is MENU:
5735 res |= expr_items(self.visibility)
5737 for value, cond in self.defaults:
5741 for value, cond in self.selects:
5745 for value, cond in self.implies:
5749 for low, high, cond in self.ranges:
5756 def __repr__(self): argument
5764 if self.item.__class__ is Symbol:
5765 add("menu node for symbol " + self.item.name)
5767 elif self.item.__class__ is Choice:
5769 if self.item.name is not None:
5770 s += " " + self.item.name
5773 elif self.item is MENU:
5779 if self.prompt:
5781 self.prompt[0], TRI_TO_STR[expr_value(self.prompt[1])]))
5783 if self.item.__class__ is Symbol and self.is_menuconfig:
5786 add("deps " + TRI_TO_STR[expr_value(self.dep)])
5788 if self.item is MENU:
5789 add("'visible if' deps " + TRI_TO_STR[expr_value(self.visibility)])
5791 if self.item.__class__ in _SYMBOL_CHOICE and self.help is not None:
5794 if self.list:
5797 if self.next:
5800 add("{}:{}".format(self.filename, self.linenr))
5804 def __str__(self): argument
5821 return self.custom_str(standard_sc_expr_str)
5823 def custom_str(self, sc_expr_str_fn): argument
5828 return self._menu_comment_node_str(sc_expr_str_fn) \
5829 if self.item in _MENU_COMMENT else \
5830 self._sym_choice_node_str(sc_expr_str_fn)
5832 def _menu_comment_node_str(self, sc_expr_str_fn): argument
5833 s = '{} "{}"'.format("menu" if self.item is MENU else "comment",
5834 self.prompt[0])
5836 if self.dep is not self.kconfig.y:
5837 s += "\n\tdepends on {}".format(expr_str(self.dep, sc_expr_str_fn))
5839 if self.item is MENU and self.visibility is not self.kconfig.y:
5840 s += "\n\tvisible if {}".format(expr_str(self.visibility,
5845 def _sym_choice_node_str(self, sc_expr_str_fn): argument
5850 if cond is not self.kconfig.y:
5854 sc = self.item
5857 if self.is_menuconfig:
5859 elif self.is_configdefault:
5867 if sc.orig_type and not self.prompt: # sc.orig_type != UNKNOWN
5872 if self.prompt:
5879 indent_add_cond(prefix + ' "{}"'.format(escape(self.prompt[0])),
5880 self.orig_prompt[1])
5895 for low, high, cond in self.orig_ranges:
5901 for default, cond in self.orig_defaults:
5909 for select, cond in self.orig_selects:
5912 for imply, cond in self.orig_implies:
5915 if self.dep is not sc.kconfig.y:
5916 indent_add("depends on " + expr_str(self.dep, sc_expr_str_fn))
5918 if self.help is not None:
5920 for line in self.help.splitlines():
5925 def _strip_dep(self, expr): argument
5931 if self.dep is expr:
5932 return self.kconfig.y
5935 if expr.__class__ is tuple and expr[0] is AND and expr[2] is self.dep:
5974 def expanded_value(self): argument
5978 return self.expanded_value_w_args()
5980 def expanded_value_w_args(self, *args): argument
5987 return self.kconfig._fn_val((self.name,) + args)
5989 def __repr__(self): argument
5991 .format(self.name,
5992 "recursive" if self.is_recursive else "immediate",
5993 self.value)
6018 def __init__(self, ioerror, msg): argument
6019 self.msg = msg
6020 super(_KconfigIOError, self).__init__(
6023 def __str__(self): argument
6024 return self.msg