diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 15032ac..b3a3dc6 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -116,7 +116,7 @@ end M.strsplit = strsplit local function split_comment(line) local comment = line:match("(%s*//.*)") --or "" - line = line:gsub("%s*//.*","") + line = line:gsub("%s*//[^\n]*","") line = line:gsub("%s*$","") return line,comment end @@ -611,6 +611,7 @@ local function clean_functypedef(line) return result end local function parseFunction(self,stname,itt,namespace,locat) + local lineorig,comment = split_comment(itt.item) line = clean_spaces(lineorig) --move * @@ -1130,6 +1131,9 @@ function M.Parser() return par.skipped[def.ov_cimguiname] or par.skipped[def.cimguiname] end function par:take_lines(cmd_line,names,compiler) + if self.COMMENTS_GENERATION then + cmd_line = cmd_line .. (compiler=="cl" and " /C " or " -C ") + end local pipe,err = io.popen(cmd_line,"r") if not pipe then error("could not execute COMPILER "..err) @@ -1246,7 +1250,34 @@ function M.Parser() table.insert(cdefs2,cdef[1]) end local txt = table.concat(cdefs2,"\n") - + --clean bad positioned comments inside functionD_re + if self.COMMENTS_GENERATION then + print"cleaning comments inside functionD_re--------------" + ---[[ + local nn = 0 + local txtclean = {} + local reg = "(\n[%w%s]-[%w]+%s*%b())(%s*//[^\n]*)([\n%s%w]*%b{}%s-;*)" + --reg = "^([^;{}]-%b()[\n%s%w]*%b{}%s-;*)" + local ini = 1 + local i,e,a,b,c = txt:find(reg,ini) + while i do + print(i,e,#txt) + table.insert(txtclean,txt:sub(ini,i-1)) + table.insert(txtclean,a) + print("a:",a) + print("b:",b) + print("c:",c) + c = c:gsub("(%s*//[^\n]*)","") + table.insert(txtclean,c) + nn = nn + 1 + ini = e + 1 + i,e,a,b,c = txt:find(reg,ini) + end + table.insert(txtclean,txt:sub(ini)) + print("end cleaning ------------------------------",nn) + txt = table.concat(txtclean) + end + --]] self.itemsarr = par:parseItemsR2(txt) itemsarr = self.itemsarr end diff --git a/generator/generator.bat b/generator/generator.bat index 1c8206b..94298f7 100644 --- a/generator/generator.bat +++ b/generator/generator.bat @@ -15,8 +15,8 @@ set PATH=%PATH%;C:\anima;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\min :: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin; ::process files :: arg[1] compiler name gcc, clang or cl -:: arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation -:: examples: "" "internal" "internal freetype" +:: arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation, comments for comments generation +:: examples: "" "internal" "internal freetype comments" :: arg[3..n] name of implementations to generate and/or CFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl diff --git a/generator/generator.lua b/generator/generator.lua index b1b8986..3738e01 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -32,10 +32,10 @@ if FREETYPE_GENERATION then end if COMPILER == "gcc" or COMPILER == "clang" then - CPRE = COMPILER..(COMMENTS_GENERATION and " -C " or "")..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] .. CFLAGS + CPRE = COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] .. CFLAGS CTEST = COMPILER.." --version" elseif COMPILER == "cl" then - CPRE = COMPILER..(COMMENTS_GENERATION and " /C " or "")..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_DEBUG_PARANOID /DIMGUI_API="" /DIMGUI_IMPL_API="" ]] .. CFLAGS + CPRE = COMPILER..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_DEBUG_PARANOID /DIMGUI_API="" /DIMGUI_IMPL_API="" ]] .. CFLAGS CTEST = COMPILER else print("Working without compiler ") @@ -352,7 +352,7 @@ local function parseImGuiHeader(header,names) parser.manuals = cimgui_manuals parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"} --parser.gen_template_typedef = gen_template_typedef --use auto - + parser.COMMENTS_GENERATION = COMMENTS_GENERATION local defines = parser:take_lines(CPRE..header,names,COMPILER) return parser