From e02c01e0628507d46ab7e25e4fa1b84183a86712 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 25 Nov 2018 00:42:40 +0100 Subject: Move _TOKEN_TO_TYPE conversion into _set_type() Factors out some code. Also use a quick 'is not UNKNOWN' test first inside it, which will usually fail, since single-def symbols are more common. That avoids building a tuple too. --- kconfiglib.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index b482212..80a65ba 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2697,7 +2697,7 @@ class Kconfig(object): t0 = self._tokens[0] if t0 in _TYPE_TOKENS: - self._set_type(node, _TOKEN_TO_TYPE[t0]) + self._set_type(node, t0) if self._tokens[1] is not None: self._parse_prompt(node) @@ -2728,7 +2728,7 @@ class Kconfig(object): elif t0 in (_T_DEF_BOOL, _T_DEF_TRISTATE, _T_DEF_INT, _T_DEF_HEX, _T_DEF_STRING): - self._set_type(node, _TOKEN_TO_TYPE[t0]) + self._set_type(node, t0) node.defaults.append((self._parse_expr(False), self._parse_cond())) @@ -2831,8 +2831,14 @@ class Kconfig(object): self._reuse_tokens = True return - def _set_type(self, node, new_type): - if node.item.orig_type not in (UNKNOWN, new_type): + def _set_type(self, node, type_token): + new_type = _TOKEN_TO_TYPE[type_token] + + # The 'is not UNKNOWN' comparison will usually fail, since single-def + # symbols/choices are more common + if node.item.orig_type is not UNKNOWN and \ + node.item.orig_type is not new_type: + self._warn("{} defined with multiple types, {} will be used" .format(_name_and_loc(node.item), TYPE_TO_STR[new_type])) -- cgit v1.2.3