ran through derefenced most if not all of the pointers

This commit is contained in:
Partho
2025-04-07 12:32:20 -04:00
parent e2aa9e7c12
commit e42e537339

View File

@ -18,7 +18,6 @@
%{
#include "../src/symbol_table.c"
void yyerror(const char *err);
int token_tracker;
TableNode * tn;
@ -142,17 +141,17 @@ definition:
| TYPE ID COLON C_INTEGER ARROW id_or_types
{
printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName($6), $4);
CreateEntry(cur,TYPE_ARRAY_TYPE, arrayprim, $2, CreateArrayInfo($4, $6));
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName($6));
printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName((TableNode*)$6), $4);
CreateEntry(cur,TYPE_ARRAY_TYPE, arrayprim, $2, CreateArrayInfo($4, (TableNode*)$6));
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName((TableNode*)$6));
}
| function_declaration
| TYPE ID COLON id_or_types ARROW id_or_types
{
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", $2, getName($4), getName($6));
CreateEntry(cur,TYPE_FUNCTION_TYPE,funtypeprime,$2,CreateFunctionTypeInfo($4 ,$6));
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", $2, getName((TableNode*)$4), getName((TableNode*)$6));
CreateEntry(cur,TYPE_FUNCTION_TYPE,funtypeprime,$2,CreateFunctionTypeInfo((TableNode*)$4 ,(TableNode*)$6));
}
| ID
@ -349,8 +348,8 @@ declaration_list:
declaration:
id_or_types COLON ID
{
printdebug("ID/TYPE: %s, ID: %s", getName($1), $3) ;
CreateEntry(cur,getAdInfoType($1),$1,$3,getAdInfo($1));
printdebug("ID/TYPE: %s, ID: %s", getName((TableNode*)$1), $3) ;
CreateEntry(cur,getAdInfoType((TableNode*)$1),(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
}
;
@ -365,8 +364,8 @@ id_or_types:
| types
{
printdebug("string of type is %s in types pattern of id_or_type rule.",getName($1));
$$ = $1;
printdebug("string of type is %s in types pattern of id_or_type rule.",getName((TableNode*)$1));
$$ = (TableNode*)$1;
}
;
@ -392,22 +391,22 @@ compound_statement:
simple_statement:
assignable ASSIGN expression
{
if(strcmp(getName($1), getName($3)) == 0) {
if(strcmp(getName((TableNode*)$1), getName((TableNode*)$3)) == 0) {
printdebug("Passed standard type check; assignable = expression");
} else if((strcmp(getType($1), "array") == 0) && (strcmp(getName($3), "address") == 0)) {
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
} else if((strcmp(getType($1), "record") == 0) && (strcmp(getName($3), "address") == 0)) {
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
} else if((strcmp(getType($1), "function type primitive") == 0) && (strcmp(getName($3), "address") == 0)) {
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
} 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 () {
// } 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, getType($1), getType($3), COLOR_WHITE);
printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType($1));
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));
}
}
@ -434,14 +433,14 @@ ablock:
argument_list:
expression COMMA argument_list
{
CreateEntry(cur,getAdInfoType($1), $1, getName($1), NULL);
CreateEntry(cur,getAdInfoType((TableNode*)$1), (TableNode*)$1, getName((TableNode*)$1), NULL);
$$ = $3 + 1;
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
}
| expression
{
CreateEntry(cur,getAdInfoType($1),$1, getName($1), NULL);
CreateEntry(cur,getAdInfoType((TableNode*)$1),(TableNode*)$1, getName((TableNode*)$1), NULL);
$$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$);
}
;
@ -452,38 +451,38 @@ expression:
constant
{
printdebug("constant expression");
$$ = $1;
$$ = (TableNode*)$1;
}
| SUB_OR_NEG expression %prec UMINUS
{
printdebug("negative expression");
if($2 != integ) {
if((TableNode*)$2 != integ) {
printdebug("cant negate something not an integer at line %d and column %d",@2.first_line,@2.first_column);
$$=undefined;
} else {
$$=$2;
$$=(TableNode*)$2;
}
}
| NOT expression
{
printdebug("not expression");
if($2 == boo) {
$$=$2;
if((TableNode*)$2 == boo) {
$$=(TableNode*)$2;
} else {
$$=undefined;
printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,getName($2));
printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,getName((TableNode*)$2));
}
}
| expression ADD expression
{
printdebug("add expression");
if($1 == $3 && $1 == integ) {
$$=$1;
if((TableNode*)$1 == (TableNode*)$3 && (TableNode*)$1 == integ) {
$$=(TableNode*)$1;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -491,10 +490,10 @@ expression:
| expression SUB_OR_NEG expression
{
printdebug("sub or neg expression");
if($1 == $3 && $1 == integ) {
$$=$1;
if((TableNode*)$1 == (TableNode*)$3 && (TableNode*)$1 == integ) {
$$=(TableNode*)$1;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -502,8 +501,8 @@ expression:
| expression MUL expression
{
printdebug("multiply expression");
if($1 == $3 && $1 == integ) {
$$=$1;
if((TableNode*)$1 == (TableNode*)$3 && (TableNode*)$1 == integ) {
$$=(TableNode*)$1;
} else{
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=undefined;
@ -513,10 +512,10 @@ expression:
| expression DIV expression
{
printdebug("divide expression");
if((strcmp(getName($1),getName($3))==0) && ($1 == integ)) {
$$=$1;
if((strcmp(getName((TableNode*)$1),getName((TableNode*)$3))==0) && ((TableNode*)$1 == integ)) {
$$=(TableNode*)$1;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -527,7 +526,7 @@ expression:
if($1 == $3 && $1 == integ) {
$$=$1;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -538,7 +537,7 @@ expression:
if($1 == $3 && $1 == boo){
$$=$1;
} else{
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -546,10 +545,10 @@ expression:
| expression OR expression
{
printdebug("OR");
if((strcmp(getName($1),getName($3))==0) && $1 == boo) {
if((strcmp(getName((TableNode*)$1),getName((TableNode*)$3))==0) && $1 == boo) {
$$=$1;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -560,7 +559,7 @@ expression:
if($1 == $3 && $1==integ) {
$$=boo;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$=undefined;
}
}
@ -571,20 +570,20 @@ expression:
if($1 == $3 && $1 != undefined) {
$$=boo;
} else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,getName($1),getName($3));
printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,getName((TableNode*)$1),getName((TableNode*)$3));
$$ = undefined;
}
}
| assignable
{
printdebug("assignable expression. current type is %s",$1);
$$= getTypeEntry($1);
printdebug("assignable expression. current type is %s",getName((TableNode*)$1));
$$= getTypeEntry((TableNode*)$1);
}
| L_PAREN expression R_PAREN
{
printdebug("paren expression. current type is %s",getName($2));
printdebug("paren expression. current type is %s",getName((TableNode*)$2));
$$=$2;
}
@ -614,17 +613,17 @@ assignable:
}
ablock
{
int type = getAdInfoType(look_up(getParent(cur), getName($1)));
int type = getAdInfoType(look_up(getParent(cur), getName((TableNode*)$1)));
printdebug("%stype is %d", COLOR_PURPLE, type);
printdebug("%s", $1);
printdebug("%s", getName((TableNode*)$1));
if (type == TYPE_FUNCTION_DECLARATION) {
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
if (look_up(getParent(cur), getName($1))->additionalinfo->FunDecAdInfo->regularoras) {
if (look_up(getParent(cur), getName((TableNode*)$1))->additionalinfo->FunDecAdInfo->regularoras) {
printdebug("as function");
//char *funtype = getType(look_up(cur, $1));
printdebug("%s", getType(look_up(cur, getName($1))));
TableNode *param = getParameter(look_up(getParent(cur), getName($1)));
printdebug("%s", getType(look_up(cur, getName((TableNode*)$1))));
TableNode *param = getParameter(look_up(getParent(cur), getName((TableNode*)$1)));
SymbolTable *recList = getRecList(param);
TableNode *lastCheckedRef = getFirstEntry(recList);
TableNode *lastCheckedAct = getFirstEntry(cur);
@ -651,32 +650,32 @@ assignable:
}
} else {
char *expected = getName(getParameter(look_up(getParent(cur), getName($1))));
char *expected = getName(getParameter(look_up(getParent(cur), getName((TableNode*)$1))));
char *actual = getType(getFirstEntry(cur));
if (strcmp(expected, actual) != 0) {
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
}
}
$$ = getReturn((table_lookup(getAncestor(cur), getType($1))));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
$$ = getReturn((table_lookup(getAncestor(cur), getType((TableNode*)$1))));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName((TableNode*)$1));
} else if (type == TYPE_ARRAY_TYPE) {
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
if (getNumArrDim(look_up(getParent(cur), getName($1))) != $<integ>2) {
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, getName($1))), $<integ>2, @2.first_line, @2.first_column);
if (getNumArrDim(look_up(getParent(cur), getName((TableNode*)$1))) != $<integ>2) {
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, getName((TableNode*)$1))), $<integ>2, @2.first_line, @2.first_column);
}
$$ = getArrType(look_up(getParent(cur), getName($1)));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
$$ = getArrType(look_up(getParent(cur), getName((TableNode*)$1)));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName((TableNode*)$1));
}
cur = getParent(cur);
}
| assignable rec_op ID
{
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), getName($1))), $3)) {
$$ = table_lookup(getRecList(table_lookup(getAncestor(cur), getName($1))), $3);
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), getName((TableNode*)$1))), $3)) {
$$ = table_lookup(getRecList(table_lookup(getAncestor(cur), getName((TableNode*)$1))), $3);
}
printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", getName($$), $1);
printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", getName((TableNode*)($$)), $1);
}
;