[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
This commit is contained in:
Benoît Minisini 2011-01-15 00:58:56 +00:00
parent 7998ec6dc3
commit 33177a678a
4 changed files with 17 additions and 12 deletions

View file

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

View file

@ -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++;
}

View file

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

View file

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