mirror of
https://github.com/cimgui/cimgui.git
synced 2026-06-11 17:11:17 +01:00
cpp2ffi: better printing and add const return when :: appears
This commit is contained in:
@@ -776,8 +776,16 @@ local function parseFunction(self,stname,itt,namespace,locat)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local ret = line:match("([^%(%):,]+[%*%s])%s?~?[_%w]+%b()")
|
||||
|
||||
local rettt = line:match("(.+[%*%s])%s?~?[_%w]+%b()")
|
||||
--if rettt and rettt:match"::" then print("rettt",rettt,ret);error"debug" end
|
||||
--if ret~=rettt then print("++++++++ret~=rettt",ret,rettt) end
|
||||
if rettt and rettt:match"^const" and not ret:match"^const" then
|
||||
ret = "const "..ret
|
||||
print("++++++++++++add const",ret)
|
||||
end
|
||||
|
||||
--local ret = line:match("(.+[%*%s])%s?~?[_%w]+%b()")
|
||||
--local funcname, args = line:match("(~?[_%w]+)%s*(%b())")
|
||||
local funcname, args, extraconst = line:match("(~?[_%w]+)%s*(%b())(.*)")
|
||||
@@ -1384,7 +1392,9 @@ local function header_subs_nonPOD(FP,txt)
|
||||
return txt
|
||||
end
|
||||
M.header_subs_nonPOD = header_subs_nonPOD
|
||||
local function get_std_function(ar)
|
||||
local function get_std_function(ar,def)
|
||||
print("get_std_function",ar.template_orig)
|
||||
print(" from",def.ov_cimguiname)
|
||||
local skip = false
|
||||
local ty=ar.template_orig:gsub(ar.name,"")
|
||||
ty = ty:match("std::function(%b<>)")
|
||||
@@ -1402,12 +1412,14 @@ local function get_std_function(ar)
|
||||
local argsT2 = {}
|
||||
local noname_counter = 0
|
||||
for i,v in ipairs(argsT) do
|
||||
local typ, name = v:match("(.+)%s+(%w+)")
|
||||
print(" arg",i,v)
|
||||
local typ, name = v:match("^(.+)%s+(%w*)$")
|
||||
if not name then
|
||||
typ = v
|
||||
noname_counter = noname_counter + 1
|
||||
name = "noname" .. noname_counter
|
||||
end
|
||||
print(" ",typ,name)
|
||||
argsT2[i] = {type=typ,name=name}
|
||||
end
|
||||
--get conversions
|
||||
@@ -1423,6 +1435,9 @@ local function get_std_function(ar)
|
||||
elseif v.type:match("std::") then
|
||||
skip = true
|
||||
else
|
||||
print(" get_std_function found type",v.type)
|
||||
-- require"anima.utils"
|
||||
-- prtable(ar)
|
||||
end
|
||||
argsT3[i] = {type=typ or v.type,conv=conv,name=v.name}
|
||||
end
|
||||
@@ -1461,10 +1476,12 @@ local function get_std_function(ar)
|
||||
return caar,asp,skip
|
||||
end
|
||||
local function ADDnonUDT(FP)
|
||||
print"===================ADDnonUDT==================================="
|
||||
local nonPOD = get_nonPOD(FP)
|
||||
get_nonPODused(FP)
|
||||
for k,defs in pairs(FP.defsT) do
|
||||
for i, def in ipairs(defs) do
|
||||
--print(" ADDnonUDT",def.ov_cimguiname,def.ret)
|
||||
local skip = nil
|
||||
--ret
|
||||
local rets = (def.ret or ""):gsub("const ","")
|
||||
@@ -1495,6 +1512,7 @@ local function ADDnonUDT(FP)
|
||||
end
|
||||
--return std:: -> skip function
|
||||
elseif def.stdret then -- not std::string
|
||||
print("skip",def.stdret,"on return")
|
||||
skip = true
|
||||
end
|
||||
--args
|
||||
@@ -1527,7 +1545,7 @@ local function ADDnonUDT(FP)
|
||||
caar = caar .. "std::string("..name.."),"
|
||||
asp = asp .. "const char* "..v.name..","
|
||||
elseif v.type:match"std::function" then
|
||||
local ca2,asp2,skip2 = get_std_function(v)
|
||||
local ca2,asp2,skip2 = get_std_function(v,def)
|
||||
caar = caar .. ca2..","
|
||||
asp = asp .. asp2..","
|
||||
if skip2 then skip = true end
|
||||
@@ -1565,6 +1583,7 @@ local function ADDnonUDT(FP)
|
||||
asp = "()"
|
||||
end
|
||||
if skip then
|
||||
print("-------ADDnonUDT skips",def.ov_cimguiname)
|
||||
def.skipped = skip
|
||||
FP.skipped[def.ov_cimguiname] = true
|
||||
else
|
||||
@@ -1642,6 +1661,9 @@ local function ADDnonUDT_OLD(FP)
|
||||
end
|
||||
|
||||
local function ADDdestructors(FP)
|
||||
print"======================================================="
|
||||
print"==============ADDdestructors========================="
|
||||
print"======================================================="
|
||||
local defsT = FP.defsT
|
||||
local newcdefs = {}
|
||||
|
||||
@@ -2056,7 +2078,7 @@ function M.Parser()
|
||||
--clean class and get name
|
||||
if it.re_name == "class_re" then
|
||||
it.name = it.item:match("class%s+(%S+)")
|
||||
print("cleaning class",it.name)
|
||||
print("cleaning class",it.name,"-------------------------------------")
|
||||
--it.item = it.item:gsub("private:.+};$","};")
|
||||
--it.item = it.item:gsub("private:","")
|
||||
it.item = it.item:gsub("public:","")
|
||||
@@ -2119,22 +2141,22 @@ function M.Parser()
|
||||
if derived then
|
||||
local derived2 = derived:gsub("%b<>","")
|
||||
derived2 = derived2:gsub("%w+::","")
|
||||
print("--derived check",stname, derived, derived2)
|
||||
M.prtable(self.opaque_structs)
|
||||
print(" --derived check",stname, derived, derived2)
|
||||
--M.prtable(self.opaque_structs)
|
||||
if self.opaque_structs[derived2] then
|
||||
print("--make opaque opaque derived",it.name,derived,derived2)
|
||||
print(" --make opaque opaque derived",it.name,derived,derived2)
|
||||
it.opaque_struct = get_parents_name(it)..it.name
|
||||
self.opaque_structs[it.name] = it.opaque_struct
|
||||
end
|
||||
end
|
||||
if derived and derived:match"std::" then
|
||||
print("--make opaque std::derived",it.name,derived)
|
||||
print(" --make opaque std::derived",it.name,derived)
|
||||
--it.opaque_struct = (itparent and itparent.name .."::" or "")..it.name
|
||||
it.opaque_struct = get_parents_name(it)..it.name
|
||||
self.opaque_structs[it.name] = it.opaque_struct
|
||||
end
|
||||
if self.forced_opaque[it.name] then
|
||||
print("--make forced opaque opaque derived",it.name)
|
||||
print(" --make forced opaque opaque derived",it.name)
|
||||
it.opaque_struct = get_parents_name(it)..it.name
|
||||
self.opaque_structs[it.name] = it.opaque_struct
|
||||
end
|
||||
@@ -2143,12 +2165,12 @@ function M.Parser()
|
||||
-- print("=====using",child.item)
|
||||
-- end
|
||||
if (child.re_name == "vardef_re") and child.item:match"std::" then
|
||||
print("--make opaque",it.name,child.item)
|
||||
print(" --make opaque with child std::",it.name,child.item)
|
||||
--M.prtable(itparent)
|
||||
--it.opaque_struct = (itparent and itparent.name .."::" or "")..it.name
|
||||
it.opaque_struct = get_parents_name(it)..it.name
|
||||
print("===parents1",get_parents_name(it),"===parents2",(itparent and itparent.name .."::" or ""))
|
||||
print("===",it.opaque_struct)
|
||||
print(" ===parents1",get_parents_name(it),"===parents2",(itparent and itparent.name .."::" or ""))
|
||||
print(" ===",it.opaque_struct)
|
||||
--cant do that as function is recursive
|
||||
--self.opaque_structs[it.name] = get_parents_name(it)..it.name--(itparent and itparent.name .."::" or "")..it.name
|
||||
self.opaque_structs[it.name] = it.opaque_struct
|
||||
@@ -2176,6 +2198,9 @@ function M.Parser()
|
||||
return table.concat(txtclean)
|
||||
end
|
||||
function par:parseItems()
|
||||
print"================================================================"
|
||||
print"===================parseItems==================================="
|
||||
print"================================================================"
|
||||
--self:initTypedefsDict()
|
||||
|
||||
self.linenumdict = {}
|
||||
@@ -2549,7 +2574,9 @@ function M.Parser()
|
||||
end
|
||||
end
|
||||
function par:gen_structs_and_enums()
|
||||
print"======================================================="
|
||||
print"--------------gen_structs_and_enums"
|
||||
print"======================================================="
|
||||
--M.prtable(self.typenames)
|
||||
local outtab = {}
|
||||
local outtabpre = {}
|
||||
@@ -2838,7 +2865,9 @@ function M.Parser()
|
||||
end
|
||||
par.enums_for_table = enums_for_table
|
||||
function par:gen_structs_and_enums_table()
|
||||
print"--------------gen_structs_and_enums_table"
|
||||
print"================================================================"
|
||||
print"===================gen_structs_and_enums_table==================================="
|
||||
print"================================================================"
|
||||
local outtab = {enums={},structs={},locations={},enumtypes={},struct_comments={},enum_comments={},opaque_structs={}}
|
||||
--self.typedefs_table = {}
|
||||
local enumsordered = {}
|
||||
@@ -3014,6 +3043,9 @@ function M.Parser()
|
||||
end
|
||||
|
||||
function par:compute_overloads()
|
||||
print"================================================================"
|
||||
print"===================compute_overloads==================================="
|
||||
print"================================================================"
|
||||
-- if self.IMGUI_HAS_TEXTURES then
|
||||
-- print"----------replacing ImTextureID with ImTextureUserID"
|
||||
-- REPLACE_TEXTUREID(self)
|
||||
@@ -3240,6 +3272,9 @@ function M.Parser()
|
||||
end
|
||||
--generate cimgui.cpp cimgui.h
|
||||
function par:cimgui_generation( cimgui_header)
|
||||
print"=========================================================="
|
||||
print"===============cimgui_generation==========================="
|
||||
print"=========================================================="
|
||||
local name = self.modulename
|
||||
local hstrfile = read_data("./"..name.."_template.h")
|
||||
M.prtable("templates",self.templates)
|
||||
|
||||
Reference in New Issue
Block a user