diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-11-25 00:42:40 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-11-25 02:00:09 +0100 |
| commit | e02c01e0628507d46ab7e25e4fa1b84183a86712 (patch) | |
| tree | 60bce0d08239312e7cbf37f5affd0521cc353b24 /kconfiglib.py | |
| parent | 29d4489c80f7d63cb34208fc4bd526f56fadd299 (diff) | |
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.
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 14 |
1 files 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])) |
