Merge branch 'side_branch' into Extra_tweaks
This commit is contained in:
@ -694,7 +694,7 @@ int getRecSize(SymbolTable *tn) {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int getRecPosition(TableNode* rec, char* id){
|
||||
int getRecPosition(TableNode *rec, char *id) {
|
||||
if (rec == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL entry to getRecPosition. Invalid.");
|
||||
@ -710,25 +710,25 @@ int getRecPosition(TableNode* rec, char* id){
|
||||
"not checking the position of a record -- invalid op");
|
||||
return -1;
|
||||
}
|
||||
TableNode* cur = getFirstEntry(getRecList(rec));
|
||||
TableNode *cur = getFirstEntry(getRecList(rec));
|
||||
int i = 1;
|
||||
while(cur != NULL){
|
||||
if(strcmp(getName(cur), id) == 0){
|
||||
while (cur != NULL) {
|
||||
if (strcmp(getName(cur), id) == 0) {
|
||||
return i;
|
||||
}
|
||||
cur = getNextEntry(cur);
|
||||
i++;
|
||||
}
|
||||
if (cur == NULL){
|
||||
if (cur == NULL) {
|
||||
printdebug(
|
||||
"passed an invalid entry to getRecPosition. Invalid.");
|
||||
return -1;
|
||||
}else{
|
||||
return i;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
int getElementOffset(TableNode *rec, char* id) {
|
||||
int getElementOffset(TableNode *rec, char *id) {
|
||||
if (rec == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL entry to getElementOffset. Invalid.");
|
||||
@ -744,7 +744,7 @@ int getElementOffset(TableNode *rec, char* id) {
|
||||
"not checking the offset of a record -- invalid op");
|
||||
return -1;
|
||||
}
|
||||
int* offsets = getRecOffsets(rec);
|
||||
int *offsets = getRecOffsets(rec);
|
||||
int position = getRecPosition(rec, id);
|
||||
if (position == -1) {
|
||||
printdebug(
|
||||
@ -754,11 +754,11 @@ int getElementOffset(TableNode *rec, char* id) {
|
||||
position = position - 1;
|
||||
int total_offset = 0;
|
||||
int current_position = 1;
|
||||
while(current_position < position+1){
|
||||
while (current_position < position + 1) {
|
||||
//adding current element in struct
|
||||
total_offset += offsets[2*current_position];
|
||||
total_offset += offsets[2 * current_position];
|
||||
//adding padding between elements
|
||||
total_offset += offsets[2*current_position+1];
|
||||
total_offset += offsets[2 * current_position + 1];
|
||||
current_position++;
|
||||
}
|
||||
//returning the offset of the start of the element
|
||||
@ -1721,7 +1721,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)) < 0) {
|
||||
if (getLine(getFirstChild(node)) < -3) {
|
||||
continue;
|
||||
} else {
|
||||
print_symbol_table(getFirstChild(node), file_ptr);
|
||||
@ -1971,3 +1971,28 @@ TableNode *printTableNode(TableNode *tn) {
|
||||
|
||||
return tn;
|
||||
}
|
||||
|
||||
int getStackSize() {
|
||||
int i = 0;
|
||||
TableNode *tn = getFirstEntry(top);
|
||||
while (tn != NULL) {
|
||||
i++;
|
||||
tn = getNextEntry(tn);
|
||||
}
|
||||
|
||||
ListOfTable *lt = getChildren(top);
|
||||
while (lt != NULL) {
|
||||
TableNode *first = lt->table->entries;
|
||||
while (first != NULL) {
|
||||
i++;
|
||||
first = getNextEntry(first);
|
||||
}
|
||||
|
||||
lt = lt->next;
|
||||
}
|
||||
|
||||
i= i * 8;
|
||||
if (i % 16 != 0) i += 8;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
Reference in New Issue
Block a user