[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
This commit is contained in:
Benoît Minisini 2012-03-02 22:05:55 +00:00
parent f3a762060f
commit 092b3abfa3
6 changed files with 32 additions and 19 deletions

View file

@ -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 */

View file

@ -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)
{

View file

@ -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);

View file

@ -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)
{

View file

@ -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();

View file

@ -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();