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

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

Large files are truncated click here to view the full 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 M…