segfaults fixed. need to verify what is being passed to functions.

This commit is contained in:
Scarlett
2025-03-31 21:18:21 -04:00
parent 5e01b93af8
commit fac92f62f7

View File

@ -968,10 +968,24 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
}*/ }*/
void print_symbol_table(SymbolTable *table, FILE *file_ptr) { void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (table == NULL) {
printdebug(
"%s[FATAL] passed in NULL table to print_symbol_table",
COLOR_RED);
return;
}
if (table->Parent_Scope != NULL) {
printdebug("%s[WARNING] passed in a non-top level scope to "
"print_symbol_table",
COLOR_ORANGE);
}
if (table->Parent_Scope == NULL) { if (table->Parent_Scope == NULL) {
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
"SCOPE", "PARENT", "TYPE", "Extra annotation"); "SCOPE", "PARENT", "TYPE", "Extra annotation");
} }
TableNode *entrie = table->entries; TableNode *entrie = table->entries;
fprintf(file_ptr, "-----------------:--------:--------:----------------" fprintf(file_ptr, "-----------------:--------:--------:----------------"
"------:---------" "------:---------"
@ -1213,7 +1227,19 @@ bool typeCheck(char *firstID, char *secondID) {
return false; return false;
} }
SymbolTable *getParent(SymbolTable *st) { return st->Parent_Scope; } SymbolTable *getParent(SymbolTable *st) {
if (st == NULL) {
printdebug("passed a NULL symbol table to getParent function. "
"Invalid.");
return NULL;
}
if (st->Parent_Scope == NULL) {
printdebug("passed a top level scope to getParent function. "
"Invalid.");
return NULL;
}
return st->Parent_Scope;
}
ListOfTable *getChildren(SymbolTable *st) { return st->Children_Scope; } ListOfTable *getChildren(SymbolTable *st) { return st->Children_Scope; }
SymbolTable *getFirstChild(ListOfTable *lt) { return lt->table; } SymbolTable *getFirstChild(ListOfTable *lt) { return lt->table; }
@ -1231,8 +1257,7 @@ TableNode *getNextEntry(TableNode *tn) {
return undefined; return undefined;
} }
return tn->next; return tn->next;
} }
// uncomment the below main function along with the headers above for a simple // uncomment the below main function along with the headers above for a simple
// standalone test of table and entry creation // standalone test of table and entry creation