/gdl-0.9.2/src/GDLInterpreter.cpp.cvs

# · Unknown · 5517 lines · 4959 code · 558 blank · 0 comment · 0 complexity · 34ac64aaa160190a9fa9d9d390b2093a MD5 · raw file

  1. /* $ANTLR 2.7.7 (20110618): "gdlc.i.g" -> "GDLInterpreter.cpp"$ */
  2. // gets inserted before the antlr generated includes in the cpp file
  3. #include "includefirst.hpp"
  4. #include "GDLInterpreter.hpp"
  5. #include <antlr/Token.hpp>
  6. #include <antlr/AST.hpp>
  7. #include <antlr/NoViableAltException.hpp>
  8. #include <antlr/MismatchedTokenException.hpp>
  9. #include <antlr/SemanticException.hpp>
  10. #include <antlr/BitSet.hpp>
  11. // gets inserted after the antlr generated includes in the cpp file
  12. #include "dinterpreter.hpp"
  13. #include "prognodeexpr.hpp"
  14. #include <cassert>
  15. // tweaking ANTLR
  16. #define ASTNULL NULLProgNodeP
  17. #define ProgNodeP( xxx ) NULL /* ProgNodeP(antlr::nullAST) */
  18. #define RefAST( xxx) ConvertAST( xxx) /* antlr::RefAST( Ref type) */
  19. #define match( a, b) /* remove from source */
  20. using namespace std;
  21. GDLInterpreter::GDLInterpreter()
  22. : antlr::TreeParser() {
  23. }
  24. RetCode GDLInterpreter::interactive(ProgNodeP _t) {
  25. RetCode retCode;
  26. ProgNodeP interactive_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  27. for (; _t != NULL;) {
  28. //_t->setLine(0);
  29. retCode=statement(_t);
  30. _t = _retTree;
  31. if( retCode != RC_OK) break; // break out if non-regular
  32. }
  33. _retTree = _t;
  34. return retCode;
  35. { // ( ... )+
  36. int _cnt3=0;
  37. for (;;) {
  38. if (_t == ProgNodeP(antlr::nullAST) )
  39. _t = ASTNULL;
  40. if ((_tokenSet_0.member(_t->getType()))) {
  41. retCode=statement(_t);
  42. _t = _retTree;
  43. if( retCode != RC_OK) break; // break out if non-regular
  44. }
  45. else {
  46. if ( _cnt3>=1 ) { goto _loop3; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
  47. }
  48. _cnt3++;
  49. }
  50. _loop3:;
  51. } // ( ... )+
  52. _retTree = _t;
  53. return retCode;
  54. }
  55. RetCode GDLInterpreter::statement(ProgNodeP _t) {
  56. RetCode retCode;
  57. ProgNodeP statement_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  58. // ProgNodeP& actPos = statement_AST_in;
  59. assert( _t != NULL);
  60. ProgNodeP last;
  61. _retTree = _t;
  62. // if( callStack.back()->GetLineNumber() == 0)
  63. // if( _t->getLine() != 0)
  64. // callStack.back()->SetLineNumber( _t->getLine());
  65. try { // for error handling
  66. do {
  67. // if( _t->getLine() != 0)
  68. // callStack.back()->SetLineNumber( _t->getLine());
  69. last = _retTree;
  70. // track actual line number
  71. callStack.back()->SetLineNumber( last->getLine());
  72. retCode = last->Run(); // Run() sets _retTree
  73. }
  74. while(
  75. _retTree != NULL &&
  76. retCode == RC_OK &&
  77. !(sigControlC && interruptEnable) &&
  78. (debugMode == DEBUG_CLEAR));
  79. if( _retTree != NULL)
  80. last = _retTree;
  81. goto afterStatement;
  82. {
  83. if (_t == ProgNodeP(antlr::nullAST) )
  84. _t = ASTNULL;
  85. switch ( _t->getType()) {
  86. case ASSIGN:
  87. {
  88. ProgNodeP tmp1_AST_in = _t;
  89. match(antlr::RefAST(_t),ASSIGN);
  90. _t = _t->getNextSibling();
  91. break;
  92. }
  93. case ASSIGN_ARRAYEXPR_MFCALL:
  94. {
  95. ProgNodeP tmp2_AST_in = _t;
  96. match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
  97. _t = _t->getNextSibling();
  98. break;
  99. }
  100. case ASSIGN_REPLACE:
  101. {
  102. ProgNodeP tmp3_AST_in = _t;
  103. match(antlr::RefAST(_t),ASSIGN_REPLACE);
  104. _t = _t->getNextSibling();
  105. break;
  106. }
  107. case PCALL_LIB:
  108. {
  109. ProgNodeP tmp4_AST_in = _t;
  110. match(antlr::RefAST(_t),PCALL_LIB);
  111. _t = _t->getNextSibling();
  112. break;
  113. }
  114. case MPCALL:
  115. {
  116. ProgNodeP tmp5_AST_in = _t;
  117. match(antlr::RefAST(_t),MPCALL);
  118. _t = _t->getNextSibling();
  119. break;
  120. }
  121. case MPCALL_PARENT:
  122. {
  123. ProgNodeP tmp6_AST_in = _t;
  124. match(antlr::RefAST(_t),MPCALL_PARENT);
  125. _t = _t->getNextSibling();
  126. break;
  127. }
  128. case PCALL:
  129. {
  130. ProgNodeP tmp7_AST_in = _t;
  131. match(antlr::RefAST(_t),PCALL);
  132. _t = _t->getNextSibling();
  133. break;
  134. }
  135. case DEC:
  136. {
  137. ProgNodeP tmp8_AST_in = _t;
  138. match(antlr::RefAST(_t),DEC);
  139. _t = _t->getNextSibling();
  140. break;
  141. }
  142. case INC:
  143. {
  144. ProgNodeP tmp9_AST_in = _t;
  145. match(antlr::RefAST(_t),INC);
  146. _t = _t->getNextSibling();
  147. break;
  148. }
  149. case FOR:
  150. {
  151. ProgNodeP tmp10_AST_in = _t;
  152. match(antlr::RefAST(_t),FOR);
  153. _t = _t->getNextSibling();
  154. break;
  155. }
  156. case FOR_LOOP:
  157. {
  158. ProgNodeP tmp11_AST_in = _t;
  159. match(antlr::RefAST(_t),FOR_LOOP);
  160. _t = _t->getNextSibling();
  161. break;
  162. }
  163. case FOREACH:
  164. {
  165. ProgNodeP tmp12_AST_in = _t;
  166. match(antlr::RefAST(_t),FOREACH);
  167. _t = _t->getNextSibling();
  168. break;
  169. }
  170. case FOREACH_LOOP:
  171. {
  172. ProgNodeP tmp13_AST_in = _t;
  173. match(antlr::RefAST(_t),FOREACH_LOOP);
  174. _t = _t->getNextSibling();
  175. break;
  176. }
  177. case FOREACH_INDEX:
  178. {
  179. ProgNodeP tmp14_AST_in = _t;
  180. match(antlr::RefAST(_t),FOREACH_INDEX);
  181. _t = _t->getNextSibling();
  182. break;
  183. }
  184. case FOREACH_INDEX_LOOP:
  185. {
  186. ProgNodeP tmp15_AST_in = _t;
  187. match(antlr::RefAST(_t),FOREACH_INDEX_LOOP);
  188. _t = _t->getNextSibling();
  189. break;
  190. }
  191. case FOR_STEP:
  192. {
  193. ProgNodeP tmp16_AST_in = _t;
  194. match(antlr::RefAST(_t),FOR_STEP);
  195. _t = _t->getNextSibling();
  196. break;
  197. }
  198. case FOR_STEP_LOOP:
  199. {
  200. ProgNodeP tmp17_AST_in = _t;
  201. match(antlr::RefAST(_t),FOR_STEP_LOOP);
  202. _t = _t->getNextSibling();
  203. break;
  204. }
  205. case REPEAT:
  206. {
  207. ProgNodeP tmp18_AST_in = _t;
  208. match(antlr::RefAST(_t),REPEAT);
  209. _t = _t->getNextSibling();
  210. break;
  211. }
  212. case REPEAT_LOOP:
  213. {
  214. ProgNodeP tmp19_AST_in = _t;
  215. match(antlr::RefAST(_t),REPEAT_LOOP);
  216. _t = _t->getNextSibling();
  217. break;
  218. }
  219. case WHILE:
  220. {
  221. ProgNodeP tmp20_AST_in = _t;
  222. match(antlr::RefAST(_t),WHILE);
  223. _t = _t->getNextSibling();
  224. break;
  225. }
  226. case IF:
  227. {
  228. ProgNodeP tmp21_AST_in = _t;
  229. match(antlr::RefAST(_t),IF);
  230. _t = _t->getNextSibling();
  231. break;
  232. }
  233. case IF_ELSE:
  234. {
  235. ProgNodeP tmp22_AST_in = _t;
  236. match(antlr::RefAST(_t),IF_ELSE);
  237. _t = _t->getNextSibling();
  238. break;
  239. }
  240. case CASE:
  241. {
  242. ProgNodeP tmp23_AST_in = _t;
  243. match(antlr::RefAST(_t),CASE);
  244. _t = _t->getNextSibling();
  245. break;
  246. }
  247. case SWITCH:
  248. {
  249. ProgNodeP tmp24_AST_in = _t;
  250. match(antlr::RefAST(_t),SWITCH);
  251. _t = _t->getNextSibling();
  252. break;
  253. }
  254. case BLOCK:
  255. {
  256. ProgNodeP tmp25_AST_in = _t;
  257. match(antlr::RefAST(_t),BLOCK);
  258. _t = _t->getNextSibling();
  259. break;
  260. }
  261. case LABEL:
  262. {
  263. ProgNodeP tmp26_AST_in = _t;
  264. match(antlr::RefAST(_t),LABEL);
  265. _t = _t->getNextSibling();
  266. break;
  267. }
  268. case ON_IOERROR_NULL:
  269. {
  270. ProgNodeP tmp27_AST_in = _t;
  271. match(antlr::RefAST(_t),ON_IOERROR_NULL);
  272. _t = _t->getNextSibling();
  273. break;
  274. }
  275. case ON_IOERROR:
  276. {
  277. ProgNodeP tmp28_AST_in = _t;
  278. match(antlr::RefAST(_t),ON_IOERROR);
  279. _t = _t->getNextSibling();
  280. break;
  281. }
  282. case BREAK:
  283. {
  284. ProgNodeP tmp29_AST_in = _t;
  285. match(antlr::RefAST(_t),BREAK);
  286. _t = _t->getNextSibling();
  287. break;
  288. }
  289. case CONTINUE:
  290. {
  291. ProgNodeP tmp30_AST_in = _t;
  292. match(antlr::RefAST(_t),CONTINUE);
  293. _t = _t->getNextSibling();
  294. break;
  295. }
  296. case GOTO:
  297. {
  298. ProgNodeP tmp31_AST_in = _t;
  299. match(antlr::RefAST(_t),GOTO);
  300. _t = _t->getNextSibling();
  301. break;
  302. }
  303. case RETF:
  304. {
  305. ProgNodeP tmp32_AST_in = _t;
  306. match(antlr::RefAST(_t),RETF);
  307. _t = _t->getNextSibling();
  308. break;
  309. }
  310. case RETP:
  311. {
  312. ProgNodeP tmp33_AST_in = _t;
  313. match(antlr::RefAST(_t),RETP);
  314. _t = _t->getNextSibling();
  315. break;
  316. }
  317. default:
  318. {
  319. throw antlr::NoViableAltException(antlr::RefAST(_t));
  320. }
  321. }
  322. }
  323. afterStatement:;
  324. // possible optimization: make sigControlC a debugMode
  325. if( interruptEnable && sigControlC)
  326. {
  327. DebugMsg( last, "Interrupted at: ");
  328. sigControlC = false;
  329. retCode = NewInterpreterInstance( last->getLine());//-1);
  330. }
  331. else if( debugMode != DEBUG_CLEAR)
  332. {
  333. if( debugMode == DEBUG_STOP)
  334. {
  335. DebugMsg( last, "Stop encountered: ");
  336. if( !interruptEnable)
  337. debugMode = DEBUG_PROCESS_STOP;
  338. }
  339. if( debugMode == DEBUG_STEP)
  340. {
  341. if( stepCount == 1)
  342. {
  343. stepCount = 0;
  344. DebugMsg( last, "Stepped to: ");
  345. debugMode = DEBUG_CLEAR;
  346. retCode = NewInterpreterInstance( last->getLine());//-1);
  347. }
  348. else
  349. {
  350. --stepCount;
  351. #ifdef GDL_DEBUG
  352. std::cout << "stepCount-- = " << stepCount << std::endl;
  353. #endif
  354. }
  355. }
  356. else
  357. if( interruptEnable)
  358. {
  359. if( debugMode == DEBUG_PROCESS_STOP)
  360. {
  361. DebugMsg( last, "Stepped to: ");
  362. }
  363. debugMode = DEBUG_CLEAR;
  364. retCode = NewInterpreterInstance( last->getLine());//-1);
  365. }
  366. else
  367. {
  368. retCode = RC_ABORT;
  369. }
  370. }
  371. return retCode;
  372. }
  373. catch ( GDLException& e) {
  374. // reset _retTree to last statement
  375. // (might otherwise be inside an expression in which case
  376. // .CONTINUE does not work)
  377. _retTree = last;
  378. if( dynamic_cast< GDLIOException*>( &e) != NULL)
  379. {
  380. // set the jump target - also logs the jump
  381. ProgNodeP onIOErr =
  382. static_cast<EnvUDT*>(callStack.back())->GetIOError();
  383. if( onIOErr != NULL)
  384. {
  385. SysVar::SetErr_String( e.getMessage());
  386. _retTree = onIOErr;
  387. return RC_OK;
  388. }
  389. }
  390. EnvUDT* targetEnv = e.GetTargetEnv();
  391. if( targetEnv == NULL)
  392. {
  393. // initial exception, set target env
  394. // look if ON_ERROR is set somewhere
  395. for( EnvStackT::reverse_iterator i = callStack.rbegin();
  396. i != callStack.rend(); ++i)
  397. {
  398. DLong oE = -1;
  399. EnvUDT* envUD = dynamic_cast<EnvUDT*>(*i);
  400. if( envUD != NULL)
  401. oE = envUD->GetOnError();
  402. if( oE != -1)
  403. { // oE was set
  404. // 0 -> stop here
  405. if( oE == 0)
  406. targetEnv = static_cast<EnvUDT*>(callStack.back());
  407. // 1 -> $MAIN$
  408. else if( oE == 1)
  409. {
  410. EnvUDT* cS_begin =
  411. static_cast<EnvUDT*>(*callStack.begin());
  412. targetEnv = cS_begin;
  413. }
  414. // 2 -> caller of routine which called ON_ERROR
  415. else if( oE == 2)
  416. {
  417. // set to caller, handle nested
  418. while( static_cast<EnvUDT*>(*(++i))->GetOnError() == 2
  419. && i != callStack.rend());
  420. if( i == callStack.rend())
  421. {
  422. EnvUDT* cS_begin =
  423. static_cast<EnvUDT*>(*callStack.begin());
  424. targetEnv = cS_begin;
  425. }
  426. else
  427. {
  428. EnvUDT* iUDT = static_cast<EnvUDT*>(*i);
  429. targetEnv = iUDT;
  430. }
  431. }
  432. // 3 -> routine which called ON_ERROR
  433. else if( oE == 3)
  434. {
  435. EnvUDT* iUDT = static_cast<EnvUDT*>(*i);
  436. targetEnv = iUDT;
  437. }
  438. // State where error occured
  439. // if( e.getLine() == 0 && _t != NULL)
  440. // e.SetLine( _t->getLine());
  441. // if( e.getLine() == 0 && _retTree != NULL)
  442. // e.SetLine( _retTree->getLine());
  443. if( e.getLine() == 0 && last != NULL)
  444. e.SetLine( last->getLine());
  445. if( interruptEnable)
  446. ReportError(e, "Error occurred at:");
  447. // remeber where to stop
  448. e.SetTargetEnv( targetEnv);
  449. if( targetEnv->GetLineNumber() != 0)
  450. e.SetLine( targetEnv->GetLineNumber());
  451. // ProgNodeP errorNodeP = targetEnv->CallingNode();
  452. // e.SetErrorNodeP( errorNodeP);
  453. // break on first occurence of set oE
  454. break;
  455. }
  456. }
  457. }
  458. if( targetEnv != NULL && targetEnv != callStack.back())
  459. {
  460. throw e; // rethrow
  461. }
  462. lib::write_journal( GetClearActualLine());
  463. // many low level routines don't have errorNode info
  464. // set line number here in this case
  465. // if( e.getLine() == 0 && _t != NULL)
  466. // e.SetLine( _t->getLine());
  467. // if( e.getLine() == 0 && _retTree != NULL)
  468. // e.SetLine( _retTree->getLine());
  469. // if( e.getLine() == 0 && actPos != NULL)
  470. // e.SetLine( actPos->getLine());
  471. if( interruptEnable)
  472. {
  473. // tell where we are
  474. ReportError(e, "Execution halted at:", targetEnv == NULL);
  475. retCode = NewInterpreterInstance(e.getLine());//-1);
  476. }
  477. else
  478. {
  479. DString msgPrefix = SysVar::MsgPrefix();
  480. if( e.Prefix())
  481. {
  482. std::cerr << msgPrefix << e.toString() << std::endl;
  483. lib::write_journal_comment(msgPrefix+e.toString());
  484. }
  485. else
  486. {
  487. std::cerr << e.toString() << std::endl;
  488. lib::write_journal_comment(e.toString());
  489. }
  490. retCode = RC_ABORT;
  491. }
  492. return retCode;
  493. }
  494. _retTree = _t;
  495. return retCode;
  496. }
  497. RetCode GDLInterpreter::execute(ProgNodeP _t) {
  498. RetCode retCode;
  499. ProgNodeP execute_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  500. // RetCode retCode;
  501. ValueGuard<bool> guard( interruptEnable);
  502. interruptEnable = false;
  503. return statement_list(_t);
  504. retCode=statement_list(_t);
  505. _t = _retTree;
  506. _retTree = _t;
  507. return retCode;
  508. }
  509. RetCode GDLInterpreter::statement_list(ProgNodeP _t) {
  510. RetCode retCode;
  511. ProgNodeP statement_list_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  512. for (; _t != NULL;) {
  513. retCode=statement(_t);
  514. _t = _retTree;
  515. if( retCode != RC_OK) break; // break out if non-regular
  516. }
  517. _retTree = _t;
  518. return retCode;
  519. { // ( ... )+
  520. int _cnt16=0;
  521. for (;;) {
  522. if (_t == ProgNodeP(antlr::nullAST) )
  523. _t = ASTNULL;
  524. if ((_tokenSet_0.member(_t->getType()))) {
  525. retCode=statement(_t);
  526. _t = _retTree;
  527. }
  528. else {
  529. if ( _cnt16>=1 ) { goto _loop16; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
  530. }
  531. _cnt16++;
  532. }
  533. _loop16:;
  534. } // ( ... )+
  535. _retTree = _t;
  536. return retCode;
  537. }
  538. BaseGDL* GDLInterpreter::call_fun(ProgNodeP _t) {
  539. BaseGDL* res;
  540. ProgNodeP call_fun_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  541. res = NULL;
  542. returnValue = NULL;
  543. RetCode retCode;
  544. for (; _t != NULL;) {
  545. retCode=statement(_t);
  546. // if( retCode == RC_RETURN)
  547. if( retCode >= RC_RETURN)
  548. {
  549. res=returnValue;
  550. returnValue=NULL;
  551. break;
  552. }
  553. _t = _retTree;
  554. }
  555. // default return value if none was set
  556. if( res == NULL) res = new DIntGDL( 0);
  557. _retTree = _t;
  558. return res;
  559. { // ( ... )*
  560. for (;;) {
  561. if (_t == ProgNodeP(antlr::nullAST) )
  562. _t = ASTNULL;
  563. if ((_tokenSet_0.member(_t->getType()))) {
  564. retCode=statement(_t);
  565. _t = _retTree;
  566. // if( retCode == RC_RETURN)
  567. if( retCode >= RC_RETURN)
  568. {
  569. res=returnValue;
  570. returnValue=NULL;
  571. break;
  572. }
  573. }
  574. else {
  575. goto _loop7;
  576. }
  577. }
  578. _loop7:;
  579. } // ( ... )*
  580. // default return value if none was set
  581. if( res == NULL) res = new DIntGDL( 0);
  582. _retTree = _t;
  583. return res;
  584. }
  585. BaseGDL** GDLInterpreter::call_lfun(ProgNodeP _t) {
  586. BaseGDL** res;
  587. ProgNodeP call_lfun_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  588. res = NULL;
  589. returnValueL = NULL;
  590. RetCode retCode;
  591. ProgNodeP in = _t;
  592. for (; _t != NULL;) {
  593. retCode=statement(_t);
  594. _t = _retTree;
  595. // if( retCode == RC_RETURN)
  596. if( retCode >= RC_RETURN)
  597. {
  598. res=returnValueL;
  599. returnValueL=NULL;
  600. break;
  601. }
  602. }
  603. // default return value if none was set
  604. if( res == NULL)
  605. throw GDLException( in, "Function "+
  606. callStack.back()->GetProName()+
  607. " must return a left-value in this context.",false,false);
  608. _retTree = _t;
  609. return res;
  610. { // ( ... )*
  611. for (;;) {
  612. if (_t == ProgNodeP(antlr::nullAST) )
  613. _t = ASTNULL;
  614. if ((_tokenSet_0.member(_t->getType()))) {
  615. retCode=statement(_t);
  616. _t = _retTree;
  617. }
  618. else {
  619. goto _loop10;
  620. }
  621. }
  622. _loop10:;
  623. } // ( ... )*
  624. _retTree = _t;
  625. return res;
  626. }
  627. void GDLInterpreter::call_pro(ProgNodeP _t) {
  628. ProgNodeP call_pro_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  629. RetCode retCode;
  630. for (; _t != NULL;) {
  631. retCode=statement(_t);
  632. _t = _retTree;
  633. // added RC_ABORT here
  634. if( retCode >= RC_RETURN) break;
  635. }
  636. _retTree = _t;
  637. return;
  638. { // ( ... )*
  639. for (;;) {
  640. if (_t == ProgNodeP(antlr::nullAST) )
  641. _t = ASTNULL;
  642. if ((_tokenSet_0.member(_t->getType()))) {
  643. retCode=statement(_t);
  644. _t = _retTree;
  645. }
  646. else {
  647. goto _loop13;
  648. }
  649. }
  650. _loop13:;
  651. } // ( ... )*
  652. _retTree = _t;
  653. }
  654. BaseGDL** GDLInterpreter::l_deref(ProgNodeP _t) {
  655. BaseGDL** res;
  656. ProgNodeP l_deref_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  657. ProgNodeP retTree = _t->getNextSibling();
  658. EnvBaseT* actEnv = callStack.back()->GetNewEnv();
  659. if( actEnv == NULL) actEnv = callStack.back();
  660. assert( actEnv != NULL);
  661. auto_ptr<BaseGDL> e1_guard;
  662. BaseGDL* e1;
  663. ProgNodeP evalExpr = _t->getFirstChild();
  664. if( NonCopyNode( evalExpr->getType()))
  665. {
  666. e1 = evalExpr->EvalNC();
  667. }
  668. else if( evalExpr->getType() == GDLTokenTypes::FCALL_LIB)
  669. {
  670. e1=lib_function_call(evalExpr);
  671. if( e1 == NULL) // ROUTINE_NAMES
  672. throw GDLException( evalExpr, "Undefined return value", true, false);
  673. if( !callStack.back()->Contains( e1))
  674. {
  675. // if( actEnv != NULL)
  676. actEnv->Guard( e1);
  677. // else
  678. // e1_guard.reset( e1);
  679. }
  680. }
  681. else
  682. {
  683. e1 = evalExpr->Eval();
  684. // if( actEnv != NULL)
  685. actEnv->Guard( e1);
  686. // else
  687. // e1_guard.reset(e1);
  688. }
  689. if( e1 == NULL || e1->Type() != PTR)
  690. throw GDLException( evalExpr, "Pointer type required"
  691. " in this context: "+Name(e1),true,false);
  692. DPtrGDL* ptr=static_cast<DPtrGDL*>(e1);
  693. DPtr sc;
  694. if( !ptr->Scalar(sc))
  695. throw GDLException( _t, "Expression must be a "
  696. "scalar in this context: "+Name(e1),true,false);
  697. if( sc == 0)
  698. throw GDLException( _t, "Unable to dereference"
  699. " NULL pointer: "+Name(e1),true,false);
  700. try
  701. {
  702. res = &GetHeap(sc);
  703. }
  704. catch( HeapException)
  705. {
  706. throw GDLException( _t, "Invalid pointer: "+Name(e1),true,false);
  707. }
  708. _retTree = retTree;
  709. return res;
  710. {
  711. ProgNodeP tmp34_AST_in = _t;
  712. match(antlr::RefAST(_t),DEREF);
  713. _t = _t->getNextSibling();
  714. }
  715. _retTree = _t;
  716. return res;
  717. }
  718. BaseGDL** GDLInterpreter::l_ret_expr(ProgNodeP _t) {
  719. BaseGDL** res;
  720. ProgNodeP l_ret_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  721. ProgNodeP varPtr = ProgNodeP(antlr::nullAST);
  722. ProgNodeP var = ProgNodeP(antlr::nullAST);
  723. BaseGDL* e1;
  724. if (_t == ProgNodeP(antlr::nullAST) )
  725. _t = ASTNULL;
  726. switch ( _t->getType()) {
  727. case DEREF:
  728. {
  729. res=l_deref(_t);
  730. _t = _retTree;
  731. break;
  732. }
  733. case QUESTION:
  734. {
  735. ProgNodeP __t22 = _t;
  736. ProgNodeP tmp35_AST_in = _t;
  737. match(antlr::RefAST(_t),QUESTION);
  738. _t = _t->getFirstChild();
  739. e1=expr(_t);
  740. _t = _retTree;
  741. auto_ptr<BaseGDL> e1_guard(e1);
  742. if( e1->True())
  743. {
  744. res=l_ret_expr(_t);
  745. }
  746. else
  747. {
  748. _t=_t->GetNextSibling(); // jump over 1st expression
  749. res=l_ret_expr(_t);
  750. }
  751. _t = __t22;
  752. _t = _t->getNextSibling();
  753. break;
  754. }
  755. case ARRAYEXPR_MFCALL:
  756. {
  757. res=l_arrayexpr_mfcall_as_mfcall(_t);
  758. _t = _retTree;
  759. break;
  760. }
  761. case FCALL:
  762. case FCALL_LIB:
  763. case MFCALL:
  764. case MFCALL_PARENT:
  765. {
  766. res=l_function_call(_t);
  767. _t = _retTree;
  768. // here a local to the actual environment could be returned
  769. if( callStack.back()->IsLocalKW( res))
  770. throw GDLException( _t,
  771. "Attempt to return indirectly a local variable "
  772. "from left-function.",true,false);
  773. break;
  774. }
  775. case VARPTR:
  776. {
  777. varPtr = _t;
  778. match(antlr::RefAST(_t),VARPTR);
  779. _t = _t->getNextSibling();
  780. res=&varPtr->var->Data(); // returns BaseGDL* of var (DVar*)
  781. break;
  782. }
  783. case VAR:
  784. {
  785. var = _t;
  786. match(antlr::RefAST(_t),VAR);
  787. _t = _t->getNextSibling();
  788. // check if variable is non-local
  789. // (because it will be invalid after return otherwise)
  790. if( !callStack.back()->GlobalKW(var->varIx))
  791. throw GDLException( _t,
  792. "Attempt to return a non-global variable from left-function.",true,false);
  793. res=&callStack.back()->GetKW(var->varIx);
  794. break;
  795. }
  796. case ASSIGN:
  797. {
  798. ProgNodeP __t23 = _t;
  799. ProgNodeP tmp36_AST_in = _t;
  800. match(antlr::RefAST(_t),ASSIGN);
  801. _t = _t->getFirstChild();
  802. auto_ptr<BaseGDL> r_guard;
  803. {
  804. if (_t == ProgNodeP(antlr::nullAST) )
  805. _t = ASTNULL;
  806. switch ( _t->getType()) {
  807. case ASSIGN:
  808. case ASSIGN_REPLACE:
  809. case ASSIGN_ARRAYEXPR_MFCALL:
  810. case ARRAYDEF:
  811. case ARRAYEXPR:
  812. case ARRAYEXPR_MFCALL:
  813. case CONSTANT:
  814. case DEREF:
  815. case EXPR:
  816. case FCALL:
  817. case FCALL_LIB_RETNEW:
  818. case MFCALL:
  819. case MFCALL_PARENT:
  820. case NSTRUC:
  821. case NSTRUC_REF:
  822. case POSTDEC:
  823. case POSTINC:
  824. case STRUC:
  825. case SYSVAR:
  826. case VAR:
  827. case VARPTR:
  828. case DEC:
  829. case INC:
  830. case DOT:
  831. case QUESTION:
  832. {
  833. e1=tmp_expr(_t);
  834. _t = _retTree;
  835. r_guard.reset( e1);
  836. break;
  837. }
  838. case FCALL_LIB:
  839. {
  840. e1=lib_function_call(_t);
  841. _t = _retTree;
  842. if( !callStack.back()->Contains( e1))
  843. r_guard.reset( e1);
  844. break;
  845. }
  846. default:
  847. {
  848. throw antlr::NoViableAltException(antlr::RefAST(_t));
  849. }
  850. }
  851. }
  852. res=l_ret_expr(_t);
  853. _t = _retTree;
  854. if( e1 != (*res))
  855. {
  856. delete *res;
  857. *res = e1;
  858. }
  859. r_guard.release();
  860. _t = __t23;
  861. _t = _t->getNextSibling();
  862. break;
  863. }
  864. case ASSIGN_ARRAYEXPR_MFCALL:
  865. {
  866. ProgNodeP __t25 = _t;
  867. ProgNodeP tmp37_AST_in = _t;
  868. match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
  869. _t = _t->getFirstChild();
  870. auto_ptr<BaseGDL> r_guard;
  871. {
  872. if (_t == ProgNodeP(antlr::nullAST) )
  873. _t = ASTNULL;
  874. switch ( _t->getType()) {
  875. case ASSIGN:
  876. case ASSIGN_REPLACE:
  877. case ASSIGN_ARRAYEXPR_MFCALL:
  878. case ARRAYDEF:
  879. case ARRAYEXPR:
  880. case ARRAYEXPR_MFCALL:
  881. case CONSTANT:
  882. case DEREF:
  883. case EXPR:
  884. case FCALL:
  885. case FCALL_LIB_RETNEW:
  886. case MFCALL:
  887. case MFCALL_PARENT:
  888. case NSTRUC:
  889. case NSTRUC_REF:
  890. case POSTDEC:
  891. case POSTINC:
  892. case STRUC:
  893. case SYSVAR:
  894. case VAR:
  895. case VARPTR:
  896. case DEC:
  897. case INC:
  898. case DOT:
  899. case QUESTION:
  900. {
  901. e1=tmp_expr(_t);
  902. _t = _retTree;
  903. r_guard.reset( e1);
  904. break;
  905. }
  906. case FCALL_LIB:
  907. {
  908. e1=lib_function_call(_t);
  909. _t = _retTree;
  910. if( !callStack.back()->Contains( e1))
  911. r_guard.reset( e1);
  912. break;
  913. }
  914. default:
  915. {
  916. throw antlr::NoViableAltException(antlr::RefAST(_t));
  917. }
  918. }
  919. }
  920. res=l_arrayexpr_mfcall_as_mfcall(_t);
  921. _t = _retTree;
  922. if( e1 != (*res))
  923. {
  924. delete *res;
  925. *res = e1;
  926. }
  927. r_guard.release();
  928. _t = __t25;
  929. _t = _t->getNextSibling();
  930. break;
  931. }
  932. case ASSIGN_REPLACE:
  933. {
  934. ProgNodeP __t27 = _t;
  935. ProgNodeP tmp38_AST_in = _t;
  936. match(antlr::RefAST(_t),ASSIGN_REPLACE);
  937. _t = _t->getFirstChild();
  938. auto_ptr<BaseGDL> r_guard;
  939. {
  940. if (_t == ProgNodeP(antlr::nullAST) )
  941. _t = ASTNULL;
  942. switch ( _t->getType()) {
  943. case ASSIGN:
  944. case ASSIGN_REPLACE:
  945. case ASSIGN_ARRAYEXPR_MFCALL:
  946. case ARRAYDEF:
  947. case ARRAYEXPR:
  948. case ARRAYEXPR_MFCALL:
  949. case CONSTANT:
  950. case DEREF:
  951. case EXPR:
  952. case FCALL:
  953. case FCALL_LIB_RETNEW:
  954. case MFCALL:
  955. case MFCALL_PARENT:
  956. case NSTRUC:
  957. case NSTRUC_REF:
  958. case POSTDEC:
  959. case POSTINC:
  960. case STRUC:
  961. case SYSVAR:
  962. case VAR:
  963. case VARPTR:
  964. case DEC:
  965. case INC:
  966. case DOT:
  967. case QUESTION:
  968. {
  969. e1=tmp_expr(_t);
  970. _t = _retTree;
  971. r_guard.reset( e1);
  972. break;
  973. }
  974. case FCALL_LIB:
  975. {
  976. e1=lib_function_call(_t);
  977. _t = _retTree;
  978. if( !callStack.back()->Contains( e1))
  979. r_guard.reset( e1);
  980. break;
  981. }
  982. default:
  983. {
  984. throw antlr::NoViableAltException(antlr::RefAST(_t));
  985. }
  986. }
  987. }
  988. res=l_ret_expr(_t);
  989. _t = _retTree;
  990. if( e1 != (*res))
  991. {
  992. delete *res;
  993. *res = e1;
  994. }
  995. r_guard.release();
  996. _t = __t27;
  997. _t = _t->getNextSibling();
  998. break;
  999. }
  1000. case ARRAYEXPR:
  1001. {
  1002. ProgNodeP __t29 = _t;
  1003. ProgNodeP tmp39_AST_in = _t;
  1004. match(antlr::RefAST(_t),ARRAYEXPR);
  1005. _t = _t->getFirstChild();
  1006. throw GDLException( _t,
  1007. "Indexed expression not allowed as left-function"
  1008. " return value.",true,false);
  1009. _t = __t29;
  1010. _t = _t->getNextSibling();
  1011. break;
  1012. }
  1013. case DOT:
  1014. {
  1015. ProgNodeP __t30 = _t;
  1016. ProgNodeP tmp40_AST_in = _t;
  1017. match(antlr::RefAST(_t),DOT);
  1018. _t = _t->getFirstChild();
  1019. throw GDLException( _t,
  1020. "Struct expression not allowed as left-function"
  1021. " return value.",true,false);
  1022. _t = __t30;
  1023. _t = _t->getNextSibling();
  1024. break;
  1025. }
  1026. case SYSVAR:
  1027. {
  1028. ProgNodeP tmp41_AST_in = _t;
  1029. match(antlr::RefAST(_t),SYSVAR);
  1030. _t = _t->getNextSibling();
  1031. throw GDLException( _t,
  1032. "System variable not allowed as left-function"
  1033. " return value.",true,false);
  1034. break;
  1035. }
  1036. case ARRAYDEF:
  1037. case EXPR:
  1038. case NSTRUC:
  1039. case NSTRUC_REF:
  1040. case POSTDEC:
  1041. case POSTINC:
  1042. case STRUC:
  1043. case DEC:
  1044. case INC:
  1045. {
  1046. e1=r_expr(_t);
  1047. _t = _retTree;
  1048. delete e1;
  1049. throw GDLException( _t,
  1050. "Expression not allowed as left-function return value.",true,false);
  1051. break;
  1052. }
  1053. case CONSTANT:
  1054. {
  1055. ProgNodeP tmp42_AST_in = _t;
  1056. match(antlr::RefAST(_t),CONSTANT);
  1057. _t = _t->getNextSibling();
  1058. throw GDLException( _t,
  1059. "Constant not allowed as left-function return value.",true,false);
  1060. break;
  1061. }
  1062. default:
  1063. {
  1064. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1065. }
  1066. }
  1067. _retTree = _t;
  1068. return res;
  1069. }
  1070. BaseGDL* GDLInterpreter::expr(ProgNodeP _t) {
  1071. BaseGDL* res;
  1072. ProgNodeP expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1073. assert( _t != NULL);
  1074. res = _t->Eval();
  1075. _retTree = _t->getNextSibling();
  1076. return res; //tmp_expr(_t);
  1077. // if ( _t->getType() == FCALL_LIB)
  1078. // {
  1079. // BaseGDL* res=lib_function_call(_t);
  1080. // if( callStack.back()->Contains( res))
  1081. // res = res->Dup();
  1082. // return res;
  1083. // }
  1084. // else
  1085. // {
  1086. // BaseGDL* res = _t->Eval();
  1087. // _retTree = _t->getNextSibling();
  1088. // return res; //tmp_expr(_t);
  1089. // }
  1090. // // finish
  1091. if (_t == ProgNodeP(antlr::nullAST) )
  1092. _t = ASTNULL;
  1093. switch ( _t->getType()) {
  1094. case ASSIGN:
  1095. case ASSIGN_REPLACE:
  1096. case ASSIGN_ARRAYEXPR_MFCALL:
  1097. case ARRAYDEF:
  1098. case ARRAYEXPR:
  1099. case ARRAYEXPR_MFCALL:
  1100. case CONSTANT:
  1101. case DEREF:
  1102. case EXPR:
  1103. case FCALL:
  1104. case FCALL_LIB_RETNEW:
  1105. case MFCALL:
  1106. case MFCALL_PARENT:
  1107. case NSTRUC:
  1108. case NSTRUC_REF:
  1109. case POSTDEC:
  1110. case POSTINC:
  1111. case STRUC:
  1112. case SYSVAR:
  1113. case VAR:
  1114. case VARPTR:
  1115. case DEC:
  1116. case INC:
  1117. case DOT:
  1118. case QUESTION:
  1119. {
  1120. res=tmp_expr(_t);
  1121. _t = _retTree;
  1122. break;
  1123. }
  1124. case FCALL_LIB:
  1125. {
  1126. res=lib_function_call(_t);
  1127. _t = _retTree;
  1128. break;
  1129. }
  1130. default:
  1131. {
  1132. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1133. }
  1134. }
  1135. _retTree = _t;
  1136. return res;
  1137. }
  1138. BaseGDL** GDLInterpreter::l_arrayexpr_mfcall_as_mfcall(ProgNodeP _t) {
  1139. BaseGDL** res;
  1140. ProgNodeP l_arrayexpr_mfcall_as_mfcall_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1141. ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
  1142. // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
  1143. StackGuard<EnvStackT> guard(callStack);
  1144. BaseGDL *self;
  1145. EnvUDT* newEnv;
  1146. ProgNodeP __t126 = _t;
  1147. ProgNodeP tmp43_AST_in = _t;
  1148. match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
  1149. _t = _t->getFirstChild();
  1150. _t = _t->getNextSibling(); // skip DOT
  1151. self=expr(_t);
  1152. _t = _retTree;
  1153. mp2 = _t;
  1154. match(antlr::RefAST(_t),IDENTIFIER);
  1155. _t = _t->getNextSibling();
  1156. auto_ptr<BaseGDL> self_guard(self);
  1157. newEnv=new EnvUDT( self, mp2, "", true);
  1158. self_guard.release();
  1159. parameter_def(_t, newEnv);
  1160. _t = _retTree;
  1161. _t = __t126;
  1162. _t = _t->getNextSibling();
  1163. // push environment onto call stack
  1164. callStack.push_back(newEnv);
  1165. // make the call
  1166. res=call_lfun(static_cast<DSubUD*>(
  1167. newEnv->GetPro())->GetTree());
  1168. _retTree = _t;
  1169. return res;
  1170. }
  1171. BaseGDL** GDLInterpreter::l_function_call(ProgNodeP _t) {
  1172. BaseGDL** res;
  1173. ProgNodeP l_function_call_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1174. res = _t->LEval();
  1175. _retTree = _t->getNextSibling();
  1176. return res;
  1177. BaseGDL *self;
  1178. EnvUDT* newEnv;
  1179. if (_t == ProgNodeP(antlr::nullAST) )
  1180. _t = ASTNULL;
  1181. switch ( _t->getType()) {
  1182. case FCALL_LIB:
  1183. {
  1184. ProgNodeP __t128 = _t;
  1185. ProgNodeP tmp44_AST_in = _t;
  1186. match(antlr::RefAST(_t),FCALL_LIB);
  1187. _t = _t->getFirstChild();
  1188. parameter_def(_t, newEnv);
  1189. _t = _retTree;
  1190. _t = __t128;
  1191. _t = _t->getNextSibling();
  1192. break;
  1193. }
  1194. case FCALL:
  1195. case MFCALL:
  1196. case MFCALL_PARENT:
  1197. {
  1198. {
  1199. {
  1200. if (_t == ProgNodeP(antlr::nullAST) )
  1201. _t = ASTNULL;
  1202. switch ( _t->getType()) {
  1203. case MFCALL:
  1204. {
  1205. ProgNodeP __t131 = _t;
  1206. ProgNodeP tmp45_AST_in = _t;
  1207. match(antlr::RefAST(_t),MFCALL);
  1208. _t = _t->getFirstChild();
  1209. self=expr(_t);
  1210. _t = _retTree;
  1211. ProgNodeP tmp46_AST_in = _t;
  1212. match(antlr::RefAST(_t),IDENTIFIER);
  1213. _t = _t->getNextSibling();
  1214. parameter_def(_t, newEnv);
  1215. _t = _retTree;
  1216. _t = __t131;
  1217. _t = _t->getNextSibling();
  1218. break;
  1219. }
  1220. case MFCALL_PARENT:
  1221. {
  1222. ProgNodeP __t132 = _t;
  1223. ProgNodeP tmp47_AST_in = _t;
  1224. match(antlr::RefAST(_t),MFCALL_PARENT);
  1225. _t = _t->getFirstChild();
  1226. self=expr(_t);
  1227. _t = _retTree;
  1228. ProgNodeP tmp48_AST_in = _t;
  1229. match(antlr::RefAST(_t),IDENTIFIER);
  1230. _t = _t->getNextSibling();
  1231. ProgNodeP tmp49_AST_in = _t;
  1232. match(antlr::RefAST(_t),IDENTIFIER);
  1233. _t = _t->getNextSibling();
  1234. parameter_def(_t, newEnv);
  1235. _t = _retTree;
  1236. _t = __t132;
  1237. _t = _t->getNextSibling();
  1238. break;
  1239. }
  1240. case FCALL:
  1241. {
  1242. ProgNodeP __t133 = _t;
  1243. ProgNodeP tmp50_AST_in = _t;
  1244. match(antlr::RefAST(_t),FCALL);
  1245. _t = _t->getFirstChild();
  1246. parameter_def(_t, newEnv);
  1247. _t = _retTree;
  1248. _t = __t133;
  1249. _t = _t->getNextSibling();
  1250. break;
  1251. }
  1252. default:
  1253. {
  1254. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1255. }
  1256. }
  1257. }
  1258. }
  1259. break;
  1260. }
  1261. default:
  1262. {
  1263. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1264. }
  1265. }
  1266. _retTree = _t;
  1267. return res;
  1268. }
  1269. BaseGDL* GDLInterpreter::tmp_expr(ProgNodeP _t) {
  1270. BaseGDL* res;
  1271. ProgNodeP tmp_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1272. ProgNodeP q = ProgNodeP(antlr::nullAST);
  1273. res = _t->Eval();
  1274. _retTree = _t->getNextSibling();
  1275. return res;
  1276. BaseGDL** e2;
  1277. if (_t == ProgNodeP(antlr::nullAST) )
  1278. _t = ASTNULL;
  1279. switch ( _t->getType()) {
  1280. case DEREF:
  1281. {
  1282. e2=l_deref(_t);
  1283. _t = _retTree;
  1284. break;
  1285. }
  1286. case QUESTION:
  1287. {
  1288. ProgNodeP __t90 = _t;
  1289. q = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1290. match(antlr::RefAST(_t),QUESTION);
  1291. _t = _t->getFirstChild();
  1292. res=q->Eval();
  1293. _t = __t90;
  1294. _t = _t->getNextSibling();
  1295. break;
  1296. }
  1297. case ARRAYEXPR:
  1298. {
  1299. {
  1300. ProgNodeP tmp51_AST_in = _t;
  1301. match(antlr::RefAST(_t),ARRAYEXPR);
  1302. _t = _t->getNextSibling();
  1303. }
  1304. break;
  1305. }
  1306. case DOT:
  1307. {
  1308. res=dot_expr(_t);
  1309. _t = _retTree;
  1310. break;
  1311. }
  1312. case ASSIGN:
  1313. case ASSIGN_REPLACE:
  1314. case ASSIGN_ARRAYEXPR_MFCALL:
  1315. {
  1316. res=assign_expr(_t);
  1317. _t = _retTree;
  1318. break;
  1319. }
  1320. case ARRAYEXPR_MFCALL:
  1321. case FCALL:
  1322. case MFCALL:
  1323. case MFCALL_PARENT:
  1324. {
  1325. res=unused_function_call(_t);
  1326. _t = _retTree;
  1327. break;
  1328. }
  1329. case ARRAYDEF:
  1330. case EXPR:
  1331. case NSTRUC:
  1332. case NSTRUC_REF:
  1333. case POSTDEC:
  1334. case POSTINC:
  1335. case STRUC:
  1336. case DEC:
  1337. case INC:
  1338. {
  1339. res=r_expr(_t);
  1340. _t = _retTree;
  1341. break;
  1342. }
  1343. case CONSTANT:
  1344. {
  1345. res=constant(_t);
  1346. _t = _retTree;
  1347. break;
  1348. }
  1349. case VAR:
  1350. case VARPTR:
  1351. {
  1352. res=simple_var(_t);
  1353. _t = _retTree;
  1354. break;
  1355. }
  1356. case SYSVAR:
  1357. {
  1358. res=sys_var(_t);
  1359. _t = _retTree;
  1360. break;
  1361. }
  1362. case FCALL_LIB_RETNEW:
  1363. {
  1364. res=lib_function_call_retnew(_t);
  1365. _t = _retTree;
  1366. break;
  1367. }
  1368. default:
  1369. {
  1370. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1371. }
  1372. }
  1373. _retTree = _t;
  1374. return res;
  1375. }
  1376. BaseGDL* GDLInterpreter::lib_function_call(ProgNodeP _t) {
  1377. BaseGDL* res;
  1378. ProgNodeP lib_function_call_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1379. assert( _t->getType() == FCALL_LIB);
  1380. res = static_cast<FCALL_LIBNode*>(_t)->EvalFCALL_LIB();
  1381. _retTree = _t->getNextSibling();
  1382. return res;
  1383. // // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
  1384. // StackGuard<EnvStackT> guard(callStack);
  1385. // ProgNodeP rTree = _t->getNextSibling();
  1386. // // match(antlr::RefAST(_t),FCALL_LIB);
  1387. // ProgNodeP& fl = _t;
  1388. // EnvT* newEnv=new EnvT( fl, fl->libFun);//libFunList[fl->funIx]);
  1389. // parameter_def(_t->getFirstChild(), newEnv);
  1390. // // push id.pro onto call stack
  1391. // callStack.push_back(newEnv);
  1392. // // make the call
  1393. // res=static_cast<DLibFun*>(newEnv->GetPro())->Fun()(newEnv);
  1394. // // *** MUST always return a defined expression
  1395. // assert( res != NULL);
  1396. // _retTree = rTree;
  1397. // return res;
  1398. EnvT* newEnv;
  1399. ProgNodeP __t106 = _t;
  1400. ProgNodeP tmp52_AST_in = _t;
  1401. match(antlr::RefAST(_t),FCALL_LIB);
  1402. _t = _t->getFirstChild();
  1403. parameter_def(_t, newEnv);
  1404. _t = _retTree;
  1405. _t = __t106;
  1406. _t = _t->getNextSibling();
  1407. _retTree = _t;
  1408. return res;
  1409. }
  1410. BaseGDL* GDLInterpreter::r_expr(ProgNodeP _t) {
  1411. BaseGDL* res;
  1412. ProgNodeP r_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1413. res=_t->Eval();
  1414. _retTree = _t->getNextSibling();
  1415. return res;
  1416. // switch ( _t->getType()) {
  1417. // case EXPR:
  1418. // case ARRAYDEF:
  1419. // case STRUC:
  1420. // case NSTRUC:
  1421. // case NSTRUC_REF:
  1422. // {
  1423. // res = _t->Eval();
  1424. // break;
  1425. // }
  1426. // case DEC:
  1427. // {
  1428. // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), DEC);
  1429. // break;
  1430. // }
  1431. // case INC:
  1432. // {
  1433. // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), INC);
  1434. // break;
  1435. // }
  1436. // case POSTDEC:
  1437. // {
  1438. // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), POSTDEC);
  1439. // break;
  1440. // }
  1441. // case POSTINC:
  1442. // {
  1443. // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), POSTINC);
  1444. // break;
  1445. // }
  1446. // // default:
  1447. // // {
  1448. // // throw antlr::NoViableAltException(antlr::RefAST(_t));
  1449. // // }
  1450. // }
  1451. // _retTree = _t->getNextSibling();
  1452. // return res;
  1453. if (_t == ProgNodeP(antlr::nullAST) )
  1454. _t = ASTNULL;
  1455. switch ( _t->getType()) {
  1456. case EXPR:
  1457. {
  1458. ProgNodeP tmp53_AST_in = _t;
  1459. match(antlr::RefAST(_t),EXPR);
  1460. _t = _t->getNextSibling();
  1461. break;
  1462. }
  1463. case ARRAYDEF:
  1464. {
  1465. ProgNodeP tmp54_AST_in = _t;
  1466. match(antlr::RefAST(_t),ARRAYDEF);
  1467. _t = _t->getNextSibling();
  1468. break;
  1469. }
  1470. case STRUC:
  1471. {
  1472. ProgNodeP tmp55_AST_in = _t;
  1473. match(antlr::RefAST(_t),STRUC);
  1474. _t = _t->getNextSibling();
  1475. break;
  1476. }
  1477. case NSTRUC:
  1478. {
  1479. ProgNodeP tmp56_AST_in = _t;
  1480. match(antlr::RefAST(_t),NSTRUC);
  1481. _t = _t->getNextSibling();
  1482. break;
  1483. }
  1484. case NSTRUC_REF:
  1485. {
  1486. ProgNodeP tmp57_AST_in = _t;
  1487. match(antlr::RefAST(_t),NSTRUC_REF);
  1488. _t = _t->getNextSibling();
  1489. break;
  1490. }
  1491. case DEC:
  1492. {
  1493. ProgNodeP __t68 = _t;
  1494. ProgNodeP tmp58_AST_in = _t;
  1495. match(antlr::RefAST(_t),DEC);
  1496. _t = _t->getFirstChild();
  1497. res=l_decinc_expr(_t, DEC);
  1498. _t = _retTree;
  1499. _t = __t68;
  1500. _t = _t->getNextSibling();
  1501. break;
  1502. }
  1503. case INC:
  1504. {
  1505. ProgNodeP __t69 = _t;
  1506. ProgNodeP tmp59_AST_in = _t;
  1507. match(antlr::RefAST(_t),INC);
  1508. _t = _t->getFirstChild();
  1509. res=l_decinc_expr(_t, INC);
  1510. _t = _retTree;
  1511. _t = __t69;
  1512. _t = _t->getNextSibling();
  1513. break;
  1514. }
  1515. case POSTDEC:
  1516. {
  1517. ProgNodeP __t70 = _t;
  1518. ProgNodeP tmp60_AST_in = _t;
  1519. match(antlr::RefAST(_t),POSTDEC);
  1520. _t = _t->getFirstChild();
  1521. res=l_decinc_expr(_t, POSTDEC);
  1522. _t = _retTree;
  1523. _t = __t70;
  1524. _t = _t->getNextSibling();
  1525. break;
  1526. }
  1527. case POSTINC:
  1528. {
  1529. ProgNodeP __t71 = _t;
  1530. ProgNodeP tmp61_AST_in = _t;
  1531. match(antlr::RefAST(_t),POSTINC);
  1532. _t = _t->getFirstChild();
  1533. res=l_decinc_expr(_t, POSTINC);
  1534. _t = _retTree;
  1535. _t = __t71;
  1536. _t = _t->getNextSibling();
  1537. break;
  1538. }
  1539. default:
  1540. {
  1541. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1542. }
  1543. }
  1544. _retTree = _t;
  1545. return res;
  1546. }
  1547. BaseGDL* GDLInterpreter::l_decinc_indexable_expr(ProgNodeP _t,
  1548. int dec_inc
  1549. ) {
  1550. BaseGDL* res;
  1551. ProgNodeP l_decinc_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1552. BaseGDL** e;
  1553. if (_t == ProgNodeP(antlr::nullAST) )
  1554. _t = ASTNULL;
  1555. switch ( _t->getType()) {
  1556. case FCALL:
  1557. case FCALL_LIB:
  1558. case MFCALL:
  1559. case MFCALL_PARENT:
  1560. {
  1561. e=l_function_call(_t);
  1562. _t = _retTree;
  1563. res = *e;
  1564. if( res == NULL)
  1565. throw GDLException( _t, "Variable is undefined: "+Name(e),true,false);
  1566. break;
  1567. }
  1568. case DEREF:
  1569. {
  1570. e=l_deref(_t);
  1571. _t = _retTree;
  1572. res = *e;
  1573. if( res == NULL)
  1574. throw GDLException( _t, "Variable is undefined: "+Name(e),true,false);
  1575. break;
  1576. }
  1577. case VAR:
  1578. case VARPTR:
  1579. {
  1580. e=l_defined_simple_var(_t);
  1581. _t = _retTree;
  1582. res = *e;
  1583. break;
  1584. }
  1585. case SYSVAR:
  1586. {
  1587. e=l_sys_var(_t);
  1588. _t = _retTree;
  1589. res = *e;
  1590. break;
  1591. }
  1592. default:
  1593. {
  1594. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1595. }
  1596. }
  1597. _retTree = _t;
  1598. return res;
  1599. }
  1600. BaseGDL** GDLInterpreter::l_defined_simple_var(ProgNodeP _t) {
  1601. BaseGDL** res;
  1602. ProgNodeP l_defined_simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1603. assert( _t != NULL);
  1604. res = _t->LEval();
  1605. _retTree = _t->getNextSibling();
  1606. if( *res == NULL)
  1607. {
  1608. if( _t->getType() == VAR)
  1609. throw GDLException( _t, "Variable is undefined: "+
  1610. callStack.back()->GetString(_t->varIx),true,false);
  1611. else
  1612. throw GDLException( _t, "Common block variable is undefined: "+
  1613. callStack.back()->GetString( *res),true,false);
  1614. }
  1615. return res;
  1616. // if( _t->getType() == VAR)
  1617. // {
  1618. // res=&callStack.back()->GetKW(_t->varIx);
  1619. // if( *res == NULL)
  1620. // throw GDLException( _t, "Variable is undefined: "+
  1621. // callStack.back()->GetString(_t->varIx),true,false);
  1622. // }
  1623. // else
  1624. // {
  1625. // res=&_t->var->Data(); // returns BaseGDL* of var (DVar*)
  1626. // if( *res == NULL)
  1627. // throw GDLException( _t, "Variable is undefined: "+
  1628. // callStack.back()->GetString( *res),true,false);
  1629. // }
  1630. // _retTree = _t->getNextSibling();
  1631. // return res;
  1632. if (_t == ProgNodeP(antlr::nullAST) )
  1633. _t = ASTNULL;
  1634. switch ( _t->getType()) {
  1635. case VAR:
  1636. {
  1637. ProgNodeP tmp62_AST_in = _t;
  1638. match(antlr::RefAST(_t),VAR);
  1639. _t = _t->getNextSibling();
  1640. break;
  1641. }
  1642. case VARPTR:
  1643. {
  1644. ProgNodeP tmp63_AST_in = _t;
  1645. match(antlr::RefAST(_t),VARPTR);
  1646. _t = _t->getNextSibling();
  1647. break;
  1648. }
  1649. default:
  1650. {
  1651. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1652. }
  1653. }
  1654. _retTree = _t;
  1655. return res;
  1656. }
  1657. BaseGDL** GDLInterpreter::l_sys_var(ProgNodeP _t) {
  1658. BaseGDL** res;
  1659. ProgNodeP l_sys_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1660. ProgNodeP sysVar = ProgNodeP(antlr::nullAST);
  1661. sysVar = _t;
  1662. match(antlr::RefAST(_t),SYSVAR);
  1663. _t = _t->getNextSibling();
  1664. res=sysVar->LEval();
  1665. _retTree = sysVar->getNextSibling();
  1666. _retTree = _t;
  1667. return res;
  1668. }
  1669. BaseGDL* GDLInterpreter::l_decinc_array_expr(ProgNodeP _t,
  1670. int dec_inc
  1671. ) {
  1672. BaseGDL* res;
  1673. ProgNodeP l_decinc_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1674. ArrayIndexListT* aL;
  1675. BaseGDL* e;
  1676. ArrayIndexListGuard guard;
  1677. if (_t == ProgNodeP(antlr::nullAST) )
  1678. _t = ASTNULL;
  1679. switch ( _t->getType()) {
  1680. case ARRAYEXPR:
  1681. {
  1682. ProgNodeP __t33 = _t;
  1683. ProgNodeP tmp64_AST_in = _t;
  1684. match(antlr::RefAST(_t),ARRAYEXPR);
  1685. _t = _t->getFirstChild();
  1686. e=l_decinc_indexable_expr(_t, dec_inc);
  1687. _t = _retTree;
  1688. aL=arrayindex_list(_t);
  1689. _t = _retTree;
  1690. _t = __t33;
  1691. _t = _t->getNextSibling();
  1692. guard.reset( aL);
  1693. aL->SetVariable( e);
  1694. if( dec_inc == DECSTATEMENT)
  1695. {
  1696. e->DecAt( aL);
  1697. res = NULL;
  1698. break;
  1699. }
  1700. if( dec_inc == INCSTATEMENT)
  1701. {
  1702. e->IncAt( aL);
  1703. res = NULL;
  1704. break;
  1705. }
  1706. if( dec_inc == DEC) e->DecAt( aL);
  1707. else if( dec_inc == INC) e->IncAt( aL);
  1708. //
  1709. res=e->Index( aL);
  1710. if( dec_inc == POSTDEC) e->DecAt( aL);
  1711. else if( dec_inc == POSTINC) e->IncAt( aL);
  1712. break;
  1713. }
  1714. case DEREF:
  1715. case FCALL:
  1716. case FCALL_LIB:
  1717. case MFCALL:
  1718. case MFCALL_PARENT:
  1719. case SYSVAR:
  1720. case VAR:
  1721. case VARPTR:
  1722. {
  1723. e=l_decinc_indexable_expr(_t, dec_inc);
  1724. _t = _retTree;
  1725. if( dec_inc == DECSTATEMENT)
  1726. {
  1727. e->Dec();
  1728. res = NULL;
  1729. break;
  1730. }
  1731. if( dec_inc == INCSTATEMENT)
  1732. {
  1733. e->Inc();
  1734. res = NULL;
  1735. break;
  1736. }
  1737. if( dec_inc == DEC) e->Dec();
  1738. else if( dec_inc == INC) e->Inc();
  1739. //
  1740. res = e->Dup();
  1741. if( dec_inc == POSTDEC) e->Dec();
  1742. else if( dec_inc == POSTINC) e->Inc();
  1743. break;
  1744. }
  1745. default:
  1746. {
  1747. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1748. }
  1749. }
  1750. _retTree = _t;
  1751. return res;
  1752. }
  1753. ArrayIndexListT* GDLInterpreter::arrayindex_list(ProgNodeP _t) {
  1754. ArrayIndexListT* aL;
  1755. ProgNodeP arrayindex_list_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1756. IxExprListT cleanupList; // for cleanup
  1757. IxExprListT ixExprList;
  1758. SizeT nExpr;
  1759. BaseGDL* s;
  1760. // ProgNodeP retTree = _t->getNextSibling();
  1761. ProgNodeP ax = _t;
  1762. // match(antlr::RefAST(_t),ARRAYIX);
  1763. _t = _t->getFirstChild();
  1764. aL = ax->arrIxList;
  1765. assert( aL != NULL);
  1766. nExpr = aL->NParam();
  1767. if( nExpr == 0)
  1768. {
  1769. aL->Init();
  1770. _retTree = ax->getNextSibling();//retTree;
  1771. return aL;
  1772. }
  1773. while( true) {
  1774. assert( _t != NULL);
  1775. if( NonCopyNode( _t->getType()))
  1776. {
  1777. s= _t->EvalNC(); //indexable_expr(_t);
  1778. //_t = _retTree;
  1779. }
  1780. else if( _t->getType() == GDLTokenTypes::FCALL_LIB)
  1781. {
  1782. s=lib_function_call(_t);
  1783. //_t = _retTree;
  1784. if( !callStack.back()->Contains( s))
  1785. cleanupList.push_back( s);
  1786. }
  1787. else
  1788. {
  1789. s=_t->Eval(); //indexable_tmp_expr(_t);
  1790. //_t = _retTree;
  1791. cleanupList.push_back( s);
  1792. }
  1793. ixExprList.push_back( s);
  1794. if( ixExprList.size() == nExpr)
  1795. break; // allows some manual tuning
  1796. _t = _t->getNextSibling();
  1797. }
  1798. aL->Init( ixExprList, &cleanupList);
  1799. _retTree = ax->getNextSibling();//retTree;
  1800. return aL;
  1801. ProgNodeP __t143 = _t;
  1802. ProgNodeP tmp65_AST_in = _t;
  1803. match(antlr::RefAST(_t),ARRAYIX);
  1804. _t = _t->getFirstChild();
  1805. { // ( ... )*
  1806. for (;;) {
  1807. if (_t == ProgNodeP(antlr::nullAST) )
  1808. _t = ASTNULL;
  1809. if ((_tokenSet_1.member(_t->getType()))) {
  1810. {
  1811. if (_t == ProgNodeP(antlr::nullAST) )
  1812. _t = ASTNULL;
  1813. switch ( _t->getType()) {
  1814. case CONSTANT:
  1815. case DEREF:
  1816. case SYSVAR:
  1817. case VAR:
  1818. case VARPTR:
  1819. {
  1820. s=indexable_expr(_t);
  1821. _t = _retTree;
  1822. break;
  1823. }
  1824. case FCALL_LIB:
  1825. {
  1826. s=lib_function_call(_t);
  1827. _t = _retTree;
  1828. break;
  1829. }
  1830. case ASSIGN:
  1831. case ASSIGN_REPLACE:
  1832. case ASSIGN_ARRAYEXPR_MFCALL:
  1833. case ARRAYDEF:
  1834. case ARRAYEXPR:
  1835. case ARRAYEXPR_MFCALL:
  1836. case EXPR:
  1837. case FCALL:
  1838. case FCALL_LIB_RETNEW:
  1839. case MFCALL:
  1840. case MFCALL_PARENT:
  1841. case NSTRUC:
  1842. case NSTRUC_REF:
  1843. case POSTDEC:
  1844. case POSTINC:
  1845. case STRUC:
  1846. case DEC:
  1847. case INC:
  1848. case DOT:
  1849. case QUESTION:
  1850. {
  1851. s=indexable_tmp_expr(_t);
  1852. _t = _retTree;
  1853. break;
  1854. }
  1855. default:
  1856. {
  1857. throw antlr::NoViableAltException(antlr::RefAST(_t));
  1858. }
  1859. }
  1860. }
  1861. }
  1862. else {
  1863. goto _loop146;
  1864. }
  1865. }
  1866. _loop146:;
  1867. } // ( ... )*
  1868. _t = __t143;
  1869. _t = _t->getNextSibling();
  1870. _retTree = _t;
  1871. return aL;
  1872. }
  1873. BaseGDL* GDLInterpreter::l_decinc_dot_expr(ProgNodeP _t,
  1874. int dec_inc
  1875. ) {
  1876. BaseGDL* res;
  1877. ProgNodeP l_decinc_dot_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1878. ProgNodeP dot = ProgNodeP(antlr::nullAST);
  1879. ProgNodeP __t35 = _t;
  1880. dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1881. match(antlr::RefAST(_t),DOT);
  1882. _t = _t->getFirstChild();
  1883. SizeT nDot=dot->nDot;
  1884. auto_ptr<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
  1885. l_dot_array_expr(_t, aD.get());
  1886. _t = _retTree;
  1887. { // ( ... )+
  1888. int _cnt37=0;
  1889. for (;;) {
  1890. if (_t == ProgNodeP(antlr::nullAST) )
  1891. _t = ASTNULL;
  1892. if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
  1893. tag_array_expr(_t, aD.get());
  1894. _t = _retTree;
  1895. }
  1896. else {
  1897. if ( _cnt37>=1 ) { goto _loop37; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
  1898. }
  1899. _cnt37++;
  1900. }
  1901. _loop37:;
  1902. } // ( ... )+
  1903. _t = __t35;
  1904. _t = _t->getNextSibling();
  1905. if( dec_inc == DECSTATEMENT)
  1906. {
  1907. aD->Dec();
  1908. res = NULL;
  1909. }
  1910. else if( dec_inc == INCSTATEMENT)
  1911. {
  1912. aD->Inc();
  1913. res = NULL;
  1914. }
  1915. else
  1916. {
  1917. if( dec_inc == DEC) aD->Dec(); //*** aD->Assign( dec_inc);
  1918. else if( dec_inc == INC) aD->Inc();
  1919. //
  1920. res=aD->Resolve();
  1921. if( dec_inc == POSTDEC) aD->Dec();
  1922. else if( dec_inc == POSTINC) aD->Inc();
  1923. }
  1924. _retTree = _t;
  1925. return res;
  1926. }
  1927. void GDLInterpreter::l_dot_array_expr(ProgNodeP _t,
  1928. DotAccessDescT* aD
  1929. ) {
  1930. ProgNodeP l_dot_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  1931. ArrayIndexListT* aL;
  1932. BaseGDL** rP;
  1933. DStructGDL* structR;
  1934. ArrayIndexListGuard guard;
  1935. if( _t->getType() == ARRAYEXPR)
  1936. {
  1937. rP=l_indexable_expr(_t->getFirstChild());
  1938. aL=arrayindex_list(_retTree);
  1939. guard.reset(aL);
  1940. _retTree = _t->getNextSibling();
  1941. // check here for object and get struct
  1942. structR=dynamic_cast<DStructGDL*>(*rP);
  1943. if( structR == NULL)
  1944. {
  1945. bool isObj = callStack.back()->IsObject();
  1946. if( isObj)
  1947. {
  1948. DStructGDL* oStruct = ObjectStructCheckAccess( *rP, _t);
  1949. // oStruct cannot be "Assoc_"
  1950. aD->Root( oStruct, guard.release());
  1951. }
  1952. else
  1953. {
  1954. throw GDLException( _t, "Expression must be a"
  1955. " STRUCT in this context: "+Name(*rP),
  1956. true,false);
  1957. }
  1958. }
  1959. else
  1960. {
  1961. if( (*rP)->IsAssoc())
  1962. throw GDLException( _t, "File expression not allowed "
  1963. "in this context: "+Name(*rP),true,false);
  1964. aD->Root( structR, guard.release() /* aL */);
  1965. }
  1966. }
  1967. else
  1968. // case ARRAYEXPR_MFCALL:
  1969. // case DEREF:
  1970. // case EXPR:
  1971. // case FCALL:
  1972. // case FCALL_LIB:
  1973. // case MFCALL:
  1974. // case MFCALL_PARENT:
  1975. // case SYSVAR:
  1976. // case VAR:
  1977. // case VARPTR:
  1978. {
  1979. rP=l_indexable_expr(_t);
  1980. //_t = _retTree; _retTree set ok
  1981. // check here for object and get struct
  1982. structR = dynamic_cast<DStructGDL*>(*rP);
  1983. if( structR == NULL)
  1984. {
  1985. bool isObj = callStack.back()->IsObject();
  1986. if( isObj) // member access to object?
  1987. {
  1988. DStructGDL* oStruct = ObjectStructCheckAccess( *rP, _t);
  1989. // oStruct cannot be "Assoc_"
  1990. aD->Root( oStruct);
  1991. }
  1992. else
  1993. {
  1994. throw GDLException( _t, "Expression must be a"
  1995. " STRUCT in this context: "+Name(*rP),
  1996. true,false);
  1997. }
  1998. }
  1999. else
  2000. {
  2001. if( (*rP)->IsAssoc())
  2002. {
  2003. throw GDLException( _t, "File expression not allowed "
  2004. "in this context: "+Name(*rP),true,false);
  2005. }
  2006. aD->Root(structR);
  2007. }
  2008. }
  2009. // _retTree = _t;
  2010. if (_t == ProgNodeP(antlr::nullAST) )
  2011. _t = ASTNULL;
  2012. switch ( _t->getType()) {
  2013. case ARRAYEXPR:
  2014. {
  2015. ProgNodeP __t52 = _t;
  2016. ProgNodeP tmp66_AST_in = _t;
  2017. match(antlr::RefAST(_t),ARRAYEXPR);
  2018. _t = _t->getFirstChild();
  2019. rP=l_indexable_expr(_t);
  2020. _t = _retTree;
  2021. aL=arrayindex_list(_t);
  2022. _t = _retTree;
  2023. _t = __t52;
  2024. _t = _t->getNextSibling();
  2025. break;
  2026. }
  2027. case ARRAYEXPR_MFCALL:
  2028. case DEREF:
  2029. case EXPR:
  2030. case FCALL:
  2031. case FCALL_LIB:
  2032. case MFCALL:
  2033. case MFCALL_PARENT:
  2034. case SYSVAR:
  2035. case VAR:
  2036. case VARPTR:
  2037. {
  2038. rP=l_indexable_expr(_t);
  2039. _t = _retTree;
  2040. break;
  2041. }
  2042. default:
  2043. {
  2044. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2045. }
  2046. }
  2047. _retTree = _t;
  2048. }
  2049. void GDLInterpreter::tag_array_expr(ProgNodeP _t,
  2050. DotAccessDescT* aD
  2051. ) {
  2052. ProgNodeP tag_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  2053. ArrayIndexListT* aL;
  2054. if( _t->getType() == ARRAYEXPR)
  2055. {
  2056. ProgNodeP tIn = _t;
  2057. _t = _t->getFirstChild();
  2058. tag_expr(_t, aD);
  2059. _t = _retTree;
  2060. aL=arrayindex_list(_t);
  2061. _t = _retTree;
  2062. aD->AddIx(aL);
  2063. _retTree = tIn->getNextSibling();
  2064. }
  2065. else
  2066. // case EXPR:
  2067. // case IDENTIFIER:
  2068. {
  2069. tag_expr(_t, aD);
  2070. //_t = _retTree;
  2071. aD->AddIx(NULL);
  2072. }
  2073. //_retTree = _t;
  2074. return;
  2075. if (_t == ProgNodeP(antlr::nullAST) )
  2076. _t = ASTNULL;
  2077. switch ( _t->getType()) {
  2078. case ARRAYEXPR:
  2079. {
  2080. ProgNodeP __t75 = _t;
  2081. ProgNodeP tmp67_AST_in = _t;
  2082. match(antlr::RefAST(_t),ARRAYEXPR);
  2083. _t = _t->getFirstChild();
  2084. tag_expr(_t, aD);
  2085. _t = _retTree;
  2086. aL=arrayindex_list(_t);
  2087. _t = _retTree;
  2088. aD->AddIx(aL);
  2089. _t = __t75;
  2090. _t = _t->getNextSibling();
  2091. break;
  2092. }
  2093. case EXPR:
  2094. case IDENTIFIER:
  2095. {
  2096. tag_expr(_t, aD);
  2097. _t = _retTree;
  2098. aD->AddIx(NULL);
  2099. break;
  2100. }
  2101. default:
  2102. {
  2103. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2104. }
  2105. }
  2106. _retTree = _t;
  2107. }
  2108. BaseGDL* GDLInterpreter::l_decinc_expr(ProgNodeP _t,
  2109. int dec_inc
  2110. ) {
  2111. BaseGDL* res;
  2112. ProgNodeP l_decinc_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  2113. ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
  2114. BaseGDL* e1;
  2115. ProgNodeP startNode = _t;
  2116. if (_t == ProgNodeP(antlr::nullAST) )
  2117. _t = ASTNULL;
  2118. switch ( _t->getType()) {
  2119. case QUESTION:
  2120. {
  2121. ProgNodeP __t39 = _t;
  2122. ProgNodeP tmp68_AST_in = _t;
  2123. match(antlr::RefAST(_t),QUESTION);
  2124. _t = _t->getFirstChild();
  2125. e1=expr(_t);
  2126. _t = _retTree;
  2127. auto_ptr<BaseGDL> e1_guard(e1);
  2128. if( e1->True())
  2129. {
  2130. res=l_decinc_expr(_t, dec_inc);
  2131. }
  2132. else
  2133. {
  2134. _t=_t->GetNextSibling(); // jump over 1st expression
  2135. res=l_decinc_expr(_t, dec_inc);
  2136. }
  2137. _t = __t39;
  2138. _t = _t->getNextSibling();
  2139. break;
  2140. }
  2141. case ASSIGN:
  2142. {
  2143. ProgNodeP __t40 = _t;
  2144. ProgNodeP tmp69_AST_in = _t;
  2145. match(antlr::RefAST(_t),ASSIGN);
  2146. _t = _t->getFirstChild();
  2147. auto_ptr<BaseGDL> r_guard;
  2148. {
  2149. if (_t == ProgNodeP(antlr::nullAST) )
  2150. _t = ASTNULL;
  2151. switch ( _t->getType()) {
  2152. case CONSTANT:
  2153. case DEREF:
  2154. case SYSVAR:
  2155. case VAR:
  2156. case VARPTR:
  2157. {
  2158. e1=indexable_expr(_t);
  2159. _t = _retTree;
  2160. break;
  2161. }
  2162. case ASSIGN:
  2163. case ASSIGN_REPLACE:
  2164. case ASSIGN_ARRAYEXPR_MFCALL:
  2165. case ARRAYDEF:
  2166. case ARRAYEXPR:
  2167. case ARRAYEXPR_MFCALL:
  2168. case EXPR:
  2169. case FCALL:
  2170. case FCALL_LIB_RETNEW:
  2171. case MFCALL:
  2172. case MFCALL_PARENT:
  2173. case NSTRUC:
  2174. case NSTRUC_REF:
  2175. case POSTDEC:
  2176. case POSTINC:
  2177. case STRUC:
  2178. case DEC:
  2179. case INC:
  2180. case DOT:
  2181. case QUESTION:
  2182. {
  2183. e1=indexable_tmp_expr(_t);
  2184. _t = _retTree;
  2185. r_guard.reset( e1);
  2186. break;
  2187. }
  2188. case FCALL_LIB:
  2189. {
  2190. e1=lib_function_call(_t);
  2191. _t = _retTree;
  2192. if( !callStack.back()->Contains( e1))
  2193. r_guard.reset( e1); // guard if no global data
  2194. break;
  2195. }
  2196. default:
  2197. {
  2198. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2199. }
  2200. }
  2201. }
  2202. ProgNodeP l = _t;
  2203. BaseGDL** tmp;
  2204. tmp=l_expr(_t, e1);
  2205. _t = _retTree;
  2206. _t = l;
  2207. res=l_decinc_expr(_t, dec_inc);
  2208. _t = _retTree;
  2209. _t = __t40;
  2210. _t = _t->getNextSibling();
  2211. break;
  2212. }
  2213. case ASSIGN_ARRAYEXPR_MFCALL:
  2214. {
  2215. ProgNodeP __t42 = _t;
  2216. ProgNodeP tmp70_AST_in = _t;
  2217. match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
  2218. _t = _t->getFirstChild();
  2219. auto_ptr<BaseGDL> r_guard;
  2220. {
  2221. if (_t == ProgNodeP(antlr::nullAST) )
  2222. _t = ASTNULL;
  2223. switch ( _t->getType()) {
  2224. case CONSTANT:
  2225. case DEREF:
  2226. case SYSVAR:
  2227. case VAR:
  2228. case VARPTR:
  2229. {
  2230. e1=indexable_expr(_t);
  2231. _t = _retTree;
  2232. break;
  2233. }
  2234. case ASSIGN:
  2235. case ASSIGN_REPLACE:
  2236. case ASSIGN_ARRAYEXPR_MFCALL:
  2237. case ARRAYDEF:
  2238. case ARRAYEXPR:
  2239. case ARRAYEXPR_MFCALL:
  2240. case EXPR:
  2241. case FCALL:
  2242. case FCALL_LIB_RETNEW:
  2243. case MFCALL:
  2244. case MFCALL_PARENT:
  2245. case NSTRUC:
  2246. case NSTRUC_REF:
  2247. case POSTDEC:
  2248. case POSTINC:
  2249. case STRUC:
  2250. case DEC:
  2251. case INC:
  2252. case DOT:
  2253. case QUESTION:
  2254. {
  2255. e1=indexable_tmp_expr(_t);
  2256. _t = _retTree;
  2257. r_guard.reset( e1);
  2258. break;
  2259. }
  2260. case FCALL_LIB:
  2261. {
  2262. e1=lib_function_call(_t);
  2263. _t = _retTree;
  2264. if( !callStack.back()->Contains( e1))
  2265. r_guard.reset( e1); // guard if no global data
  2266. break;
  2267. }
  2268. default:
  2269. {
  2270. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2271. }
  2272. }
  2273. }
  2274. ProgNodeP l = _t;
  2275. BaseGDL** tmp;
  2276. // try MFCALL
  2277. try
  2278. {
  2279. tmp=l_arrayexpr_mfcall_as_mfcall(l);
  2280. if( e1 != (*tmp))
  2281. {
  2282. delete *tmp;
  2283. if( r_guard.get() == e1)
  2284. *tmp = r_guard.release();
  2285. else
  2286. *tmp = e1->Dup();
  2287. }
  2288. res=l_decinc_expr( l, dec_inc);
  2289. }
  2290. catch( GDLException& ex)
  2291. {
  2292. // try ARRAYEXPR
  2293. try
  2294. {
  2295. tmp=l_arrayexpr_mfcall_as_arrayexpr(l, e1);
  2296. }
  2297. catch( GDLException& ex2)
  2298. {
  2299. throw GDLException(ex.toString() + " or "+ex2.toString());
  2300. }
  2301. res=l_decinc_expr( l, dec_inc);
  2302. }
  2303. _t = __t42;
  2304. _t = _t->getNextSibling();
  2305. break;
  2306. }
  2307. case ASSIGN_REPLACE:
  2308. {
  2309. ProgNodeP __t44 = _t;
  2310. ProgNodeP tmp71_AST_in = _t;
  2311. match(antlr::RefAST(_t),ASSIGN_REPLACE);
  2312. _t = _t->getFirstChild();
  2313. auto_ptr<BaseGDL> r_guard;
  2314. {
  2315. if (_t == ProgNodeP(antlr::nullAST) )
  2316. _t = ASTNULL;
  2317. switch ( _t->getType()) {
  2318. case ASSIGN:
  2319. case ASSIGN_REPLACE:
  2320. case ASSIGN_ARRAYEXPR_MFCALL:
  2321. case ARRAYDEF:
  2322. case ARRAYEXPR:
  2323. case ARRAYEXPR_MFCALL:
  2324. case CONSTANT:
  2325. case DEREF:
  2326. case EXPR:
  2327. case FCALL:
  2328. case FCALL_LIB_RETNEW:
  2329. case MFCALL:
  2330. case MFCALL_PARENT:
  2331. case NSTRUC:
  2332. case NSTRUC_REF:
  2333. case POSTDEC:
  2334. case POSTINC:
  2335. case STRUC:
  2336. case SYSVAR:
  2337. case VAR:
  2338. case VARPTR:
  2339. case DEC:
  2340. case INC:
  2341. case DOT:
  2342. case QUESTION:
  2343. {
  2344. e1=tmp_expr(_t);
  2345. _t = _retTree;
  2346. r_guard.reset( e1);
  2347. break;
  2348. }
  2349. case FCALL_LIB:
  2350. {
  2351. e1=lib_function_call(_t);
  2352. _t = _retTree;
  2353. if( !callStack.back()->Contains( e1))
  2354. r_guard.reset( e1);
  2355. break;
  2356. }
  2357. default:
  2358. {
  2359. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2360. }
  2361. }
  2362. }
  2363. ProgNodeP l = _t;
  2364. BaseGDL** tmp;
  2365. {
  2366. if (_t == ProgNodeP(antlr::nullAST) )
  2367. _t = ASTNULL;
  2368. switch ( _t->getType()) {
  2369. case FCALL:
  2370. case FCALL_LIB:
  2371. case MFCALL:
  2372. case MFCALL_PARENT:
  2373. {
  2374. tmp=l_function_call(_t);
  2375. _t = _retTree;
  2376. break;
  2377. }
  2378. case DEREF:
  2379. {
  2380. tmp=l_deref(_t);
  2381. _t = _retTree;
  2382. break;
  2383. }
  2384. case VAR:
  2385. case VARPTR:
  2386. {
  2387. tmp=l_simple_var(_t);
  2388. _t = _retTree;
  2389. break;
  2390. }
  2391. default:
  2392. {
  2393. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2394. }
  2395. }
  2396. }
  2397. if( e1 != (*tmp))
  2398. {
  2399. delete *tmp;
  2400. if( r_guard.get() == e1)
  2401. *tmp = r_guard.release();
  2402. else
  2403. *tmp = e1->Dup();
  2404. }
  2405. _t = l;
  2406. res=l_decinc_expr(_t, dec_inc);
  2407. _t = _retTree;
  2408. _t = __t44;
  2409. _t = _t->getNextSibling();
  2410. break;
  2411. }
  2412. case ARRAYEXPR:
  2413. case DEREF:
  2414. case FCALL:
  2415. case FCALL_LIB:
  2416. case MFCALL:
  2417. case MFCALL_PARENT:
  2418. case SYSVAR:
  2419. case VAR:
  2420. case VARPTR:
  2421. {
  2422. res=l_decinc_array_expr(_t, dec_inc);
  2423. _t = _retTree;
  2424. break;
  2425. }
  2426. case ARRAYEXPR_MFCALL:
  2427. {
  2428. ProgNodeP __t47 = _t;
  2429. ProgNodeP tmp72_AST_in = _t;
  2430. match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
  2431. _t = _t->getFirstChild();
  2432. ProgNodeP mark = _t;
  2433. _t = _t->getNextSibling(); // step over DOT
  2434. BaseGDL* self;
  2435. self=expr(_t);
  2436. _t = _retTree;
  2437. mp2 = _t;
  2438. match(antlr::RefAST(_t),IDENTIFIER);
  2439. _t = _t->getNextSibling();
  2440. auto_ptr<BaseGDL> self_guard(self);
  2441. EnvUDT* newEnv;
  2442. try {
  2443. newEnv=new EnvUDT( self, mp2, "", true);
  2444. self_guard.release();
  2445. }
  2446. catch( GDLException& ex)
  2447. {
  2448. _t = mark;
  2449. res=l_decinc_dot_expr(_t, dec_inc);
  2450. _retTree = startNode->getNextSibling();
  2451. return res;
  2452. }
  2453. parameter_def(_t, newEnv);
  2454. _t = _retTree;
  2455. // push environment onto call stack
  2456. callStack.push_back(newEnv);
  2457. // make the call
  2458. BaseGDL** ee=call_lfun(static_cast<DSubUD*>(
  2459. newEnv->GetPro())->GetTree());
  2460. BaseGDL* e = *ee;
  2461. if( e == NULL)
  2462. throw GDLException( _t, "Variable is undefined: "+Name(ee),true,false);
  2463. if( dec_inc == DECSTATEMENT)
  2464. {
  2465. e->Dec();
  2466. res = NULL;
  2467. _retTree = startNode->getNextSibling();
  2468. return res;
  2469. }
  2470. if( dec_inc == INCSTATEMENT)
  2471. {
  2472. e->Inc();
  2473. res = NULL;
  2474. _retTree = startNode->getNextSibling();
  2475. return res;
  2476. }
  2477. if( dec_inc == DEC) e->Dec();
  2478. else if( dec_inc == INC) e->Inc();
  2479. //
  2480. res = e->Dup();
  2481. if( dec_inc == POSTDEC) e->Dec();
  2482. else if( dec_inc == POSTINC) e->Inc();
  2483. _retTree = startNode->getNextSibling();
  2484. return res;
  2485. _t = __t47;
  2486. _t = _t->getNextSibling();
  2487. break;
  2488. }
  2489. case DOT:
  2490. {
  2491. res=l_decinc_dot_expr(_t, dec_inc);
  2492. _t = _retTree;
  2493. break;
  2494. }
  2495. case ARRAYDEF:
  2496. case EXPR:
  2497. case NSTRUC:
  2498. case NSTRUC_REF:
  2499. case POSTDEC:
  2500. case POSTINC:
  2501. case STRUC:
  2502. case DEC:
  2503. case INC:
  2504. {
  2505. e1=r_expr(_t);
  2506. _t = _retTree;
  2507. delete e1;
  2508. throw GDLException( _t,
  2509. "Expression not allowed with decrement/increment operator.",true,false);
  2510. break;
  2511. }
  2512. case CONSTANT:
  2513. {
  2514. ProgNodeP tmp73_AST_in = _t;
  2515. match(antlr::RefAST(_t),CONSTANT);
  2516. _t = _t->getNextSibling();
  2517. throw GDLException( _t,
  2518. "Constant not allowed with decrement/increment operator.",true,false);
  2519. break;
  2520. }
  2521. default:
  2522. {
  2523. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2524. }
  2525. }
  2526. _retTree = _t;
  2527. return res;
  2528. }
  2529. BaseGDL* GDLInterpreter::indexable_expr(ProgNodeP _t) {
  2530. BaseGDL* res;
  2531. ProgNodeP indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  2532. res = _t->EvalNC();
  2533. _retTree = _t->getNextSibling();
  2534. return res;
  2535. BaseGDL** e2;
  2536. if (_t == ProgNodeP(antlr::nullAST) )
  2537. _t = ASTNULL;
  2538. switch ( _t->getType()) {
  2539. case VAR:
  2540. case VARPTR:
  2541. {
  2542. e2=l_defined_simple_var(_t);
  2543. _t = _retTree;
  2544. res = *e2;
  2545. break;
  2546. }
  2547. case SYSVAR:
  2548. {
  2549. res=sys_var_nocopy(_t);
  2550. _t = _retTree;
  2551. break;
  2552. }
  2553. case CONSTANT:
  2554. {
  2555. ProgNodeP tmp74_AST_in = _t;
  2556. match(antlr::RefAST(_t),CONSTANT);
  2557. _t = _t->getNextSibling();
  2558. break;
  2559. }
  2560. case DEREF:
  2561. {
  2562. e2=l_deref(_t);
  2563. _t = _retTree;
  2564. break;
  2565. }
  2566. default:
  2567. {
  2568. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2569. }
  2570. }
  2571. _retTree = _t;
  2572. return res;
  2573. }
  2574. BaseGDL* GDLInterpreter::indexable_tmp_expr(ProgNodeP _t) {
  2575. BaseGDL* res;
  2576. ProgNodeP indexable_tmp_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  2577. ProgNodeP q = ProgNodeP(antlr::nullAST);
  2578. res = _t->Eval(); //lib_function_call_retnew(_t);
  2579. _retTree = _t->getNextSibling();
  2580. return res;
  2581. // BaseGDL* e1;
  2582. // BaseGDL* res;
  2583. // ProgNodeP q = ProgNodeP(antlr::nullAST);
  2584. // ProgNodeP a = ProgNodeP(antlr::nullAST);
  2585. switch ( _t->getType()) {
  2586. case QUESTION:
  2587. // {
  2588. // res = _t->Eval();
  2589. // _retTree = _t->getNextSibling();
  2590. // break;
  2591. // }
  2592. case ARRAYEXPR:
  2593. // {
  2594. // res = _t->Eval();
  2595. // _retTree = _t->getNextSibling();
  2596. // break;
  2597. // }
  2598. case ARRAYEXPR_MFCALL:
  2599. case FCALL:
  2600. case MFCALL:
  2601. case MFCALL_PARENT:
  2602. // {
  2603. // res=_t->Eval(); //function_call(_t);
  2604. // _retTree = _t->getNextSibling();
  2605. // // _t = _retTree;
  2606. // break;
  2607. // }
  2608. case ARRAYDEF:
  2609. case EXPR:
  2610. case NSTRUC:
  2611. case NSTRUC_REF:
  2612. case POSTDEC:
  2613. case POSTINC:
  2614. case STRUC:
  2615. case DEC:
  2616. case INC:
  2617. // {
  2618. // res=_t->Eval(); //r_expr(_t);
  2619. // _retTree = _t->getNextSibling();
  2620. // // _t = _retTree;
  2621. // break;
  2622. // }
  2623. case DOT:
  2624. // {
  2625. // res=_t->Eval(); //dot_expr(_t);
  2626. // _retTree = _t->getNextSibling();
  2627. // // _t = _retTree;
  2628. // break;
  2629. // }
  2630. case ASSIGN:
  2631. case ASSIGN_REPLACE:
  2632. case ASSIGN_ARRAYEXPR_MFCALL:
  2633. // {
  2634. // res=_t->Eval(); //assign_expr(_t);
  2635. // _retTree = _t->getNextSibling();
  2636. // // _t = _retTree;
  2637. // break;
  2638. // }
  2639. case FCALL_LIB_RETNEW:
  2640. {
  2641. res=_t->Eval(); //lib_function_call_retnew(_t);
  2642. _retTree = _t->getNextSibling();
  2643. // _t = _retTree;
  2644. break;
  2645. }
  2646. }
  2647. // _retTree = _t;
  2648. return res;
  2649. if (_t == ProgNodeP(antlr::nullAST) )
  2650. _t = ASTNULL;
  2651. switch ( _t->getType()) {
  2652. case QUESTION:
  2653. {
  2654. ProgNodeP __t85 = _t;
  2655. q = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  2656. match(antlr::RefAST(_t),QUESTION);
  2657. _t = _t->getFirstChild();
  2658. res=q->Eval();
  2659. _t = __t85;
  2660. _t = _t->getNextSibling();
  2661. break;
  2662. }
  2663. case ARRAYEXPR:
  2664. {
  2665. {
  2666. ProgNodeP tmp75_AST_in = _t;
  2667. match(antlr::RefAST(_t),ARRAYEXPR);
  2668. _t = _t->getNextSibling();
  2669. }
  2670. break;
  2671. }
  2672. case DOT:
  2673. {
  2674. res=dot_expr(_t);
  2675. _t = _retTree;
  2676. break;
  2677. }
  2678. case ASSIGN:
  2679. case ASSIGN_REPLACE:
  2680. case ASSIGN_ARRAYEXPR_MFCALL:
  2681. {
  2682. res=assign_expr(_t);
  2683. _t = _retTree;
  2684. break;
  2685. }
  2686. case ARRAYEXPR_MFCALL:
  2687. case FCALL:
  2688. case MFCALL:
  2689. case MFCALL_PARENT:
  2690. {
  2691. res=unused_function_call(_t);
  2692. _t = _retTree;
  2693. break;
  2694. }
  2695. case ARRAYDEF:
  2696. case EXPR:
  2697. case NSTRUC:
  2698. case NSTRUC_REF:
  2699. case POSTDEC:
  2700. case POSTINC:
  2701. case STRUC:
  2702. case DEC:
  2703. case INC:
  2704. {
  2705. res=r_expr(_t);
  2706. _t = _retTree;
  2707. break;
  2708. }
  2709. case FCALL_LIB_RETNEW:
  2710. {
  2711. res=lib_function_call_retnew(_t);
  2712. _t = _retTree;
  2713. break;
  2714. }
  2715. default:
  2716. {
  2717. throw antlr::NoViableAltException(antlr::RefAST(_t));
  2718. }
  2719. }
  2720. _retTree = _t;
  2721. return res;
  2722. }
  2723. BaseGDL** GDLInterpreter::l_expr(ProgNodeP _t,
  2724. BaseGDL* right
  2725. ) {
  2726. BaseGDL** res;
  2727. ProgNodeP l_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  2728. ProgNodeP dot = ProgNodeP(antlr::nullAST);
  2729. res = _t->LExpr( right);
  2730. SetRetTree( _t->getNextSibling());
  2731. return res;
  2732. BaseGDL* e1;
  2733. // switch ( _t->getType()) {
  2734. // case QUESTION:
  2735. // {
  2736. // ProgNodeP tIn = _t;
  2737. // _t = _t->getFirstChild();
  2738. // e1=expr(_t);
  2739. // _t = _retTree;
  2740. // auto_ptr<BaseGDL> e1_guard(e1);
  2741. // if( e1->True())
  2742. // {
  2743. // res=l_expr(_t, right);
  2744. // }
  2745. // else
  2746. // {
  2747. // _t=_t->GetNextSibling(); // jump over 1st expression
  2748. // res=l_expr(_t, right);
  2749. // }
  2750. // SetRetTree( tIn->getNextSibling());
  2751. // return res;
  2752. // }
  2753. // case ARRAYEXPR:
  2754. // {
  2755. // //res=l_array_expr(_t, right);
  2756. // if( right == NULL)
  2757. // throw GDLException( _t, "Indexed expression not allowed in this context.",
  2758. // true,false);
  2759. // ArrayIndexListT* aL;
  2760. // ArrayIndexListGuard guard;
  2761. // res=l_indexable_expr( _t->getFirstChild());
  2762. // aL=arrayindex_list( _retTree); //_t->getFirstChild()->getNextSibling());
  2763. // guard.reset(aL);
  2764. // try {
  2765. // aL->AssignAt( *res, right);
  2766. // }
  2767. // catch( GDLException& ex)
  2768. // {
  2769. // ex.SetErrorNodeP( _t);
  2770. // throw ex;
  2771. // }
  2772. // _retTree = _t->getNextSibling();
  2773. // return res;
  2774. // }
  2775. // case SYSVAR:
  2776. // {
  2777. // ProgNodeP sysVar = _t;
  2778. // if( right == NULL)
  2779. // throw GDLException( _t, "System variable not allowed in this context.",
  2780. // true,false);
  2781. // res=l_sys_var(_t);
  2782. // // _t = _retTree; // ok
  2783. // auto_ptr<BaseGDL> conv_guard; //( rConv);
  2784. // BaseGDL* rConv = right;
  2785. // if( !(*res)->EqType( right))
  2786. // {
  2787. // rConv = right->Convert2( (*res)->Type(), BaseGDL::COPY);
  2788. // conv_guard.reset( rConv);
  2789. // }
  2790. // if( right->N_Elements() != 1 && ((*res)->N_Elements() != right->N_Elements()))
  2791. // {
  2792. // throw GDLException( sysVar, "Conflicting data structures: <"+
  2793. // right->TypeStr()+" "+right->Dim().ToString()+">, !"+
  2794. // sysVar->getText(),true,false);
  2795. // }
  2796. // (*res)->AssignAt( rConv); // linear copy
  2797. // return res;
  2798. // }
  2799. // case FCALL:
  2800. // case FCALL_LIB:
  2801. // case MFCALL:
  2802. // case MFCALL_PARENT:
  2803. // // {
  2804. // // res=_t->LEval(); //l_function_call(_t);
  2805. // // _retTree = _t->getNextSibling();
  2806. // // //_t = _retTree;
  2807. // // if( right != NULL && right != (*res))
  2808. // // {
  2809. // // delete *res;
  2810. // // *res = right->Dup();
  2811. // // }
  2812. // // return res;
  2813. // // }
  2814. // case DEREF:
  2815. // case VAR:
  2816. // case VARPTR:
  2817. // {
  2818. // res=_t->LEval(); //l_simple_var(_t);
  2819. // _retTree = _t->getNextSibling();
  2820. // //_t = _retTree;
  2821. // if( right != NULL && right != (*res))
  2822. // {
  2823. // delete *res;
  2824. // *res = right->Dup();
  2825. // }
  2826. // return res;
  2827. // }
  2828. // case ARRAYEXPR_MFCALL:
  2829. // {
  2830. // res=l_arrayexpr_mfcall(_t, right);
  2831. // return res;
  2832. // }
  2833. // case DOT:
  2834. // {
  2835. // ProgNodeP tIn = _t;
  2836. // _t = _t->getFirstChild();
  2837. // SizeT nDot = tIn->nDot;
  2838. // auto_ptr<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
  2839. // l_dot_array_expr(_t, aD.get());
  2840. // _t = _retTree;
  2841. // for( int d=0; d<nDot; ++d)
  2842. // {
  2843. // // if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR ||
  2844. // // _t->getType() == IDENTIFIER)) {
  2845. // tag_array_expr(_t, aD.get());
  2846. // _t = _retTree;
  2847. // // }
  2848. // // else {
  2849. // // break;
  2850. // // }
  2851. // }
  2852. // if( right == NULL)
  2853. // throw GDLException( tIn, "Struct expression not allowed in this context.",
  2854. // true,false);
  2855. // aD->Assign( right);
  2856. // res=NULL;
  2857. // SetRetTree( tIn->getNextSibling());
  2858. // return res;
  2859. // }
  2860. // case ASSIGN:
  2861. // {
  2862. // ProgNodeP tIn = _t;
  2863. // _t = _t->getFirstChild();
  2864. // if( NonCopyNode(_t->getType()))
  2865. // {
  2866. // e1=indexable_expr(_t);
  2867. // _t = _retTree;
  2868. // }
  2869. // else if( _t->getType() == FCALL_LIB)
  2870. // {
  2871. // e1=lib_function_call(_t);
  2872. // _t = _retTree;
  2873. // if( !callStack.back()->Contains( e1))
  2874. // delete e1; // guard if no global data
  2875. // }
  2876. // else
  2877. // {
  2878. // // case ASSIGN:
  2879. // // case ASSIGN_REPLACE:
  2880. // // case ASSIGN_ARRAYEXPR_MFCALL:
  2881. // // case ARRAYDEF:
  2882. // // case ARRAYEXPR:
  2883. // // case ARRAYEXPR_MFCALL:
  2884. // // case EXPR:
  2885. // // case FCALL:
  2886. // // case FCALL_LIB_RETNEW:
  2887. // // case MFCALL:
  2888. // // case MFCALL_PARENT:
  2889. // // case NSTRUC:
  2890. // // case NSTRUC_REF:
  2891. // // case POSTDEC:
  2892. // // case POSTINC:
  2893. // // case STRUC:
  2894. // // case DEC:
  2895. // // case INC:
  2896. // // case DOT:
  2897. // // case QUESTION:
  2898. // e1=indexable_tmp_expr(_t);
  2899. // _t = _retTree;
  2900. // delete e1;
  2901. // }
  2902. // res=l_expr(_t, right);
  2903. // SetRetTree( tIn->getNextSibling());
  2904. // return res;
  2905. // }
  2906. // case ASSIGN_ARRAYEXPR_MFCALL:
  2907. // {
  2908. // ProgNodeP tIn = _t;
  2909. // _t = _t->getFirstChild();
  2910. // if( NonCopyNode(_t->getType()))
  2911. // {
  2912. // e1=indexable_expr(_t);
  2913. // _t = _retTree;
  2914. // }
  2915. // else if( _t->getType() == FCALL_LIB)
  2916. // {
  2917. // e1=lib_function_call(_t);
  2918. // _t = _retTree;
  2919. // if( !callStack.back()->Contains( e1))
  2920. // delete e1; // guard if no global data
  2921. // }
  2922. // else
  2923. // {
  2924. // // case ASSIGN:
  2925. // // case ASSIGN_REPLACE:
  2926. // // case ASSIGN_ARRAYEXPR_MFCALL:
  2927. // // case ARRAYDEF:
  2928. // // case ARRAYEXPR:
  2929. // // case ARRAYEXPR_MFCALL:
  2930. // // case EXPR:
  2931. // // case FCALL:
  2932. // // case FCALL_LIB_RETNEW:
  2933. // // case MFCALL:
  2934. // // case MFCALL_PARENT:
  2935. // // case NSTRUC:
  2936. // // case NSTRUC_REF:
  2937. // // case POSTDEC:
  2938. // // case POSTINC:
  2939. // // case STRUC:
  2940. // // case DEC:
  2941. // // case INC:
  2942. // // case DOT:
  2943. // // case QUESTION:
  2944. // e1=indexable_tmp_expr(_t);
  2945. // _t = _retTree;
  2946. // delete e1;
  2947. // }
  2948. // ProgNodeP l = _t;
  2949. // // try MFCALL
  2950. // try
  2951. // {
  2952. // res=l_arrayexpr_mfcall_as_mfcall( l);
  2953. // if( right != (*res))
  2954. // {
  2955. // delete *res;
  2956. // *res = right->Dup();
  2957. // }
  2958. // }
  2959. // catch( GDLException& ex)
  2960. // {
  2961. // // try ARRAYEXPR
  2962. // try
  2963. // {
  2964. // res=l_arrayexpr_mfcall_as_arrayexpr(l, right);
  2965. // }
  2966. // catch( GDLException& ex2)
  2967. // {
  2968. // throw GDLException(ex.toString() + " or "+ex2.toString());
  2969. // }
  2970. // }
  2971. // SetRetTree( tIn->getNextSibling());
  2972. // return res;
  2973. // }
  2974. // case ASSIGN_REPLACE:
  2975. // {
  2976. // ProgNodeP tIn = _t;
  2977. // _t = _t->getFirstChild();
  2978. // if( _t->getType() == FCALL_LIB)
  2979. // {
  2980. // e1=lib_function_call(_t);
  2981. // _t = _retTree;
  2982. // if( !callStack.back()->Contains( e1))
  2983. // delete e1;
  2984. // }
  2985. // else
  2986. // {
  2987. // // case ASSIGN:
  2988. // // case ASSIGN_REPLACE:
  2989. // // case ASSIGN_ARRAYEXPR_MFCALL:
  2990. // // case ARRAYDEF:
  2991. // // case ARRAYEXPR:
  2992. // // case ARRAYEXPR_MFCALL:
  2993. // // case CONSTANT:
  2994. // // case DEREF:
  2995. // // case EXPR:
  2996. // // case FCALL:
  2997. // // case FCALL_LIB_RETNEW:
  2998. // // case MFCALL:
  2999. // // case MFCALL_PARENT:
  3000. // // case NSTRUC:
  3001. // // case NSTRUC_REF:
  3002. // // case POSTDEC:
  3003. // // case POSTINC:
  3004. // // case STRUC:
  3005. // // case SYSVAR:
  3006. // // case VAR:
  3007. // // case VARPTR:
  3008. // // case DEC:
  3009. // // case INC:
  3010. // // case DOT:
  3011. // // case QUESTION:
  3012. // e1=tmp_expr(_t);
  3013. // _t = _retTree;
  3014. // delete e1;
  3015. // }
  3016. // // switch ( _t->getType()) {
  3017. // // case DEREF:
  3018. // // // {
  3019. // // // res=_t->LEval(); //l_deref(_t);
  3020. // // // _t = _retTree;
  3021. // // // break;
  3022. // // // }
  3023. // // case VAR:
  3024. // // case VARPTR:
  3025. // // // {
  3026. // // // res=_t->LEval(); //l_simple_var(_t);
  3027. // // // _retTree = tIn->getNextSibling();
  3028. // // // //_t = _retTree;
  3029. // // // break;
  3030. // // // }
  3031. // // default:
  3032. // // // case FCALL:
  3033. // // // case FCALL_LIB:
  3034. // // // case MFCALL:
  3035. // // // case MFCALL_PARENT:
  3036. // // {
  3037. // res=_t->LEval(); //l_function_call(_t);
  3038. // //_retTree = tIn->getNextSibling();
  3039. // //_t = _retTree;
  3040. // // break;
  3041. // // }
  3042. // // }
  3043. // if( right != (*res))
  3044. // {
  3045. // delete *res;
  3046. // assert( right != NULL);
  3047. // *res = right->Dup();
  3048. // }
  3049. // SetRetTree( tIn->getNextSibling());
  3050. // return res;
  3051. // }
  3052. // default:
  3053. // {
  3054. // // case ARRAYDEF:
  3055. // // case EXPR:
  3056. // // case NSTRUC:
  3057. // // case NSTRUC_REF:
  3058. // // case POSTDEC:
  3059. // // case POSTINC:
  3060. // // case STRUC:
  3061. // // case DEC:
  3062. // // case INC:
  3063. // // case CONSTANT:
  3064. // throw GDLException( _t, "Expression not allowed as l-value.",
  3065. // true,false);
  3066. // }
  3067. // } // switch
  3068. // return res; // avoid compiler warning
  3069. // l_expr finish /////////////////////////////////////////////
  3070. if (_t == ProgNodeP(antlr::nullAST) )
  3071. _t = ASTNULL;
  3072. switch ( _t->getType()) {
  3073. case QUESTION:
  3074. {
  3075. ProgNodeP __t54 = _t;
  3076. ProgNodeP tmp76_AST_in = _t;
  3077. match(antlr::RefAST(_t),QUESTION);
  3078. _t = _t->getFirstChild();
  3079. e1=expr(_t);
  3080. _t = _retTree;
  3081. _t = __t54;
  3082. _t = _t->getNextSibling();
  3083. break;
  3084. }
  3085. case ARRAYEXPR:
  3086. {
  3087. res=unused_l_array_expr(_t, right);
  3088. _t = _retTree;
  3089. break;
  3090. }
  3091. case SYSVAR:
  3092. {
  3093. res=l_sys_var(_t);
  3094. _t = _retTree;
  3095. break;
  3096. }
  3097. case DEREF:
  3098. case FCALL:
  3099. case FCALL_LIB:
  3100. case MFCALL:
  3101. case MFCALL_PARENT:
  3102. case VAR:
  3103. case VARPTR:
  3104. {
  3105. {
  3106. if (_t == ProgNodeP(antlr::nullAST) )
  3107. _t = ASTNULL;
  3108. switch ( _t->getType()) {
  3109. case FCALL:
  3110. case FCALL_LIB:
  3111. case MFCALL:
  3112. case MFCALL_PARENT:
  3113. {
  3114. res=l_function_call(_t);
  3115. _t = _retTree;
  3116. break;
  3117. }
  3118. case DEREF:
  3119. {
  3120. res=l_deref(_t);
  3121. _t = _retTree;
  3122. break;
  3123. }
  3124. case VAR:
  3125. case VARPTR:
  3126. {
  3127. res=l_simple_var(_t);
  3128. _t = _retTree;
  3129. break;
  3130. }
  3131. default:
  3132. {
  3133. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3134. }
  3135. }
  3136. }
  3137. break;
  3138. }
  3139. case ARRAYEXPR_MFCALL:
  3140. {
  3141. res=l_arrayexpr_mfcall(_t, right);
  3142. _t = _retTree;
  3143. break;
  3144. }
  3145. case DOT:
  3146. {
  3147. ProgNodeP __t56 = _t;
  3148. dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3149. match(antlr::RefAST(_t),DOT);
  3150. _t = _t->getFirstChild();
  3151. l_dot_array_expr(_t, NULL);
  3152. _t = _retTree;
  3153. _t = __t56;
  3154. _t = _t->getNextSibling();
  3155. break;
  3156. }
  3157. case ASSIGN:
  3158. {
  3159. ProgNodeP __t57 = _t;
  3160. ProgNodeP tmp77_AST_in = _t;
  3161. match(antlr::RefAST(_t),ASSIGN);
  3162. _t = _t->getFirstChild();
  3163. {
  3164. if (_t == ProgNodeP(antlr::nullAST) )
  3165. _t = ASTNULL;
  3166. switch ( _t->getType()) {
  3167. case CONSTANT:
  3168. case DEREF:
  3169. case SYSVAR:
  3170. case VAR:
  3171. case VARPTR:
  3172. {
  3173. e1=indexable_expr(_t);
  3174. _t = _retTree;
  3175. break;
  3176. }
  3177. case ASSIGN:
  3178. case ASSIGN_REPLACE:
  3179. case ASSIGN_ARRAYEXPR_MFCALL:
  3180. case ARRAYDEF:
  3181. case ARRAYEXPR:
  3182. case ARRAYEXPR_MFCALL:
  3183. case EXPR:
  3184. case FCALL:
  3185. case FCALL_LIB_RETNEW:
  3186. case MFCALL:
  3187. case MFCALL_PARENT:
  3188. case NSTRUC:
  3189. case NSTRUC_REF:
  3190. case POSTDEC:
  3191. case POSTINC:
  3192. case STRUC:
  3193. case DEC:
  3194. case INC:
  3195. case DOT:
  3196. case QUESTION:
  3197. {
  3198. e1=indexable_tmp_expr(_t);
  3199. _t = _retTree;
  3200. delete e1;
  3201. break;
  3202. }
  3203. case FCALL_LIB:
  3204. {
  3205. e1=lib_function_call(_t);
  3206. _t = _retTree;
  3207. if( !callStack.back()->Contains( e1))
  3208. delete e1; // guard if no global data
  3209. break;
  3210. }
  3211. default:
  3212. {
  3213. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3214. }
  3215. }
  3216. }
  3217. res=l_expr(_t, right);
  3218. _t = _retTree;
  3219. _t = __t57;
  3220. _t = _t->getNextSibling();
  3221. break;
  3222. }
  3223. case ASSIGN_ARRAYEXPR_MFCALL:
  3224. {
  3225. ProgNodeP __t59 = _t;
  3226. ProgNodeP tmp78_AST_in = _t;
  3227. match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
  3228. _t = _t->getFirstChild();
  3229. {
  3230. if (_t == ProgNodeP(antlr::nullAST) )
  3231. _t = ASTNULL;
  3232. switch ( _t->getType()) {
  3233. case CONSTANT:
  3234. case DEREF:
  3235. case SYSVAR:
  3236. case VAR:
  3237. case VARPTR:
  3238. {
  3239. e1=indexable_expr(_t);
  3240. _t = _retTree;
  3241. break;
  3242. }
  3243. case ASSIGN:
  3244. case ASSIGN_REPLACE:
  3245. case ASSIGN_ARRAYEXPR_MFCALL:
  3246. case ARRAYDEF:
  3247. case ARRAYEXPR:
  3248. case ARRAYEXPR_MFCALL:
  3249. case EXPR:
  3250. case FCALL:
  3251. case FCALL_LIB_RETNEW:
  3252. case MFCALL:
  3253. case MFCALL_PARENT:
  3254. case NSTRUC:
  3255. case NSTRUC_REF:
  3256. case POSTDEC:
  3257. case POSTINC:
  3258. case STRUC:
  3259. case DEC:
  3260. case INC:
  3261. case DOT:
  3262. case QUESTION:
  3263. {
  3264. e1=indexable_tmp_expr(_t);
  3265. _t = _retTree;
  3266. delete e1;
  3267. break;
  3268. }
  3269. case FCALL_LIB:
  3270. {
  3271. e1=lib_function_call(_t);
  3272. _t = _retTree;
  3273. break;
  3274. }
  3275. default:
  3276. {
  3277. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3278. }
  3279. }
  3280. }
  3281. _t = __t59;
  3282. _t = _t->getNextSibling();
  3283. break;
  3284. }
  3285. case ASSIGN_REPLACE:
  3286. {
  3287. ProgNodeP __t61 = _t;
  3288. ProgNodeP tmp79_AST_in = _t;
  3289. match(antlr::RefAST(_t),ASSIGN_REPLACE);
  3290. _t = _t->getFirstChild();
  3291. {
  3292. if (_t == ProgNodeP(antlr::nullAST) )
  3293. _t = ASTNULL;
  3294. switch ( _t->getType()) {
  3295. case ASSIGN:
  3296. case ASSIGN_REPLACE:
  3297. case ASSIGN_ARRAYEXPR_MFCALL:
  3298. case ARRAYDEF:
  3299. case ARRAYEXPR:
  3300. case ARRAYEXPR_MFCALL:
  3301. case CONSTANT:
  3302. case DEREF:
  3303. case EXPR:
  3304. case FCALL:
  3305. case FCALL_LIB_RETNEW:
  3306. case MFCALL:
  3307. case MFCALL_PARENT:
  3308. case NSTRUC:
  3309. case NSTRUC_REF:
  3310. case POSTDEC:
  3311. case POSTINC:
  3312. case STRUC:
  3313. case SYSVAR:
  3314. case VAR:
  3315. case VARPTR:
  3316. case DEC:
  3317. case INC:
  3318. case DOT:
  3319. case QUESTION:
  3320. {
  3321. e1=tmp_expr(_t);
  3322. _t = _retTree;
  3323. break;
  3324. }
  3325. case FCALL_LIB:
  3326. {
  3327. e1=lib_function_call(_t);
  3328. _t = _retTree;
  3329. break;
  3330. }
  3331. default:
  3332. {
  3333. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3334. }
  3335. }
  3336. }
  3337. {
  3338. if (_t == ProgNodeP(antlr::nullAST) )
  3339. _t = ASTNULL;
  3340. switch ( _t->getType()) {
  3341. case FCALL:
  3342. case FCALL_LIB:
  3343. case MFCALL:
  3344. case MFCALL_PARENT:
  3345. {
  3346. res=l_function_call(_t);
  3347. _t = _retTree;
  3348. break;
  3349. }
  3350. case DEREF:
  3351. {
  3352. res=l_deref(_t);
  3353. _t = _retTree;
  3354. break;
  3355. }
  3356. case VAR:
  3357. case VARPTR:
  3358. {
  3359. res=l_simple_var(_t);
  3360. _t = _retTree;
  3361. break;
  3362. }
  3363. default:
  3364. {
  3365. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3366. }
  3367. }
  3368. }
  3369. _t = __t61;
  3370. _t = _t->getNextSibling();
  3371. break;
  3372. }
  3373. case ARRAYDEF:
  3374. case EXPR:
  3375. case NSTRUC:
  3376. case NSTRUC_REF:
  3377. case POSTDEC:
  3378. case POSTINC:
  3379. case STRUC:
  3380. case DEC:
  3381. case INC:
  3382. {
  3383. e1=r_expr(_t);
  3384. _t = _retTree;
  3385. break;
  3386. }
  3387. case CONSTANT:
  3388. {
  3389. ProgNodeP tmp80_AST_in = _t;
  3390. match(antlr::RefAST(_t),CONSTANT);
  3391. _t = _t->getNextSibling();
  3392. break;
  3393. }
  3394. default:
  3395. {
  3396. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3397. }
  3398. }
  3399. _retTree = _t;
  3400. return res;
  3401. }
  3402. BaseGDL** GDLInterpreter::l_simple_var(ProgNodeP _t) {
  3403. BaseGDL** res;
  3404. ProgNodeP l_simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3405. assert( _t != NULL);
  3406. res = _t->LEval();
  3407. _retTree = _t->getNextSibling();
  3408. return res;
  3409. // _retTree = _t->getNextSibling();
  3410. // if( _t->getType() == VAR)
  3411. // {
  3412. // return &callStack.back()->GetKW(_t->varIx);
  3413. // // ProgNodeP var = _t;
  3414. // // match(antlr::RefAST(_t),VAR);
  3415. // }
  3416. // else
  3417. // {
  3418. // return &_t->var->Data(); // returns BaseGDL* of var (DVar*)
  3419. // // ProgNodeP varPtr = _t;
  3420. // // match(antlr::RefAST(_t),VARPTR);
  3421. // }
  3422. // return res;
  3423. if (_t == ProgNodeP(antlr::nullAST) )
  3424. _t = ASTNULL;
  3425. switch ( _t->getType()) {
  3426. case VAR:
  3427. {
  3428. ProgNodeP tmp81_AST_in = _t;
  3429. match(antlr::RefAST(_t),VAR);
  3430. _t = _t->getNextSibling();
  3431. break;
  3432. }
  3433. case VARPTR:
  3434. {
  3435. ProgNodeP tmp82_AST_in = _t;
  3436. match(antlr::RefAST(_t),VARPTR);
  3437. _t = _t->getNextSibling();
  3438. break;
  3439. }
  3440. default:
  3441. {
  3442. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3443. }
  3444. }
  3445. _retTree = _t;
  3446. return res;
  3447. }
  3448. void GDLInterpreter::parameter_def(ProgNodeP _t,
  3449. EnvBaseT* actEnv
  3450. ) {
  3451. ProgNodeP parameter_def_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3452. auto_ptr<EnvBaseT> guard(actEnv);
  3453. EnvBaseT* callerEnv = callStack.back();
  3454. EnvBaseT* oldNewEnv = callerEnv->GetNewEnv();
  3455. callerEnv->SetNewEnv( actEnv);
  3456. try{
  3457. _retTree = _t;
  3458. if( _retTree != NULL)
  3459. {
  3460. int nPar = _retTree->GetNParam();
  3461. int nSub = actEnv->GetPro()->NPar();
  3462. // // variable number of parameters
  3463. // if( nSub == -1)
  3464. // {
  3465. // // _retTree != NULL, save one check
  3466. // static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  3467. // while(_retTree != NULL)
  3468. // static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  3469. // }
  3470. // // fixed number of parameters
  3471. if( nSub != -1 && nPar > nSub) // check here
  3472. {
  3473. throw GDLException( _t, actEnv->GetProName() +
  3474. ": Incorrect number of arguments.",
  3475. false, false);
  3476. }
  3477. else
  3478. {
  3479. // _retTree != NULL, save one check
  3480. static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  3481. // Parameter does no checking
  3482. while(_retTree != NULL)
  3483. static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  3484. }
  3485. actEnv->Extra(); // expand _EXTRA
  3486. }
  3487. }
  3488. catch( GDLException& e)
  3489. {
  3490. callerEnv->SetNewEnv( oldNewEnv);
  3491. // update line number, currently set to caller->CallingNode()
  3492. // because actEnv is not on the stack yet,
  3493. // report caller->Pro()'s name is ok, because we are not inside
  3494. // the call yet
  3495. e.SetErrorNodeP( actEnv->CallingNode());
  3496. throw e;
  3497. }
  3498. callerEnv->SetNewEnv( oldNewEnv);
  3499. guard.release();
  3500. return;
  3501. {
  3502. ProgNodeP __t138 = _t;
  3503. ProgNodeP tmp83_AST_in = _t;
  3504. match(antlr::RefAST(_t),KEYDEF_REF);
  3505. _t = _t->getFirstChild();
  3506. ProgNodeP tmp84_AST_in = _t;
  3507. match(antlr::RefAST(_t),IDENTIFIER);
  3508. _t = _t->getNextSibling();
  3509. _t = __t138;
  3510. _t = _t->getNextSibling();
  3511. }
  3512. _retTree = _t;
  3513. }
  3514. BaseGDL** GDLInterpreter::l_indexable_expr(ProgNodeP _t) {
  3515. BaseGDL** res;
  3516. ProgNodeP l_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3517. res = _t->LEval();
  3518. if( *res == NULL)
  3519. {
  3520. // check not needed for SYSVAR
  3521. assert( _t->getType() != SYSVAR);
  3522. if( _t->getType() == VARPTR)
  3523. throw GDLException( _t, "Common block variable is undefined: "+
  3524. callStack.back()->GetString( *res),true,false);
  3525. if( _t->getType() == VAR)
  3526. throw GDLException( _t, "Variable is undefined: "+
  3527. callStack.back()->GetString(_t->varIx),true,false);
  3528. throw GDLException( _t, "Variable is undefined: "+Name(res),true,false);
  3529. }
  3530. _retTree = _t->getNextSibling();
  3531. return res;
  3532. if (_t == ProgNodeP(antlr::nullAST) )
  3533. _t = ASTNULL;
  3534. switch ( _t->getType()) {
  3535. case EXPR:
  3536. {
  3537. ProgNodeP __t49 = _t;
  3538. ProgNodeP tmp85_AST_in = _t;
  3539. match(antlr::RefAST(_t),EXPR);
  3540. _t = _t->getFirstChild();
  3541. res=l_expr(_t, NULL);
  3542. _t = _retTree;
  3543. _t = __t49;
  3544. _t = _t->getNextSibling();
  3545. break;
  3546. }
  3547. case FCALL:
  3548. case FCALL_LIB:
  3549. case MFCALL:
  3550. case MFCALL_PARENT:
  3551. {
  3552. res=l_function_call(_t);
  3553. _t = _retTree;
  3554. break;
  3555. }
  3556. case ARRAYEXPR_MFCALL:
  3557. {
  3558. res=l_arrayexpr_mfcall_as_mfcall(_t);
  3559. _t = _retTree;
  3560. break;
  3561. }
  3562. case DEREF:
  3563. {
  3564. res=l_deref(_t);
  3565. _t = _retTree;
  3566. break;
  3567. }
  3568. case VAR:
  3569. case VARPTR:
  3570. {
  3571. res=l_defined_simple_var(_t);
  3572. _t = _retTree;
  3573. break;
  3574. }
  3575. case SYSVAR:
  3576. {
  3577. res=l_sys_var(_t);
  3578. _t = _retTree;
  3579. break;
  3580. }
  3581. default:
  3582. {
  3583. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3584. }
  3585. }
  3586. _retTree = _t;
  3587. return res;
  3588. }
  3589. BaseGDL** GDLInterpreter::unused_l_array_expr(ProgNodeP _t,
  3590. BaseGDL* right
  3591. ) {
  3592. BaseGDL** res;
  3593. ProgNodeP unused_l_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3594. ProgNodeP tmp86_AST_in = _t;
  3595. match(antlr::RefAST(_t),ARRAYEXPR);
  3596. _t = _t->getNextSibling();
  3597. _retTree = _t;
  3598. return res;
  3599. }
  3600. BaseGDL** GDLInterpreter::l_arrayexpr_mfcall(ProgNodeP _t,
  3601. BaseGDL* right
  3602. ) {
  3603. BaseGDL** res;
  3604. ProgNodeP l_arrayexpr_mfcall_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3605. ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
  3606. ProgNodeP dot = ProgNodeP(antlr::nullAST);
  3607. // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
  3608. StackGuard<EnvStackT> guard(callStack);
  3609. BaseGDL *self;
  3610. EnvUDT* newEnv;
  3611. ProgNodeP startNode = _t;
  3612. ProgNodeP __t116 = _t;
  3613. ProgNodeP tmp87_AST_in = _t;
  3614. match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
  3615. _t = _t->getFirstChild();
  3616. ProgNodeP mark = _t;
  3617. _t = _t->getNextSibling(); // skip DOT
  3618. self=expr(_t);
  3619. _t = _retTree;
  3620. mp2 = _t;
  3621. match(antlr::RefAST(_t),IDENTIFIER);
  3622. _t = _t->getNextSibling();
  3623. auto_ptr<BaseGDL> self_guard(self);
  3624. try {
  3625. newEnv=new EnvUDT( self, mp2, "", true);
  3626. self_guard.release();
  3627. }
  3628. catch( GDLException& ex)
  3629. {
  3630. goto tryARRAYEXPR;
  3631. }
  3632. parameter_def(_t, newEnv);
  3633. _t = _retTree;
  3634. _t = __t116;
  3635. _t = _t->getNextSibling();
  3636. // push environment onto call stack
  3637. callStack.push_back(newEnv);
  3638. // make the call
  3639. res=call_lfun(static_cast<DSubUD*>(
  3640. newEnv->GetPro())->GetTree());
  3641. _retTree = startNode->getNextSibling();
  3642. return res;
  3643. tryARRAYEXPR:;
  3644. _t = mark;
  3645. ProgNodeP __t117 = _t;
  3646. dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3647. match(antlr::RefAST(_t),DOT);
  3648. _t = _t->getFirstChild();
  3649. SizeT nDot=dot->nDot;
  3650. auto_ptr<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
  3651. l_dot_array_expr(_t, aD.get());
  3652. _t = _retTree;
  3653. { // ( ... )+
  3654. int _cnt119=0;
  3655. for (;;) {
  3656. if (_t == ProgNodeP(antlr::nullAST) )
  3657. _t = ASTNULL;
  3658. if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
  3659. tag_array_expr(_t, aD.get());
  3660. _t = _retTree;
  3661. }
  3662. else {
  3663. if ( _cnt119>=1 ) { goto _loop119; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
  3664. }
  3665. _cnt119++;
  3666. }
  3667. _loop119:;
  3668. } // ( ... )+
  3669. _t = __t117;
  3670. _t = _t->getNextSibling();
  3671. if( right == NULL)
  3672. throw GDLException( _t,
  3673. "Struct expression not allowed in this context.",
  3674. true,false);
  3675. aD->Assign( right);
  3676. res=NULL;
  3677. _retTree = startNode->getNextSibling();
  3678. return res;
  3679. _retTree = _t;
  3680. return res;
  3681. }
  3682. void GDLInterpreter::tag_expr(ProgNodeP _t,
  3683. DotAccessDescT* aD
  3684. ) {
  3685. ProgNodeP tag_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3686. ProgNodeP i = ProgNodeP(antlr::nullAST);
  3687. BaseGDL* e;
  3688. if( _t->getType() == EXPR)
  3689. {
  3690. ProgNodeP tIn = _t;
  3691. _t = _t->getFirstChild();
  3692. e=expr(_t);
  3693. auto_ptr<BaseGDL> e_guard(e);
  3694. SizeT tagIx;
  3695. int ret=e->Scalar2index(tagIx);
  3696. if( ret < 1) // this is a return code, not the index
  3697. throw GDLException( tIn, "Expression must be a scalar"
  3698. " >= 0 in this context: "+Name(e),true,false);
  3699. aD->Add( tagIx);
  3700. _retTree = tIn->getNextSibling();
  3701. }
  3702. else
  3703. // case IDENTIFIER:
  3704. {
  3705. assert( _t->getType() == IDENTIFIER);
  3706. std::string tagName=_t->getText();
  3707. aD->Add( tagName);
  3708. _retTree = _t->getNextSibling();
  3709. }
  3710. return;
  3711. if (_t == ProgNodeP(antlr::nullAST) )
  3712. _t = ASTNULL;
  3713. switch ( _t->getType()) {
  3714. case EXPR:
  3715. {
  3716. ProgNodeP __t73 = _t;
  3717. ProgNodeP tmp88_AST_in = _t;
  3718. match(antlr::RefAST(_t),EXPR);
  3719. _t = _t->getFirstChild();
  3720. e=expr(_t);
  3721. _t = _retTree;
  3722. auto_ptr<BaseGDL> e_guard(e);
  3723. SizeT tagIx;
  3724. int ret=e->Scalar2index(tagIx);
  3725. if( ret < 1) // this is a return code, not the index
  3726. throw GDLException( _t, "Expression must be a scalar"
  3727. " >= 0 in this context: "+Name(e),true,false);
  3728. aD->Add( tagIx);
  3729. _t = __t73;
  3730. _t = _t->getNextSibling();
  3731. break;
  3732. }
  3733. case IDENTIFIER:
  3734. {
  3735. i = _t;
  3736. match(antlr::RefAST(_t),IDENTIFIER);
  3737. _t = _t->getNextSibling();
  3738. std::string tagName=i->getText();
  3739. aD->Add( tagName);
  3740. break;
  3741. }
  3742. default:
  3743. {
  3744. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3745. }
  3746. }
  3747. _retTree = _t;
  3748. }
  3749. BaseGDL* GDLInterpreter::r_dot_indexable_expr(ProgNodeP _t,
  3750. DotAccessDescT* aD
  3751. ) {
  3752. BaseGDL* res;
  3753. ProgNodeP r_dot_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3754. BaseGDL** e;
  3755. switch ( _t->getType()) {
  3756. case EXPR:
  3757. {
  3758. ProgNodeP tIn = _t;
  3759. _t = _t->getFirstChild();
  3760. res=expr(_t);
  3761. aD->SetOwner( true);
  3762. _retTree = tIn->getNextSibling();
  3763. break;
  3764. }
  3765. case VAR:
  3766. case VARPTR:
  3767. {
  3768. e=l_defined_simple_var(_t);
  3769. //_t = _retTree;
  3770. res = *e;
  3771. break;
  3772. }
  3773. case SYSVAR:
  3774. {
  3775. res = _t->EvalNC();
  3776. _retTree = _t->getNextSibling();
  3777. //res=sys_var_nocopy(_t);
  3778. //_t = _retTree;
  3779. break;
  3780. }
  3781. }
  3782. //_retTree = _t;
  3783. return res;
  3784. if (_t == ProgNodeP(antlr::nullAST) )
  3785. _t = ASTNULL;
  3786. switch ( _t->getType()) {
  3787. case EXPR:
  3788. {
  3789. ProgNodeP __t77 = _t;
  3790. ProgNodeP tmp89_AST_in = _t;
  3791. match(antlr::RefAST(_t),EXPR);
  3792. _t = _t->getFirstChild();
  3793. res=expr(_t);
  3794. _t = _retTree;
  3795. aD->SetOwner( true);
  3796. _t = __t77;
  3797. _t = _t->getNextSibling();
  3798. break;
  3799. }
  3800. case VAR:
  3801. case VARPTR:
  3802. {
  3803. e=l_defined_simple_var(_t);
  3804. _t = _retTree;
  3805. res = *e;
  3806. break;
  3807. }
  3808. case SYSVAR:
  3809. {
  3810. res=sys_var_nocopy(_t);
  3811. _t = _retTree;
  3812. break;
  3813. }
  3814. default:
  3815. {
  3816. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3817. }
  3818. }
  3819. _retTree = _t;
  3820. return res;
  3821. }
  3822. BaseGDL* GDLInterpreter::sys_var_nocopy(ProgNodeP _t) {
  3823. BaseGDL* res;
  3824. ProgNodeP sys_var_nocopy_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3825. res = _t->EvalNC();
  3826. _retTree = _t->getNextSibling();
  3827. return res; // no ->Dup()
  3828. ProgNodeP tmp90_AST_in = _t;
  3829. match(antlr::RefAST(_t),SYSVAR);
  3830. _t = _t->getNextSibling();
  3831. _retTree = _t;
  3832. return res;
  3833. }
  3834. void GDLInterpreter::r_dot_array_expr(ProgNodeP _t,
  3835. DotAccessDescT* aD
  3836. ) {
  3837. ProgNodeP r_dot_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3838. ArrayIndexListT* aL;
  3839. BaseGDL* r;
  3840. DStructGDL* structR;
  3841. ArrayIndexListGuard guard;
  3842. bool isObj = callStack.back()->IsObject();
  3843. if (_t == ProgNodeP(antlr::nullAST) )
  3844. _t = ASTNULL;
  3845. switch ( _t->getType()) {
  3846. case ARRAYEXPR:
  3847. {
  3848. ProgNodeP __t79 = _t;
  3849. ProgNodeP tmp91_AST_in = _t;
  3850. match(antlr::RefAST(_t),ARRAYEXPR);
  3851. _t = _t->getFirstChild();
  3852. r=r_dot_indexable_expr(_t, aD);
  3853. _t = _retTree;
  3854. aL=arrayindex_list(_t);
  3855. _t = _retTree;
  3856. guard.reset(aL);
  3857. _t = __t79;
  3858. _t = _t->getNextSibling();
  3859. // check here for object and get struct
  3860. structR=dynamic_cast<DStructGDL*>(r);
  3861. if( structR == NULL)
  3862. {
  3863. if( isObj)
  3864. {
  3865. DStructGDL* oStruct = ObjectStructCheckAccess( r, _t);
  3866. // DStructGDL* obj = oStruct->Index( aL);
  3867. if( aD->IsOwner()) delete r;
  3868. aD->SetOwner( false); // object struct, not owned
  3869. aD->Root( oStruct, guard.release());
  3870. // aD->Root( obj);
  3871. // BaseGDL* obj = r->Index( aL);
  3872. // auto_ptr<BaseGDL> objGuard( obj); // new object -> guard
  3873. // DStructGDL* oStruct = ObjectStructCheckAccess( obj, _t);
  3874. // // oStruct cannot be "Assoc_"
  3875. // if( aD->IsOwner()) delete r;
  3876. // aD->SetOwner( false); // object structs are never owned
  3877. // aD->Root( oStruct);
  3878. }
  3879. else
  3880. {
  3881. throw GDLException( _t, "Expression must be a"
  3882. " STRUCT in this context: "+Name(r),true,false);
  3883. }
  3884. }
  3885. else
  3886. {
  3887. if( r->IsAssoc())
  3888. throw GDLException( _t, "File expression not allowed "
  3889. "in this context: "+Name(r),true,false);
  3890. aD->Root( structR, guard.release());
  3891. }
  3892. break;
  3893. }
  3894. case EXPR:
  3895. case SYSVAR:
  3896. case VAR:
  3897. case VARPTR:
  3898. {
  3899. r=r_dot_indexable_expr(_t, aD);
  3900. _t = _retTree;
  3901. // check here for object and get struct
  3902. structR = dynamic_cast<DStructGDL*>(r);
  3903. if( structR == NULL)
  3904. {
  3905. if( isObj) // memeber access to object?
  3906. {
  3907. DStructGDL* oStruct = ObjectStructCheckAccess( r, _t);
  3908. // oStruct cannot be "Assoc_"
  3909. if( aD->IsOwner()) delete r;
  3910. aD->SetOwner( false); // object structs are never owned
  3911. aD->Root( oStruct);
  3912. }
  3913. else
  3914. {
  3915. throw GDLException( _t, "Expression must be a"
  3916. " STRUCT in this context: "+Name(r),true,false);
  3917. }
  3918. }
  3919. else
  3920. {
  3921. if( r->IsAssoc())
  3922. {
  3923. throw GDLException( _t, "File expression not allowed "
  3924. "in this context: "+Name(r),true,false);
  3925. }
  3926. aD->Root(structR);
  3927. }
  3928. break;
  3929. }
  3930. default:
  3931. {
  3932. throw antlr::NoViableAltException(antlr::RefAST(_t));
  3933. }
  3934. }
  3935. _retTree = _t;
  3936. }
  3937. BaseGDL* GDLInterpreter::dot_expr(ProgNodeP _t) {
  3938. BaseGDL* res;
  3939. ProgNodeP dot_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3940. res = _t->Eval();
  3941. _retTree = _t->getNextSibling();
  3942. return res;
  3943. // ProgNodeP rTree = _t->getNextSibling();
  3944. // //ProgNodeP
  3945. // dot = _t;
  3946. // // match(antlr::RefAST(_t),DOT);
  3947. // _t = _t->getFirstChild();
  3948. // SizeT nDot=dot->nDot;
  3949. // DotAccessDescT aD( nDot+1);
  3950. // r_dot_array_expr(_t, &aD);
  3951. // _t = _retTree;
  3952. // for (; _t != NULL;) {
  3953. // tag_array_expr(_t, &aD); // nDot times
  3954. // _t = _retTree;
  3955. // }
  3956. // res= aD.Resolve();
  3957. // _retTree = rTree;
  3958. // return res;
  3959. ProgNodeP __t81 = _t;
  3960. ProgNodeP tmp92_AST_in = _t;
  3961. match(antlr::RefAST(_t),DOT);
  3962. _t = _t->getFirstChild();
  3963. r_dot_array_expr(_t, NULL);
  3964. _t = _retTree;
  3965. { // ( ... )+
  3966. int _cnt83=0;
  3967. for (;;) {
  3968. if (_t == ProgNodeP(antlr::nullAST) )
  3969. _t = ASTNULL;
  3970. if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
  3971. tag_array_expr(_t, NULL);
  3972. _t = _retTree;
  3973. }
  3974. else {
  3975. if ( _cnt83>=1 ) { goto _loop83; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
  3976. }
  3977. _cnt83++;
  3978. }
  3979. _loop83:;
  3980. } // ( ... )+
  3981. _t = __t81;
  3982. _t = _t->getNextSibling();
  3983. _retTree = _t;
  3984. return res;
  3985. }
  3986. BaseGDL* GDLInterpreter::assign_expr(ProgNodeP _t) {
  3987. BaseGDL* res;
  3988. ProgNodeP assign_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  3989. res = _t->Eval();
  3990. _retTree = _t->getNextSibling();
  3991. return res;
  3992. BaseGDL** l;
  3993. if (_t == ProgNodeP(antlr::nullAST) )
  3994. _t = ASTNULL;
  3995. switch ( _t->getType()) {
  3996. case ASSIGN:
  3997. {
  3998. ProgNodeP __t93 = _t;
  3999. ProgNodeP tmp93_AST_in = _t;
  4000. match(antlr::RefAST(_t),ASSIGN);
  4001. _t = _t->getFirstChild();
  4002. {
  4003. if (_t == ProgNodeP(antlr::nullAST) )
  4004. _t = ASTNULL;
  4005. switch ( _t->getType()) {
  4006. case ASSIGN:
  4007. case ASSIGN_REPLACE:
  4008. case ASSIGN_ARRAYEXPR_MFCALL:
  4009. case ARRAYDEF:
  4010. case ARRAYEXPR:
  4011. case ARRAYEXPR_MFCALL:
  4012. case CONSTANT:
  4013. case DEREF:
  4014. case EXPR:
  4015. case FCALL:
  4016. case FCALL_LIB_RETNEW:
  4017. case MFCALL:
  4018. case MFCALL_PARENT:
  4019. case NSTRUC:
  4020. case NSTRUC_REF:
  4021. case POSTDEC:
  4022. case POSTINC:
  4023. case STRUC:
  4024. case SYSVAR:
  4025. case VAR:
  4026. case VARPTR:
  4027. case DEC:
  4028. case INC:
  4029. case DOT:
  4030. case QUESTION:
  4031. {
  4032. res=tmp_expr(_t);
  4033. _t = _retTree;
  4034. break;
  4035. }
  4036. case FCALL_LIB:
  4037. {
  4038. res=lib_function_call(_t);
  4039. _t = _retTree;
  4040. break;
  4041. }
  4042. default:
  4043. {
  4044. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4045. }
  4046. }
  4047. }
  4048. l=l_expr(_t, res);
  4049. _t = _retTree;
  4050. _t = __t93;
  4051. _t = _t->getNextSibling();
  4052. break;
  4053. }
  4054. case ASSIGN_ARRAYEXPR_MFCALL:
  4055. {
  4056. ProgNodeP __t95 = _t;
  4057. ProgNodeP tmp94_AST_in = _t;
  4058. match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
  4059. _t = _t->getFirstChild();
  4060. {
  4061. if (_t == ProgNodeP(antlr::nullAST) )
  4062. _t = ASTNULL;
  4063. switch ( _t->getType()) {
  4064. case ASSIGN:
  4065. case ASSIGN_REPLACE:
  4066. case ASSIGN_ARRAYEXPR_MFCALL:
  4067. case ARRAYDEF:
  4068. case ARRAYEXPR:
  4069. case ARRAYEXPR_MFCALL:
  4070. case CONSTANT:
  4071. case DEREF:
  4072. case EXPR:
  4073. case FCALL:
  4074. case FCALL_LIB_RETNEW:
  4075. case MFCALL:
  4076. case MFCALL_PARENT:
  4077. case NSTRUC:
  4078. case NSTRUC_REF:
  4079. case POSTDEC:
  4080. case POSTINC:
  4081. case STRUC:
  4082. case SYSVAR:
  4083. case VAR:
  4084. case VARPTR:
  4085. case DEC:
  4086. case INC:
  4087. case DOT:
  4088. case QUESTION:
  4089. {
  4090. res=tmp_expr(_t);
  4091. _t = _retTree;
  4092. break;
  4093. }
  4094. case FCALL_LIB:
  4095. {
  4096. res=lib_function_call(_t);
  4097. _t = _retTree;
  4098. break;
  4099. }
  4100. default:
  4101. {
  4102. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4103. }
  4104. }
  4105. }
  4106. l=l_expr(_t, res);
  4107. _t = _retTree;
  4108. _t = __t95;
  4109. _t = _t->getNextSibling();
  4110. break;
  4111. }
  4112. case ASSIGN_REPLACE:
  4113. {
  4114. ProgNodeP __t97 = _t;
  4115. ProgNodeP tmp95_AST_in = _t;
  4116. match(antlr::RefAST(_t),ASSIGN_REPLACE);
  4117. _t = _t->getFirstChild();
  4118. {
  4119. if (_t == ProgNodeP(antlr::nullAST) )
  4120. _t = ASTNULL;
  4121. switch ( _t->getType()) {
  4122. case ASSIGN:
  4123. case ASSIGN_REPLACE:
  4124. case ASSIGN_ARRAYEXPR_MFCALL:
  4125. case ARRAYDEF:
  4126. case ARRAYEXPR:
  4127. case ARRAYEXPR_MFCALL:
  4128. case CONSTANT:
  4129. case DEREF:
  4130. case EXPR:
  4131. case FCALL:
  4132. case FCALL_LIB_RETNEW:
  4133. case MFCALL:
  4134. case MFCALL_PARENT:
  4135. case NSTRUC:
  4136. case NSTRUC_REF:
  4137. case POSTDEC:
  4138. case POSTINC:
  4139. case STRUC:
  4140. case SYSVAR:
  4141. case VAR:
  4142. case VARPTR:
  4143. case DEC:
  4144. case INC:
  4145. case DOT:
  4146. case QUESTION:
  4147. {
  4148. res=tmp_expr(_t);
  4149. _t = _retTree;
  4150. break;
  4151. }
  4152. case FCALL_LIB:
  4153. {
  4154. res=lib_function_call(_t);
  4155. _t = _retTree;
  4156. break;
  4157. }
  4158. default:
  4159. {
  4160. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4161. }
  4162. }
  4163. }
  4164. {
  4165. if (_t == ProgNodeP(antlr::nullAST) )
  4166. _t = ASTNULL;
  4167. switch ( _t->getType()) {
  4168. case FCALL:
  4169. case FCALL_LIB:
  4170. case MFCALL:
  4171. case MFCALL_PARENT:
  4172. {
  4173. l=l_function_call(_t);
  4174. _t = _retTree;
  4175. break;
  4176. }
  4177. case DEREF:
  4178. {
  4179. l=l_deref(_t);
  4180. _t = _retTree;
  4181. break;
  4182. }
  4183. case VAR:
  4184. case VARPTR:
  4185. {
  4186. l=l_simple_var(_t);
  4187. _t = _retTree;
  4188. break;
  4189. }
  4190. default:
  4191. {
  4192. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4193. }
  4194. }
  4195. }
  4196. _t = __t97;
  4197. _t = _t->getNextSibling();
  4198. break;
  4199. }
  4200. default:
  4201. {
  4202. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4203. }
  4204. }
  4205. _retTree = _t;
  4206. return res;
  4207. }
  4208. BaseGDL* GDLInterpreter::unused_function_call(ProgNodeP _t) {
  4209. BaseGDL* res;
  4210. ProgNodeP unused_function_call_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4211. ProgNodeP mp = ProgNodeP(antlr::nullAST);
  4212. ProgNodeP parent = ProgNodeP(antlr::nullAST);
  4213. ProgNodeP p = ProgNodeP(antlr::nullAST);
  4214. ProgNodeP f = ProgNodeP(antlr::nullAST);
  4215. ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
  4216. // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
  4217. StackGuard<EnvStackT> guard(callStack);
  4218. BaseGDL *self;
  4219. EnvUDT* newEnv;
  4220. ProgNodeP startNode = _t;
  4221. ProgNodeP mark;
  4222. {
  4223. if (_t == ProgNodeP(antlr::nullAST) )
  4224. _t = ASTNULL;
  4225. switch ( _t->getType()) {
  4226. case MFCALL:
  4227. {
  4228. ProgNodeP __t111 = _t;
  4229. ProgNodeP tmp96_AST_in = _t;
  4230. match(antlr::RefAST(_t),MFCALL);
  4231. _t = _t->getFirstChild();
  4232. self=expr(_t);
  4233. _t = _retTree;
  4234. mp = _t;
  4235. match(antlr::RefAST(_t),IDENTIFIER);
  4236. _t = _t->getNextSibling();
  4237. parameter_def(_t, newEnv);
  4238. _t = _retTree;
  4239. _t = __t111;
  4240. _t = _t->getNextSibling();
  4241. break;
  4242. }
  4243. case MFCALL_PARENT:
  4244. {
  4245. ProgNodeP __t112 = _t;
  4246. ProgNodeP tmp97_AST_in = _t;
  4247. match(antlr::RefAST(_t),MFCALL_PARENT);
  4248. _t = _t->getFirstChild();
  4249. self=expr(_t);
  4250. _t = _retTree;
  4251. parent = _t;
  4252. match(antlr::RefAST(_t),IDENTIFIER);
  4253. _t = _t->getNextSibling();
  4254. p = _t;
  4255. match(antlr::RefAST(_t),IDENTIFIER);
  4256. _t = _t->getNextSibling();
  4257. parameter_def(_t, newEnv);
  4258. _t = _retTree;
  4259. _t = __t112;
  4260. _t = _t->getNextSibling();
  4261. break;
  4262. }
  4263. case FCALL:
  4264. {
  4265. ProgNodeP __t113 = _t;
  4266. f = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4267. match(antlr::RefAST(_t),FCALL);
  4268. _t = _t->getFirstChild();
  4269. parameter_def(_t, newEnv);
  4270. _t = _retTree;
  4271. _t = __t113;
  4272. _t = _t->getNextSibling();
  4273. break;
  4274. }
  4275. case ARRAYEXPR_MFCALL:
  4276. {
  4277. ProgNodeP __t114 = _t;
  4278. ProgNodeP tmp98_AST_in = _t;
  4279. match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
  4280. _t = _t->getFirstChild();
  4281. self=expr(_t);
  4282. _t = _retTree;
  4283. mp2 = _t;
  4284. match(antlr::RefAST(_t),IDENTIFIER);
  4285. _t = _t->getNextSibling();
  4286. parameter_def(_t, newEnv);
  4287. _t = _retTree;
  4288. _t = __t114;
  4289. _t = _t->getNextSibling();
  4290. break;
  4291. }
  4292. default:
  4293. {
  4294. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4295. }
  4296. }
  4297. }
  4298. _retTree = _t;
  4299. return res;
  4300. }
  4301. BaseGDL* GDLInterpreter::lib_function_call_retnew(ProgNodeP _t) {
  4302. BaseGDL* res;
  4303. ProgNodeP lib_function_call_retnew_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4304. res = _t->Eval();
  4305. _retTree = _t->getNextSibling();
  4306. return res; //_t->cData->Dup();
  4307. // // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
  4308. // StackGuard<EnvStackT> guard(callStack);
  4309. // ProgNodeP rTree = _t->getNextSibling();
  4310. // // match(antlr::RefAST(_t),FCALL_LIB_RETNEW);
  4311. // // _t = _t->getFirstChild();
  4312. // // match(antlr::RefAST(_t),IDENTIFIER);
  4313. // EnvT* newEnv=new EnvT( _t, _t->libFun);//libFunList[fl->funIx]);
  4314. // // special handling for N_ELEMENTS()
  4315. // static int n_elementsIx = LibFunIx("N_ELEMENTS");
  4316. // static DLibFun* n_elementsFun = libFunList[n_elementsIx];
  4317. // if( _t->libFun == n_elementsFun)
  4318. // {
  4319. // parameter_def_n_elements(_t->getFirstChild(), newEnv);
  4320. // }
  4321. // else
  4322. // {
  4323. // parameter_def(_t->getFirstChild(), newEnv);
  4324. // }
  4325. // // push id.pro onto call stack
  4326. // callStack.push_back(newEnv);
  4327. // // make the call
  4328. // //BaseGDL*
  4329. // res=static_cast<DLibFun*>(newEnv->GetPro())->Fun()(newEnv);
  4330. // //*** MUST always return a defined expression
  4331. // _retTree = rTree;
  4332. // return res;
  4333. EnvT* newEnv;
  4334. ProgNodeP __t108 = _t;
  4335. ProgNodeP tmp99_AST_in = _t;
  4336. match(antlr::RefAST(_t),FCALL_LIB_RETNEW);
  4337. _t = _t->getFirstChild();
  4338. parameter_def(_t, newEnv);
  4339. _t = _retTree;
  4340. _t = __t108;
  4341. _t = _t->getNextSibling();
  4342. _retTree = _t;
  4343. return res;
  4344. }
  4345. BaseGDL* GDLInterpreter::constant(ProgNodeP _t) {
  4346. BaseGDL* res;
  4347. ProgNodeP constant_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4348. res = _t->Eval();
  4349. _retTree = _t->getNextSibling();
  4350. return res; //_t->cData->Dup();
  4351. ProgNodeP tmp100_AST_in = _t;
  4352. match(antlr::RefAST(_t),CONSTANT);
  4353. _t = _t->getNextSibling();
  4354. _retTree = _t;
  4355. return res;
  4356. }
  4357. BaseGDL* GDLInterpreter::simple_var(ProgNodeP _t) {
  4358. BaseGDL* res;
  4359. ProgNodeP simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4360. ProgNodeP var = ProgNodeP(antlr::nullAST);
  4361. ProgNodeP varPtr = ProgNodeP(antlr::nullAST);
  4362. assert( _t != NULL);
  4363. BaseGDL* vData = _t->EvalNC();
  4364. if( vData == NULL)
  4365. {
  4366. if( _t->getType() == VAR)
  4367. throw GDLException( _t, "Variable is undefined: "+var->getText(),true,false);
  4368. else // VARPTR
  4369. throw GDLException( _t, "Common block variable is undefined.",true,false);
  4370. }
  4371. _retTree = _t->getNextSibling();
  4372. return vData->Dup();
  4373. if (_t == ProgNodeP(antlr::nullAST) )
  4374. _t = ASTNULL;
  4375. switch ( _t->getType()) {
  4376. case VAR:
  4377. {
  4378. var = _t;
  4379. match(antlr::RefAST(_t),VAR);
  4380. _t = _t->getNextSibling();
  4381. break;
  4382. }
  4383. case VARPTR:
  4384. {
  4385. varPtr = _t;
  4386. match(antlr::RefAST(_t),VARPTR);
  4387. _t = _t->getNextSibling();
  4388. break;
  4389. }
  4390. default:
  4391. {
  4392. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4393. }
  4394. }
  4395. _retTree = _t;
  4396. return res;
  4397. }
  4398. BaseGDL* GDLInterpreter::sys_var(ProgNodeP _t) {
  4399. BaseGDL* res;
  4400. ProgNodeP sys_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4401. res = _t->Eval();
  4402. _retTree = _t->getNextSibling();
  4403. return res; // no ->Dup()
  4404. res=sys_var_nocopy(_t);
  4405. _t = _retTree;
  4406. _retTree = _t;
  4407. return res;
  4408. }
  4409. BaseGDL* GDLInterpreter::unused_constant_nocopy(ProgNodeP _t) {
  4410. BaseGDL* res;
  4411. ProgNodeP unused_constant_nocopy_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4412. ProgNodeP c = ProgNodeP(antlr::nullAST);
  4413. //BaseGDL*
  4414. _retTree = _t->getNextSibling();
  4415. return _t->cData; // no ->Dup();
  4416. c = _t;
  4417. match(antlr::RefAST(_t),CONSTANT);
  4418. _t = _t->getNextSibling();
  4419. _retTree = _t;
  4420. return res;
  4421. }
  4422. BaseGDL** GDLInterpreter::l_arrayexpr_mfcall_as_arrayexpr(ProgNodeP _t,
  4423. BaseGDL* right
  4424. ) {
  4425. BaseGDL** res;
  4426. ProgNodeP l_arrayexpr_mfcall_as_arrayexpr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4427. ProgNodeP dot = ProgNodeP(antlr::nullAST);
  4428. ProgNodeP __t121 = _t;
  4429. ProgNodeP tmp101_AST_in = _t;
  4430. match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
  4431. _t = _t->getFirstChild();
  4432. ProgNodeP __t122 = _t;
  4433. dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4434. match(antlr::RefAST(_t),DOT);
  4435. _t = _t->getFirstChild();
  4436. SizeT nDot=dot->nDot;
  4437. auto_ptr<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
  4438. l_dot_array_expr(_t, aD.get());
  4439. _t = _retTree;
  4440. { // ( ... )+
  4441. int _cnt124=0;
  4442. for (;;) {
  4443. if (_t == ProgNodeP(antlr::nullAST) )
  4444. _t = ASTNULL;
  4445. if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
  4446. tag_array_expr(_t, aD.get());
  4447. _t = _retTree;
  4448. }
  4449. else {
  4450. if ( _cnt124>=1 ) { goto _loop124; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
  4451. }
  4452. _cnt124++;
  4453. }
  4454. _loop124:;
  4455. } // ( ... )+
  4456. _t = __t122;
  4457. _t = _t->getNextSibling();
  4458. _t = __t121;
  4459. _t = _t->getNextSibling();
  4460. if( right == NULL)
  4461. throw GDLException( _t,
  4462. "Struct expression not allowed in this context.",
  4463. true,false);
  4464. aD->Assign( right);
  4465. res=NULL;
  4466. _retTree = _t;
  4467. return res;
  4468. }
  4469. void GDLInterpreter::parameter_def_n_elements(ProgNodeP _t,
  4470. EnvBaseT* actEnv
  4471. ) {
  4472. ProgNodeP parameter_def_n_elements_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4473. auto_ptr<EnvBaseT> guard(actEnv);
  4474. _retTree = _t;
  4475. // bool interruptEnableIn = interruptEnable;
  4476. if( _retTree != NULL)
  4477. {
  4478. int nPar = _retTree->GetNParam();
  4479. //int nSub = actEnv->GetPro()->NPar();
  4480. assert( actEnv->GetPro()->NPar() == 1); // N_ELEMENTS
  4481. // fixed number of parameters
  4482. if( nPar > 1)//nSub) // check here
  4483. {
  4484. throw GDLException( _t, actEnv->GetProName() +
  4485. ": Incorrect number of arguments.",
  4486. false, false);
  4487. }
  4488. if( _retTree->getType() == REF ||
  4489. _retTree->getType() == REF_EXPR ||
  4490. _retTree->getType() == REF_CHECK ||
  4491. _retTree->getType() == PARAEXPR)
  4492. {
  4493. try
  4494. {
  4495. // interruptEnable = false;
  4496. static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  4497. // interruptEnable = interruptEnableIn;
  4498. }
  4499. catch( GDLException& e)
  4500. {
  4501. // an error occured -> parameter is undefined
  4502. // interruptEnable = interruptEnableIn;
  4503. if( actEnv->NParam() == 0) // not set yet
  4504. {
  4505. BaseGDL* nullP = NULL;
  4506. actEnv->SetNextPar( nullP);
  4507. }
  4508. }
  4509. }
  4510. else // used for error handling: keywords are checked only here in Parameter()
  4511. {
  4512. try
  4513. {
  4514. // as N_ELEMENTS has no keywords this should throw always
  4515. static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  4516. assert( 0);
  4517. }
  4518. catch( GDLException& e)
  4519. {
  4520. // update line number, currently set to caller->CallingNode()
  4521. // because actEnv is not on the stack yet,
  4522. // report caller->Pro()'s name is ok, because we are not inside
  4523. // the call yet
  4524. e.SetErrorNodeP( actEnv->CallingNode());
  4525. throw e;
  4526. }
  4527. }
  4528. // actEnv->Extra(); // expand _EXTRA
  4529. } // if( _retTree != NULL)
  4530. guard.release();
  4531. return;
  4532. ProgNodeP __t135 = _t;
  4533. ProgNodeP tmp102_AST_in = _t;
  4534. match(antlr::RefAST(_t),KEYDEF_REF_EXPR);
  4535. _t = _t->getFirstChild();
  4536. ProgNodeP tmp103_AST_in = _t;
  4537. match(antlr::RefAST(_t),IDENTIFIER);
  4538. _t = _t->getNextSibling();
  4539. _t = __t135;
  4540. _t = _t->getNextSibling();
  4541. _retTree = _t;
  4542. }
  4543. void GDLInterpreter::parameter_def_nocheck(ProgNodeP _t,
  4544. EnvBaseT* actEnv
  4545. ) {
  4546. ProgNodeP parameter_def_nocheck_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4547. auto_ptr<EnvBaseT> guard(actEnv);
  4548. EnvBaseT* callerEnv = callStack.back();
  4549. EnvBaseT* oldNewEnv = callerEnv->GetNewEnv();
  4550. callerEnv->SetNewEnv( actEnv);
  4551. try{
  4552. if( _t != NULL)
  4553. {
  4554. _retTree = _t;
  4555. // _retTree != NULL, save one check // 'if' is needed already for Extra()
  4556. static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  4557. // Parameter does no checking
  4558. while(_retTree != NULL)
  4559. static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
  4560. actEnv->Extra(); // expand _EXTRA
  4561. }
  4562. }
  4563. catch( GDLException& e)
  4564. {
  4565. callerEnv->SetNewEnv( oldNewEnv);
  4566. // update line number, currently set to caller->CallingNode()
  4567. // because actEnv is not on the stack yet,
  4568. // report caller->Pro()'s name is ok, because we are not inside
  4569. // the call yet
  4570. e.SetErrorNodeP( actEnv->CallingNode());
  4571. throw e;
  4572. }
  4573. callerEnv->SetNewEnv( oldNewEnv);
  4574. guard.release();
  4575. return;
  4576. {
  4577. ProgNodeP __t141 = _t;
  4578. ProgNodeP tmp104_AST_in = _t;
  4579. match(antlr::RefAST(_t),KEYDEF_REF);
  4580. _t = _t->getFirstChild();
  4581. ProgNodeP tmp105_AST_in = _t;
  4582. match(antlr::RefAST(_t),IDENTIFIER);
  4583. _t = _t->getNextSibling();
  4584. _t = __t141;
  4585. _t = _t->getNextSibling();
  4586. }
  4587. _retTree = _t;
  4588. }
  4589. ArrayIndexListT* GDLInterpreter::arrayindex_list_noassoc(ProgNodeP _t) {
  4590. ArrayIndexListT* aL;
  4591. ProgNodeP arrayindex_list_noassoc_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
  4592. IxExprListT cleanupList; // for cleanup
  4593. IxExprListT ixExprList;
  4594. SizeT nExpr;
  4595. BaseGDL* s;
  4596. // ProgNodeP retTree = _t->getNextSibling();
  4597. ProgNodeP ax = _t;
  4598. // match(antlr::RefAST(_t),ARRAYIX);
  4599. _t = _t->getFirstChild();
  4600. aL = ax->arrIxListNoAssoc;
  4601. assert( aL != NULL);
  4602. nExpr = aL->NParam();
  4603. if( nExpr == 0)
  4604. {
  4605. aL->Init();
  4606. _retTree = ax->getNextSibling();//retTree;
  4607. return aL;
  4608. }
  4609. while( true) {
  4610. assert( _t != NULL);
  4611. if( NonCopyNode( _t->getType()))
  4612. {
  4613. s= _t->EvalNC(); //indexable_expr(_t);
  4614. //_t = _retTree;
  4615. }
  4616. else if( _t->getType() == GDLTokenTypes::FCALL_LIB)
  4617. {
  4618. s=lib_function_call(_t);
  4619. //_t = _retTree;
  4620. if( !callStack.back()->Contains( s))
  4621. cleanupList.push_back( s);
  4622. }
  4623. else
  4624. {
  4625. s=_t->Eval(); //indexable_tmp_expr(_t);
  4626. //_t = _retTree;
  4627. cleanupList.push_back( s);
  4628. }
  4629. ixExprList.push_back( s);
  4630. if( ixExprList.size() == nExpr)
  4631. break; // allows some manual tuning
  4632. _t = _t->getNextSibling();
  4633. }
  4634. aL->Init( ixExprList, &cleanupList);
  4635. _retTree = ax->getNextSibling();//retTree;
  4636. return aL;
  4637. ProgNodeP __t148 = _t;
  4638. ProgNodeP tmp106_AST_in = _t;
  4639. match(antlr::RefAST(_t),ARRAYIX);
  4640. _t = _t->getFirstChild();
  4641. { // ( ... )*
  4642. for (;;) {
  4643. if (_t == ProgNodeP(antlr::nullAST) )
  4644. _t = ASTNULL;
  4645. if ((_tokenSet_1.member(_t->getType()))) {
  4646. {
  4647. if (_t == ProgNodeP(antlr::nullAST) )
  4648. _t = ASTNULL;
  4649. switch ( _t->getType()) {
  4650. case CONSTANT:
  4651. case DEREF:
  4652. case SYSVAR:
  4653. case VAR:
  4654. case VARPTR:
  4655. {
  4656. s=indexable_expr(_t);
  4657. _t = _retTree;
  4658. break;
  4659. }
  4660. case FCALL_LIB:
  4661. {
  4662. s=lib_function_call(_t);
  4663. _t = _retTree;
  4664. break;
  4665. }
  4666. case ASSIGN:
  4667. case ASSIGN_REPLACE:
  4668. case ASSIGN_ARRAYEXPR_MFCALL:
  4669. case ARRAYDEF:
  4670. case ARRAYEXPR:
  4671. case ARRAYEXPR_MFCALL:
  4672. case EXPR:
  4673. case FCALL:
  4674. case FCALL_LIB_RETNEW:
  4675. case MFCALL:
  4676. case MFCALL_PARENT:
  4677. case NSTRUC:
  4678. case NSTRUC_REF:
  4679. case POSTDEC:
  4680. case POSTINC:
  4681. case STRUC:
  4682. case DEC:
  4683. case INC:
  4684. case DOT:
  4685. case QUESTION:
  4686. {
  4687. s=indexable_tmp_expr(_t);
  4688. _t = _retTree;
  4689. break;
  4690. }
  4691. default:
  4692. {
  4693. throw antlr::NoViableAltException(antlr::RefAST(_t));
  4694. }
  4695. }
  4696. }
  4697. }
  4698. else {
  4699. goto _loop151;
  4700. }
  4701. }
  4702. _loop151:;
  4703. } // ( ... )*
  4704. _t = __t148;
  4705. _t = _t->getNextSibling();
  4706. _retTree = _t;
  4707. return aL;
  4708. }
  4709. void GDLInterpreter::initializeASTFactory( antlr::ASTFactory& )
  4710. {
  4711. }
  4712. const char* GDLInterpreter::tokenNames[] = {
  4713. "<0>",
  4714. "EOF",
  4715. "<2>",
  4716. "NULL_TREE_LOOKAHEAD",
  4717. "ALL",
  4718. "ASSIGN",
  4719. "ASSIGN_INPLACE",
  4720. "ASSIGN_REPLACE",
  4721. "ASSIGN_ARRAYEXPR_MFCALL",
  4722. "ARRAYDEF",
  4723. "ARRAYDEF_CONST",
  4724. "ARRAYIX",
  4725. "ARRAYIX_ALL",
  4726. "ARRAYIX_ORANGE",
  4727. "ARRAYIX_RANGE",
  4728. "ARRAYIX_ORANGE_S",
  4729. "ARRAYIX_RANGE_S",
  4730. "ARRAYEXPR",
  4731. "ARRAYEXPR_FN",
  4732. "ARRAYEXPR_MFCALL",
  4733. "BLOCK",
  4734. "BREAK",
  4735. "CSBLOCK",
  4736. "CONTINUE",
  4737. "COMMONDECL",
  4738. "COMMONDEF",
  4739. "CONSTANT",
  4740. "DEREF",
  4741. "ELSEBLK",
  4742. "EXPR",
  4743. "\"for\"",
  4744. "FOR_STEP",
  4745. "\"foreach\"",
  4746. "FOREACH_INDEX",
  4747. "FOR_LOOP",
  4748. "FOR_STEP_LOOP",
  4749. "FOREACH_LOOP",
  4750. "FOREACH_INDEX_LOOP",
  4751. "FCALL",
  4752. "FCALL_LIB",
  4753. "FCALL_LIB_RETNEW",
  4754. "IF_ELSE",
  4755. "KEYDECL",
  4756. "KEYDEF",
  4757. "KEYDEF_REF",
  4758. "KEYDEF_REF_CHECK",
  4759. "KEYDEF_REF_EXPR",
  4760. "LABEL",
  4761. "MPCALL",
  4762. "MPCALL_PARENT",
  4763. "MFCALL",
  4764. "MFCALL_LIB",
  4765. "MFCALL_LIB_RETNEW",
  4766. "MFCALL_PARENT",
  4767. "MFCALL_PARENT_LIB",
  4768. "MFCALL_PARENT_LIB_RETNEW",
  4769. "NOP",
  4770. "NSTRUC",
  4771. "NSTRUC_REF",
  4772. "ON_IOERROR_NULL",
  4773. "PCALL",
  4774. "PCALL_LIB",
  4775. "PARADECL",
  4776. "PARAEXPR",
  4777. "PARAEXPR_VN",
  4778. "POSTDEC",
  4779. "POSTINC",
  4780. "DECSTATEMENT",
  4781. "INCSTATEMENT",
  4782. "REF",
  4783. "REF_VN",
  4784. "REF_CHECK",
  4785. "REF_CHECK_VN",
  4786. "REF_EXPR",
  4787. "REF_EXPR_VN",
  4788. "\"repeat\"",
  4789. "REPEAT_LOOP",
  4790. "RETURN",
  4791. "RETF",
  4792. "RETP",
  4793. "STRUC",
  4794. "SYSVAR",
  4795. "UMINUS",
  4796. "VAR",
  4797. "VARPTR",
  4798. "\"while\"",
  4799. "IDENTIFIER",
  4800. "\"and\"",
  4801. "\"begin\"",
  4802. "\"case\"",
  4803. "\"common\"",
  4804. "\"compile_opt\"",
  4805. "\"do\"",
  4806. "\"else\"",
  4807. "\"end\"",
  4808. "\"endcase\"",
  4809. "\"endelse\"",
  4810. "\"endfor\"",
  4811. "\"endforeach\"",
  4812. "\"endif\"",
  4813. "\"endrep\"",
  4814. "\"endswitch\"",
  4815. "\"endwhile\"",
  4816. "\"eq\"",
  4817. "\"forward_function\"",
  4818. "\"function\"",
  4819. "\"ge\"",
  4820. "\"goto\"",
  4821. "\"gt\"",
  4822. "\"if\"",
  4823. "\"inherits\"",
  4824. "\"le\"",
  4825. "\"lt\"",
  4826. "\"mod\"",
  4827. "\"ne\"",
  4828. "\"not\"",
  4829. "\"of\"",
  4830. "\"on_ioerror\"",
  4831. "\"or\"",
  4832. "\"pro\"",
  4833. "\"switch\"",
  4834. "\"then\"",
  4835. "\"until\"",
  4836. "\"xor\"",
  4837. "METHOD",
  4838. "COMMA",
  4839. "COLON",
  4840. "END_U",
  4841. "EQUAL",
  4842. "DEC",
  4843. "INC",
  4844. "AND_OP_EQ",
  4845. "ASTERIX_EQ",
  4846. "EQ_OP_EQ",
  4847. "GE_OP_EQ",
  4848. "GTMARK_EQ",
  4849. "GT_OP_EQ",
  4850. "LE_OP_EQ",
  4851. "LTMARK_EQ",
  4852. "LT_OP_EQ",
  4853. "MATRIX_OP1_EQ",
  4854. "MATRIX_OP2_EQ",
  4855. "MINUS_EQ",
  4856. "MOD_OP_EQ",
  4857. "NE_OP_EQ",
  4858. "OR_OP_EQ",
  4859. "PLUS_EQ",
  4860. "POW_EQ",
  4861. "SLASH_EQ",
  4862. "XOR_OP_EQ",
  4863. "MEMBER",
  4864. "LBRACE",
  4865. "RBRACE",
  4866. "SLASH",
  4867. "LSQUARE",
  4868. "RSQUARE",
  4869. "SYSVARNAME",
  4870. "EXCLAMATION",
  4871. "LCURLY",
  4872. "RCURLY",
  4873. "CONSTANT_HEX_BYTE",
  4874. "CONSTANT_HEX_LONG",
  4875. "CONSTANT_HEX_LONG64",
  4876. "CONSTANT_HEX_INT",
  4877. "CONSTANT_HEX_I",
  4878. "CONSTANT_HEX_ULONG",
  4879. "CONSTANT_HEX_ULONG64",
  4880. "CONSTANT_HEX_UI",
  4881. "CONSTANT_HEX_UINT",
  4882. "CONSTANT_BYTE",
  4883. "CONSTANT_LONG",
  4884. "CONSTANT_LONG64",
  4885. "CONSTANT_INT",
  4886. "CONSTANT_I",
  4887. "CONSTANT_ULONG",
  4888. "CONSTANT_ULONG64",
  4889. "CONSTANT_UI",
  4890. "CONSTANT_UINT",
  4891. "CONSTANT_OCT_BYTE",
  4892. "CONSTANT_OCT_LONG",
  4893. "CONSTANT_OCT_LONG64",
  4894. "CONSTANT_OCT_INT",
  4895. "CONSTANT_OCT_I",
  4896. "CONSTANT_OCT_ULONG",
  4897. "CONSTANT_OCT_ULONG64",
  4898. "CONSTANT_OCT_UI",
  4899. "CONSTANT_OCT_UINT",
  4900. "CONSTANT_FLOAT",
  4901. "CONSTANT_DOUBLE",
  4902. "CONSTANT_BIN_BYTE",
  4903. "CONSTANT_BIN_LONG",
  4904. "CONSTANT_BIN_LONG64",
  4905. "CONSTANT_BIN_INT",
  4906. "CONSTANT_BIN_I",
  4907. "CONSTANT_BIN_ULONG",
  4908. "CONSTANT_BIN_ULONG64",
  4909. "CONSTANT_BIN_UI",
  4910. "CONSTANT_BIN_UINT",
  4911. "ASTERIX",
  4912. "DOT",
  4913. "STRING_LITERAL",
  4914. "POW",
  4915. "MATRIX_OP1",
  4916. "MATRIX_OP2",
  4917. "PLUS",
  4918. "MINUS",
  4919. "LTMARK",
  4920. "GTMARK",
  4921. "LOG_NEG",
  4922. "LOG_AND",
  4923. "LOG_OR",
  4924. "QUESTION",
  4925. "STRING",
  4926. "INCLUDE",
  4927. "EOL",
  4928. "W",
  4929. "D",
  4930. "L",
  4931. "H",
  4932. "O",
  4933. "B",
  4934. "EXP",
  4935. "DBL_E",
  4936. "DBL",
  4937. "CONSTANT_OR_STRING_LITERAL",
  4938. "COMMENT",
  4939. "END_MARKER",
  4940. "WHITESPACE",
  4941. "SKIP_LINES",
  4942. "CONT_STATEMENT",
  4943. "END_OF_LINE",
  4944. "MAX_TOKEN_NUMBER",
  4945. 0
  4946. };
  4947. const unsigned long GDLInterpreter::_tokenSet_0_data_[] = { 3232760224UL, 939754047UL, 35706880UL, 18884608UL, 6UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
  4948. // ASSIGN ASSIGN_REPLACE ASSIGN_ARRAYEXPR_MFCALL BLOCK BREAK CONTINUE "for"
  4949. // FOR_STEP "foreach" FOREACH_INDEX FOR_LOOP FOR_STEP_LOOP FOREACH_LOOP
  4950. // FOREACH_INDEX_LOOP IF_ELSE LABEL MPCALL MPCALL_PARENT ON_IOERROR_NULL
  4951. // PCALL PCALL_LIB "repeat" REPEAT_LOOP RETF RETP "while" "case" "goto"
  4952. // "if" "on_ioerror" "switch" DEC INC
  4953. const antlr::BitSet GDLInterpreter::_tokenSet_0(_tokenSet_0_data_,12);
  4954. const unsigned long GDLInterpreter::_tokenSet_1_data_[] = { 738853792UL, 103023040UL, 1769478UL, 0UL, 6UL, 0UL, 524416UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
  4955. // ASSIGN ASSIGN_REPLACE ASSIGN_ARRAYEXPR_MFCALL ARRAYDEF ARRAYEXPR ARRAYEXPR_MFCALL
  4956. // CONSTANT DEREF EXPR FCALL FCALL_LIB FCALL_LIB_RETNEW MFCALL MFCALL_PARENT
  4957. // NSTRUC NSTRUC_REF POSTDEC POSTINC STRUC SYSVAR VAR VARPTR DEC INC DOT
  4958. // QUESTION
  4959. const antlr::BitSet GDLInterpreter::_tokenSet_1(_tokenSet_1_data_,16);