Skip to content

Commit 20c42bb

Browse files
author
Kabombom
committed
Frees symbol tables
1 parent 3e0542a commit 20c42bb

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

symbol_table.c

+51
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,54 @@ void show_tables() {
182182
aux = aux->next;
183183
}
184184
}
185+
186+
void destroy_param_types(param_type *current) {
187+
if (current == NULL) {
188+
return;
189+
}
190+
191+
if (current->name != NULL) {
192+
free(current->name);
193+
}
194+
195+
destroy_param_types(current->next);
196+
197+
free(current);
198+
}
199+
200+
void destroy_symbols(symbol *current) {
201+
if (current == NULL) {
202+
return;
203+
}
204+
205+
if (current->name != NULL) {
206+
free(current->name);
207+
}
208+
if (current->type != NULL) {
209+
free(current->type);
210+
}
211+
if (current->param != NULL) {
212+
destroy_param_types(current->param);
213+
}
214+
215+
destroy_symbols(current->next);
216+
217+
free(current);
218+
}
219+
220+
void destroy_tables(table *current) {
221+
if (current == NULL) {
222+
return;
223+
}
224+
225+
if (current->name != NULL) {
226+
free(current->name);
227+
}
228+
if(current->symbol != NULL) {
229+
destroy_symbols(current->symbol);
230+
}
231+
232+
destroy_tables(current->next);
233+
234+
free(current);
235+
}

symbol_table.h

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ void show_symbol(symbol *symbol);
4949
void show_table(table *table);
5050
void show_tables();
5151

52+
void destroy_param_types(param_type *param);
53+
void destroy_symbols(symbol *symbols);
54+
void destroy_tables();
55+
5256
table *tables;
5357
table *current;
5458

uccompiler.l

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ int main(int argc, char *argv[]) {
189189
check_program(ast);
190190
generate_code(ast);
191191
destroy_ast(ast);
192+
destroy_tables(tables);
192193
}
193194
}
194195
return 0;
@@ -203,3 +204,4 @@ void yyerror (char *s) {
203204
int aux_col = col - strlen(yytext);
204205
printf("Line %d, col %d: %s: %s\n", line, aux_col, s, yytext);
205206
}
207+

0 commit comments

Comments
 (0)