rewriter: Minor code cleanup
# or an interpreter-based tool
from . import AstInterpreter
-from .. import compilers, environment, mesonlib, mparser, optinterpreter
+from .. import compilers, environment, mesonlib, optinterpreter
from .. import coredata as cdata
from ..interpreterbase import InvalidArguments
from ..build import Executable, Jar, SharedLibrary, SharedModule, StaticLibrary
+from ..mparser import ArithmeticNode, ArrayNode, ElementaryNode, IdNode, FunctionNode, StringNode
import os
build_target_functions = ['executable', 'jar', 'library', 'shared_library', 'shared_module', 'static_library', 'both_libraries']
@@ -77,7 +78,7 @@ class IntrospectionInterpreter(AstInterpreter):
proj_name = args[0]
proj_vers = kwargs.get('version', 'undefined')
proj_langs = self.flatten_args(args[1:])
- if isinstance(proj_vers, mparser.ElementaryNode):
+ if isinstance(proj_vers, ElementaryNode):
proj_vers = proj_vers.value
if not isinstance(proj_vers, str):
proj_vers = 'undefined'
@@ -96,7 +97,7 @@ class IntrospectionInterpreter(AstInterpreter):
if not self.is_subproject() and 'subproject_dir' in kwargs:
spdirname = kwargs['subproject_dir']
- if isinstance(spdirname, mparser.ElementaryNode):
+ if isinstance(spdirname, ElementaryNode):
self.subproject_dir = spdirname.value
if not self.is_subproject():
self.project_data['subprojects'] = []
@@ -155,25 +156,25 @@ class IntrospectionInterpreter(AstInterpreter):
while srcqueue:
curr = srcqueue.pop(0)
arg_node = None
- if isinstance(curr, mparser.FunctionNode):
+ if isinstance(curr, FunctionNode):
arg_node = curr.args
- elif isinstance(curr, mparser.ArrayNode):
+ elif isinstance(curr, ArrayNode):
arg_node = curr.args
- elif isinstance(curr, mparser.IdNode):
+ elif isinstance(curr, IdNode):
# Try to resolve the ID and append the node to the queue
id = curr.value
if id in self.assignments and self.assignments[id]:
tmp_node = self.assignments[id][0]
- if isinstance(tmp_node, (mparser.ArrayNode, mparser.IdNode, mparser.FunctionNode)):
+ if isinstance(tmp_node, (ArrayNode, IdNode, FunctionNode)):
srcqueue += [tmp_node]
- elif isinstance(curr, mparser.ArithmeticNode):
+ elif isinstance(curr, ArithmeticNode):
srcqueue += [curr.left, curr.right]
if arg_node is None:
continue
- elemetary_nodes = list(filter(lambda x: isinstance(x, (str, mparser.StringNode)), arg_node.arguments))
- srcqueue += list(filter(lambda x: isinstance(x, (mparser.FunctionNode, mparser.ArrayNode, mparser.IdNode, mparser.ArithmeticNode)), arg_node.arguments))
+ elemetary_nodes = list(filter(lambda x: isinstance(x, (str, StringNode)), arg_node.arguments))
+ srcqueue += list(filter(lambda x: isinstance(x, (FunctionNode, ArrayNode, IdNode, ArithmeticNode)), arg_node.arguments))
# Pop the first element if the function is a build target function
- if isinstance(curr, mparser.FunctionNode) and curr.func_name in build_target_functions:
+ if isinstance(curr, FunctionNode) and curr.func_name in build_target_functions:
elemetary_nodes.pop(0)
if elemetary_nodes:
source_nodes += [curr]
@@ -233,7 +234,7 @@ class IntrospectionInterpreter(AstInterpreter):
if 'target_type' not in kwargs:
return
target_type = kwargs.pop('target_type')
- if isinstance(target_type, mparser.ElementaryNode):
+ if isinstance(target_type, ElementaryNode):
target_type = target_type.value
if target_type == 'executable':
return self.build_target(node, args, kwargs, Executable)
