From 53e859913d6eb7141dbd1ed48f28c336f1322534 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 5 Jun 2018 14:09:01 +0200 Subject: Replacing VOID by VOID_T --- res/test_read.tpc | 9 +++------ src/generator.c | 5 ++--- src/generator.h | 2 ++ src/symbol_table.c | 2 +- src/symbol_table.h | 2 +- src/tpc.lex | 1 - src/tpc.y | 12 ++++++------ 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/res/test_read.tpc b/res/test_read.tpc index a201223..0109e4d 100644 --- a/res/test_read.tpc +++ b/res/test_read.tpc @@ -4,12 +4,9 @@ entier r1,b,s,c,r2 ; caractere letter, digit, punct; -void calcul(void) { - caractere r1; - readc(r1); - print(r1); -} entier main(void) { - calcul(); + caractere r1; + readc(r1); + print(r1); } diff --git a/src/generator.c b/src/generator.c index 3f9cc3b..d5df545 100644 --- a/src/generator.c +++ b/src/generator.c @@ -4,7 +4,6 @@ */ #include "generator.h" -#include "symbol_table.h" // ----- GLOBAL FUNCTIONS ----- @@ -107,14 +106,14 @@ void gen_function_return(Type expect, Type actual) { exit(1); } - if (actual != VOID) fprintf(output, "pop rax\n"); + if (actual != VOID_T) fprintf(output, "pop rax\n"); gen_function_end_declaration(); } int gen_function_call(const char name[], int nb_param) { Type return_type = fun_lookup(name, nb_param); fprintf(output, "call %s\n", name); - if (return_type != VOID) fprintf(output, "push rax\n"); + if (return_type != VOID_T) fprintf(output, "push rax\n"); return return_type; } diff --git a/src/generator.h b/src/generator.h index 205fc01..1f586c1 100644 --- a/src/generator.h +++ b/src/generator.h @@ -7,6 +7,7 @@ #define __GENERATOR_H__ #include +#include "symbol_table.h" typedef enum scope { GLOBAL, @@ -14,6 +15,7 @@ typedef enum scope { } Scope; extern int nb_globals; +extern int lineno; FILE *output; void gen_prologue(); diff --git a/src/symbol_table.c b/src/symbol_table.c index 3ac34fb..9d9617c 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -203,7 +203,7 @@ static char *string_of_type(int type) { return "INT"; case CHAR: return "CHAR"; - case VOID: + case VOID_T: return "VOID"; default: return "UNEXPECTED"; diff --git a/src/symbol_table.h b/src/symbol_table.h index cd14ae2..a5dba69 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -17,7 +17,7 @@ typedef enum type { INT, CHAR, - VOID + VOID_T } Type; typedef struct { diff --git a/src/tpc.lex b/src/tpc.lex index 7d907b4..bdf6bb5 100644 --- a/src/tpc.lex +++ b/src/tpc.lex @@ -7,7 +7,6 @@ #include "tpc.tab.h" #define INT 0 #define CHAR 1 -#define VOID 2 int lineno = 1; %} diff --git a/src/tpc.y b/src/tpc.y index 3bd3df4..dc6bc4f 100644 --- a/src/tpc.y +++ b/src/tpc.y @@ -20,7 +20,7 @@ extern int lineno; int yylex(); void yyerror(char *); static Scope scope = GLOBAL; -static Type return_type = VOID; +static Type return_type = VOID_T; static int bss_done = 0; static int num_label = 0; static int num_if = 0; @@ -89,11 +89,11 @@ DeclFoncts: ; DeclFonct: EnTeteFonct { scope = LOCAL; } - Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID; } + Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID_T; } ; EnTeteFonct: TYPE IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($2, $1, $5); } -| VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($2, VOID, $5); } +| VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($2, VOID_T, $5); } ; PrologueCont: {gen_prologue_continue(&bss_done);}; @@ -116,8 +116,8 @@ SuiteInstr: Instr: Exp ';' | ';' -| RETURN Exp ';' { gen_function_return(return_type, $2); scope = GLOBAL; return_type = VOID; } -| RETURN ';' { gen_function_return(return_type, VOID); scope = GLOBAL; return_type = VOID; } +| RETURN Exp ';' { gen_function_return(return_type, $2); scope = GLOBAL; return_type = VOID_T; } +| RETURN ';' { gen_function_return(return_type, VOID_T); scope = GLOBAL; return_type = VOID_T; } | READE '(' IDENT ')' ';' { gen_reade($3); } | READC '(' IDENT ')' ';' { gen_readc($3); } | PRINT '(' Exp ')' ';' { gen_print($3);} @@ -164,7 +164,7 @@ F: | LValue { $$ = gen_value($1, scope); } | NUM { $$ = gen_num($1, scope); } | CARACTERE { $$ = gen_char($1, scope); } -| IDENT '(' Arguments ')' { $$ = gen_function_call($1,$3);} +| IDENT '(' Arguments ')' { return_type = fun_lookup($1,$3);$$ = gen_function_call($1,$3); } ; LValue: IDENT { gen_check($1, scope); } -- cgit v1.2.3