2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbc_trans_expr.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
(c) 2000-2009 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
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
|
|
|
/*#define DEBUG*/
|
|
|
|
|
|
|
|
//static bool _accept_statement = FALSE;
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
static short get_nparam(PATTERN *tree, int count, int *index, uint64_t *byref)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
PATTERN pattern;
|
2008-01-19 18:52:05 +01:00
|
|
|
short nparam = 0;
|
|
|
|
int shift = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
if (*index < count)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
pattern = tree[*index + 1];
|
|
|
|
if (PATTERN_is_param(pattern))
|
|
|
|
{
|
|
|
|
(*index)++;
|
2008-01-19 18:52:05 +01:00
|
|
|
nparam = (short)PATTERN_index(pattern);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-01-19 18:52:05 +01:00
|
|
|
|
|
|
|
if (byref)
|
|
|
|
*byref = 0;
|
2010-05-22 20:02:34 +02:00
|
|
|
while (*index < count)
|
2008-01-19 18:52:05 +01:00
|
|
|
{
|
|
|
|
pattern = tree[*index + 1];
|
|
|
|
if (!PATTERN_is_param(pattern))
|
|
|
|
break;
|
|
|
|
(*index)++;
|
|
|
|
if (byref)
|
|
|
|
{
|
|
|
|
*byref |= (uint64_t)PATTERN_index(pattern) << shift;
|
|
|
|
shift += 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/*
|
2008-01-17 22:39:26 +01:00
|
|
|
Gère le cas où on a codé un subr sans mettre de parenthèses
|
2007-12-30 17:41:49 +01:00
|
|
|
=> nparam = 0
|
|
|
|
*/
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
return 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
|
|
|
{
|
|
|
|
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);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEAR(&decl);
|
2008-01-17 22:39:26 +01:00
|
|
|
decl.type = TYPE_make(number.type, 0, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
decl.index = NO_SYMBOL;
|
|
|
|
decl.value = index;
|
2008-01-17 22:39:26 +01:00
|
|
|
if (number.type == T_LONG)
|
|
|
|
decl.lvalue = number.lval;
|
2007-12-30 17:41:49 +01:00
|
|
|
CODE_push_const(CLASS_add_constant(JOB->class, &decl));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
static void push_string(int index, bool trans)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
TRANS_DECL decl;
|
|
|
|
SYMBOL *sym;
|
2008-01-06 19:49:23 +01:00
|
|
|
int len;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-25 13:19:00 +02:00
|
|
|
if (index == VOID_STRING)
|
|
|
|
len = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sym = TABLE_get_symbol(JOB->class->string, index);
|
|
|
|
len = sym->len;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
{
|
2009-09-17 22:58:27 +02:00
|
|
|
CODE_push_void_string();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else if (len == 1 && !trans)
|
|
|
|
{
|
|
|
|
CODE_push_char(*(sym->name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CLEAR(&decl);
|
|
|
|
|
|
|
|
if (trans)
|
|
|
|
decl.type = TYPE_make(T_CSTRING, 0, 0);
|
|
|
|
else
|
|
|
|
decl.type = TYPE_make(T_STRING, 0, 0);
|
|
|
|
decl.index = NO_SYMBOL;
|
|
|
|
decl.value = index;
|
|
|
|
|
|
|
|
CODE_push_const(CLASS_add_constant(JOB->class, &decl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
void TRANS_class(int index)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (CLASS_exist_class(JOB->class, index))
|
|
|
|
CODE_push_class(CLASS_add_class(JOB->class, index));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = TABLE_get_symbol_name(JOB->class->table, index);
|
|
|
|
THROW("Unknown identifier: &1", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
static void trans_identifier(int index, bool first, bool point, PATTERN next)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
CLASS_SYMBOL *sym = CLASS_get_symbol(JOB->class, index);
|
|
|
|
bool is_static;
|
|
|
|
bool is_func;
|
|
|
|
int type;
|
|
|
|
CONSTANT *constant;
|
|
|
|
|
|
|
|
if (!TYPE_is_null(sym->local.type) && !point)
|
|
|
|
{
|
|
|
|
CODE_push_local(sym->local.value);
|
|
|
|
}
|
|
|
|
else if (!TYPE_is_null(sym->global.type) && !point)
|
|
|
|
{
|
|
|
|
type = TYPE_get_kind(sym->global.type);
|
|
|
|
|
|
|
|
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)
|
2007-12-30 17:41:49 +01:00
|
|
|
CODE_push_number(constant->value);
|
|
|
|
else
|
|
|
|
CODE_push_const(sym->global.value);
|
|
|
|
}
|
|
|
|
else if (type == TK_EXTERN)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_point(next))
|
|
|
|
goto __CLASS;
|
|
|
|
|
|
|
|
CODE_push_extern(sym->global.value);
|
|
|
|
}
|
2008-03-18 13:47:12 +01:00
|
|
|
/* That breaks some code if the property has the same name as a class!
|
2008-03-17 15:54:17 +01:00
|
|
|
else if (type == TK_PROPERTY)
|
|
|
|
{
|
|
|
|
CODE_push_me(FALSE);
|
|
|
|
CODE_push_unknown(CLASS_add_unknown(JOB->class, index));
|
2008-03-18 13:47:12 +01:00
|
|
|
}*/
|
|
|
|
else if (type == TK_EVENT || type == TK_LABEL || type == TK_PROPERTY)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
goto __CLASS;
|
|
|
|
}
|
|
|
|
else /* TK_FUNCTION || TK_VARIABLE */
|
|
|
|
{
|
|
|
|
is_static = TYPE_is_static(sym->global.type);
|
|
|
|
is_func = type == TK_FUNCTION;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*index = CLASS_add_symbol(JOB->class, index);*/
|
|
|
|
|
|
|
|
if (point)
|
|
|
|
CODE_push_unknown(CLASS_add_unknown(JOB->class, index));
|
|
|
|
/* Class must be declared now ! */
|
|
|
|
else
|
|
|
|
goto __CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
2009-09-20 19:32:12 +02: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
|
|
|
{
|
|
|
|
SUBR_INFO *info = &COMP_subr_info[subr];
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
CODE_subr(info->opcode, nparam, info->optype, FALSE /* output */, (info->max_param == info->min_param));
|
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
|
|
|
{
|
|
|
|
COMP_INFO *info = &COMP_res_info[op];
|
|
|
|
|
|
|
|
switch (info->value)
|
|
|
|
{
|
|
|
|
case OP_PT:
|
|
|
|
|
|
|
|
if (nparam == 0)
|
|
|
|
TRANS_use_with();
|
|
|
|
else if (!PATTERN_is_identifier(previous))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
|
|
|
|
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);
|
|
|
|
break;
|
|
|
|
|
2008-11-11 18:22:38 +01:00
|
|
|
case OP_COLON:
|
|
|
|
TRANS_subr(TS_SUBR_COLLECTION, nparam);
|
|
|
|
break;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
case OP_MINUS:
|
|
|
|
if (nparam == 1)
|
2009-09-27 11:28:52 +02:00
|
|
|
CODE_op(C_NEG, 0, nparam, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
2009-09-27 11:28:52 +02:00
|
|
|
CODE_op(info->code, info->subcode, nparam, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
break;
|
2008-01-19 18:52:05 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
default:
|
|
|
|
|
2009-09-27 11:28:52 +02:00
|
|
|
CODE_op(info->code, info->subcode, nparam, (info->flag != RSF_OPN));
|
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);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CODE_call_byref(nparam, byref);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-01-19 18:52:05 +01:00
|
|
|
int i, op;
|
2007-12-30 17:41:49 +01:00
|
|
|
short nparam;
|
|
|
|
PATTERN pattern, next_pattern, prev_pattern;
|
2008-01-19 18:52:05 +01:00
|
|
|
uint64_t byref;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
count--;
|
2007-12-30 17:41:49 +01:00
|
|
|
pattern = NULL_PATTERN;
|
|
|
|
|
|
|
|
for (i = 0; i <= count; i++)
|
|
|
|
{
|
|
|
|
prev_pattern = pattern;
|
|
|
|
pattern = tree[i];
|
|
|
|
if (i < count)
|
|
|
|
next_pattern = tree[i + 1];
|
|
|
|
else
|
|
|
|
next_pattern = NULL_PATTERN;
|
|
|
|
|
|
|
|
if (PATTERN_is_number(pattern))
|
|
|
|
push_number(PATTERN_index(pattern));
|
|
|
|
|
|
|
|
else if (PATTERN_is_string(pattern))
|
|
|
|
push_string(PATTERN_index(pattern), FALSE);
|
|
|
|
|
|
|
|
else if (PATTERN_is_tstring(pattern))
|
|
|
|
push_string(PATTERN_index(pattern), TRUE);
|
|
|
|
|
|
|
|
else if (PATTERN_is_identifier(pattern))
|
|
|
|
trans_identifier(PATTERN_index(pattern), PATTERN_is_first(pattern), PATTERN_is_point(pattern), next_pattern);
|
|
|
|
|
|
|
|
else if (PATTERN_is_class(pattern))
|
2009-09-20 19:32:12 +02:00
|
|
|
TRANS_class(PATTERN_index(pattern));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
else if (PATTERN_is_subr(pattern))
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
nparam = get_nparam(tree, count, &i, NULL);
|
2008-01-19 18:52:05 +01:00
|
|
|
trans_subr(PATTERN_index(pattern), nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (PATTERN_is_reserved(pattern))
|
|
|
|
{
|
|
|
|
if (PATTERN_is(pattern, RS_TRUE))
|
|
|
|
{
|
|
|
|
CODE_push_boolean(TRUE);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_FALSE))
|
|
|
|
{
|
|
|
|
CODE_push_boolean(FALSE);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_NULL))
|
|
|
|
{
|
|
|
|
CODE_push_null();
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_ME))
|
|
|
|
{
|
|
|
|
/*if (FUNCTION_is_static(JOB->func))
|
|
|
|
THROW("ME cannot be used in a static function");*/
|
|
|
|
|
|
|
|
CODE_push_me(FALSE);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_SUPER))
|
|
|
|
{
|
|
|
|
/*if (FUNCTION_is_static(JOB->func))
|
|
|
|
THROW("ME cannot be used in a static function");*/
|
|
|
|
|
|
|
|
CODE_push_super(FALSE);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_LAST))
|
|
|
|
{
|
|
|
|
CODE_push_last();
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_AT))
|
|
|
|
{
|
2008-01-19 21:59:09 +01:00
|
|
|
if (!CODE_popify_last())
|
|
|
|
THROW("This expression cannot be passed by reference");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_COMMA))
|
|
|
|
{
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_ERROR))
|
|
|
|
{
|
|
|
|
TRANS_subr(TS_SUBR_ERROR, 0);
|
|
|
|
}
|
|
|
|
else if (PATTERN_is(pattern, RS_OPTIONAL))
|
|
|
|
{
|
|
|
|
CODE_push_void();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-19 18:52:05 +01:00
|
|
|
op = PATTERN_index(pattern);
|
|
|
|
if (op == RS_LBRA)
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
nparam = get_nparam(tree, count, &i, &byref);
|
2008-01-19 18:52:05 +01:00
|
|
|
trans_call(nparam, byref);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
nparam = get_nparam(tree, count, &i, NULL);
|
2008-01-19 18:52:05 +01:00
|
|
|
trans_operation((short)op, nparam, prev_pattern);
|
|
|
|
}
|
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
|
|
|
{
|
2008-01-06 19:49:23 +01:00
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
int i, nparam;
|
2009-07-08 21:57:50 +02:00
|
|
|
bool array = FALSE;
|
|
|
|
bool event = FALSE;
|
|
|
|
bool collection = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
bool check_param = FALSE;
|
|
|
|
|
|
|
|
nparam = 0;
|
|
|
|
|
|
|
|
if (PATTERN_is_class(*JOB->current))
|
|
|
|
{
|
2008-08-31 02:32:21 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
CODE_push_class(index);
|
2007-12-30 17:41:49 +01:00
|
|
|
nparam = 1;
|
|
|
|
}
|
|
|
|
else if (PATTERN_is_type(*JOB->current))
|
|
|
|
{
|
|
|
|
if (!PATTERN_is(JOB->current[1], RS_LSQR))
|
|
|
|
THROW("Cannot instanciate native types");
|
|
|
|
|
|
|
|
//CODE_push_number(RES_get_type(PATTERN_index(*JOB->current)));
|
2008-08-31 02:32:21 +02:00
|
|
|
CODE_push_class(CLASS_get_array_class(JOB->class, RES_get_type(PATTERN_index(*JOB->current)), -1));
|
2007-12-30 17:41:49 +01:00
|
|
|
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++;
|
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
if (TRANS_is(RS_LSQR))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (collection)
|
|
|
|
THROW("Array declaration is forbidden with typed collection");
|
|
|
|
|
|
|
|
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))
|
2009-09-21 18:57:21 +02:00
|
|
|
THROW(E_MISSING, "']'");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
array = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-12 23:49:13 +02:00
|
|
|
if (TRANS_is(RS_LBRA))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (nparam > MAX_PARAM_FUNC)
|
|
|
|
THROW("Too many arguments");
|
|
|
|
|
[DEVELOPMENT ENVIRONMENT]
* BUG: Use TextEdit.RichText insted of TextEdit.Text.
* BUG: END SUB can be the end of a method. The class analyze now takes
that into account.
[HELP]
* BUG: Fixed the generated treeview.
[COMPILER]
* OPT: The NOT operator used just at the beginning of a conditional
expression is optimized. Consequently, an expression like 'IF NOT 2' is
now equivalent to 'IF 2 = 0' and not to 'IF (NOT 2) <> 0' as before. In
other words, the boolean conversion is now done before the NOT, and not
after. The following instructions are concerned: IF, WHILE, UNTIL.
* NEW: BYREF is new keyword that is a more readable synonymous of '@'.
[GB.DB.FORM]
* BUG: Correctly manage data controls inside TabStrip-like containers.
* BUG: Setting the focus on a non-initialized DataControl does not raise
an error anymore.
[GB.GTK]
* BUG: HSplitter.Layout and VSplitter.Layout now work correctly. It is a
list of children widths, hidden children having a zero width.
* BUG: Window arrangement is done before the Open event is raised, as in
gb.qt.
* BUG: Keyboard, focus and mouse events now work correctly on Window and
DrawingArea controls.
[GB.QT]
* BUG: HSplitter.Layout and VSplitter.Layout now work correctly. It is a
list of children widths, hidden children having a zero width.
* BUG: Many warning fixes.
* BUG: Now the Control.Visible property works like in gb.gtk, i.e. it
returns if the control was not explicitely hidden.
git-svn-id: svn://localhost/gambas/trunk@1060 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-02-06 01:25:48 +01:00
|
|
|
if (PATTERN_is(*JOB->current, RS_AT) || PATTERN_is(*JOB->current, RS_BYREF))
|
|
|
|
THROW("NEW cannot have arguments passed by reference");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
|
|
|
|
if (PATTERN_is(*JOB->current, RS_RBRA))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!PATTERN_is(*JOB->current, RS_COMMA))
|
2009-09-21 18:57:21 +02:00
|
|
|
THROW(E_MISSING, "')'");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current++;
|
|
|
|
|
|
|
|
if (check_param && nparam == 0)
|
|
|
|
THROW("Not enough argument to New()");
|
|
|
|
}
|
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
if (TRANS_is(RS_AS))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
event = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CODE_call(nparam, FALSE);
|
|
|
|
CODE_drop();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collection)
|
|
|
|
CODE_new(nparam, TRUE, event);
|
|
|
|
else
|
|
|
|
CODE_new(nparam, array, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void TRANS_expression(bool check_statement)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
TRANS_TREE *tree;
|
2010-05-22 20:02:34 +02:00
|
|
|
int tree_length;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
if (TRANS_is(RS_NEW))
|
|
|
|
{
|
|
|
|
TRANS_new();
|
|
|
|
return;
|
|
|
|
}
|
2009-09-20 19:32:12 +02:00
|
|
|
else if (TRANS_is(RS_READ))
|
|
|
|
{
|
|
|
|
TRANS_read();
|
|
|
|
return;
|
|
|
|
}
|
2009-07-12 23:49:13 +02:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
TRANS_tree(check_statement, &tree, &tree_length);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
trans_expr_from_tree(tree, tree_length);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
FREE(&tree, "TRANS_expression");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (check_statement)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (!CODE_check_statement_last())
|
|
|
|
THROW("This expression cannot be a statement");
|
|
|
|
*/
|
|
|
|
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void TRANS_ignore_expression()
|
2008-03-17 15:54:17 +01:00
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TRANS_tree(FALSE, NULL, NULL);
|
2008-03-17 15:54:17 +01:00
|
|
|
}
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
TYPE TRANS_variable_get_type()
|
|
|
|
{
|
2010-05-28 08:24:14 +02:00
|
|
|
TYPE type = TYPE_make(T_VOID, 0, 0);
|
2010-05-22 20:02:34 +02:00
|
|
|
TRANS_TREE *tree;
|
|
|
|
int count;
|
2009-09-20 19:32:12 +02:00
|
|
|
int index;
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
TRANS_tree(FALSE, &tree, &count);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
FREE(&tree, "TRANS_variable_get_type");
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void TRANS_reference(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
|
|
|
|
if (!CODE_popify_last())
|
|
|
|
THROW("Invalid assignment");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
bool TRANS_affectation(bool dup)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
static TRANS_STATEMENT statement[] = {
|
|
|
|
//{ RS_NEW, TRANS_new },
|
|
|
|
{ RS_OPEN, TRANS_open },
|
|
|
|
{ RS_SHELL, TRANS_shell },
|
|
|
|
{ RS_EXEC, TRANS_exec },
|
|
|
|
{ RS_RAISE, TRANS_raise },
|
|
|
|
{ RS_PIPE, TRANS_pipe },
|
|
|
|
{ RS_LOCK, TRANS_lock },
|
2009-09-17 22:58:27 +02:00
|
|
|
{ RS_MEMORY, TRANS_memory },
|
2009-09-20 19:32:12 +02:00
|
|
|
//{ RS_READ, TRANS_read },
|
2007-12-30 17:41:49 +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;
|
|
|
|
int op;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
if (PATTERN_is_newline(*look)) // || PATTERN_is_end(*look))
|
2007-12-30 17:41:49 +01:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!equal)
|
|
|
|
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)))
|
|
|
|
{
|
2009-07-12 23:49:13 +02:00
|
|
|
if (TRANS_is(RS_NEW))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
TRANS_in_affectation++;
|
|
|
|
TRANS_new();
|
|
|
|
TRANS_in_affectation--;
|
|
|
|
stat = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (st = statement; st->id; st++)
|
|
|
|
{
|
2009-07-12 23:49:13 +02:00
|
|
|
if (TRANS_is(st->id))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
TRANS_in_affectation++;
|
|
|
|
(*st->func)();
|
|
|
|
TRANS_in_affectation--;
|
|
|
|
stat = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stat)
|
|
|
|
{
|
|
|
|
if (op != RS_NONE)
|
|
|
|
{
|
|
|
|
JOB->current = left;
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
JOB->current = expr;
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
after = JOB->current;
|
|
|
|
|
|
|
|
if (op != RS_NONE)
|
2008-01-19 18:52:05 +01:00
|
|
|
trans_operation(op, 2, NULL_PATTERN);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
after = JOB->current;
|
|
|
|
|
|
|
|
if (dup)
|
|
|
|
CODE_dup();
|
|
|
|
|
|
|
|
JOB->current = left;
|
|
|
|
TRANS_reference();
|
|
|
|
|
|
|
|
JOB->current = after;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|