have to finish idlist rules

This commit is contained in:
Partho
2025-04-11 19:00:24 -04:00
parent e8bad44949
commit 3fc7a6371a
4 changed files with 47 additions and 17 deletions

View File

@ -176,25 +176,25 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
int total_size = 0;
int counter = 0;
int *offsets = (int *)calloc(2 * k, sizeof(int));
if(getAdInfoType(this) == TYPE_FUNCTION_TYPE){
if(getAdInfoType(this) == TYPE_FUNCTION_DECLARATION){
offsets[counter] = 8;
total_size = total_size + offsets[counter];
largest = 8;
counter++;
}
else if(getAdInfoType(this) == TYPE_RECORD_TYPE){
offsets[counter] = getRecTotal(this);
else if((getAdInfoType(this) == TYPE_RECORD) && (node != getTypeEntry(this))){
offsets[counter] = getRecTotal(getTypeEntry(this));
total_size = total_size + offsets[counter];
largest = offsets[counter];
counter++;
}
else if(getAdInfoType(this)==TYPE_PRIMITIVE){
offsets[counter] = getPrimSize(this);
offsets[counter] = getPrimSize(getTypeEntry(this));
total_size = total_size + offsets[counter];
largest = offsets[counter];
counter++;
}
else if(getAdInfoType(this)==TYPE_ARRAY_TYPE){
else if(getAdInfoType(this)==TYPE_ARRAY){
offsets[counter] = 8;
total_size = total_size + offsets[counter];
largest = offsets[counter];
@ -202,12 +202,12 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
}
else {
printdebug(
"[TYPE CHECK] passed an invalid (first) parameter to a function definition.");
"[TYPE CHECK] passed an invalid (first) parameter to a function definition. seeing %d",getAdInfoType(this));
return undefined;
}
this = getNextEntry(this);
while(this != NULL){
if(getAdInfoType(this) == TYPE_FUNCTION_TYPE){
if(getAdInfoType(this) == TYPE_FUNCTION_DECLARATION){
int s = 8;
if (s > largest) {
largest = s;
@ -222,7 +222,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
counter++;
this = getNextEntry(this);
}
else if(getAdInfoType(this) == TYPE_ARRAY_TYPE){
else if(getAdInfoType(this) == TYPE_ARRAY){
int s = 8;
if (s > largest) {
largest = s;
@ -237,12 +237,14 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
counter++;
this = getNextEntry(this);
}
else if(getAdInfoType(this) == TYPE_RECORD_TYPE){
int s = getRecTotal(this);
else if((getAdInfoType(this) == TYPE_RECORD) && (node != getTypeEntry(this))){
int s = getRecTotal(getTypeEntry(this));
if (s > largest) {
largest = s;
}
//make sure current location is aligned properly
printTableNode(this);
printTableNode(node);
offsets[counter] = (total_size % s);
total_size = total_size + offsets[counter];
counter++;
@ -253,7 +255,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
this = getNextEntry(this);
}
else if(getAdInfoType(this) == TYPE_PRIMITIVE){
int s = getPrimSize(this);
int s = getPrimSize(getTypeEntry(this));
if (s > largest) {
largest = s;
}
@ -1049,8 +1051,12 @@ TableNode *look_up(SymbolTable *table, char *x) {
}
int col_widths[5] = {30, 8, 8, 35, 35};
void printline(FILE *file_ptr);
void printline(FILE *file_ptr) {
void printline(FILE *file_ptr, bool b);
void printline(FILE *file_ptr, bool b) {
if (b) {
fprintf(file_ptr, "oop\n");
}
for (int i = 0; i < 5; i++) {
for (int ii = 0; ii < col_widths[i]; ii++) {
fprintf(file_ptr, "-");
@ -1095,7 +1101,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
}
TableNode *entry = table->entries;
printline(file_ptr);
printline(file_ptr, false);
int parentScopeNum = 0;
int currentScopeNum = 0;
@ -1213,7 +1219,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
}
if (getParent(table) == NULL) {
printline(file_ptr);
printline(file_ptr, true);
}
}
// get top most symbol table