From 25582e38e670dab76951e00e3c3ed212abe049c2 Mon Sep 17 00:00:00 2001 From: marekuzel Date: Thu, 7 Dec 2023 00:23:14 +0100 Subject: [PATCH] added comments --- src/symtable.c | 8 ++++---- src/symtable.h | 29 +++++++++++++++++++++++++++-- src/utils.c | 4 ++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/symtable.c b/src/symtable.c index 4ea94bc..3b6919a 100644 --- a/src/symtable.c +++ b/src/symtable.c @@ -175,7 +175,7 @@ void awl_insert(awl_t **awl, char *key, symtable_entry_t *entry) { CHECK_MEM_ERR(*awl) - (*awl)->key = add_string(key); + (*awl)->key = copy_str(key); (*awl)->value = entry; (*awl)->left = NULL; (*awl)->right = NULL; @@ -451,8 +451,8 @@ param_t *param_create(char *id, char *name, TokenType type) { CHECK_MEM_ERR(new_param) - new_param->id = add_string(id); - new_param->name = add_string(name); + new_param->id = copy_str(id); + new_param->name = copy_str(name); new_param->type = type; return new_param; @@ -545,7 +545,7 @@ bool is_global(symtable_t *table, char *name) { } -char* add_string(char *str) { +char* copy_str(char *str) { assert(str != NULL); size_t str_len = strlen(str); diff --git a/src/symtable.h b/src/symtable.h index 372a5fe..daeccd7 100644 --- a/src/symtable.h +++ b/src/symtable.h @@ -374,12 +374,37 @@ void table_insert_builtin_funcs(symtable_t *table); */ bool is_global(symtable_t *table, char *name); - +/** + * @brief exports paramBuffer to an array of param_t + * @param buffer: pointer to a paramBuffer + * + * @return param_t** + */ param_t **param_buffer_export(ParamBufferT *); +/** + * @brief adding parameter of function to local scope + * + * @param table ptr to local symtable + * @param entry paramater entry + */ void add_params_to_scope(symtable_t *table, symtable_entry_t *entry); -char* add_string(char *str); +/** + * @brief creates a copy of a string + * + * @param str ptr to string + * @return char* ptr to copy of string + */ +char* copy_str(char *str); +/** + * @brief searches local symtable for a given name + * + * @param table ptr to local symtable + * @param name name to find + * @return true if found + * @return false if not found + */ bool table_search_local(symtable_t *table, char *name); #endif \ No newline at end of file diff --git a/src/utils.c b/src/utils.c index be942c3..979b7aa 100644 --- a/src/utils.c +++ b/src/utils.c @@ -239,7 +239,7 @@ void token_dtor(TokenT *token) { \ void stack_##TNAME##_push(stack_##TNAME##_t *stack, T item) { \ if (stack->top == MAXSTACK - 1) { \ - fprintf(stderr,"[W] Stack overflow\n"); \ + fprintf(stderr,"[W] Stack overflow\n"); \ } else { \ stack->items[++stack->top] = item; \ } \ @@ -254,7 +254,7 @@ void token_dtor(TokenT *token) { \ T stack_##TNAME##_pop(stack_##TNAME##_t *stack) { \ if (stack->top == -1) { \ - fprintf(stderr,"[W] Stack underflow\n"); \ + fprintf(stderr,"[W] Stack underflow\n"); \ return NULL; \ } \ return stack->items[stack->top--]; \