updated print symbol table to use getters
This commit is contained in:
@ -105,13 +105,13 @@ TableNode *getArrType(TableNode *definition) {
|
||||
printdebug(
|
||||
"passed an NULL entry to getArrType "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
return undefined;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug(
|
||||
"passed an undefined entry to getArrType "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
return undefined;
|
||||
}
|
||||
if (strcmp(getType(definition), "array") != 0) {
|
||||
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)) {
|
||||
if (getAdInfoType(entry) == TYPE_ARRAY_TYPE) {
|
||||
char *arrayType = (char *)malloc(100);
|
||||
sprintf(arrayType, " %d -> %s", entry->additionalinfo->ArrayAdInfo->numofdimensions,
|
||||
entry->additionalinfo->ArrayAdInfo->typeofarray->theName);
|
||||
sprintf(arrayType, " %d -> %s", getNumArrDim(entry),
|
||||
getName(getArrType(entry)));
|
||||
|
||||
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 {
|
||||
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) {
|
||||
char *recordAdInfo = (char *)malloc(100);
|
||||
sprintf(recordAdInfo, " elements-%d", entry->additionalinfo->RecAdInfo->numofelements);
|
||||
sprintf(recordAdInfo, " elements-%d", getRecLength(entry));
|
||||
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 {
|
||||
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) {
|
||||
char *recordAdInfo = (char *)malloc(100);
|
||||
sprintf(recordAdInfo, " elements-%d", entry->additionalinfo->RecAdInfo->numofelements);
|
||||
sprintf(recordAdInfo, " elements-%d", getRecLength(entry));
|
||||
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 {
|
||||
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) {
|
||||
char *primAdInfo = (char *)malloc(100);
|
||||
sprintf(primAdInfo, " size-%d bytes", entry->additionalinfo->PrimAdInfo->size);
|
||||
sprintf(primAdInfo, " size-%d bytes", getPrimSize(entry));
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, entry->theName, currentScopeNum, -100, " Primitive", primAdInfo);
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " Primitive", primAdInfo);
|
||||
} else {
|
||||
printdebug("%sTHIS ONE", COLOR_RED);
|
||||
printTableNode(entry);
|
||||
char *primType = (char *)malloc(sizeof(getType(entry) + 1));
|
||||
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) {
|
||||
char *functiontype = (char *)malloc(100);
|
||||
sprintf(functiontype, " %s -> %s", entry->additionalinfo->FunTypeAdInfo->parameter->theName,
|
||||
entry->additionalinfo->FunTypeAdInfo->returntype->theName);
|
||||
sprintf(functiontype, " %s -> %s", getName(getParameter(entry)),
|
||||
getName(getReturn(entry)));
|
||||
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 {
|
||||
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 (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 {
|
||||
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 (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 {
|
||||
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) {
|
||||
ListOfTable *node = getChildren(table);
|
||||
for (; node != NULL; node = node->next) {
|
||||
if ((node->table) == NULL) {
|
||||
print_symbol_table(node->table, file_ptr);
|
||||
for (; node != NULL; node = getRestOfChildren(node)) {
|
||||
if ((getFirstChild(node)) == NULL) {
|
||||
print_symbol_table(getFirstChild(node), file_ptr);
|
||||
} else {
|
||||
if ((node->table)->Line_Number == -1) {
|
||||
if (getLine(getFirstChild(node)) == -1) {
|
||||
continue;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user