Fixed -tok, spacings in -st, and validation tests
This commit is contained in:
@ -92,9 +92,9 @@ int getNumArrDim(TableNode *definition) {
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if(getAdInfoType(definition) != TYPE_ARRAY_TYPE){
|
||||
if (getAdInfoType(definition) != TYPE_ARRAY_TYPE) {
|
||||
printdebug(
|
||||
"passed an invalid node to getNumArrDim. Seeing tag %d in getNumArrDim. Invalid.",getAdInfoType(definition));
|
||||
"passed an invalid node to getNumArrDim. Seeing tag %d in getNumArrDim. Invalid.", getAdInfoType(definition));
|
||||
return -1;
|
||||
}
|
||||
return definition->additionalinfo->ArrayAdInfo->numofdimensions;
|
||||
@ -114,9 +114,9 @@ TableNode *getArrType(TableNode *definition) {
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if(getAdInfoType(definition) != TYPE_ARRAY_TYPE){
|
||||
if (getAdInfoType(definition) != TYPE_ARRAY_TYPE) {
|
||||
printdebug(
|
||||
"passed an invalid node to getArrType. Seeing tag %d. Invalid.",getAdInfoType(definition));
|
||||
"passed an invalid node to getArrType. Seeing tag %d. Invalid.", getAdInfoType(definition));
|
||||
return undefined;
|
||||
}
|
||||
return definition->additionalinfo->ArrayAdInfo->typeofarray;
|
||||
@ -138,25 +138,25 @@ AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) {
|
||||
// Perhaps this may not be needed since we need to iterate over all elements
|
||||
// anyways.
|
||||
|
||||
int getRecTotal(TableNode* node){
|
||||
if(node == NULL){
|
||||
int getRecTotal(TableNode *node) {
|
||||
if (node == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL node to getRecTotal. Invalid.");
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
if(getAdInfoType(node) != TYPE_RECORD_TYPE){
|
||||
if (getAdInfoType(node) != TYPE_RECORD_TYPE) {
|
||||
printdebug(
|
||||
"passed an invalid node to getRecTotal. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if(node->additionalinfo == NULL){
|
||||
if (node->additionalinfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
return node->additionalinfo->RecAdInfo->total_size;
|
||||
}
|
||||
TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
TableNode *setRecOffsetInfo(SymbolTable *scope, TableNode *node) {
|
||||
if (node == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL node to setRecOffsetInfo. Invalid.");
|
||||
@ -167,51 +167,47 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
"passed an NULL scope to setRecOffsetInfo. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if(getFirstEntry(scope) == NULL){
|
||||
if (getFirstEntry(scope) == NULL) {
|
||||
printdebug(
|
||||
"passed an empty scope to setRecOffsetInfo. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
TableNode* this = getFirstEntry(scope);
|
||||
TableNode *this = getFirstEntry(scope);
|
||||
int largest = 0;
|
||||
int k = getRecLength(node);
|
||||
int total_size = 0;
|
||||
int counter = 0;
|
||||
int *offsets = (int *)calloc(2 * k, sizeof(int));
|
||||
if(getAdInfoType(this) == TYPE_FUNCTION_DECLARATION){
|
||||
if (getAdInfoType(this) == TYPE_FUNCTION_DECLARATION) {
|
||||
offsets[counter] = 8;
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = 8;
|
||||
counter++;
|
||||
}
|
||||
else if((getAdInfoType(this) == TYPE_RECORD)){
|
||||
} else if ((getAdInfoType(this) == TYPE_RECORD)) {
|
||||
offsets[counter] = 8;
|
||||
printf("hitting record and adding to largest");
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = offsets[counter];
|
||||
counter++;
|
||||
}
|
||||
else if(getAdInfoType(this)==TYPE_PRIMITIVE){
|
||||
} else if (getAdInfoType(this) == TYPE_PRIMITIVE) {
|
||||
offsets[counter] = getPrimSize(getTypeEntry(this));
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = offsets[counter];
|
||||
counter++;
|
||||
}
|
||||
else if(getAdInfoType(this)==TYPE_ARRAY){
|
||||
} else if (getAdInfoType(this) == TYPE_ARRAY) {
|
||||
offsets[counter] = 8;
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = offsets[counter];
|
||||
counter++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printdebug(
|
||||
"[TYPE CHECK] passed an invalid (first) parameter to a function definition. seeing %d. Type of entry is %s. Name attempted to pass is %s.",getAdInfoType(this),getType(this),getName(this));
|
||||
"[TYPE CHECK] passed an invalid (first) parameter to a function definition. seeing %d. Type of entry is %s. Name attempted to pass is %s.", getAdInfoType(this), getType(this), getName(this));
|
||||
|
||||
return undefined;
|
||||
}
|
||||
this = getNextEntry(this);
|
||||
while(this != NULL){
|
||||
if(getAdInfoType(this) == TYPE_FUNCTION_DECLARATION){
|
||||
while (this != NULL) {
|
||||
if (getAdInfoType(this) == TYPE_FUNCTION_DECLARATION) {
|
||||
int s = 8;
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
@ -225,8 +221,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
total_size = total_size + offsets[counter];
|
||||
counter++;
|
||||
this = getNextEntry(this);
|
||||
}
|
||||
else if(getAdInfoType(this) == TYPE_ARRAY){
|
||||
} else if (getAdInfoType(this) == TYPE_ARRAY) {
|
||||
int s = 8;
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
@ -240,8 +235,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
total_size = total_size + offsets[counter];
|
||||
counter++;
|
||||
this = getNextEntry(this);
|
||||
}
|
||||
else if((getAdInfoType(this) == TYPE_RECORD)){
|
||||
} else if ((getAdInfoType(this) == TYPE_RECORD)) {
|
||||
int s = 8;
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
@ -257,8 +251,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
total_size = total_size + offsets[counter];
|
||||
counter++;
|
||||
this = getNextEntry(this);
|
||||
}
|
||||
else if(getAdInfoType(this) == TYPE_PRIMITIVE){
|
||||
} else if (getAdInfoType(this) == TYPE_PRIMITIVE) {
|
||||
int s = getPrimSize(getTypeEntry(this));
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
@ -272,9 +265,9 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
total_size = total_size + offsets[counter];
|
||||
counter++;
|
||||
this = getNextEntry(this);
|
||||
}else{
|
||||
} else {
|
||||
printdebug(
|
||||
"[TYPE CHECK] passed an invalid parameter at position %d in record.",((counter+1)/2));
|
||||
"[TYPE CHECK] passed an invalid parameter at position %d in record.", ((counter + 1) / 2));
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@ -286,18 +279,18 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
int* getRecOffsets(TableNode* node){
|
||||
if(node == NULL){
|
||||
int *getRecOffsets(TableNode *node) {
|
||||
if (node == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL node to getRecTotal. Invalid.");
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
if(getAdInfoType(node) != TYPE_RECORD_TYPE){
|
||||
if (getAdInfoType(node) != TYPE_RECORD_TYPE) {
|
||||
printdebug(
|
||||
"passed an invalid node to getRecTotal. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if(node->additionalinfo == NULL){
|
||||
if (node->additionalinfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return NULL;
|
||||
@ -341,7 +334,8 @@ SymbolTable *getRecList(TableNode *definition) {
|
||||
if (strcmp(getType(definition), "record") != 0) {
|
||||
printdebug(
|
||||
"not checking the list of types of a record -- invalid "
|
||||
"op of type %s", getType(definition));
|
||||
"op of type %s",
|
||||
getType(definition));
|
||||
return NULL;
|
||||
}
|
||||
return definition->additionalinfo->RecAdInfo->recordScope;
|
||||
@ -521,7 +515,7 @@ TableNode *getParameter(TableNode *definition) {
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if(definition->additionalinfo == NULL){
|
||||
if (definition->additionalinfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return undefined;
|
||||
@ -552,7 +546,7 @@ TableNode *getReturn(TableNode *definition) {
|
||||
"not checking the return of a function -- invalid op");
|
||||
return undefined;
|
||||
}
|
||||
if(definition->additionalinfo == NULL){
|
||||
if (definition->additionalinfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return undefined;
|
||||
@ -605,10 +599,10 @@ SymbolTable *init(SymbolTable *start) {
|
||||
chara = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
stri = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
boo = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode* reservetype = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode* reserve = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode* releasetype = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode* release = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode *reservetype = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode *reserve = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode *releasetype = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
TableNode *release = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
// TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
start->entries = integ;
|
||||
integ->next = addr;
|
||||
@ -721,7 +715,7 @@ SymbolTable *init(SymbolTable *start) {
|
||||
integ->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for integ
|
||||
addr->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for addr
|
||||
chara->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for chara
|
||||
stri->tag = TYPE_ARRAY_TYPE; // explicitly set the type for stri
|
||||
stri->tag = TYPE_ARRAY_TYPE; // explicitly set the type for stri
|
||||
boo->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for boo
|
||||
reserve->tag = TYPE_FUNCTION_DECLARATION;
|
||||
reservetype->tag = TYPE_FUNCTION_TYPE;
|
||||
@ -1064,7 +1058,7 @@ TableNode *table_lookup(SymbolTable *table, char *x) {
|
||||
// check current table and all parents
|
||||
TableNode *look_up(SymbolTable *table, char *x) {
|
||||
if (table == NULL) {
|
||||
printdebug("Could not find %s in any scope using lookup",x);
|
||||
printdebug("Could not find %s in any scope using lookup", x);
|
||||
return undefined;
|
||||
}
|
||||
TableNode *ret = table_lookup(table, x);
|
||||
@ -1157,33 +1151,33 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
}
|
||||
}
|
||||
if (getAdInfoType(entry) == TYPE_ARRAY) {
|
||||
char *arrayType = (char *)malloc(100);
|
||||
//sprintf(arrayType, " %d -> %s", getNumArrDim(entry),
|
||||
// getName(getArrType(entry)));
|
||||
|
||||
char *arrayType = (char *)malloc(sizeof(getType(entry) + 1));
|
||||
sprintf(arrayType, " %s", getType(entry));
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, getType(entry), " Array Instance");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, arrayType, " Array Instance");
|
||||
} else {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, getType(entry), " Array Instance");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, arrayType, " Array Instance");
|
||||
}
|
||||
}
|
||||
if (getAdInfoType(entry) == TYPE_RECORD_TYPE) {
|
||||
char *recordAdInfo = (char *)malloc(100);
|
||||
sprintf(recordAdInfo, " elements-%d size-%d bytes", getRecLength(entry), getRecTotal(entry));
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " record type", recordAdInfo);
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " Record Type", recordAdInfo);
|
||||
} else {
|
||||
st_fprint(file_ptr, getName(entry), 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", getRecLength(entry));
|
||||
char *recordType = (char *)malloc(sizeof(getType(entry) + 1));
|
||||
sprintf(recordType, " %s", getType(entry));
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, getType(entry), "record instance");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, recordType, " Record Instance");
|
||||
} else {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, getType(entry), "record instance");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, recordType, " Record Instance");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1193,8 +1187,6 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " Primitive Type", 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, getName(entry), currentScopeNum, parentScopeNum, primType, primAdInfo);
|
||||
@ -1206,11 +1198,9 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
if (parentScopeNum == 0) {
|
||||
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, getName(entry), currentScopeNum, parentScopeNum, getType(entry), "Primitive Instance");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, primType, " Primitive Instance");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1226,10 +1216,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
}
|
||||
|
||||
if (getAdInfoType(entry) == TYPE_FUNCTION_DECLARATION) {
|
||||
char *functiontype = (char *)malloc(100);
|
||||
sprintf(functiontype, " %s", getName(getReturn(entry)));
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, getType(entry), " Function Definition");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, functiontype, " Function Definition");
|
||||
} else {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, getType(entry), " Function Definition");
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, functiontype, " Function Definition");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1393,7 +1385,7 @@ TableNode *getNextEntry(TableNode *tn) {
|
||||
// Uses pointers to the table node to print the info
|
||||
TableNode *printTableNode(TableNode *tn) {
|
||||
if (DEBUG == 0) {
|
||||
return tn;
|
||||
return tn;
|
||||
}
|
||||
|
||||
if (tn == NULL) {
|
||||
|
Reference in New Issue
Block a user