still fixing assignable type checking

This commit is contained in:
Partho
2025-04-29 14:42:19 -04:00
parent 49b83cd8ad
commit dcdcf31068
4 changed files with 48 additions and 53 deletions

View File

@ -650,7 +650,7 @@ argument_list:
//NEED TO EMIT PARAMETERS HERE. MAYBE USE STACK STRUCTURE
expression COMMA argument_list
{
CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), getName((TableNode*)$1), NULL);
CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
$$ = $3 + 1;
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
}
@ -880,6 +880,8 @@ assignable:
| assignable
{
printdebug("%sBeginning rule 2 of assignable.", COLOR_CYAN);
//Creating a dummy scope where we create entries for all the arguments of a function call
//Must also consider that we might be in an array access
cur = CreateScope(cur, -1,-1);
}
//we have to consider emmissions in ablocks
@ -892,61 +894,45 @@ assignable:
if (type == TYPE_FUNCTION_TYPE) {
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
if (look_up(getParent(cur), getType((TableNode*)$1))->additionalinfo->FunDecAdInfo->regularoras) {
printdebug("as function");
//char *funtype = getType(look_up(cur, $1));
//printdebug("%s", getType(look_up(cur, getName((TableNode*)$1))));
TableNode * typeNode = getTypeEntry((TableNode*)$1);
TableNode *param = getParameter(typeNode);
printTableNode(param);
if (getAdInfoType(param) == TYPE_RECORD_TYPE) {
SymbolTable *recList = getRecList(param);
TableNode *lastCheckedRef = getFirstEntry(recList);
TableNode *lastCheckedAct = getFirstEntry(cur);
while (getNextEntry(lastCheckedRef) != NULL) {
lastCheckedRef = getNextEntry(lastCheckedRef);
//getting the parameter. The type of assignable is a function type so we need to access the paramater of the type
TableNode *expected = getParameter(getTypeEntry((TableNode*)$1));
//Jump into case where the parameter is a record type
if(getAdInfoType(expected) == TYPE_RECORD_TYPE){
//int argument_size = getRecSize(cur);
int parameter_size = getRecSize(getRecList(expected));
printdebug("argument size is %d\n", $3);
printdebug("parameter size is %d\n", parameter_size);
if ($3 != parameter_size) {
throw_error(ERROR_SYNTAX, "expected %d arguments for this function but got %d", parameter_size, $3);
}else{
TableNode* param_arg_type = getFirstEntry(getRecList(expected));
TableNode* arg_given = getFirstEntry(cur);
while(arg_given != NULL && getName(arg_given)[0]=='&'){
arg_given = getNextEntry(arg_given);
}
if ($3 != getRecLength(param)) {
throw_error(ERROR_SYNTAX, "expected %d arguments but got %d", getRecLength(param), $3);
if(getTypeEntry(arg_given) != param_arg_type){
throw_error(ERROR_TYPE, "expected %s expression as first argument in function call but got %s", getName(param_arg_type), getType(arg_given));
}
//this isn't very efficient, but will hopefully work
while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
if (getTypeEntry(lastCheckedRef) != getTypeEntry(lastCheckedAct)) {
throw_error(ERROR_TYPE, "expected %s. expression in function call got %s",getType(lastCheckedRef), getName(lastCheckedAct));
param_arg_type = getNextEntry(param_arg_type);
arg_given = getNextEntry(arg_given);
while(arg_given != NULL && param_arg_type != NULL){
while(arg_given != NULL && getName(arg_given)[0]=='&'){
arg_given = getNextEntry(arg_given);
}
lastCheckedAct = getNextEntry(lastCheckedAct);
TableNode *tn = getFirstEntry(recList);
if (tn != lastCheckedRef) {
while (getNextEntry(tn) != lastCheckedRef) {
tn = getNextEntry(tn);
}
lastCheckedRef = tn;
} else {break;}
}
} else {
if (strcmp(getName(param), getType(getFirstEntry(cur))) != 0) {
throw_error(ERROR_TYPE, "expected %s expression in function call but got %s", getName(param), getName(getFirstEntry(cur)));
}
if (getNextEntry(getFirstEntry(cur)) != NULL) {
throw_error(ERROR_SYNTAX, "expected 1 parameter, but got multiple in function call");
if(getTypeEntry(arg_given) != param_arg_type){
throw_error(ERROR_TYPE, "expected %s expression as argument in function call but got %s", getName(param_arg_type), getType(arg_given));
}
arg_given = getNextEntry(arg_given);
param_arg_type = getNextEntry(param_arg_type);
}
}
} else {
char *expected = getName(getParameter(look_up(getParent(cur), getType((TableNode*)$1))));
char *actual = getType(getFirstEntry(cur));
if (strcmp(expected, actual) != 0) {
throw_error(ERROR_TYPE, "expected %s expression in function call but got %s", expected, actual);
}
if ($3 != 1) {
throw_error(ERROR_SYNTAX, "expected 1 argument but got %d", $3); }
}else{
TableNode *actual = getTypeEntry(getFirstEntry(cur));
if (expected == actual) {
throw_error(ERROR_TYPE, "expected %s expression in function call but got %s", expected, actual);
}
if ($3 != 1) {
throw_error(ERROR_SYNTAX, "expected 1 argument but got %d", $3); }
printTableNode(getReturn(getTypeEntry((TableNode*)$1)));
char* temp = temp_var_gen();
@ -971,7 +957,7 @@ assignable:
$$ = node;
//NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK for function call)
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName(typeNode2), getName((TableNode*)$1));
}
} else if (type == TYPE_ARRAY_TYPE) {
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
if (getNumArrDim(look_up(getParent(cur), getType((TableNode*)$1))) != $<integ>2) {