Merge pull request #68 from UB-CSE443/array_type_check

working on making sure arrays and reserve/release are working properly
This commit is contained in:
Moroseui
2025-05-05 03:58:15 -04:00
committed by GitHub
3 changed files with 216 additions and 27 deletions

View File

@ -408,7 +408,7 @@ int getRecLength(TableNode *definition) {
}
return definition->additionalinfo->RecAdInfo->numofelements;
}
// This gets the array. Needs to up be updated to get the scope instead
SymbolTable *getRecList(TableNode *definition) {
if (definition == NULL) {
printdebug(
@ -462,6 +462,76 @@ int getRecSize(SymbolTable *tn) {
}
return -1;
}
int getRecPosition(TableNode* rec, char* id){
if (rec == NULL) {
printdebug(
"passed a NULL entry to getRecPosition. Invalid.");
return -1;
}
if (rec == undefined) {
printdebug(
"passed an undefined entry to getRecPosition. Invalid.");
return -1;
}
if (getAdInfoType(rec) != TYPE_RECORD_TYPE) {
printdebug(
"not checking the position of a record -- invalid op");
return -1;
}
TableNode* cur = getFirstEntry(getRecList(rec));
int i = 1;
while(cur != NULL){
if(strcmp(getName(cur), id) == 0){
return i;
}
cur = getNextEntry(cur);
i++;
}
if (cur == NULL){
printdebug(
"passed an invalid entry to getRecPosition. Invalid.");
return -1;
}else{
return i;
}
}
int getElementOffset(TableNode *rec, char* id) {
if (rec == NULL) {
printdebug(
"passed a NULL entry to getElementOffset. Invalid.");
return -1;
}
if (rec == undefined) {
printdebug(
"passed an undefined entry to getElementOffset. Invalid.");
return -1;
}
if (getAdInfoType(rec) != TYPE_RECORD_TYPE) {
printdebug(
"not checking the offset of a record -- invalid op");
return -1;
}
int* offsets = getRecOffsets(rec);
int position = getRecPosition(rec, id);
if (position == -1) {
printdebug(
"passed an invalid entry to getElementOffset. Invalid.");
return -1;
}
position = position - 1;
int total_offset = 0;
int current_position = 1;
while(current_position < position+1){
//adding current element in struct
total_offset += offsets[2*current_position];
//adding padding between elements
total_offset += offsets[2*current_position+1];
current_position++;
}
//returning the offset of the start of the element
return total_offset;
}
// below function takes a bool to see if parameter should be decomposed or not
; // note that functions only take one input and have one output
@ -1419,7 +1489,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if ((getFirstChild(node)) == NULL) {
print_symbol_table(getFirstChild(node), file_ptr);
} else {
if (getLine(getFirstChild(node)) == -1) {
if (getLine(getFirstChild(node)) < 0) {
continue;
} else {
print_symbol_table(getFirstChild(node), file_ptr);