Type check errors

This commit is contained in:
Scarlett
2025-04-16 16:30:58 -04:00
parent 5a23ef2756
commit c72e7a2a28
6 changed files with 128 additions and 89 deletions

View File

@ -59,8 +59,9 @@ int check_flag(char *arg, char *alpha) {
fprintf(stderr, "FLAGS REPEAT\n");
return -1;
} else if (strcmp("-tc", arg) == 0) {
if (tc_flag == NULL) {
return new_file(arg, alpha);
if (tc_flag == false) {
tc_flag = true;
return 0;
}
fprintf(stderr, "FLAGS REPEAT\n");
return -1;
@ -124,13 +125,12 @@ int run(FILE *alpha) {
}
if (asc_flag != NULL) {
printf("Flag -asc is not implemented yet\n");
printdebug("[-asc] Annotated Source Code is enabled.");
fclose(asc_flag);
}
if (tc_flag != NULL) {
printf("Flag -tc is not implemented yet\n");
fclose(tc_flag);
if (tc_flag != false) {
printdebug("[-tc] Type checking is enabled.");
}
if (ir_flag != NULL) {
@ -180,8 +180,12 @@ int new_file(char *arg, char *alpha) {
type_len = TOK_LEN;
} else if (strcmp(arg, "-st") == 0) {
type_len = ST_LEN;
} else if (strcmp(arg, "-tc") == 0) {
type_len = TC_LEN;
} else if (strcmp(arg, "-asc") == 0) {
type_len = ASC_LEN;
} else if (strcmp(arg, "-ir") == 0) {
type_len = IR_LEN;
} else if (strcmp(arg, "-cg") == 0) {
type_len = CG_LEN;
} else {
fprintf(stderr, INVALID);
return -1;
@ -189,13 +193,17 @@ int new_file(char *arg, char *alpha) {
// calculate lengths
int basename_len = strlen(basename);
char *file_name =
calloc(basename_len - ALPHA_OFFSET + type_len + 2, sizeof(char));
char *file_name = calloc(basename_len - ALPHA_OFFSET + type_len + 2, sizeof(char));
// coy filename and add extension
strncpy(file_name, basename, basename_len - ALPHA_OFFSET);
strcat(file_name, ".");
strcat(file_name, arg + 1);
if (strcmp(arg, "-cg") == 0) {
strncpy(file_name, basename, basename_len - ALPHA_OFFSET);
strcat(file_name, ".s");
} else {
strncpy(file_name, basename, basename_len - ALPHA_OFFSET);
strcat(file_name, ".");
strcat(file_name, arg + 1);
}
if (strcmp(arg, "-tok") == 0) {
tok_flag = fopen(file_name, "w");
@ -203,8 +211,6 @@ int new_file(char *arg, char *alpha) {
st_flag = fopen(file_name, "w");
} else if (strcmp(arg, "-asc") == 0) {
asc_flag = fopen(file_name, "w");
} else if (strcmp(arg, "-tc") == 0) {
tc_flag = fopen(file_name, "w");
} else if (strcmp(arg, "-ir") == 0) {
ir_flag = fopen(file_name, "w");
} else if (strcmp(arg, "-cg") == 0) {