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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
function printg( a )
{
printf a >> FILENAME ".h"
}
function doFunc( a )
{
gsub("attribute", "", $0)
nr = split($0, b, " ")
printg( "\t" )
# do method
i = 1
while ( i < nr && b[i + 1] != "(" )
{
printg( b[i++] )
printg( " " )
}
while ( i < nr && b[i + 1] != ");" )
{
if( b[i] == "in" )
{
if( b[i + 1] != "float" && b[i + 1] != "unsigned" && b[i+1] != "short" && b[i+1] != "bool" )
{
float = "ok"
printg( "const " )
}
else
float = "bad"
i++
while ( i + 1 < nr && b[i + 1] != "in" && b[i + 1] != ");" )
{
printg( b[i++] " " )
#if( b[ i ] != ");" ) printg( " " )
}
if( float == "ok" )
printg( "&" b[i++] )
else
printg( b[i++] )
if( i < nr ) printg( " " )
}
else
printg( b[i++] )
}
printg( ");\n" );
}
function doAttr( a, class )
{
sub( ";", "", a)
sub( "\r", "", a)
gsub("attribute", "", a)
nr = split(a, b, " ")
# do put method
printg( "\tvoid set" )
printg( toupper( substr( b[nr], 1, 1) ) )
printg( substr( b[nr], 2) "(" )
i = 1
if( b[i] != "float" && b[i] != "unsigned" && b[i] != "short" && b[i] != "bool" )
#if( b[i] != "float" && match( b[i], "unsigned") == 0)
{
float = "ok"
printg( "const " )
}
else
float = "bad"
while ( i < nr )
{
printg( b[i++] )
if( i < nr ) printg( " " )
}
if( float == "ok" )
printg( " &" )
else
printg( " " )
printg( b[nr] ");\n" )
# do get method
printg("\t")
i = 1
while ( i < nr )
{
printg( b[i++] " " )
}
$temp = b[nr]
printg( $temp "() const;" )
printg( "\n\n" )
}
function doReadonlyAttr( a, class )
{
gsub("readonly attribute", "", $0)
nr = split($0, b, " ")
# do get method
i = 1
printg("\t")
while ( i < nr )
{
printg( b[i++] " " )
}
sub( ";", "", b[nr])
sub( "\r", "", b[nr])
$temp = b[nr]
printg( $temp "() const;" )
printg( "\n" )
}
{
sub("boolean", "bool", $0); # to shut up frerich :P
if(/interface /)
{
gsub(" interface ", "", $0)
gsub(": ", ": public ", $0)
gsub(",", ", public", $0)
gsub("{", "\n{", $0)
sub( ";", "", $0 )
sub( "\r", "", $0 )
nr = split($0, b, " ")
clas = b[1]
printg( "class " clas "Impl;" )
printg( "\nclass " )
printg( $0 )
printg( "\npublic:\n" )
printg( "\t" clas "();\n" )
printg( "\t" clas "(const " clas " &other);\n" )
printg( "\t" clas " &operator=(const " clas " &other);\n" )
printg( "\t" clas "(" clas "Impl *other);\n" )
printg( "\tvirtual ~" clas "();\n\n" )
#printg( "\tbool isNull() const { return !impl; }\n" )
}
else if(/readonly attribute/)
{
doReadonlyAttr( $0, $class )
}
else if(/attribute /)
{
doAttr( $0, $class )
}
else if(/raises/)
{
}
else if(/\)/)
{
doFunc( $0 );
}
else if(/};/)
{
printg( "private:\n\t" clas "Impl *impl;\n};\n\n" );
}
else if(/ = /)
{
sub( "\r", "", $0 )
printg( $0 "\n" );
}
#else if(//)
#{
# # end of class
# printf $0;
#}
}
# END
# {
# print "};";
# }
|