4 readfile
= function(fn
) local f
= assert(io
.open(fn
)) local s
= f
:read'*a' f
:close() return s
end
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())')
17 -- only single arguments are supported
18 return 'function', r
, string.match(a
, '%(([^,]*)%))')
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
)
30 if rawget(base_types
, k
) then
31 t
[k
] = rawget(base_types
, k
)
32 return rawget(base_types
, k
)
35 if string.match(k
, '[<>]') then
36 return nil -- explicitly won't support templates yet
39 -- traverse namespace tree
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'
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
51 error(tostring(k
)..' '..tostring(space
.fullname
)..' '..tostring(n
) )
54 -- make use of final result
55 if type(space
)~='table' then
64 local types_name
= setmetatable({}, {
65 __index
= function(t
, k
)
67 if rawget(base_types
, k
) then
72 if string.match(k
, '<') then
73 return nil -- explicitly won't support templates yet
76 -- traverse namespace tree
78 local iter
= string.gmatch(k
, '[^:]+')
79 for n
in iter
do if space
.byname
and space
.byname
[n
] then
80 space
= space
.byname
[n
]
81 if type(space
)=='table' and space
.label
=='TypeAlias' then
83 local alias
= space
.xarg
.type_name
84 if space
.xarg
.type_base
~=alias
then
85 -- if it is not a pure object name, it should not have members
87 error'compound type shouldn\'t have members'
89 local sub
= t
[space
.xarg
.type_base
]
90 local ret
= sub
and string.gsub(alias
, space
.xarg
.type_base
, sub
) or nil
95 else -- alias to compound type?
96 for i
in iter
do alias
= alias
..'::'..i
end -- reconstruct full name
97 --print ('----', k, 'is alias for', n)
99 if ret
then t
[k
] = ret
end
100 print ('----', k
, 'is alias for', alias
, 'and is', ret
)
102 end -- alias to compound type?
109 -- make use of final result
110 if type(space
)~='table' then
113 t
[k
] = space
.xarg
.fullname
121 for _
, v
in pairs(xmlstream
.byid
) do
122 if v
.xarg
.type_base
then
123 if not string.match(v
.xarg
.context
, '[<,]%s*'..v
.xarg
.type_base
..'%s*[>,]') then
124 local __
= types_desc
[v
.xarg
.type_base
]
128 --if v.xarg.scope~=v.xarg.context..'::' then print(v.label, v.xarg.id, v.xarg.type_name, v.xarg.scope, v.xarg.context) end
129 --cache[v.xarg.context] = true
130 --print(pushtype(v)(v.xarg.name), ' // '.._..': '..v.label..' : '..(v.xarg.type_name or ''))
131 --assert(type_name(v.xarg.type_base, v.xarg.type_constant, v.xarg.type_volatile, v.xarg.type_reference, v.xarg.indirections or 0)==v.xarg.type_name)
133 --table.foreach(cache, print)
136 --table.foreach(types_desc, function(i, j) t[j] = true end)
137 table.foreach(types_desc
, print)