3 """ This file generates a c file from a list of cpp prototypes. """
7 skip_objects = ['fft', 'pvoc', 'filter', 'filterbank', 'biquad']
9 cpp_output = [l.strip() for l in os.popen('cpp -I ../../build/default/src ../../src/aubio.h').readlines()]
11 cpp_output = filter(lambda y: len(y) > 1, cpp_output)
12 cpp_output = filter(lambda y: not y.startswith('#'), cpp_output)
16 if i >= len(cpp_output): break
17 if cpp_output[i-1].endswith(',') or cpp_output[i-1].endswith('{') or cpp_output[i].startswith('}'):
18 cpp_output[i] = cpp_output[i-1] + ' ' + cpp_output[i]
23 typedefs = filter(lambda y: y.startswith ('typedef struct _aubio'), cpp_output)
25 objects = [a.split()[3][:-1] for a in typedefs]
27 print "-- INFO: %d objects in total" % len(objects)
29 for object in objects:
32 if object[-2:] == '_t':
33 object_name = object[:-2]
36 print "-- WARNING: %s does not end in _t" % object
38 if object_name[:len('aubio_')] != 'aubio_':
39 print "-- WARNING: %s does not start n aubio_" % object
41 print "-- INFO: looking at", object_name
42 object_methods = filter(lambda x: object in x, cpp_output)
43 object_methods = [a.strip() for a in object_methods]
44 object_methods = filter(lambda x: not x.startswith('typedef'), object_methods)
45 #for method in object_methods:
48 new_methods = filter(lambda x: 'new_'+object_name in x, object_methods)
49 if len(new_methods) > 1:
50 print "-- WARNING: more than one new method for", object_name
51 for method in new_methods:
53 elif len(new_methods) < 1:
54 print "-- WARNING: no new method for", object_name
56 for method in new_methods:
59 del_methods = filter(lambda x: 'del_'+object_name in x, object_methods)
60 if len(del_methods) > 1:
61 print "-- WARNING: more than one del method for", object_name
62 for method in del_methods:
64 elif len(del_methods) < 1:
65 print "-- WARNING: no del method for", object_name
67 do_methods = filter(lambda x: object_name+'_do' in x, object_methods)
68 if len(do_methods) > 1:
70 #print "-- WARNING: more than one do method for", object_name
71 #for method in do_methods:
73 elif len(do_methods) < 1:
74 print "-- WARNING: no do method for", object_name
76 for method in do_methods:
79 # check do methods return void
80 for method in do_methods:
81 if (method.split()[0] != 'void'):
82 print "-- ERROR: _do method does not return void:", method
84 get_methods = filter(lambda x: object_name+'_get_' in x, object_methods)
86 set_methods = filter(lambda x: object_name+'_set_' in x, object_methods)
87 for method in set_methods:
88 if (method.split()[0] != 'uint_t'):
89 print "-- ERROR: _set method does not return uint_t:", method
91 other_methods = filter(lambda x: x not in new_methods, object_methods)
92 other_methods = filter(lambda x: x not in del_methods, other_methods)
93 other_methods = filter(lambda x: x not in do_methods, other_methods)
94 other_methods = filter(lambda x: x not in get_methods, other_methods)
95 other_methods = filter(lambda x: x not in set_methods, other_methods)
97 if len(other_methods) > 0:
98 print "-- WARNING: some methods for", object_name, "were unidentified"
99 for method in other_methods:
103 if not os.path.isdir('generated'): os.mkdir('generated')
104 from gen_pyobject import *
105 short_name = object_name[len('aubio_'):]
106 if short_name in skip_objects:
107 print "-- INFO: skipping object", short_name
110 s = gen_new_init(new_methods[0], short_name)
111 s += gen_do(do_methods[0], short_name)
112 s += gen_members(new_methods[0], short_name)
113 s += gen_methods(get_methods, set_methods, short_name)
114 s += gen_finish(short_name)
115 fd = open('generated/gen-'+short_name+'.c', 'w')
117 #except Exception, e:
118 # print "-- ERROR:", type(e), str(e), "in", short_name