From 8f6dd273479bdc7789d40a235b0afb6598fd0435 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 5 Jun 2018 13:41:13 +0200 Subject: Handle func return --- src/tpc.y | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/tpc.y') diff --git a/src/tpc.y b/src/tpc.y index e8f2e41..3bd3df4 100644 --- a/src/tpc.y +++ b/src/tpc.y @@ -20,6 +20,7 @@ extern int lineno; int yylex(); void yyerror(char *); static Scope scope = GLOBAL; +static Type return_type = VOID; static int bss_done = 0; static int num_label = 0; static int num_if = 0; @@ -88,11 +89,11 @@ DeclFoncts: ; DeclFonct: EnTeteFonct { scope = LOCAL; } - Corps { gen_function_end_declaration(); scope = GLOBAL; } + Corps { gen_function_end_declaration(); scope = GLOBAL; return_type = VOID; } ; EnTeteFonct: - TYPE IDENT PrologueCont '(' Parametres ')' {gen_function_declaration($2, $1, $5);} -| VOID IDENT PrologueCont '(' Parametres ')' {gen_function_declaration($2, 2, $5);} + TYPE IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($2, $1, $5); } +| VOID IDENT PrologueCont '(' Parametres ')' { return_type = gen_function_declaration($2, VOID, $5); } ; PrologueCont: {gen_prologue_continue(&bss_done);}; @@ -115,8 +116,8 @@ SuiteInstr: Instr: Exp ';' | ';' -| RETURN Exp ';' -| RETURN ';' +| 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; } | READE '(' IDENT ')' ';' { gen_reade($3); } | READC '(' IDENT ')' ';' { gen_readc($3); } | PRINT '(' Exp ')' ';' { gen_print($3);} -- cgit v1.2.3