diff --git a/src/grammar.y b/src/grammar.y index 24b7d15..579ebd5 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -185,6 +185,7 @@ definition: || type_of_param_type == TYPE_PRIMITIVE || type_of_param_type == TYPE_ALL_ELSE || type_of_param_type == TYPE_SYSTEM_DEFINED + || type_of_param_type == TYPE_RECORD || 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 function definition is %s which is invalid", getAdInfo(parameter)); type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases @@ -192,7 +193,15 @@ definition: 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)); + if(type_of_param_type == TYPE_FUNCTION_TYPE){ + CreateEntry(cur, TYPE_FUNCTION_DECLARATION, parameter,NULL, getAdInfo(parameter)); + } + if(type_of_param_type == TYPE_ARRAY_TYPE){ + CreateEntry(cur, TYPE_ARRAY, parameter,NULL, getAdInfo(parameter)); + } + if(type_of_param_type == TYPE_PRIMITIVE_TYPE){ + CreateEntry(cur, TYPE_PRIMITIVE, parameter,NULL, getAdInfo(parameter)); + } } } else { for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){ @@ -200,22 +209,32 @@ definition: 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_PRIMITIVE || type_of_param_type == TYPE_ALL_ELSE || type_of_param_type == TYPE_SYSTEM_DEFINED + || type_of_param_type == TYPE_RECORD || 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)); + printdebug("[TYPE CHECK] type of parameter (if record) inside record 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 }else{ - printdebug("type of parameter correctly being passed in to AS function definition is %s which is valid", getName(entry)); + 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 { + if(type_of_param_type == TYPE_FUNCTION_TYPE){ + CreateEntry(cur, TYPE_FUNCTION_DECLARATION, entry,NULL, getAdInfo(entry)); + } + if(type_of_param_type == TYPE_ARRAY_TYPE){ + CreateEntry(cur, TYPE_ARRAY, entry,NULL, getAdInfo(entry)); + } + if(type_of_param_type == TYPE_PRIMITIVE_TYPE){ + CreateEntry(cur, TYPE_PRIMITIVE, entry,NULL, getAdInfo(entry)); + } + /*printdebug("creating entry of type %s for function", getType(entry)); + CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/ + } } - 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,$5); diff --git a/tests/sprint2/test/sp2_carls_mistake.alpha b/tests/sprint2/test/sp2_carls_mistake.alpha index c85c310..45d53c3 100644 --- a/tests/sprint2/test/sp2_carls_mistake.alpha +++ b/tests/sprint2/test/sp2_carls_mistake.alpha @@ -5,7 +5,7 @@ type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer type arr: 1 -> integer - +type w : rec function foo: T1 function bar1: T2 function bar2: T2