fixed the NULL checks for the incorrect ORs
This commit is contained in:
@ -124,7 +124,7 @@ definition:
|
||||
TYPE ID COLON {
|
||||
printdebug("Currently see a record definition for %s", $<words>2);
|
||||
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
||||
if (table_lookup(getAncestor(cur), $2) == NULL) {
|
||||
if (table_lookup(getAncestor(cur), $2) == undefined) {
|
||||
printdebug("rec not found ");
|
||||
}
|
||||
}dblock { setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur));
|
||||
|
@ -37,7 +37,7 @@ char *COLOR_LIGHTPURPLE = "\033[1;35m";
|
||||
char *COLOR_LIGHTCYAN = "\033[1;36m";
|
||||
char *COLOR_WHITE = "\033[1;37m";
|
||||
|
||||
bool DEBUG = true;
|
||||
bool DEBUG = false;
|
||||
|
||||
void printdebug_impl(char *file, int line, const char *format, ...);
|
||||
|
||||
@ -142,11 +142,16 @@ AdInfo *CreatePrimitiveInfo(int size) {
|
||||
|
||||
// only gets the size of a primitive type
|
||||
int getPrimSize(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
if (definition == NULL) {
|
||||
printdebug(
|
||||
"passed an NULL entry to getPrimSize function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug(
|
||||
"passed an undefined entry to getPrimSize function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (definition->additionalinfo == NULL) {
|
||||
printdebug("node has NULL additionalinfo. Invalid.");
|
||||
return -1;
|
||||
@ -172,8 +177,18 @@ int getPrimSize(TableNode *definition) {
|
||||
// type stored in the array per professor, the actual size of the array is
|
||||
// calculated at runtime so bounds checking only needs to be done then
|
||||
AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
|
||||
if (type == NULL || type == undefined) {
|
||||
printdebug("passed a NULL or undefined type reference to "
|
||||
if (type == NULL) {
|
||||
printdebug("passed a NULL reference to "
|
||||
"CreateArrayInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (type == undefined) {
|
||||
printdebug("passed an undefined reference to "
|
||||
"CreateArrayInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (type == undefined) {
|
||||
printdebug("passed a undefined type reference to "
|
||||
"CreateArrayInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
@ -187,8 +202,13 @@ AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
|
||||
}
|
||||
// This gets the number of dimensions from array info
|
||||
int getNumArrDim(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getNumArrDim "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed an NULL entry to getNumArrDim "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getNumArrDim "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
@ -201,8 +221,13 @@ int getNumArrDim(TableNode *definition) {
|
||||
// This gets the type stored in an array from arrtype. It returns a reference to
|
||||
// the entry of that type
|
||||
TableNode *getArrType(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getArrType "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed an NULL entry to getArrType "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getArrType "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
@ -229,8 +254,13 @@ AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) {
|
||||
// Perhaps this may not be needed since we need to iterate over all elements
|
||||
// anyways.
|
||||
int getRecLength(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getRecLength "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed an NULL entry to getRecLength "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getRecLength "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
@ -243,8 +273,13 @@ int getRecLength(TableNode *definition) {
|
||||
}
|
||||
// This gets the array. Needs to up be updated to get the scope instead
|
||||
SymbolTable *getRecList(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getRecList "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed a NULL entry to getRecList "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getRecList "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
@ -258,10 +293,14 @@ SymbolTable *getRecList(TableNode *definition) {
|
||||
}
|
||||
|
||||
TableNode *setRecSize(TableNode *tn, int n) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
if (tn == NULL) {
|
||||
printdebug("passed in NULL entry for setRecSize. Invalid");
|
||||
return undefined;
|
||||
}
|
||||
if (tn == undefined) {
|
||||
printdebug("passed in undefined entry for setRecSize. Invalid");
|
||||
return undefined;
|
||||
}
|
||||
tn->additionalinfo->RecAdInfo->numofelements = n;
|
||||
return tn;
|
||||
}
|
||||
@ -300,8 +339,13 @@ AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular) {
|
||||
// gets the line at which the function was first defined. (Can be used to print
|
||||
// out in table if needed)
|
||||
int getStartLine(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getStartLine "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed a NULL entry to getStartLine "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getStartLine "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
@ -315,9 +359,15 @@ int getStartLine(TableNode *definition) {
|
||||
}
|
||||
|
||||
TableNode *setStartLine(TableNode *tn, int start) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
if (tn == NULL) {
|
||||
printdebug(
|
||||
"passing in a NULL or undefined entry to setStartLine. "
|
||||
"passing in a NULL entry to setStartLine. "
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
if (tn == undefined) {
|
||||
printdebug(
|
||||
"passing in an undefined entry to setStartLine. "
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
@ -327,8 +377,13 @@ TableNode *setStartLine(TableNode *tn, int start) {
|
||||
// checks if "as" keyword was used for function definition. Either 0 or 1 for
|
||||
// not used or used.
|
||||
bool getAsKeyword(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getAsKeyword "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed a NULL entry to getAsKeyword "
|
||||
"function. Invalid.");
|
||||
return false;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getAsKeyword "
|
||||
"function. Invalid.");
|
||||
return false;
|
||||
}
|
||||
@ -342,9 +397,15 @@ bool getAsKeyword(TableNode *definition) {
|
||||
}
|
||||
|
||||
TableNode *setAsKeyword(TableNode *tn, bool as) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
if (tn == NULL) {
|
||||
printdebug(
|
||||
"passing in a NULL or undefined entry to setAsKeyword. "
|
||||
"passing in a NULL entry to setAsKeyword. "
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
if (tn == undefined) {
|
||||
printdebug(
|
||||
"passing in an undefined entry to setAsKeyword. "
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
@ -354,13 +415,23 @@ TableNode *setAsKeyword(TableNode *tn, bool as) {
|
||||
|
||||
// stores the type of a function (parameter type and return type)
|
||||
AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
|
||||
if (parameter == NULL || parameter == undefined) {
|
||||
printdebug("passed a NULL or undefined parameter to "
|
||||
if (parameter == NULL) {
|
||||
printdebug("passed a NULL parameter to "
|
||||
"CreateFunctionTypeInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (returntype == NULL || returntype == undefined) {
|
||||
printdebug("passed a NULL or undefined return type to "
|
||||
if (parameter == undefined) {
|
||||
printdebug("passed an undefined parameter to "
|
||||
"CreateFunctionTypeInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (returntype == NULL) {
|
||||
printdebug("passed a NULL return type to "
|
||||
"CreateFunctionTypeInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (returntype == undefined) {
|
||||
printdebug("passed an undefined return type to "
|
||||
"CreateFunctionTypeInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
@ -373,8 +444,13 @@ AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
|
||||
}
|
||||
// returns parameter type of a function
|
||||
TableNode *getParameter(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getParameter "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed a NULL entry to getParameter "
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getParameter "
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
@ -387,8 +463,13 @@ TableNode *getParameter(TableNode *definition) {
|
||||
}
|
||||
// returns return type of a function
|
||||
TableNode *getReturn(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printdebug("passed an NULL or undefined entry to getReturn "
|
||||
if (definition == NULL) {
|
||||
printdebug("passed a NULL entry to getReturn "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (definition == undefined) {
|
||||
printdebug("passed an undefined entry to getReturn "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
@ -548,13 +629,21 @@ TableNode* recprime;
|
||||
TableNode* funtypeprime;
|
||||
*/
|
||||
TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printdebug("passed in an invalid table node to modify (NULL or "
|
||||
"undefined).");
|
||||
if (tn == NULL) {
|
||||
printdebug("passed in an NULL table node to populateTypeAndInfo.");
|
||||
return undefined;
|
||||
}
|
||||
if (type == NULL || type == undefined) {
|
||||
printdebug("passed in a NULL or undefined type reference to "
|
||||
if (tn == undefined) {
|
||||
printdebug("passed in an undefined table node to populateTypeAndInfo");
|
||||
return undefined;
|
||||
}
|
||||
if (type == NULL) {
|
||||
printdebug("passed in a NULL type reference to "
|
||||
"populate a table node. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if (type == undefined) {
|
||||
printdebug("passed in an undefined type reference to "
|
||||
"populate a table node. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
@ -571,13 +660,22 @@ TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
||||
}
|
||||
|
||||
int getAdInfoType(TableNode *tn) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printdebug("passing in NULL or undefined table entry. Invalid");
|
||||
if (tn == NULL) {
|
||||
printdebug("passing in NULL table entry to getAdInfoType. Invalid");
|
||||
return -1;
|
||||
}
|
||||
if (tn->theType == NULL || tn->theType == undefined) {
|
||||
printdebug("Entry being passed in has a null or undefined "
|
||||
"reference for theType. Invalid.");
|
||||
if (tn == undefined) {
|
||||
printdebug("passing in undefined table entry to getAdInfoType. Invalid");
|
||||
return -1;
|
||||
}
|
||||
if (tn->theType == NULL) {
|
||||
printdebug("Entry being passed in has a null"
|
||||
"reference for theType to getAdInfoType. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (tn->theType == undefined) {
|
||||
printdebug("Entry being passed in an undefined "
|
||||
"reference for theType to getAdInfoType. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getName(tn), getName(integ)) == 0) {
|
||||
@ -626,10 +724,14 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
if (typeOf == NULL || typeOf == undefined) {
|
||||
if (typeOf == NULL) {
|
||||
printdebug(
|
||||
"This is not pointing to a proper definition (either "
|
||||
"NULL or undefined)");
|
||||
"Passing an NULL Type Node to Create Entry");
|
||||
return undefined;
|
||||
}
|
||||
if (typeOf == undefined) {
|
||||
printdebug(
|
||||
"Passing an undefined Type Node to Create Entry");
|
||||
return undefined;
|
||||
}
|
||||
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
@ -648,21 +750,32 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
||||
}
|
||||
|
||||
char *getType(TableNode *tn) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printdebug("passed a NULL or undefined table entry to getType");
|
||||
if (tn == NULL) {
|
||||
printdebug("passed a NULL table entry to getType");
|
||||
return getName(undefined);
|
||||
}
|
||||
if (tn->theType == NULL || tn->theType == undefined) {
|
||||
printdebug("type of entry is currently NULL or undefined type");
|
||||
if (tn == undefined) {
|
||||
printdebug("passed an undefined table entry to getType");
|
||||
return getName(undefined);
|
||||
}
|
||||
if (tn->theType == NULL) {
|
||||
printdebug("type of entry is currently NULL type");
|
||||
return getName(undefined);
|
||||
}
|
||||
if (tn->theType == undefined) {
|
||||
printdebug("type of entry is currently undefined type");
|
||||
return getName(undefined);
|
||||
}
|
||||
return tn->theType->theName;
|
||||
}
|
||||
|
||||
char *getName(TableNode *tn) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
// printdebug("passed a NULL or undefined table entry to
|
||||
// getName");
|
||||
if (tn == NULL) {
|
||||
printdebug("passed a NULL table entry to getName");
|
||||
return undefined->theName;
|
||||
}
|
||||
if (tn == undefined) {
|
||||
printdebug("passed an undefined table entry to getName");
|
||||
return undefined->theName;
|
||||
}
|
||||
if (tn->theName == NULL) {
|
||||
@ -689,9 +802,15 @@ int getColumn(SymbolTable *st) {
|
||||
return st->Column_Number;
|
||||
}
|
||||
TableNode *addName(TableNode *tn, char *str) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
if (tn == NULL) {
|
||||
printdebug(
|
||||
"passed a Null or undefined table node to the addName "
|
||||
"passed a Null table node to the addName "
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if (tn == undefined) {
|
||||
printdebug(
|
||||
"passed an undefined table node to the addName "
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
@ -1054,12 +1173,20 @@ bool typeCheck(char *firstID, char *secondID) {
|
||||
|
||||
TableNode *entry1 = look_up(cur, firstID);
|
||||
TableNode *entry2 = look_up(cur, secondID);
|
||||
if (entry1 == NULL || entry1 == undefined) {
|
||||
printdebug("first type not defined");
|
||||
if (entry1 == NULL) {
|
||||
printdebug("first type is NULL in type check. Invalid.");
|
||||
return false;
|
||||
}
|
||||
if (entry2 == NULL || entry2 == undefined) {
|
||||
printdebug("second type not defined");
|
||||
if (entry1 == undefined) {
|
||||
printdebug("first type is undefined in type check. Invalid.");
|
||||
return false;
|
||||
}
|
||||
if (entry2 == NULL) {
|
||||
printdebug("second type is NULL in type check. Invalid.");
|
||||
return false;
|
||||
}
|
||||
if (entry2 == undefined) {
|
||||
printdebug("second type is undefined in type check. Invalid.");
|
||||
return false;
|
||||
}
|
||||
if (table_lookup(getAncestor(cur), getType(look_up(cur, firstID))) ==
|
||||
|
Reference in New Issue
Block a user