added a bunch of NULL checks

This commit is contained in:
Partho
2025-03-28 22:22:58 -04:00
parent 227cec0b73
commit 57ba34ab37
3 changed files with 260 additions and 144 deletions

View File

@ -36,7 +36,7 @@
char * words;
}
%type <integ> idlist
%type <words> assignable
%type <words> expression
%type <words> constant
@ -121,27 +121,39 @@ prototype:
L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID;
definition:
TYPE ID COLON {tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
TYPE ID COLON {
printf("Currently see a record definition for %s\n", $<words>2);
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
if (table_lookup(getAncestor(cur), $2) == NULL) {
printf("rec not found \n");
}
}dblock { setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur));
cur = getParent(cur);}
| TYPE ID COLON C_INTEGER ARROW id_or_types { CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));}
| TYPE ID COLON C_INTEGER ARROW id_or_types
{printf("Currently see a array definition of name %s,storing type %s, of dimensions %d\n",
$2, $6, $4);
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));}
| function_declaration
| TYPE ID COLON id_or_types ARROW id_or_types {
printf("Currently see a function type definition of name %s,parameter type %s, of return type %s\n",
$2, $4, $6);
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6)));
}
| ID {
TableNode *node = table_lookup(getAncestor(cur), $<words>1);
if (node == NULL || getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
if (node == NULL) {
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
} else {
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
}
else {
setStartLine(node, @1.first_line);
setAsKeyword(node, false);
}
cur = CreateScope(cur, 0, 0);
} L_PAREN ID {
printf("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s\n",
$1,$4);
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL);
}R_PAREN ASSIGN sblock
| ID {
@ -149,23 +161,29 @@ TYPE ID COLON {tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo
if (node == NULL) {
printf("null check\n");
}
if (node == NULL || getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
if (node == NULL) {
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
} else {
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
}
else {
setStartLine(node, @1.first_line);
setAsKeyword(node, false);
}
cur = CreateScope(cur, 0, 0);
}AS L_PAREN {
TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1))));
if (parameter == NULL || getAdInfoType(parameter) != TYPE_RECORD) {
if (parameter == NULL) {
printf("function defined with as, but parameter is not a record at line %d, column %d\n", @1.first_line, @1.first_column);
} else {
}else if(getAdInfoType(parameter) != TYPE_RECORD){
printf("function defined with as, but parameter is not a record at line %d, column %d\n", @1.first_line, @1.first_column);
}else {
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
CreateEntry(cur, entry, NULL, NULL);
}
}
} idlist R_PAREN ASSIGN sblock
} idlist {printf("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d\n",
$1,$6);} R_PAREN ASSIGN sblock
;
@ -185,7 +203,7 @@ idlist:
printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column);
}
addName(entry, $<words>1);
} COMMA idlist
} COMMA idlist {$$ = $<integ>3 + 1;}
| ID {
TableNode *entry = getFirstEntry(cur);
@ -196,6 +214,7 @@ idlist:
printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column);
}
addName(entry, $<words>1);
$$ = 1;
}
;