Commit 51a9a103 authored by Benoît Minisini's avatar Benoît Minisini

Fix crash when using the new PROPERTY ... USE syntax.

[COMPILER]
* BUG: Fix crash when using the new PROPERTY ... USE syntax.
parent d3fdd6fd
......@@ -252,7 +252,7 @@ void CLASS_check_unused_global(CLASS *class)
}
void CLASS_add_function(CLASS *class, TRANS_FUNC *decl)
int CLASS_add_function(CLASS *class, TRANS_FUNC *decl)
{
FUNCTION *func;
int i;
......@@ -278,13 +278,14 @@ void CLASS_add_function(CLASS *class, TRANS_FUNC *decl)
if (JOB->debug)
ARRAY_create(&func->pos_line);
if (!decl) return;
sym = CLASS_declare(class, decl->index, TK_FUNCTION, TRUE);
/*CLASS_add_symbol(class, JOB->table, decl->index, &sym, NULL);*/
if (!decl) return count;
sym->global.type = decl->type;
sym->global.value = ARRAY_count(class->function) - 1;
if (decl->index != NO_SYMBOL)
{
sym = CLASS_declare(class, decl->index, TK_FUNCTION, TRUE);
sym->global.type = decl->type;
sym->global.value = count;
}
if (TYPE_is_static(decl->type))
class->has_static = TRUE;
......@@ -340,6 +341,8 @@ void CLASS_add_function(CLASS *class, TRANS_FUNC *decl)
if (func->npmin < 0)
func->npmin = func->nparam;
return count;
}
......@@ -883,6 +886,7 @@ static int check_one_property_func(CLASS *class, PROPERTY *prop, bool write)
bool is_static;
FUNCTION *func;
int index;
int value;
JOB->line = prop->line;
JOB->current = NULL;
......@@ -899,7 +903,7 @@ static int check_one_property_func(CLASS *class, PROPERTY *prop, bool write)
THROW("&1 is not declared", name);
CLEAR(&decl);
decl.index = index = CLASS_add_symbol(class, name);
decl.index = index = NO_SYMBOL; //index = CLASS_add_symbol(class, name);
if (write)
{
......@@ -919,7 +923,7 @@ static int check_one_property_func(CLASS *class, PROPERTY *prop, bool write)
if (is_static)
TYPE_set_flag(&decl.type, TF_STATIC);
CLASS_add_function(JOB->class, &decl);
value = CLASS_add_function(JOB->class, &decl);
JOB->nobreak = TRUE;
sym = CLASS_get_symbol(JOB->class, prop->use);
......@@ -937,52 +941,57 @@ static int check_one_property_func(CLASS *class, PROPERTY *prop, bool write)
CODE_push_global(sym->global.value, is_static, FALSE);
CODE_return(1);
}
FUNCTION_add_last_pos_line();
JOB->func->stack = CODE_stack_usage;
}
sym = (CLASS_SYMBOL *)TABLE_get_symbol(class->table, index);
if (TYPE_get_kind(sym->global.type) != TK_FUNCTION)
THROW("&1 is declared but is not a function", name);
if (index != NO_SYMBOL)
{
sym = (CLASS_SYMBOL *)TABLE_get_symbol(class->table, index);
if (TYPE_get_kind(sym->global.type) != TK_FUNCTION)
THROW("&1 is declared but is not a function", name);
func = &class->function[sym->global.value];
JOB->line = func->line;
func = &class->function[sym->global.value];
JOB->line = func->line;
if (TYPE_is_public(sym->global.type))
THROW("A property implementation cannot be public");
if (TYPE_is_public(sym->global.type))
THROW("A property implementation cannot be public");
if (is_static != TYPE_is_static(sym->global.type))
{
if (is_static)
THROW("&1 must be static", name);
else
THROW("&1 cannot be static", name);
}
if (is_static != TYPE_is_static(sym->global.type))
{
if (is_static)
THROW("&1 must be static", name);
else
THROW("&1 cannot be static", name);
}
if (write)
{
if (TYPE_get_id(func->type) != T_VOID)
goto _BAD_SIGNATURE;
if (write)
{
if (TYPE_get_id(func->type) != T_VOID)
goto _BAD_SIGNATURE;
if (func->nparam != 1 || func->npmin != 1)
goto _BAD_SIGNATURE;
if (func->nparam != 1 || func->npmin != 1)
goto _BAD_SIGNATURE;
if (!TYPE_compare(&func->param[0].type, &prop->type))
goto _BAD_SIGNATURE;
}
else
{
if (!TYPE_compare(&func->type, &prop->type))
goto _BAD_SIGNATURE;
if (!TYPE_compare(&func->param[0].type, &prop->type))
goto _BAD_SIGNATURE;
}
else
{
if (!TYPE_compare(&func->type, &prop->type))
goto _BAD_SIGNATURE;
if (func->nparam != 0 || func->npmin != 0)
goto _BAD_SIGNATURE;
if (func->nparam != 0 || func->npmin != 0)
goto _BAD_SIGNATURE;
}
sym->global_used = TRUE;
}
STR_free(name);
sym->global_used = TRUE;
return sym->global.value;
return value;
_BAD_SIGNATURE:
......
......@@ -239,7 +239,7 @@ CLASS_SYMBOL *CLASS_declare(CLASS *class, int index, int type, bool global);
void CLASS_check_unused_global(CLASS *class);
void CLASS_begin_init_function(CLASS *class, int type);
void CLASS_add_function(CLASS *class, TRANS_FUNC *decl);
int CLASS_add_function(CLASS *class, TRANS_FUNC *decl);
void CLASS_add_event(CLASS *class, TRANS_EVENT *decl);
void CLASS_add_property(CLASS *class, TRANS_PROPERTY *prop);
void CLASS_add_extern(CLASS *class, TRANS_EXTERN *decl);
......
......@@ -292,7 +292,7 @@ static bool header_event(TRANS_EVENT *event)
static bool header_property(TRANS_PROPERTY *prop)
{
TRANS_DECL ptype;
TRANS_DECL ptype = { 0 };
PATTERN *look = JOB->current;
bool is_static = FALSE;
bool is_public = TRUE;
......
......@@ -68,6 +68,21 @@ static char *_pbuffer;
static OUTPUT_CHANGE *_change = NULL;
static const char *get_symbol_name(TABLE *table, int index, int *len)
{
if (UNLIKELY((index < 0) || (index >= ARRAY_count(table->symbol))))
{
*len = 1;
return "?";
}
else
{
SYMBOL *sym = TABLE_get_symbol(table, index);
*len = sym->len;
return sym->name;
}
}
static void output_init(void)
{
TABLE_create(&StringTable, sizeof(OUTPUT_SYMBOL), TF_NORMAL);
......@@ -999,13 +1014,13 @@ static void output_debug_global()
static void output_debug_method()
{
int i, j, n;
SYMBOL *sym;
OUTPUT_SYMBOL *osym;
CLASS_SYMBOL *csym;
PARAM *param;
FUNCTION *func;
TABLE *table;
int index;
const char *name;
int len;
begin_section("Debug method info", 5 * sizeof(int));
......@@ -1021,8 +1036,8 @@ static void output_debug_method()
/* pos_line */
write_int(0);
/* nom */
sym = TABLE_get_symbol(Class->table, func->name);
write_int(get_string(sym->name, sym->len));
name = get_symbol_name(Class->table, func->name, &len);
write_int(get_string(name, len));
/* local symbols */
write_int(0);
/* n_local */
......@@ -1071,7 +1086,7 @@ static void output_debug_method()
if (func->name != NO_SYMBOL)
{
sym = (SYMBOL *)TABLE_get_symbol(Class->table, func->name);
/*sym = (SYMBOL *)TABLE_get_symbol(Class->table, func->name);*/
/*printf("%.*s()\n", sym->len, sym->name);*/
TABLE_create(&table, sizeof(OUTPUT_SYMBOL), TF_IGNORE_CASE);
......@@ -1079,9 +1094,9 @@ static void output_debug_method()
for (j = 0; j < func->nlocal + func->nparam; j++)
{
param = &func->local[j];
csym = (CLASS_SYMBOL *)TABLE_get_symbol(Class->table, param->index);
index = TABLE_add_symbol(table, csym->symbol.name, csym->symbol.len);
name = get_symbol_name(Class->table, param->index, &len);
index = TABLE_add_symbol(table, name, len);
osym = (OUTPUT_SYMBOL *)TABLE_get_symbol(table, index);
osym->value = param->value;/*TYPE_long(param->type);*/
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment