@ -171,6 +171,7 @@ definition:
|
|||||||
setAsKeyword(node, true);
|
setAsKeyword(node, true);
|
||||||
}
|
}
|
||||||
cur = CreateScope(cur, 0, 0);
|
cur = CreateScope(cur, 0, 0);
|
||||||
|
setFunScope(node, cur);
|
||||||
printdebug("Created a new scope");
|
printdebug("Created a new scope");
|
||||||
} L_PAREN {
|
} L_PAREN {
|
||||||
TableNode * parameter = getParameter(getTypeEntry(table_lookup(getAncestor(cur), $1)));
|
TableNode * parameter = getParameter(getTypeEntry(table_lookup(getAncestor(cur), $1)));
|
||||||
@ -290,11 +291,11 @@ function_declaration:
|
|||||||
if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){
|
if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){
|
||||||
//printf("%s\n",$2);
|
//printf("%s\n",$2);
|
||||||
//printf("%s\n",getName(table_lookup(cur, $4)));
|
//printf("%s\n",getName(table_lookup(cur, $4)));
|
||||||
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false));
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2);
|
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2);
|
||||||
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false));
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,11 +303,11 @@ function_declaration:
|
|||||||
| EXTERNAL FUNCTION ID COLON ID
|
| EXTERNAL FUNCTION ID COLON ID
|
||||||
{
|
{
|
||||||
if(getAdInfoType(look_up(cur, $5))==TYPE_FUNCTION_TYPE){
|
if(getAdInfoType(look_up(cur, $5))==TYPE_FUNCTION_TYPE){
|
||||||
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false));
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false,NULL));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $3);
|
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $3);
|
||||||
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false));
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false,NULL));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,7 +468,7 @@ declaration:
|
|||||||
printdebug("invalid (function) type passed in declaration list in dblock", @2.first_line, @2.first_column);
|
printdebug("invalid (function) type passed in declaration list in dblock", @2.first_line, @2.first_column);
|
||||||
d = TYPE_FUNCTION_DECLARATION;
|
d = TYPE_FUNCTION_DECLARATION;
|
||||||
|
|
||||||
if(CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)) == undefined){
|
if(CreateEntry(cur,d,(TableNode*)$1,$3,NULL) == undefined){
|
||||||
throw_error(ERROR_TYPE, "Duplicate defination of function in declaration list");
|
throw_error(ERROR_TYPE, "Duplicate defination of function in declaration list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,12 +456,13 @@ int getRecSize(SymbolTable *tn) {
|
|||||||
// using "as" the input record can be decomposed to give the illusion of
|
// using "as" the input record can be decomposed to give the illusion of
|
||||||
// multiple inputs Below function also has the line number where the function is
|
// multiple inputs Below function also has the line number where the function is
|
||||||
// first defined
|
// first defined
|
||||||
AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular) {
|
AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular, SymbolTable *scope) {
|
||||||
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
AdInfo *info = (AdInfo *)calloc(1,sizeof(AdInfo));
|
||||||
info->FunDecAdInfo = (function_declaration_info *)malloc(
|
info->FunDecAdInfo = (function_declaration_info *)malloc(
|
||||||
sizeof(function_declaration_info));
|
sizeof(function_declaration_info));
|
||||||
info->FunDecAdInfo->startlinenumber = line;
|
info->FunDecAdInfo->startlinenumber = line;
|
||||||
info->FunDecAdInfo->regularoras = asorregular;
|
info->FunDecAdInfo->regularoras = asorregular;
|
||||||
|
info->FunDecAdInfo->scope = scope;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
// gets the line at which the function was first defined. (Can be used to print
|
// gets the line at which the function was first defined. (Can be used to print
|
||||||
@ -530,6 +531,68 @@ bool getAsKeyword(TableNode *definition) {
|
|||||||
return definition->additionalinfo->FunDecAdInfo->regularoras;
|
return definition->additionalinfo->FunDecAdInfo->regularoras;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SymbolTable *getFunScope(TableNode *definition) {
|
||||||
|
if (definition == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"passed a NULL entry to getScope "
|
||||||
|
"function. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (getAdInfoType(definition) != TYPE_FUNCTION_DECLARATION) {
|
||||||
|
printdebug(
|
||||||
|
"passed in invalid entry type to getScope "
|
||||||
|
"function. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (definition->additionalinfo == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"node has NULL additionalinfo. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if(definition->additionalinfo->FunDecAdInfo == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"node has NULL additionalinfo. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if(definition->additionalinfo->FunDecAdInfo->scope == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"node has no scope initialized.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return definition->additionalinfo->FunDecAdInfo->scope;
|
||||||
|
}
|
||||||
|
TableNode *setFunScope(TableNode *tn, SymbolTable *scope) {
|
||||||
|
if (tn == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"passing in a NULL entry to setFunScope. "
|
||||||
|
"invalid");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (getAdInfoType(tn) != TYPE_FUNCTION_DECLARATION) {
|
||||||
|
printdebug(
|
||||||
|
"passing in an invalid entry to setFunScope. "
|
||||||
|
"invalid");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if(tn->additionalinfo == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"node has NULL additionalinfo. Invalid.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if(tn->additionalinfo->FunDecAdInfo == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"node has NULL additionalinfo. Invalid.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if(scope == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"passed in an empty scope.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
tn->additionalinfo->FunDecAdInfo->scope = scope;
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
TableNode *setAsKeyword(TableNode *tn, bool as) {
|
TableNode *setAsKeyword(TableNode *tn, bool as) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug(
|
printdebug(
|
||||||
@ -787,10 +850,10 @@ SymbolTable *init(SymbolTable *start) {
|
|||||||
chara->additionalinfo = CreatePrimitiveInfo(SIZE_CHAR);
|
chara->additionalinfo = CreatePrimitiveInfo(SIZE_CHAR);
|
||||||
stri->additionalinfo = CreateArrayInfo(1, chara);
|
stri->additionalinfo = CreateArrayInfo(1, chara);
|
||||||
boo->additionalinfo = CreatePrimitiveInfo(SIZE_BOOL);
|
boo->additionalinfo = CreatePrimitiveInfo(SIZE_BOOL);
|
||||||
reserve->additionalinfo = CreateFunctionDeclarationInfo(0, false);
|
reserve->additionalinfo = CreateFunctionDeclarationInfo(0, false,NULL);
|
||||||
reservetype->additionalinfo = CreateFunctionTypeInfo(integ, addr);
|
reservetype->additionalinfo = CreateFunctionTypeInfo(integ, addr);
|
||||||
releasetype->additionalinfo = CreateFunctionTypeInfo(addr, integ);
|
releasetype->additionalinfo = CreateFunctionTypeInfo(addr, integ);
|
||||||
release->additionalinfo = CreateFunctionDeclarationInfo(0, false);
|
release->additionalinfo = CreateFunctionDeclarationInfo(0, false,NULL);
|
||||||
|
|
||||||
integ->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for integ
|
integ->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for integ
|
||||||
addr->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for addr
|
addr->tag = TYPE_PRIMITIVE_TYPE; // explicitly set the type for addr
|
||||||
@ -1308,10 +1371,16 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
|||||||
if (getAdInfoType(entry) == TYPE_FUNCTION_DECLARATION) {
|
if (getAdInfoType(entry) == TYPE_FUNCTION_DECLARATION) {
|
||||||
char *functiontype = (char *)malloc(100);
|
char *functiontype = (char *)malloc(100);
|
||||||
sprintf(functiontype, " %s", getName(getTypeEntry(entry)));
|
sprintf(functiontype, " %s", getName(getTypeEntry(entry)));
|
||||||
if (parentScopeNum == 0) {
|
char* functionScope = (char *)malloc(100);
|
||||||
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, functiontype, " Function Definition");
|
if(getLine(getFunScope(entry)) < 1){
|
||||||
|
sprintf(functionScope, " Function not defined before runtime");
|
||||||
}else{
|
}else{
|
||||||
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, functiontype, " Function Definition");
|
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);
|
||||||
|
} else {
|
||||||
|
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, functiontype, functionScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ extern FILE *ir_flag;
|
|||||||
struct TableNode;
|
struct TableNode;
|
||||||
typedef struct TFList TFList;
|
typedef struct TFList TFList;
|
||||||
typedef struct CGNode CGNode;
|
typedef struct CGNode CGNode;
|
||||||
|
typedef struct SymbolTable SymbolTable;
|
||||||
|
|
||||||
typedef struct Constant_Stack {
|
typedef struct Constant_Stack {
|
||||||
struct TableNode *theType;
|
struct TableNode *theType;
|
||||||
@ -47,6 +48,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int startlinenumber;
|
int startlinenumber;
|
||||||
bool regularoras;
|
bool regularoras;
|
||||||
|
SymbolTable* scope;
|
||||||
} function_declaration_info;
|
} function_declaration_info;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -120,7 +122,9 @@ int getRecLength(TableNode *definition);
|
|||||||
SymbolTable *getRecList(TableNode *definition);
|
SymbolTable *getRecList(TableNode *definition);
|
||||||
TableNode *setRecSize(TableNode *tn, int n);
|
TableNode *setRecSize(TableNode *tn, int n);
|
||||||
int getRecSize(SymbolTable *tn);
|
int getRecSize(SymbolTable *tn);
|
||||||
AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular);
|
AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular,SymbolTable *scope);
|
||||||
|
TableNode *setFunScope(TableNode *tn, SymbolTable *scope);
|
||||||
|
SymbolTable *getFunScope(TableNode *definition);
|
||||||
int getStartLine(TableNode *definition);
|
int getStartLine(TableNode *definition);
|
||||||
TableNode *setStartLine(TableNode *tn, int start);
|
TableNode *setStartLine(TableNode *tn, int start);
|
||||||
bool getAsKeyword(TableNode *definition);
|
bool getAsKeyword(TableNode *definition);
|
||||||
|
Reference in New Issue
Block a user