annotate test/call_suite_aggrs/mk-cases.lua @ 519:99819b874bac

test/call_suite_aggrs: - refactored generator code a bit to be simpler, write cleaner output, have better shareability and clarity - added rtypes w/ default value nil to config.lua, to self document - shared some code under test/common/ - fixed nonemptyaggrs sigs and cases.h (accidentally overwritten with cases having empty aggrs)
author Tassilo Philipp
date Mon, 11 Apr 2022 22:26:07 +0200
parents 01f928eb9584
children a2de1d0a73f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
1 require"config"
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
2 require"math"
514
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
3
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
4 -- use shared helpers to generate cases
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
5 package.path = '../common/?.lua;' .. package.path
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
6 require"mk-cases"
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
7
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
8
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
9 local max_numargs = 0
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
10
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
11
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
12
496
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
13 function put_sig_rtype_first(sig)
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
14 return sig:sub(sig:find(')')+1,-1)..sig:sub(1,sig:find(')')-1)
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
15 end
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
16
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
17
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
18 -- returns one case as str; accumulates unique idx => aggr-sig in aggrs
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
19 -- (sequentially) and aggr-sig => {body,name} in seen_aggrs (depth first for
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
20 -- nested aggrs, so sub-aggrs conveniently precede parents)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
21 function mkcase(id, sig, aggrs, seen_aggrs)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
22 local sig = trim(sig)
496
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
23 local fsig = put_sig_rtype_first(sig)
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
24 local h = { "/* ",id,":",sig," */ " }
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
25 local t = { "" }
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
26 local pos = -1
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
27 local n_nest = 0
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
28 local aggr = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
29 local aggr_sig = { }
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
30 aggr[0] = { } -- non-sequential [0] collects all non-aggr types (not used, though)
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
31 aggr_sig[0] = ''
496
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
32 for i = 1, #fsig do
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
33 local name = "a"..pos
496
da5232da6270 - test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents: 485
diff changeset
34 local ch = fsig:sub(i,i)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
35
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
36
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
37 -- aggregate nest level change?
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
38 if ch == '{' or ch == '<' then
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
39 n_nest = n_nest + 1
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
40 aggr[n_nest] = { }
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
41 aggr_sig[n_nest] = ''
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
42 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
43
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
44 aggr_sig[n_nest] = aggr_sig[n_nest]..ch
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
45
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
46 -- array? Just append to name of member var from prev loop
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
47 if ch:match('[%[%]0123456789]') ~= nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
48 aggr[n_nest][#aggr[n_nest]] = aggr[n_nest][#aggr[n_nest]]..ch
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
49 else
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
50 -- register (sub)aggrs on closing char
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
51 if ch == '}' or ch == '>' then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
52 -- only add unseen aggregates, key is aggr sig, val is body and name
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
53 if seen_aggrs[aggr_sig[n_nest]] == nil then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
54 aggrs[#aggrs+1] = aggr_sig[n_nest]
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
55 if ch == '}' then ch = 'struct ' else ch = 'union ' end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
56 ch = ch..'A'..#aggrs
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
57 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch }
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
58 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
59 ch = seen_aggrs[aggr_sig[n_nest]][2]
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
60
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
61 n_nest = n_nest - 1
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
62 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
63 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
64
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
65 -- add member type and var name to aggr
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
66 if ch ~= '{' and ch ~= '}' and ch ~= '<' and ch ~= '>' then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
67 aggr[n_nest][#aggr[n_nest]+1] = ch
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
68 aggr[n_nest][#aggr[n_nest]+1] = 'm'..(#aggr[n_nest] >> 1)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
69 end
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
70
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
71 -- no nesting (= actual func args), generate case code
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
72 if n_nest == 0 then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
73 h[#h+1] = ch
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
74 -- aggregate types have more than one char
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
75 if #h[#h] > 1 then
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
76 if aggrcpsimple then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
77 t[#t+1] = '*('..h[#h]..'*)V_a['..pos.."]="..name..";"
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
78 else
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
79 t[#t+1] = 'f_cp'..h[#h]:match('A.*')..'(V_a['..pos.."],&"..name..");"
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
80 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
81 if aggrmutabletest then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
82 t[#t] = t[#t]..'memset(&'..name..',0,sizeof('..name..'));'
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
83 end
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
84 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
85 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";"
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
86 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
87
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
88 -- is return type or func arg?
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
89 if pos == -1 then
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
90 h[#h+1] = " f"..id.."("
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
91 h[#h+1] = ''
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
92 t[#t] = '' -- clear; aggr return type handled explicitly
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
93 else
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
94 h[#h+1] = ' '..name
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
95 h[#h+1] = ","
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
96 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
97
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
98 pos = pos + 1
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
99 end
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
100 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
101 end
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
102 max_numargs = math.max(max_numargs, pos)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
103 h[#h] = "){"
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
104 if #h[6] == 1 then
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
105 t[#t+1] = "ret_"..h[6].."("..pos..")}\n"
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
106 else
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
107 t[#t+1] = "ret_a("..pos..","..h[6]..")}\n"
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
108 end
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
109 return table.concat(h,"")..table.concat(t,"")
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
110 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
111
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
112
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
113 function mkaggrdefs(aggrs, seen_aggrs)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
114 local agg_defs = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
115 local agg_sizes = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
116 local agg_sigs = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
117 local agg_names = { }
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 500
diff changeset
118
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 433
diff changeset
119 for a = 1, #aggrs do
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
120 local k = aggrs[a]
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
121 local v = seen_aggrs[k]
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
122 local am = v[1] -- aggregate members
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
123 local at = v[2] -- aggregate type
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
124 local an = at:match('A.*') -- aggregate name (w/o struct or union)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
125
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
126 -- aggregate def
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
127 aggr_def = '/* '..k..' */\n'
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
128 if aggrpacking ~= 0 then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
129 local pack = aggrpacking
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
130 if pack < 0 then
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
131 pack = math.floor(math.pow(2,math.floor(math.log(math.random(math.abs(pack)),2))))
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
132 end
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
133 aggr_def = aggr_def..'#pragma pack(push,'..pack..')\n'
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
134 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
135
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
136 aggr_def = aggr_def..at..' { '
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
137 for i = 1, #am, 2 do
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
138 aggr_def = aggr_def..am[i]..' '..am[i+1]..'; '
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
139 end
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
140 aggr_def = aggr_def..'};\n'
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
141
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
142 if aggrpacking ~= 0 then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
143 aggr_def = aggr_def..'#pragma pack(pop)\n'
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
144 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
145
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 441
diff changeset
146 -- aggregate cp and cmp funcs
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
147 s = {
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
148 'void f_cp'..an..'('..at..' *x, const '..at..' *y) { ',
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
149 'int f_cmp'..an..'(const '..at..' *x, const '..at..' *y) { return '
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
150 }
441
e59e381b4fca - suite_aggrs: silenced warning, generated real case list
Tassilo Philipp
parents: 438
diff changeset
151 o = { '=', '==', 'f_cp', 'f_cmp', '; ', ' && ', '', '1' }
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
152 for t = 1, 2 do
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
153 if t ~= 1 or aggrcpsimple == false then
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
154 aggr_def = aggr_def..s[t]
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
155 local b = {}
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
156 for i = 1, #am, 2 do
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
157 local mn, mc = split_array_decl(am[i+1]) -- aggr member name and (array) count
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
158 local fmt = ''
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
159 if mc ~= nil then -- need array suffixes?
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
160 fmt = '[%d]'
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
161 else
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
162 mc = 1
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
163 end
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
164
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
165 for j = 1, mc do
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
166 name = mn..fmt:format(j-1)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
167 amn = am[i]:match('A.*')
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
168 if amn then -- is aggr?
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
169 b[#b+1] = o[t+2]..amn..'(&x->'..name..', &y->'..name..')'
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
170 else
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
171 b[#b+1] = 'x->'..name..' '..o[t]..' y->'..name
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
172 end
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
173 end
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
174 end
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
175 if #b == 0 then -- to handle empty aggregates
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
176 b[1] = o[t+6]
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
177 end
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
178 aggr_def = aggr_def..table.concat(b,o[t+4])..'; };\n'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
179 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
180 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
181
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
182 -- write convenient dcNewAggr() helper/wrapper funcs
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
183 aggr_def = aggr_def..'DCaggr* f_touchdcst'..an..'() {\n\tstatic DCaggr* a = NULL;\n\tif(!a) {\n\t\ta = dcNewAggr('..(#am>>1)..', sizeof('..at..'));\n\t\t'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
184 for i = 1, #am, 2 do
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
185 local mn, mc = split_array_decl(am[i+1])
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
186 if mc == nil then
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
187 mc = 1
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
188 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
189 amn = am[i]:match('A.*')
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
190 if amn then -- is aggr?
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
191 --aggr_def = aggr_def..'dcAggrField(at, DC_SIGCHAR_AGGREGATE, offsetof('..at..', '..mn..'), '..mc..', f_touchdcst'..amn..'());\n\t\t'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
192 aggr_def = aggr_def.."AFa("..at..','..mn..','..mc..','..amn..')\n\t\t'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
193 else
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
194 --aggr_def = aggr_def.."dcAggrField(at, '"..am[i].."', offsetof("..at..', '..mn..'), '..mc..');\n\t\t'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
195 aggr_def = aggr_def.."AF('"..am[i].."',"..at..','..mn..','..mc..')\n\t\t'
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
196 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
197 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
198
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
199 agg_defs [#agg_defs + 1] = aggr_def..'dcCloseAggr(a);\n\t}\n\treturn a;\n};'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
200 agg_sizes[#agg_sizes + 1] = 'sizeof('..at..')'
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
201 agg_sigs [#agg_sigs + 1] = k
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
202 agg_names[#agg_names + 1] = an
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
203 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
204
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
205 return agg_defs, agg_sizes, agg_sigs, agg_names
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
206 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
207
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
208
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
209 function mkall()
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
210 local lineno = 0
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
211 local sigtab = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
212 local cases = ''
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
213 local aggrs = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
214 local seen_aggrs = { }
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
215
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
216
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
217 for line in io.lines() do
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
218 local sig = trim(line)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
219 cases = cases..mkcase(lineno, sig, aggrs, seen_aggrs)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
220 sigtab[#sigtab+1] = sig
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
221 lineno = lineno + 1
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
222 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
223
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
224 local agg_defs, agg_sizes, agg_sigs, agg_names = mkaggrdefs(aggrs, seen_aggrs)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
225
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
226 -- make table.concat work
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
227 if #agg_names > 0 then
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
228 table.insert(agg_names, 1, '')
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
229 end
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
230
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
231 io.write(table.concat(agg_defs,'\n')..'\n')
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
232 io.write(cases)
512
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 510
diff changeset
233 io.write(mkfuntab(lineno, 'f', 'funptr', 'G_funtab', true))
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents: 510
diff changeset
234 io.write(mksigtab(sigtab, '', 'G_sigtab'))
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
235 io.write('const char* G_agg_sigs[] = {\n\t"'..table.concat(agg_sigs, '",\n\t"')..'"\n};\n')
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
236 io.write('int G_agg_sizes[] = {\n\t'..table.concat(agg_sizes, ',\n\t')..'\n};\n')
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
237 io.write('funptr G_agg_touchdcstfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_touchdcst'),2)..'\n};\n')
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
238 io.write('funptr G_agg_cmpfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_cmp'),2)..'\n};\n')
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
239 io.write("int G_maxargs = "..max_numargs..";\n")
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
240 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
241
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
242 math.randomseed(seed)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
243 mkall()
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
244