cpp2ffi: gen_structs_and_enums declares nested struct before parent struct, if nested struct declares member of parent keep it (imnodes needs that)

This commit is contained in:
Victor Bombi
2020-10-03 16:34:58 +02:00
parent 8c6dbf6de7
commit 0e408d392e
2 changed files with 28 additions and 15 deletions

View File

@@ -888,32 +888,32 @@ struct ImGuiOnceUponAFrame
{ {
int RefFrame; int RefFrame;
}; };
struct ImGuiTextRange
{
const char* b;
const char* e;
};
struct ImGuiTextFilter struct ImGuiTextFilter
{ {
char InputBuf[256]; char InputBuf[256];
ImVector_ImGuiTextRange Filters; ImVector_ImGuiTextRange Filters;
int CountGrep; int CountGrep;
}; };
struct ImGuiTextRange
{
const char* b;
const char* e;
};
struct ImGuiTextBuffer struct ImGuiTextBuffer
{ {
ImVector_char Buf; ImVector_char Buf;
}; };
struct ImGuiStoragePair
{
ImGuiID key;
union { int val_i; float val_f; void* val_p; };
};
struct ImGuiStorage struct ImGuiStorage
{ {
ImVector_ImGuiStoragePair Data; ImVector_ImGuiStoragePair Data;
}; };
typedef struct ImVector_ImGuiTabBar {int Size;int Capacity;ImGuiTabBar* Data;} ImVector_ImGuiTabBar; typedef struct ImVector_ImGuiTabBar {int Size;int Capacity;ImGuiTabBar* Data;} ImVector_ImGuiTabBar;
typedef struct ImPool_ImGuiTabBar {ImVector_ImGuiTabBar Buf;ImGuiStorage Map;ImPoolIdx FreeIdx;} ImPool_ImGuiTabBar; typedef struct ImPool_ImGuiTabBar {ImVector_ImGuiTabBar Buf;ImGuiStorage Map;ImPoolIdx FreeIdx;} ImPool_ImGuiTabBar;
struct ImGuiStoragePair
{
ImGuiID key;
union { int val_i; float val_f; void* val_p; };
};
struct ImGuiListClipper struct ImGuiListClipper
{ {
int DisplayStart, DisplayEnd; int DisplayStart, DisplayEnd;

View File

@@ -1057,6 +1057,7 @@ function M.Parser()
local stru = itst.item local stru = itst.item
local outtab = {} local outtab = {}
local commtab = {} local commtab = {}
local predeclare = ""
--local iner = strip_end(stru:match("%b{}"):sub(2,-2)) --local iner = strip_end(stru:match("%b{}"):sub(2,-2))
local inistruct = clean_spaces(stru:match("(.-)%b{}")) local inistruct = clean_spaces(stru:match("(.-)%b{}"))
--local stname = stru:match("struct%s*(%S+)%s*%b{}") --local stname = stru:match("struct%s*(%S+)%s*%b{}")
@@ -1124,7 +1125,16 @@ function M.Parser()
table.insert(outtab,it2) table.insert(outtab,it2)
table.insert(commtab,it.comments )--or "") table.insert(commtab,it.comments )--or "")
end end
elseif it.re_name == "struct_re" or it.re_name == "enum_re" then elseif it.re_name == "struct_re" then
--check if has declaration
local decl = it.item:match"%b{}%s*([^%s}{]+)%s*;"
if decl then
table.insert(outtab,"\n "..it.name.." "..decl..";")
table.insert(commtab,it.comments )--or "")
end
local cleanst,structname,strtab,comstab,predec = self:clean_structR1(it)
predeclare = predeclare .. predec .. cleanst
elseif it.re_name == "enum_re" then
--nop --nop
elseif it.re_name ~= "functionD_re" and it.re_name ~= "function_re" then elseif it.re_name ~= "functionD_re" and it.re_name ~= "function_re" then
print(it.re_name,"not processed clean_struct",it.item:sub(1,12)) print(it.re_name,"not processed clean_struct",it.item:sub(1,12))
@@ -1133,7 +1143,7 @@ function M.Parser()
end end
--final --final
table.insert(outtab,"\n};") table.insert(outtab,"\n};")
return table.concat(outtab,""),stname,outtab,commtab return table.concat(outtab,""),stname,outtab,commtab, predeclare
end end
local function get_parents_name(it) local function get_parents_name(it)
local parnam = "" local parnam = ""
@@ -1180,11 +1190,14 @@ function M.Parser()
table.insert(outtab,cl_item) table.insert(outtab,cl_item)
end end
elseif it.re_name == "struct_re" or it.re_name == "typedef_st_re" then elseif it.re_name == "struct_re" or it.re_name == "typedef_st_re" then
local cleanst,structname = self:clean_structR1(it, it.locat) local cleanst,structname,strtab,comstab,predec = self:clean_structR1(it)
if not structname then print("NO NAME",cleanst,it.item) end if not structname then print("NO NAME",cleanst,it.item) end
--if not void stname or templated --if not void stname or templated
if structname and not self.typenames[structname] then if structname and not self.typenames[structname] then
table.insert(outtab,cleanst) --dont insert child structs as they are inserted before parent struct
if not (it.parent and it.parent.re_name == "struct_re") then
table.insert(outtab,predec .. cleanst)
end
table.insert(typedefs_table,"typedef struct "..structname.." "..structname..";\n") table.insert(typedefs_table,"typedef struct "..structname.." "..structname..";\n")
self.typedefs_dict[structname]="struct "..structname self.typedefs_dict[structname]="struct "..structname
end end
@@ -1348,7 +1361,7 @@ function M.Parser()
elseif it.re_name == "enum_re" then elseif it.re_name == "enum_re" then
enums_for_table(it, outtab, enumsordered) enums_for_table(it, outtab, enumsordered)
elseif it.re_name == "struct_re" or it.re_name == "typedef_st_re" then elseif it.re_name == "struct_re" or it.re_name == "typedef_st_re" then
local cleanst,structname,strtab,comstab = self:clean_structR1(it, it.locat) local cleanst,structname,strtab,comstab = self:clean_structR1(it)
--if not void stname or templated --if not void stname or templated
if not structname then print("NO NAME",cleanst,it.item) end if not structname then print("NO NAME",cleanst,it.item) end
if structname and not self.typenames[structname] then if structname and not self.typenames[structname] then