2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbx_exec_enum.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.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#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;
|
|
|
|
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];
|
|
|
|
|
2010-05-28 08:24:14 +02:00
|
|
|
EXEC_object(local, &class, &object);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
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];
|
|
|
|
|
2010-05-28 08:24:14 +02:00
|
|
|
defined = EXEC_object(local, &class, &object);
|
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)
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv_variant(&SP[-1]);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|