added code to analyze functions
[lqt.git] / new / generator.lua
blob190f27132bec27a15775ab75531926f3d1ffac4b
1 #!/usr/bin/lua
3 local my = {
4 readfile = function(fn) local f = assert(io.open(fn)) local s = f:read'*a' f:close() return s end
8 local filename = ...
9 local path = string.match(arg[0], '(.*/)[^%/]+') or ''
10 local xmlstream = dofile(path..'xml.lua')(my.readfile(filename))
11 local code = xmlstream[1]
13 local decompound = function(n)
14 -- test function pointer
15 local r, a = string.match(n, '(.-) %(%*%) (%b())')
16 if r and a then
17 -- only single arguments are supported
18 return 'function', r, string.match(a, '%(([^,]*)%))')
19 end
20 return nil
21 end
24 local base_types = dofile'types.lua'
26 -- this only works on resolved types (no typedefs) and no compound types
27 local types_desc = setmetatable({}, {
28 __index = function(t, k)
29 -- exclude base types
30 if rawget(base_types, k) then
31 t[k] = rawget(base_types, k)
32 return rawget(base_types, k)
33 end
34 -- exclude templates
35 if string.match(k, '[<>]') then
36 return nil -- explicitly won't support templates yet
37 end
39 -- traverse namespace tree
40 local space = code
41 local iter = string.gmatch(k, '[^:]+')
42 for n in iter do if space.byname and space.byname[n] then
43 space = space.byname[n]
44 if type(space)=='table' and space.label=='TypeAlias' then
45 print(space.xarg.fullname, k)
46 error'you should resolve aliases before calling this function'
47 end -- is an alias?
48 else -- this name is not in this space
49 -- this is probably a template argument (at least in Qt) so we do not care for now
50 do return nil end
51 error(tostring(k)..' '..tostring(space.fullname)..' '..tostring(n) )
52 end end
54 -- make use of final result
55 if type(space)~='table' then
56 return nil
57 else
58 t[k] = space
59 space.on_stack = 'userdata;'
60 end
61 return t[k]
62 end,
65 local cache = {}
66 for _, v in pairs(xmlstream.byid) do
67 if v.xarg.type_base then
68 if not string.match(v.xarg.context, '[<,]%s*'..v.xarg.type_base..'%s*[>,]') then
69 local __ = types_desc[v.xarg.type_base]
70 else
71 end
72 end
73 end
76 local t = {}
77 --table.foreach(types_desc, function(i, j) t[j] = true end)
78 table.foreach(types_desc, function(n,d) print(n, d.label, d.on_stack) end)
79 end
81 bind_function = function(f)
82 if type(f)~='table' or string.find(f.label, 'Function')~=1 then
83 error('this is NOT a function')
84 end
85 io.write(f.xarg.type_name .. ' ' .. f.xarg.fullname ..
86 (f.xarg.static=='1' and ' [static]' or '')..
87 (f.xarg.virtual=='1' and ' [virtual]' or '')..
88 ' [in ' .. tostring(f.xarg.member_of) .. ']\n')
89 end
90 for _, v in pairs(xmlstream.byid) do
91 pcall(bind_function, v)
92 end