This commit is contained in:
Scarlett
2025-04-08 16:01:36 -04:00
parent 87659ebf46
commit a4dc3d90be
5 changed files with 82 additions and 25 deletions

View File

@ -326,14 +326,14 @@ sblock:
dblock:
L_BRACKET
{if(getLine(cur)==0){
setLineNumber(cur, @1.first_line);
setColumnNumber(cur,@1.first_line);}
else{
cur = CreateScope(cur,@1.first_line,@1.first_column);
{
if (getLine(cur) == 0) {
setLineNumber(cur, @1.first_line);
setColumnNumber(cur,@1.first_line);
} else{
cur = CreateScope(cur,@1.first_line,@1.first_column); // <----- What is this?
}
}
}
declaration_list R_BRACKET;
@ -391,22 +391,45 @@ compound_statement:
simple_statement:
assignable ASSIGN expression
{
if(strcmp(getName((TableNode*)$1), getName((TableNode*)$3)) == 0) {
printdebug("Passed standard type check; assignable = expression");
} else if((strcmp(getType((TableNode*)$1), "array") == 0) && (strcmp(getName((TableNode*)$3), "address") == 0)) {
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName((TableNode*)$1), getName((TableNode*)$3));
} else if((strcmp(getType((TableNode*)$1), "record") == 0) && (strcmp(getName((TableNode*)$3), "address") == 0)) {
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName((TableNode*)$1), getName((TableNode*)$3));
} else if((strcmp(getType((TableNode*)$1), "function type primitive") == 0) && (strcmp(getName((TableNode*)$3), "address") == 0)) {
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName((TableNode*)$1), getName((TableNode*)$3));
// } else if () {
bool passCheck = false;
TableNode * left = (TableNode*)$1;
TableNode * right = (TableNode*)$3;
printTableNode((TableNode*)$1);
printTableNode((TableNode*)$3);
// } 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 {
if (strcmp(getType(right), "primitive") == 0) {
if (strcmp((getType(left)),(getName(right))) == 0) {
printdebug("%s[☺] Passed primitive type check; %s = %s", COLOR_GREEN, getName(left), getName(right));
passCheck = true;
}
}
if(strcmp(getName(left), getName(right)) == 0) {
printdebug("Passed standard type check; assignable = expression");
passCheck = true;
}
if((strcmp(getType(left), "array") == 0) && (strcmp(getName(right), "address") == 0)) {
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName(left), getName(right));
passCheck = true;
}
if((strcmp(getType(left), "record") == 0) && (strcmp(getName(right), "address") == 0)) {
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName(left), getName(right));
passCheck = true;
}
if((strcmp(getType(left), "function type primitive") == 0) && (strcmp(getName(right), "address") == 0)) {
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName(left), getName(right));
passCheck = true;
}
// Type check fails:
if (!passCheck) {
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, getType((TableNode*)$1), getType((TableNode*)$3), COLOR_WHITE);
printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType((TableNode*)$1));
printdebug(" - Invalid types %s$1: %s and $3: %s%s", COLOR_YELLOW, getType(left), getType(right), COLOR_WHITE);
printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType(left));
}
}
@ -624,6 +647,8 @@ assignable:
//char *funtype = getType(look_up(cur, $1));
printdebug("%s", getType(look_up(cur, getName((TableNode*)$1))));
TableNode * typeNode = table_lookup(getAncestor(cur), getType((TableNode*)$1));
TableNode *param = getParameter(typeNode);
printTableNode(param);