kconfig: fix relational operators for bool and tristate symbols

Since commit 31847b67bec0 ("kconfig: allow use of relations other than
(in)equality") it is possible to use relational operators in Kconfig
statements. However, those operators give unexpected results when
applied to bool/tristate values:

(n < y) = y (correct)
(m < y) = y (correct)
(n < m) = n (wrong)

This happens because relational operators process bool and tristate
symbols as strings and m sorts before n. It makes little sense to do a
lexicographical compare on bool and tristate values though.

Documentation/kbuild/kconfig-language.txt states that expression can have
a value of 'n', 'm' or 'y' (or 0, 1, 2 respectively for calculations).
Let's make it so for relational comparisons with bool/tristate
expressions as well and document them. If at least one symbol is an
actual string then the lexicographical compare works just as before.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

authored by Nicolas Pitre and committed by Masahiro Yamada 9059a349 cfe17c9b

+19 -9
+15 -8
Documentation/kbuild/kconfig-language.txt
··· 200 200 <expr> ::= <symbol> (1) 201 201 <symbol> '=' <symbol> (2) 202 202 <symbol> '!=' <symbol> (3) 203 - '(' <expr> ')' (4) 204 - '!' <expr> (5) 205 - <expr> '&&' <expr> (6) 206 - <expr> '||' <expr> (7) 203 + <symbol1> '<' <symbol2> (4) 204 + <symbol1> '>' <symbol2> (4) 205 + <symbol1> '<=' <symbol2> (4) 206 + <symbol1> '>=' <symbol2> (4) 207 + '(' <expr> ')' (5) 208 + '!' <expr> (6) 209 + <expr> '&&' <expr> (7) 210 + <expr> '||' <expr> (8) 207 211 208 212 Expressions are listed in decreasing order of precedence. 209 213 ··· 218 214 otherwise 'n'. 219 215 (3) If the values of both symbols are equal, it returns 'n', 220 216 otherwise 'y'. 221 - (4) Returns the value of the expression. Used to override precedence. 222 - (5) Returns the result of (2-/expr/). 223 - (6) Returns the result of min(/expr/, /expr/). 224 - (7) Returns the result of max(/expr/, /expr/). 217 + (4) If value of <symbol1> is respectively lower, greater, lower-or-equal, 218 + or greater-or-equal than value of <symbol2>, it returns 'y', 219 + otherwise 'n'. 220 + (5) Returns the value of the expression. Used to override precedence. 221 + (6) Returns the result of (2-/expr/). 222 + (7) Returns the result of min(/expr/, /expr/). 223 + (8) Returns the result of max(/expr/, /expr/). 225 224 226 225 An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2 227 226 respectively for calculations). A menu entry becomes visible when its
+4 -1
scripts/kconfig/expr.c
··· 893 893 switch (type) { 894 894 case S_BOOLEAN: 895 895 case S_TRISTATE: 896 - return k_string; 896 + val->s = !strcmp(str, "n") ? 0 : 897 + !strcmp(str, "m") ? 1 : 898 + !strcmp(str, "y") ? 2 : -1; 899 + return k_signed; 897 900 case S_INT: 898 901 val->s = strtoll(str, &tail, 10); 899 902 kind = k_signed;