aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2017-05-17 19:40:49 -0400
committerElliott Sales de Andrade <quantum.analyst@gmail.com>2017-05-17 19:43:39 -0400
commit30645ed54b4e08611ae4883137d774a4c02b0278 (patch)
tree18c12c2a637bb4e3fc95ad690b4999be2b34529c
parentc69d82795ce543dbba0fc4fd50356628f7afc62d (diff)
downloadmeson-30645ed54b4e08611ae4883137d774a4c02b0278.zip
meson-30645ed54b4e08611ae4883137d774a4c02b0278.tar.gz
meson-30645ed54b4e08611ae4883137d774a4c02b0278.tar.bz2
Remove extra casts on InterpreterBase.evaluate_statement.
The result of this method is always a "native" object, and code coverage (plus a manual inspection) shows that this conversion is never done.
-rw-r--r--mesonbuild/interpreter.py3
-rw-r--r--mesonbuild/interpreterbase.py44
2 files changed, 6 insertions, 41 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 987e32b..948a6d4 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2625,11 +2625,10 @@ different subdirectory.
raise InterpreterException('Tried to add non-existing source file %s.' % s)
def format_string(self, templ, args):
- templ = self.to_native(templ)
if isinstance(args, mparser.ArgumentNode):
args = args.arguments
for (i, arg) in enumerate(args):
- arg = self.to_native(self.evaluate_statement(arg))
+ arg = self.evaluate_statement(arg)
if isinstance(arg, bool): # Python boolean is upper case.
arg = str(arg).lower()
templ = templ.replace('@{}@'.format(i), str(arg))
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 86a6b47..2fe21d9 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -198,8 +198,6 @@ class InterpreterBase:
def evaluate_notstatement(self, cur):
v = self.evaluate_statement(cur.value)
- if isinstance(v, mparser.BooleanNode):
- v = v.value
if not isinstance(v, bool):
raise InterpreterException('Argument to "not" is not a boolean.')
return not v
@@ -217,16 +215,8 @@ class InterpreterBase:
self.evaluate_codeblock(node.elseblock)
def evaluate_comparison(self, node):
- v1 = self.evaluate_statement(node.left)
- v2 = self.evaluate_statement(node.right)
- if self.is_elementary_type(v1):
- val1 = v1
- else:
- val1 = v1.value
- if self.is_elementary_type(v2):
- val2 = v2
- else:
- val2 = v2.value
+ val1 = self.evaluate_statement(node.left)
+ val2 = self.evaluate_statement(node.right)
if node.ctype == '==':
return val1 == val2
elif node.ctype == '!=':
@@ -244,45 +234,35 @@ class InterpreterBase:
def evaluate_andstatement(self, cur):
l = self.evaluate_statement(cur.left)
- if isinstance(l, mparser.BooleanNode):
- l = l.value
if not isinstance(l, bool):
raise InterpreterException('First argument to "and" is not a boolean.')
if not l:
return False
r = self.evaluate_statement(cur.right)
- if isinstance(r, mparser.BooleanNode):
- r = r.value
if not isinstance(r, bool):
raise InterpreterException('Second argument to "and" is not a boolean.')
return r
def evaluate_orstatement(self, cur):
l = self.evaluate_statement(cur.left)
- if isinstance(l, mparser.BooleanNode):
- l = l.get_value()
if not isinstance(l, bool):
raise InterpreterException('First argument to "or" is not a boolean.')
if l:
return True
r = self.evaluate_statement(cur.right)
- if isinstance(r, mparser.BooleanNode):
- r = r.get_value()
if not isinstance(r, bool):
raise InterpreterException('Second argument to "or" is not a boolean.')
return r
def evaluate_uminusstatement(self, cur):
v = self.evaluate_statement(cur.value)
- if isinstance(v, mparser.NumberNode):
- v = v.value
if not isinstance(v, int):
raise InterpreterException('Argument to negation is not an integer.')
return -v
def evaluate_arithmeticstatement(self, cur):
- l = self.to_native(self.evaluate_statement(cur.left))
- r = self.to_native(self.evaluate_statement(cur.right))
+ l = self.evaluate_statement(cur.left)
+ r = self.evaluate_statement(cur.right)
if cur.operation == 'add':
try:
@@ -382,8 +362,6 @@ class InterpreterBase:
obj = self.evaluate_statement(invokable)
method_name = node.name
args = node.args
- if isinstance(obj, mparser.StringNode):
- obj = obj.get_value()
if isinstance(obj, str):
return self.string_method_call(obj, method_name, args)
if isinstance(obj, bool):
@@ -402,7 +380,6 @@ class InterpreterBase:
return obj.method_call(method_name, self.flatten(args), kwargs)
def bool_method_call(self, obj, method_name, args):
- obj = self.to_native(obj)
(posargs, _) = self.reduce_arguments(args)
if method_name == 'to_string':
if not posargs:
@@ -426,7 +403,6 @@ class InterpreterBase:
raise InterpreterException('Unknown method "%s" for a boolean.' % method_name)
def int_method_call(self, obj, method_name, args):
- obj = self.to_native(obj)
(posargs, _) = self.reduce_arguments(args)
if method_name == 'is_even':
if not posargs:
@@ -442,7 +418,6 @@ class InterpreterBase:
raise InterpreterException('Unknown method "%s" for an integer.' % method_name)
def string_method_call(self, obj, method_name, args):
- obj = self.to_native(obj)
(posargs, _) = self.reduce_arguments(args)
if method_name == 'strip':
return obj.strip()
@@ -534,8 +509,6 @@ class InterpreterBase:
raise InvalidArguments('Keyword argument name is not a string.')
a = args.kwargs[key]
reduced_kw[key] = self.evaluate_statement(a)
- if not isinstance(reduced_pos, list):
- reduced_pos = [reduced_pos]
self.argument_depth -= 1
return reduced_pos, reduced_kw
@@ -564,7 +537,6 @@ To specify a keyword argument, use : instead of =.''')
if not isinstance(var_name, str):
raise InvalidArguments('Tried to assign value to a non-variable.')
value = self.evaluate_statement(node.value)
- value = self.to_native(value)
if not self.is_assignable(value):
raise InvalidCode('Tried to assign an invalid value to variable.')
# For mutable objects we need to make a copy on assignment
@@ -593,12 +565,6 @@ To specify a keyword argument, use : instead of =.''')
return self.variables[varname]
raise InvalidCode('Unknown variable "%s".' % varname)
- def to_native(self, arg):
- if isinstance(arg, (mparser.StringNode, mparser.NumberNode,
- mparser.BooleanNode)):
- return arg.value
- return arg
-
def is_assignable(self, value):
return isinstance(value, (InterpreterObject, dependencies.Dependency,
str, int, list, mesonlib.File))
@@ -624,7 +590,7 @@ To specify a keyword argument, use : instead of =.''')
if len(args) != 2:
raise InvalidCode('Set_variable takes two arguments.')
varname = args[0]
- value = self.to_native(args[1])
+ value = args[1]
self.set_variable(varname, value)
# @noKwargs