aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:58:59 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:58:59 +0330
commit77d2f8a44e2503796a7ef5c170e11811a4f7fcfd (patch)
treedf316b685295cecaf8d587ad3bf36a245839abca /src
parentbool: normalising into a bool keeps an incompatible source type, so the retur... (diff)
prototypes: parameters may be unnamed, int f(int, int*); (appendix b.2.13)
Diffstat (limited to 'src')
-rw-r--r--src/compiler/decl.zc13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc
index e9500c4..87281ad 100644
--- a/src/compiler/decl.zc
+++ b/src/compiler/decl.zc
@@ -282,7 +282,7 @@ int body() {
// into stype, checked against any earlier prototype or prescan result, and
// where the o3 region for an o3 function is handed to the core)
int fndef(int chk, int rty, int ret, int n) {
- int s, np = 0, tags = 0, t, sig, i; char*[24] pn; word[24] pt; word[24] pty; int typed = 0, ft, explicit_rty = !!rty, o3f = o3nxt, lo, hi, pk, lt, lend, lfl = tline, redef;
+ int s, np = 0, tags = 0, t, sig, i; char*[24] pn; word[24] pt; word[24] pty; int typed = 0, ft, explicit_rty = !!rty, o3f = o3nxt, lo, hi, pk, lt, lend, lfl = tline, redef, amb = 0, nonm = 0;
o3nxt = 0;
if (rty || ntp) typed = 1;
if (!dnm) dnm = n;
@@ -327,7 +327,9 @@ int fndef(int chk, int rty, int ret, int n) {
} else if (tv == s_d) t = 2; else die("a parameter tag is .m or .d");
next();
}
- pnoffs[np] = toff; pnplaces[np] = tpack(); rs_note(RS_PARAM, toff); pn[np] = name();
+ pnoffs[np] = toff; pnplaces[np] = tpack(); rs_note(RS_PARAM, toff);
+ if (!pk && !t && tk == T_ID && istypename(tv)) amb = amb | (1 << np); // int f(int): a name, or a type if this is a prototype
+ if (pk && tk == T_OP && (tv == s_comma || tv == s_rp)) { pn[np] = 0; nonm = 1; } else pn[np] = name(); // int f(int*, int): a prototype's parameters may be unnamed
if (o3f && pty[np] == tword) serr("o3 parameters need a type");
if (np >= 12 && t) die("only the first 12 parameters can be tagged");
pt[np] = t;
@@ -338,6 +340,13 @@ int fndef(int chk, int rty, int ret, int n) {
}
}
expect(s_rp);
+ if (is_op(s_semi)) { // a prototype: a lone type name is an unnamed parameter of that type (b.2.13)
+ i = 0;
+ while (i < np) {
+ if (((amb >> i) & 1) && pn[i]) { t = lookup(pn[i]); if (t >= 0 && skind[t] == K_TYPE) { pty[i] = sval[t]; typed = 1; } }
+ i++;
+ }
+ } else if (nonm) serr("a parameter needs a name");
sig = ret + np + np + tags * 64;
if ((sflag[s] & F_SIG) && !(sflag[s] & F_PRE)) {
if (ssig[s] != sig) serrn(n, "doesn't match its earlier declaration");