diff --git a/interpreter.py b/interpreter.py index db570c7e0..e12e4f21e 100755 --- a/interpreter.py +++ b/interpreter.py @@ -286,6 +286,8 @@ class Interpreter(): raise InvalidCode('Line %d: unknown variable "%s".' % (cur.lineno(), varname)) elif isinstance(cur, nodes.Comparison): return self.evaluate_comparison(cur) + elif isinstance(cur, nodes.ArrayStatement): + return self.evaluate_arraystatement(cur) else: raise InvalidCode("Line %d: Unknown statement." % cur.lineno()) @@ -394,7 +396,17 @@ class Interpreter(): c = ConfigureFile(self.subdir, args[0], args[1]) self.build.configure_files.append(c) + def flatten(self, args): + result = [] + for a in args: + if isinstance(a, list): + result = result + self.flatten(a) + else: + result.append(a) + return result + def build_target(self, node, args, targetclass): + args = self.flatten(args) for a in args: if not isinstance(a, str): raise InvalidArguments('Line %d: Argument %s is not a string.' % (node.lineno(), str(a))) @@ -421,7 +433,8 @@ class Interpreter(): if isinstance(value, InterpreterObject) or \ isinstance(value, environment.PkgConfigDependency) or\ isinstance(value, nodes.StringStatement) or\ - isinstance(value, nodes.BoolStatement): + isinstance(value, nodes.BoolStatement) or\ + isinstance(value, list): return True return False @@ -500,6 +513,11 @@ class Interpreter(): return val1 != val2 else: raise InvalidCode('You broke me.') + + def evaluate_arraystatement(self, cur): + arguments = self.reduce_arguments(cur.get_args()) + return arguments + if __name__ == '__main__': code = """project('myawesomeproject') message('I can haz text printed out?') diff --git a/nodes.py b/nodes.py index da2ab6c22..e141eba1e 100644 --- a/nodes.py +++ b/nodes.py @@ -99,6 +99,14 @@ class Comparison(Statement): def get_second(self): return self.second +class ArrayStatement(Statement): + def __init__(self, args, lineno): + Statement.__init__(self, lineno) + self.args = args + + def get_args(self): + return self.args + class StringStatement(Statement): def __init__(self, value, lineno): assert(type(value) == type('')) diff --git a/parser.py b/parser.py index ad2e87f62..ce01011aa 100755 --- a/parser.py +++ b/parser.py @@ -119,11 +119,15 @@ def p_statement_assign(t): 'statement : expression ASSIGN statement' t[0] = nodes.Assignment(t[1], t[3], t.lineno(1)) -def p_statement_equals(t): +def p_statement_comparison(t): '''statement : statement EQUALS statement | statement NEQUALS statement''' t[0] = nodes.Comparison(t[1], t[2], t[3], t.lineno(1)) +def p_statement_array(t): + '''statement : LBRACKET args RBRACKET''' + t[0] = nodes.ArrayStatement(t[2], t.lineno(1)) + def p_statement_func_call(t): 'statement : expression LPAREN args RPAREN' t[0] = nodes.FunctionCall(t[1], t[3], t.lineno(1)) diff --git a/test cases/20 array/builder.txt b/test cases/20 array/builder.txt new file mode 100644 index 000000000..f12ca5b73 --- /dev/null +++ b/test cases/20 array/builder.txt @@ -0,0 +1,6 @@ +project('array test', 'c') + +arr = ['func.c', 'prog.c'] + +exe = executable('prog', arr) +add_test('arr test', exe) diff --git a/test cases/20 array/func.c b/test cases/20 array/func.c new file mode 100644 index 000000000..741237235 --- /dev/null +++ b/test cases/20 array/func.c @@ -0,0 +1 @@ +int func() { return 0; } diff --git a/test cases/20 array/prog.c b/test cases/20 array/prog.c new file mode 100644 index 000000000..ad58a0b3a --- /dev/null +++ b/test cases/20 array/prog.c @@ -0,0 +1,3 @@ +extern int func(); + +int main(int argc, char **argv) { return func(); }