5 Copyright (c) 2007-2009 Mauro Iazzi
6 Copyright (c) 2008 Peter K�mmel
7 Copyright (c) 2010 Michal Kottman
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation
11 files (the "Software"), to deal in the Software without
12 restriction, including without limitation the rights to use,
13 copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following
18 The above copyright notice and this permission notice shall be
19 included in all copies or substantial portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 OTHER DEALINGS IN THE SOFTWARE.
32 local osseparator
= package
.config
:sub(1,1)
34 local path
= string.match(arg
[0], '(.*'..osseparator
..')[^%'..osseparator
..']+') or ''
36 --- remove script name
37 path
= string.sub(arg
[0], 1, #arg
[0] - #'generator.lua')
43 template_file
= path
.. 'qtemplates.lua'
45 local filterfiles
= {}
52 while select(i
, ...) do
53 local argi
= select(i
, ...)
56 module_name
= select(i
, ...)
57 elseif argi
=='-i' then
59 table.insert(output_includes
, (select(i
, ...)))
60 elseif argi
=='-t' then
62 table.insert(typefiles
, (select(i
, ...)))
63 elseif argi
=='-f' then
65 table.insert(filterfiles
, (select(i
, ...)))
66 elseif argi
=='-c' then
68 template_file
= select(i
, ...)
70 filename
= filename
and error'duplicate filename' or argi
76 local my_includes
= ''
77 for _
, i
in ipairs(output_includes
) do
78 if string.match(i
, '^<.+>$') then
79 my_includes
= my_includes
.. '#include '..i
..'\n'
80 elseif string.match(i
, '^".+"$') then
81 my_includes
= my_includes
.. '#include '..i
..'\n'
83 my_includes
= my_includes
.. '#include "'..i
..'"\n'
86 output_includes
= my_includes
.. '\n'
88 local readfile
= function(fn
)
89 local f
= assert(io
.open(fn
))
97 for i
= 1, select('#',...) do
98 f
:write((i
==1) and '' or '\t', tostring(select(i
,...)))
105 _src
= '_src'..osseparator
106 local debug
= fprint(io
.stderr
)
109 local ignore_file
= assert(io
.open('ignores_'..module_name
..'.csv', 'w'))
110 function ignore(name
, cause
, context
)
112 ignore_file
:write(name
..';'..cause
..';'..(context
or '')..'\n')
116 local xmlstream
, idindex
= dofile(path
..'xml.lua')(readfile(filename
))
118 -- Remove duplicate entries (~4300/20000 for QtCore)
121 for e
in pairs(idindex
) do
122 if e
.xarg
and e
.xarg
.id
and dups
[e
.xarg
.id
] then
123 -- print('Duplicate!', dups[e.xarg.id], e.xarg.name, e.xarg.id)
126 dups
[e
.xarg
.id
] = true
128 for e
in pairs(remove) do
132 package
.path
= path
..'?.lua;' .. package
.path
134 require('class_types')
136 ----------------------------------------------------------------------------------
138 typesystem
= dofile(path
..'types.lua')
141 for i
, ft
in ipairs(typefiles
) do
142 ts
= assert(loadfile(ft
))(ts
)
144 setmetatable(typesystem
, {
145 __newindex
= function(t
, k
, v
)
146 --debug('added type', k)
149 __index
= function(t
, k
)
151 -- if not ret then debug("unknown type:", tostring(k), ret) end
159 function argument_name(tn
, an
)
161 if string.match(tn
, '%(%*%)') then
162 ret
= string.gsub(tn
, '%(%*%)', '(*'..an
..')', 1)
163 elseif string.match(tn
, '%[.*%]') then
164 ret
= string.gsub(tn
, '%s*(%[.*%])', ' '..an
..'%1')
166 ret
= tn
.. ' ' .. an
172 for e
in pairs(idindex
) do
173 if e
.xarg
and e
.xarg
.id
then
174 local id
= assert(tonumber(e
.xarg
.id
:match("_(%d+)")))
175 if id
> gen_id
then gen_id
= id
+ 1 end
179 function next_id() gen_id
= gen_id
+ 1; return "_" .. gen_id
end
182 --- Constructs the code that pushes arguments to the Lua stack.
183 -- Returns the code as a string, and stack increment. In case that an unknown
184 -- type is encountered, nil and the unknown type is returned.
185 function make_pushlines(args
)
186 local pushlines
, stack
= '', 0
187 for i
, a
in ipairs(args
) do
188 if not typesystem
[a
.xarg
.type_name
] then return nil, a
.xarg
.type_name
end
189 local apush
, an
= typesystem
[a
.xarg
.type_name
].push('arg'..i
)
190 pushlines
= pushlines
.. ' ' .. apush
.. ';\n'
193 return pushlines
, stack
201 for e
in pairs(idindex
) do
202 if e
.xarg
.fullname
then fullnames
[e
.xarg
.fullname
] = e
end
205 enums
.preprocess(idindex
)
206 classes
.preprocess(idindex
)
208 enums
.process(idindex
, typesystem
)
209 classes
.process(idindex
, typesystem
, filterfiles
)
211 ------------- BEGIN OUTPUT
216 --print_openmodule(module_name) -- does that