Mercurial > pub > dyncall > dyncall
annotate test/suite_aggrs/mk-cases.lua @ 434:3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
author | Tassilo Philipp |
---|---|
date | Sun, 23 Jan 2022 23:20:02 +0100 |
parents | 45662241d9cd |
children | a29baee68340 |
rev | line source |
---|---|
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
1 require"math" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
2 local max = math.max |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
3 local maxargs = 0 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
4 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
5 local 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
|
6 local seen_aggrs = { } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
7 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
8 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
9 function canon_type(t) |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
10 -- struct types have more than one char |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
11 if #t > 1 then |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
12 return 'struct '..t |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
13 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
14 return t |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
15 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
16 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
17 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
18 function mkcase(id,sig) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
19 local sig = trim(sig) |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
20 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
|
21 local t = { "" } |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
22 local pos = 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
|
23 local n_nest = 0 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
24 local aggr = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
25 local aggr_sig = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
26 aggr[0] = { } -- non-sequential [0] collects all non-aggr types |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
27 aggr_sig[0] = '' |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
28 for i = 1, #sig 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
|
29 local name = "a"..pos |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
30 local ch = sig:sub(i,i) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
31 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
32 -- aggregate nest level change? |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
33 if ch == '{' then |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
34 n_nest = n_nest + 1 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
35 aggr[n_nest] = { } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
36 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
|
37 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
38 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
39 aggr_sig[n_nest] = aggr_sig[n_nest]..ch |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
40 |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
41 if ch == '}' then |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
42 -- register yet unseen aggregates, key is sig, val is body and name |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
43 if seen_aggrs[aggr_sig[n_nest]] == nil then |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
44 aggrs[#aggrs+1] = aggr_sig[n_nest] |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
45 ch = 'A'..#aggrs |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
46 seen_aggrs[aggr_sig[n_nest]] = { aggr[n_nest], ch } |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
47 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
48 ch = seen_aggrs[aggr_sig[n_nest]][2] |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
49 |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
50 n_nest = n_nest - 1 |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
51 aggr_sig[n_nest] = aggr_sig[n_nest]..aggr_sig[n_nest+1] |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
52 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
53 |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
54 if ch ~= '{' and ch ~= '}' then |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
55 aggr[n_nest][#aggr[n_nest]+1] = canon_type(ch) |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
56 aggr[n_nest][#aggr[n_nest]+1] = 'm'..(#aggr[n_nest] >> 1) |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
57 end |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
58 |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
59 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
60 if n_nest == 0 then |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
61 h[#h+1] = canon_type(ch) |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
62 -- struct types (more than one char) need copying via a func |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
63 if #ch > 1 then |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
64 t[#t+1] = 'f_cp'..ch..'(V_a['..pos.."],&"..name..");" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
65 else |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
66 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
67 end |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
68 |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
69 -- is return type or func arg? |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
70 if pos == 0 then |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
71 h[#h+1] = " f"..id.."(" |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
72 h[#h+1] = '' |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
73 t[#t] = '' -- clear; aggr return type handled explicitly |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
74 else |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
75 h[#h+1] = ' '..name |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
76 h[#h+1] = "," |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
77 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
|
78 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
79 pos = pos + 1 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
80 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
81 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
82 maxargs = max(maxargs, pos-1) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
83 h[#h] = "){" |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
84 if #h[6] == 1 then |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
85 t[#t+1] = "ret_"..h[6].."("..(pos-1)..")}\n" |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
86 else |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
87 t[#t+1] = "ret_a("..(pos-1)..","..h[6]..")}\n" |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
88 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
|
89 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
|
90 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
91 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
92 function mkfuntab(n) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
93 local s = { "funptr G_funtab[] = {\n"} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
94 for i = 0, n-1 do |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
95 s[#s+1] = "\t(funptr)&f"..i..",\n" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
96 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
97 s[#s+1] = "};\n" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
98 return table.concat(s,"") |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
99 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
100 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
101 function mksigtab(sigs) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
102 local s = { "char const * G_sigtab[] = {\n"} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
103 for k,v in pairs(sigs) do |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
104 s[#s+1] = '\t"'..v..'",\n' |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
105 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
106 s[#s+1] = "};\n" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
107 return table.concat(s,"") |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
108 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
109 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
110 function mkall() |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
111 local lineno = 0 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
112 local sigtab = { } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
113 local cases = '' |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
114 for line in io.lines() do |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
115 local sig = trim(line) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
116 cases = cases..mkcase(lineno,sig) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
117 sigtab[#sigtab+1] = sig |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
118 lineno = lineno + 1 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
119 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
120 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
121 agg_sizes = {} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
122 agg_sigs = {} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
123 agg_names = {} |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
124 for a = 1, #aggrs do |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
125 k = aggrs[a] |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
126 v = seen_aggrs[k] |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
127 st = 'struct '..v[2] |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
128 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
129 agg_sizes[#agg_sizes + 1] = 'sizeof('..st..')' |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
130 agg_sigs [#agg_sigs + 1] = k |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
131 agg_names[#agg_names + 1] = v[2] |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
132 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
133 -- struct def |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
134 io.write('/* '..k..' */\n') |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
135 io.write(st..' { ') |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
136 for i = 1, #v[1], 2 do |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
137 io.write(v[1][i]..' '..v[1][i+1]..'; ') |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
138 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
139 io.write("};\n") |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
140 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
141 -- struct cp and cmp funcs |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
142 s = { |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
143 'void f_cp'..v[2]..'('..st..' *x, const '..st..' *y) { ', |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
144 'int f_cmp'..v[2]..'(const '..st..' *x, const '..st..' *y) { return ' |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
145 } |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
146 o = { '=', '==', 'f_cp', 'f_cmp', '; ', ' && ' } |
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 for t = 1, 2 do |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
148 io.write(s[t]) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
149 b = {} |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
150 for i = 1, #v[1], 2 do |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
151 if string.match(v[1][i], '^struct') then |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
152 b[#b+1] = o[t+2]..v[1][i]:sub(8)..'(&x->'..v[1][i+1]..', &y->'..v[1][i+1]..')'; |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
153 else |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
154 b[#b+1] = 'x->'..v[1][i+1]..' '..o[t]..' y->'..v[1][i+1]; |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
155 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
|
156 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
157 if #b == 0 then |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
158 b[1] = '1' -- to handle empty structs |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
159 end |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
160 io.write(table.concat(b,o[t+4]).."; };\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
|
161 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
162 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
163 -- convenient dcnewstruct helper funcs |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
164 io.write('static int nfields'..v[2]..' = '..(#v[1]>>1)..';\n') |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
165 io.write('DCstruct* f_newdcst'..v[2]..'(DCstruct* parent) {\n\tDCstruct* st = parent;\n\tif(!st) st = dcNewStruct(nfields'..v[2]..', sizeof('..st..'), 0, 1);\n\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
|
166 for i = 1, #v[1], 2 do |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
167 if string.match(v[1][i], '^struct') then |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
168 io.write('dcSubStruct(st, nfields'..v[1][i]:sub(8)..', offsetof('..st..', '..v[1][i+1]..'), sizeof('..v[1][i]..'), 0, DC_TRUE, 1);\n\t') |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
169 io.write("f_newdcst"..v[1][i]:sub(8)..'(st);\n\t') |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
170 else |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
171 io.write("dcStructField(st, '"..v[1][i].."', offsetof("..st..', '..v[1][i+1]..'), 1);\n\t') |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
172 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
|
173 end |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
433
diff
changeset
|
174 io.write("dcCloseStruct(st);\n\treturn st;\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
|
175 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
176 |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
177 -- make table.concat work |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
178 if #agg_names > 0 then |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
179 table.insert(agg_names, 1, '') |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
180 end |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
181 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
182 io.write(cases) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
183 io.write(mkfuntab(lineno)) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
184 io.write(mksigtab(sigtab)) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
185 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
|
186 io.write('int G_agg_sizes[] = {\n\t'..table.concat(agg_sizes, ',\n\t')..'\n};\n') |
433
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
187 io.write('funptr G_agg_newdcstfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_newdcst'),2)..'\n};\n') |
45662241d9cd
suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents:
432
diff
changeset
|
188 io.write('funptr G_agg_cmpfuncs[] = {'..string.sub(table.concat(agg_names, ',\n\t(funptr)&f_cmp'),2)..'\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
|
189 io.write("int G_maxargs = "..maxargs..";\n") |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
190 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
191 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
192 mkall() |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
193 |