small changes, segfault issue found
This commit is contained in:
@ -121,7 +121,7 @@ prototype:
|
|||||||
L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID;
|
L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID;
|
||||||
|
|
||||||
definition:
|
definition:
|
||||||
TYPE ID COLON {
|
TYPE ID COLON {
|
||||||
printdebug("Currently see a record definition for %s", $<words>2);
|
printdebug("Currently see a record definition for %s", $<words>2);
|
||||||
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
||||||
if (table_lookup(getAncestor(cur), $2) == undefined) {
|
if (table_lookup(getAncestor(cur), $2) == undefined) {
|
||||||
@ -238,7 +238,7 @@ declaration:
|
|||||||
;
|
;
|
||||||
|
|
||||||
id_or_types:
|
id_or_types:
|
||||||
ID {printdebug("string of id is %s in ID pattern of id_or_type rule."); $$ = $1;}
|
ID {printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); $$ = $1;}
|
||||||
//{printdebug("string of id is %s in ID pattern of id_or_type rule. Type passed up the tree is %s.",$1,getType(look_up(cur,$1))); $$ = getType(look_up(cur,$1));}
|
//{printdebug("string of id is %s in ID pattern of id_or_type rule. Type passed up the tree is %s.",$1,getType(look_up(cur,$1))); $$ = getType(look_up(cur,$1));}
|
||||||
| types {printdebug("string of type is %s in types pattern of id_or_type rule.",$1);} {$$ = $1;}
|
| types {printdebug("string of type is %s in types pattern of id_or_type rule.",$1);} {$$ = $1;}
|
||||||
//{printdebug("string of type is %s in types pattern of id_or_type rule. That is passed up the tree.",$<words>1);} {$$ = $<words>1;}
|
//{printdebug("string of type is %s in types pattern of id_or_type rule. That is passed up the tree.",$<words>1);} {$$ = $<words>1;}
|
||||||
|
@ -148,8 +148,8 @@ int getPrimSize(TableNode *definition) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (definition == undefined) {
|
if (definition == undefined) {
|
||||||
printdebug(
|
printdebug("passed an undefined entry to getPrimSize function. "
|
||||||
"passed an undefined entry to getPrimSize function. Invalid.");
|
"Invalid.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (definition->additionalinfo == NULL) {
|
if (definition->additionalinfo == NULL) {
|
||||||
@ -360,15 +360,13 @@ int getStartLine(TableNode *definition) {
|
|||||||
|
|
||||||
TableNode *setStartLine(TableNode *tn, int start) {
|
TableNode *setStartLine(TableNode *tn, int start) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug(
|
printdebug("passing in a NULL entry to setStartLine. "
|
||||||
"passing in a NULL entry to setStartLine. "
|
"invalid");
|
||||||
"invalid");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (tn == undefined) {
|
if (tn == undefined) {
|
||||||
printdebug(
|
printdebug("passing in an undefined entry to setStartLine. "
|
||||||
"passing in an undefined entry to setStartLine. "
|
"invalid");
|
||||||
"invalid");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
tn->additionalinfo->FunDecAdInfo->startlinenumber = start;
|
tn->additionalinfo->FunDecAdInfo->startlinenumber = start;
|
||||||
@ -398,15 +396,13 @@ bool getAsKeyword(TableNode *definition) {
|
|||||||
|
|
||||||
TableNode *setAsKeyword(TableNode *tn, bool as) {
|
TableNode *setAsKeyword(TableNode *tn, bool as) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug(
|
printdebug("passing in a NULL entry to setAsKeyword. "
|
||||||
"passing in a NULL entry to setAsKeyword. "
|
"invalid");
|
||||||
"invalid");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (tn == undefined) {
|
if (tn == undefined) {
|
||||||
printdebug(
|
printdebug("passing in an undefined entry to setAsKeyword. "
|
||||||
"passing in an undefined entry to setAsKeyword. "
|
"invalid");
|
||||||
"invalid");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
tn->additionalinfo->FunDecAdInfo->regularoras = as;
|
tn->additionalinfo->FunDecAdInfo->regularoras = as;
|
||||||
@ -630,11 +626,13 @@ TableNode* funtypeprime;
|
|||||||
*/
|
*/
|
||||||
TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug("passed in an NULL table node to populateTypeAndInfo.");
|
printdebug(
|
||||||
|
"passed in an NULL table node to populateTypeAndInfo.");
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (tn == undefined) {
|
if (tn == undefined) {
|
||||||
printdebug("passed in an undefined table node to populateTypeAndInfo");
|
printdebug(
|
||||||
|
"passed in an undefined table node to populateTypeAndInfo");
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (type == NULL) {
|
if (type == NULL) {
|
||||||
@ -661,11 +659,13 @@ TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
|||||||
|
|
||||||
int getAdInfoType(TableNode *tn) {
|
int getAdInfoType(TableNode *tn) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug("passing in NULL table entry to getAdInfoType. Invalid");
|
printdebug(
|
||||||
|
"passing in NULL table entry to getAdInfoType. Invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (tn == undefined) {
|
if (tn == undefined) {
|
||||||
printdebug("passing in undefined table entry to getAdInfoType. Invalid");
|
printdebug("passing in undefined table entry to getAdInfoType. "
|
||||||
|
"Invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (tn->theType == NULL) {
|
if (tn->theType == NULL) {
|
||||||
@ -725,26 +725,27 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (typeOf == NULL) {
|
if (typeOf == NULL) {
|
||||||
printdebug(
|
printdebug("Passing an NULL Type Node to Create Entry");
|
||||||
"Passing an NULL Type Node to Create Entry");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (typeOf == undefined) {
|
if (typeOf == undefined) {
|
||||||
printdebug(
|
printdebug("Passing an undefined Type Node to Create Entry");
|
||||||
"Passing an undefined Type Node to Create Entry");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
|
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
|
||||||
newEntry->theType = typeOf /*topDef*/;
|
newEntry->theType = typeOf /*topDef*/;
|
||||||
newEntry->theName = id;
|
newEntry->theName = id;
|
||||||
newEntry->additionalinfo = ad;
|
newEntry->additionalinfo = ad;
|
||||||
if (table->entries == NULL) {
|
if (table->entries == NULL) {
|
||||||
table->entries = newEntry;
|
table->entries = newEntry;
|
||||||
|
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
||||||
return newEntry;
|
return newEntry;
|
||||||
} else {
|
} else {
|
||||||
TableNode *oldEntry = table->entries;
|
TableNode *oldEntry = table->entries;
|
||||||
table->entries = newEntry;
|
table->entries = newEntry;
|
||||||
newEntry->next = oldEntry;
|
newEntry->next = oldEntry;
|
||||||
|
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
||||||
return newEntry;
|
return newEntry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -779,7 +780,7 @@ char *getName(TableNode *tn) {
|
|||||||
return undefined->theName;
|
return undefined->theName;
|
||||||
}
|
}
|
||||||
if (tn->theName == NULL) {
|
if (tn->theName == NULL) {
|
||||||
// printdebug("name of entry is currently NULL, undefined");
|
printdebug("name of entry is currently NULL, undefined");
|
||||||
return undefined->theName;
|
return undefined->theName;
|
||||||
}
|
}
|
||||||
return tn->theName;
|
return tn->theName;
|
||||||
@ -803,15 +804,13 @@ int getColumn(SymbolTable *st) {
|
|||||||
}
|
}
|
||||||
TableNode *addName(TableNode *tn, char *str) {
|
TableNode *addName(TableNode *tn, char *str) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug(
|
printdebug("passed a Null table node to the addName "
|
||||||
"passed a Null table node to the addName "
|
"function. Invalid.");
|
||||||
"function. Invalid.");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (tn == undefined) {
|
if (tn == undefined) {
|
||||||
printdebug(
|
printdebug("passed an undefined table node to the addName "
|
||||||
"passed an undefined table node to the addName "
|
"function. Invalid.");
|
||||||
"function. Invalid.");
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (tn->theName != NULL) {
|
if (tn->theName != NULL) {
|
||||||
@ -1220,7 +1219,11 @@ ListOfTable *getChildren(SymbolTable *st) { return st->Children_Scope; }
|
|||||||
SymbolTable *getFirstChild(ListOfTable *lt) { return lt->table; }
|
SymbolTable *getFirstChild(ListOfTable *lt) { return lt->table; }
|
||||||
ListOfTable *getRestOfChildren(ListOfTable *lt) { return lt->next; }
|
ListOfTable *getRestOfChildren(ListOfTable *lt) { return lt->next; }
|
||||||
TableNode *getFirstEntry(SymbolTable *st) { return st->entries; }
|
TableNode *getFirstEntry(SymbolTable *st) { return st->entries; }
|
||||||
TableNode *getNextEntry(TableNode *tn) { return tn->next; }
|
|
||||||
|
// Segfaults when passed an invalid table node!
|
||||||
|
TableNode *getNextEntry(TableNode *tn) { return tn; }
|
||||||
|
|
||||||
|
|
||||||
// uncomment the below main function along with the headers above for a simple
|
// uncomment the below main function along with the headers above for a simple
|
||||||
// standalone test of table and entry creation
|
// standalone test of table and entry creation
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user