From 658a82651897676ab036d922b9603e81a5ba7333 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Tue, 30 Jul 2013 21:44:40 +0300 Subject: Can check if headers have functions of a given name. --- interpreter.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'interpreter.py') diff --git a/interpreter.py b/interpreter.py index 318f7b3..0025ec0 100644 --- a/interpreter.py +++ b/interpreter.py @@ -650,6 +650,7 @@ class CompilerHolder(InterpreterObject): 'sizeof': self.sizeof_method, 'has_header': self.has_header_method, 'run' : self.run_method, + 'has_function' : self.has_function_method, }) def run_method(self, args, kwargs): @@ -665,7 +666,25 @@ class CompilerHolder(InterpreterObject): def get_id_method(self, args, kwargs): return self.compiler.get_id() - + + + def has_function_method(self, args, kwargs): + if len(args) != 1: + raise InterpreterException('Has_function takes exactly one argument.') + funcname = args[0] + if not isinstance(funcname, str): + raise InterpreterException('Argument to has_function must be a string.') + prefix = kwargs.get('prefix', '') + if not isinstance(prefix, str): + raise InterpreterException('Prefix argument of has_function must be a string.') + had = self.compiler.has_function(funcname, prefix) + if had: + hadtxt = mlog.green('YES') + else: + hadtxt = mlog.red('NO') + mlog.log('Checking for function "', mlog.bold(funcname), '": ', hadtxt, sep='') + return had + def sizeof_method(self, args, kwargs): if len(args) != 1: raise InterpreterException('Sizeof takes exactly one argument.') @@ -688,7 +707,7 @@ class CompilerHolder(InterpreterObject): if not isinstance(string, str): raise InterpreterException('Argument to compiles() must be a string') return self.compiler.compiles(string) - + def has_header_method(self, args, kwargs): if len(args) != 1: raise InterpreterException('has_header method takes exactly one argument.') -- cgit v1.1