2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbc_class.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-08-03 17:38:01 +02:00
|
|
|
(c) 2000-2013 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
2011-12-31 03:39:20 +01:00
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBC_CLASS_C
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gb_str.h"
|
|
|
|
#include "gb_file.h"
|
|
|
|
|
|
|
|
#include "gb_table.h"
|
|
|
|
#include "gbc_compile.h"
|
|
|
|
#include "gb_code.h"
|
|
|
|
|
|
|
|
static int _array_class[17];
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_create(CLASS **result)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
CLASS *class;
|
|
|
|
TRANS_FUNC func;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC_ZERO(&class, sizeof(CLASS));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
ARRAY_create_inc(&class->function, 256);
|
2008-08-31 02:32:21 +02:00
|
|
|
ARRAY_create(&class->event);
|
|
|
|
ARRAY_create(&class->prop);
|
|
|
|
ARRAY_create(&class->ext_func);
|
2010-05-22 20:02:34 +02:00
|
|
|
ARRAY_create_inc(&class->constant, 256);
|
2008-08-31 02:32:21 +02:00
|
|
|
ARRAY_create(&class->class);
|
2010-05-22 20:02:34 +02:00
|
|
|
ARRAY_create_inc(&class->unknown, 256);
|
|
|
|
ARRAY_create_inc(&class->stat, 256);
|
|
|
|
ARRAY_create_inc(&class->dyn, 256);
|
2008-08-31 02:32:21 +02:00
|
|
|
ARRAY_create(&class->array);
|
|
|
|
ARRAY_create(&class->structure);
|
|
|
|
ARRAY_create(&class->names);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
TABLE_create(&class->table, sizeof(CLASS_SYMBOL), TF_IGNORE_CASE);
|
|
|
|
TABLE_create(&class->string, sizeof(SYMBOL), TF_NORMAL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
CLEAR(&func);
|
2008-08-31 02:32:21 +02:00
|
|
|
TYPE_clear(&func.type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
func.index = CLASS_add_symbol(class, "@init");
|
|
|
|
CLASS_add_function(class, &func);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
func.index = CLASS_add_symbol(class, "@new");
|
|
|
|
CLASS_add_function(class, &func);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
class->name = STR_copy(FILE_set_ext(FILE_get_name(JOB->name), NULL));
|
|
|
|
class->parent = NO_SYMBOL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
memset(_array_class, 0, sizeof(_array_class));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
*result = class;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void delete_function(FUNCTION *func)
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
ARRAY_delete(&func->local);
|
|
|
|
if (func->code)
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&func->code);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (JOB->debug)
|
|
|
|
ARRAY_delete(&func->pos_line);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (func->param)
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&func->param);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void delete_event(EVENT *event)
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
if (event->param)
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&event->param);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void delete_extfunc(EXTFUNC *extfunc)
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
if (extfunc->param)
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&extfunc->param);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void delete_structure(CLASS_STRUCT *structure)
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
if (structure->field)
|
|
|
|
ARRAY_delete(&structure->field);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_delete(CLASS **class)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (*class)
|
|
|
|
{
|
|
|
|
TABLE_delete(&((*class)->table));
|
|
|
|
TABLE_delete(&((*class)->string));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count((*class)->function); i++)
|
|
|
|
delete_function(&((*class)->function[i]));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count((*class)->event); i++)
|
|
|
|
delete_event(&((*class)->event[i]));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count((*class)->ext_func); i++)
|
|
|
|
delete_extfunc(&((*class)->ext_func[i]));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count((*class)->structure); i++)
|
|
|
|
delete_structure(&((*class)->structure[i]));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count((*class)->names); i++)
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&((*class)->names[i]));
|
2008-08-31 02:32:21 +02:00
|
|
|
|
|
|
|
ARRAY_delete(&((*class)->function));
|
|
|
|
ARRAY_delete(&((*class)->event));
|
|
|
|
ARRAY_delete(&((*class)->prop));
|
|
|
|
ARRAY_delete(&((*class)->ext_func));
|
|
|
|
ARRAY_delete(&((*class)->constant));
|
|
|
|
ARRAY_delete(&((*class)->class));
|
|
|
|
ARRAY_delete(&((*class)->unknown));
|
|
|
|
ARRAY_delete(&((*class)->stat));
|
|
|
|
ARRAY_delete(&((*class)->dyn));
|
|
|
|
ARRAY_delete(&((*class)->array));
|
|
|
|
ARRAY_delete(&((*class)->structure));
|
|
|
|
ARRAY_delete(&((*class)->names));
|
|
|
|
|
|
|
|
if ((*class)->name != NULL)
|
|
|
|
STR_free((*class)->name);
|
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(class);
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
CLASS_SYMBOL *CLASS_declare(CLASS *class, int index, bool global)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
CLASS_SYMBOL *sym = CLASS_get_symbol(class, index);
|
|
|
|
|
|
|
|
if ((global && !TYPE_is_null(sym->global.type))
|
2012-09-02 02:38:34 +02:00
|
|
|
|| (!global && !TYPE_is_null(sym->local.type))) // || !TYPE_is_null(sym->global.type))))
|
2008-08-31 02:32:21 +02:00
|
|
|
{
|
|
|
|
char name[sym->symbol.len + 1];
|
|
|
|
memcpy(name, sym->symbol.name, sym->symbol.len);
|
|
|
|
name[sym->symbol.len] = 0;
|
|
|
|
THROW("'&1' already declared", name);
|
|
|
|
}
|
2012-09-04 09:29:39 +02:00
|
|
|
|
2012-09-05 01:11:11 +02:00
|
|
|
if (!global && !TYPE_is_null(sym->global.type))
|
|
|
|
{
|
|
|
|
switch (TYPE_get_kind(sym->global.type))
|
|
|
|
{
|
|
|
|
case TK_VARIABLE:
|
|
|
|
COMPILE_print(MSG_WARNING, -1, "global variable hidden by local declaration: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_FUNCTION:
|
|
|
|
COMPILE_print(MSG_WARNING, -1, "function hidden by local declaration: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_EXTERN:
|
|
|
|
COMPILE_print(MSG_WARNING, -1, "extern function hidden by local declaration: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CONST:
|
|
|
|
COMPILE_print(MSG_WARNING, -1, "constant hidden by local declaration: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-31 02:32:21 +02:00
|
|
|
|
2012-09-04 09:29:39 +02:00
|
|
|
if (global)
|
|
|
|
sym->global.line = JOB->line;
|
|
|
|
else
|
|
|
|
sym->local.line = JOB->line;
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
return sym;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-04 09:29:39 +02:00
|
|
|
void CLASS_check_unused_global(CLASS *class)
|
|
|
|
{
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
int i;
|
|
|
|
TYPE type;
|
|
|
|
|
|
|
|
for (i = 0; i < TABLE_count(class->table); i++)
|
|
|
|
{
|
|
|
|
sym = CLASS_get_symbol(class, i);
|
|
|
|
type = sym->global.type;
|
|
|
|
|
|
|
|
if (sym->global_used)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (TYPE_is_null(type) || TYPE_is_public(type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (TYPE_get_kind(type) == TK_VARIABLE)
|
|
|
|
COMPILE_print(MSG_WARNING, sym->global.line, "unused global variable: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
else if (TYPE_get_kind(type) == TK_FUNCTION)
|
|
|
|
COMPILE_print(MSG_WARNING, sym->global.line, "unused function: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
else if (TYPE_get_kind(type) == TK_EXTERN)
|
|
|
|
COMPILE_print(MSG_WARNING, sym->global.line, "unused extern function: &1", SYMBOL_get_name(&sym->symbol));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_add_function(CLASS *class, TRANS_FUNC *decl)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
FUNCTION *func;
|
|
|
|
int i;
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
PARAM *param;
|
|
|
|
int count;
|
2008-04-10 14:06:14 +02:00
|
|
|
|
|
|
|
count = ARRAY_count(class->function);
|
|
|
|
if (count >= MAX_CLASS_FUNCTION)
|
|
|
|
THROW("Too many functions");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
func = ARRAY_add_void(&class->function);
|
|
|
|
TYPE_clear(&func->type);
|
|
|
|
func->nparam = 0;
|
|
|
|
func->name = NO_SYMBOL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
ARRAY_create(&func->local);
|
|
|
|
//ARRAY_create_inc(&func->code, 512);
|
|
|
|
func->code = NULL;
|
|
|
|
func->ncode = 0;
|
|
|
|
func->ncode_max = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (JOB->debug)
|
|
|
|
ARRAY_create(&func->pos_line);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (!decl) return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
sym = CLASS_declare(class, decl->index, TRUE);
|
|
|
|
/*CLASS_add_symbol(class, JOB->table, decl->index, &sym, NULL);*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
sym->global.type = decl->type;
|
|
|
|
sym->global.value = ARRAY_count(class->function) - 1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
func->nparam = decl->nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (decl->nparam)
|
|
|
|
{
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC(&func->param, decl->nparam * sizeof(PARAM));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
for (i = 0; i < decl->nparam; i++)
|
|
|
|
func->param[i] = decl->param[i];
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
func->type = decl->type;
|
|
|
|
func->start = decl->start;
|
|
|
|
func->line = decl->line;
|
|
|
|
func->name = decl->index;
|
2013-04-29 23:27:11 +02:00
|
|
|
func->last_code = CODE_NO_POS;
|
|
|
|
func->last_code2 = CODE_NO_POS;
|
2008-08-31 02:32:21 +02:00
|
|
|
func->stack = 8; // Some stack may be needed for initialization functions
|
|
|
|
func->finally = 0;
|
|
|
|
func->catch = 0;
|
|
|
|
func->npmin = -1;
|
|
|
|
func->vararg = decl->vararg;
|
2012-05-24 14:05:21 +02:00
|
|
|
func->fast = decl->fast;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
// Function startup
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
CODE_begin_function(func);
|
|
|
|
JOB->func = func;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
// Byref check at function startup
|
|
|
|
|
|
|
|
if (decl->byref)
|
|
|
|
CODE_byref(decl->byref);
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
// Optional parameters
|
2008-02-24 17:29:02 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
for (i = 0; i < func->nparam; i++)
|
|
|
|
{
|
|
|
|
param = &func->param[i];
|
|
|
|
if (param->optional == NULL)
|
|
|
|
continue;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (func->npmin < 0)
|
|
|
|
func->npmin = i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
TRANS_init_optional(param);
|
|
|
|
CODE_pop_optional(i - func->nparam);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (func->npmin < 0)
|
|
|
|
func->npmin = func->nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_add_event(CLASS *class, TRANS_EVENT *decl)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
EVENT *event;
|
|
|
|
int i;
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = ARRAY_count(class->event);
|
|
|
|
if (count >= MAX_CLASS_EVENT)
|
|
|
|
THROW("Too many events");
|
|
|
|
|
|
|
|
event = ARRAY_add_void(&class->event);
|
|
|
|
TYPE_clear(&event->type);
|
|
|
|
event->nparam = 0;
|
|
|
|
event->name = NO_SYMBOL;
|
|
|
|
|
|
|
|
if (!decl) return;
|
|
|
|
|
|
|
|
sym = CLASS_declare(class, decl->index, TRUE);
|
|
|
|
/*CLASS_add_symbol(class, JOB->table, decl->index, &sym, NULL);*/
|
|
|
|
|
|
|
|
sym->global.type = decl->type;
|
|
|
|
sym->global.value = ARRAY_count(class->event) - 1;
|
|
|
|
|
|
|
|
event->nparam = decl->nparam;
|
|
|
|
|
|
|
|
if (event->nparam)
|
|
|
|
{
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC(&event->param, decl->nparam * sizeof(PARAM));
|
2008-08-31 02:32:21 +02:00
|
|
|
|
|
|
|
for (i = 0; i < decl->nparam; i++)
|
|
|
|
{
|
|
|
|
event->param[i].type = decl->param[i].type;
|
|
|
|
event->param[i].index = decl->param[i].index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event->type = decl->type;
|
|
|
|
event->name = decl->index;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_add_property(CLASS *class, TRANS_PROPERTY *decl)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
PROPERTY *prop;
|
|
|
|
CLASS_SYMBOL *sym;
|
2012-02-25 02:35:55 +01:00
|
|
|
int index;
|
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-25 02:35:55 +01:00
|
|
|
index = ARRAY_count(class->prop);
|
2008-08-31 02:32:21 +02:00
|
|
|
prop = ARRAY_add_void(&class->prop);
|
|
|
|
TYPE_clear(&prop->type);
|
|
|
|
prop->name = NO_SYMBOL;
|
|
|
|
prop->read = TRUE;
|
|
|
|
prop->write = decl->read == 0;
|
2012-02-25 02:35:55 +01:00
|
|
|
prop->synonymous = -1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
sym = CLASS_declare(class, decl->index, TRUE);
|
|
|
|
/*CLASS_add_symbol(class, JOB->table, decl->index, &sym, NULL);*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
sym->global.type = decl->type;
|
|
|
|
sym->global.value = ARRAY_count(class->prop) - 1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
prop->type = decl->type;
|
|
|
|
prop->name = decl->index;
|
|
|
|
prop->line = decl->line;
|
|
|
|
prop->comment = decl->comment;
|
2012-02-25 02:35:55 +01:00
|
|
|
|
|
|
|
for (i = 0; i < decl->nsynonymous; i++)
|
|
|
|
{
|
|
|
|
prop = ARRAY_add_void(&class->prop);
|
|
|
|
TYPE_clear(&prop->type);
|
|
|
|
prop->name = NO_SYMBOL;
|
|
|
|
prop->read = TRUE;
|
|
|
|
prop->write = decl->read == 0;
|
|
|
|
prop->synonymous = index;
|
|
|
|
|
|
|
|
sym = CLASS_declare(class, decl->synonymous[i], TRUE);
|
|
|
|
/*CLASS_add_symbol(class, JOB->table, decl->index, &sym, NULL);*/
|
|
|
|
|
|
|
|
sym->global.type = decl->type;
|
|
|
|
sym->global.value = ARRAY_count(class->prop) - 1;
|
|
|
|
|
|
|
|
prop->type = decl->type;
|
|
|
|
prop->name = decl->synonymous[i];
|
|
|
|
prop->line = decl->line;
|
|
|
|
prop->comment = decl->comment;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_add_extern(CLASS *class, TRANS_EXTERN *decl)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
EXTFUNC *extfunc;
|
|
|
|
int i;
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = ARRAY_count(class->ext_func);
|
|
|
|
if (count >= MAX_CLASS_EXTERN)
|
|
|
|
THROW("Too many external functions");
|
|
|
|
|
|
|
|
extfunc = ARRAY_add_void(&class->ext_func);
|
|
|
|
TYPE_clear(&extfunc->type);
|
|
|
|
extfunc->nparam = 0;
|
2012-06-01 02:18:38 +02:00
|
|
|
extfunc->vararg = FALSE;
|
2008-08-31 02:32:21 +02:00
|
|
|
extfunc->name = NO_SYMBOL;
|
|
|
|
|
|
|
|
if (!decl) return;
|
|
|
|
|
|
|
|
sym = CLASS_declare(class, decl->index, TRUE);
|
|
|
|
/*CLASS_add_symbol(class, JOB->table, decl->index, &sym, NULL);*/
|
|
|
|
|
|
|
|
sym->global.type = decl->type;
|
|
|
|
sym->global.value = ARRAY_count(class->ext_func) - 1;
|
|
|
|
|
|
|
|
extfunc->nparam = decl->nparam;
|
2012-06-01 02:18:38 +02:00
|
|
|
extfunc->vararg = decl->vararg;
|
2008-08-31 02:32:21 +02:00
|
|
|
|
|
|
|
if (extfunc->nparam)
|
|
|
|
{
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC(&extfunc->param, decl->nparam * sizeof(PARAM));
|
2008-08-31 02:32:21 +02:00
|
|
|
|
|
|
|
for (i = 0; i < decl->nparam; i++)
|
|
|
|
{
|
|
|
|
extfunc->param[i].type = decl->param[i].type;
|
|
|
|
extfunc->param[i].index = decl->param[i].index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extfunc->type = decl->type;
|
|
|
|
extfunc->name = decl->index;
|
|
|
|
extfunc->library = decl->library;
|
|
|
|
extfunc->alias = decl->alias;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
int CLASS_add_constant(CLASS *class, TRANS_DECL *decl)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
CONSTANT *desc;
|
|
|
|
int num;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
num = ARRAY_count(class->constant);
|
|
|
|
if (num >= MAX_CLASS_CONST)
|
|
|
|
THROW("Too many constants");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
desc = ARRAY_add(&class->constant);
|
|
|
|
desc->type = decl->type;
|
|
|
|
desc->index = decl->index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
desc->value = decl->value;
|
|
|
|
if (TYPE_get_id(decl->type) == T_LONG)
|
|
|
|
desc->lvalue = decl->lvalue;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
desc->line = JOB->line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
return num;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-01 01:45:47 +02:00
|
|
|
static int add_class(CLASS *class, int index, bool used, bool exported)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
int num;
|
|
|
|
CLASS_REF *desc;
|
|
|
|
CLASS_SYMBOL *sym = CLASS_get_symbol(class, index);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
num = sym->class - 1;
|
|
|
|
if (num < 0)
|
|
|
|
{
|
|
|
|
num = ARRAY_count(class->class);
|
|
|
|
if (num >= MAX_CLASS_CLASS)
|
|
|
|
THROW("Too many different classes used");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
desc = ARRAY_add_void(&class->class);
|
2008-08-31 02:32:21 +02:00
|
|
|
desc->index = index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
sym->class = num + 1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (JOB->verbose)
|
2008-09-01 01:45:47 +02:00
|
|
|
printf("Adding class %.*s %s%s\n", sym->symbol.len, sym->symbol.name, used ? "" : "Unused ", exported ? "Exported" : "");
|
|
|
|
|
|
|
|
JOB->class->class[num].exported = exported;
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-12-07 18:14:32 +01:00
|
|
|
if (used != JOB->class->class[num].used)
|
|
|
|
{
|
|
|
|
if (JOB->verbose)
|
|
|
|
printf("Switching class %.*s to %s\n", sym->symbol.len, sym->symbol.name, used ? "Used" : "Unused");
|
|
|
|
|
|
|
|
JOB->class->class[num].used = used;
|
|
|
|
}
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
return num;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-09-01 01:45:47 +02:00
|
|
|
int CLASS_add_class(CLASS *class, int index)
|
|
|
|
{
|
|
|
|
return add_class(class, index, TRUE, FALSE);
|
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
int CLASS_add_class_unused(CLASS *class, int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-09-01 01:45:47 +02:00
|
|
|
return add_class(class, index, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
int CLASS_add_class_exported(CLASS *class, int index)
|
2008-09-01 01:45:47 +02:00
|
|
|
{
|
2010-05-21 01:23:39 +02:00
|
|
|
return add_class(class, index, TRUE, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
int CLASS_add_class_exported_unused(CLASS *class, int index)
|
2008-05-13 14:52:06 +02:00
|
|
|
{
|
2010-05-21 01:23:39 +02:00
|
|
|
return add_class(class, index, FALSE, TRUE);
|
2008-05-13 14:52:06 +02:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-05-13 14:52:06 +02:00
|
|
|
bool CLASS_exist_class(CLASS *class, int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
return CLASS_get_symbol(class, index)->class > 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
static char *CLASS_add_name(CLASS *class, const char *name, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
char *ret;
|
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC(&ret, len + 1);
|
2008-08-31 02:32:21 +02:00
|
|
|
memcpy(ret, name, len);
|
|
|
|
ret[len] = 0;
|
|
|
|
|
|
|
|
*((char **)ARRAY_add(&class->names)) = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
int CLASS_get_array_class(CLASS *class, int type, int value)
|
|
|
|
{
|
|
|
|
static char *names[] = {
|
|
|
|
NULL, "Boolean[]", "Byte[]", "Short[]", "Integer[]", "Long[]", "Single[]", "Float[]",
|
2010-05-19 14:43:57 +02:00
|
|
|
"Date[]", "String[]", "String[]", "Pointer[]", "Variant[]", NULL, NULL, NULL, "Object[]"
|
2008-08-31 02:32:21 +02:00
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (value < 0)
|
|
|
|
{
|
|
|
|
if (type <= T_VOID || type > T_OBJECT)
|
2013-01-06 17:13:31 +01:00
|
|
|
ERROR_panic("Bad native array class");
|
2008-08-31 02:32:21 +02:00
|
|
|
|
|
|
|
index = _array_class[type];
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
{
|
2010-05-25 13:19:00 +02:00
|
|
|
if (!TABLE_find_symbol(class->table, names[type], strlen(names[type]), &index))
|
2008-08-31 02:32:21 +02:00
|
|
|
index = CLASS_add_symbol(class, names[type]);
|
2008-09-01 01:45:47 +02:00
|
|
|
index = CLASS_add_class_exported(class, index);
|
2008-08-31 02:32:21 +02:00
|
|
|
_array_class[type] = index;
|
|
|
|
//printf("%s -> %ld\n", name[type], index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CLASS_SYMBOL *sym = CLASS_get_symbol(class, class->class[value].index);
|
|
|
|
int len = sym->symbol.len;
|
|
|
|
char name[len + 2];
|
|
|
|
|
|
|
|
memcpy(name, sym->symbol.name, len);
|
|
|
|
memcpy(&name[len], "[]", 2);
|
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
if (!TABLE_find_symbol(class->table, name, len + 2, &index))
|
2008-08-31 02:32:21 +02:00
|
|
|
{
|
|
|
|
char *name_alloc = CLASS_add_name(class, name, len + 2);
|
2010-05-25 13:19:00 +02:00
|
|
|
TABLE_add_symbol(class->table, name_alloc, len + 2, &index);
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
2008-09-01 01:45:47 +02:00
|
|
|
|
|
|
|
if (class->class[value].exported)
|
|
|
|
index = CLASS_add_class_exported(JOB->class, index);
|
2008-08-31 02:32:21 +02:00
|
|
|
else
|
2010-05-21 01:23:39 +02:00
|
|
|
index = CLASS_add_class(JOB->class, index);
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
int CLASS_add_unknown(CLASS *class, int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
int num;
|
|
|
|
int *desc;
|
|
|
|
CLASS_SYMBOL *sym = CLASS_get_symbol(class, index);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
num = sym->unknown - 1;
|
|
|
|
if (num < 0)
|
|
|
|
{
|
|
|
|
num = ARRAY_count(class->unknown);
|
|
|
|
if (num >= MAX_CLASS_UNKNOWN)
|
|
|
|
THROW("Too many unknown symbols");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
desc = ARRAY_add(&class->unknown);
|
|
|
|
*desc = index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
sym->unknown = num + 1;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
return num;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
int CLASS_add_array(CLASS *class, TRANS_ARRAY *array)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
CLASS_ARRAY *desc;
|
|
|
|
int num;
|
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
num = ARRAY_count(class->array);
|
|
|
|
if (num >= MAX_CLASS_ARRAY)
|
|
|
|
THROW("Too many array declarations");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
desc = ARRAY_add(&class->array);
|
|
|
|
desc->type = array->type;
|
|
|
|
desc->ndim = array->ndim;
|
|
|
|
for (i = 0; i < desc->ndim; i++)
|
|
|
|
desc->dim[i] = array->dim[i];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
return num;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 23:25:37 +01:00
|
|
|
|
|
|
|
void CLASS_begin_init_function(CLASS *class, int type)
|
|
|
|
{
|
|
|
|
FUNCTION *func = &class->function[type];
|
|
|
|
CODE_begin_function(func);
|
|
|
|
JOB->func = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_add_declaration(CLASS *class, TRANS_DECL *decl)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
CLASS_SYMBOL *sym = CLASS_declare(class, decl->index, TRUE);
|
|
|
|
VARIABLE *var;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
sym->global.type = decl->type;
|
|
|
|
|
|
|
|
if (TYPE_get_kind(decl->type) == TK_CONST)
|
|
|
|
{
|
|
|
|
sym->global.value = CLASS_add_constant(class, decl);
|
|
|
|
}
|
|
|
|
else if (TYPE_is_static(decl->type))
|
|
|
|
{
|
|
|
|
count = ARRAY_count(class->stat);
|
|
|
|
if (count >= MAX_CLASS_SYMBOL)
|
|
|
|
THROW("Too many static variables");
|
|
|
|
|
|
|
|
sym->global.value = count;
|
|
|
|
var = ARRAY_add(&class->stat);
|
|
|
|
|
|
|
|
var->type = decl->type;
|
|
|
|
var->index = decl->index;
|
2010-05-25 13:19:00 +02:00
|
|
|
//var->pos = class->size_stat;
|
|
|
|
//var->size = TYPE_sizeof(var->type);
|
2008-08-31 02:32:21 +02:00
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
//class->size_stat += var->size;
|
2008-08-31 02:32:21 +02:00
|
|
|
|
2014-11-12 23:25:37 +01:00
|
|
|
CLASS_begin_init_function(class, FUNC_INIT_STATIC);
|
|
|
|
|
2012-12-22 01:23:51 +01:00
|
|
|
if (TRANS_has_init_var(decl))
|
|
|
|
{
|
|
|
|
FUNCTION_add_all_pos_line();
|
|
|
|
TRANS_init_var(decl);
|
2008-08-31 02:32:21 +02:00
|
|
|
CODE_pop_global(sym->global.value, TRUE);
|
2012-12-22 01:23:51 +01:00
|
|
|
}
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = ARRAY_count(class->dyn);
|
|
|
|
if (count >= MAX_CLASS_SYMBOL)
|
|
|
|
THROW("Too many dynamic variables");
|
|
|
|
|
|
|
|
sym->global.value = count;
|
|
|
|
var = ARRAY_add(&class->dyn);
|
|
|
|
|
|
|
|
var->type = decl->type;
|
|
|
|
var->index = decl->index;
|
2010-05-25 13:19:00 +02:00
|
|
|
//var->pos = class->size_dyn;
|
|
|
|
//var->size = TYPE_sizeof(var->type);
|
2008-08-31 02:32:21 +02:00
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
//class->size_dyn += var->size;
|
2012-12-19 22:55:16 +01:00
|
|
|
|
2014-11-12 23:25:37 +01:00
|
|
|
CLASS_begin_init_function(class, FUNC_INIT_DYNAMIC);
|
|
|
|
|
2012-12-22 01:23:51 +01:00
|
|
|
if (TRANS_has_init_var(decl))
|
|
|
|
{
|
|
|
|
FUNCTION_add_all_pos_line();
|
|
|
|
TRANS_init_var(decl);
|
2008-08-31 02:32:21 +02:00
|
|
|
CODE_pop_global(sym->global.value, FALSE);
|
2012-12-22 01:23:51 +01:00
|
|
|
}
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
#if 0
|
2007-12-30 17:41:49 +01:00
|
|
|
static void reorder_decl(CLASS *class, VARIABLE *tvar, const char *desc)
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
int count;
|
|
|
|
int pos;
|
|
|
|
VARIABLE *var;
|
|
|
|
int i, j;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* variables statiques */
|
|
|
|
|
|
|
|
count = ARRAY_count(tvar);
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
if (JOB->verbose)
|
|
|
|
printf("Reordering %s variables:", desc);
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < count; j++)
|
|
|
|
{
|
|
|
|
var = &tvar[j];
|
|
|
|
n = var->size & 3;
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0: if (n != 0) continue; else break;
|
|
|
|
case 1: if (n != 2) continue; else break;
|
|
|
|
case 2: if (n != 1 && n != 3) continue; else break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->pos = pos;
|
|
|
|
pos += var->size;
|
|
|
|
|
|
|
|
if (JOB->verbose)
|
|
|
|
printf(" %s (%d) ", TABLE_get_symbol_name(class->table, var->index), var->pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JOB->verbose)
|
|
|
|
printf("\n");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-08-31 02:32:21 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
// Don't do that! The order of variables must be kept.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_sort_declaration(CLASS *class)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
//reorder_decl(class, class->stat, "static");
|
|
|
|
//reorder_decl(class, class->dyn, "dynamic");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
int CLASS_add_symbol(CLASS *class, const char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
TABLE_add_symbol(class->table, name, strlen(name), &index);
|
2008-08-31 02:32:21 +02:00
|
|
|
return index;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-19 22:55:16 +01:00
|
|
|
void FUNCTION_add_last_pos_line(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-12-19 22:55:16 +01:00
|
|
|
int current_pos;
|
2008-08-31 02:32:21 +02:00
|
|
|
|
2012-12-22 01:23:51 +01:00
|
|
|
if (!JOB->debug || JOB->nobreak)
|
2012-12-19 22:55:16 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
current_pos = CODE_get_current_pos();
|
|
|
|
*ARRAY_add(&JOB->func->pos_line) = current_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FUNCTION_add_all_pos_line(void)
|
|
|
|
{
|
|
|
|
int line;
|
|
|
|
int current_pos;
|
|
|
|
|
2012-12-22 01:23:51 +01:00
|
|
|
if (!JOB->debug || JOB->nobreak)
|
2012-12-19 22:55:16 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
line = JOB->func->line + ARRAY_count(JOB->func->pos_line) - 1;
|
|
|
|
current_pos = CODE_get_current_pos();
|
|
|
|
|
2012-12-22 01:23:51 +01:00
|
|
|
//fprintf(stderr, "FUNCTION_add_all_pos_line: line = %d JOB->line = %d\n", line, JOB->line);
|
|
|
|
|
2012-12-19 22:55:16 +01:00
|
|
|
while (line < JOB->line)
|
2008-08-31 02:32:21 +02:00
|
|
|
{
|
2012-12-19 22:55:16 +01:00
|
|
|
*ARRAY_add(&JOB->func->pos_line) = current_pos;
|
|
|
|
line++;
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
char *FUNCTION_get_fake_name(int func)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
static char buf[6];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
snprintf(buf, sizeof(buf), "$%d", func);
|
|
|
|
return buf;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_one_property_func(CLASS *class, PROPERTY *prop, bool write)
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
char *name;
|
|
|
|
bool is_static;
|
|
|
|
FUNCTION *func;
|
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
JOB->line = prop->line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
is_static = TYPE_is_static(prop->type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
name = STR_copy(TABLE_get_symbol_name_suffix(class->table, prop->name, write ? "_Write" : "_Read"));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
if (!TABLE_find_symbol(class->table, name, strlen(name), &index))
|
2008-08-31 02:32:21 +02:00
|
|
|
THROW("&1 is not declared", name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
sym = (CLASS_SYMBOL *)TABLE_get_symbol(class->table, index);
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (TYPE_get_kind(sym->global.type) != TK_FUNCTION)
|
|
|
|
THROW("&1 is declared but is not a function", name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
func = &class->function[sym->global.value];
|
|
|
|
JOB->line = func->line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (TYPE_is_public(sym->global.type))
|
|
|
|
THROW("A property implementation cannot be public");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
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);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (write)
|
|
|
|
{
|
|
|
|
if (TYPE_get_id(func->type) != T_VOID)
|
|
|
|
goto _BAD_SIGNATURE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (func->nparam != 1 || func->npmin != 1)
|
|
|
|
goto _BAD_SIGNATURE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (!TYPE_compare(&func->param[0].type, &prop->type))
|
|
|
|
goto _BAD_SIGNATURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!TYPE_compare(&func->type, &prop->type))
|
|
|
|
goto _BAD_SIGNATURE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
if (func->nparam != 0 || func->npmin != 0)
|
|
|
|
goto _BAD_SIGNATURE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
STR_free(name);
|
2012-09-04 09:29:39 +02:00
|
|
|
sym->global_used = TRUE;
|
2008-08-31 02:32:21 +02:00
|
|
|
return sym->global.value;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
_BAD_SIGNATURE:
|
|
|
|
|
2008-08-31 02:32:21 +02:00
|
|
|
THROW("&1 declaration does not match", name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void CLASS_check_properties(CLASS *class)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
int i;
|
|
|
|
PROPERTY *prop;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count(class->prop); i++)
|
|
|
|
{
|
|
|
|
prop = &class->prop[i];
|
2012-02-25 02:35:55 +01:00
|
|
|
if (prop->synonymous >= 0)
|
|
|
|
{
|
|
|
|
prop->read = class->prop[prop->synonymous].read;
|
|
|
|
prop->write = class->prop[prop->synonymous].write;
|
|
|
|
}
|
2008-08-31 02:32:21 +02:00
|
|
|
else
|
2012-02-25 02:35:55 +01:00
|
|
|
{
|
|
|
|
prop->read = check_one_property_func(class, prop, FALSE);
|
|
|
|
if (prop->write)
|
|
|
|
prop->write = check_one_property_func(class, prop, TRUE);
|
|
|
|
else
|
|
|
|
prop->write = NO_SYMBOL;
|
|
|
|
}
|
2008-08-31 02:32:21 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|