2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
exec_enum.c
|
|
|
|
|
|
|
|
Enumeration management
|
|
|
|
|
|
|
|
(c) 2000-2007 Benoit Minisini <gambas@users.sourceforge.net>
|
|
|
|
|
|
|
|
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 1, or (at your option)
|
|
|
|
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.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gbx_c_enum.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* EXEC_object() ne doit pas faire d'auto-create, car sinon
|
|
|
|
il renvoie un objet référencé */
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_enum_first(PCODE code)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
OBJECT *object;
|
|
|
|
CLASS *class;
|
|
|
|
boolean defined;
|
|
|
|
VALUE *local;
|
2008-11-08 18:45:13 +01:00
|
|
|
CENUM *old = EXEC_enum;
|
|
|
|
CENUM *cenum;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
local = &BP[code & 0xFF];
|
|
|
|
|
|
|
|
EXEC_object(local, &class, &object, &defined);
|
|
|
|
|
|
|
|
if (!object && class->auto_create && !class->enum_static)
|
|
|
|
object = EXEC_auto_create(class, FALSE);
|
|
|
|
|
2008-11-08 18:45:13 +01:00
|
|
|
cenum = CENUM_create(object ? (void *)object : (void *)class);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
local++;
|
|
|
|
RELEASE(local);
|
2008-11-08 18:45:13 +01:00
|
|
|
local->_object.class = OBJECT_class(cenum);
|
|
|
|
local->_object.object = cenum;
|
|
|
|
OBJECT_REF(cenum, "EXEC_enum_first");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-11-08 18:45:13 +01:00
|
|
|
EXEC_enum = cenum;
|
2007-12-30 17:41:49 +01:00
|
|
|
EXEC_special(SPEC_FIRST, class, object, 0, TRUE);
|
2008-11-08 18:45:13 +01:00
|
|
|
EXEC_enum = old;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool EXEC_enum_next(PCODE code)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
OBJECT *object;
|
|
|
|
CLASS *class;
|
2008-11-08 18:45:13 +01:00
|
|
|
bool defined;
|
2007-12-30 17:41:49 +01:00
|
|
|
VALUE *local;
|
|
|
|
bool drop = (code & 0xFF);
|
2008-11-08 18:45:13 +01:00
|
|
|
bool err;
|
|
|
|
CENUM *old = EXEC_enum;
|
|
|
|
CENUM *cenum;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
local = &BP[PC[-1] & 0xFF];
|
|
|
|
|
|
|
|
EXEC_object(local, &class, &object, &defined);
|
2008-11-08 18:45:13 +01:00
|
|
|
cenum = (CENUM *)local[1]._object.object;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-11-08 18:45:13 +01:00
|
|
|
if (!cenum->stop)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-11-08 18:45:13 +01:00
|
|
|
EXEC_enum = cenum;
|
|
|
|
err = EXEC_special(SPEC_NEXT, class, object, 0, FALSE);
|
|
|
|
EXEC_enum = old;
|
|
|
|
if (err)
|
2007-12-30 17:41:49 +01:00
|
|
|
THROW(E_ENUM);
|
2008-11-08 18:45:13 +01:00
|
|
|
|
|
|
|
if (!defined && !drop && !cenum->stop)
|
2007-12-30 17:41:49 +01:00
|
|
|
VALUE_conv(&SP[-1], T_VARIANT);
|
|
|
|
}
|
|
|
|
|
2008-11-08 18:45:13 +01:00
|
|
|
if (drop || cenum->stop)
|
2007-12-30 17:41:49 +01:00
|
|
|
POP();
|
2008-11-08 18:45:13 +01:00
|
|
|
|
|
|
|
return cenum->stop;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|