Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marekuzel committed Dec 6, 2023
1 parent 4510c71 commit 25582e3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 27 additions & 2 deletions src/symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
} \
Expand All @@ -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--]; \
Expand Down

0 comments on commit 25582e3

Please sign in to comment.