summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-03-16 00:58:35 +0100
committerkdx <kdx@42l.fr>2023-03-16 00:58:35 +0100
commitbfd3c4cf7a324d08e180dce36ea547a51fb50cae (patch)
treeb9581d37d4e9cce52a73ab511ebe47a84eedf7ae
parentf3f52fafb74dd9f94f405f704b82b06a1a5efcf4 (diff)
downloadgolem-bfd3c4cf7a324d08e180dce36ea547a51fb50cae.tar.gz
declaration identification removes identifier
-rw-r--r--identify.c28
-rw-r--r--identify.h8
2 files changed, 19 insertions, 17 deletions
diff --git a/identify.c b/identify.c
index def4438..f3a102a 100644
--- a/identify.c
+++ b/identify.c
@@ -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);
}
diff --git a/identify.h b/identify.h
index 1986469..a70c297 100644
--- a/identify.h
+++ b/identify.h
@@ -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);