2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbc_header.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
|
|
|
|
2011-12-31 03:39:20 +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
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define _TRANS_HEADER_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 "gbc_trans.h"
|
|
|
|
#include "gbc_header.h"
|
|
|
|
|
|
|
|
/*#define DEBUG*/
|
|
|
|
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
static void check_public_private(PATTERN **look, bool *is_public)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
*is_public = JOB->is_module && JOB->public_module;
|
|
|
|
|
|
|
|
if (PATTERN_is(**look, RS_PUBLIC))
|
|
|
|
{
|
|
|
|
*is_public = TRUE;
|
|
|
|
(*look)++;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(**look, RS_PRIVATE))
|
|
|
|
{
|
|
|
|
*is_public = FALSE;
|
|
|
|
(*look)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PATTERN *jump_expression(PATTERN *look)
|
|
|
|
{
|
|
|
|
int niv = 0;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_newline(*look))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (PATTERN_is(*look, RS_LBRA) || PATTERN_is(*look, RS_LSQR))
|
|
|
|
{
|
|
|
|
niv++;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(*look, RS_RBRA) || PATTERN_is(*look, RS_RSQR))
|
|
|
|
{
|
|
|
|
if (niv > 0)
|
|
|
|
niv--;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (niv == 0)
|
|
|
|
{
|
|
|
|
if (PATTERN_is(*look, RS_COMMA))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return look;
|
2010-05-21 01:23:39 +02:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void analyze_function_desc(TRANS_FUNC *func, int flag)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
TRANS_PARAM *param;
|
|
|
|
//bool is_output;
|
|
|
|
bool is_optional = FALSE;
|
|
|
|
TRANS_DECL ttyp;
|
|
|
|
uint64_t byref_mask = 1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_identifier(*look))
|
|
|
|
THROW("Syntax error. Invalid identifier in function name");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
func->index = PATTERN_index(*look);
|
2010-05-22 20:02:34 +02:00
|
|
|
TYPE_clear(&func->type);
|
2011-11-10 02:51:49 +01:00
|
|
|
look++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (flag & HF_EVENT)
|
|
|
|
TABLE_copy_symbol_with_prefix(JOB->class->table, func->index, ':', &func->index);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
func->nparam = 0;
|
|
|
|
func->byref = 0;
|
|
|
|
func->vararg = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if ((flag & HF_VOID) && PATTERN_is_newline(*look))
|
|
|
|
{
|
|
|
|
JOB->current = ++look;
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is(*look, RS_LBRA))
|
2010-04-25 12:46:57 +02:00
|
|
|
THROW_UNEXPECTED(look);
|
2011-11-10 02:51:49 +01:00
|
|
|
look++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
param = &func->param[func->nparam];
|
2010-05-22 20:02:34 +02:00
|
|
|
CLEAR(param);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is(*look, RS_RBRA))
|
|
|
|
{
|
|
|
|
look++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (func->nparam > 0)
|
|
|
|
{
|
|
|
|
if (!PATTERN_is(*look, RS_COMMA))
|
|
|
|
THROW(E_SYNTAX_MISSING, "',' or ')'");
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
2012-06-01 02:25:45 +02:00
|
|
|
if (PATTERN_is(*look, RS_3PTS) && !(flag & HF_NO_3PTS))
|
2011-11-10 02:51:49 +01:00
|
|
|
{
|
|
|
|
look++;
|
|
|
|
if (!PATTERN_is(*look, RS_RBRA))
|
|
|
|
THROW("Syntax error. '...' must be the last argument"); //, get_num_desc(func->nparam + 1));
|
|
|
|
look++;
|
|
|
|
func->vararg = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//is_output = FALSE;
|
|
|
|
|
|
|
|
if (!(flag & HF_NO_OPT))
|
|
|
|
{
|
|
|
|
if (PATTERN_is(*look, RS_OPTIONAL))
|
|
|
|
{
|
|
|
|
look++;
|
|
|
|
is_optional = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PATTERN_is(*look, RS_AT) || PATTERN_is(*look, RS_BYREF))
|
|
|
|
{
|
|
|
|
func->byref |= byref_mask;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
2012-09-04 09:29:39 +02:00
|
|
|
if (PATTERN_is(*look, RS_LBRA))
|
|
|
|
{
|
|
|
|
param->ignore = TRUE;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_identifier(*look))
|
|
|
|
THROW("Syntax error. The &1 argument is not a valid identifier", TRANS_get_num_desc(func->nparam + 1));
|
2012-09-04 09:29:39 +02:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
param->index = PATTERN_index(*look);
|
|
|
|
look++;
|
2012-09-04 09:29:39 +02:00
|
|
|
|
|
|
|
if (param->ignore)
|
|
|
|
{
|
|
|
|
if (!PATTERN_is(*look, RS_RBRA))
|
|
|
|
THROW(E_MISSING, "')'");
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->current = look;
|
|
|
|
|
|
|
|
if (!TRANS_type(TT_NOTHING, &ttyp))
|
|
|
|
THROW("Syntax error. Invalid type description of &1 argument", TRANS_get_num_desc(func->nparam + 1));
|
|
|
|
|
|
|
|
param->type = ttyp.type;
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (is_output)
|
|
|
|
TYPE_set_flag(¶m->type, TF_OUTPUT);
|
|
|
|
*/
|
|
|
|
|
|
|
|
look = JOB->current;
|
|
|
|
|
|
|
|
if (is_optional)
|
|
|
|
{
|
|
|
|
param->optional = look;
|
|
|
|
look = jump_expression(look);
|
|
|
|
JOB->current = look;
|
|
|
|
}
|
|
|
|
|
|
|
|
func->nparam++;
|
|
|
|
byref_mask <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current = look;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void header_module_type(void)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
const char *ext;
|
2012-01-28 10:55:55 +01:00
|
|
|
const FORM_FAMILY *p;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
/*JOB->class->name = STR_copy(FILE_get_name(JOB->name));*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
ext = FILE_get_ext(JOB->name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (strcasecmp(ext, "module") == 0)
|
|
|
|
{
|
|
|
|
JOB->is_module = TRUE;
|
|
|
|
JOB->is_form = FALSE;
|
|
|
|
}
|
|
|
|
else if (strcasecmp(ext, "class") == 0)
|
|
|
|
{
|
|
|
|
JOB->is_module = FALSE;
|
|
|
|
JOB->is_form = FALSE;
|
|
|
|
}
|
|
|
|
else
|
2010-03-11 11:59:53 +01:00
|
|
|
{
|
|
|
|
p = COMP_form_families;
|
2012-01-28 10:55:55 +01:00
|
|
|
while (p->ext)
|
2010-03-11 11:59:53 +01:00
|
|
|
{
|
2012-01-28 10:55:55 +01:00
|
|
|
if (strcasecmp(ext, p->ext) == 0)
|
2010-03-11 11:59:53 +01:00
|
|
|
{
|
|
|
|
JOB->is_module = FALSE;
|
|
|
|
JOB->is_form = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2012-01-28 10:55:55 +01:00
|
|
|
if (!p->ext)
|
2010-03-11 11:59:53 +01:00
|
|
|
THROW("Unknown file extension");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->declared = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool header_event(TRANS_EVENT *event)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
//TRANS_DECL ttyp;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is(*look, RS_EVENT))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
CLEAR(event);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (JOB->is_module)
|
|
|
|
THROW("A module cannot raise events");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->current++;
|
2011-12-22 19:35:14 +01:00
|
|
|
analyze_function_desc((TRANS_FUNC *)event, HF_VOID + HF_NO_BYREF + HF_NO_3PTS + HF_NO_OPT);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
/*if (PATTERN_is(*JOB->current, RS_AS))
|
|
|
|
{
|
|
|
|
if (!TRANS_type(TT_CAN_SQUARE, &ttyp))
|
|
|
|
THROW("Syntax error in return type");
|
|
|
|
event->type = ttyp.type;
|
|
|
|
}*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
TYPE_set_kind(&event->type, TK_EVENT);
|
|
|
|
TYPE_set_flag(&event->type, TF_PUBLIC);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool header_property(TRANS_PROPERTY *prop)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
TRANS_DECL ptype;
|
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
bool is_static = FALSE;
|
|
|
|
bool is_public = TRUE;
|
|
|
|
|
|
|
|
CLEAR(prop);
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
|
|
|
if (JOB->is_module)
|
|
|
|
{
|
|
|
|
is_static = TRUE;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(*look, RS_STATIC))
|
|
|
|
{
|
|
|
|
is_static = TRUE;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* public */
|
|
|
|
|
|
|
|
if (PATTERN_is(*look, RS_PUBLIC) || PATTERN_is(*look, RS_PRIVATE))
|
|
|
|
{
|
|
|
|
is_public = PATTERN_is(*look, RS_PUBLIC);
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PATTERN_is(*look, RS_PROPERTY))
|
|
|
|
return FALSE;
|
|
|
|
look++;
|
|
|
|
JOB->current = look;
|
|
|
|
|
|
|
|
if (!is_public)
|
|
|
|
THROW("A property must be public");
|
|
|
|
|
|
|
|
/* read-only property */
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_READ))
|
|
|
|
{
|
|
|
|
prop->read = TRUE;
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prop->read = FALSE;
|
|
|
|
|
|
|
|
/* property name */
|
|
|
|
|
|
|
|
if (!PATTERN_is_identifier(*JOB->current))
|
|
|
|
THROW("Syntax error. Invalid identifier in property name");
|
|
|
|
|
|
|
|
prop->index = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
2012-02-25 02:35:55 +01:00
|
|
|
|
|
|
|
prop->nsynonymous = 0;
|
|
|
|
|
|
|
|
while (TRANS_is(RS_COMMA))
|
|
|
|
{
|
|
|
|
if (prop->nsynonymous == 3)
|
|
|
|
THROW("Too many property synonymous");
|
|
|
|
if (!PATTERN_is_identifier(*JOB->current))
|
|
|
|
THROW("Syntax error. Invalid identifier in property name");
|
|
|
|
prop->synonymous[prop->nsynonymous++] = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
|
|
|
}
|
2011-11-10 02:51:49 +01:00
|
|
|
|
|
|
|
if (!TRANS_type(TT_NOTHING, &ptype))
|
|
|
|
THROW("Syntax error. Bad property type");
|
|
|
|
|
|
|
|
prop->type = ptype.type;
|
|
|
|
prop->line = JOB->line;
|
|
|
|
|
|
|
|
TYPE_set_kind(&prop->type, TK_PROPERTY);
|
|
|
|
if (is_static)
|
|
|
|
TYPE_set_flag(&prop->type, TF_STATIC);
|
|
|
|
TYPE_set_flag(&prop->type, TF_PUBLIC);
|
|
|
|
|
|
|
|
if (PATTERN_is_string(*JOB->current))
|
|
|
|
{
|
|
|
|
prop->comment = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prop->comment = NO_SYMBOL;
|
|
|
|
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:58:55 +02:00
|
|
|
static bool header_extern(TRANS_EXTERN *trans)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
TRANS_DECL ttyp;
|
|
|
|
int index;
|
|
|
|
bool is_public;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-05 22:58:55 +02:00
|
|
|
check_public_private(&look, &is_public);
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is(*look, RS_EXTERN))
|
|
|
|
return FALSE;
|
|
|
|
look++;
|
|
|
|
|
|
|
|
CLEAR(trans);
|
|
|
|
|
|
|
|
JOB->current = look;
|
2012-06-01 02:25:45 +02:00
|
|
|
analyze_function_desc((TRANS_FUNC *)trans, HF_NO_BYREF);
|
2011-11-10 02:51:49 +01:00
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_AS))
|
|
|
|
{
|
|
|
|
if (!TRANS_type(TT_NOTHING, &ttyp))
|
|
|
|
THROW("Syntax error in return type");
|
|
|
|
trans->type = ttyp.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TRANS_is(RS_IN))
|
|
|
|
{
|
|
|
|
if (!PATTERN_is_string(*JOB->current))
|
|
|
|
THROW("Library name must be a string");
|
|
|
|
|
|
|
|
index = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (JOB->default_library == NO_SYMBOL)
|
|
|
|
THROW(E_MISSING, "IN");
|
|
|
|
|
|
|
|
index = JOB->default_library;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->library = index;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_EXEC))
|
|
|
|
{
|
|
|
|
if (!PATTERN_is_string(*JOB->current))
|
|
|
|
THROW("Alias name must be a string");
|
|
|
|
|
|
|
|
trans->alias = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trans->alias = NO_SYMBOL;
|
|
|
|
|
|
|
|
TYPE_set_kind(&trans->type, TK_EXTERN);
|
|
|
|
TYPE_set_flag(&trans->type, TF_STATIC);
|
|
|
|
if (is_public) TYPE_set_flag(&trans->type, TF_PUBLIC);
|
|
|
|
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool header_class(TRANS_DECL *decl)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!TRANS_is(RS_CLASS))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_identifier(*JOB->current))
|
|
|
|
THROW("Syntax error. CLASS needs an identifier");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
CLEAR(decl);
|
|
|
|
decl->index = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool header_declaration(TRANS_DECL *decl)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
PATTERN *save;
|
|
|
|
bool is_static = FALSE;
|
|
|
|
bool is_public = FALSE;
|
|
|
|
bool is_const = FALSE;
|
2012-03-10 15:32:37 +01:00
|
|
|
//bool has_static = FALSE;
|
2011-11-10 02:51:49 +01:00
|
|
|
|
|
|
|
/* static ! */
|
|
|
|
|
|
|
|
if (JOB->is_module)
|
|
|
|
{
|
|
|
|
is_static = TRUE;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(*look, RS_STATIC))
|
|
|
|
{
|
|
|
|
is_static = TRUE;
|
2012-03-10 15:32:37 +01:00
|
|
|
//has_static = TRUE;
|
2011-11-10 02:51:49 +01:00
|
|
|
look++;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-05 22:58:55 +02:00
|
|
|
check_public_private(&look, &is_public);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
/* const ? */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
is_const = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is(*look, RS_CONST))
|
|
|
|
{
|
2012-03-10 15:32:37 +01:00
|
|
|
//if (has_static)
|
|
|
|
// THROW("Unexpected &1", "STATIC");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
is_const = TRUE;
|
|
|
|
look++;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_identifier(*look))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
CLEAR(decl);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
decl->index = PATTERN_index(*look);
|
|
|
|
look++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
save = JOB->current;
|
|
|
|
JOB->current = look;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!TRANS_type((!is_const ? TT_CAN_ARRAY | TT_CAN_EMBED : 0) | TT_CAN_NEW, decl))
|
|
|
|
{
|
|
|
|
JOB->current = save;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (is_static) TYPE_set_flag(&decl->type, TF_STATIC);
|
|
|
|
if (is_public) TYPE_set_flag(&decl->type, TF_PUBLIC);
|
|
|
|
if (is_const)
|
|
|
|
TYPE_set_kind(&decl->type, TK_CONST);
|
|
|
|
else
|
|
|
|
TYPE_set_kind(&decl->type, TK_VARIABLE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (is_const)
|
|
|
|
{
|
|
|
|
if (!decl->init)
|
|
|
|
THROW(E_SYNTAX_MISSING, "'='");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->current = decl->init;
|
2007-12-30 17:41:49 +01:00
|
|
|
JOB->current = TRANS_get_constant_value(decl, JOB->current);
|
2011-11-10 02:51:49 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
//JOB->current = look;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-05 22:58:55 +02:00
|
|
|
static bool header_enumeration(TRANS_DECL *decl)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
PATTERN *look = JOB->current;
|
2010-05-05 22:58:55 +02:00
|
|
|
bool is_public;
|
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
check_public_private(&look, &is_public);
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is(*look, RS_ENUM))
|
|
|
|
return FALSE;
|
2010-05-05 22:58:55 +02:00
|
|
|
look++;
|
|
|
|
|
|
|
|
JOB->current = look;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2010-05-08 22:17:29 +02:00
|
|
|
TRANS_newline();
|
|
|
|
|
2010-05-05 22:58:55 +02:00
|
|
|
if (!PATTERN_is_identifier(*JOB->current))
|
|
|
|
THROW("Syntax error. Identifier expected.");
|
|
|
|
|
|
|
|
CLEAR(decl);
|
|
|
|
|
|
|
|
decl->index = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
decl->type = TYPE_make(T_INTEGER, -1, 0);
|
2010-05-05 22:58:55 +02:00
|
|
|
|
|
|
|
if (is_public) TYPE_set_flag(&decl->type, TF_PUBLIC);
|
|
|
|
TYPE_set_kind(&decl->type, TK_CONST);
|
|
|
|
|
|
|
|
if (TRANS_is(RS_EQUAL))
|
|
|
|
{
|
|
|
|
JOB->current = TRANS_get_constant_value(decl, JOB->current);
|
|
|
|
value = decl->value + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
decl->value = value;
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
CLASS_add_declaration(JOB->class, decl);
|
2010-05-05 22:58:55 +02:00
|
|
|
|
|
|
|
if (TRANS_newline())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!PATTERN_is(*JOB->current, RS_COMMA))
|
2011-11-10 02:51:49 +01:00
|
|
|
THROW_UNEXPECTED(JOB->current);
|
2010-05-05 22:58:55 +02:00
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static bool header_function(TRANS_FUNC *func)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
static HEADER_SPECIAL spec[] =
|
|
|
|
{
|
|
|
|
{ "_init", HS_PUBLIC + HS_STATIC + HS_PROCEDURE + HS_NOPARAM },
|
|
|
|
{ "_exit", HS_PUBLIC + HS_STATIC + HS_PROCEDURE + HS_NOPARAM},
|
|
|
|
{ "_new", HS_PUBLIC + HS_DYNAMIC + HS_PROCEDURE },
|
|
|
|
{ "_free", HS_PUBLIC + HS_DYNAMIC + HS_PROCEDURE + HS_NOPARAM },
|
|
|
|
{ "_call", HS_PUBLIC },
|
|
|
|
{ "_get", HS_PUBLIC + HS_FUNCTION },
|
|
|
|
{ "_put", HS_PUBLIC + HS_PROCEDURE + HS_PUT },
|
|
|
|
{ "_next", HS_PUBLIC + HS_NOPARAM },
|
|
|
|
{ "_property", HS_PUBLIC + HS_NOPARAM + HS_FUNCTION + HS_PROPERTY },
|
|
|
|
{ "_unknown", HS_PUBLIC + HS_UNKNOWN },
|
|
|
|
{ "_compare", HS_PUBLIC + HS_DYNAMIC + HS_FUNCTION + HS_COMPARE },
|
2009-07-12 23:49:13 +02:00
|
|
|
{ "_attach", HS_PUBLIC + HS_DYNAMIC + HS_PROCEDURE + HS_ATTACH },
|
2011-11-10 02:51:49 +01:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
PATTERN pat;
|
|
|
|
TRANS_DECL ttyp;
|
|
|
|
SYMBOL *sym;
|
|
|
|
HEADER_SPECIAL *hsp;
|
|
|
|
|
|
|
|
bool is_proc = FALSE;
|
|
|
|
bool is_static = FALSE;
|
|
|
|
bool is_public = FALSE;
|
2012-05-24 14:05:21 +02:00
|
|
|
bool is_fast = FALSE;
|
2011-11-10 02:51:49 +01:00
|
|
|
|
2012-05-24 14:05:21 +02:00
|
|
|
// fast ?
|
|
|
|
|
|
|
|
if (PATTERN_is(*look, RS_FAST))
|
|
|
|
{
|
|
|
|
is_fast = TRUE;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static ?
|
2011-11-10 02:51:49 +01:00
|
|
|
|
|
|
|
if (JOB->is_module)
|
|
|
|
{
|
|
|
|
is_static = TRUE;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(*look, RS_STATIC))
|
|
|
|
{
|
|
|
|
is_static = TRUE;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
2012-05-24 14:05:21 +02:00
|
|
|
// public ou static ?
|
2011-11-10 02:51:49 +01:00
|
|
|
|
|
|
|
is_public = JOB->is_module && JOB->public_module;
|
|
|
|
|
|
|
|
if (PATTERN_is(*look, RS_PUBLIC))
|
|
|
|
{
|
|
|
|
is_public = TRUE;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(*look, RS_PRIVATE))
|
|
|
|
{
|
|
|
|
is_public = FALSE;
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PATTERN_is(*look, RS_PROCEDURE) || PATTERN_is(*look, RS_SUB))
|
|
|
|
is_proc = TRUE;
|
|
|
|
else if (!PATTERN_is(*look, RS_FUNCTION))
|
|
|
|
return FALSE;
|
|
|
|
look++;
|
|
|
|
|
|
|
|
//CLEAR(func);
|
|
|
|
|
|
|
|
JOB->current = look;
|
|
|
|
analyze_function_desc(func, HF_NORMAL);
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_AS))
|
|
|
|
{
|
|
|
|
if (!TRANS_type(TT_NOTHING, &ttyp))
|
|
|
|
THROW("Syntax error. Invalid return type");
|
|
|
|
func->type = ttyp.type;
|
|
|
|
is_proc = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TYPE_set_kind(&func->type, TK_FUNCTION);
|
|
|
|
if (is_static) TYPE_set_flag(&func->type, TF_STATIC);
|
|
|
|
if (is_public) TYPE_set_flag(&func->type, TF_PUBLIC);
|
2012-05-24 14:05:21 +02:00
|
|
|
|
|
|
|
func->fast = is_fast;
|
2011-11-10 02:51:49 +01:00
|
|
|
|
|
|
|
// Check special methods
|
|
|
|
|
|
|
|
sym = TABLE_get_symbol(JOB->class->table, func->index);
|
|
|
|
|
|
|
|
if (*sym->name == '_')
|
|
|
|
{
|
|
|
|
for (hsp = spec; hsp->name; hsp++)
|
|
|
|
{
|
|
|
|
if (sym->len != strlen(hsp->name))
|
|
|
|
continue;
|
|
|
|
if (strncmp(sym->name, hsp->name, sym->len))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (hsp->flag == HS_ERROR)
|
|
|
|
THROW("The special method &1 cannot be implemented", hsp->name);
|
|
|
|
|
|
|
|
if ((hsp->flag & HS_PUBLIC) && !is_public)
|
|
|
|
THROW("The special method &1 must be public", hsp->name);
|
|
|
|
|
|
|
|
if ((hsp->flag & HS_STATIC) && !is_static)
|
|
|
|
THROW("The special method &1 must be static", hsp->name);
|
|
|
|
|
|
|
|
if ((hsp->flag & HS_DYNAMIC) && is_static)
|
|
|
|
THROW("The special method &1 cannot be static", hsp->name);
|
|
|
|
|
|
|
|
if ((hsp->flag & HS_PROCEDURE) && !is_proc)
|
|
|
|
THROW("The special method &1 cannot be a function", hsp->name);
|
|
|
|
|
|
|
|
if ((hsp->flag & HS_FUNCTION) && is_proc)
|
|
|
|
THROW("The special method &1 must be a function", hsp->name);
|
|
|
|
|
|
|
|
if ((hsp->flag & HS_NOPARAM) && func->nparam > 0)
|
|
|
|
THROW("The special method &1 takes no arguments", hsp->name);
|
|
|
|
|
|
|
|
if (hsp->flag & HS_PUT)
|
|
|
|
{
|
|
|
|
if (func->nparam < 1)
|
|
|
|
THROW("The special method &1 must take at least one argument", hsp->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hsp->flag & HS_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (func->nparam > 0 || !func->vararg)
|
|
|
|
THROW("The special method &1 must take a variable number of arguments only", hsp->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hsp->flag & HS_PROPERTY)
|
|
|
|
{
|
|
|
|
if (TYPE_get_id(func->type) != T_BOOLEAN)
|
|
|
|
THROW("The special method &1 must return a boolean", hsp->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hsp->flag & HS_COMPARE)
|
|
|
|
{
|
|
|
|
if (func->type.t.id != T_INTEGER)
|
|
|
|
THROW("The special method must return an integer");
|
2007-12-30 17:41:49 +01:00
|
|
|
if (func->nparam != 1)
|
2011-11-10 02:51:49 +01:00
|
|
|
THROW("The special method must take exactly one argument");
|
|
|
|
}
|
2009-07-12 23:49:13 +02:00
|
|
|
|
|
|
|
if (hsp->flag & HS_ATTACH)
|
|
|
|
{
|
|
|
|
if (func->nparam != 2)
|
2011-11-10 02:51:49 +01:00
|
|
|
THROW("The special method must take exactly two arguments");
|
2009-07-12 23:49:13 +02:00
|
|
|
if (func->param[0].type.t.id != T_OBJECT || func->param[1].type.t.id != T_STRING)
|
2011-11-10 02:51:49 +01:00
|
|
|
THROW("The special method signature is incorrect");
|
2009-07-12 23:49:13 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2012-05-24 14:05:21 +02:00
|
|
|
// We ignore function body
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_newline(*(JOB->current)))
|
|
|
|
THROW("Syntax error at function declaration");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
func->line = PATTERN_index(*(JOB->current)) + 1;
|
|
|
|
func->start = JOB->current + 1;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
look = JOB->current;
|
2011-11-10 02:51:49 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
pat = *look;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is_newline(pat))
|
2009-06-11 23:33:17 +02:00
|
|
|
{
|
|
|
|
JOB->line = PATTERN_index(pat) + 1;
|
2010-05-22 20:02:34 +02:00
|
|
|
pat = look[1];
|
2009-06-11 23:33:17 +02:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is(pat, RS_END))
|
|
|
|
{
|
|
|
|
if (PATTERN_is_newline(look[2]))
|
|
|
|
{
|
|
|
|
look += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (TRANS_is_end_function(is_proc, &look[2]))
|
|
|
|
{
|
|
|
|
look += 3;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-11 23:33:17 +02:00
|
|
|
else
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
if (is_proc && PATTERN_is(look[2], RS_FUNCTION))
|
2009-09-21 18:57:21 +02:00
|
|
|
THROW(E_EXPECTED, "END SUB");
|
2010-05-22 20:02:34 +02:00
|
|
|
else if (!is_proc && PATTERN_is(look[2], RS_SUB))
|
2009-09-21 18:57:21 +02:00
|
|
|
THROW(E_EXPECTED, "END FUNCTION");
|
2009-06-11 23:33:17 +02:00
|
|
|
}
|
2011-11-10 02:51:49 +01:00
|
|
|
}
|
2011-04-16 15:25:46 +02:00
|
|
|
else if (UNLIKELY(PATTERN_is_end(pat))) // || PATTERN_is_command(pat)))
|
2010-05-22 20:02:34 +02:00
|
|
|
THROW(E_MISSING, "END");
|
2009-06-11 23:33:17 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
look++;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
JOB->current = look;
|
2011-11-10 02:51:49 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool header_inherits(void)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is(*JOB->current, RS_INHERITS))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
/*{
|
|
|
|
if (!(PATTERN_is(JOB->current[0], RS_CLASS)
|
|
|
|
&& PATTERN_is(JOB->current[1], RS_INHERITS)))
|
|
|
|
return FALSE;
|
|
|
|
JOB->current++;
|
|
|
|
}*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->current++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_class(*JOB->current))
|
|
|
|
THROW("Syntax error. INHERITS needs a class name");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (JOB->class->parent != NO_SYMBOL)
|
|
|
|
THROW("Cannot inherit twice");
|
2012-11-29 12:41:42 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
index = PATTERN_index(*JOB->current);
|
2012-11-29 12:41:42 +01:00
|
|
|
|
|
|
|
if (strcasecmp(TABLE_get_symbol_name(JOB->class->table, index), JOB->class->name) == 0)
|
|
|
|
THROW("Cannot inherit itself");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->class->parent = CLASS_add_class(JOB->class, index);
|
|
|
|
/*printf("JOB->class->parent = %d\n", JOB->class->parent);*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->current++;
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool header_option(void)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is(JOB->current[0], RS_EXPORT))
|
|
|
|
{
|
|
|
|
JOB->current++;
|
|
|
|
JOB->class->exported = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (PATTERN_is(JOB->current[0], RS_OPTIONAL))
|
2011-11-10 02:51:49 +01:00
|
|
|
{
|
|
|
|
JOB->current++;
|
|
|
|
JOB->class->optional = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is(JOB->current[0], RS_CREATE))
|
|
|
|
{
|
|
|
|
JOB->current++;
|
|
|
|
|
|
|
|
if (PATTERN_is_newline(JOB->current[0]) || PATTERN_is(JOB->current[0], RS_STATIC))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->class->autocreate = TRUE;
|
|
|
|
if (PATTERN_is(JOB->current[0], RS_STATIC))
|
|
|
|
JOB->current++;
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2011-11-10 02:51:49 +01:00
|
|
|
else if (PATTERN_is(JOB->current[0], RS_PRIVATE))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->class->nocreate = TRUE;
|
|
|
|
JOB->current++;
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2011-11-10 02:51:49 +01:00
|
|
|
}
|
2012-05-23 21:26:15 +02:00
|
|
|
|
|
|
|
if (PATTERN_is(JOB->current[0], RS_FAST))
|
|
|
|
{
|
|
|
|
JOB->current++;
|
|
|
|
JOB->class->all_fast = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static bool header_library(void)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!TRANS_is(RS_LIBRARY))
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_string(*JOB->current))
|
|
|
|
THROW("Library name must be a string");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->default_library = PATTERN_index(*JOB->current);
|
|
|
|
JOB->current++;
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
static bool header_structure(void)
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
PATTERN *look = JOB->current;
|
2010-05-21 01:23:39 +02:00
|
|
|
bool is_public;
|
|
|
|
CLASS_STRUCT *structure;
|
|
|
|
VARIABLE *field;
|
|
|
|
TRANS_DECL decl;
|
|
|
|
int nfield;
|
2010-05-28 08:24:14 +02:00
|
|
|
int index;
|
2010-05-21 01:23:39 +02:00
|
|
|
|
|
|
|
check_public_private(&look, &is_public);
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is(*look, RS_STRUCT))
|
|
|
|
return FALSE;
|
|
|
|
look++;
|
2010-05-21 01:23:39 +02:00
|
|
|
JOB->current = look;
|
|
|
|
|
|
|
|
if (!is_public)
|
|
|
|
THROW("Structures must be public");
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_identifier(*JOB->current))
|
|
|
|
THROW("Syntax error. STRUCT needs an identifier");
|
2010-05-21 01:23:39 +02:00
|
|
|
|
|
|
|
structure = ARRAY_add_void(&JOB->class->structure);
|
|
|
|
ARRAY_create(&structure->field);
|
|
|
|
nfield = 0;
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
structure->index = PATTERN_index(*JOB->current);
|
|
|
|
index = CLASS_add_class_exported(JOB->class, structure->index);
|
2010-05-29 23:10:36 +02:00
|
|
|
JOB->class->class[index].structure = TRUE;
|
2010-06-05 01:48:53 +02:00
|
|
|
//fprintf(stderr, "Set structure flag to %s\n", TABLE_get_symbol_name(JOB->class->table, structure->index));
|
2010-05-28 08:24:14 +02:00
|
|
|
|
|
|
|
//TABLE_copy_symbol_with_prefix(JOB->class->table, structure->index, '.', NULL, &structure->index);
|
2010-05-21 01:23:39 +02:00
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
TRANS_want_newline();
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
if (PATTERN_is_end(*JOB->current)) // || PATTERN_is_command(*JOB->current))
|
|
|
|
THROW ("Missing END STRUCT");
|
2010-05-21 01:23:39 +02:00
|
|
|
}
|
|
|
|
while (TRANS_newline());
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_END) && PATTERN_is(JOB->current[1], RS_STRUCT))
|
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
if (nfield == 0)
|
|
|
|
THROW ("Syntax error. A structure must have one field at least.");
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
JOB->current += 2;
|
2011-11-10 02:51:49 +01:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
TRANS_want_newline();
|
2011-11-10 02:51:49 +01:00
|
|
|
break;
|
2010-05-21 01:23:39 +02:00
|
|
|
}
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (!PATTERN_is_identifier(*JOB->current))
|
|
|
|
THROW("Syntax error. The &1 field is not a valid identifier", TRANS_get_num_desc(nfield + 1));
|
2010-05-21 01:23:39 +02:00
|
|
|
|
|
|
|
field = ARRAY_add(&structure->field);
|
|
|
|
field->index = PATTERN_index(*JOB->current);
|
|
|
|
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
JOB->current++;
|
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
CLEAR(&decl);
|
2011-11-10 02:51:49 +01:00
|
|
|
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));
|
2010-05-21 01:23:39 +02:00
|
|
|
|
|
|
|
TRANS_want_newline();
|
2011-11-10 02:51:49 +01:00
|
|
|
|
2010-05-21 01:23:39 +02:00
|
|
|
field->type = decl.type;
|
|
|
|
|
|
|
|
nfield++;
|
|
|
|
}
|
|
|
|
|
|
|
|
structure->nfield = nfield;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-22 18:52:59 +02:00
|
|
|
static void check_class_header()
|
|
|
|
{
|
|
|
|
while (TRUE) //(JOB->current < JOB->end)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_end(*JOB->current))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (TRANS_newline())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (header_option())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (header_inherits())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void HEADER_do(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2011-11-10 02:51:49 +01:00
|
|
|
union {
|
|
|
|
TRANS_DECL decl;
|
|
|
|
TRANS_FUNC func;
|
|
|
|
TRANS_EVENT event;
|
|
|
|
TRANS_EXTERN ext;
|
|
|
|
TRANS_PROPERTY prop;
|
|
|
|
} trans;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
TRANS_reset();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
header_module_type();
|
2011-04-22 18:52:59 +02:00
|
|
|
|
|
|
|
if (JOB->line == 1)
|
|
|
|
check_class_header();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
while (TRUE) //JOB->current < JOB->end)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_end(*JOB->current))
|
|
|
|
break;
|
2010-05-21 01:23:39 +02:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (TRANS_newline())
|
2011-04-22 18:52:59 +02:00
|
|
|
{
|
|
|
|
if (JOB->line == 1)
|
|
|
|
check_class_header();
|
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
continue;
|
2011-04-22 18:52:59 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (header_function(&trans.func))
|
|
|
|
{
|
|
|
|
CLASS_add_function(JOB->class, &trans.func);
|
2010-05-05 22:58:55 +02:00
|
|
|
continue;
|
2011-11-10 02:51:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (header_event(&trans.event))
|
|
|
|
{
|
|
|
|
CLASS_add_event(JOB->class, &trans.event);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header_property(&trans.prop))
|
|
|
|
{
|
|
|
|
CLASS_add_property(JOB->class, &trans.prop);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header_extern(&trans.ext))
|
|
|
|
{
|
|
|
|
CLASS_add_extern(JOB->class, &trans.ext);
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-21 01:23:39 +02:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (header_enumeration(&trans.decl))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (header_declaration(&trans.decl))
|
|
|
|
{
|
|
|
|
CLASS_add_declaration(JOB->class, &trans.decl);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header_structure())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (header_class(&trans.decl))
|
|
|
|
{
|
|
|
|
CLASS_add_class_exported(JOB->class, trans.decl.index);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header_inherits())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (header_library())
|
|
|
|
continue;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-04-16 15:25:46 +02:00
|
|
|
/*if (PATTERN_is_command(*JOB->current))
|
2008-02-14 12:59:36 +01:00
|
|
|
{
|
|
|
|
JOB->current++;
|
|
|
|
continue;
|
2011-04-16 15:25:46 +02:00
|
|
|
}*/
|
2008-02-14 12:59:36 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
THROW_UNEXPECTED(JOB->current);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-04-25 12:46:57 +02:00
|
|
|
// Sort class declaration to avoid alignment problems.
|
|
|
|
// This should be useless now, as it is done again by the interpreter
|
|
|
|
// when loading the class.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
CLASS_sort_declaration(JOB->class);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-11-10 02:51:49 +01:00
|
|
|
if (JOB->verbose)
|
|
|
|
CLASS_dump();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|