Mercurial > pub > dyncall > dyncall
diff test/suite_aggrs/mk-cases.lua @ 461:236015fdf7a8
suite_aggrs:
- added support to gen unions in addition to structs
- regenerated struct/union-mixed and nested cases
- made rand-sig.lua ignore closing struct/union chars if not opened, effectively reducing number of empty aggregates as it now generated way too much
author | Tassilo Philipp |
---|---|
date | Mon, 31 Jan 2022 14:41:11 +0100 |
parents | e59e381b4fca |
children | 653b65580cb4 |
line wrap: on
line diff
--- a/test/suite_aggrs/mk-cases.lua Sun Jan 30 17:12:47 2022 +0100 +++ b/test/suite_aggrs/mk-cases.lua Mon Jan 31 14:41:11 2022 +0100 @@ -7,9 +7,10 @@ function canon_type(t) - -- struct types have more than one char - if #t > 1 then - return 'struct '..t + -- aggregate types start with special (closing) char + c = ({ ['}'] = 'struct ', ['>'] = 'union ' })[t:sub(1,1)] + if c ~= nil then + return c..'A'..t:sub(2) end return t end @@ -30,7 +31,7 @@ local ch = sig:sub(i,i) -- aggregate nest level change? - if ch == '{' then + if ch == '{' or ch == '<' then n_nest = n_nest + 1 aggr[n_nest] = { } aggr_sig[n_nest] = '' @@ -38,11 +39,11 @@ aggr_sig[n_nest] = aggr_sig[n_nest]..ch - if ch == '}' then + if ch == '}' or ch == '>' then -- register yet unseen aggregates, key is sig, val is body and name if seen_aggrs[aggr_sig[n_nest]] == nil then aggrs[#aggrs+1] = aggr_sig[n_nest] - ch = 'A'..#aggrs + ch = ch..#aggrs seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch } end ch = seen_aggrs[aggr_sig[n_nest]][2] @@ -51,7 +52,7 @@ aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1] end - if ch ~= '{' and ch ~= '}' then + if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then aggr[n_nest][#aggr[n_nest]+1] = canon_type(ch) aggr[n_nest][#aggr[n_nest]+1] = 'm'..(#aggr[n_nest] >> 1) end @@ -59,9 +60,9 @@ if n_nest == 0 then h[#h+1] = canon_type(ch) - -- struct types (more than one char) need copying via a func - if #ch > 1 then - t[#t+1] = 'f_cp'..ch..'(V_a['..pos.."],&"..name..");" + -- aggregate types (more than one char) need copying via a func + if #h[#h] > 1 then + t[#t+1] = 'f_cp'..h[#h]:sub(8)..'(V_a['..pos.."],&"..name..");" else t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" end @@ -124,13 +125,13 @@ for a = 1, #aggrs do k = aggrs[a] v = seen_aggrs[k] - st = 'struct '..v[2] + st = canon_type(v[2]) agg_sizes[#agg_sizes + 1] = 'sizeof('..st..')' agg_sigs [#agg_sigs + 1] = k - agg_names[#agg_names + 1] = v[2] + agg_names[#agg_names + 1] = st:sub(8) - -- struct def + -- aggregate def io.write('/* '..k..' */\n') io.write(st..' { ') for i = 1, #v[1], 2 do @@ -138,32 +139,32 @@ end io.write("};\n") - -- struct cp and cmp funcs + -- aggregate cp and cmp funcs s = { - 'void f_cp'..v[2]..'('..st..' *x, const '..st..' *y) { ', - 'int f_cmp'..v[2]..'(const '..st..' *x, const '..st..' *y) { return ' + 'void f_cp'..st:sub(8)..'('..st..' *x, const '..st..' *y) { ', + 'int f_cmp'..st:sub(8)..'(const '..st..' *x, const '..st..' *y) { return ' } o = { '=', '==', 'f_cp', 'f_cmp', '; ', ' && ', '', '1' } for t = 1, 2 do io.write(s[t]) b = {} for i = 1, #v[1], 2 do - if string.match(v[1][i], '^struct') then + if string.match(v[1][i], ' ') then -- aggregate canonical types contain at least one space b[#b+1] = o[t+2]..v[1][i]:sub(8)..'(&x->'..v[1][i+1]..', &y->'..v[1][i+1]..')'; else b[#b+1] = 'x->'..v[1][i+1]..' '..o[t]..' y->'..v[1][i+1]; end end - if #b == 0 then -- to handle empty structs + if #b == 0 then -- to handle empty aggregates b[1] = o[t+6] end io.write(table.concat(b,o[t+4]).."; };\n") end -- convenient dcnewstruct helper funcs - io.write('DCstruct* f_touchdcst'..v[2]..'() {\n\tstatic DCstruct* st = NULL;\n\tif(!st) {\n\t\tst = dcNewStruct('..(#v[1]>>1)..', sizeof('..st..'), DC_TRUE);\n\t\t') + io.write('DCstruct* f_touchdcst'..st:sub(8)..'() {\n\tstatic DCstruct* st = NULL;\n\tif(!st) {\n\t\tst = dcNewStruct('..(#v[1]>>1)..', sizeof('..st..'), DC_TRUE);\n\t\t') for i = 1, #v[1], 2 do - if string.match(v[1][i], '^struct') then + if string.match(v[1][i], ' ') then -- aggregate canonical types contain at least one space io.write('dcStructField(st, DC_SIGCHAR_STRUCT, offsetof('..st..', '..v[1][i+1]..'), 1, f_touchdcst'..v[1][i]:sub(8)..'());\n\t\t') else io.write("dcStructField(st, '"..v[1][i].."', offsetof("..st..', '..v[1][i+1]..'), 1);\n\t\t')