harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit de9d0c8926b01712f924bccd731415f96a1bffce
parent 858404bda6a1a4cbc789905d1028ae73f98e7cbf
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri, 17 Jun 2022 17:28:17 -0400

check: only allow one fn declaration attribute

Now, harec will error if a function is declared with multiple
conflicting attributes (@init, @fini, @test).

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Msrc/check.c | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -3206,16 +3206,21 @@ check_function(struct context *ctx, decl->func.body = body; // TODO: Add function name to errors - if ((decl->func.flags & FN_INIT) - || (decl->func.flags & FN_FINI) - || (decl->func.flags & FN_TEST)) { + if (decl->func.flags != 0) { const char *flag; - if (decl->func.flags & FN_INIT) { + switch (decl->func.flags) { + case FN_INIT: flag = "@init"; - } else if (decl->func.flags & FN_FINI) { + break; + case FN_FINI: flag = "@fini"; - } else { + break; + case FN_TEST: flag = "@test"; + break; + default: + expect(ctx, &adecl->loc, 0, + "Only one of @init, @fini, or @test may be used in a function declaration"); }; expect(ctx, &adecl->loc, fntype->func.result == &builtin_type_void, "%s function must return void", flag);