2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
2012-03-24 14:06:46 -04:00
|
|
|
* Copyright 2001, 2011 Fidelity Information Services, Inc *
|
2012-02-05 11:35:58 -05:00
|
|
|
* *
|
|
|
|
* 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 "subscript.h"
|
|
|
|
#include "advancewindow.h"
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
error_def(ERR_MAXNRSUBSCRIPTS);
|
|
|
|
error_def(ERR_RPARENMISSING);
|
|
|
|
error_def(ERR_VAREXPECTED);
|
2012-02-05 11:35:58 -05:00
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
int lvn(oprtype *a, opctype index_op, triple *parent)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
char x;
|
2012-03-24 14:06:46 -04:00
|
|
|
oprtype *sb, *sb1, *sb2, subscripts[MAX_LVSUBSCRIPTS];
|
|
|
|
triple *ref, *root, *s;
|
|
|
|
DCL_THREADGBL_ACCESS;
|
2012-02-05 11:35:58 -05:00
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
SETUP_THREADGBL_ACCESS;
|
|
|
|
if (TREF(window_token) != TK_IDENT)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
stx_error(ERR_VAREXPECTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-24 14:06:46 -04:00
|
|
|
*a = put_mvar(&(TREF(window_ident)));
|
2012-02-05 11:35:58 -05:00
|
|
|
advancewindow();
|
2012-03-24 14:06:46 -04:00
|
|
|
if (TK_LPAREN != TREF(window_token))
|
2012-02-05 11:35:58 -05:00
|
|
|
return TRUE;
|
2012-03-24 14:06:46 -04:00
|
|
|
assert(TRIP_REF == a->oprclass);
|
2012-02-05 11:35:58 -05:00
|
|
|
ref = a->oprval.tref;
|
2012-03-24 14:06:46 -04:00
|
|
|
assert(OC_VAR == ref->opcode);
|
2012-02-05 11:35:58 -05:00
|
|
|
sb1 = sb2 = subscripts;
|
|
|
|
*sb1++ = *a;
|
|
|
|
for (;;)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
if (ARRAYTOP(subscripts) <= sb1)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
stx_error(ERR_MAXNRSUBSCRIPTS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
advancewindow();
|
2012-03-24 14:06:46 -04:00
|
|
|
if (EXPR_FAIL == expr(sb1++, MUMPS_EXPR))
|
2012-02-05 11:35:58 -05:00
|
|
|
return FALSE;
|
2012-03-24 14:06:46 -04:00
|
|
|
if (TK_RPAREN == (x = TREF(window_token))) /* NOTE assignment */
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
advancewindow();
|
|
|
|
break;
|
|
|
|
}
|
2012-03-24 14:06:46 -04:00
|
|
|
if (TK_COMMA != x)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
stx_error(ERR_RPARENMISSING);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parent)
|
|
|
|
{ /* only $ORDER, $NEXT, $ZPREV have parent */
|
|
|
|
sb1--;
|
|
|
|
if (sb1 - sb2 == 1) /* only name and 1 subscript */
|
|
|
|
{ /* SRCHINDX not necessary if only 1 subscript */
|
|
|
|
sb = &parent->operand[1]; *sb = *sb1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
root = ref = newtriple(index_op);
|
|
|
|
ref->operand[0] = put_ilit((mint)(sb1 - sb2));
|
|
|
|
while (sb2 < sb1)
|
|
|
|
{
|
|
|
|
s = newtriple(OC_PARAMETER);
|
|
|
|
ref->operand[1] = put_tref(s);
|
|
|
|
s->operand[0] = *sb2++;
|
|
|
|
ref = s;
|
|
|
|
}
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
parent->operand[0] = put_tref(root);
|
|
|
|
sb = &parent->operand[1];
|
|
|
|
*sb = *sb2;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
*a = put_tref(root);
|
|
|
|
return TRUE;
|
|
|
|
}
|