diff options
author | kdx <kdx@42l.fr> | 2023-03-16 00:58:35 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-03-16 00:58:35 +0100 |
commit | bfd3c4cf7a324d08e180dce36ea547a51fb50cae (patch) | |
tree | b9581d37d4e9cce52a73ab511ebe47a84eedf7ae | |
parent | f3f52fafb74dd9f94f405f704b82b06a1a5efcf4 (diff) | |
download | golem-bfd3c4cf7a324d08e180dce36ea547a51fb50cae.tar.gz |
declaration identification removes identifier
-rw-r--r-- | identify.c | 28 | ||||
-rw-r--r-- | identify.h | 8 |
2 files changed, 19 insertions, 17 deletions
@@ -3,20 +3,23 @@ #include <stddef.h> static int -identify_dec(Token *list, unsigned int type) +identify_dec(Token **list, unsigned int type) { - if (list == NULL || list->next == NULL) + if (*list == NULL || (*list)->next == NULL) return 0; - if (list->type != type) + if ((*list)->type != type) return 0; - for (Token *e = list->next; e != NULL; e = e->next) + for (Token *e = (*list)->next; e != NULL; e = e->next) if (e->type != TOK_WORD) return 0; + + // Delete redundant first element (always the type keyword). + token_delete(list, *list); return 1; } void -identify(Token *list, int (*fun)(Token*), unsigned int type, int recurse) +identify(Token *list, int (*fun)(Token**), unsigned int type, int recurse) { if (recurse) for (Token *e = list; e != NULL; e = e->next) @@ -24,31 +27,30 @@ identify(Token *list, int (*fun)(Token*), unsigned int type, int recurse) identify(e->group.tokens, fun, type, 1); for (Token *e = list; e != NULL; e = e->next) - if (token_isgroup(e, GROUP_ATOM) && fun(e->group.tokens)) + if (token_isgroup(e, GROUP_ATOM) && fun(&e->group.tokens)) e->group.type = type; } int -identify_function(Token *list) +identify_function(Token **list) { - while (list != NULL) { - if (list->next == NULL && !token_isgroup(list, GROUP_SCOPE)) + for (Token *e = *list; e != NULL; e = e->next) { + if (e->next == NULL && !token_isgroup(*list, GROUP_SCOPE)) return 0; - if (list->next != NULL && list->type != TOK_WORD) + if (e->next != NULL && e->type != TOK_WORD) return 0; - list = list->next; } return 1; } int -identify_global(Token *list) +identify_global(Token **list) { return identify_dec(list, TOK_KW_GLOBAL); } int -identify_local(Token *list) +identify_local(Token **list) { return identify_dec(list, TOK_KW_LOCAL); } @@ -1,7 +1,7 @@ #pragma once #include "token.h" -void identify(Token *list, int (*fun)(Token*), unsigned int type, int recurse); -int identify_function(Token *list); -int identify_global(Token *list); -int identify_local(Token *list); +void identify(Token *list, int (*fun)(Token**), unsigned int type, int recurse); +int identify_function(Token **list); +int identify_global(Token **list); +int identify_local(Token **list); |