new generator: embeded_structs use get_parents_name

This commit is contained in:
Victor Bombi
2020-09-04 09:11:07 +02:00
parent 8fee1a6fe7
commit 46f51395eb

View File

@@ -897,10 +897,13 @@ function M.Parser()
if it.re_name == "struct_re" then if it.re_name == "struct_re" then
local typename = it.item:match("%s*template%s*<%s*typename%s*(%S+)%s*>") local typename = it.item:match("%s*template%s*<%s*typename%s*(%S+)%s*>")
local stname = it.item:match("struct%s+(%S+)") local stname = it.item:match("struct%s+(%S+)")
it.name = stname
if typename then -- it is a struct template if typename then -- it is a struct template
self.typenames = self.typenames or {} self.typenames = self.typenames or {}
self.typenames[stname] = typename self.typenames[stname] = typename
end end
elseif it.re_name == "namespace_re" then
it.name = it.item:match("namespace%s+(%S+)")
end end
end end
end end
@@ -1046,7 +1049,15 @@ function M.Parser()
table.insert(outtab,"\n};") table.insert(outtab,"\n};")
return table.concat(outtab,""),stname,outtab return table.concat(outtab,""),stname,outtab
end end
local function get_parents_name(it)
local parnam = ""
while it.parent do
print("get_parents_name", it.parent.name)
parnam = it.parent.name.."::"..parnam
it = it.parent
end
return parnam
end
function par:gen_structs_and_enums() function par:gen_structs_and_enums()
local outtab = {} local outtab = {}
local outtabpre = {} local outtabpre = {}
@@ -1083,11 +1094,12 @@ function M.Parser()
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
if it.parent and it.parent.re_name == "struct_re" then if it.parent then --and (it.parent.re_name == "struct_re" or it.parent.re_name == "typedef_st_re" then
--TODO nesting more levels and namespace local embededst = (it.re_name == "struct_re" and it.item:match("struct%s+(%S+)"))
local stname = it.parent.item:match("struct%s+(%S+)") or (it.re_name == "typedef_st_re" and it.item:match("%b{}%s*(%S+)%s*;"))
local embededst = it.item:match("struct%s+(%S+)") --TODO nesting namespace and class
self.embeded_structs[embededst] = stname.."::"..embededst local parname = get_parents_name(it)
self.embeded_structs[embededst] = parname..embededst
end end
elseif it.re_name == "namespace_re" or it.re_name == "union_re" or it.re_name == "functype_re" then elseif it.re_name == "namespace_re" or it.re_name == "union_re" or it.re_name == "functype_re" then
--nop --nop