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