🤯🤯🤯🤯🤯🤯🤯🤯🤯
This commit is contained in:
@ -116,15 +116,15 @@ int getPrimSize(TableNode *definition) {
|
||||
"Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if(getAdInfoType(definition) == TYPE_ARRAY_TYPE){
|
||||
if (getAdInfoType(definition) == TYPE_ARRAY_TYPE) {
|
||||
//special case to return size for reference to an array
|
||||
return 8;
|
||||
}
|
||||
if(getAdInfoType(definition) == TYPE_FUNCTION_TYPE){
|
||||
if (getAdInfoType(definition) == TYPE_FUNCTION_TYPE) {
|
||||
//special case to return size for reference to a function
|
||||
return 8;
|
||||
}
|
||||
if(getAdInfoType(definition) == TYPE_RECORD_TYPE){
|
||||
if (getAdInfoType(definition) == TYPE_RECORD_TYPE) {
|
||||
//special case to return size for reference to a record
|
||||
return getRecTotal(definition);
|
||||
}
|
||||
@ -469,7 +469,7 @@ int getRecSize(SymbolTable *tn) {
|
||||
// multiple inputs Below function also has the line number where the function is
|
||||
// first defined
|
||||
AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular, SymbolTable *scope) {
|
||||
AdInfo *info = (AdInfo *)calloc(1,sizeof(AdInfo));
|
||||
AdInfo *info = (AdInfo *)calloc(1, sizeof(AdInfo));
|
||||
info->FunDecAdInfo = (function_declaration_info *)malloc(
|
||||
sizeof(function_declaration_info));
|
||||
info->FunDecAdInfo->startlinenumber = line;
|
||||
@ -561,12 +561,12 @@ SymbolTable *getFunScope(TableNode *definition) {
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if(definition->additionalinfo->FunDecAdInfo == NULL) {
|
||||
if (definition->additionalinfo->FunDecAdInfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if(definition->additionalinfo->FunDecAdInfo->scope == NULL) {
|
||||
if (definition->additionalinfo->FunDecAdInfo->scope == NULL) {
|
||||
printdebug(
|
||||
"node has no scope initialized.");
|
||||
return NULL;
|
||||
@ -587,17 +587,17 @@ TableNode *setFunScope(TableNode *tn, SymbolTable *scope) {
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
if(tn->additionalinfo == NULL) {
|
||||
if (tn->additionalinfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if(tn->additionalinfo->FunDecAdInfo == NULL) {
|
||||
if (tn->additionalinfo->FunDecAdInfo == NULL) {
|
||||
printdebug(
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if(scope == NULL) {
|
||||
if (scope == NULL) {
|
||||
printdebug(
|
||||
"passed in an empty scope.");
|
||||
return undefined;
|
||||
@ -705,7 +705,7 @@ TableNode *getReturn(TableNode *definition) {
|
||||
"node has NULL additionalinfo. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
printdebug("function:%s with return type %s\n",getName(definition),getName(definition->additionalinfo->FunTypeAdInfo->returntype));
|
||||
printdebug("function:%s with return type %s\n", getName(definition), getName(definition->additionalinfo->FunTypeAdInfo->returntype));
|
||||
return definition->additionalinfo->FunTypeAdInfo->returntype;
|
||||
}
|
||||
|
||||
@ -862,10 +862,10 @@ SymbolTable *init(SymbolTable *start) {
|
||||
chara->additionalinfo = CreatePrimitiveInfo(SIZE_CHAR);
|
||||
stri->additionalinfo = CreateArrayInfo(1, chara);
|
||||
boo->additionalinfo = CreatePrimitiveInfo(SIZE_BOOL);
|
||||
reserve->additionalinfo = CreateFunctionDeclarationInfo(0, false,NULL);
|
||||
reserve->additionalinfo = CreateFunctionDeclarationInfo(0, false, NULL);
|
||||
reservetype->additionalinfo = CreateFunctionTypeInfo(integ, addr);
|
||||
releasetype->additionalinfo = CreateFunctionTypeInfo(addr, integ);
|
||||
release->additionalinfo = CreateFunctionDeclarationInfo(0, false,NULL);
|
||||
release->additionalinfo = CreateFunctionDeclarationInfo(0, false, NULL);
|
||||
|
||||
integ->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for integ
|
||||
addr->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for addr
|
||||
@ -1031,7 +1031,7 @@ TableNode *CreateEntry(SymbolTable *table, int tag, TableNode *typeOf, char *id,
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
if((id != NULL) && table_lookup(cur,id)!=undefined){
|
||||
if ((id != NULL) && table_lookup(cur, id) != undefined) {
|
||||
printdebug("This name is already defined in the current scope");
|
||||
//throw_error(ERROR_TYPE, "Already defined.");
|
||||
return undefined;
|
||||
@ -1062,7 +1062,7 @@ TableNode *CreateEntry(SymbolTable *table, int tag, TableNode *typeOf, char *id,
|
||||
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
||||
return newEntry;
|
||||
} else {
|
||||
TableNode*oldEntry = table->entries;
|
||||
TableNode *oldEntry = table->entries;
|
||||
while (oldEntry->next != NULL) {
|
||||
oldEntry = oldEntry->next;
|
||||
}
|
||||
@ -1309,7 +1309,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
}
|
||||
|
||||
for (; entry != NULL; entry = getNextEntry(entry)) {
|
||||
if((getName(entry)[0] == '$' || getName(entry)[0] == '&') && ir_flag == NULL){
|
||||
if ((getName(entry)[0] == '$' || getName(entry)[0] == '&') && ir_flag == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (getAdInfoType(entry) == TYPE_ARRAY_TYPE) {
|
||||
@ -1391,11 +1391,11 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
if (getAdInfoType(entry) == TYPE_FUNCTION_DECLARATION) {
|
||||
char *functiontype = (char *)malloc(100);
|
||||
sprintf(functiontype, " %s", getName(getTypeEntry(entry)));
|
||||
char* functionScope = (char *)malloc(100);
|
||||
if(getLine(getFunScope(entry)) < 1){
|
||||
char *functionScope = (char *)malloc(100);
|
||||
if (getLine(getFunScope(entry)) < 1) {
|
||||
sprintf(functionScope, " Function not defined before runtime");
|
||||
}else{
|
||||
sprintf(functionScope, " Function Definition that starts at line %d",getLine(getFunScope(entry)));
|
||||
} else {
|
||||
sprintf(functionScope, " Function Definition that starts at line %d", getLine(getFunScope(entry)));
|
||||
}
|
||||
if (parentScopeNum == 0) {
|
||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, functiontype, functionScope);
|
||||
@ -1545,7 +1545,13 @@ SymbolTable *getParent(SymbolTable *st) {
|
||||
ListOfTable *getChildren(SymbolTable *st) { return st->Children_Scope; }
|
||||
SymbolTable *getFirstChild(ListOfTable *lt) { return lt->table; }
|
||||
ListOfTable *getRestOfChildren(ListOfTable *lt) { return lt->next; }
|
||||
TableNode *getFirstEntry(SymbolTable *st) { return st->entries; }
|
||||
TableNode *getFirstEntry(SymbolTable *st) {
|
||||
if (st == NULL || st->entries == NULL) {
|
||||
printdebug("passed a NULL symbol table to getFirstEntry");
|
||||
return undefined;
|
||||
}
|
||||
return st->entries;
|
||||
}
|
||||
|
||||
// Segfaults when passed an invalid table node!
|
||||
TableNode *getNextEntry(TableNode *tn) {
|
||||
|
Reference in New Issue
Block a user