summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-06-28 03:08:04 +0200
committermetamuffin <metamuffin@disroot.org>2025-06-28 03:08:04 +0200
commit06bf61c38929060704e65855bf35b7e6004eb72c (patch)
tree1e259be9c6a12aebc5787bb660cabf7f59010a64
parentfbb4db921ec1cb59c9264aab78d4dd3a7ef6d030 (diff)
downloadattocc-06bf61c38929060704e65855bf35b7e6004eb72c.tar
attocc-06bf61c38929060704e65855bf35b7e6004eb72c.tar.bz2
attocc-06bf61c38929060704e65855bf35b7e6004eb72c.tar.zst
continue function declsHEADmaster
-rw-r--r--attocc.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/attocc.c b/attocc.c
index 82ea8d8..b608805 100644
--- a/attocc.c
+++ b/attocc.c
@@ -663,6 +663,8 @@ struct global_context {
char **enums;
};
+struct function_context {};
+
int gcx_find_enum(struct global_context *gcx, char *name) {
for (int i = 0; i < gcx->num_enums; i++)
if (strlen(gcx->enums[i]) == strlen(name) &&
@@ -735,6 +737,8 @@ int enum_decl(struct global_context *gcx, struct token_iter *iter,
int read_type(struct global_context *gcx, struct token_iter *iter,
struct token *a, struct type *ty) {
+ ty->pointer_level = 0;
+
if (a->kind != TOK_KEYWORD)
return 1;
if (a->data.keyword == KW_STRUCT) {
@@ -815,8 +819,26 @@ int function_decl(struct global_context *gcx, struct token_iter *iter,
fprintf(stderr, "expected lcurly after function head\n");
return 1;
}
- if (token_step(iter, a)) // lcurly
- return 1;
+
+ while (1) {
+ if (a->kind == TOK_SEPERATOR && a->data.seperator == SEP_RCURLY)
+ break;
+ struct type type;
+ int res = read_type(gcx, iter, a, &type);
+ if (!res) {
+ // var decl
+ if (a->kind != TOK_IDENTIFIER) {
+ fprintf(stderr, "expected ident after type\n");
+ return 1;
+ }
+ char *varname = strdup_failsafe(a->data.identifier);
+ if (token_step(iter, a))
+ return 1;
+
+ } else {
+ TRAP
+ }
+ }
return 0;
}