removed as from function definitions

This commit is contained in:
Annie
2025-04-09 13:13:20 -04:00
parent 3010ad6517
commit d262bd9c39

View File

@ -156,41 +156,6 @@ definition:
CreateEntry(cur,TYPE_FUNCTION_TYPE,funtypeprime,$2,CreateFunctionTypeInfo((TableNode*)$4 ,(TableNode*)$6));
}
| ID
{
TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) {
printdebug("[TYPE CHECK] function not declared at line %d, column %d", @1.first_line, @1.first_column);
} else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
printdebug("[TYPE CHECK] function not declared at line %d, column %d", @1.first_line, @1.first_column);
} else {
setStartLine(node, @1.first_line);
setAsKeyword(node, false);
}
cur = CreateScope(cur, 0, 0);
printdebug("Created a new scope");
}
L_PAREN ID
{
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s", $1,$4);
TableNode* type_of_param = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1))));
int type_of_param_type = getAdInfoType(type_of_param);
if( type_of_param_type == TYPE_UNDEFINED
|| type_of_param_type == TYPE_FUNCTION_DECLARATION
|| type_of_param_type == TYPE_ARRAY
|| type_of_param_type == TYPE_ALL_ELSE
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
printdebug("[TYPE CHECK] type of parameter is undefined or invalid at line %d, column %d", @4.first_line, @4.first_column);
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
}else{
printdebug("type of parameter is %s at line %d, column %d", getName(type_of_param), @4.first_line, @4.first_column);
}
CreateEntry(cur,type_of_param_type, type_of_param, $4, getAdInfo(type_of_param));
}
R_PAREN ASSIGN sblock //leaving scope is being taken care of in sblock
| ID {
TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) {
@ -206,42 +171,55 @@ definition:
}
cur = CreateScope(cur, 0, 0);
printdebug("Created a new scope");
}AS L_PAREN {
} L_PAREN {
TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1))));
printdebug("parameter type: %s", getType(parameter));
if (parameter == undefined) {
printdebug("[TYPE CHECK] function defined with as, but parameter is undefined at line %d, column %d", @1.first_line, @1.first_column);
}else if(getAdInfoType(parameter) != TYPE_RECORD){
printdebug("record: %s., primitive: %s.", getType(parameter), getName(recprime));
printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column);
}else {
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
int type_of_param_type = getAdInfoType(entry);
if( type_of_param_type == TYPE_UNDEFINED
int type_of_param_type = getAdInfoType(parameter);
if( type_of_param_type == TYPE_UNDEFINED
|| type_of_param_type == TYPE_FUNCTION_DECLARATION
|| type_of_param_type == TYPE_ARRAY
|| type_of_param_type == TYPE_ALL_ELSE
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
printdebug("[TYPE CHECK] type of parameter being passed in to AS function definition is %s which is invalid", getName(entry));
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
}else{
printdebug("type of parameter correctly being passed in to AS function definition is %s which is valid", getName(entry));
}
if(type_of_param_type == TYPE_UNDEFINED){
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
} else {
CreateEntry(cur,type_of_param_type, entry, NULL, getAdInfo(entry));
/*printdebug("creating entry of type %s for function", getType(entry));
CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/
printdebug("[TYPE CHECK] type of parameter being passed in to function definition is %s which is invalid", getAdInfo(parameter));
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
}
if(type_of_param_type == TYPE_UNDEFINED){
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
} else {
CreateEntry(cur, getAdInfoType(parameter), parameter,NULL, getAdInfo(parameter));
}
} else {
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
int type_of_param_type = getAdInfoType(entry);
if( type_of_param_type == TYPE_UNDEFINED
|| type_of_param_type == TYPE_FUNCTION_DECLARATION
|| type_of_param_type == TYPE_ARRAY
|| type_of_param_type == TYPE_ALL_ELSE
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
printdebug("[TYPE CHECK] type of parameter being passed in to AS function definition is %s which is invalid", getName(entry));
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
}else{
printdebug("type of parameter correctly being passed in to AS function definition is %s which is valid", getName(entry));
}
if(type_of_param_type == TYPE_UNDEFINED){
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
} else {
CreateEntry(cur,type_of_param_type, entry, NULL, getAdInfo(entry));
/*printdebug("creating entry of type %s for function", getType(entry));
CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/
}
}
}
}
} idlist {printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d",
$1,$6);} R_PAREN ASSIGN sblock //check sblock type
;
} idlist {
printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d", $1,$5);
} R_PAREN ASSIGN sblock //check sblock type
;
function_declaration:
FUNCTION ID COLON ID