The final renaming.

pull/15/head
Jussi Pakkanen 11 years ago
parent 4ab3dc440b
commit 2502beccc9
  1. 6
      backends.py
  2. 86
      interpreter.py
  3. 0
      mparser.py
  4. 20
      optinterpreter.py

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import parsertest as mparser2 import mparser
import os, sys, re, pickle import os, sys, re, pickle
import environment, mlog import environment, mlog
from meson_install import InstallData from meson_install import InstallData
@ -39,7 +39,7 @@ def do_replacement(regex, line, confdata):
var = confdata.get(varname) var = confdata.get(varname)
if isinstance(var, str): if isinstance(var, str):
pass pass
elif isinstance(var, mparser2.StringNode): elif isinstance(var, mparser.StringNode):
var = var.value var = var.value
elif isinstance(var, int): elif isinstance(var, int):
var = str(var) var = str(var)
@ -60,7 +60,7 @@ def do_mesondefine(line, confdata):
v = confdata.get(varname) v = confdata.get(varname)
except KeyError: except KeyError:
return '/* undef %s */\n' % varname return '/* undef %s */\n' % varname
if isinstance(v, mparser2.BooleanNode): if isinstance(v, mparser.BooleanNode):
v = v.value v = v.value
if isinstance(v, bool): if isinstance(v, bool):
if v: if v:

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import parsertest as mparser2 import mparser
import environment import environment
import coredata import coredata
import dependencies import dependencies
@ -601,7 +601,7 @@ class Interpreter():
raise InvalidCode('Builder file is empty.') raise InvalidCode('Builder file is empty.')
assert(isinstance(code, str)) assert(isinstance(code, str))
try: try:
self.ast = mparser2.Parser(code).parse() self.ast = mparser.Parser(code).parse()
except coredata.MesonException as me: except coredata.MesonException as me:
me.file = environment.build_filename me.file = environment.build_filename
raise me raise me
@ -658,12 +658,12 @@ class Interpreter():
return self.variables return self.variables
def sanity_check_ast(self): def sanity_check_ast(self):
if not isinstance(self.ast, mparser2.CodeBlockNode): if not isinstance(self.ast, mparser.CodeBlockNode):
raise InvalidCode('AST is of invalid type. Possibly a bug in the parser.') raise InvalidCode('AST is of invalid type. Possibly a bug in the parser.')
if len(self.ast.lines) == 0: if len(self.ast.lines) == 0:
raise InvalidCode('No statements in code.') raise InvalidCode('No statements in code.')
first = self.ast.lines[0] first = self.ast.lines[0]
if not isinstance(first, mparser2.FunctionNode) or first.func_name != 'project': if not isinstance(first, mparser.FunctionNode) or first.func_name != 'project':
raise InvalidCode('First statement must be a call to project') raise InvalidCode('First statement must be a call to project')
def run(self): def run(self):
@ -672,7 +672,7 @@ class Interpreter():
def evaluate_codeblock(self, node): def evaluate_codeblock(self, node):
if node is None: if node is None:
return return
if not isinstance(node, mparser2.CodeBlockNode): if not isinstance(node, mparser.CodeBlockNode):
e = InvalidCode('Tried to execute a non-codeblock. Possibly a bug in the parser.') e = InvalidCode('Tried to execute a non-codeblock. Possibly a bug in the parser.')
e.lineno = node.lineno e.lineno = node.lineno
e.colno = node.colno e.colno = node.colno
@ -703,31 +703,31 @@ class Interpreter():
self.variables[varname] = variable self.variables[varname] = variable
def evaluate_statement(self, cur): def evaluate_statement(self, cur):
if isinstance(cur, mparser2.FunctionNode): if isinstance(cur, mparser.FunctionNode):
return self.function_call(cur) return self.function_call(cur)
elif isinstance(cur, mparser2.AssignmentNode): elif isinstance(cur, mparser.AssignmentNode):
return self.assignment(cur) return self.assignment(cur)
elif isinstance(cur, mparser2.MethodNode): elif isinstance(cur, mparser.MethodNode):
return self.method_call(cur) return self.method_call(cur)
elif isinstance(cur, mparser2.StringNode): elif isinstance(cur, mparser.StringNode):
return cur.value return cur.value
elif isinstance(cur, mparser2.BooleanNode): elif isinstance(cur, mparser.BooleanNode):
return cur.value return cur.value
elif isinstance(cur, mparser2.IfClauseNode): elif isinstance(cur, mparser.IfClauseNode):
return self.evaluate_if(cur) return self.evaluate_if(cur)
elif isinstance(cur, mparser2.IdNode): elif isinstance(cur, mparser.IdNode):
return self.get_variable(cur.value) return self.get_variable(cur.value)
elif isinstance(cur, mparser2.ComparisonNode): elif isinstance(cur, mparser.ComparisonNode):
return self.evaluate_comparison(cur) return self.evaluate_comparison(cur)
elif isinstance(cur, mparser2.ArrayNode): elif isinstance(cur, mparser.ArrayNode):
return self.evaluate_arraystatement(cur) return self.evaluate_arraystatement(cur)
elif isinstance(cur, mparser2.NumberNode): elif isinstance(cur, mparser.NumberNode):
return cur return cur
elif isinstance(cur, mparser2.AndNode): elif isinstance(cur, mparser.AndNode):
return self.evaluate_andstatement(cur) return self.evaluate_andstatement(cur)
elif isinstance(cur, mparser2.OrNode): elif isinstance(cur, mparser.OrNode):
return self.evaluate_orstatement(cur) return self.evaluate_orstatement(cur)
elif isinstance(cur, mparser2.NotNode): elif isinstance(cur, mparser.NotNode):
return self.evaluate_notstatement(cur) return self.evaluate_notstatement(cur)
else: else:
raise InvalidCode("Unknown statement.") raise InvalidCode("Unknown statement.")
@ -1046,7 +1046,7 @@ class Interpreter():
code = open(absname).read() code = open(absname).read()
assert(isinstance(code, str)) assert(isinstance(code, str))
try: try:
codeblock = mparser2.Parser(code).parse() codeblock = mparser.Parser(code).parse()
except coredata.MesonException as me: except coredata.MesonException as me:
me.file = buildfilename me.file = buildfilename
raise me raise me
@ -1113,7 +1113,7 @@ class Interpreter():
self.build.global_args[lang] = args self.build.global_args[lang] = args
def flatten(self, args): def flatten(self, args):
if isinstance(args, mparser2.StringNode): if isinstance(args, mparser.StringNode):
return args.value return args.value
if isinstance(args, str): if isinstance(args, str):
return args return args
@ -1124,7 +1124,7 @@ class Interpreter():
if isinstance(a, list): if isinstance(a, list):
rest = self.flatten(a) rest = self.flatten(a)
result = result + rest result = result + rest
elif isinstance(a, mparser2.StringNode): elif isinstance(a, mparser.StringNode):
result.append(a.value) result.append(a.value)
else: else:
result.append(a) result.append(a)
@ -1193,7 +1193,7 @@ class Interpreter():
return False return False
def assignment(self, node): def assignment(self, node):
assert(isinstance(node, mparser2.AssignmentNode)) assert(isinstance(node, mparser.AssignmentNode))
var_name = node.var_name var_name = node.var_name
if not isinstance(var_name, str): if not isinstance(var_name, str):
raise InvalidArguments('Tried to assign value to a non-variable.') raise InvalidArguments('Tried to assign value to a non-variable.')
@ -1207,27 +1207,27 @@ class Interpreter():
return value return value
def reduce_single(self, arg): def reduce_single(self, arg):
if isinstance(arg, mparser2.IdNode): if isinstance(arg, mparser.IdNode):
return self.get_variable(arg.value) return self.get_variable(arg.value)
elif isinstance(arg, str): elif isinstance(arg, str):
return arg return arg
elif isinstance(arg, mparser2.StringNode): elif isinstance(arg, mparser.StringNode):
return arg.value return arg.value
elif isinstance(arg, mparser2.FunctionNode): elif isinstance(arg, mparser.FunctionNode):
return self.function_call(arg) return self.function_call(arg)
elif isinstance(arg, mparser2.MethodNode): elif isinstance(arg, mparser.MethodNode):
return self.method_call(arg) return self.method_call(arg)
elif isinstance(arg, mparser2.BooleanNode): elif isinstance(arg, mparser.BooleanNode):
return arg.value return arg.value
elif isinstance(arg, mparser2.ArrayNode): elif isinstance(arg, mparser.ArrayNode):
return [self.reduce_single(curarg) for curarg in arg.args.arguments] return [self.reduce_single(curarg) for curarg in arg.args.arguments]
elif isinstance(arg, mparser2.NumberNode): elif isinstance(arg, mparser.NumberNode):
return arg.value return arg.value
else: else:
raise InvalidCode('Irreducible argument.') raise InvalidCode('Irreducible argument.')
def reduce_arguments(self, args): def reduce_arguments(self, args):
assert(isinstance(args, mparser2.ArgumentNode)) assert(isinstance(args, mparser.ArgumentNode))
if args.incorrect_order(): if args.incorrect_order():
raise InvalidArguments('All keyword arguments must be after positional arguments.') raise InvalidArguments('All keyword arguments must be after positional arguments.')
reduced_pos = [self.reduce_single(arg) for arg in args.arguments] reduced_pos = [self.reduce_single(arg) for arg in args.arguments]
@ -1247,15 +1247,15 @@ class Interpreter():
raise InterpreterException('Unknown method "%s" for a string.' % method_name) raise InterpreterException('Unknown method "%s" for a string.' % method_name)
def to_native(self, arg): def to_native(self, arg):
if isinstance(arg, mparser2.StringNode) or \ if isinstance(arg, mparser.StringNode) or \
isinstance(arg, mparser2.NumberNode) or \ isinstance(arg, mparser.NumberNode) or \
isinstance(arg, mparser2.BooleanNode): isinstance(arg, mparser.BooleanNode):
return arg.value return arg.value
return arg return arg
def format_string(self, templ, args): def format_string(self, templ, args):
templ = self.to_native(templ) templ = self.to_native(templ)
if isinstance(args, mparser2.ArgumentNode): if isinstance(args, mparser.ArgumentNode):
args = args.arguments args = args.arguments
for (i, arg) in enumerate(args): for (i, arg) in enumerate(args):
arg = self.to_native(self.reduce_single(arg)) arg = self.to_native(self.reduce_single(arg))
@ -1266,7 +1266,7 @@ class Interpreter():
def method_call(self, node): def method_call(self, node):
invokable = node.source_object invokable = node.source_object
if isinstance(invokable, mparser2.IdNode): if isinstance(invokable, mparser.IdNode):
object_name = invokable.value object_name = invokable.value
obj = self.get_variable(object_name) obj = self.get_variable(object_name)
else: else:
@ -1275,7 +1275,7 @@ class Interpreter():
if method_name == 'extract_objects' and self.environment.coredata.unity: if method_name == 'extract_objects' and self.environment.coredata.unity:
raise InterpreterException('Single object files can not be extracted in Unity builds.') raise InterpreterException('Single object files can not be extracted in Unity builds.')
args = node.args args = node.args
if isinstance(obj, mparser2.StringNode): if isinstance(obj, mparser.StringNode):
obj = obj.get_value() obj = obj.get_value()
if isinstance(obj, str): if isinstance(obj, str):
return self.string_method_call(obj, method_name, args) return self.string_method_call(obj, method_name, args)
@ -1285,7 +1285,7 @@ class Interpreter():
return obj.method_call(method_name, args, kwargs) return obj.method_call(method_name, args, kwargs)
def evaluate_if(self, node): def evaluate_if(self, node):
assert(isinstance(node, mparser2.IfClauseNode)) assert(isinstance(node, mparser.IfClauseNode))
for i in node.ifs: for i in node.ifs:
result = self.evaluate_statement(i.condition) result = self.evaluate_statement(i.condition)
if not(isinstance(result, bool)): if not(isinstance(result, bool)):
@ -1293,7 +1293,7 @@ class Interpreter():
if result: if result:
self.evaluate_codeblock(i.block) self.evaluate_codeblock(i.block)
return return
if not isinstance(node.elseblock, mparser2.EmptyNode): if not isinstance(node.elseblock, mparser.EmptyNode):
self.evaluate_codeblock(node.elseblock) self.evaluate_codeblock(node.elseblock)
def is_elementary_type(self, v): def is_elementary_type(self, v):
@ -1324,14 +1324,14 @@ class Interpreter():
def evaluate_andstatement(self, cur): def evaluate_andstatement(self, cur):
l = self.evaluate_statement(cur.left) l = self.evaluate_statement(cur.left)
if isinstance(l, mparser2.BooleanNode): if isinstance(l, mparser.BooleanNode):
l = l.value l = l.value
if not isinstance(l, bool): if not isinstance(l, bool):
raise InterpreterException('First argument to "and" is not a boolean.') raise InterpreterException('First argument to "and" is not a boolean.')
if not l: if not l:
return False return False
r = self.evaluate_statement(cur.right) r = self.evaluate_statement(cur.right)
if isinstance(r, mparser2.BooleanNode): if isinstance(r, mparser.BooleanNode):
r = r.value r = r.value
if not isinstance(r, bool): if not isinstance(r, bool):
raise InterpreterException('Second argument to "and" is not a boolean.') raise InterpreterException('Second argument to "and" is not a boolean.')
@ -1339,14 +1339,14 @@ class Interpreter():
def evaluate_orstatement(self, cur): def evaluate_orstatement(self, cur):
l = self.evaluate_statement(cur.left) l = self.evaluate_statement(cur.left)
if isinstance(l, mparser2.BooleanNode): if isinstance(l, mparser.BooleanNode):
l = l.get_value() l = l.get_value()
if not isinstance(l, bool): if not isinstance(l, bool):
raise InterpreterException('First argument to "or" is not a boolean.') raise InterpreterException('First argument to "or" is not a boolean.')
if l: if l:
return True return True
r = self.evaluate_statement(cur.right) r = self.evaluate_statement(cur.right)
if isinstance(r, mparser2.BooleanNode): if isinstance(r, mparser.BooleanNode):
r = r.get_value() r = r.get_value()
if not isinstance(r, bool): if not isinstance(r, bool):
raise InterpreterException('Second argument to "or" is not a boolean.') raise InterpreterException('Second argument to "or" is not a boolean.')
@ -1354,7 +1354,7 @@ class Interpreter():
def evaluate_notstatement(self, cur): def evaluate_notstatement(self, cur):
v = self.evaluate_statement(cur.value) v = self.evaluate_statement(cur.value)
if isinstance(v, mparser2.BooleanNode): if isinstance(v, mparser.BooleanNode):
v = v.value v = v.value
if not isinstance(v, bool): if not isinstance(v, bool):
raise InterpreterException('Argument to "not" is not a boolean.') raise InterpreterException('Argument to "not" is not a boolean.')

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import parsertest as mparser2 import mparser
import coredata import coredata
import os import os
@ -88,11 +88,11 @@ class OptionInterpreter:
def process(self, option_file): def process(self, option_file):
try: try:
ast = mparser2.Parser(open(option_file, 'r').read()).parse() ast = mparser.Parser(open(option_file, 'r').read()).parse()
except coredata.MesonException as me: except coredata.MesonException as me:
me.file = option_file me.file = option_file
raise me raise me
if not isinstance(ast, mparser2.CodeBlockNode): if not isinstance(ast, mparser.CodeBlockNode):
e = OptionException('Option file is malformed.') e = OptionException('Option file is malformed.')
e.lineno = ast.lineno() e.lineno = ast.lineno()
raise e raise e
@ -106,23 +106,23 @@ class OptionInterpreter:
raise e raise e
def reduce_single(self, arg): def reduce_single(self, arg):
if isinstance(arg, mparser2.IdNode): if isinstance(arg, mparser.IdNode):
return self.get_variable(arg.value) return self.get_variable(arg.value)
elif isinstance(arg, str): elif isinstance(arg, str):
return arg return arg
elif isinstance(arg, mparser2.StringNode): elif isinstance(arg, mparser.StringNode):
return arg.value return arg.value
elif isinstance(arg, mparser2.BooleanNode): elif isinstance(arg, mparser.BooleanNode):
return arg.value return arg.value
elif isinstance(arg, mparser2.ArrayNode): elif isinstance(arg, mparser.ArrayNode):
return [self.reduce_single(curarg) for curarg in arg.args.arguments] return [self.reduce_single(curarg) for curarg in arg.args.arguments]
elif isinstance(arg, mparser2.NumberNode): elif isinstance(arg, mparser.NumberNode):
return arg.get_value() return arg.get_value()
else: else:
raise OptionException('Arguments may only be string, int, bool, or array of those.') raise OptionException('Arguments may only be string, int, bool, or array of those.')
def reduce_arguments(self, args): def reduce_arguments(self, args):
assert(isinstance(args, mparser2.ArgumentNode)) assert(isinstance(args, mparser.ArgumentNode))
if args.incorrect_order(): if args.incorrect_order():
raise OptionException('All keyword arguments must be after positional arguments.') raise OptionException('All keyword arguments must be after positional arguments.')
reduced_pos = [self.reduce_single(arg) for arg in args.arguments] reduced_pos = [self.reduce_single(arg) for arg in args.arguments]
@ -135,7 +135,7 @@ class OptionInterpreter:
return (reduced_pos, reduced_kw) return (reduced_pos, reduced_kw)
def evaluate_statement(self, node): def evaluate_statement(self, node):
if not isinstance(node, mparser2.FunctionNode): if not isinstance(node, mparser.FunctionNode):
raise OptionException('Option file may only contain option definitions') raise OptionException('Option file may only contain option definitions')
func_name = node.func_name func_name = node.func_name
if func_name != 'option': if func_name != 'option':

Loading…
Cancel
Save