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