-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgir-parser.py
71 lines (60 loc) · 1.88 KB
/
gir-parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from xml.dom.minidom import *
dictionary = {}
with open("gtk.rules") as f:
for line in f:
if "\t" in line and not line.strip() == "":
dictionary[line.split()[0].strip()] = True
# print dictionary
# exit(0)
xml_glib = parse('/usr/share/gir-1.0/GLib-2.0.gir')
xml_gtk = parse('/usr/share/gir-1.0/Gtk-2.0.gir')
memory = []
def getAttr(node, attr):
try:
return node.attributes[attr].nodeValue
except:
return ""
def getType(node):
try:
t = node.getElementsByTagName('type')[0]
return t.attributes['c:type'].nodeValue
except:
t = node.getElementsByTagName('array')[0]
return 'array ' + t.attributes['c:type'].nodeValue
def getOwner(node):
try:
return node.attributes['transfer-ownership'].nodeValue
except:
return 'none'
print "functions:"
for func in xml_glib.getElementsByTagName('function') + xml_glib.getElementsByTagName('method') + xml_gtk.getElementsByTagName('function') + xml_gtk.getElementsByTagName('method'):
param_has_ptr = False
try:
for param in func.getElementsByTagName('parameter'):
p_type = getType(param)
if p_type == "gpointer" or "*" in p_type:
param_has_ptr = True
except:
pass
# ret = func.getElementsByTagName('return-value')[0]
# ret_type = getType(ret)
# if ret_type == "void":
# ret = 'noreturn'
# else:
# ret = 'return'
f_name = getAttr(func, 'c:identifier')
#if func.parentNode.nodeName == "record" or param_has_ptr:
ret = ' leak-ignore'
if f_name not in dictionary:
print "\t", f_name + "\t" + ret
# for methods in gir.getElementsByTagName('record'):
# for rec in gir.getElementsByTagName('record'):
# a = False
# for func in rec.getElementsByTagName('constructor'):
# ret = func.getElementsByTagName('return-value')[0]
# ret_type = getType(ret)
# if (ret_type == "gpointer" or "*" in ret_type) and "const" not in ret_type:
# a = True
# print getAttr(func, 'c:identifier'), ret_type
# if a:
# print rec.toxml()