From 416083ad78ea17d765a993d87c1a46325b908dc5 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 28 Jan 2018 06:20:01 +0100 Subject: Flag constant symbols where they're not allowed Might break U-Boot if they ever upgrade Kconfiglib, because they have a 'select y' in there (which the C tools don't flag since they only look for quotes), but it's a one-line fix. --- kconfiglib.py | 25 +++++++++++++++++++------ tests/Kwtf | 18 ------------------ testsuite.py | 7 ------- 3 files changed, 19 insertions(+), 31 deletions(-) delete mode 100644 tests/Kwtf diff --git a/kconfiglib.py b/kconfiglib.py index 8c5dcf6..a10cbdf 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1397,6 +1397,8 @@ class Kconfig(object): # The functions below are just _next_token() with extra syntax checking. # Inlining _next_token() and _peek_token() into them saves a few % of # parsing time. + # + # See the 'Intro to expressions' section for what a constant symbol is. def _expect_sym(self): self._tokens_i += 1 @@ -1407,12 +1409,21 @@ class Kconfig(object): return token - def _expect_sym_and_eol(self): + def _expect_nonconst_sym(self): self._tokens_i += 1 token = self._tokens[self._tokens_i] - if not isinstance(token, Symbol): - self._parse_error("expected symbol") + if not isinstance(token, Symbol) or token.is_constant: + self._parse_error("expected nonconstant symbol") + + return token + + def _expect_nonconst_sym_and_eol(self): + self._tokens_i += 1 + token = self._tokens[self._tokens_i] + + if not isinstance(token, Symbol) or token.is_constant: + self._parse_error("expected nonconstant symbol") if self._tokens[self._tokens_i + 1] is not None: self._parse_error("extra tokens at end of line") @@ -1527,7 +1538,7 @@ class Kconfig(object): if t0 in (_T_CONFIG, _T_MENUCONFIG): # The tokenizer allocates Symbol objects for us - sym = self._expect_sym_and_eol() + sym = self._expect_nonconst_sym_and_eol() self.defined_syms.append(sym) node = MenuNode() @@ -1777,13 +1788,15 @@ class Kconfig(object): if not isinstance(node.item, Symbol): self._parse_error("only symbols can select") - selects.append((self._expect_sym(), self._parse_cond())) + selects.append((self._expect_nonconst_sym(), + self._parse_cond())) elif t0 == _T_IMPLY: if not isinstance(node.item, Symbol): self._parse_error("only symbols can imply") - implies.append((self._expect_sym(), self._parse_cond())) + implies.append((self._expect_nonconst_sym(), + self._parse_cond())) elif t0 == _T_DEFAULT: defaults.append((self._parse_expr(False), self._parse_cond())) diff --git a/tests/Kwtf b/tests/Kwtf deleted file mode 100644 index 85ae57e..0000000 --- a/tests/Kwtf +++ /dev/null @@ -1,18 +0,0 @@ -config A - bool - select n - select m - select y - select UNAME_RELEASE - select "n" - select "m" - select "y" - select "UNAME_RELEASE" - imply n - imply m - imply y - imply UNAME_RELEASE - imply "n" - imply "m" - imply "y" - imply "UNAME_RELEASE" diff --git a/testsuite.py b/testsuite.py index 6663f32..a250c6e 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1694,13 +1694,6 @@ g verify_is_normal_choice_symbol("WS9") - print("Testing compatibility with weird selects/implies") - - # Check that Kconfiglib doesn't crash for stuff like 'select n' (seen in - # U-Boot). These probably originate from misunderstandings of how Kconfig - # works. - Kconfig("Kconfiglib/tests/Kwtf") - print("\nAll selftests passed\n" if all_passed else "\nSome selftests failed\n") -- cgit v1.2.3