cpp2ffi: ADDiMSTR_S before overload naming and copy defaults, overload_Algo improvement

This commit is contained in:
Victor Bombi
2021-02-01 13:05:55 +01:00
parent afdbb6b799
commit 383ebf3a7a

View File

@@ -414,14 +414,13 @@ local function parseItems(txt,linenumdict, itparent, dumpit)
end end
M.parseItems = parseItems M.parseItems = parseItems
local function name_overloadsAlgo(v) local function name_overloadsAlgo(v)
local aa = {} local aa = {}
local bb = {} local bb = {}
local done = {} local done = {}
local maxnum = 0 local maxnum = 0
for i,t in ipairs(v) do for i,t in ipairs(v) do
bb[i] = "" bb[i] = ""
--local signature = t.signature:sub(2,-2) -- without parenthesis
--inside parenthesis
local signature = t.signature:match("%b()") local signature = t.signature:match("%b()")
signature = signature:sub(2,-2) signature = signature:sub(2,-2)
--add const function --add const function
@@ -430,11 +429,7 @@ local function name_overloadsAlgo(v)
end end
aa[i] = {} aa[i] = {}
local num = 1 local num = 1
--for typec in t.signature:gmatch(".-([^,%(%s]+)[,%)]") do
--for typec in t.signature:gmatch(".-([^,%(]+)[,%)]") do
--for typec in signature:gmatch(".-([^,]+),?") do
for typec in signature:gsub("(%(.-%))", function(x) return x:gsub(",","\0") end):gmatch(".-([^,]+),?") do for typec in signature:gsub("(%(.-%))", function(x) return x:gsub(",","\0") end):gmatch(".-([^,]+),?") do
--typec = typec:gsub
aa[i][num] = typec:gsub("%z+", ",") aa[i][num] = typec:gsub("%z+", ",")
num = num + 1 num = num + 1
end end
@@ -448,7 +443,7 @@ local function name_overloadsAlgo(v)
local equal = true local equal = true
for i=1,#v do for i=1,#v do
aa[i][l] = aa[i][l] or "nil" aa[i][l] = aa[i][l] or "nil"
keys[aa[i][l]] = 1 + (aa[i][l] and keys[aa[i][l]] or 0) keys[aa[i][l]] = 1 + (keys[aa[i][l]] or 0)
if not done[i] then if not done[i] then
for j=i+1,#v do for j=i+1,#v do
if not done[j] then if not done[j] then
@@ -465,11 +460,20 @@ local function name_overloadsAlgo(v)
for i=1,#v do for i=1,#v do
if not done[i] then if not done[i] then
bb[i] = bb[i]..(aa[i][l]=="nil" and "" or aa[i][l]) bb[i] = bb[i]..(aa[i][l]=="nil" and "" or aa[i][l])
if keys[aa[i][l]] == 1 then -- if keys[aa[i][l]] == 1 then
done[i] = true -- done[i] = true
-- end
end end
end end
end end
--test done
for i=1,#v do
done[i] = true
for j=1,#v do
if i~=j and bb[i]==bb[j] then
done[i] = false
end
end
end end
end end
--avoid empty postfix which will be reserved to generic --avoid empty postfix which will be reserved to generic
@@ -797,6 +801,11 @@ local function ADDIMSTR_S(FP)
for k,v in ipairs(defT.argsT) do for k,v in ipairs(defT.argsT) do
local typ = (v.type == "ImStr" or v.type == "const ImStr") and "const char*" or v.type local typ = (v.type == "ImStr" or v.type == "const ImStr") and "const char*" or v.type
table.insert(defT2.argsT,{type=typ,name=v.name}) table.insert(defT2.argsT,{type=typ,name=v.name})
end
--defaults table
defT2.defaults = {}
for k,v in pairs(defT.defaults) do
defT2.defaults[k] = v
end end
defT2.args = defT.args:gsub("const ImStr","const char*") defT2.args = defT.args:gsub("const ImStr","const char*")
defT2.args = defT2.args:gsub("ImStr","const char*") defT2.args = defT2.args:gsub("ImStr","const char*")
@@ -817,17 +826,27 @@ local function ADDIMSTR_S(FP)
else else
caar = "()" caar = "()"
end end
defT2.call_args = caar defT2.call_args = caar:gsub("ImStr%(([^%(%)]+)%)","%1")
------------------ ------------------
defT2.signature = defT.signature:gsub("ImStr","const char*").."_S" defT2.signature = defT.signature:gsub("ImStr","const char*") --.."_S"
defT2.ov_cimguiname = (defT2.ov_cimguiname or defT2.cimguiname).."_S" --defT2.ov_cimguiname = (defT2.ov_cimguiname or defT2.cimguiname).."_S"
defT2.isIMSTR_S = 1 defT2.isIMSTR_S = 1
-- check there is not an equal version in imgui_stname
--replace local doadd = true
for i,dd in ipairs(cimf) do
if dd.signature == defT2.signature then
doadd = false;
print("skip _S addition",defT2.cimguiname)
break
end
end
--add _S version
if doadd then
cimf[#cimf+1] = defT2 cimf[#cimf+1] = defT2
cimf[defT2.signature] = defT2 cimf[defT2.signature] = defT2
newcdefs[#newcdefs+1] = {stname=t.stname,funcname=t.funcname,args=defT2.args,signature=defT2.signature,cimguiname=defT2.cimguiname,ret =defT2.ret} newcdefs[#newcdefs+1] = {stname=t.stname,funcname=t.funcname,args=defT2.args,signature=defT2.signature,cimguiname=defT2.cimguiname,ret =defT2.ret}
end end
end
else print("not cimguiname in");M.prtable(t) else print("not cimguiname in");M.prtable(t)
end end
end end
@@ -1555,6 +1574,7 @@ function M.Parser()
for k,v in pairs(self.alltypes) do print(k, typetoStr(k) ) end for k,v in pairs(self.alltypes) do print(k, typetoStr(k) ) end
end end
function par:compute_overloads() function par:compute_overloads()
ADDIMSTR_S(self)
local strt = {} local strt = {}
local numoverloaded = 0 local numoverloaded = 0
self.alltypes = {} self.alltypes = {}
@@ -1570,6 +1590,15 @@ function M.Parser()
for i,t in ipairs(v) do for i,t in ipairs(v) do
--take overloaded name from manual table or algorythm --take overloaded name from manual table or algorythm
t.ov_cimguiname = self.getCname_overload(t.stname,t.funcname,t.signature,t.namespace) or k..typetoStr(post[i]) t.ov_cimguiname = self.getCname_overload(t.stname,t.funcname,t.signature,t.namespace) or k..typetoStr(post[i])
--check ...
if( t.ov_cimguiname:match"%.%.%.") then
print("... in ov",t.ov_cimguiname)
for i,dd in ipairs(v) do
print(dd.signature,post[i])
end
error"Bad check ..."
end
--if t.isIMSTR_S then t.ov_cimguiname = t.ov_cimguiname .. "_S" end
table.insert(strt,string.format("%d\t%s\t%s %s",i,t.ret,t.ov_cimguiname,t.signature)) table.insert(strt,string.format("%d\t%s\t%s %s",i,t.ret,t.ov_cimguiname,t.signature))
--M.prtable(typesc[i],post) --M.prtable(typesc[i],post)
end end
@@ -1589,7 +1618,7 @@ function M.Parser()
end) end)
--print(numoverloaded, "overloaded") --print(numoverloaded, "overloaded")
table.insert(strt,string.format("%d overloaded",numoverloaded)) table.insert(strt,string.format("%d overloaded",numoverloaded))
ADDIMSTR_S(self) --ADDIMSTR_S(self)
AdjustArguments(self) AdjustArguments(self)
ADDnonUDT(self) ADDnonUDT(self)