4649
4678
arrayindex_AST = RefDNode(currentAST.root);
4651
c1 = comp.Constant( e1);
4680
bool constantOK = false;
4652
4682
if( c1 != NULL)
4684
DType dType = c1->Type();
4685
int typeCheck = DTypeOrder[ dType];
4686
if( dType == GDL_STRING || typeCheck >= 100)
4694
// ATTENTION: These two grab c1 (all others don't)
4695
// a bit unclean, but for maximum efficiency
4654
4696
if( c1->Rank() == 0)
4658
CArrayIndexScalar( c1));
4662
CArrayIndexIndexed( c1));
4697
ixList->push_back( new CArrayIndexScalar( c1));
4699
ixList->push_back( new CArrayIndexIndexed( c1));
4701
// prevent c1 from being deleted
4702
e1_AST->StealCData(); // ok, as #e1 is not used anymore
4706
catch( GDLException& e) {
4707
//delete c1; // owned by #e1
4666
4714
if( LoopVar( e1_AST))
4667
4716
if( e1_AST->getType() == VAR)
4668
ixList->push_back( new
4669
ArrayIndexScalar( e1_AST));
4717
ixList->push_back( new ArrayIndexScalar( e1_AST));
4671
ixList->push_back( new
4672
ArrayIndexScalarVP( e1_AST));
4719
ixList->push_back( new ArrayIndexScalarVP( e1_AST));
4675
4723
arrayindex_AST = e1_AST;
4676
ixList->push_back( new
4677
ArrayIndexIndexed());
4724
ixList->push_back( new ArrayIndexIndexed());
5423
5516
_t = _t->getNextSibling();
5425
id_text=id_AST->getText();
5427
// IsVar already tries to find the function and compile it
5428
isVar = comp.IsVar( id_text);
5432
i=LibFunIx(id_text);
5520
id_text = id_AST->getText();
5522
// IsVar is not needed, we must emit an ARRAYEXPR_FCALL even if the variable is known
5523
// (rule: Accessible functions always override variables
5524
//isVar = comp.IsVar( id_text);
5525
// isVar == true -> VAR for sure
5526
// (== false: maybe VAR nevertheless)
5528
int libIx = LibFunIx(id_text);
5435
if (_t == RefDNode(antlr::nullAST) )
5437
if (((_t->getType() == ARRAYIX))&&( isVar)) {
5438
al = (_t == ASTNULL) ? RefDNode(antlr::nullAST) : _t;
5439
arrayindex_list(_t);
5443
else if ((_t->getType() == ARRAYIX)) {
5444
el = (_t == ASTNULL) ? RefDNode(antlr::nullAST) : _t;
5445
arrayindex_list_to_parameter_list(_t, i != -1 && libFunList[ i]->NPar() == -1);
5450
throw antlr::NoViableAltException(antlr::RefAST(_t));
5532
el = (_t == ASTNULL) ? RefDNode(antlr::nullAST) : _t;
5533
arrayindex_list_to_parameter_list(_t, libIx != -1 && libFunList[ libIx]->NPar() == -1);
5454
5537
arrayexpr_fn_AST = RefDNode(currentAST.root);
5457
{ // no variable -> function call
5459
5539
// first search library functions
5460
int i=LibFunIx(id_text);
5463
5542
int nParam = 0;
5464
5543
if( el_AST != RefDNode(antlr::nullAST))
5465
5544
nParam = el_AST->GetNParam();
5467
int libParam = libFunList[i]->NPar();
5546
int libParam = libFunList[libIx]->NPar();
5547
int libParamMin = libFunList[libIx]->NParMin();
5468
5548
if( libParam != -1 && nParam > libParam)
5469
throw GDLException( aIn, libFunList[i]->Name() + ": Too many arguments.");
5549
throw GDLException( aIn, libFunList[libIx]->Name() + ": Too many arguments.");
5550
if( libParam != -1 && nParam < libParamMin)
5551
throw GDLException( aIn, libFunList[libIx]->Name() + ": Too few arguments.");
5471
id_AST->SetLibFun( libFunList[i]);
5472
if( libFunList[ i]->RetNew())
5553
id_AST->SetLibFun( libFunList[libIx]);
5554
if( libFunList[ libIx]->RetNew())
5556
if( libFunList[ libIx]->Name() == "N_ELEMENTS")
5557
id_AST->setType( FCALL_LIB_N_ELEMENTS);
5558
else if( libFunList[ libIx]->DirectCall())
5559
id_AST->setType( FCALL_LIB_DIRECT);
5474
5561
id_AST->setType( FCALL_LIB_RETNEW);
5476
RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5562
arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5477
5563
// #([/*FCALL_LIB_RETNEW,"fcall_lib_retnew"],*/ id, el);
5481
5567
id_AST->setType( FCALL_LIB);
5483
RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5568
arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5484
5569
// #(/*[FCALL_LIB,"fcall_lib"],*/ id, el);
5489
5572
// then search user defined functions
5576
int funIx=FunIx( id_text);
5578
// we use #id for the FCALL part
5490
5579
id_AST->setType( FCALL);
5492
id_AST->SetFunIx(i);
5495
RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5496
// #(/*[FCALL,"fcall"],*/ id, el);
5500
{ // variable -> arrayexpr
5503
va_AST=astFactory->create(VAR,id_AST->getText());
5504
// #va=#[VAR,id->getText()];
5508
RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(astFactory->create(ARRAYEXPR,"arrayexpr")))->add(antlr::RefAST(va_AST))->add(antlr::RefAST(al_AST))));
5580
id_AST->SetFunIx( funIx);
5582
if( funIx != -1) // found -> FCALL
5584
arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5585
// #(/*[FCALL,"fcall"],*/ id, el);
5587
else // function not found -> still ambiguous
5589
// _t = mark; // rewind to parse again
5590
arrayindex_list( mark);
5592
arrayindex_listAST = returnAST;
5595
va2=astFactory->create( VAR, id_text);
5596
// #va=#[VAR,id->getText()];
5597
comp.Var( va2); // we declare the variable here!
5598
// if IsVar() still would be used this would lead to surprising behavior:
5599
// e. g.: function_call(42) & function_call(43)
5600
// The first (42) would be an ARRAYEXPR_FCALL the 2nd (43) an ARRAYEXPR
5601
// if then at runtime function "function_call" is known,
5602
// it will be called only at the first appearance of the call.
5603
// that's why we cannot allow unambiguous VAR here
5605
vaAlt = RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(astFactory->create(ARRAYEXPR,"arrayexpr")))->add(antlr::RefAST(va2))->add(antlr::RefAST(arrayindex_listAST))));
5606
fn = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5608
arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(aIn_AST))->add(antlr::RefAST(vaAlt))->add(antlr::RefAST(fn))));
5612
// // not valid s. a. (kept for reference): unambiguous VAR
5613
// { // variable -> arrayexpr
5615
// #va=astFactory->create(VAR,#id->getText());
5616
// // #va=#[VAR,id->getText()];
5619
// #([ARRAYEXPR,"arrayexpr"], va, al);
5511
5622
currentAST.root = arrayexpr_fn_AST;
5512
5623
if ( arrayexpr_fn_AST!=RefDNode(antlr::nullAST) &&
7306
7446
// MATRIX_OP2_EQ MINUS_EQ MOD_OP_EQ NE_OP_EQ OR_OP_EQ PLUS_EQ POW_EQ SLASH_EQ
7308
7448
const antlr::BitSet GDLTreeParser::_tokenSet_0(_tokenSet_0_data_,12);
7309
const unsigned long GDLTreeParser::_tokenSet_1_data_[] = { 739116576UL, 69468224UL, 9371654UL, 139433088UL, 37748734UL, 0UL, 1048256UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
7310
// ASSIGN ARRAYDEF ARRAYDEF_CONST ARRAYEXPR ARRAYEXPR_FN ARRAYEXPR_MFCALL
7311
// CONSTANT DEREF EXPR FCALL MFCALL MFCALL_PARENT NSTRUC_REF POSTDEC POSTINC
7312
// STRUC SYSVAR UMINUS VAR "and" "eq" "ge" "gt" "le" "lt" "mod" "ne" "not"
7313
// "or" "xor" DEC INC AND_OP_EQ ASTERIX_EQ EQ_OP_EQ GE_OP_EQ GTMARK_EQ
7314
// GT_OP_EQ LE_OP_EQ LTMARK_EQ LT_OP_EQ MATRIX_OP1_EQ MATRIX_OP2_EQ MINUS_EQ
7315
// MOD_OP_EQ NE_OP_EQ OR_OP_EQ PLUS_EQ POW_EQ SLASH_EQ XOR_OP_EQ SLASH
7316
// ASTERIX DOT POW MATRIX_OP1 MATRIX_OP2 PLUS MINUS LTMARK GTMARK LOG_NEG
7317
// LOG_AND LOG_OR QUESTION
7449
const unsigned long GDLTreeParser::_tokenSet_1_data_[] = { 739116576UL, 555747392UL, 74973232UL, 1115464704UL, 301989872UL, 0UL, 8386048UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
7450
// ASSIGN ARRAYDEF ARRAYDEF_CONST ARRAYEXPR ARRAYEXPR_FCALL ARRAYEXPR_MFCALL
7451
// CONSTANT DEREF EXPR FCALL GDLNULL MFCALL MFCALL_PARENT NSTRUC_REF POSTDEC
7452
// POSTINC STRUC SYSVAR UMINUS VAR "and" "eq" "ge" "gt" "le" "lt" "mod"
7453
// "ne" "not" "or" "xor" DEC INC AND_OP_EQ ASTERIX_EQ EQ_OP_EQ GE_OP_EQ
7454
// GTMARK_EQ GT_OP_EQ LE_OP_EQ LTMARK_EQ LT_OP_EQ MATRIX_OP1_EQ MATRIX_OP2_EQ
7455
// MINUS_EQ MOD_OP_EQ NE_OP_EQ OR_OP_EQ PLUS_EQ POW_EQ SLASH_EQ XOR_OP_EQ
7456
// SLASH ASTERIX DOT POW MATRIX_OP1 MATRIX_OP2 PLUS MINUS LTMARK GTMARK
7457
// LOG_NEG LOG_AND LOG_OR QUESTION
7318
7458
const antlr::BitSet GDLTreeParser::_tokenSet_1(_tokenSet_1_data_,16);