From 092b3abfa381f024f2ee9a55f9ce2c0822c43d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 2 Mar 2012 22:05:55 +0000 Subject: [PATCH] [COMPILER] * NEW: Raise an error now when using TRY with GOTO, BREAK, CONTINUE or STOP. git-svn-id: svn://localhost/gambas/trunk@4523 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbc/gbc_compile.h | 2 +- main/gbc/gbc_trans.c | 1 + main/gbc/gbc_trans.h | 3 ++- main/gbc/gbc_trans_code.c | 8 ++++++++ main/gbc/gbc_trans_ctrl.c | 28 ++++++++++++++++++++-------- main/gbc/gbc_trans_subr.c | 9 --------- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/main/gbc/gbc_compile.h b/main/gbc/gbc_compile.h index 2ef0253e8..bad7fe0a9 100644 --- a/main/gbc/gbc_compile.h +++ b/main/gbc/gbc_compile.h @@ -57,7 +57,7 @@ typedef unsigned public_module : 1; /* modules symbols are public by default */ unsigned trans_error : 1; /* display error messages in a translatable form */ unsigned no_old_read_syntax : 1; /* do not compile the old read syntax */ - unsigned column : 1; /* search column when there is an error */ + unsigned column : 1; /* search column where there is an error */ unsigned _reserved : 18; /* reserved*/ char *output; /* output file */ PATTERN *pattern; /* lexical analyze */ diff --git a/main/gbc/gbc_trans.c b/main/gbc/gbc_trans.c index 887d5c10f..bb45e3c55 100644 --- a/main/gbc/gbc_trans.c +++ b/main/gbc/gbc_trans.c @@ -44,6 +44,7 @@ #define IS_PURE_INTEGER(_int64_val) ((_int64_val) == ((int)(_int64_val))) int TRANS_in_affectation = 0; +bool TRANS_in_try = FALSE; void TRANS_reset(void) { diff --git a/main/gbc/gbc_trans.h b/main/gbc/gbc_trans.h index 108342d83..39333441d 100644 --- a/main/gbc/gbc_trans.h +++ b/main/gbc/gbc_trans.h @@ -115,6 +115,7 @@ enum { #ifndef __GBC_TRANS_C EXTERN int TRANS_in_affectation; +EXTERN bool TRANS_in_try; //EXTERN int TRANS_in_expression; #endif @@ -190,6 +191,7 @@ void TRANS_with(void); void TRANS_use_with(void); void TRANS_end_with(void); void TRANS_raise(void); +void TRANS_stop(void); /* trans_subr.c */ @@ -209,7 +211,6 @@ void TRANS_unlock(void); void TRANS_seek(void); void TRANS_line_input(void); void TRANS_flush(void); -void TRANS_stop(void); void TRANS_quit(void); void TRANS_exec(void); void TRANS_shell(void); diff --git a/main/gbc/gbc_trans_code.c b/main/gbc/gbc_trans_code.c index f193133a0..32314130a 100644 --- a/main/gbc/gbc_trans_code.c +++ b/main/gbc/gbc_trans_code.c @@ -150,6 +150,14 @@ static bool TRANS_local(void) return TRUE; } +void TRANS_stop(void) +{ + if (TRANS_is(RS_EVENT)) + CODE_stop_event(); + else + CODE_stop(); +} + void TRANS_statement(void) { diff --git a/main/gbc/gbc_trans_ctrl.c b/main/gbc/gbc_trans_ctrl.c index 39c77653e..fe171d3d3 100644 --- a/main/gbc/gbc_trans_ctrl.c +++ b/main/gbc/gbc_trans_ctrl.c @@ -274,6 +274,17 @@ static void control_check_loop_var(short var) current_ctrl->loop_var = var; } +static void check_try(const char *name) +{ + if (TRANS_in_try) + { + TRANS_in_try = FALSE; + if (name) + THROW("Cannot use TRY with &1", name); + else + THROW("Cannot use TRY twice"); + } +} void TRANS_control_init() { @@ -557,6 +568,8 @@ void TRANS_goto() { int index; + check_try("GOTO"); + if (!PATTERN_is_identifier(*JOB->current)) THROW(E_SYNTAX); @@ -793,6 +806,8 @@ void TRANS_break(void) { TRANS_CTRL *ctrl_inner = control_get_inner(); + check_try("BREAK"); + if (!ctrl_inner) THROW(E_UNEXPECTED, "BREAK"); @@ -805,6 +820,8 @@ void TRANS_continue(void) { TRANS_CTRL *ctrl_inner = control_get_inner(); + check_try("CONTINUE"); + if (!ctrl_inner) THROW(E_UNEXPECTED, "CONTINUE"); @@ -984,21 +1001,16 @@ void TRANS_next(void) void TRANS_try(void) { - static int no_try = 0; ushort pos; - if (no_try) - { - no_try = 0; - THROW("Cannot use TRY twice"); - } + check_try(NULL); pos = CODE_get_current_pos(); CODE_try(); - no_try++; + TRANS_in_try = TRUE; TRANS_statement(); - no_try--; + TRANS_in_try = FALSE; CODE_jump_length(pos, CODE_get_current_pos()); CODE_end_try(); diff --git a/main/gbc/gbc_trans_subr.c b/main/gbc/gbc_trans_subr.c index e31e69af7..be6f6d27d 100644 --- a/main/gbc/gbc_trans_subr.c +++ b/main/gbc/gbc_trans_subr.c @@ -591,15 +591,6 @@ void TRANS_flush(void) } -void TRANS_stop(void) -{ - if (TRANS_is(RS_EVENT)) - CODE_stop_event(); - else - CODE_stop(); -} - - void TRANS_quit(void) { CODE_quit();