Can check for members in structures.

pull/15/head
Jussi Pakkanen 12 years ago
parent 6ba724c5c7
commit 44c0e22330
  1. 12
      environment.py
  2. 21
      interpreter.py
  3. 11
      test cases/common/44 has member/meson.build

@ -201,6 +201,18 @@ int main(int argc, char **argv) {
res = self.run(templ % (prefix, funcname))
return res.compiled
def has_member(self, typename, membername, prefix):
# This fails (returns true) if funcname is a ptr or a variable.
# The correct check is a lot more difficult.
# Fix this to do that eventually.
templ = '''%s
void foo() {
%s foo;
foo.%s;
};
'''
return self.compiles(templ % (prefix, typename, membername))
class CPPCompiler(CCompiler):
def __init__(self, exelist):
CCompiler.__init__(self, exelist)

@ -651,6 +651,7 @@ class CompilerHolder(InterpreterObject):
'has_header': self.has_header_method,
'run' : self.run_method,
'has_function' : self.has_function_method,
'has_member' : self.has_member_method,
})
def run_method(self, args, kwargs):
@ -667,6 +668,26 @@ class CompilerHolder(InterpreterObject):
def get_id_method(self, args, kwargs):
return self.compiler.get_id()
def has_member_method(self, args, kwargs):
if len(args) != 2:
raise InterpreterException('Has_member takes exactly two arguments.')
typename = args[0]
if not isinstance(typename, str):
raise InterpreterException('Name of type must be a string.')
membername = args[1]
if not isinstance(membername, str):
raise InterpreterException('Name of member 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_member(typename, membername, prefix)
if had:
hadtxt = mlog.green('YES')
else:
hadtxt = mlog.red('NO')
mlog.log('Checking whether type "', mlog.bold(typename),
'" has member "', mlog.bold(membername), '": ', hadtxt, sep='')
return had
def has_function_method(self, args, kwargs):
if len(args) != 1:

@ -0,0 +1,11 @@
project('has member', 'c')
cc = meson.get_compiler('c')
if not cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>')
error('Did not detect member that exists.')
endif
if cc.has_member('struct tm', 'tm_nonexistent', prefix : '#include<time.h>')
error('Not existing member found.')
endif
Loading…
Cancel
Save