-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBeanFromC#.awk
More file actions
103 lines (97 loc) · 2.65 KB
/
BeanFromC#.awk
File metadata and controls
103 lines (97 loc) · 2.65 KB
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
#/bin/awk -f
BEGIN {
text = ""
classes = ""
primitives["string"] = "QString"
primitives["List"] = "QList"
primitives["Uri"] = "QString"
primitives["Dictionary"] = "QMap"
print "#include <qrestbean.h>\n"
}
/public partial class / {
class = substr($4,1,length($4)-1)
text = "class " class " : public QRestBean<" class ">\n"
text = text "{\n"
text = text " Q_GADGET\n"
depend = ""
}
/ public / {
sub(".",substr(tolower($3),1,1),$3)
if (match($2, /.+\<.+\>/)) {
i = index($2, "<");
stun = substr($2, 1, i - 1)
args = substr($2, i + 1, length($2) - i - 1)
split(args, args2, ",")
for (a in args2) {
arg = args2[a];
if (primitives[arg]) {
sub(arg, primitives[arg], args)
} else {
depend = depend " " arg
if (!match(templates[arg], stun))
templates[arg] = templates[arg] " " stun
}
}
if (primitives[stun])
sub(stun, primitives[stun], $2)
} else {
if (primitives[$2])
$2 = primitives[$2]
else
depend = depend " " $2
}
props[$3] = $2
}
/^}/ {
text = text "public:\n"
for (p in props) {
text = text " Q_PROPERTY(" props[p] " " p " MEMBER " p ")\n"
}
text = text "public:\n"
for (p in props) {
text = text " " props[p] " " p ";\n"
}
delete props
text = text "};\n\n"
text = text "Q_DECLARE_METATYPE(" class ")\n"
texts[class] = text;
depends[class] = depend
classes = classes " " class
}
function print_class(c, d, depends2, templates2)
{
if (texts[c]) {
lastclass = c
#if (!depends[c])
# print "no dep " c;
#print c "->" depends[c]
split(depends[c], depends2, " ");
delete depends[c]
for (d in depends2) {
#print d ": " depends2[d]
print_class(depends2[d])
}
print texts[c]
delete texts[c]
split(templates[c], templates2, " ");
for (d in templates2) {
template = template " " c "::register" templates2[d] "();\n"
}
print
delete templates[c]
} else {
#print "no class " c
}
}
END {
template = template "static struct XXXInitializer : QRestBeanInitializer<XXXInitializer> {\n"
template = template " static void doInit() {\n"
split(classes, classes2, " ");
for (c in classes2) {
print_class(classes2[c])
}
template = template " }\n"
template = template "} initXXX;\n"
gsub("XXX", lastclass, template)
print template
}