updated print symbol table to use getters

This commit is contained in:
Partho
2025-04-11 12:50:24 -04:00
parent d7d7d22c72
commit df8c9fb661

View File

@ -105,13 +105,13 @@ TableNode *getArrType(TableNode *definition) {
printdebug( printdebug(
"passed an NULL entry to getArrType " "passed an NULL entry to getArrType "
"function. Invalid."); "function. Invalid.");
return NULL; return undefined;
} }
if (definition == undefined) { if (definition == undefined) {
printdebug( printdebug(
"passed an undefined entry to getArrType " "passed an undefined entry to getArrType "
"function. Invalid."); "function. Invalid.");
return NULL; return undefined;
} }
if (strcmp(getType(definition), "array") != 0) { if (strcmp(getType(definition), "array") != 0) {
printdebug("not checking the type of an array -- invalid op"); printdebug("not checking the type of an array -- invalid op");
@ -1103,93 +1103,93 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
for (; entry != NULL; entry = getNextEntry(entry)) { for (; entry != NULL; entry = getNextEntry(entry)) {
if (getAdInfoType(entry) == TYPE_ARRAY_TYPE) { if (getAdInfoType(entry) == TYPE_ARRAY_TYPE) {
char *arrayType = (char *)malloc(100); char *arrayType = (char *)malloc(100);
sprintf(arrayType, " %d -> %s", entry->additionalinfo->ArrayAdInfo->numofdimensions, sprintf(arrayType, " %d -> %s", getNumArrDim(entry),
entry->additionalinfo->ArrayAdInfo->typeofarray->theName); getName(getArrType(entry)));
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, arrayType, " Type of Array"); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, arrayType, " Type of Array");
} else { } else {
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, arrayType, " Type of Array"); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, arrayType, " Type of Array");
} }
} }
if (getAdInfoType(entry) == TYPE_RECORD_TYPE) { if (getAdInfoType(entry) == TYPE_RECORD_TYPE) {
char *recordAdInfo = (char *)malloc(100); char *recordAdInfo = (char *)malloc(100);
sprintf(recordAdInfo, " elements-%d", entry->additionalinfo->RecAdInfo->numofelements); sprintf(recordAdInfo, " elements-%d", getRecLength(entry));
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, "record type", recordAdInfo); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, "record type", recordAdInfo);
} else { } else {
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, "record type", recordAdInfo); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, "record type", recordAdInfo);
} }
} }
if (getAdInfoType(entry) == TYPE_RECORD) { if (getAdInfoType(entry) == TYPE_RECORD) {
char *recordAdInfo = (char *)malloc(100); char *recordAdInfo = (char *)malloc(100);
sprintf(recordAdInfo, " elements-%d", entry->additionalinfo->RecAdInfo->numofelements); sprintf(recordAdInfo, " elements-%d", getRecLength(entry));
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, "record instance", recordAdInfo); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, "record instance", recordAdInfo);
} else { } else {
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, "record instance", recordAdInfo); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, "record instance", recordAdInfo);
} }
} }
if (getAdInfoType(entry) == TYPE_PRIMITIVE) { if (getAdInfoType(entry) == TYPE_PRIMITIVE) {
char *primAdInfo = (char *)malloc(100); char *primAdInfo = (char *)malloc(100);
sprintf(primAdInfo, " size-%d bytes", entry->additionalinfo->PrimAdInfo->size); sprintf(primAdInfo, " size-%d bytes", getPrimSize(entry));
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, " Primitive", primAdInfo); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " Primitive", primAdInfo);
} else { } else {
printdebug("%sTHIS ONE", COLOR_RED); printdebug("%sTHIS ONE", COLOR_RED);
printTableNode(entry); printTableNode(entry);
char *primType = (char *)malloc(sizeof(getType(entry) + 1)); char *primType = (char *)malloc(sizeof(getType(entry) + 1));
sprintf(primType, " %s", getType(entry)); sprintf(primType, " %s", getType(entry));
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, primType, primAdInfo); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, primType, primAdInfo);
} }
} }
if (getAdInfoType(entry) == TYPE_FUNCTION_TYPE) { if (getAdInfoType(entry) == TYPE_FUNCTION_TYPE) {
char *functiontype = (char *)malloc(100); char *functiontype = (char *)malloc(100);
sprintf(functiontype, " %s -> %s", entry->additionalinfo->FunTypeAdInfo->parameter->theName, sprintf(functiontype, " %s -> %s", getName(getParameter(entry)),
entry->additionalinfo->FunTypeAdInfo->returntype->theName); getName(getReturn(entry)));
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, functiontype, " Type of Function"); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, functiontype, " Type of Function");
} else { } else {
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, functiontype, " Type of Function"); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, functiontype, " Type of Function");
} }
} }
if (getAdInfoType(entry) == TYPE_FUNCTION_DECLARATION) { if (getAdInfoType(entry) == TYPE_FUNCTION_DECLARATION) {
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, " Function", " Function Declaration"); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " Function", " Function Declaration");
} else { } else {
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, " Function", " Function Declaration"); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, " Function", " Function Declaration");
} }
} }
if (getAdInfoType(entry) == TYPE_UNDEFINED) { if (getAdInfoType(entry) == TYPE_UNDEFINED) {
if (parentScopeNum == 0) { if (parentScopeNum == 0) {
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, " undefined", "undefined entry"); st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " undefined", "undefined entry");
} else { } else {
st_fprint(file_ptr, entry->theName, currentScopeNum, parentScopeNum, " undefined", "undefined entry"); st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, " undefined", "undefined entry");
} }
} }
} }
if (getChildren(table) != NULL) { if (getChildren(table) != NULL) {
ListOfTable *node = getChildren(table); ListOfTable *node = getChildren(table);
for (; node != NULL; node = node->next) { for (; node != NULL; node = getRestOfChildren(node)) {
if ((node->table) == NULL) { if ((getFirstChild(node)) == NULL) {
print_symbol_table(node->table, file_ptr); print_symbol_table(getFirstChild(node), file_ptr);
} else { } else {
if ((node->table)->Line_Number == -1) { if (getLine(getFirstChild(node)) == -1) {
continue; continue;
} else { } else {
print_symbol_table(node->table, file_ptr); print_symbol_table(getFirstChild(node), file_ptr);
} }
} }
} }
} }
if (table->Parent_Scope == NULL) { if (getParent(table) == NULL) {
printline(file_ptr); printline(file_ptr);
} }
} }