avoid excesive typedefs

This commit is contained in:
sonoro1234
2018-07-06 12:02:04 +02:00
parent ce4ac9dfcf
commit 9694c710b7
4 changed files with 28 additions and 73 deletions

View File

@@ -37,30 +37,11 @@ typedef unsigned long long ImU64;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef struct ImFont ImFont;
typedef struct ImFontAtlas ImFontAtlas;
typedef struct CustomRect CustomRect;
typedef struct GlyphRangesBuilder GlyphRangesBuilder;
typedef struct ImFontGlyph ImFontGlyph;
typedef struct ImFontConfig ImFontConfig;
typedef struct ImDrawData ImDrawData;
typedef struct ImDrawList ImDrawList;
typedef struct ImDrawChannel ImDrawChannel;
typedef struct ImDrawVert ImDrawVert;
typedef struct ImDrawCmd ImDrawCmd;
typedef struct ImGuiListClipper ImGuiListClipper;
typedef struct ImColor ImColor;
typedef struct ImGuiPayload ImGuiPayload;
typedef struct ImGuiSizeCallbackData ImGuiSizeCallbackData;
typedef struct ImGuiTextEditCallbackData ImGuiTextEditCallbackData;
typedef struct ImGuiStorage ImGuiStorage;
typedef struct Pair Pair;
typedef struct ImGuiTextBuffer ImGuiTextBuffer;
typedef struct ImGuiTextFilter ImGuiTextFilter;
typedef struct TextRange TextRange;
typedef struct ImGuiOnceUponAFrame ImGuiOnceUponAFrame;
typedef struct ImGuiIO ImGuiIO;
typedef struct ImGuiStyle ImGuiStyle;
typedef struct ImVec4 ImVec4;
typedef struct ImVec2 ImVec2;
typedef struct ImGuiContext ImGuiContext;

View File

@@ -36,29 +36,14 @@ typedef unsigned long long ImU64;
//struct SDL_Window;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef unsigned short ImDrawIdx;typedef struct ImFont ImFont;
typedef struct ImFontAtlas ImFontAtlas;
typedef unsigned short ImDrawIdx;
typedef void* ImTextureID;
// dear imgui, v1.62
typedef struct CustomRect CustomRect;
typedef struct GlyphRangesBuilder GlyphRangesBuilder;
typedef struct ImFontGlyph ImFontGlyph;
typedef struct ImFontConfig ImFontConfig;
typedef struct ImDrawData ImDrawData;
typedef struct ImDrawList ImDrawList;
typedef struct ImDrawChannel ImDrawChannel;
typedef struct ImDrawCmd ImDrawCmd;
typedef struct ImGuiListClipper ImGuiListClipper;
typedef struct ImColor ImColor;
typedef struct ImGuiPayload ImGuiPayload;
typedef struct ImGuiSizeCallbackData ImGuiSizeCallbackData;
typedef struct ImGuiTextEditCallbackData ImGuiTextEditCallbackData;
typedef struct ImGuiStorage ImGuiStorage;
typedef struct Pair Pair;
typedef struct ImGuiTextBuffer ImGuiTextBuffer;
typedef struct ImGuiTextFilter ImGuiTextFilter;
typedef struct TextRange TextRange;
typedef struct ImGuiOnceUponAFrame ImGuiOnceUponAFrame;
typedef struct ImGuiIO ImGuiIO;
typedef struct ImGuiStyle ImGuiStyle;
typedef struct ImVec4 ImVec4;
typedef struct ImVec2 ImVec2;
typedef struct ImGuiContext ImGuiContext;
@@ -82,7 +67,6 @@ typedef struct ImDrawList ImDrawList;
typedef struct ImDrawData ImDrawData;
typedef struct ImDrawCmd ImDrawCmd;
typedef struct ImDrawChannel ImDrawChannel;
typedef void* ImTextureID;// dear imgui, v1.62
// (headers)
// See imgui.cpp file for documentation.
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.

View File

@@ -37,30 +37,11 @@ typedef unsigned long long ImU64;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef struct ImFont ImFont;
typedef struct ImFontAtlas ImFontAtlas;
typedef struct CustomRect CustomRect;
typedef struct GlyphRangesBuilder GlyphRangesBuilder;
typedef struct ImFontGlyph ImFontGlyph;
typedef struct ImFontConfig ImFontConfig;
typedef struct ImDrawData ImDrawData;
typedef struct ImDrawList ImDrawList;
typedef struct ImDrawChannel ImDrawChannel;
typedef struct ImDrawVert ImDrawVert;
typedef struct ImDrawCmd ImDrawCmd;
typedef struct ImGuiListClipper ImGuiListClipper;
typedef struct ImColor ImColor;
typedef struct ImGuiPayload ImGuiPayload;
typedef struct ImGuiSizeCallbackData ImGuiSizeCallbackData;
typedef struct ImGuiTextEditCallbackData ImGuiTextEditCallbackData;
typedef struct ImGuiStorage ImGuiStorage;
typedef struct Pair Pair;
typedef struct ImGuiTextBuffer ImGuiTextBuffer;
typedef struct ImGuiTextFilter ImGuiTextFilter;
typedef struct TextRange TextRange;
typedef struct ImGuiOnceUponAFrame ImGuiOnceUponAFrame;
typedef struct ImGuiIO ImGuiIO;
typedef struct ImGuiStyle ImGuiStyle;
typedef struct ImVec4 ImVec4;
typedef struct ImVec2 ImVec2;
typedef struct ImGuiContext ImGuiContext;

View File

@@ -620,7 +620,7 @@ local function gen_structs_and_enums_table(cdefs)
end
local function gen_structs_and_enums(cdefs,addextra)
local function gen_structs_and_enums(cdefs)
local function_closing_re = "}"
local namespace_re = "namespace"
local in_namespace = false
@@ -634,10 +634,7 @@ local function gen_structs_and_enums(cdefs,addextra)
local outtab = {}
-- Output the file
--table.insert(outtab,"/////////////// BEGIN AUTOGENERATED SEGMENT\n")
if addextra then
table.insert(outtab,[[typedef unsigned short ImDrawIdx;]])
table.insert(outtab,[[typedef void* ImTextureID;]])
end
for i,line in ipairs(cdefs) do
repeat -- simulating continue with break
-- separate comments from code and try to add them with same tab
@@ -659,6 +656,7 @@ local function gen_structs_and_enums(cdefs,addextra)
end
end
-- ImVector special treatment
if structnames[#structnames] == "ImVector" then
if line:match(struct_closing_re) then
table.insert(outtab,[[struct ImVector
@@ -727,8 +725,12 @@ typedef struct ImVector ImVector;]])
end
--table.insert(outtab,"//////////////// END AUTOGENERATED SEGMENT \n")
local uniques = {}
for i,l in ipairs(typedefs_table) do
table.insert(outtab,2,l)
if not uniques[l] then
uniques[l] = true
table.insert(outtab,2,l)
end
end
local cstructsstr = table.concat(outtab)
cstructsstr = cstructsstr:gsub("\n+","\n") --several empty lines to one empty line
@@ -863,13 +865,18 @@ local function func_implementation(FP)
--cppfile:close()
return table.concat(outtab)
end
--generate cimgui.cpp cimgui.h and auto versions depending on postfix
local function cimgui_generation(postfix,STP,FP)
--merge it in cimgui_template.h to cimgui.h
local hfile = io.open("./cimgui_template.h","r")
local hstrfile = hfile:read"*a"
hfile:close()
local cstructsstr = gen_structs_and_enums(STP.lines,postfix=="")
local cstructsstr = gen_structs_and_enums(STP.lines)
--for not gcc parsing
if postfix == "" then
cstructsstr = "typedef unsigned short ImDrawIdx;\ntypedef void* ImTextureID;\n"..cstructsstr
end
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
local cfuncsstr = func_header_generate(FP)
hstrfile = hstrfile:gsub([[#include "auto_funcs%.h"]],cfuncsstr)
@@ -907,6 +914,8 @@ FP:compute_overloads()
cimgui_generation("",STP,FP)
--then gcc
local pFP,pSTP
if HAVE_GCC then
local pipe,err = io.popen([[gcc -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
@@ -914,26 +923,26 @@ if not pipe then
error("could not execute gcc "..err)
end
STP = struct_parser() --overwrite
FP = func_parser() --overwrite
pSTP = struct_parser() --overwrite
pFP = func_parser() --overwrite
for line in location(pipe,{"imgui"}) do
local line, comment = split_comment(line)
STP.insert(line,comment)
FP.insert(line,comment)
pSTP.insert(line,comment)
pFP.insert(line,comment)
end
pipe:close()
local ovstr = FP:compute_overloads()
local ovstr = pFP:compute_overloads()
save_data("./generated/overloads.txt",ovstr)
cimgui_generation("_auto",STP,FP)
cimgui_generation("_auto",pSTP,pFP)
end
----------save fundefs in definitions.lua for using in bindings
save_data("./generated/definitions.lua",serializeTable("defs",FP.defsT),"\nreturn defs")
save_data("./generated/definitions.lua",serializeTable("defs",pFP.defsT),"\nreturn defs")
----------save struct and enums lua table in structs_and_enums.lua for using in bindings
local structs_and_enums_table = gen_structs_and_enums_table(STP.lines)
local structs_and_enums_table = gen_structs_and_enums_table(pSTP.lines)
save_data("./generated/structs_and_enums.lua",serializeTable("defs",structs_and_enums_table),"\nreturn defs")
--=================================Now implementations
@@ -993,7 +1002,7 @@ local function json_prepare(defs)
end
local json = require"json"
save_data("./generated/definitions.json",json.encode(json_prepare(FP.defsT)))
save_data("./generated/definitions.json",json.encode(json_prepare(pFP.defsT)))
save_data("./generated/structs_and_enums.json",json.encode(structs_and_enums_table))
if iFP then
save_data("./generated/impl_definitions.json",json.encode(json_prepare(iFP.defsT)))