Lines Matching full:choice
257 menu or Choice, but menu nodes for symbols can sometimes have a non-None 'list'
260 MenuNode.item is either a Symbol or a Choice object, or one of the constants
262 which also holds the title for menus and comments. For Symbol and Choice,
267 a Symbol or Choice can be found in the Symbol/Choice.nodes attribute.
270 menu node(s) rather than in the Symbol or Choice objects themselves. This makes
280 It is possible to give a Choice a name and define it in multiple locations,
281 hence why Choice.nodes is also a list.
322 ***For choice symbols, the parent Choice will appear in expressions as well,
323 but it's usually invisible as the value interfaces of Symbol and Choice are
324 identical. This mirrors the C implementation and makes different choice modes
597 A dictionary like 'syms' for named choices (choice FOO)
1124 # Add extra dependencies from choices to choice symbols that get
1263 for choice in self.unique_choices:
1264 choice._was_set = False
1299 if sym.choice and val != "n":
1301 # choice from the kind of values that are assigned
1302 # to the choice symbols
1304 prev_mode = sym.choice.user_value
1309 "within the same choice",
1312 # Set the choice's mode
1313 sym.choice.set_value(val)
1366 for choice in self.unique_choices:
1367 if not choice._was_set:
1368 choice.unset_value()
1708 # non-choice symbols, as selects don't affect choice
1710 if not sym.choice and \
1719 # choice, unless the choice is optional or the symbol type
1720 # isn't bool (it might be possible to set the choice mode
1722 if sym.choice and \
1723 not sym.choice.is_optional and \
1724 sym.choice._selection_from_defaults() is sym and \
2004 for choice in self.unique_choices:
2005 choice.unset_value()
2426 # Named choices ('choice FOO') also end up here.
2896 # menu, or choice statement.
2903 # The parent menu node, corresponding to a menu, Choice, or 'if'.
2911 # Choice): After parsing the children, the 'next' pointer is assigned
3065 choice = Choice()
3066 choice.direct_dep = self.n
3068 # Named choice
3070 choice = self.named_choices.get(name)
3071 if not choice:
3072 choice = Choice()
3073 choice.name = name
3074 choice.direct_dep = self.n
3075 self.named_choices[name] = choice
3077 self.choices.append(choice)
3080 node.kconfig = choice.kconfig = self
3081 node.item = choice
3089 choice.nodes.append(node)
3104 "no corresponding 'choice'" if t0 is _T_ENDCHOICE else
3141 # property is added when a symbol or choice is defined in multiple
3279 if node.item.__class__ is not Choice:
3290 # Sets the type of 'sc' (symbol or choice) to 'new_type'
3479 # Populates the Symbol/Choice._dependents sets, which contain all other
3522 # In addition to the above, choice symbols depend on the choice
3523 # they're in, but that's handled automatically since the Choice is
3527 for choice in self.unique_choices:
3531 for node in choice.nodes:
3533 depend_on(choice, node.prompt[1])
3536 for _, cond in choice.defaults:
3537 depend_on(choice, cond)
3540 # Choices also depend on the choice symbols themselves, because the
3541 # y-mode selection of the choice might change if a choice symbol's
3546 # <choice symbol> <-> <choice> dependency loops, but they make loop
3549 for choice in self.unique_choices:
3550 for sym in choice.syms:
3551 sym._dependents.add(choice)
3560 for choice in self.unique_choices:
3561 choice._invalidate()
3597 # - Sets 'choice' types and registers choice symbols
3632 # The menu node is a choice, menu, or if. Finalize each child node.
3657 if node.item.__class__ is Choice:
3658 # Add the node's non-node-specific properties to the choice, like
3660 choice = node.item
3661 choice.direct_dep = self._make_or(choice.direct_dep, node.dep)
3662 choice.defaults += node.defaults
3669 # If the parent node holds a Choice, we use the Choice itself as the
3670 # parent dependency. This makes sense as the value (mode) of the choice
3671 # limits the visibility of the contained choice symbols. The C
3674 # Due to the similar interface, Choice works as a drop-in replacement
3676 basedep = node.item if node.item.__class__ is Choice else node.dep
3710 elif cur.prompt: # Not a symbol/choice
3854 # Checks various choice properties that are handiest to check after
3858 msg = "the choice symbol {} is {} by the following symbols, but " \
3859 "select/imply has no effect on choice symbols" \
3868 for choice in self.unique_choices:
3869 if choice.orig_type not in _BOOL_TRISTATE:
3871 .format(choice.name_and_loc,
3872 TYPE_TO_STR[choice.orig_type]))
3874 for node in choice.nodes:
3878 self._warn(choice.name_and_loc + " defined without a prompt")
3880 for default, _ in choice.defaults:
3884 .format(choice.name_and_loc, expr_str(default)))
3886 if default.choice is not choice:
3888 "contained in the choice"
3890 choice.name_and_loc))
3892 for sym in choice.syms:
3894 self._warn("default on the choice symbol {} will have "
3895 "no effect, as defaults do not affect choice "
3905 if node.parent.item is choice:
3907 self._warn("the choice symbol {} has no prompt"
3911 self._warn("the choice symbol {} is defined with a "
3912 "prompt outside the choice"
4162 choice:
4163 Holds the parent Choice for choice symbols, and None for non-choice
4164 symbols. Doubles as a flag for whether a symbol is a choice symbol.
4234 Choices appear in the dependencies of choice symbols.
4288 "choice",
4317 (self.choice and self.choice.tri_value == 2 or
4491 if not self.choice:
4492 # Non-choice symbol
4533 # Visible choice symbol in y-mode choice. The choice mode limits
4534 # the visibility of choice symbols, so it's sufficient to just
4535 # check the visibility of the choice symbols themselves.
4536 val = 2 if self.choice.selection is self else 0
4539 # Visible choice symbol in m-mode choice, with set non-0 user value
4606 Setting a choice symbol to 2 (y) sets Choice.user_selection to the
4607 choice symbol in addition to setting Symbol.user_value.
4608 Choice.user_selection is considered when the choice is in y mode (the
4642 # This optimization is skipped for choice symbols: Setting a choice
4643 # symbol's user value to y might change the state of the choice, so it
4646 if value == self.user_value and not self.choice:
4672 if self.choice and value == 2:
4673 # Setting a choice symbol to y makes it the user selection of the
4674 # choice. Like for symbol user values, the user selection is not
4675 # guaranteed to match the actual selection of the choice, as
4677 self.choice.user_selection = self
4678 self.choice._was_set = True
4679 self.choice._rec_invalidate()
4757 if self.choice:
4758 add("choice symbol")
4801 all symbol/choice references. See expr_str().
4836 self.choice = \
4866 if self.choice:
4929 # for choices, where the choice depends on the choice symbols
4965 # Defaults, selects, and implies do not affect choice symbols
4966 if not self.choice:
5030 class Choice(object): class
5032 Represents a choice statement:
5034 choice
5038 The following attributes are available on Choice instances. They should be
5042 Note: Prompts, help texts, and locations are stored in the Choice's
5043 MenuNode(s) rather than in the Choice itself. Check the MenuNode class and
5044 the Choice.nodes attribute. This organization matches the C tools.
5047 The name of the choice, e.g. "FOO" for 'choice FOO', or None if the
5048 Choice has no name.
5051 The type of the choice. One of BOOL, TRISTATE, UNKNOWN. UNKNOWN is for
5053 type either (otherwise the choice inherits the type of the first symbol
5062 when printing the choice.
5065 The tristate value (mode) of the choice. A choice can be in one of three
5068 0 (n) - The choice is disabled and no symbols can be selected. For
5072 1 (m) - Any number of choice symbols can be set to m, the rest will
5077 Only tristate choices can be in m mode. The visibility of the choice is
5079 visibility of the choice symbols.
5081 To change the mode, use Choice.set_value().
5086 similarity to Symbol. The value (mode) of a choice is really just a
5091 Symbols within choices get the choice propagated as a dependency to
5092 their properties. This turns the mode of the choice into an upper bound
5093 on e.g. the visibility of choice symbols, and explains the gotcha
5094 related to printing choice symbols mentioned in the module docstring.
5096 Kconfiglib uses a separate Choice class only because it makes the code
5098 Corresponding attributes have the same name in the Symbol and Choice
5102 Like choice.tri_value, but gives the value as one of the strings
5106 The value (mode) selected by the user through Choice.set_value(). Either
5111 Choice.set_value() instead.
5117 The Symbol instance of the currently selected symbol. None if the Choice
5119 dependencies on choice symbols).
5122 sym.set_value(2) on the choice symbol you want to select instead.
5126 choice is not in y mode, but still remembered so that the choice "snaps
5131 sym.set_value(2) on the choice symbol to be selected instead.
5139 "<choice MY_CHOICE> (defined at foo/Kconfig:12)"
5141 , giving the name of the choice and its definition location(s). If the
5142 choice has no name (isn't defined with 'choice MY_CHOICE'), then it will
5143 be shown as "<choice>" before the list of locations (always a single one
5147 List of symbols contained in the choice.
5150 choice so that an implicit menu is created, it won't be a choice symbol,
5154 A list of MenuNodes for this choice. In practice, the list will probably
5155 always contain a single MenuNode, but it is possible to give a choice a
5159 List of (symbol, cond) tuples for the choice's 'defaults' properties. For
5174 conditions of the choice.
5177 get propagated to the choice (see the 'Intro to symbol values' section in
5181 True if the choice has the 'optional' flag set on it and can be in
5185 The Kconfig instance this choice is from.
5214 Returns the type of the choice. See Symbol.type.
5270 # Reuse the expression format, which is '<choice (name, if any)>'.
5284 Sets the user value (mode) of the choice. Like for Symbol.set_value(),
5290 Returns True if the value is valid for the type of the choice, and
5292 Choice.assignable attribute to see what values are currently in range
5293 and would actually be reflected in the mode of the choice.
5325 Resets the user value (mode) and user selection of the Choice, as if
5326 the user had never touched the mode or any of the choice symbols.
5348 Returns a string with information about the choice when it is evaluated
5351 fields = ["choice " + self.name if self.name else "choice",
5388 Returns a string representation of the choice when it is printed.
5389 Matches the Kconfig format (though without the contained choice
5401 Works like Choice.__str__(), but allows a custom format to be used for
5402 all symbol/choice references. See expr_str().
5413 Choice constructor -- not intended to be called directly by Kconfiglib
5511 and comments also get menu nodes. If a symbol or choice is defined in
5517 The menu nodes for a Symbol or Choice can be found in the
5518 Symbol/Choice.nodes attribute. Menus and comments are represented as plain
5526 Either a Symbol, a Choice, or one of the constants MENU and COMMENT.
5549 the Symbol or Choice instance. For menus and comments, the prompt holds
5556 When evaluating defaults, you should use Symbol/Choice.defaults instead,
5557 as it include properties from all menu nodes (a symbol/choice can have
5584 no help text. Always stored in the node rather than the Symbol or Choice.
5600 If a symbol or choice is defined in multiple locations, only the
5615 Choices appear in the dependencies of choice symbols.
5767 elif self.item.__class__ is Choice:
5768 s = "menu node for choice"
5812 for a gotcha related to choice symbols.
5826 for all symbol/choice references. See expr_str().
5865 lines = ["choice " + sc.name if sc.name else "choice"]
5905 if sc.__class__ is Choice and sc.is_optional:
6037 'expr' must be an already-parsed expression from a Symbol, Choice, or
6091 Standard symbol/choice printing function. Uses plain Kconfig syntax, and
6092 displays choices as <choice> (or <choice NAME>, for named choices).
6101 return "<choice {}>".format(sc.name) if sc.name else "<choice>"
6112 This function is called for every symbol/choice (hence "sc") appearing in
6113 the expression, with the symbol/choice as the argument. It is expected to
6114 return a string to be used for the symbol/choice.
6117 documentation, or for printing the value of each symbol/choice after it.
6168 # Symbol or choice
6334 # Symbol or Choice 'sc' -- the logic is nearly identical.
6342 if sc.__class__ is Symbol and sc.choice:
6343 if sc.choice.orig_type is TRISTATE and \
6344 sc.orig_type is not TRISTATE and sc.choice.tri_value != 2:
6345 # Non-tristate choice symbols are only visible in y mode
6348 if sc.orig_type is TRISTATE and vis == 1 and sc.choice.tri_value == 2:
6349 # Choice symbols with m visibility are not visible in y mode
6361 # Adds 'sc' (symbol or choice) as a "dependee" to all symbols in 'expr'.
6375 # Non-constant symbol, or choice
6454 # Python 3 (3.3+) only. Best choice when available, because it
6474 # Symbol/Choice.name_and_loc helper. Returns the "(defined at ...)" part of
6475 # the string. 'sc' is a Symbol or Choice.
6491 # items inside choice statements are considered choice items.
6532 # named choice is defined in multiple locations to add on symbols). It
6533 # looks confusing, and the menuconfig already shows all choice symbols if
6534 # you enter the choice at some location with a prompt.
6538 node.item.__class__ is not Choice:
6581 # Finalizes a choice, marking each symbol whose menu node has the choice as
6582 # the parent as a choice symbol, and automatically determining types if not
6585 choice = node.item
6590 cur.item.choice = choice
6591 choice.syms.append(cur.item)
6594 # If no type is specified for the choice, its type is that of
6595 # the first choice item with a specified type
6596 if not choice.orig_type:
6597 for item in choice.syms:
6599 choice.orig_type = item.orig_type
6602 # Each choice item of UNKNOWN type gets the type of the choice
6603 for sym in choice.syms:
6605 sym.orig_type = choice.orig_type
6616 # 2. When a symbol/choice is first visited, _visited is set to 1, meaning
6618 # search then continues from the symbol/choice.
6620 # 3. If we run into a symbol/choice X with _visited already set to 1,
6625 # 4. Once a symbol/choice and all its dependencies (or dependents in this
6630 # This saves work if we run into the symbol/choice again in later calls
6633 # Choices complicate things, as every choice symbol depends on every other
6634 # choice symbol in a sense. When a choice is "entered" via a choice symbol
6635 # X, we visit all choice symbols from the choice except X, and prevent
6636 # immediately revisiting the choice with a flag (ignore_choice).
6647 # Choices show up in Symbol._dependents when the choice has the
6651 # Since we aren't entering the choice via a choice symbol, all
6652 # choice symbols need to be checked, hence the None.
6654 if dep.__class__ is Choice \
6661 if sym.choice and not ignore_choice:
6662 loop = _check_dep_loop_choice(sym.choice, sym)
6683 def _check_dep_loop_choice(choice, skip): argument
6684 if not choice._visited:
6685 # choice._visited == 0, unvisited
6687 choice._visited = 1
6689 # Check for loops involving choice symbols. If we came here via a
6690 # choice symbol, skip that one, as we'd get a false positive
6691 # '<sym FOO> -> <choice> -> <sym FOO>' loop otherwise.
6692 for sym in choice.syms:
6694 # Prevent the choice from being immediately re-entered via the
6695 # "is a choice symbol" path by passing True
6699 return _found_dep_loop(loop, choice)
6701 # The choice is not part of a dependency loop
6702 choice._visited = 2
6707 if choice._visited == 2:
6708 # The choice was checked earlier and is already known to not be part of
6712 # choice._visited == 1, found a dependency loop. Return the choice as the
6714 return (choice,)
6720 # Is the symbol/choice 'cur' where the loop started?
6733 if item.__class__ is Symbol and item.choice:
6734 msg += "the choice symbol "
6740 # Symbol/Choice._dependents sets for recursive dependency detection, we
6874 # Constant representing that there's no cached choice selection. This is
6961 "choice": _T_CHOICE,
7030 # Symbol/choice types. UNKNOWN is 0 (falsy) to simplify some checks.
7138 Choice,