summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kconfiglib.py86
1 files changed, 30 insertions, 56 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index b268808..7692f89 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1235,7 +1235,7 @@ class Kconfig(object):
.format(self.config_prefix, sym.name,
escape(val)))
- elif sym.orig_type in _INT_HEX:
+ else: # sym.orig_type in _INT_HEX:
if sym.orig_type is HEX and \
not val.startswith(("0x", "0X")):
val = "0x" + val
@@ -1243,11 +1243,6 @@ class Kconfig(object):
f.write("#define {}{} {}\n"
.format(self.config_prefix, sym.name, val))
- else:
- _internal_error("Internal error while creating C "
- 'header: unknown type "{}".'
- .format(sym.orig_type))
-
def write_config(self, filename,
header="# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n"):
r"""
@@ -3330,9 +3325,7 @@ class Kconfig(object):
"default value for string symbol "
+ _name_and_loc(sym))
- elif sym.orig_type in _INT_HEX and \
- not num_ok(default, sym.orig_type):
-
+ elif not num_ok(default, sym.orig_type): # INT/HEX
self._warn("the {0} symbol {1} has a non-{0} default {2}"
.format(TYPE_TO_STR[sym.orig_type],
_name_and_loc(sym),
@@ -4095,12 +4088,9 @@ class Symbol(object):
return "{}{}={}\n" \
.format(self.kconfig.config_prefix, self.name, val)
- if self.orig_type is STRING:
- return '{}{}="{}"\n' \
- .format(self.kconfig.config_prefix, self.name, escape(val))
-
- _internal_error("Internal error while creating .config: unknown "
- 'type "{}".'.format(self.orig_type))
+ # sym.orig_type is STRING
+ return '{}{}="{}"\n' \
+ .format(self.kconfig.config_prefix, self.name, escape(val))
def set_value(self, value):
"""
@@ -5180,16 +5170,9 @@ class MenuNode(object):
elif self.item is MENU:
fields.append("menu node for menu")
- elif self.item is COMMENT:
+ else: # self.item is COMMENT
fields.append("menu node for comment")
- elif not self.item:
- fields.append("menu node for if (should not appear in the final "
- " tree)")
-
- else:
- _internal_error("unable to determine type in MenuNode.__repr__()")
-
if self.prompt:
fields.append('prompt "{}" (visibility {})'
.format(self.prompt[0],
@@ -5388,7 +5371,7 @@ class KconfigError(Exception):
KconfigSyntaxError = KconfigError # Backwards compatibility
class InternalError(Exception):
- "Exception raised for internal errors"
+ "Never raised. Kept around for backwards compatibility."
# Workaround:
#
@@ -5437,35 +5420,33 @@ def expr_value(expr):
if expr[0] is NOT:
return 2 - expr_value(expr[1])
- if expr[0] in _RELATIONS:
- # Implements <, <=, >, >= comparisons as well. These were added to
- # kconfig in 31847b67 (kconfig: allow use of relations other than
- # (in)equality).
+ # Relation
+ #
+ # Implements <, <=, >, >= comparisons as well. These were added to
+ # kconfig in 31847b67 (kconfig: allow use of relations other than
+ # (in)equality).
- rel, v1, v2 = expr
+ rel, v1, v2 = expr
- # If both operands are strings...
- if v1.orig_type is STRING and v2.orig_type is STRING:
- # ...then compare them lexicographically
+ # If both operands are strings...
+ if v1.orig_type is STRING and v2.orig_type is STRING:
+ # ...then compare them lexicographically
+ comp = _strcmp(v1.str_value, v2.str_value)
+ else:
+ # Otherwise, try to compare them as numbers
+ try:
+ comp = _sym_to_num(v1) - _sym_to_num(v2)
+ except ValueError:
+ # Fall back on a lexicographic comparison if the operands don't
+ # parse as numbers
comp = _strcmp(v1.str_value, v2.str_value)
- else:
- # Otherwise, try to compare them as numbers
- try:
- comp = _sym_to_num(v1) - _sym_to_num(v2)
- except ValueError:
- # Fall back on a lexicographic comparison if the operands don't
- # parse as numbers
- comp = _strcmp(v1.str_value, v2.str_value)
- if rel is EQUAL: return 2*(comp == 0)
- if rel is UNEQUAL: return 2*(comp != 0)
- if rel is LESS: return 2*(comp < 0)
- if rel is LESS_EQUAL: return 2*(comp <= 0)
- if rel is GREATER: return 2*(comp > 0)
- if rel is GREATER_EQUAL: return 2*(comp >= 0)
-
- _internal_error("Internal error while evaluating expression: "
- "unknown operation {}.".format(expr[0]))
+ if rel is EQUAL: return 2*(comp == 0)
+ if rel is UNEQUAL: return 2*(comp != 0)
+ if rel is LESS: return 2*(comp < 0)
+ if rel is LESS_EQUAL: return 2*(comp <= 0)
+ if rel is GREATER: return 2*(comp > 0)
+ return 2*(comp >= 0) # rel is GREATER_EQUAL
def standard_sc_expr_str(sc):
"""
@@ -5795,13 +5776,6 @@ def _touch_dep_file(sym_name):
os.close(os.open(
sym_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644))
-def _internal_error(msg):
- raise InternalError(
- msg +
- "\nSorry! You may want to send an email to ulfalizer a.t Google's "
- "email service to tell me about this. Include the message above and "
- "the stack trace and describe what you were doing.")
-
def _decoding_error(e, filename, macro_linenr=None):
# Gives the filename and context for UnicodeDecodeError's, which are a pain
# to debug otherwise. 'e' is the UnicodeDecodeError object.