more type check fixes
This commit is contained in:
@ -266,13 +266,20 @@ simple_statement:
|
||||
{
|
||||
if(strcmp($1, $3) == 0) {
|
||||
printdebug("Passed standard type check; assignable = expression");
|
||||
} else if((strcmp($1, "rec") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("Passed rec type check; rec = address");
|
||||
} else if((strcmp($1, "array") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("Passed array type check; array = address");
|
||||
} else if((strcmp(getType(look_up(cur, $1)), "array") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else if((strcmp(getType(look_up(cur, $1)), "record") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else if((strcmp(getType(look_up(cur, $1)), "function type primitive") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
// } else if () {
|
||||
|
||||
// } else if(strcmp(getType(table_lookup(cur, $1)), getType(table_lookup(cur, $3))) == 0) {
|
||||
// printdebug("%s[] Passed double lookup type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else {
|
||||
printdebug("%s[TYPE ERROR] %sMismatch at %sline %d and column %d%s", COLOR_ORANGE, COLOR_WHITE, COLOR_YELLOW, @2.first_line, @2.first_column, COLOR_WHITE);
|
||||
printdebug(" - Invalid types %s$1: %s and $3: %s%s", COLOR_YELLOW, $1, $3, COLOR_WHITE);
|
||||
printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType(look_up(cur, $1)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -387,32 +394,35 @@ expression:
|
||||
// add array case
|
||||
// include type check for ablock in arrays - ablock is always the int of the elements in array/rec
|
||||
assignable:
|
||||
ID {$$ = getType(look_up(cur,$1)); printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
|
||||
| assignable {
|
||||
cur = CreateScope(cur, -1,-1);
|
||||
}ablock {
|
||||
int type = getAdInfoType(look_up(getParent(cur), $1));
|
||||
if (type == TYPE_FUNCTION_DECLARATION) {
|
||||
if (getAsKeyword(look_up(getParent(cur), $1))) {
|
||||
TableNode *param = getParameter(look_up(getParent(cur), $1));
|
||||
SymbolTable *recList = getRecList(param);
|
||||
TableNode *lastCheckedRef = getFirstEntry(recList);
|
||||
TableNode *lastCheckedAct = getFirstEntry(cur);
|
||||
while (getNextEntry(lastCheckedRef) != NULL) {
|
||||
lastCheckedRef = getNextEntry(lastCheckedRef);
|
||||
}
|
||||
//this isn't very efficient, but will hopefully work
|
||||
while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
|
||||
if (strcmp(getType(lastCheckedAct), getName(lastCheckedRef)) != 0) {
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
|
||||
}
|
||||
lastCheckedAct = getNextEntry(lastCheckedAct);
|
||||
TableNode *tn = getFirstEntry(recList);
|
||||
while (getNextEntry(tn) != lastCheckedRef) {
|
||||
tn = getNextEntry(tn);
|
||||
}
|
||||
lastCheckedRef = tn;
|
||||
}
|
||||
ID {$$ = getType(look_up(cur,$1)); printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
|
||||
| assignable
|
||||
{
|
||||
cur = CreateScope(cur, -1,-1);
|
||||
}
|
||||
ablock
|
||||
{
|
||||
int type = getAdInfoType(look_up(getParent(cur), $1));
|
||||
if (type == TYPE_FUNCTION_DECLARATION) {
|
||||
if (getAsKeyword(look_up(getParent(cur), $1))) {
|
||||
TableNode *param = getParameter(look_up(getParent(cur), $1));
|
||||
SymbolTable *recList = getRecList(param);
|
||||
TableNode *lastCheckedRef = getFirstEntry(recList);
|
||||
TableNode *lastCheckedAct = getFirstEntry(cur);
|
||||
while (getNextEntry(lastCheckedRef) != NULL) {
|
||||
lastCheckedRef = getNextEntry(lastCheckedRef);
|
||||
}
|
||||
//this isn't very efficient, but will hopefully work
|
||||
while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
|
||||
if (strcmp(getName(lastCheckedAct), getName(lastCheckedRef)) != 0) {
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",getName(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
|
||||
}
|
||||
lastCheckedAct = getNextEntry(lastCheckedAct);
|
||||
TableNode *tn = getFirstEntry(recList);
|
||||
while (getNextEntry(tn) != lastCheckedRef) {
|
||||
tn = getNextEntry(tn);
|
||||
}
|
||||
lastCheckedRef = tn;
|
||||
}
|
||||
|
||||
} else {
|
||||
char *expected = getName(getParameter(look_up(getParent(cur), $1)));
|
||||
@ -433,7 +443,7 @@ assignable:
|
||||
printdebug("expected only integer expressions in array ablock at line %d column %d", @3.first_line, @3.first_column);
|
||||
}
|
||||
}
|
||||
$$ = $1;
|
||||
$$ = getName(getArrType(look_up(getParent(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
}
|
||||
cur = getParent(cur);
|
||||
|
Reference in New Issue
Block a user