From 33177a678ad6b8815f0a4f4ea508167edfb9e837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 15 Jan 2011 00:58:56 +0000 Subject: [PATCH] [COMPILER] * BUG: Normal arrays of structures are not supported. Display an error message instead of compiling something that crashes the interpreter. git-svn-id: svn://localhost/gambas/trunk@3454 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbc/gbc_header.c | 4 ++-- main/gbc/gbc_trans.c | 19 ++++++++++++------- main/gbc/gbc_trans.h | 2 +- main/gbx/gbx_class_load.c | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/main/gbc/gbc_header.c b/main/gbc/gbc_header.c index e528b0f04..8eba8ec8d 100644 --- a/main/gbc/gbc_header.c +++ b/main/gbc/gbc_header.c @@ -442,7 +442,7 @@ static bool header_declaration(TRANS_DECL *decl) save = JOB->current; JOB->current = look; - if (!TRANS_type((!is_const ? TT_CAN_ARRAY | TT_CAN_STATIC : 0) | TT_CAN_NEW, decl)) + if (!TRANS_type((!is_const ? TT_CAN_ARRAY | TT_CAN_EMBED : 0) | TT_CAN_NEW, decl)) { JOB->current = save; return FALSE; @@ -874,7 +874,7 @@ static bool header_structure(void) JOB->current++; CLEAR(&decl); - if (!TRANS_type(TT_CAN_ARRAY | TT_CAN_STATIC, &decl)) + if (!TRANS_type(TT_CAN_ARRAY | TT_CAN_EMBED, &decl)) THROW("Syntax error. Invalid type description of &1 field", TRANS_get_num_desc(nfield + 1)); TRANS_want_newline(); diff --git a/main/gbc/gbc_trans.c b/main/gbc/gbc_trans.c index 155961da7..083e89d30 100644 --- a/main/gbc/gbc_trans.c +++ b/main/gbc/gbc_trans.c @@ -354,10 +354,10 @@ static PATTERN *trans_embedded_array(PATTERN *look, int mode, TRANS_DECL *result TRANS_NUMBER tnum; int i; - if (!(mode & TT_CAN_STATIC)) + if (!(mode & TT_CAN_EMBED)) { if (PATTERN_is(*look, RS_LSQR)) - THROW("Static arrays are forbidden here"); + THROW("Embedded arrays are forbidden here"); return look; } @@ -444,9 +444,9 @@ static int TRANS_get_class(PATTERN pattern, bool array) return CLASS_add_class(JOB->class, index); } -static bool check_structure(int cindex) +static bool check_structure(int *cindex) { - SYMBOL *sym = TABLE_get_symbol(JOB->class->table, JOB->class->class[cindex].index); + SYMBOL *sym = TABLE_get_symbol(JOB->class->table, JOB->class->class[*cindex].index); int len = sym->len; char name[sym->len + 1]; int index; @@ -467,12 +467,15 @@ static bool check_structure(int cindex) } else { - index = cindex; + index = *cindex; is_array = FALSE; } if (JOB->class->class[index].structure) + { + *cindex = index; return is_array; + } __ERROR: @@ -520,7 +523,7 @@ bool TRANS_type(int mode, TRANS_DECL *result) } } - if ((mode & TT_CAN_STATIC) && PATTERN_is(*look, RS_STRUCT)) + if ((mode & TT_CAN_EMBED) && PATTERN_is(*look, RS_STRUCT)) { id = T_STRUCT; look++; @@ -529,7 +532,7 @@ bool TRANS_type(int mode, TRANS_DECL *result) THROW_UNEXPECTED(look); value = TRANS_get_class(*look, TRUE); - is_array = check_structure(value); + is_array = check_structure(&value); if (!is_array) { @@ -538,6 +541,8 @@ bool TRANS_type(int mode, TRANS_DECL *result) //if (result->array.ndim > 0) // THROW("Cannot mix embedded array and embedded structure"); } + else + THROW("Arrays of structure are not supported"); look++; } diff --git a/main/gbc/gbc_trans.h b/main/gbc/gbc_trans.h index c62e91a5c..dc11cc9ef 100644 --- a/main/gbc/gbc_trans.h +++ b/main/gbc/gbc_trans.h @@ -33,7 +33,7 @@ enum { TT_NOTHING = 0, TT_DO_NOT_CHECK_AS = 1, - TT_CAN_STATIC = 2, + TT_CAN_EMBED = 2, TT_CAN_ARRAY = 4, TT_CAN_NEW = 8 }; diff --git a/main/gbx/gbx_class_load.c b/main/gbx/gbx_class_load.c index 30d6cf9c2..095796dd6 100644 --- a/main/gbx/gbx_class_load.c +++ b/main/gbx/gbx_class_load.c @@ -50,7 +50,7 @@ #include "gbx_class.h" -//#define DEBUG +//#define DEBUG DEBUG //#define DEBUG_LOAD 1 //#define DEBUG_STRUCT 1 @@ -214,7 +214,7 @@ static char *get_section(char *sec_name, char **section, short *pcount, const ch #ifdef DEBUG NSection++; - fprintf(stderr, "Section #%d %s %08lX %d %d\n", NSection + 1, sec_name, (int)(current - (char *)Class->data), one, section_size); + fprintf(stderr, "Section #%d %s %08lX %d %d\n", NSection + 1, sec_name, (int)(current - (char *)Class->data), (int)size_one, (int)section_size); #endif *section += section_size + sizeof(int);