2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbc_trans_expr.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-02-12 02:53:46 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
|
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_EXPR_C
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbc_compile.h"
|
|
|
|
|
|
|
|
#include "gbc_trans.h"
|
|
|
|
#include "gb_code.h"
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
//#define DEBUG 1
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//static bool _accept_statement = FALSE;
|
|
|
|
|
2019-05-08 06:13:04 +02:00
|
|
|
static int *_tree_pos = NULL;
|
|
|
|
static int _tree_length = 0;
|
|
|
|
static int _tree_index = 0;
|
|
|
|
static int _tree_line;
|
|
|
|
|
2014-05-05 22:16:41 +02:00
|
|
|
static bool _must_drop_vargs = FALSE;
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
static TYPE _type[MAX_EXPR_LEVEL];
|
|
|
|
static int _type_level = 0;
|
2016-09-04 01:45:59 +02:00
|
|
|
static TYPE _last_type;
|
|
|
|
|
2018-02-14 17:03:14 +01:00
|
|
|
static CLASS_SYMBOL *_last_symbol_used = NULL;
|
|
|
|
static bool _last_symbol_global = FALSE;
|
|
|
|
|
2016-09-04 01:45:59 +02:00
|
|
|
static void trans_expression(bool check_statement);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
static void _push_type(TYPE type)
|
|
|
|
{
|
|
|
|
if (_type_level >= MAX_EXPR_LEVEL) // should have been detected by TRANS_tree()
|
|
|
|
THROW("Expression too complex");
|
|
|
|
|
2016-09-04 01:45:59 +02:00
|
|
|
fprintf(stderr, "level = %d / %d\n", _type_level, MAX_EXPR_LEVEL);
|
2016-03-14 02:40:50 +01:00
|
|
|
_type[_type_level++] = type;
|
|
|
|
}
|
|
|
|
|
2016-09-04 01:45:59 +02:00
|
|
|
static void _drop_type(int n)
|
|
|
|
{
|
|
|
|
_type_level -= n;
|
|
|
|
if (_type_level < 0)
|
|
|
|
ERROR_panic("Incorrect type analyze");
|
|
|
|
}
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
#define push_type(_type) fprintf(stderr, "push_type: %d in %s.%d\n", (_type).t.id, __func__, __LINE__), _push_type(_type)
|
2016-03-20 02:27:31 +01:00
|
|
|
#define push_type_id(_id) fprintf(stderr, "push_type_id: %d in %s.%d\n", (_id), __func__, __LINE__), _push_type(TYPE_make_simple(_id))
|
2016-09-04 01:45:59 +02:00
|
|
|
#define pop_type() (fprintf(stderr, "pop_type: in %s.%d\n", __func__, __LINE__),(_type[--_type_level]))
|
|
|
|
#define drop_type(_n) fprintf(stderr, "drop_type: %d in %s.%d\n", (_n), __func__, __LINE__),_drop_type(_n)
|
2018-03-03 03:14:11 +01:00
|
|
|
#define get_type_id(_i, _nparam) (fprintf(stderr, "get_type(%d,%d): %d in %s.%d\n", (_i), (_nparam), (_type[_type_level + (_i) - (_nparam)].t.id), __func__, __LINE__),(_type[_type_level + (_i) - (_nparam)].t.id))
|
2016-09-04 01:45:59 +02:00
|
|
|
#define dup_type() fprintf(stderr, "dup_type: in %s.%d\n", __func__, __LINE__),push_type(_type[_type_level - 1])
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static void push_type(TYPE type)
|
|
|
|
{
|
|
|
|
if (_type_level >= MAX_EXPR_LEVEL) // should have been detected by TRANS_tree()
|
|
|
|
THROW("Expression too complex");
|
|
|
|
|
|
|
|
_type[_type_level++] = type;
|
|
|
|
}
|
|
|
|
|
2016-09-04 01:45:59 +02:00
|
|
|
static void drop_type(int n)
|
|
|
|
{
|
|
|
|
_type_level -= n;
|
|
|
|
if (_type_level < 0)
|
|
|
|
ERROR_panic("Incorrect type analyze");
|
|
|
|
}
|
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
#define push_type_id(_id) push_type(TYPE_make_simple(_id))
|
2016-03-14 02:40:50 +01:00
|
|
|
#define pop_type() (_type[--_type_level])
|
2018-03-03 03:14:11 +01:00
|
|
|
#define get_type(_i, _nparam) (_type[_type_level + (_i) - (_nparam)])
|
|
|
|
#define get_type_id(_i, _nparam) (get_type(_i, _nparam).t.id)
|
2016-09-04 01:45:59 +02:00
|
|
|
#define dup_type() push_type(_type[_type_level - 1])
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-05-29 02:11:55 +02:00
|
|
|
static short get_nparam(PATTERN *tree, int count, int *pindex, uint64_t *byref)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
PATTERN pattern;
|
|
|
|
int nparam = 0;
|
2010-05-29 02:11:55 +02:00
|
|
|
int index = *pindex;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (index < count)
|
|
|
|
{
|
|
|
|
pattern = tree[index + 1];
|
|
|
|
if (PATTERN_is_param(pattern))
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
nparam = PATTERN_index(pattern);
|
|
|
|
}
|
2008-01-19 18:52:05 +01:00
|
|
|
|
|
|
|
if (byref)
|
|
|
|
{
|
2010-05-29 02:11:55 +02:00
|
|
|
int shift = 0;
|
|
|
|
*byref = 0;
|
|
|
|
while (index < count)
|
2008-01-19 18:52:05 +01:00
|
|
|
{
|
2010-05-29 02:11:55 +02:00
|
|
|
pattern = tree[index + 1];
|
|
|
|
if (!PATTERN_is_param(pattern))
|
|
|
|
break;
|
|
|
|
index++;
|
2008-01-19 18:52:05 +01:00
|
|
|
*byref |= (uint64_t)PATTERN_index(pattern) << shift;
|
|
|
|
shift += 16;
|
|
|
|
}
|
|
|
|
}
|
2010-05-29 02:11:55 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (index < count)
|
|
|
|
{
|
|
|
|
pattern = tree[index + 1];
|
|
|
|
if (!PATTERN_is_param(pattern))
|
|
|
|
break;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2010-05-29 02:11:55 +02:00
|
|
|
*pindex = index;
|
2008-01-19 18:52:05 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
/*
|
|
|
|
Gère le cas où on a codé un subr sans mettre de parenthèses
|
|
|
|
=> nparam = 0
|
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
return (short)nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
static void push_number(int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_NUMBER number;
|
|
|
|
TRANS_DECL decl;
|
|
|
|
|
|
|
|
if (TRANS_get_number(index, &number))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
|
|
|
|
if (number.type == T_INTEGER)
|
|
|
|
{
|
|
|
|
CODE_push_number(number.ival);
|
|
|
|
}
|
2012-07-09 01:23:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CLEAR(&decl);
|
2016-03-20 02:27:31 +01:00
|
|
|
decl.type = TYPE_make_simple(number.type);
|
2012-07-09 01:23:24 +02:00
|
|
|
decl.index = NO_SYMBOL;
|
|
|
|
decl.value = index;
|
|
|
|
if (number.type == T_LONG)
|
|
|
|
decl.lvalue = number.lval;
|
|
|
|
CODE_push_const(CLASS_add_constant(JOB->class, &decl));
|
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2012-07-09 01:23:24 +02:00
|
|
|
if (number.complex)
|
2016-03-14 02:40:50 +01:00
|
|
|
{
|
2012-07-09 01:23:24 +02:00
|
|
|
CODE_push_complex();
|
2016-03-14 02:40:50 +01:00
|
|
|
push_type_id(T_OBJECT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
push_type_id(number.type);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
static void push_string(int index, bool trans)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_DECL decl;
|
|
|
|
SYMBOL *sym;
|
|
|
|
int len;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-08-31 15:58:53 +02:00
|
|
|
if (index == VOID_STRING_INDEX)
|
2010-05-25 13:19:00 +02:00
|
|
|
len = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sym = TABLE_get_symbol(JOB->class->string, index);
|
|
|
|
len = sym->len;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
CODE_push_void_string();
|
|
|
|
}
|
|
|
|
else if (len == 1 && !trans)
|
|
|
|
{
|
|
|
|
CODE_push_char(*(sym->name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//CLEAR(&decl);
|
|
|
|
|
|
|
|
if (trans)
|
2016-03-20 02:27:31 +01:00
|
|
|
decl.type = TYPE_make_simple(T_CSTRING);
|
2010-12-29 09:21:51 +01:00
|
|
|
else
|
2016-03-20 02:27:31 +01:00
|
|
|
decl.type = TYPE_make_simple(T_STRING);
|
2010-12-29 09:21:51 +01:00
|
|
|
decl.index = NO_SYMBOL;
|
|
|
|
decl.value = index;
|
|
|
|
|
|
|
|
CODE_push_const(CLASS_add_constant(JOB->class, &decl));
|
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
push_type_id(T_STRING);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 23:25:37 +01:00
|
|
|
bool TRANS_string(PATTERN pattern)
|
|
|
|
{
|
|
|
|
if (!PATTERN_is_string(pattern))
|
|
|
|
return TRUE;
|
|
|
|
push_string(PATTERN_index(pattern), FALSE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
static void trans_class(int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
const char *name;
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
if (!CLASS_exist_class(JOB->class, index))
|
2010-12-29 09:21:51 +01:00
|
|
|
{
|
|
|
|
name = TABLE_get_symbol_name(JOB->class->table, index);
|
|
|
|
THROW("Unknown identifier: &1", name);
|
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
CODE_push_class(CLASS_add_class(JOB->class, index));
|
|
|
|
push_type_id(T_OBJECT);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:16:17 +02:00
|
|
|
static void trans_identifier(int index, bool point, PATTERN next)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
CLASS_SYMBOL *sym = CLASS_get_symbol(JOB->class, index);
|
|
|
|
bool is_static;
|
|
|
|
bool is_func;
|
|
|
|
int type;
|
|
|
|
CONSTANT *constant;
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
#if DEBUG
|
|
|
|
fprintf(stderr, "trans_identifier: %.*s\n", sym->symbol.len, sym->symbol.name);
|
|
|
|
#endif
|
|
|
|
|
2018-02-14 17:03:14 +01:00
|
|
|
_last_symbol_used = NULL;
|
|
|
|
//fprintf(stderr, "_last_symbol_used = NULL\n");
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (!TYPE_is_null(sym->local.type) && !point)
|
|
|
|
{
|
2021-06-01 23:12:55 +02:00
|
|
|
if (TYPE_is_static(sym->local.type))
|
|
|
|
CODE_push_global(sym->global.value, TRUE, FALSE);
|
|
|
|
else
|
|
|
|
CODE_push_local(sym->local.value);
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
push_type(sym->local.type);
|
2012-09-04 09:29:39 +02:00
|
|
|
sym->local_used = TRUE;
|
2018-02-14 17:03:14 +01:00
|
|
|
_last_symbol_used = sym;
|
|
|
|
_last_symbol_global = FALSE;
|
|
|
|
//fprintf(stderr, "_last_symbol_used = %.*s / local\n", sym->symbol.len, sym->symbol.name);
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
else if (!TYPE_is_null(sym->global.type) && !point)
|
|
|
|
{
|
|
|
|
type = TYPE_get_kind(sym->global.type);
|
2012-09-04 09:29:39 +02:00
|
|
|
if (!TYPE_is_public(sym->global.type))
|
2018-02-14 17:03:14 +01:00
|
|
|
{
|
2012-09-04 09:29:39 +02:00
|
|
|
sym->global_used = TRUE;
|
2018-02-14 17:03:14 +01:00
|
|
|
_last_symbol_used = sym;
|
|
|
|
_last_symbol_global = TRUE;
|
|
|
|
//fprintf(stderr, "_last_symbol_used = %.*s / global\n", sym->symbol.len, sym->symbol.name);
|
|
|
|
}
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (type == TK_CONST)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_point(next))
|
|
|
|
goto __CLASS;
|
|
|
|
|
|
|
|
constant = &JOB->class->constant[sym->global.value];
|
|
|
|
type = TYPE_get_id(constant->type);
|
2009-10-05 01:32:14 +02:00
|
|
|
if (type == T_BOOLEAN)
|
|
|
|
CODE_push_boolean(constant->value);
|
|
|
|
else if (type == T_INTEGER)
|
2010-12-29 09:21:51 +01:00
|
|
|
CODE_push_number(constant->value);
|
|
|
|
else
|
|
|
|
CODE_push_const(sym->global.value);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
push_type_id(type);
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
else if (type == TK_EXTERN)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_point(next))
|
|
|
|
goto __CLASS;
|
|
|
|
|
|
|
|
CODE_push_extern(sym->global.value);
|
2016-03-14 02:40:50 +01:00
|
|
|
push_type(JOB->class->ext_func[sym->global.value].type);
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
/* That breaks some code if the property has the same name as a class!
|
|
|
|
else if (type == TK_PROPERTY)
|
|
|
|
{
|
|
|
|
CODE_push_me(FALSE);
|
|
|
|
CODE_push_unknown(CLASS_add_unknown(JOB->class, index));
|
|
|
|
}*/
|
|
|
|
else if (type == TK_EVENT || type == TK_LABEL || type == TK_PROPERTY)
|
|
|
|
{
|
|
|
|
goto __CLASS;
|
|
|
|
}
|
|
|
|
else /* TK_FUNCTION || TK_VARIABLE */
|
|
|
|
{
|
|
|
|
is_static = TYPE_is_static(sym->global.type);
|
|
|
|
is_func = type == TK_FUNCTION;
|
|
|
|
|
2015-01-22 23:46:11 +01:00
|
|
|
if (is_func && PATTERN_is_point(next))
|
|
|
|
goto __CLASS;
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (!is_static && TYPE_is_static(JOB->func->type))
|
|
|
|
THROW("Dynamic symbols cannot be used in static function");
|
|
|
|
|
|
|
|
if (is_func && PATTERN_is_point(next))
|
|
|
|
goto __CLASS;
|
|
|
|
else
|
|
|
|
CODE_push_global(sym->global.value, is_static, is_func);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
if (is_func)
|
|
|
|
push_type(JOB->class->function[sym->global.value].type);
|
|
|
|
else if (is_static)
|
|
|
|
push_type(JOB->class->stat[sym->global.value].type);
|
|
|
|
else
|
|
|
|
push_type(JOB->class->dyn[sym->global.value].type);
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (point)
|
2016-03-14 02:40:50 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
CODE_push_unknown(CLASS_add_unknown(JOB->class, index));
|
2016-03-14 02:40:50 +01:00
|
|
|
push_type_id(T_VOID);
|
|
|
|
}
|
2010-12-29 09:21:51 +01:00
|
|
|
else
|
|
|
|
goto __CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
trans_class(index);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
static void trans_subr(int subr, short nparam)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
SUBR_INFO *info = &COMP_subr_info[subr];
|
2016-03-14 02:40:50 +01:00
|
|
|
int type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2014-05-08 17:10:21 +02:00
|
|
|
if (nparam < info->min_param)
|
|
|
|
THROW("Not enough arguments to &1()", info->name);
|
|
|
|
else if (nparam > info->max_param)
|
|
|
|
THROW("Too many arguments to &1()", info->name);
|
|
|
|
|
2008-01-19 02:36:38 +01:00
|
|
|
if (subr == SUBR_VarPtr)
|
|
|
|
{
|
|
|
|
if (CODE_check_varptr())
|
|
|
|
THROW("VarPtr() argument must be a dynamic, a static or a local variable");
|
|
|
|
}
|
2014-05-08 17:10:21 +02:00
|
|
|
else if (subr == SUBR_IsMissing)
|
|
|
|
{
|
2014-05-18 15:18:32 +02:00
|
|
|
JOB->func->use_is_missing = TRUE;
|
2014-05-08 17:10:21 +02:00
|
|
|
if (CODE_check_ismissing())
|
|
|
|
THROW("IsMissing() requires a function argument");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2014-01-28 00:46:37 +01:00
|
|
|
CODE_subr(info->opcode, nparam, info->optype, info->max_param == info->min_param);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
type = info->type;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RST_SAME:
|
2018-03-03 03:14:11 +01:00
|
|
|
type = get_type_id(0, nparam);
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RST_BCLR:
|
2018-03-03 03:14:11 +01:00
|
|
|
type = get_type_id(0, nparam);
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
2018-02-17 16:44:38 +01:00
|
|
|
|
|
|
|
case RST_MIN:
|
2018-03-03 03:14:11 +01:00
|
|
|
type = Max(get_type_id(0, nparam), get_type_id(1, nparam));
|
2018-02-17 16:44:38 +01:00
|
|
|
if (type > T_DATE && type != T_VARIANT)
|
|
|
|
THROW("Number or Date expected");
|
2016-03-14 02:40:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nparam)
|
|
|
|
drop_type(nparam);
|
|
|
|
|
|
|
|
push_type_id(type);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
static void trans_operation(short op, short nparam, PATTERN previous)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
COMP_INFO *info = &COMP_res_info[op];
|
2016-03-14 02:40:50 +01:00
|
|
|
int type = info->type;
|
2018-02-28 14:07:24 +01:00
|
|
|
int type1, type2;
|
2018-03-03 03:14:11 +01:00
|
|
|
TYPE ftype;
|
2010-12-29 09:21:51 +01:00
|
|
|
|
|
|
|
switch (info->value)
|
|
|
|
{
|
|
|
|
case OP_PT:
|
|
|
|
if (nparam == 0)
|
2016-03-14 02:40:50 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_use_with();
|
2016-03-14 02:40:50 +01:00
|
|
|
type = T_OBJECT;
|
|
|
|
}
|
2010-12-29 09:21:51 +01:00
|
|
|
else if (!PATTERN_is_identifier(previous))
|
|
|
|
THROW(E_SYNTAX);
|
2016-03-14 02:40:50 +01:00
|
|
|
else
|
|
|
|
{
|
2018-03-03 03:14:11 +01:00
|
|
|
switch(get_type_id(0, nparam))
|
2016-03-14 02:40:50 +01:00
|
|
|
{
|
|
|
|
case T_OBJECT:
|
|
|
|
case T_VARIANT:
|
2018-07-07 02:23:08 +02:00
|
|
|
case T_STRUCT:
|
2018-09-23 09:15:29 +02:00
|
|
|
case T_STRING:
|
2019-11-30 06:29:17 +01:00
|
|
|
case T_ARRAY:
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW("Not an object");
|
|
|
|
}
|
|
|
|
}
|
2010-12-29 09:21:51 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_EXCL:
|
|
|
|
if (!PATTERN_is_identifier(previous))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_LSQR:
|
|
|
|
CODE_push_array(nparam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_RSQR:
|
|
|
|
TRANS_subr(TS_SUBR_ARRAY, nparam);
|
2016-09-04 01:45:59 +02:00
|
|
|
if (nparam > MAX_PARAM_OP)
|
|
|
|
nparam--;
|
2010-12-29 09:21:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_COLON:
|
|
|
|
TRANS_subr(TS_SUBR_COLLECTION, nparam);
|
2016-09-04 01:45:59 +02:00
|
|
|
if (nparam > MAX_PARAM_OP)
|
|
|
|
nparam -= 2;
|
2010-12-29 09:21:51 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_MINUS:
|
|
|
|
if (nparam == 1)
|
2016-03-14 02:40:50 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
CODE_op(C_NEG, 0, nparam, TRUE);
|
2016-03-14 02:40:50 +01:00
|
|
|
type = RST_SAME;
|
|
|
|
}
|
2010-12-29 09:21:51 +01:00
|
|
|
else
|
|
|
|
CODE_op(info->code, info->subcode, nparam, TRUE);
|
|
|
|
break;
|
2020-04-04 16:18:10 +02:00
|
|
|
|
|
|
|
case OP_AMP:
|
|
|
|
if (nparam == 1)
|
|
|
|
CODE_op(info->code, 1, 2, TRUE);
|
|
|
|
else
|
|
|
|
CODE_op(info->code, info->subcode, nparam, FALSE);
|
|
|
|
break;
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
default:
|
|
|
|
CODE_op(info->code, info->subcode, nparam, (info->flag != RSF_OPN));
|
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RST_SAME:
|
2018-03-03 03:14:11 +01:00
|
|
|
ftype = get_type(0, nparam);
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RST_ADD:
|
2018-03-03 03:14:11 +01:00
|
|
|
type = Max(get_type_id(0, nparam), get_type_id(1, nparam));
|
2016-03-14 02:40:50 +01:00
|
|
|
if (type == T_DATE)
|
|
|
|
type = T_FLOAT;
|
2018-03-03 03:14:11 +01:00
|
|
|
ftype = TYPE_make_simple(type);
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RST_AND:
|
2018-03-03 03:14:11 +01:00
|
|
|
type1 = get_type_id(0, nparam);
|
|
|
|
type2 = get_type_id(1, nparam);
|
2018-02-28 14:07:24 +01:00
|
|
|
|
2018-02-28 16:48:39 +01:00
|
|
|
if (type1 != T_VARIANT && type2 != T_VARIANT)
|
|
|
|
{
|
|
|
|
if ((type1 > T_BOOLEAN && type1 <= T_LONG) ^ (type2 > T_BOOLEAN && type2 <= T_LONG))
|
|
|
|
COMPILE_print(MSG_WARNING, JOB->line, "integer and boolean mixed with `&1' operator", info->name);
|
|
|
|
}
|
2018-02-28 14:07:24 +01:00
|
|
|
|
|
|
|
type = Max(type1, type2);
|
|
|
|
|
|
|
|
if (type > T_LONG)
|
|
|
|
{
|
|
|
|
if (type != T_VARIANT)
|
|
|
|
type = T_BOOLEAN;
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:14:11 +01:00
|
|
|
ftype = TYPE_make_simple(type);
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RST_NOT:
|
2018-03-03 03:14:11 +01:00
|
|
|
type = get_type_id(0, nparam);
|
2018-02-28 14:07:24 +01:00
|
|
|
if (type == T_STRING || type == T_OBJECT || type == T_DATE)
|
2016-03-14 02:40:50 +01:00
|
|
|
type = T_BOOLEAN;
|
2018-03-03 03:14:11 +01:00
|
|
|
ftype = TYPE_make_simple(type);
|
2016-03-14 02:40:50 +01:00
|
|
|
break;
|
2018-02-28 16:48:39 +01:00
|
|
|
|
|
|
|
case RST_MOD:
|
2018-03-03 03:14:11 +01:00
|
|
|
type1 = get_type_id(0, nparam);
|
|
|
|
type2 = get_type_id(1, nparam);
|
2018-02-28 16:48:39 +01:00
|
|
|
|
|
|
|
if (type1 != T_VARIANT && type2 != T_VARIANT)
|
|
|
|
{
|
2018-02-28 16:54:23 +01:00
|
|
|
if (type1 <= T_BOOLEAN || type1 > T_LONG || type2 <= T_BOOLEAN || type2 > T_LONG)
|
2018-02-28 16:48:39 +01:00
|
|
|
THROW("Type mismatch");
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:14:11 +01:00
|
|
|
ftype = TYPE_make_simple(Max(type1, type2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RST_GET:
|
|
|
|
ftype = TYPE_make_simple(T_VARIANT);
|
2018-02-28 16:48:39 +01:00
|
|
|
break;
|
2018-03-03 03:14:11 +01:00
|
|
|
|
|
|
|
/*case RST_GET:
|
|
|
|
ftype = get_type(0, nparam);
|
|
|
|
if (ftype.t.id == T_OBJECT)
|
|
|
|
{
|
|
|
|
ftype = JOB->class->class[ftype.t.value].array;
|
|
|
|
if (TYPE_is_null(ftype))
|
|
|
|
ftype = TYPE_make_simple(T_VARIANT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ftype = TYPE_make_simple(T_VARIANT);
|
|
|
|
|
|
|
|
fprintf(stderr, "RST_GET: %s\n", TYPE_get_desc(ftype));
|
|
|
|
break;*/
|
|
|
|
|
|
|
|
default:
|
|
|
|
ftype = TYPE_make_simple(type);
|
|
|
|
|
2016-03-14 02:40:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nparam)
|
|
|
|
drop_type(nparam);
|
|
|
|
|
2018-03-03 03:14:11 +01:00
|
|
|
push_type(ftype);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
static void trans_call(short nparam, uint64_t byref)
|
|
|
|
{
|
|
|
|
if (!byref)
|
|
|
|
{
|
|
|
|
CODE_call(nparam);
|
2019-11-09 11:58:57 +01:00
|
|
|
if (_must_drop_vargs)
|
|
|
|
{
|
|
|
|
CODE_end_vargs();
|
|
|
|
_must_drop_vargs = FALSE;
|
|
|
|
}
|
2008-01-19 18:52:05 +01:00
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
else
|
2014-05-05 22:16:41 +02:00
|
|
|
{
|
2016-03-14 02:40:50 +01:00
|
|
|
CODE_call_byref(nparam, byref);
|
|
|
|
if (_must_drop_vargs)
|
|
|
|
{
|
|
|
|
CODE_drop_vargs();
|
|
|
|
_must_drop_vargs = FALSE;
|
|
|
|
}
|
2014-05-05 22:16:41 +02:00
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
drop_type(nparam + 1);
|
|
|
|
|
|
|
|
push_type_id(T_VARIANT);
|
2008-01-19 18:52:05 +01:00
|
|
|
}
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
static void trans_expr_from_tree(TRANS_TREE *tree, int count)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2016-03-20 02:27:31 +01:00
|
|
|
static void *jump[] = {
|
|
|
|
&&__CONTINUE, &&__CONTINUE, &&__RESERVED, &&__IDENTIFIER, &&__NUMBER, &&__STRING, &&__TSTRING, &&__CONTINUE, &&__SUBR, &&__CLASS, &&__CONTINUE, &&__CONTINUE
|
|
|
|
};
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
int i, op;
|
|
|
|
short nparam;
|
|
|
|
PATTERN pattern, next_pattern, prev_pattern;
|
2016-03-14 02:40:50 +01:00
|
|
|
uint64_t byref = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
pattern = NULL_PATTERN;
|
2016-03-14 02:40:50 +01:00
|
|
|
|
|
|
|
#if DEBUG
|
2016-09-04 01:45:59 +02:00
|
|
|
fprintf(stderr, "-------------------------------------------- %d\n", _type_level);
|
2016-03-14 02:40:50 +01:00
|
|
|
#endif
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
i = 0;
|
|
|
|
|
2019-05-08 06:13:04 +02:00
|
|
|
for (i = 0; i < count; i++)
|
2010-12-29 09:21:51 +01:00
|
|
|
{
|
2019-05-08 06:13:04 +02:00
|
|
|
_tree_index = i;
|
2010-12-29 09:21:51 +01:00
|
|
|
prev_pattern = pattern;
|
|
|
|
pattern = tree[i];
|
2016-03-20 02:27:31 +01:00
|
|
|
next_pattern = tree[i + 1];
|
|
|
|
|
|
|
|
goto *jump[PATTERN_type(pattern)];
|
|
|
|
|
|
|
|
__NUMBER:
|
|
|
|
|
|
|
|
push_number(PATTERN_index(pattern));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
__STRING:
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
push_string(PATTERN_index(pattern), FALSE);
|
|
|
|
continue;
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
__TSTRING:
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
push_string(PATTERN_index(pattern), TRUE);
|
|
|
|
continue;
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
__IDENTIFIER:
|
|
|
|
|
|
|
|
trans_identifier(PATTERN_index(pattern), PATTERN_is_point(pattern), next_pattern);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
|
|
|
trans_class(PATTERN_index(pattern));
|
|
|
|
continue;
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
__SUBR:
|
|
|
|
|
|
|
|
nparam = get_nparam(tree, count, &i, NULL);
|
|
|
|
trans_subr(PATTERN_index(pattern), nparam);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
__RESERVED:
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
if (PATTERN_is(pattern, RS_TRUE))
|
2010-12-29 09:21:51 +01:00
|
|
|
{
|
2016-03-20 02:27:31 +01:00
|
|
|
CODE_push_boolean(TRUE);
|
|
|
|
push_type_id(T_BOOLEAN);
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
2016-03-20 02:27:31 +01:00
|
|
|
else if (PATTERN_is(pattern, RS_FALSE))
|
2010-12-29 09:21:51 +01:00
|
|
|
{
|
2016-03-20 02:27:31 +01:00
|
|
|
CODE_push_boolean(FALSE);
|
|
|
|
push_type_id(T_BOOLEAN);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_NULL))
|
|
|
|
{
|
|
|
|
CODE_push_null();
|
|
|
|
push_type_id(T_OBJECT);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_ME))
|
|
|
|
{
|
|
|
|
/*if (FUNCTION_is_static(JOB->func))
|
|
|
|
THROW("ME cannot be used in a static function");*/
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
CODE_push_me(FALSE);
|
|
|
|
push_type_id(T_OBJECT);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_SUPER))
|
|
|
|
{
|
|
|
|
/*if (FUNCTION_is_static(JOB->func))
|
|
|
|
THROW("ME cannot be used in a static function");*/
|
2010-12-29 09:21:51 +01:00
|
|
|
|
2016-03-20 02:27:31 +01:00
|
|
|
CODE_push_super(FALSE);
|
|
|
|
push_type_id(T_OBJECT);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_LAST))
|
|
|
|
{
|
|
|
|
CODE_push_last();
|
|
|
|
push_type_id(T_OBJECT);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_AT))
|
|
|
|
{
|
2018-02-14 17:03:14 +01:00
|
|
|
if (TRANS_popify_last())
|
2016-03-20 02:27:31 +01:00
|
|
|
THROW("This expression cannot be passed by reference");
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_COMMA))
|
|
|
|
{
|
|
|
|
CODE_drop();
|
|
|
|
drop_type(1);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_ERROR))
|
|
|
|
{
|
|
|
|
TRANS_subr(TS_SUBR_ERROR, 0);
|
2016-09-04 01:45:59 +02:00
|
|
|
push_type_id(T_BOOLEAN);
|
2016-03-20 02:27:31 +01:00
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_OPTIONAL))
|
|
|
|
{
|
|
|
|
CODE_push_void();
|
|
|
|
push_type_id(T_VOID);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_PINF))
|
|
|
|
{
|
|
|
|
CODE_push_inf(FALSE);
|
|
|
|
push_type_id(T_FLOAT);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_MINF))
|
|
|
|
{
|
|
|
|
CODE_push_inf(TRUE);
|
|
|
|
push_type_id(T_FLOAT);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_3PTS))
|
|
|
|
{
|
|
|
|
_must_drop_vargs = TRUE;
|
|
|
|
CODE_push_vargs();
|
|
|
|
// push_type_id(T_FLOAT); we push no type
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
op = PATTERN_index(pattern);
|
|
|
|
if (op == RS_LBRA)
|
2014-05-05 22:07:00 +02:00
|
|
|
{
|
2016-03-20 02:27:31 +01:00
|
|
|
nparam = get_nparam(tree, count, &i, &byref);
|
|
|
|
trans_call(nparam, byref);
|
2014-05-05 22:07:00 +02:00
|
|
|
}
|
2010-12-29 09:21:51 +01:00
|
|
|
else
|
|
|
|
{
|
2016-03-20 02:27:31 +01:00
|
|
|
nparam = get_nparam(tree, count, &i, NULL);
|
|
|
|
trans_operation((short)op, nparam, prev_pattern);
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2016-03-20 02:27:31 +01:00
|
|
|
|
|
|
|
__CONTINUE:
|
|
|
|
;
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
2016-09-04 01:45:59 +02:00
|
|
|
|
|
|
|
_last_type = pop_type();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void TRANS_new(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
int index;
|
|
|
|
int i, nparam;
|
|
|
|
bool array = FALSE;
|
|
|
|
bool event = FALSE;
|
2013-01-06 17:13:31 +01:00
|
|
|
//bool collection = FALSE;
|
2010-12-29 09:21:51 +01:00
|
|
|
bool check_param = FALSE;
|
|
|
|
|
|
|
|
nparam = 0;
|
|
|
|
|
|
|
|
if (PATTERN_is_class(*JOB->current))
|
|
|
|
{
|
|
|
|
index = CLASS_add_class(JOB->class, PATTERN_index(*JOB->current));
|
|
|
|
if (PATTERN_is(JOB->current[1], RS_LSQR))
|
|
|
|
index = CLASS_get_array_class(JOB->class, T_OBJECT, index);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
CODE_push_class(index);
|
|
|
|
nparam = 1;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is_type(*JOB->current))
|
|
|
|
{
|
|
|
|
if (!PATTERN_is(JOB->current[1], RS_LSQR))
|
2011-03-13 14:41:57 +01:00
|
|
|
THROW("Cannot instantiate native types");
|
2010-12-29 09:21:51 +01:00
|
|
|
|
|
|
|
//CODE_push_number(RES_get_type(PATTERN_index(*JOB->current)));
|
|
|
|
CODE_push_class(CLASS_get_array_class(JOB->class, RES_get_type(PATTERN_index(*JOB->current)), -1));
|
|
|
|
nparam = 1;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(*JOB->current, RS_LBRA))
|
|
|
|
{
|
|
|
|
/* NEW ("Class", ...) */
|
|
|
|
nparam = 0;
|
|
|
|
JOB->current--;
|
|
|
|
check_param = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_LSQR))
|
|
|
|
{
|
2013-01-06 17:13:31 +01:00
|
|
|
//if (collection)
|
|
|
|
// THROW("Array declaration is forbidden with typed collection");
|
2010-12-29 09:21:51 +01:00
|
|
|
|
|
|
|
if (!PATTERN_is(*JOB->current, RS_RSQR))
|
|
|
|
{
|
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
|
|
|
if (i > MAX_ARRAY_DIM)
|
|
|
|
THROW("Too many dimensions");
|
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_RSQR))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!PATTERN_is(*JOB->current, RS_COMMA))
|
|
|
|
THROW(E_MISSING, "']'");
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
array = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_LBRA))
|
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (nparam > MAX_PARAM_FUNC)
|
|
|
|
THROW("Too many arguments");
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_AT) || PATTERN_is(*JOB->current, RS_BYREF))
|
|
|
|
THROW("NEW cannot have arguments passed by reference");
|
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_RBRA))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!PATTERN_is(*JOB->current, RS_COMMA))
|
|
|
|
THROW(E_MISSING, "')'");
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
|
|
|
|
if (check_param && nparam == 0)
|
|
|
|
THROW("Not enough argument to New()");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TRANS_is(RS_AS))
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
event = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CODE_call(nparam, FALSE);
|
|
|
|
CODE_drop();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2013-01-06 17:13:31 +01:00
|
|
|
//if (collection)
|
|
|
|
// CODE_new(nparam, TRUE, event);
|
|
|
|
//else
|
|
|
|
CODE_new(nparam, array, event);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-04 01:45:59 +02:00
|
|
|
static void trans_expression(bool check_statement)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_TREE *tree;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2014-01-28 02:08:58 +01:00
|
|
|
if (!check_statement)
|
2009-07-12 23:49:13 +02:00
|
|
|
{
|
2014-01-28 02:08:58 +01:00
|
|
|
if (TRANS_is(RS_NEW))
|
|
|
|
{
|
|
|
|
TRANS_new();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (TRANS_is(RS_READ))
|
|
|
|
{
|
|
|
|
TRANS_read();
|
|
|
|
return;
|
|
|
|
}
|
2020-02-11 01:45:10 +01:00
|
|
|
else if (TRANS_is(RS_PEEK))
|
|
|
|
{
|
|
|
|
TRANS_peek();
|
|
|
|
return;
|
|
|
|
}
|
2009-09-20 19:32:12 +02:00
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2019-05-08 06:13:04 +02:00
|
|
|
_tree_line = JOB->line;
|
|
|
|
TRANS_tree(check_statement, &tree, &_tree_length, &_tree_pos);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-05-08 06:13:04 +02:00
|
|
|
JOB->step = JOB_STEP_TREE;
|
|
|
|
trans_expr_from_tree(tree, _tree_length);
|
|
|
|
JOB->step = JOB_STEP_CODE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&tree);
|
2019-05-08 06:27:14 +02:00
|
|
|
_tree_pos = NULL;
|
2019-05-08 06:13:04 +02:00
|
|
|
_tree_length = 0;
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (check_statement)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (!CODE_check_statement_last())
|
|
|
|
THROW("This expression cannot be a statement");
|
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
CODE_drop();
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2019-05-08 06:13:04 +02:00
|
|
|
int TRANS_get_column(int *pline)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int line;
|
2019-05-08 15:32:11 +02:00
|
|
|
int col;
|
2019-05-08 06:13:04 +02:00
|
|
|
|
|
|
|
if (!_tree_pos)
|
|
|
|
{
|
|
|
|
*pline = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = _tree_line;
|
2019-05-08 15:32:11 +02:00
|
|
|
col = _tree_pos[0];
|
2019-05-08 06:13:04 +02:00
|
|
|
for (i = 1; i <= _tree_index; i++)
|
|
|
|
{
|
2019-05-08 15:32:11 +02:00
|
|
|
col = _tree_pos[i];
|
|
|
|
if (col < 0)
|
2019-05-08 06:13:04 +02:00
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pline = line;
|
2019-05-08 15:32:11 +02:00
|
|
|
return abs(col);
|
2019-05-08 06:13:04 +02:00
|
|
|
}
|
|
|
|
|
2018-02-14 17:03:14 +01:00
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void TRANS_ignore_expression()
|
2008-03-17 15:54:17 +01:00
|
|
|
{
|
2019-05-08 06:13:04 +02:00
|
|
|
TRANS_tree(FALSE, NULL, NULL, NULL);
|
2008-03-17 15:54:17 +01:00
|
|
|
}
|
|
|
|
|
2018-02-14 17:03:14 +01:00
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
TYPE TRANS_variable_get_type()
|
|
|
|
{
|
2016-03-20 02:27:31 +01:00
|
|
|
TYPE type = TYPE_make_simple(T_VOID);
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_TREE *tree;
|
2010-05-22 20:02:34 +02:00
|
|
|
int count;
|
2009-09-20 19:32:12 +02:00
|
|
|
int index;
|
|
|
|
CLASS_SYMBOL *sym;
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2019-05-08 06:13:04 +02:00
|
|
|
TRANS_tree(FALSE, &tree, &count, NULL);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
if (count == 1 && PATTERN_is_identifier(*tree))
|
2009-09-20 19:32:12 +02:00
|
|
|
{
|
|
|
|
index = PATTERN_index(*tree);
|
|
|
|
sym = CLASS_get_symbol(JOB->class, index);
|
|
|
|
|
|
|
|
if (!TYPE_is_null(sym->local.type))
|
|
|
|
{
|
|
|
|
return sym->local.type;
|
|
|
|
}
|
|
|
|
else if (!TYPE_is_null(sym->global.type))
|
|
|
|
{
|
|
|
|
int type = TYPE_get_kind(sym->global.type);
|
|
|
|
if (type == TK_VARIABLE)
|
|
|
|
return sym->global.type;
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&tree);
|
2016-03-14 02:40:50 +01:00
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-02-14 17:03:14 +01:00
|
|
|
bool TRANS_popify_last()
|
|
|
|
{
|
|
|
|
if (!CODE_popify_last())
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (_last_symbol_used)
|
|
|
|
{
|
|
|
|
if (_last_symbol_global)
|
|
|
|
_last_symbol_used->global_assigned = TRUE;
|
|
|
|
else
|
|
|
|
_last_symbol_used->local_assigned = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void TRANS_reference(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_expression(FALSE);
|
2018-02-14 17:03:14 +01:00
|
|
|
if (TRANS_popify_last())
|
2010-12-29 09:21:51 +01:00
|
|
|
THROW("Invalid assignment");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
bool TRANS_affectation(bool dup)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 09:21:51 +01:00
|
|
|
static TRANS_STATEMENT statement[] = {
|
|
|
|
//{ RS_NEW, TRANS_new },
|
|
|
|
{ RS_OPEN, TRANS_open },
|
2013-11-04 16:17:01 +01:00
|
|
|
{ RS_CLOSE, TRANS_close },
|
2010-12-29 09:21:51 +01:00
|
|
|
{ RS_SHELL, TRANS_shell },
|
|
|
|
{ RS_EXEC, TRANS_exec },
|
|
|
|
{ RS_RAISE, TRANS_raise },
|
|
|
|
{ RS_PIPE, TRANS_pipe },
|
|
|
|
{ RS_LOCK, TRANS_lock },
|
|
|
|
{ RS_MEMORY, TRANS_memory },
|
2009-09-20 19:32:12 +02:00
|
|
|
//{ RS_READ, TRANS_read },
|
2010-12-29 09:21:51 +01:00
|
|
|
{ RS_NONE, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
TRANS_STATEMENT *st;
|
|
|
|
PATTERN *look = JOB->current;
|
|
|
|
PATTERN *left, *expr, *after;
|
|
|
|
int niv = 0;
|
|
|
|
bool equal = FALSE;
|
|
|
|
bool stat = FALSE;
|
2014-11-28 00:31:51 +01:00
|
|
|
int op = RS_NONE;
|
|
|
|
int id = RS_NONE;
|
2016-09-04 01:45:59 +02:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_newline(*look)) // || PATTERN_is_end(*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 if (niv == 0)
|
|
|
|
{
|
|
|
|
if (PATTERN_is(*look, RS_EQUAL))
|
|
|
|
{
|
|
|
|
equal = TRUE;
|
|
|
|
op = RS_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is_reserved(*look) && RES_is_assignment(PATTERN_index(*look)))
|
|
|
|
{
|
|
|
|
equal = TRUE;
|
|
|
|
op = RES_get_assignment_operator(PATTERN_index(*look));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
look++;
|
|
|
|
}
|
|
|
|
|
2013-05-04 00:45:11 +02:00
|
|
|
if (!equal || look == JOB->current)
|
2010-12-29 09:21:51 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
left = JOB->current;
|
|
|
|
*look++ = PATTERN_make(RT_NEWLINE, 0);
|
|
|
|
expr = look;
|
|
|
|
|
|
|
|
JOB->current = expr;
|
|
|
|
|
|
|
|
if (op == RS_NONE && (PATTERN_is_reserved(*JOB->current)))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_NEW))
|
|
|
|
{
|
2018-02-14 17:03:14 +01:00
|
|
|
TRANS_in_assignment++;
|
2010-12-29 09:21:51 +01:00
|
|
|
TRANS_new();
|
2018-02-14 17:03:14 +01:00
|
|
|
TRANS_in_assignment--;
|
2014-11-28 00:31:51 +01:00
|
|
|
id = RS_NEW;
|
2010-12-29 09:21:51 +01:00
|
|
|
stat = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (st = statement; st->id; st++)
|
|
|
|
{
|
|
|
|
if (TRANS_is(st->id))
|
|
|
|
{
|
2014-11-28 00:31:51 +01:00
|
|
|
id = st->id;
|
2018-02-14 17:03:14 +01:00
|
|
|
TRANS_in_assignment++;
|
2010-12-29 09:21:51 +01:00
|
|
|
(*st->func)();
|
2018-02-14 17:03:14 +01:00
|
|
|
TRANS_in_assignment--;
|
2010-12-29 09:21:51 +01:00
|
|
|
stat = TRUE;
|
2014-11-28 00:31:51 +01:00
|
|
|
break;
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stat)
|
|
|
|
{
|
2016-09-04 01:45:59 +02:00
|
|
|
TYPE type;
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
if (op != RS_NONE)
|
|
|
|
{
|
|
|
|
JOB->current = left;
|
2016-09-04 01:45:59 +02:00
|
|
|
trans_expression(FALSE);
|
|
|
|
type = _last_type;
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current = expr;
|
2016-09-04 01:45:59 +02:00
|
|
|
trans_expression(FALSE);
|
2010-12-29 09:21:51 +01:00
|
|
|
after = JOB->current;
|
|
|
|
|
|
|
|
if (op != RS_NONE)
|
2012-09-17 13:13:32 +02:00
|
|
|
{
|
2016-09-04 01:45:59 +02:00
|
|
|
push_type(_last_type);
|
|
|
|
push_type(type);
|
2020-04-04 16:18:10 +02:00
|
|
|
/*if (op == RS_AMP && COMPILE_version >= 0x03150000)
|
|
|
|
trans_operation(op, 1, NULL_PATTERN);
|
|
|
|
else*/
|
|
|
|
trans_operation(op, 2, NULL_PATTERN);
|
2016-09-04 01:45:59 +02:00
|
|
|
pop_type();
|
2012-09-17 13:13:32 +02:00
|
|
|
}
|
2010-12-29 09:21:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
after = JOB->current;
|
|
|
|
|
|
|
|
if (dup)
|
|
|
|
CODE_dup();
|
|
|
|
|
2015-05-08 19:40:28 +02:00
|
|
|
if (COMPILE_version >= 0x03070000)
|
|
|
|
{
|
|
|
|
if (id == RS_EXEC || id == RS_SHELL)
|
|
|
|
CODE_dup();
|
|
|
|
}
|
2014-11-28 00:31:51 +01:00
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
JOB->current = left;
|
|
|
|
TRANS_reference();
|
|
|
|
|
2014-05-06 22:09:50 +02:00
|
|
|
if (!PATTERN_is_newline(*JOB->current))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
|
2020-04-04 16:18:10 +02:00
|
|
|
if (COMPILE_version >= 0x03150000 && op == RS_AMP)
|
|
|
|
CODE_check_fast_cat();
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
JOB->current = after;
|
|
|
|
|
2015-05-08 19:40:28 +02:00
|
|
|
if (COMPILE_version >= 0x03070000)
|
2014-11-28 00:31:51 +01:00
|
|
|
{
|
2015-05-08 19:40:28 +02:00
|
|
|
if (id == RS_EXEC || id == RS_SHELL)
|
|
|
|
{
|
|
|
|
TRANS_subr(TS_SUBR_CHECK_EXEC, 1);
|
|
|
|
CODE_drop();
|
|
|
|
}
|
2014-11-28 00:31:51 +01:00
|
|
|
}
|
|
|
|
|
2010-12-29 09:21:51 +01:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-04 01:45:59 +02:00
|
|
|
void TRANS_expression(bool check_statement)
|
|
|
|
{
|
|
|
|
_type_level = 0;
|
|
|
|
trans_expression(check_statement);
|
|
|
|
}
|
|
|
|
|