summaryrefslogtreecommitdiff
path: root/codegen/scanvirtuals.py
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 02:21:24 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 02:21:24 +0900
commitc6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3 (patch)
tree1436172370a45714687122f914354ad167a2f528 /codegen/scanvirtuals.py
parentf7d643cbb2184346b6f8d26091eb7eb38c6bbfe1 (diff)
downloadpygobject2-c6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3.tar.gz
pygobject2-c6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3.tar.bz2
pygobject2-c6b9e84f2f7f8c85939a8e5ff5d8a5aa067cecf3.zip
Diffstat (limited to 'codegen/scanvirtuals.py')
-rwxr-xr-xcodegen/scanvirtuals.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/codegen/scanvirtuals.py b/codegen/scanvirtuals.py
new file mode 100755
index 0000000..c108737
--- /dev/null
+++ b/codegen/scanvirtuals.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+import re
+import sys
+
+
+def main():
+ rx = re.compile(r'^\s*([\w\s\*]+)\(\s*\*\s*(\w+)\s*\)\s*\(([^()]*)\);',
+ re.DOTALL|re.MULTILINE)
+ for f in sys.argv[1:]:
+ #print ";; From", f
+ buf = file(f).read()
+ for m in rx.findall(buf):
+ return_type = m[0].strip()
+ if 'typedef' in return_type:
+ continue
+ if return_type == 'void':
+ return_type = 'none'
+ return_type = return_type.replace(' ', '')
+ virtual_name = m[1]
+ if 'reserved' in virtual_name:
+ continue
+ params = []
+ if not m[2]:
+ print >> sys.stderr, repr(m)
+ continue
+ for param in map(str.strip, m[2].split(',')):
+ if '*' in param:
+ tokens = param.split('*')
+ ptype = tokens[0].strip() + '*'*(len(tokens) - 1)
+ pname = tokens[-1].strip()
+ else:
+ if param == 'void':
+ continue
+ ptype, pname = map(str.strip, param.split())
+ ptype = ptype.replace('const ', 'const-')
+ while '[]' in pname:
+ pname = pname.replace('[]', '')
+ ptype += '[]'
+ params.append((ptype, pname))
+ if not params:
+ continue
+ objname = params[0][0].replace('*', '')
+ print '(define-virtual', virtual_name
+ print ' (of-object "%s")' % objname
+ print ' (return-type "%s")' % return_type
+ if len(params) > 1:
+ print ' (parameters'
+ for param in params[1:]:
+ print ' \'("%s" "%s")' % param
+ print ' )'
+ print ')'
+
+if __name__ == '__main__':
+ main()