2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
|
|
|
* Copyright 2001, 2011 Fidelity Information Services, Inc *
|
|
|
|
* *
|
|
|
|
* This source code contains the intellectual property *
|
|
|
|
* of its copyright holder(s), and is made available *
|
|
|
|
* under a license. If you do not know the terms of *
|
|
|
|
* the license, please stop and do not read further. *
|
|
|
|
* *
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "mdef.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "opcode.h"
|
|
|
|
#include "toktyp.h"
|
|
|
|
#include "mdq.h"
|
|
|
|
#include "mmemory.h"
|
|
|
|
#include "advancewindow.h"
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
error_def(ERR_COLON);
|
|
|
|
error_def(ERR_SELECTFALSE);
|
|
|
|
|
2012-02-05 11:35:58 -05:00
|
|
|
LITREF octabstruct oc_tab[];
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
int f_select(oprtype *a, opctype op)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
boolean_t first_time, save_saw_side, save_shift;
|
|
|
|
unsigned int save_depth;
|
|
|
|
opctype old_op;
|
|
|
|
oprtype *cnd, endtrip, target, tmparg;
|
|
|
|
triple *oldchain, *r, *ref, *save_start, *save_start_orig, tmpchain, *triptr;
|
2012-02-05 11:35:58 -05:00
|
|
|
DCL_THREADGBL_ACCESS;
|
|
|
|
|
|
|
|
SETUP_THREADGBL_ACCESS;
|
|
|
|
save_shift = TREF(shift_side_effects);
|
2012-03-24 14:06:46 -04:00
|
|
|
save_saw_side = TREF(saw_side_effect);
|
2012-02-05 11:35:58 -05:00
|
|
|
save_depth = TREF(expr_depth);
|
|
|
|
save_start = TREF(expr_start);
|
|
|
|
save_start_orig = TREF(expr_start_orig);
|
|
|
|
TREF(shift_side_effects) = FALSE;
|
2012-03-24 14:06:46 -04:00
|
|
|
TREF(saw_side_effect) = FALSE;
|
2012-02-05 11:35:58 -05:00
|
|
|
TREF(expr_depth) = 0;
|
|
|
|
TREF(expr_start) = TREF(expr_start_orig) = NULL;
|
|
|
|
if (save_shift)
|
|
|
|
{
|
|
|
|
dqinit(&tmpchain, exorder);
|
|
|
|
oldchain = setcurtchain(&tmpchain);
|
|
|
|
}
|
|
|
|
r = maketriple(op);
|
|
|
|
first_time = TRUE;
|
|
|
|
endtrip = put_tjmp(r);
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
cnd = (oprtype *)mcalloc(SIZEOF(oprtype));
|
2012-03-24 14:06:46 -04:00
|
|
|
if (!bool_expr(FALSE, cnd))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
if (save_shift)
|
|
|
|
setcurtchain(oldchain);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-24 14:06:46 -04:00
|
|
|
if (TK_COLON != TREF(window_token))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
if (save_shift)
|
|
|
|
setcurtchain(oldchain);
|
|
|
|
stx_error(ERR_COLON);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
advancewindow();
|
2012-03-24 14:06:46 -04:00
|
|
|
if (EXPR_FAIL == expr(&tmparg, MUMPS_EXPR))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
if (save_shift)
|
|
|
|
setcurtchain(oldchain);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
assert(TRIP_REF == tmparg.oprclass);
|
|
|
|
old_op = tmparg.oprval.tref->opcode;
|
|
|
|
if (first_time)
|
|
|
|
{
|
|
|
|
if ((OC_LIT == old_op) || (oc_tab[old_op].octype & OCT_MVADDR))
|
|
|
|
{
|
|
|
|
ref = newtriple(OC_STOTEMP);
|
|
|
|
ref->operand[0] = tmparg;
|
|
|
|
tmparg = put_tref(ref);
|
|
|
|
}
|
|
|
|
r->operand[0] = target = tmparg;
|
|
|
|
first_time = FALSE;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
ref = newtriple(OC_STO);
|
|
|
|
ref->operand[0] = target;
|
|
|
|
ref->operand[1] = tmparg;
|
|
|
|
if (OC_PASSTHRU == tmparg.oprval.tref->opcode)
|
|
|
|
{
|
|
|
|
assert(TRIP_REF == tmparg.oprval.tref->operand[0].oprclass);
|
|
|
|
ref = newtriple(OC_STO);
|
|
|
|
ref->operand[0] = target;
|
|
|
|
ref->operand[1] = put_tref(tmparg.oprval.tref->operand[0].oprval.tref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ref = newtriple(OC_JMP);
|
|
|
|
ref->operand[0] = endtrip;
|
|
|
|
tnxtarg(cnd);
|
2012-03-24 14:06:46 -04:00
|
|
|
if (TK_COMMA != TREF(window_token))
|
2012-02-05 11:35:58 -05:00
|
|
|
break;
|
|
|
|
advancewindow();
|
|
|
|
}
|
|
|
|
tmparg = put_ilit(ERR_SELECTFALSE);
|
|
|
|
ref = newtriple(OC_RTERROR);
|
|
|
|
ref->operand[0] = tmparg;
|
|
|
|
ref->operand[1] = put_ilit(FALSE); /* Not a subroutine reference */
|
|
|
|
ins_triple(r);
|
|
|
|
assert(!TREF(expr_depth));
|
|
|
|
TREF(shift_side_effects) = save_shift;
|
2012-03-24 14:06:46 -04:00
|
|
|
TREF(saw_side_effect) = save_saw_side;
|
2012-02-05 11:35:58 -05:00
|
|
|
TREF(expr_depth) = save_depth;
|
|
|
|
TREF(expr_start) = save_start;
|
|
|
|
TREF(expr_start_orig) = save_start_orig;
|
|
|
|
if (save_shift)
|
|
|
|
{
|
|
|
|
newtriple(OC_GVSAVTARG);
|
|
|
|
setcurtchain(oldchain);
|
|
|
|
dqadd(TREF(expr_start), &tmpchain, exorder);
|
|
|
|
TREF(expr_start) = tmpchain.exorder.bl;
|
|
|
|
triptr = newtriple(OC_GVRECTARG);
|
|
|
|
triptr->operand[0] = put_tref(TREF(expr_start));
|
|
|
|
}
|
|
|
|
*a = put_tref(r);
|
|
|
|
return TRUE;
|
|
|
|
}
|