-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmksccode
executable file
·147 lines (112 loc) · 3.09 KB
/
mksccode
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
import sys
import sip
class Wrapper:
def __init__(self, type):
self.type = type
self.superclass = None
self.subclasses = []
self.index = -1
def dump_tree(base=None, indent=-1):
if base:
print "%s%s" % (" " * indent, base.__name__)
scl = wrappers[base].subclasses
else:
scl = base_wrappers
for w in scl:
dump_tree(w.type, indent + 1)
def output():
def output_pass1(scl, index=0):
for w in scl:
w.index = index
index += 1
for w in scl:
index = output_pass1(w.subclasses, index)
return index
def output_pass2(scl):
for w in scl:
name = w.type.__name__
if w.subclasses:
yes = w.subclasses[0].index
else:
yes = -1
if w.superclass is None:
if base_wrappers[-1] is w:
no = -1
else:
no = w.index + 1
elif w.superclass.subclasses[-1] is w:
no = -1
else:
no = w.index + 1
print " {sipName_%s, &sipClass_%s, %d, %d}," % (name, name, yes, no)
for w in scl:
output_pass2(w.subclasses)
print "%ConvertToSubClassCode"
print " static struct class_graph {"
print " char *name;"
print " sipWrapperType **type;"
print " int yes, no;"
print " } graph[] = {"
output_pass1(base_wrappers)
output_pass2(base_wrappers)
print " };"
print " int i = 0;"
print " sipClass = NULL;"
print " do {"
print " struct class_graph *cg = &graph[i];"
print " if (cg->name != NULL && sipCpp->inherits(cg->name)) {"
print " sipClass = *cg->type;"
print " i = cg->yes;"
print " } else {"
print " i = cg->no;"
print " }"
print " } while (i >= 0);"
print "%End"
def import_module(name):
mod = __import__(name)
for chunk in name.split('.')[1:]:
mod = getattr(mod, chunk)
return mod
def usage():
print "Usage: %s [-d] module" % sys.argv[0]
print
print "Examples:"
print "./mksccode Qwt4"
print "./mksccode Qwt5"
print "./mksccode PyQt4.Qwt5"
sys.exit(1)
if len(sys.argv) == 1:
usage()
argv = sys.argv[1:]
if argv and argv[0] == "-d":
dump = True
argv = argv[1:]
else:
dump = False
if len(argv) != 1:
usage()
mod = import_module(argv[0])
wrappers = {}
for o in mod.__dict__.values():
if type(o) is sip.wrappertype:
for sup in o.__mro__[1:]:
if sup.__name__ == "QObject":
wrappers[o] = Wrapper(o)
break
base_wrappers = []
for w in wrappers.values():
parent = w.type.__mro__[1]
try:
w.superclass = wrappers[parent]
except KeyError:
base_wrappers.append(w)
else:
wrappers[parent].subclasses.append(w)
if dump:
dump_tree()
else:
output()
# Local Variables: ***
# mode: python ***
# End: ***