1 /* $ANTLR 2.7.7 (2006-11-01): "gdlc.i.g" -> "GDLInterpreter.cpp"$ */
2 
3     // gets inserted before the antlr generated includes in the cpp file
4 #include "includefirst.hpp"
5 
6 #include "GDLInterpreter.hpp"
7 #include <antlr/Token.hpp>
8 #include <antlr/AST.hpp>
9 #include <antlr/NoViableAltException.hpp>
10 #include <antlr/MismatchedTokenException.hpp>
11 #include <antlr/SemanticException.hpp>
12 #include <antlr/BitSet.hpp>
13 
14     // gets inserted after the antlr generated includes in the cpp file
15 #include "dinterpreter.hpp"
16 #include "prognodeexpr.hpp"
17 
18 #include <cassert>
19 
20 // tweaking ANTLR
21 #define ASTNULL          NULLProgNodeP
22 #define ProgNodeP( xxx ) NULL             /* ProgNodeP(antlr::nullAST) */
23 #define RefAST( xxx)     ConvertAST( xxx) /* antlr::RefAST( Ref type)  */
24 #define match( a, b)     /* remove from source */
25 
26 using namespace std;
27 
GDLInterpreter()28 GDLInterpreter::GDLInterpreter()
29 	: antlr::TreeParser() {
30 }
31 
interactive(ProgNodeP _t)32  RetCode  GDLInterpreter::interactive(ProgNodeP _t) {
33 	 RetCode retCode;
34 	ProgNodeP interactive_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
35 
36 		for (; _t != NULL;) {
37 
38 	//_t->setLine(0);
39 			retCode=statement(_t);
40 			_t = _retTree;
41 
42 			if( retCode != RC_OK) break; // break out if non-regular
43 		}
44 		_retTree = _t;
45 		return retCode;
46 
47 
48 	{ // ( ... )+
49 	int _cnt3=0;
50 	for (;;) {
51 		if (_t == ProgNodeP(antlr::nullAST) )
52 			_t = ASTNULL;
53 		if ((_tokenSet_0.member(_t->getType()))) {
54 			retCode=statement(_t);
55 			_t = _retTree;
56 
57 			if( retCode != RC_OK) break; // break out if non-regular
58 
59 		}
60 		else {
61 			if ( _cnt3>=1 ) { goto _loop3; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
62 		}
63 
64 		_cnt3++;
65 	}
66 	_loop3:;
67 	}  // ( ... )+
68 	_retTree = _t;
69 	return retCode;
70 }
71 
statement(ProgNodeP _t)72  RetCode  GDLInterpreter::statement(ProgNodeP _t) {
73 	 RetCode retCode;
74 	ProgNodeP statement_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
75 
76 	//    ProgNodeP& actPos = statement_AST_in;
77 	assert( _t != NULL);
78 	ProgNodeP last;
79 	_retTree = _t;
80 	//  if( callStack.back()->GetLineNumber() == 0)
81 	//  if( _t->getLine() != 0)
82 	//      callStack.back()->SetLineNumber( _t->getLine());
83 
84 
85 	try {      // for error handling
86 
87 		do {
88 		//                 if( _t->getLine() != 0)
89 		//                     callStack.back()->SetLineNumber( _t->getLine());
90 
91 		last = _retTree;
92 
93 		// track actual line number
94 		callStack.back()->SetLineNumber( last->getLine());
95 
96 		retCode = last->Run(); // Run() sets _retTree
97 
98 		}
99 		while(
100 		_retTree != NULL &&
101 		retCode == RC_OK &&
102 		!(sigControlC && interruptEnable) &&
103 		(debugMode == DEBUG_CLEAR));
104 
105 		// commented out, because we are only at the last statement
106 		// if( _retTree != NULL)
107 		//     last = _retTree;
108 
109 		goto afterStatement;
110 
111 		{
112 		if (_t == ProgNodeP(antlr::nullAST) )
113 			_t = ASTNULL;
114 		switch ( _t->getType()) {
115 		case ASSIGN:
116 		{
117 			ProgNodeP tmp1_AST_in = _t;
118 			match(antlr::RefAST(_t),ASSIGN);
119 			_t = _t->getNextSibling();
120 			break;
121 		}
122 		case ASSIGN_ARRAYEXPR_MFCALL:
123 		{
124 			ProgNodeP tmp2_AST_in = _t;
125 			match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
126 			_t = _t->getNextSibling();
127 			break;
128 		}
129 		case ASSIGN_REPLACE:
130 		{
131 			ProgNodeP tmp3_AST_in = _t;
132 			match(antlr::RefAST(_t),ASSIGN_REPLACE);
133 			_t = _t->getNextSibling();
134 			break;
135 		}
136 		case PCALL_LIB:
137 		{
138 			ProgNodeP tmp4_AST_in = _t;
139 			match(antlr::RefAST(_t),PCALL_LIB);
140 			_t = _t->getNextSibling();
141 			break;
142 		}
143 		case MPCALL:
144 		{
145 			ProgNodeP tmp5_AST_in = _t;
146 			match(antlr::RefAST(_t),MPCALL);
147 			_t = _t->getNextSibling();
148 			break;
149 		}
150 		case MPCALL_PARENT:
151 		{
152 			ProgNodeP tmp6_AST_in = _t;
153 			match(antlr::RefAST(_t),MPCALL_PARENT);
154 			_t = _t->getNextSibling();
155 			break;
156 		}
157 		case PCALL:
158 		{
159 			ProgNodeP tmp7_AST_in = _t;
160 			match(antlr::RefAST(_t),PCALL);
161 			_t = _t->getNextSibling();
162 			break;
163 		}
164 		case DEC:
165 		{
166 			ProgNodeP tmp8_AST_in = _t;
167 			match(antlr::RefAST(_t),DEC);
168 			_t = _t->getNextSibling();
169 			break;
170 		}
171 		case INC:
172 		{
173 			ProgNodeP tmp9_AST_in = _t;
174 			match(antlr::RefAST(_t),INC);
175 			_t = _t->getNextSibling();
176 			break;
177 		}
178 		case FOR:
179 		{
180 			ProgNodeP tmp10_AST_in = _t;
181 			match(antlr::RefAST(_t),FOR);
182 			_t = _t->getNextSibling();
183 			break;
184 		}
185 		case FOR_LOOP:
186 		{
187 			ProgNodeP tmp11_AST_in = _t;
188 			match(antlr::RefAST(_t),FOR_LOOP);
189 			_t = _t->getNextSibling();
190 			break;
191 		}
192 		case FOREACH:
193 		{
194 			ProgNodeP tmp12_AST_in = _t;
195 			match(antlr::RefAST(_t),FOREACH);
196 			_t = _t->getNextSibling();
197 			break;
198 		}
199 		case FOREACH_LOOP:
200 		{
201 			ProgNodeP tmp13_AST_in = _t;
202 			match(antlr::RefAST(_t),FOREACH_LOOP);
203 			_t = _t->getNextSibling();
204 			break;
205 		}
206 		case FOREACH_INDEX:
207 		{
208 			ProgNodeP tmp14_AST_in = _t;
209 			match(antlr::RefAST(_t),FOREACH_INDEX);
210 			_t = _t->getNextSibling();
211 			break;
212 		}
213 		case FOREACH_INDEX_LOOP:
214 		{
215 			ProgNodeP tmp15_AST_in = _t;
216 			match(antlr::RefAST(_t),FOREACH_INDEX_LOOP);
217 			_t = _t->getNextSibling();
218 			break;
219 		}
220 		case FOR_STEP:
221 		{
222 			ProgNodeP tmp16_AST_in = _t;
223 			match(antlr::RefAST(_t),FOR_STEP);
224 			_t = _t->getNextSibling();
225 			break;
226 		}
227 		case FOR_STEP_LOOP:
228 		{
229 			ProgNodeP tmp17_AST_in = _t;
230 			match(antlr::RefAST(_t),FOR_STEP_LOOP);
231 			_t = _t->getNextSibling();
232 			break;
233 		}
234 		case REPEAT:
235 		{
236 			ProgNodeP tmp18_AST_in = _t;
237 			match(antlr::RefAST(_t),REPEAT);
238 			_t = _t->getNextSibling();
239 			break;
240 		}
241 		case REPEAT_LOOP:
242 		{
243 			ProgNodeP tmp19_AST_in = _t;
244 			match(antlr::RefAST(_t),REPEAT_LOOP);
245 			_t = _t->getNextSibling();
246 			break;
247 		}
248 		case WHILE:
249 		{
250 			ProgNodeP tmp20_AST_in = _t;
251 			match(antlr::RefAST(_t),WHILE);
252 			_t = _t->getNextSibling();
253 			break;
254 		}
255 		case IF:
256 		{
257 			ProgNodeP tmp21_AST_in = _t;
258 			match(antlr::RefAST(_t),IF);
259 			_t = _t->getNextSibling();
260 			break;
261 		}
262 		case IF_ELSE:
263 		{
264 			ProgNodeP tmp22_AST_in = _t;
265 			match(antlr::RefAST(_t),IF_ELSE);
266 			_t = _t->getNextSibling();
267 			break;
268 		}
269 		case CASE:
270 		{
271 			ProgNodeP tmp23_AST_in = _t;
272 			match(antlr::RefAST(_t),CASE);
273 			_t = _t->getNextSibling();
274 			break;
275 		}
276 		case SWITCH:
277 		{
278 			ProgNodeP tmp24_AST_in = _t;
279 			match(antlr::RefAST(_t),SWITCH);
280 			_t = _t->getNextSibling();
281 			break;
282 		}
283 		case BLOCK:
284 		{
285 			ProgNodeP tmp25_AST_in = _t;
286 			match(antlr::RefAST(_t),BLOCK);
287 			_t = _t->getNextSibling();
288 			break;
289 		}
290 		case LABEL:
291 		{
292 			ProgNodeP tmp26_AST_in = _t;
293 			match(antlr::RefAST(_t),LABEL);
294 			_t = _t->getNextSibling();
295 			break;
296 		}
297 		case ON_IOERROR_NULL:
298 		{
299 			ProgNodeP tmp27_AST_in = _t;
300 			match(antlr::RefAST(_t),ON_IOERROR_NULL);
301 			_t = _t->getNextSibling();
302 			break;
303 		}
304 		case ON_IOERROR:
305 		{
306 			ProgNodeP tmp28_AST_in = _t;
307 			match(antlr::RefAST(_t),ON_IOERROR);
308 			_t = _t->getNextSibling();
309 			break;
310 		}
311 		case BREAK:
312 		{
313 			ProgNodeP tmp29_AST_in = _t;
314 			match(antlr::RefAST(_t),BREAK);
315 			_t = _t->getNextSibling();
316 			break;
317 		}
318 		case CONTINUE:
319 		{
320 			ProgNodeP tmp30_AST_in = _t;
321 			match(antlr::RefAST(_t),CONTINUE);
322 			_t = _t->getNextSibling();
323 			break;
324 		}
325 		case GOTO:
326 		{
327 			ProgNodeP tmp31_AST_in = _t;
328 			match(antlr::RefAST(_t),GOTO);
329 			_t = _t->getNextSibling();
330 			break;
331 		}
332 		case RETF:
333 		{
334 			ProgNodeP tmp32_AST_in = _t;
335 			match(antlr::RefAST(_t),RETF);
336 			_t = _t->getNextSibling();
337 			break;
338 		}
339 		case RETP:
340 		{
341 			ProgNodeP tmp33_AST_in = _t;
342 			match(antlr::RefAST(_t),RETP);
343 			_t = _t->getNextSibling();
344 			break;
345 		}
346 		default:
347 		{
348 			throw antlr::NoViableAltException(antlr::RefAST(_t));
349 		}
350 		}
351 		}
352 
353 		afterStatement:;
354 
355 		// possible optimization: make sigControlC a debugMode
356 		if( interruptEnable && sigControlC)
357 		{
358 		DebugMsg( last, "Interrupted at: ");
359 
360 		sigControlC = false;
361 
362 		retCode = NewInterpreterInstance( last->getLine());//-1);
363 		}
364 		else if( debugMode != DEBUG_CLEAR)
365 		{
366 		if( debugMode == DEBUG_STOP)
367 		{
368 		DebugMsg( last, "Stop encountered: ");
369 		if( !interruptEnable)
370 		debugMode = DEBUG_PROCESS_STOP;
371 		}
372 
373 		if( debugMode == DEBUG_STEP)
374 		{
375 		if( stepCount == 1)
376 		{
377 		stepCount = 0;
378 		DebugMsg( last, "Stepped to: ");
379 
380 		debugMode = DEBUG_CLEAR;
381 
382 		retCode = NewInterpreterInstance( last->getLine());//-1);
383 		}
384 		else
385 		{
386 		--stepCount;
387 		#ifdef GDL_DEBUG
388 		std::cout << "stepCount-- = " << stepCount << std::endl;
389 		#endif
390 		}
391 		}
392 		// else if( debugMode == DEBUG_SKIP)
393 		//     {
394 		//         if( last != NULL)
395 		//             {
396 		//                 last = last->getNextSibling();
397 		//                 DebugMsg( last, "Skipped to: ");
398 		//             }
399 		//         else
400 		//             DebugMsg( last, "Cannot SKIP fro here");
401 
402 		//         debugMode = DEBUG_CLEAR;
403 		//         retCode = RC_OK;
404 		//     }
405 		else if( interruptEnable)
406 		{
407 		if( debugMode == DEBUG_PROCESS_STOP)
408 		{
409 		DebugMsg( last, "Stepped to: ");
410 		}
411 
412 		debugMode = DEBUG_CLEAR;
413 
414 		retCode = NewInterpreterInstance( last->getLine());//-1);
415 		}
416 		else
417 		{
418 		retCode = RC_ABORT;
419 		}
420 		}
421 		return retCode;
422 
423 	}
424 	catch ( GDLException& e) {
425 
426 		// reset _retTree to last statement
427 		// (might otherwise be inside an expression in which case
428 		// .CONTINUE does not work)
429 		_retTree = last;
430 
431 		if( last->IsWrappedNode())
432 		throw e; // WRAPPED_... nodes should not stop inside
433 
434 		// set !ERROR_STATE sys var
435 		DStructDesc* errorStateDesc = SysVar::Error_State()->Desc();   //MUST NOT BE STATIC, due to .reset
436 		static unsigned nameTag = errorStateDesc->TagIndex( "NAME");
437 		static unsigned codeTag = errorStateDesc->TagIndex( "CODE");
438 		static unsigned msgTag = errorStateDesc->TagIndex( "MSG");
439 
440 		if( e.IsIOException())
441 		{
442 		assert( dynamic_cast< GDLIOException*>( &e) != NULL);
443 		// set the jump target - also logs the jump
444 		ProgNodeP onIOErr =
445 		static_cast<EnvUDT*>(callStack.back())->GetIOError();
446 		if( onIOErr != NULL)
447 		{
448 		DStructGDL* errorState = SysVar::Error_State();
449 		(*static_cast<DStringGDL*>( errorState->GetTag( nameTag)))[0] =
450 		"IDL_M_FAILURE";
451 		(*static_cast<DLongGDL*>( errorState->GetTag( codeTag)))[0] =
452 		e.ErrorCode();
453 		SysVar::SetErrError( e.ErrorCode());
454 		(*static_cast<DStringGDL*>( errorState->GetTag( msgTag)))[0] =
455 		e.getMessage();
456 		SysVar::SetErr_String( e.getMessage());
457 
458 		_retTree = onIOErr;
459 		return RC_OK;
460 		}
461 		}
462 
463 		// handle CATCH
464 		ProgNodeP catchNode = callStack.back()->GetCatchNode();
465 		if( catchNode != NULL)
466 		{
467 		DStructGDL* errorState = SysVar::Error_State();
468 		(*static_cast<DStringGDL*>( errorState->GetTag( nameTag)))[0] =
469 		"IDL_M_FAILURE";
470 		(*static_cast<DLongGDL*>( errorState->GetTag( codeTag)))[0] =
471 		e.ErrorCode();
472 		SysVar::SetErrError( e.ErrorCode());
473 		(*static_cast<DStringGDL*>( errorState->GetTag( msgTag)))[0] =
474 		e.getMessage();
475 		SysVar::SetErr_String( e.getMessage());
476 
477 		BaseGDL** catchVar = callStack.back()->GetCatchVar();
478 		GDLDelete(*catchVar);
479 		*catchVar = new DLongGDL( e.ErrorCode());
480 		_retTree = catchNode;
481 		return RC_OK;
482 		}
483 
484 		EnvUDT* targetEnv = e.GetTargetEnv();
485 		if( targetEnv == NULL)
486 		{
487 		// initial exception, set target env
488 
489 		// set !ERROR_STATE here
490 		DStructGDL* errorState = SysVar::Error_State();
491 		(*static_cast<DStringGDL*>( errorState->GetTag( nameTag)))[0] =
492 		"IDL_M_FAILURE";
493 		(*static_cast<DLongGDL*>( errorState->GetTag( codeTag)))[0] =
494 		e.ErrorCode();
495 		SysVar::SetErrError( e.ErrorCode());
496 		(*static_cast<DStringGDL*>( errorState->GetTag( msgTag)))[0] =
497 		e.getMessage();
498 		SysVar::SetErr_String( e.getMessage());
499 
500 		// look if ON_ERROR is set somewhere
501 		// for( EnvStackT::reverse_iterator i = callStack.rbegin();
502 		//     i != callStack.rend(); ++i)
503 		for( long ix = callStack.size() - 1; ix>=0; --ix)
504 		{
505 		EnvUDT** i = &callStack[ ix];
506 		DLong oE = -1;
507 		EnvUDT* envUD = dynamic_cast<EnvUDT*>(*i);
508 		if( envUD != NULL)
509 		oE = envUD->GetOnError();
510 
511 		if( oE != -1)
512 		{ // oE was set
513 
514 		// 0 -> stop here
515 		if( oE == 0)
516 		targetEnv = static_cast<EnvUDT*>(callStack.back());
517 		// 1 -> $MAIN$
518 		else if( oE == 1)
519 		{
520 		EnvUDT* cS_begin =
521 		static_cast<EnvUDT*>(callStack[0]);
522 		// static_cast<EnvUDT*>(*callStack.begin());
523 		targetEnv = cS_begin;
524 		}
525 		// 2 -> caller of routine which called ON_ERROR
526 		else if( oE == 2)
527 		{
528 		// set to caller, handle nested
529 		while( ix > 0 && static_cast<EnvUDT*>(callStack[--ix])->GetOnError() == 2)
530 		; // just set ix
531 
532 		EnvUDT* iUDT = static_cast<EnvUDT*>(callStack[ix]);
533 		targetEnv = iUDT;
534 
535 
536 		// while( static_cast<EnvUDT*>(*(++i))->GetOnError() == 2
537 		//        && i != callStack.rend());
538 		// if( i == callStack.rend())
539 		// {
540 		//     EnvUDT* cS_begin =
541 		//     static_cast<EnvUDT*>(*callStack.begin());
542 		//     targetEnv = cS_begin;
543 		// }
544 		// else
545 		// {
546 		//     EnvUDT* iUDT = static_cast<EnvUDT*>(*i);
547 		//     targetEnv = iUDT;
548 		// }
549 		}
550 		// 3 -> routine which called ON_ERROR
551 		else if( oE == 3)
552 		{
553 		EnvUDT* iUDT = static_cast<EnvUDT*>(callStack[ix]);
554 		// EnvUDT* iUDT = static_cast<EnvUDT*>(*i);
555 		targetEnv = iUDT;
556 		}
557 
558 
559 		// State where error occured
560 		//                     if( e.getLine() == 0 && _t != NULL)
561 		//                         e.SetLine( _t->getLine());
562 		//                     if( e.getLine() == 0 && _retTree != NULL)
563 		//                         e.SetLine( _retTree->getLine());
564 		if( e.getLine() == 0 && last != NULL)
565 		e.SetLine( last->getLine());
566 
567 		if( interruptEnable)
568 		ReportError(e, "Error occurred at:");
569 
570 		// remeber where to stop
571 		e.SetTargetEnv( targetEnv);
572 
573 		if( targetEnv->GetLineNumber() != 0)
574 		e.SetLine( targetEnv->GetLineNumber());
575 
576 		//                     ProgNodeP errorNodeP = targetEnv->CallingNode();
577 		//                     e.SetErrorNodeP( errorNodeP);
578 
579 		// break on first occurence of set oE
580 		break;
581 		}
582 		}
583 		}
584 
585 		if( targetEnv != NULL && targetEnv != callStack.back())
586 		{
587 		throw e; // rethrow
588 		}
589 		lib::write_journal( GetClearActualLine());
590 
591 		// many low level routines don't have errorNode info
592 		// set line number here in this case
593 		//         if( e.getLine() == 0 && _t != NULL)
594 		//             e.SetLine( _t->getLine());
595 		//         if( e.getLine() == 0 && _retTree != NULL)
596 		//             e.SetLine( _retTree->getLine());
597 		//        if( e.getLine() == 0 && actPos != NULL)
598 		//            e.SetLine( actPos->getLine());
599 
600 		if( interruptEnable)
601 		{
602 		if( e.getLine() == 0 && last != NULL)
603 		e.SetLine( last->getLine());
604 
605 		// tell where we are
606 		ReportError(e, "Execution halted at:", targetEnv == NULL);
607 
608 		retCode = NewInterpreterInstance(e.getLine());//-1);
609 		}
610 		else
611 		{
612 
613 		DString msgPrefix = SysVar::MsgPrefix();
614 		if( e.Prefix())
615 		{
616 		std::cerr << msgPrefix << e.toString() << std::endl;
617 		lib::write_journal_comment(msgPrefix+e.toString());
618 		}
619 		else
620 		{
621 		std::cerr << e.toString() << std::endl;
622 		lib::write_journal_comment(e.toString());
623 		}
624 
625 		retCode = RC_ABORT;
626 		}
627 
628 		return retCode;
629 
630 	}
631 	_retTree = _t;
632 	return retCode;
633 }
634 
execute(ProgNodeP _t)635  RetCode  GDLInterpreter::execute(ProgNodeP _t) {
636 	 RetCode retCode;
637 	ProgNodeP execute_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
638 
639 	//    RetCode retCode;
640 	ValueGuard<bool> guard( interruptEnable);
641 	interruptEnable = false;
642 
643 //		return statement_list(_t);
644 
645 
646 	retCode=statement_list(_t);
647 	_t = _retTree;
648 	_retTree = _t;
649 	return retCode;
650 }
651 
statement_list(ProgNodeP _t)652  RetCode  GDLInterpreter::statement_list(ProgNodeP _t) {
653 	 RetCode retCode;
654 	ProgNodeP statement_list_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
655 
656 		for (; _t != NULL;) {
657 
658 			retCode=statement(_t);
659 			_t = _retTree;
660 
661 			if( retCode != RC_OK) break; // break out if non-regular
662 		}
663 		_retTree = _t;
664 		return retCode;
665 
666 
667 	{ // ( ... )+
668 	int _cnt16=0;
669 	for (;;) {
670 		if (_t == ProgNodeP(antlr::nullAST) )
671 			_t = ASTNULL;
672 		if ((_tokenSet_0.member(_t->getType()))) {
673 			retCode=statement(_t);
674 			_t = _retTree;
675 		}
676 		else {
677 			if ( _cnt16>=1 ) { goto _loop16; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
678 		}
679 
680 		_cnt16++;
681 	}
682 	_loop16:;
683 	}  // ( ... )+
684 	_retTree = _t;
685 	return retCode;
686 }
687 
call_fun(ProgNodeP _t)688  BaseGDL*  GDLInterpreter::call_fun(ProgNodeP _t) {
689 	 BaseGDL* res;
690 	ProgNodeP call_fun_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
691 
692 
693 	res = NULL;
694 	assert(returnValue == NULL);
695 	RetCode retCode;
696 
697 		for (; _t != NULL;) {
698 
699 				retCode=statement(_t);
700 	_t = _retTree;
701 
702 	// 			if( retCode == RC_RETURN)
703 				if( retCode >= RC_RETURN)
704 				{
705 	res=returnValue;
706 	returnValue=NULL;
707 	// already done in RETFNode::Run() :
708 	// if( returnValueL != NULL)
709 	//     {
710 	//         callStack.back()->SetPtrToReturnValue( returnValueL);
711 	//         returnValueL = NULL;
712 	//     }
713 				break;
714 				}
715 		}
716 
717 		// default return value if none was set
718 		if( res == NULL) res = new DIntGDL( 0);
719 
720 		_retTree = _t;
721 		return res;
722 
723 
724 	{ // ( ... )*
725 	for (;;) {
726 		if (_t == ProgNodeP(antlr::nullAST) )
727 			_t = ASTNULL;
728 		if ((_tokenSet_0.member(_t->getType()))) {
729 			retCode=statement(_t);
730 			_t = _retTree;
731 		}
732 		else {
733 			goto _loop7;
734 		}
735 
736 	}
737 	_loop7:;
738 	} // ( ... )*
739 	_retTree = _t;
740 	return res;
741 }
742 
call_lfun(ProgNodeP _t)743  BaseGDL**  GDLInterpreter::call_lfun(ProgNodeP _t) {
744 	 BaseGDL** res;
745 	ProgNodeP call_lfun_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
746 
747 	res = NULL;
748 	assert(returnValueL == NULL);
749 	RetCode retCode;
750 
751 		ProgNodeP in = _t;
752 
753 		for (; _t != NULL;)
754 	{
755 	retCode=statement(_t);
756 	_t = _retTree;
757 
758 	if( retCode >= RC_RETURN)
759 				{
760 	res=returnValueL;
761 	returnValueL=NULL;
762 	break;
763 	}
764 	}
765 
766 		// res must be defined here
767 		if( res == NULL)
768 	throw GDLException( in, "Function "+callStack.back()->GetProName()+
769 	" must return a global left-value in this context.",
770 	false,false);
771 		_retTree = _t;
772 		return res;
773 
774 
775 	{ // ( ... )*
776 	for (;;) {
777 		if (_t == ProgNodeP(antlr::nullAST) )
778 			_t = ASTNULL;
779 		if ((_tokenSet_0.member(_t->getType()))) {
780 			retCode=statement(_t);
781 			_t = _retTree;
782 		}
783 		else {
784 			goto _loop10;
785 		}
786 
787 	}
788 	_loop10:;
789 	} // ( ... )*
790 	_retTree = _t;
791 	return res;
792 }
793 
call_pro(ProgNodeP _t)794 void GDLInterpreter::call_pro(ProgNodeP _t) {
795 	ProgNodeP call_pro_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
796 
797 	RetCode retCode;
798 
799 		for (; _t != NULL;) {
800 				retCode=statement(_t);
801 				_t = _retTree;
802 
803 				// added RC_ABORT here
804 				if( retCode >= RC_RETURN) break;
805 		}
806 		_retTree = _t;
807 	return;
808 
809 
810 	{ // ( ... )*
811 	for (;;) {
812 		if (_t == ProgNodeP(antlr::nullAST) )
813 			_t = ASTNULL;
814 		if ((_tokenSet_0.member(_t->getType()))) {
815 			retCode=statement(_t);
816 			_t = _retTree;
817 		}
818 		else {
819 			goto _loop13;
820 		}
821 
822 	}
823 	_loop13:;
824 	} // ( ... )*
825 	_retTree = _t;
826 }
827 
l_deref(ProgNodeP _t)828 BaseGDL**  GDLInterpreter::l_deref(ProgNodeP _t) {
829 	BaseGDL** res;
830 	ProgNodeP l_deref_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
831 
832 		ProgNodeP retTree = _t->getNextSibling();
833 
834 	BaseGDL* e1;
835 	ProgNodeP evalExpr = _t->getFirstChild();
836 	if( NonCopyNode( evalExpr->getType()))
837 	{
838 	e1 = evalExpr->EvalNC();
839 	}
840 	else
841 	{
842 	BaseGDL** ref = evalExpr->EvalRefCheck(e1);
843 	if( ref == NULL)
844 	{
845 	// use new env if set (during parameter parsing)
846 	EnvBaseT* actEnv = DInterpreter::CallStackBack()->GetNewEnv();
847 	if( actEnv == NULL) actEnv = DInterpreter::CallStackBack();
848 	assert( actEnv != NULL);
849 	// this is crucial, a guard does not work here as a temporary
850 	// ptr will be cleaned up at return from this function
851 	actEnv->DeleteAtExit( e1);
852 	}
853 	else
854 	e1 = *ref;
855 	}
856 
857 	if( e1 == NULL || e1->Type() != GDL_PTR)
858 	throw GDLException( evalExpr, "Pointer type required in this context: "+Name(e1),true,false);
859 
860 	DPtrGDL* ptr=static_cast<DPtrGDL*>(e1);
861 
862 	DPtr sc;
863 	if( !ptr->Scalar(sc))
864 	throw GDLException( _t, "Expression must be a scalar in this context: "+Name(e1),true,false);
865 	if( sc == 0)
866 	throw GDLException( _t, "Unable to dereference NULL pointer: "+Name(e1),true,false);
867 
868 	try
869 	{
870 	res = &GetHeap(sc);
871 	}
872 	catch( HeapException)
873 	{
874 	throw GDLException( _t, "Invalid pointer: "+Name(e1),true,false);
875 	}
876 
877 		_retTree = retTree;
878 		return res;
879 
880 
881 	ProgNodeP tmp34_AST_in = _t;
882 	match(antlr::RefAST(_t),DEREF);
883 	_t = _t->getNextSibling();
884 	_retTree = _t;
885 	return res;
886 }
887 
l_decinc_indexable_expr(ProgNodeP _t,BaseGDL * & res)888 BaseGDL**  GDLInterpreter::l_decinc_indexable_expr(ProgNodeP _t,
889 	 BaseGDL*& res
890 ) {
891 	BaseGDL** e;
892 	ProgNodeP l_decinc_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
893 
894 	e = _t->LEval();
895 	res = *e;
896 	if( res == NULL)
897 	throw GDLException( _t, "Variable is undefined: "+Name(e),true,false);
898 	return e;
899 
900 
901 	if (_t == ProgNodeP(antlr::nullAST) )
902 		_t = ASTNULL;
903 	switch ( _t->getType()) {
904 	case FCALL:
905 	case FCALL_LIB:
906 	case MFCALL:
907 	case MFCALL_PARENT:
908 	{
909 		e=l_function_call_internal(_t);
910 		_t = _retTree;
911 		break;
912 	}
913 	case DEREF:
914 	{
915 		e=l_deref(_t);
916 		_t = _retTree;
917 		break;
918 	}
919 	case VAR:
920 	case VARPTR:
921 	{
922 		e=l_defined_simple_var(_t);
923 		_t = _retTree;
924 		break;
925 	}
926 	case SYSVAR:
927 	{
928 		e=l_sys_var(_t);
929 		_t = _retTree;
930 		break;
931 	}
932 	default:
933 	{
934 		throw antlr::NoViableAltException(antlr::RefAST(_t));
935 	}
936 	}
937 	_retTree = _t;
938 	return e;
939 }
940 
l_function_call_internal(ProgNodeP _t)941  BaseGDL**  GDLInterpreter::l_function_call_internal(ProgNodeP _t) {
942 	 BaseGDL** res;
943 	ProgNodeP l_function_call_internal_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
944 
945 	res = _t->LEval();
946 	_retTree = _t->getNextSibling();
947 	return res;
948 
949 
950 	if (_t == ProgNodeP(antlr::nullAST) )
951 		_t = ASTNULL;
952 	switch ( _t->getType()) {
953 	case FCALL_LIB:
954 	{
955 		ProgNodeP tmp35_AST_in = _t;
956 		match(antlr::RefAST(_t),FCALL_LIB);
957 		_t = _t->getNextSibling();
958 		break;
959 	}
960 	case MFCALL:
961 	{
962 		ProgNodeP tmp36_AST_in = _t;
963 		match(antlr::RefAST(_t),MFCALL);
964 		_t = _t->getNextSibling();
965 		break;
966 	}
967 	case MFCALL_PARENT:
968 	{
969 		ProgNodeP tmp37_AST_in = _t;
970 		match(antlr::RefAST(_t),MFCALL_PARENT);
971 		_t = _t->getNextSibling();
972 		break;
973 	}
974 	case FCALL:
975 	{
976 		ProgNodeP tmp38_AST_in = _t;
977 		match(antlr::RefAST(_t),FCALL);
978 		_t = _t->getNextSibling();
979 		break;
980 	}
981 	default:
982 	{
983 		throw antlr::NoViableAltException(antlr::RefAST(_t));
984 	}
985 	}
986 	_retTree = _t;
987 	return res;
988 }
989 
l_defined_simple_var(ProgNodeP _t)990 BaseGDL**  GDLInterpreter::l_defined_simple_var(ProgNodeP _t) {
991 	BaseGDL** res;
992 	ProgNodeP l_defined_simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
993 
994 		assert( _t != NULL);
995 	res = _t->LEval();
996 	_retTree = _t->getNextSibling();
997 		if( *res == NULL)
998 	{
999 	if( _t->getType() == VAR)
1000 	throw GDLException( _t, "Variable is undefined: "+
1001 	callStack.back()->GetString(_t->varIx),true,false);
1002 	else
1003 	throw GDLException( _t, "Common block variable is undefined: "+
1004 	callStack.back()->GetString( *res),true,false);
1005 	}
1006 	return res;
1007 
1008 
1009 
1010 	if (_t == ProgNodeP(antlr::nullAST) )
1011 		_t = ASTNULL;
1012 	switch ( _t->getType()) {
1013 	case VAR:
1014 	{
1015 		ProgNodeP tmp39_AST_in = _t;
1016 		match(antlr::RefAST(_t),VAR);
1017 		_t = _t->getNextSibling();
1018 		break;
1019 	}
1020 	case VARPTR:
1021 	{
1022 		ProgNodeP tmp40_AST_in = _t;
1023 		match(antlr::RefAST(_t),VARPTR);
1024 		_t = _t->getNextSibling();
1025 		break;
1026 	}
1027 	default:
1028 	{
1029 		throw antlr::NoViableAltException(antlr::RefAST(_t));
1030 	}
1031 	}
1032 	_retTree = _t;
1033 	return res;
1034 }
1035 
l_sys_var(ProgNodeP _t)1036 BaseGDL**  GDLInterpreter::l_sys_var(ProgNodeP _t) {
1037 	BaseGDL** res;
1038 	ProgNodeP l_sys_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1039 
1040 		ProgNodeP sysVar = _t;
1041 		//match(antlr::RefAST(_t),SYSVAR);
1042 		res=sysVar->LEval();
1043 		_retTree = sysVar->getNextSibling();
1044 		return res;
1045 
1046 
1047 
1048 	ProgNodeP tmp41_AST_in = _t;
1049 	match(antlr::RefAST(_t),SYSVAR);
1050 	_t = _t->getNextSibling();
1051 	_retTree = _t;
1052 	return res;
1053 }
1054 
l_decinc_array_expr(ProgNodeP _t,int dec_inc,BaseGDL * & res)1055 BaseGDL**  GDLInterpreter::l_decinc_array_expr(ProgNodeP _t,
1056 	int dec_inc, BaseGDL*& res
1057 ) {
1058 	BaseGDL** e;
1059 	ProgNodeP l_decinc_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1060 
1061 		ArrayIndexListT* aL;
1062 		ArrayIndexListGuard guard;
1063 
1064 		if( _t->getType() == ARRAYEXPR)
1065 		{
1066 			ProgNodeP arrExNP = _t;
1067 			// match(antlr::RefAST(_t),ARRAYEXPR);
1068 
1069 			_t = _t->getFirstChild();
1070 
1071 			BaseGDL** tmp =_t->LEval();// l_decinc_indexable_expr(_t, res);
1072 	res = *tmp;
1073 	if( res == NULL)
1074 	throw GDLException( _t, "Variable is undefined: " + Name(tmp),
1075 	true,false);
1076 			_t = _t->getNextSibling();
1077 
1078 			aL=arrayindex_list(_t,!res->IsAssoc());
1079 
1080 			_retTree = arrExNP->getNextSibling();
1081 
1082 			guard.reset( aL);
1083 			aL->SetVariable( res);
1084 
1085 			if( dec_inc == DECSTATEMENT)
1086 			{
1087 	res->DecAt( aL);
1088 	return NULL;
1089 			}
1090 			if( dec_inc == INCSTATEMENT)
1091 			{
1092 	res->IncAt( aL);
1093 	return NULL;
1094 			}
1095 
1096 			if( dec_inc == DEC || dec_inc == DEC_REF_CHECK)
1097 			res->DecAt( aL);
1098 			else if( dec_inc == INC || dec_inc == INC_REF_CHECK)
1099 			res->IncAt( aL);
1100 
1101 			BaseGDL* resBefore = res;
1102 			res = resBefore->Index( aL);
1103 
1104 			if( dec_inc == POSTDEC) resBefore->DecAt( aL);
1105 			else if( dec_inc == POSTINC) resBefore->IncAt( aL);
1106 
1107 	return NULL;
1108 		}
1109 	else
1110 	{
1111 			e =_t->LEval();// l_decinc_indexable_expr(_t, res);
1112 	res = *e;
1113 	if( res == NULL)
1114 	throw GDLException( _t, "Variable is undefined: " + Name(e),
1115 	true,false);
1116 			_retTree = _t->getNextSibling();
1117 			// e=l_decinc_indexable_expr(_t, res);
1118 			// _t = _retTree;
1119 
1120 			if( dec_inc == DECSTATEMENT || dec_inc == DEC_REF_CHECK)
1121 			{
1122 	res->Dec();
1123 	return e;
1124 			}
1125 			if( dec_inc == INCSTATEMENT || dec_inc == INC_REF_CHECK)
1126 			{
1127 	res->Inc();
1128 	return e;
1129 			}
1130 
1131 			if( dec_inc == DEC) res->Dec();
1132 			else if( dec_inc == INC) res->Inc();
1133 
1134 			BaseGDL* resBefore = res;
1135 			res = resBefore->Dup();
1136 
1137 			if( dec_inc == POSTDEC) resBefore->Dec();
1138 			else if( dec_inc == POSTINC) resBefore->Inc();
1139 
1140 	return e;
1141 		}
1142 	assert(false);
1143 		return e;
1144 
1145 	// not used _______________________________________
1146 	// ------------------------------------------------
1147 
1148 
1149 	if (_t == ProgNodeP(antlr::nullAST) )
1150 		_t = ASTNULL;
1151 	switch ( _t->getType()) {
1152 	case ARRAYEXPR:
1153 	{
1154 		ProgNodeP tmp42_AST_in = _t;
1155 		match(antlr::RefAST(_t),ARRAYEXPR);
1156 		_t = _t->getNextSibling();
1157 		break;
1158 	}
1159 	case DEREF:
1160 	case FCALL:
1161 	case FCALL_LIB:
1162 	case MFCALL:
1163 	case MFCALL_PARENT:
1164 	case SYSVAR:
1165 	case VAR:
1166 	case VARPTR:
1167 	{
1168 		e=l_decinc_indexable_expr(_t, res);
1169 		_t = _retTree;
1170 		break;
1171 	}
1172 	default:
1173 	{
1174 		throw antlr::NoViableAltException(antlr::RefAST(_t));
1175 	}
1176 	}
1177 	_retTree = _t;
1178 	return e;
1179 }
1180 
l_decinc_dot_expr(ProgNodeP _t,int dec_inc)1181 BaseGDL*  GDLInterpreter::l_decinc_dot_expr(ProgNodeP _t,
1182 	int dec_inc
1183 ) {
1184 	BaseGDL* res;
1185 	ProgNodeP l_decinc_dot_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1186 
1187 		ProgNodeP dot = _t;
1188 		//match(antlr::RefAST(_t),DOT);
1189 
1190 		_t = _t->getFirstChild();
1191 
1192 		SizeT nDot=dot->nDot;
1193 		Guard<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
1194 
1195 		l_dot_array_expr(_t, aD.Get());
1196 		_t = _retTree;
1197 
1198 	while( _t != NULL)
1199 	{
1200 	tag_array_expr(_t, aD.Get());
1201 				_t = _retTree;
1202 			}
1203 
1204 		_retTree = dot->getNextSibling();
1205 
1206 		if( dec_inc == DECSTATEMENT)
1207 	{
1208 	aD.Get()->Dec();
1209 	return NULL;
1210 	}
1211 		if( dec_inc == INCSTATEMENT)
1212 	{
1213 	aD.Get()->Inc();
1214 	return NULL;
1215 	}
1216 
1217 		if( dec_inc == DEC || dec_inc == DEC_REF_CHECK)
1218 	aD.Get()->Dec(); //*** aD->Assign( dec_inc);
1219 		else if( dec_inc == INC || dec_inc == INC_REF_CHECK)
1220 	aD.Get()->Inc();
1221 
1222 		res=aD.Get()->ADResolve();
1223 
1224 		if( dec_inc == POSTDEC) aD.Get()->Dec();
1225 		else if( dec_inc == POSTINC) aD.Get()->Inc();
1226 
1227 		return res;
1228 
1229 
1230 	ProgNodeP tmp43_AST_in = _t;
1231 	match(antlr::RefAST(_t),DOT);
1232 	_t = _t->getNextSibling();
1233 	_retTree = _t;
1234 	return res;
1235 }
1236 
l_decinc_expr(ProgNodeP _t,int dec_inc,BaseGDL * & res)1237 BaseGDL**  GDLInterpreter::l_decinc_expr(ProgNodeP _t,
1238 	int dec_inc, BaseGDL*& res
1239 ) {
1240 	BaseGDL** refRet;
1241 	ProgNodeP l_decinc_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1242 	ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
1243 
1244 	refRet = NULL;
1245 
1246 	BaseGDL*       e1;
1247 	ProgNodeP startNode = _t;
1248 
1249 
1250 	if (_t == ProgNodeP(antlr::nullAST) )
1251 		_t = ASTNULL;
1252 	switch ( _t->getType()) {
1253 	case QUESTION:
1254 	{
1255 		ProgNodeP __t24 = _t;
1256 		ProgNodeP tmp44_AST_in = _t;
1257 		match(antlr::RefAST(_t),QUESTION);
1258 		_t = _t->getFirstChild();
1259 		e1=expr(_t);
1260 		_t = _retTree;
1261 
1262 		Guard<BaseGDL> e1_guard(e1);
1263 
1264 		if( e1->True())
1265 		{
1266 		refRet=l_decinc_expr(_t, dec_inc, res);
1267 		}
1268 		else
1269 		{
1270 		_t=_t->GetNextSibling(); // jump over 1st expression
1271 		refRet=l_decinc_expr(_t, dec_inc, res);
1272 		}
1273 
1274 		_t = __t24;
1275 		_t = _t->getNextSibling();
1276 		break;
1277 	}
1278 	case ASSIGN:
1279 	{
1280 		ProgNodeP __t25 = _t;
1281 		ProgNodeP tmp45_AST_in = _t;
1282 		match(antlr::RefAST(_t),ASSIGN);
1283 		_t = _t->getFirstChild();
1284 
1285 		Guard<BaseGDL> r_guard;
1286 
1287 		{
1288 		if (_t == ProgNodeP(antlr::nullAST) )
1289 			_t = ASTNULL;
1290 		switch ( _t->getType()) {
1291 		case CONSTANT:
1292 		case DEREF:
1293 		case SYSVAR:
1294 		case VAR:
1295 		case VARPTR:
1296 		{
1297 			e1=indexable_expr(_t);
1298 			_t = _retTree;
1299 			break;
1300 		}
1301 		case ASSIGN:
1302 		case ASSIGN_REPLACE:
1303 		case ASSIGN_ARRAYEXPR_MFCALL:
1304 		case ARRAYDEF:
1305 		case ARRAYDEF_GENERALIZED_INDGEN:
1306 		case ARRAYEXPR:
1307 		case ARRAYEXPR_MFCALL:
1308 		case EXPR:
1309 		case FCALL:
1310 		case FCALL_LIB_RETNEW:
1311 		case MFCALL:
1312 		case MFCALL_PARENT:
1313 		case NSTRUC:
1314 		case NSTRUC_REF:
1315 		case POSTDEC:
1316 		case POSTINC:
1317 		case STRUC:
1318 		case DEC:
1319 		case INC:
1320 		case DOT:
1321 		case QUESTION:
1322 		{
1323 			e1=indexable_tmp_expr(_t);
1324 			_t = _retTree;
1325 			r_guard.Init( e1);
1326 			break;
1327 		}
1328 		case FCALL_LIB:
1329 		{
1330 			e1=lib_function_call_internal(_t);
1331 			_t = _retTree;
1332 
1333 			// if( !callStack.back()->Contains( e1))
1334 			if( callStack.back()->GetPtrToReturnValueNull() == NULL)
1335 			r_guard.Init( e1); // guard if no global data
1336 
1337 			break;
1338 		}
1339 		default:
1340 		{
1341 			throw antlr::NoViableAltException(antlr::RefAST(_t));
1342 		}
1343 		}
1344 		}
1345 
1346 		ProgNodeP l = _t;
1347 
1348 		BaseGDL** tmp;
1349 
1350 		tmp=l_expr_internal(_t, e1);
1351 		_t = _retTree;
1352 
1353 		_t = l;
1354 
1355 		refRet=l_decinc_expr(_t,dec_inc, res);
1356 		_t = _retTree;
1357 		_t = __t25;
1358 		_t = _t->getNextSibling();
1359 		break;
1360 	}
1361 	case ASSIGN_ARRAYEXPR_MFCALL:
1362 	{
1363 		ProgNodeP __t27 = _t;
1364 		ProgNodeP tmp46_AST_in = _t;
1365 		match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
1366 		_t = _t->getFirstChild();
1367 
1368 		Guard<BaseGDL> r_guard;
1369 
1370 		{
1371 		if (_t == ProgNodeP(antlr::nullAST) )
1372 			_t = ASTNULL;
1373 		switch ( _t->getType()) {
1374 		case CONSTANT:
1375 		case DEREF:
1376 		case SYSVAR:
1377 		case VAR:
1378 		case VARPTR:
1379 		{
1380 			e1=indexable_expr(_t);
1381 			_t = _retTree;
1382 			break;
1383 		}
1384 		case ASSIGN:
1385 		case ASSIGN_REPLACE:
1386 		case ASSIGN_ARRAYEXPR_MFCALL:
1387 		case ARRAYDEF:
1388 		case ARRAYDEF_GENERALIZED_INDGEN:
1389 		case ARRAYEXPR:
1390 		case ARRAYEXPR_MFCALL:
1391 		case EXPR:
1392 		case FCALL:
1393 		case FCALL_LIB_RETNEW:
1394 		case MFCALL:
1395 		case MFCALL_PARENT:
1396 		case NSTRUC:
1397 		case NSTRUC_REF:
1398 		case POSTDEC:
1399 		case POSTINC:
1400 		case STRUC:
1401 		case DEC:
1402 		case INC:
1403 		case DOT:
1404 		case QUESTION:
1405 		{
1406 			e1=indexable_tmp_expr(_t);
1407 			_t = _retTree;
1408 			r_guard.Init( e1);
1409 			break;
1410 		}
1411 		case FCALL_LIB:
1412 		{
1413 			e1=lib_function_call_internal(_t);
1414 			_t = _retTree;
1415 
1416 			// if( !callStack.back()->Contains( e1))
1417 			if( callStack.back()->GetPtrToReturnValueNull() == NULL)
1418 			r_guard.Init( e1); // guard if no global data
1419 
1420 			break;
1421 		}
1422 		default:
1423 		{
1424 			throw antlr::NoViableAltException(antlr::RefAST(_t));
1425 		}
1426 		}
1427 		}
1428 
1429 		ProgNodeP l = _t;
1430 
1431 		BaseGDL** tmp;
1432 
1433 		// try MFCALL
1434 		try
1435 		{
1436 
1437 		tmp=l_arrayexpr_mfcall_as_mfcall(l);
1438 
1439 		if( e1 != (*tmp))
1440 		{
1441 		delete *tmp;
1442 
1443 		if( r_guard.Get() == e1)
1444 		*tmp = r_guard.release();
1445 		else
1446 		*tmp = e1->Dup();
1447 		}
1448 
1449 		refRet=l_decinc_expr( l, dec_inc, res);
1450 		}
1451 		catch( GDLException& ex)
1452 		{
1453 		// try ARRAYEXPR
1454 		try
1455 			                {
1456 		tmp=l_arrayexpr_mfcall_as_arrayexpr(l, e1);
1457 			                }
1458 		catch( GDLException& ex2)
1459 		{
1460 		throw GDLException(ex.toString() + " or "+ex2.toString());
1461 		}
1462 
1463 		refRet=l_decinc_expr( l, dec_inc, res);
1464 		}
1465 
1466 		_t = __t27;
1467 		_t = _t->getNextSibling();
1468 		break;
1469 	}
1470 	case ASSIGN_REPLACE:
1471 	{
1472 		ProgNodeP __t29 = _t;
1473 		ProgNodeP tmp47_AST_in = _t;
1474 		match(antlr::RefAST(_t),ASSIGN_REPLACE);
1475 		_t = _t->getFirstChild();
1476 
1477 		Guard<BaseGDL> r_guard;
1478 
1479 		{
1480 		if (_t == ProgNodeP(antlr::nullAST) )
1481 			_t = ASTNULL;
1482 		switch ( _t->getType()) {
1483 		case ASSIGN:
1484 		case ASSIGN_REPLACE:
1485 		case ASSIGN_ARRAYEXPR_MFCALL:
1486 		case ARRAYDEF:
1487 		case ARRAYDEF_GENERALIZED_INDGEN:
1488 		case ARRAYEXPR:
1489 		case ARRAYEXPR_MFCALL:
1490 		case CONSTANT:
1491 		case DEREF:
1492 		case EXPR:
1493 		case FCALL:
1494 		case FCALL_LIB_RETNEW:
1495 		case MFCALL:
1496 		case MFCALL_PARENT:
1497 		case NSTRUC:
1498 		case NSTRUC_REF:
1499 		case POSTDEC:
1500 		case POSTINC:
1501 		case STRUC:
1502 		case SYSVAR:
1503 		case VAR:
1504 		case VARPTR:
1505 		case DEC:
1506 		case INC:
1507 		case DOT:
1508 		case QUESTION:
1509 		{
1510 			e1=tmp_expr(_t);
1511 			_t = _retTree;
1512 
1513 			r_guard.Init( e1);
1514 
1515 			break;
1516 		}
1517 		case FCALL_LIB:
1518 		{
1519 			e1=lib_function_call_internal(_t);
1520 			_t = _retTree;
1521 
1522 			// if( !callStack.back()->Contains( e1))
1523 			if( callStack.back()->GetPtrToReturnValueNull() == NULL)
1524 			r_guard.Init( e1);
1525 
1526 			break;
1527 		}
1528 		default:
1529 		{
1530 			throw antlr::NoViableAltException(antlr::RefAST(_t));
1531 		}
1532 		}
1533 		}
1534 
1535 		ProgNodeP l = _t;
1536 
1537 		BaseGDL** tmp;
1538 
1539 		{
1540 		if (_t == ProgNodeP(antlr::nullAST) )
1541 			_t = ASTNULL;
1542 		switch ( _t->getType()) {
1543 		case FCALL:
1544 		case FCALL_LIB:
1545 		case MFCALL:
1546 		case MFCALL_PARENT:
1547 		{
1548 			tmp=l_function_call_internal(_t);
1549 			_t = _retTree;
1550 			break;
1551 		}
1552 		case DEREF:
1553 		{
1554 			tmp=l_deref(_t);
1555 			_t = _retTree;
1556 			break;
1557 		}
1558 		case VAR:
1559 		case VARPTR:
1560 		{
1561 			tmp=l_simple_var(_t);
1562 			_t = _retTree;
1563 			break;
1564 		}
1565 		default:
1566 		{
1567 			throw antlr::NoViableAltException(antlr::RefAST(_t));
1568 		}
1569 		}
1570 		}
1571 
1572 		if( e1 != (*tmp))
1573 		{
1574 		delete *tmp;
1575 
1576 		if( r_guard.Get() == e1)
1577 		*tmp = r_guard.release();
1578 		else
1579 		*tmp = e1->Dup();
1580 		}
1581 
1582 
1583 		_t = l;
1584 
1585 		refRet=l_decinc_expr(_t,dec_inc, res);
1586 		_t = _retTree;
1587 		_t = __t29;
1588 		_t = _t->getNextSibling();
1589 		break;
1590 	}
1591 	case ARRAYEXPR:
1592 	case DEREF:
1593 	case FCALL:
1594 	case FCALL_LIB:
1595 	case MFCALL:
1596 	case MFCALL_PARENT:
1597 	case SYSVAR:
1598 	case VAR:
1599 	case VARPTR:
1600 	{
1601 		refRet=l_decinc_array_expr(_t,dec_inc, res);
1602 		_t = _retTree;
1603 		break;
1604 	}
1605 	case ARRAYEXPR_MFCALL:
1606 	{
1607 		ProgNodeP __t32 = _t;
1608 		ProgNodeP tmp48_AST_in = _t;
1609 		match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
1610 		_t = _t->getFirstChild();
1611 
1612 		ProgNodeP mark = _t;
1613 		_t = _t->getNextSibling(); // step over DOT
1614 
1615 		BaseGDL* self;
1616 
1617 		self=expr(_t);
1618 		_t = _retTree;
1619 		mp2 = _t;
1620 		match(antlr::RefAST(_t),IDENTIFIER);
1621 		_t = _t->getNextSibling();
1622 
1623 		Guard<BaseGDL> self_guard(self);
1624 
1625 		EnvUDT* newEnv;
1626 
1627 		DObjGDL* selfObj = NULL;
1628 		if( self->Type() == GDL_OBJ)
1629 		selfObj = static_cast<DObjGDL*>( self);
1630 		try {
1631 		newEnv=new EnvUDT( selfObj, mp2, "", EnvUDT::LFUNCTION);
1632 		self_guard.release();
1633 		}
1634 		catch( GDLException& ex)
1635 		{
1636 		_t = mark;
1637 
1638 		res=l_decinc_dot_expr(_t, dec_inc);
1639 
1640 		_retTree = startNode->getNextSibling();
1641 		return refRet;
1642 		}
1643 
1644 		parameter_def(_t, newEnv);
1645 		_t = _retTree;
1646 
1647 		// push environment onto call stack
1648 		callStack.push_back(newEnv);
1649 
1650 		// make the call
1651 		BaseGDL** ee=call_lfun(static_cast<DSubUD*>(
1652 		newEnv->GetPro())->GetTree());
1653 
1654 		BaseGDL* e = *ee;
1655 		if( e == NULL)
1656 		throw GDLException( _t, "Variable is undefined: "+Name(ee),true,false);
1657 
1658 		if( dec_inc == DECSTATEMENT || dec_inc == DEC_REF_CHECK)
1659 		{
1660 		e->Dec();
1661 		_retTree = startNode->getNextSibling();
1662 		return ee;
1663 		}
1664 		if( dec_inc == INCSTATEMENT || dec_inc == INC_REF_CHECK)
1665 		{
1666 		e->Inc();
1667 		_retTree = startNode->getNextSibling();
1668 		return ee;
1669 		}
1670 
1671 		if( dec_inc == DEC) e->Dec();
1672 		else if( dec_inc == INC) e->Inc();
1673 		//
1674 		res = e->Dup();
1675 
1676 		if( dec_inc == POSTDEC) e->Dec();
1677 		else if( dec_inc == POSTINC) e->Inc();
1678 
1679 		_retTree = startNode->getNextSibling();
1680 		return ee;
1681 
1682 		_t = __t32;
1683 		_t = _t->getNextSibling();
1684 		break;
1685 	}
1686 	case DOT:
1687 	{
1688 		res=l_decinc_dot_expr(_t,dec_inc);
1689 		_t = _retTree;
1690 		break;
1691 	}
1692 	case ARRAYDEF:
1693 	case ARRAYDEF_GENERALIZED_INDGEN:
1694 	case EXPR:
1695 	case NSTRUC:
1696 	case NSTRUC_REF:
1697 	case POSTDEC:
1698 	case POSTINC:
1699 	case STRUC:
1700 	case DEC:
1701 	case INC:
1702 	{
1703 		e1=r_expr(_t);
1704 		_t = _retTree;
1705 
1706 		delete e1;
1707 		throw GDLException( _t,
1708 		"Expression not allowed with decrement/increment operator.",true,false);
1709 
1710 		break;
1711 	}
1712 	case CONSTANT:
1713 	{
1714 		ProgNodeP tmp49_AST_in = _t;
1715 		match(antlr::RefAST(_t),CONSTANT);
1716 		_t = _t->getNextSibling();
1717 
1718 		throw GDLException( _t,
1719 		"Constant not allowed with decrement/increment operator.",true,false);
1720 
1721 		break;
1722 	}
1723 	default:
1724 	{
1725 		throw antlr::NoViableAltException(antlr::RefAST(_t));
1726 	}
1727 	}
1728 	_retTree = _t;
1729 	return refRet;
1730 }
1731 
expr(ProgNodeP _t)1732 BaseGDL*  GDLInterpreter::expr(ProgNodeP _t) {
1733 	BaseGDL* res;
1734 	ProgNodeP expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1735 
1736 		assert( _t != NULL);
1737 
1738 	res = _t->Eval();
1739 	_retTree = _t->getNextSibling();
1740 	return res; //tmp_expr(_t);
1741 
1742 
1743 	if (_t == ProgNodeP(antlr::nullAST) )
1744 		_t = ASTNULL;
1745 	switch ( _t->getType()) {
1746 	case ASSIGN:
1747 	case ASSIGN_REPLACE:
1748 	case ASSIGN_ARRAYEXPR_MFCALL:
1749 	case ARRAYDEF:
1750 	case ARRAYDEF_GENERALIZED_INDGEN:
1751 	case ARRAYEXPR:
1752 	case ARRAYEXPR_MFCALL:
1753 	case CONSTANT:
1754 	case DEREF:
1755 	case EXPR:
1756 	case FCALL:
1757 	case FCALL_LIB_RETNEW:
1758 	case MFCALL:
1759 	case MFCALL_PARENT:
1760 	case NSTRUC:
1761 	case NSTRUC_REF:
1762 	case POSTDEC:
1763 	case POSTINC:
1764 	case STRUC:
1765 	case SYSVAR:
1766 	case VAR:
1767 	case VARPTR:
1768 	case DEC:
1769 	case INC:
1770 	case DOT:
1771 	case QUESTION:
1772 	{
1773 		res=tmp_expr(_t);
1774 		_t = _retTree;
1775 		break;
1776 	}
1777 	case FCALL_LIB:
1778 	{
1779 		res=lib_function_call_internal(_t);
1780 		_t = _retTree;
1781 		break;
1782 	}
1783 	default:
1784 	{
1785 		throw antlr::NoViableAltException(antlr::RefAST(_t));
1786 	}
1787 	}
1788 	_retTree = _t;
1789 	return res;
1790 }
1791 
indexable_expr(ProgNodeP _t)1792 BaseGDL*  GDLInterpreter::indexable_expr(ProgNodeP _t) {
1793 	BaseGDL* res;
1794 	ProgNodeP indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1795 
1796 	res = _t->EvalNC();
1797 	_retTree = _t->getNextSibling();
1798 	return res;
1799 
1800 	BaseGDL** e2;
1801 
1802 
1803 	if (_t == ProgNodeP(antlr::nullAST) )
1804 		_t = ASTNULL;
1805 	switch ( _t->getType()) {
1806 	case VAR:
1807 	case VARPTR:
1808 	{
1809 		e2=l_defined_simple_var(_t);
1810 		_t = _retTree;
1811 		break;
1812 	}
1813 	case SYSVAR:
1814 	{
1815 		ProgNodeP tmp50_AST_in = _t;
1816 		match(antlr::RefAST(_t),SYSVAR);
1817 		_t = _t->getNextSibling();
1818 		break;
1819 	}
1820 	case CONSTANT:
1821 	{
1822 		ProgNodeP tmp51_AST_in = _t;
1823 		match(antlr::RefAST(_t),CONSTANT);
1824 		_t = _t->getNextSibling();
1825 		break;
1826 	}
1827 	case DEREF:
1828 	{
1829 		e2=l_deref(_t);
1830 		_t = _retTree;
1831 		break;
1832 	}
1833 	default:
1834 	{
1835 		throw antlr::NoViableAltException(antlr::RefAST(_t));
1836 	}
1837 	}
1838 	_retTree = _t;
1839 	return res;
1840 }
1841 
indexable_tmp_expr(ProgNodeP _t)1842 BaseGDL*  GDLInterpreter::indexable_tmp_expr(ProgNodeP _t) {
1843 	BaseGDL* res;
1844 	ProgNodeP indexable_tmp_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1845 
1846 	res = _t->Eval(); //lib_function_call_retnew_internal(_t);
1847 		_retTree = _t->getNextSibling();
1848 	return res;
1849 
1850 
1851 	if (_t == ProgNodeP(antlr::nullAST) )
1852 		_t = ASTNULL;
1853 	switch ( _t->getType()) {
1854 	case QUESTION:
1855 	{
1856 		{
1857 		ProgNodeP tmp52_AST_in = _t;
1858 		match(antlr::RefAST(_t),QUESTION);
1859 		_t = _t->getNextSibling();
1860 		}
1861 		break;
1862 	}
1863 	case ARRAYEXPR:
1864 	{
1865 		{
1866 		ProgNodeP tmp53_AST_in = _t;
1867 		match(antlr::RefAST(_t),ARRAYEXPR);
1868 		_t = _t->getNextSibling();
1869 		}
1870 		break;
1871 	}
1872 	case DOT:
1873 	{
1874 		ProgNodeP tmp54_AST_in = _t;
1875 		match(antlr::RefAST(_t),DOT);
1876 		_t = _t->getNextSibling();
1877 		break;
1878 	}
1879 	case ASSIGN:
1880 	case ASSIGN_REPLACE:
1881 	case ASSIGN_ARRAYEXPR_MFCALL:
1882 	{
1883 		res=assign_expr(_t);
1884 		_t = _retTree;
1885 		break;
1886 	}
1887 	case ARRAYEXPR_MFCALL:
1888 	case FCALL:
1889 	case MFCALL:
1890 	case MFCALL_PARENT:
1891 	{
1892 		res=unused_function_call(_t);
1893 		_t = _retTree;
1894 		break;
1895 	}
1896 	case ARRAYDEF:
1897 	case ARRAYDEF_GENERALIZED_INDGEN:
1898 	case EXPR:
1899 	case NSTRUC:
1900 	case NSTRUC_REF:
1901 	case POSTDEC:
1902 	case POSTINC:
1903 	case STRUC:
1904 	case DEC:
1905 	case INC:
1906 	{
1907 		res=r_expr(_t);
1908 		_t = _retTree;
1909 		break;
1910 	}
1911 	case FCALL_LIB_RETNEW:
1912 	{
1913 		res=lib_function_call_retnew_internal(_t);
1914 		_t = _retTree;
1915 		break;
1916 	}
1917 	default:
1918 	{
1919 		throw antlr::NoViableAltException(antlr::RefAST(_t));
1920 	}
1921 	}
1922 	_retTree = _t;
1923 	return res;
1924 }
1925 
lib_function_call_internal(ProgNodeP _t)1926  BaseGDL*  GDLInterpreter::lib_function_call_internal(ProgNodeP _t) {
1927 	 BaseGDL* res;
1928 	ProgNodeP lib_function_call_internal_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1929 
1930 	assert( _t->getType() == FCALL_LIB);
1931 		BaseGDL** retValPtr;
1932 		res = static_cast<FCALL_LIBNode*>(_t)->EvalFCALL_LIB(retValPtr);
1933 		_retTree = _t->getNextSibling();
1934 
1935 	callStack.back()->SetPtrToReturnValue( retValPtr);
1936 	return res;
1937 
1938 
1939 	ProgNodeP tmp55_AST_in = _t;
1940 	match(antlr::RefAST(_t),FCALL_LIB);
1941 	_t = _t->getNextSibling();
1942 	_retTree = _t;
1943 	return res;
1944 }
1945 
l_expr_internal(ProgNodeP _t,BaseGDL * right)1946 BaseGDL**  GDLInterpreter::l_expr_internal(ProgNodeP _t,
1947 	BaseGDL* right
1948 ) {
1949 	BaseGDL** res;
1950 	ProgNodeP l_expr_internal_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
1951 
1952 	res = _t->LExpr( right);
1953 	_retTree = _t->getNextSibling();
1954 	return res;
1955 
1956 	BaseGDL* e1;
1957 
1958 
1959 	if (_t == ProgNodeP(antlr::nullAST) )
1960 		_t = ASTNULL;
1961 	switch ( _t->getType()) {
1962 	case QUESTION:
1963 	{
1964 		ProgNodeP tmp56_AST_in = _t;
1965 		match(antlr::RefAST(_t),QUESTION);
1966 		_t = _t->getNextSibling();
1967 		break;
1968 	}
1969 	case ARRAYEXPR:
1970 	{
1971 		res=unused_l_array_expr(_t, right);
1972 		_t = _retTree;
1973 		break;
1974 	}
1975 	case SYSVAR:
1976 	{
1977 		res=l_sys_var(_t);
1978 		_t = _retTree;
1979 		break;
1980 	}
1981 	case FCALL:
1982 	case FCALL_LIB:
1983 	case MFCALL:
1984 	case MFCALL_PARENT:
1985 	{
1986 		res=l_function_call_internal(_t);
1987 		_t = _retTree;
1988 		break;
1989 	}
1990 	case DEREF:
1991 	{
1992 		res=l_deref(_t);
1993 		_t = _retTree;
1994 		break;
1995 	}
1996 	case VAR:
1997 	case VARPTR:
1998 	{
1999 		res=l_simple_var(_t);
2000 		_t = _retTree;
2001 		break;
2002 	}
2003 	case ARRAYEXPR_MFCALL:
2004 	{
2005 		res=l_arrayexpr_mfcall(_t, right);
2006 		_t = _retTree;
2007 		break;
2008 	}
2009 	case DOT:
2010 	{
2011 		ProgNodeP tmp57_AST_in = _t;
2012 		match(antlr::RefAST(_t),DOT);
2013 		_t = _t->getNextSibling();
2014 		break;
2015 	}
2016 	case ASSIGN:
2017 	{
2018 		ProgNodeP tmp58_AST_in = _t;
2019 		match(antlr::RefAST(_t),ASSIGN);
2020 		_t = _t->getNextSibling();
2021 		break;
2022 	}
2023 	case ASSIGN_ARRAYEXPR_MFCALL:
2024 	{
2025 		ProgNodeP tmp59_AST_in = _t;
2026 		match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
2027 		_t = _t->getNextSibling();
2028 		break;
2029 	}
2030 	case ASSIGN_REPLACE:
2031 	{
2032 		ProgNodeP tmp60_AST_in = _t;
2033 		match(antlr::RefAST(_t),ASSIGN_REPLACE);
2034 		_t = _t->getNextSibling();
2035 		break;
2036 	}
2037 	case ARRAYDEF:
2038 	case ARRAYDEF_GENERALIZED_INDGEN:
2039 	case EXPR:
2040 	case NSTRUC:
2041 	case NSTRUC_REF:
2042 	case POSTDEC:
2043 	case POSTINC:
2044 	case STRUC:
2045 	case DEC:
2046 	case INC:
2047 	{
2048 		e1=r_expr(_t);
2049 		_t = _retTree;
2050 		break;
2051 	}
2052 	case CONSTANT:
2053 	{
2054 		ProgNodeP tmp61_AST_in = _t;
2055 		match(antlr::RefAST(_t),CONSTANT);
2056 		_t = _t->getNextSibling();
2057 		break;
2058 	}
2059 	default:
2060 	{
2061 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2062 	}
2063 	}
2064 	_retTree = _t;
2065 	return res;
2066 }
2067 
tmp_expr(ProgNodeP _t)2068 BaseGDL*  GDLInterpreter::tmp_expr(ProgNodeP _t) {
2069 	BaseGDL* res;
2070 	ProgNodeP tmp_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2071 
2072 		res = _t->Eval();
2073 		_retTree = _t->getNextSibling();
2074 	return res;
2075 
2076 	BaseGDL** e2;
2077 
2078 
2079 	if (_t == ProgNodeP(antlr::nullAST) )
2080 		_t = ASTNULL;
2081 	switch ( _t->getType()) {
2082 	case DEREF:
2083 	{
2084 		e2=l_deref(_t);
2085 		_t = _retTree;
2086 		break;
2087 	}
2088 	case QUESTION:
2089 	{
2090 		{
2091 		ProgNodeP tmp62_AST_in = _t;
2092 		match(antlr::RefAST(_t),QUESTION);
2093 		_t = _t->getNextSibling();
2094 		}
2095 		break;
2096 	}
2097 	case ARRAYEXPR:
2098 	{
2099 		{
2100 		ProgNodeP tmp63_AST_in = _t;
2101 		match(antlr::RefAST(_t),ARRAYEXPR);
2102 		_t = _t->getNextSibling();
2103 		}
2104 		break;
2105 	}
2106 	case DOT:
2107 	{
2108 		ProgNodeP tmp64_AST_in = _t;
2109 		match(antlr::RefAST(_t),DOT);
2110 		_t = _t->getNextSibling();
2111 		break;
2112 	}
2113 	case ASSIGN:
2114 	case ASSIGN_REPLACE:
2115 	case ASSIGN_ARRAYEXPR_MFCALL:
2116 	{
2117 		res=assign_expr(_t);
2118 		_t = _retTree;
2119 		break;
2120 	}
2121 	case ARRAYEXPR_MFCALL:
2122 	case FCALL:
2123 	case MFCALL:
2124 	case MFCALL_PARENT:
2125 	{
2126 		res=unused_function_call(_t);
2127 		_t = _retTree;
2128 		break;
2129 	}
2130 	case ARRAYDEF:
2131 	case ARRAYDEF_GENERALIZED_INDGEN:
2132 	case EXPR:
2133 	case NSTRUC:
2134 	case NSTRUC_REF:
2135 	case POSTDEC:
2136 	case POSTINC:
2137 	case STRUC:
2138 	case DEC:
2139 	case INC:
2140 	{
2141 		res=r_expr(_t);
2142 		_t = _retTree;
2143 		break;
2144 	}
2145 	case CONSTANT:
2146 	{
2147 		ProgNodeP tmp65_AST_in = _t;
2148 		match(antlr::RefAST(_t),CONSTANT);
2149 		_t = _t->getNextSibling();
2150 		break;
2151 	}
2152 	case VAR:
2153 	case VARPTR:
2154 	{
2155 		res=simple_var(_t);
2156 		_t = _retTree;
2157 		break;
2158 	}
2159 	case SYSVAR:
2160 	{
2161 		res=sys_var(_t);
2162 		_t = _retTree;
2163 		break;
2164 	}
2165 	case FCALL_LIB_RETNEW:
2166 	{
2167 		res=lib_function_call_retnew_internal(_t);
2168 		_t = _retTree;
2169 		break;
2170 	}
2171 	default:
2172 	{
2173 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2174 	}
2175 	}
2176 	_retTree = _t;
2177 	return res;
2178 }
2179 
l_simple_var(ProgNodeP _t)2180 BaseGDL**  GDLInterpreter::l_simple_var(ProgNodeP _t) {
2181 	BaseGDL** res;
2182 	ProgNodeP l_simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2183 
2184 		assert( _t != NULL);
2185 	res = _t->LEval();
2186 	_retTree = _t->getNextSibling();
2187 	return res;
2188 
2189 
2190 
2191 	if (_t == ProgNodeP(antlr::nullAST) )
2192 		_t = ASTNULL;
2193 	switch ( _t->getType()) {
2194 	case VAR:
2195 	{
2196 		ProgNodeP tmp66_AST_in = _t;
2197 		match(antlr::RefAST(_t),VAR);
2198 		_t = _t->getNextSibling();
2199 		break;
2200 	}
2201 	case VARPTR:
2202 	{
2203 		ProgNodeP tmp67_AST_in = _t;
2204 		match(antlr::RefAST(_t),VARPTR);
2205 		_t = _t->getNextSibling();
2206 		break;
2207 	}
2208 	default:
2209 	{
2210 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2211 	}
2212 	}
2213 	_retTree = _t;
2214 	return res;
2215 }
2216 
parameter_def(ProgNodeP _t,EnvBaseT * actEnv)2217 void GDLInterpreter::parameter_def(ProgNodeP _t,
2218 	EnvBaseT* actEnv
2219 ) {
2220 	ProgNodeP parameter_def_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2221 
2222 	// as actEnv is not on the stack guard it here
2223 	Guard<EnvBaseT> guard(actEnv);
2224 
2225 	EnvBaseT* callerEnv = callStack.back();
2226 	EnvBaseT* oldNewEnv = callerEnv->GetNewEnv();
2227 
2228 	callerEnv->SetNewEnv( actEnv);
2229 
2230 	try{
2231 
2232 	_retTree = _t;
2233 	if( _retTree != NULL)
2234 	{
2235 	int nPar = _retTree->GetNParam();
2236 	int nSub = actEnv->GetPro()->NPar();
2237 	// // variable number of parameters
2238 	// if( nSub == -1)
2239 	//     {
2240 	//         // _retTree != NULL, save one check
2241 	//         static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
2242 	//         while(_retTree != NULL)
2243 	//             static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
2244 	//     }
2245 	// // fixed number of parameters
2246 	if( nSub != -1 && nPar > nSub) // check here
2247 	{
2248 	throw GDLException( _t, actEnv->GetProName() +
2249 	": Incorrect number of arguments.",
2250 	false, false);
2251 	}
2252 	else
2253 	{
2254 	// _retTree != NULL, save one check
2255 	static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
2256 	// Parameter does no checking
2257 	while(_retTree != NULL)
2258 	static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
2259 	}
2260 	actEnv->ResolveExtra(); // expand _EXTRA
2261 	}
2262 	}
2263 	catch( GDLException& e)
2264 	{
2265 	callerEnv->SetNewEnv( oldNewEnv);
2266 	// update line number, currently set to caller->CallingNode()
2267 	// because actEnv is not on the stack yet,
2268 	// report caller->Pro()'s name is ok, because we are not inside
2269 	// the call yet
2270 	e.SetErrorNodeP( actEnv->CallingNode());
2271 	throw e;
2272 	}
2273 	callerEnv->SetNewEnv( oldNewEnv);
2274 
2275 		guard.release();
2276 
2277 	return;
2278 
2279 
2280 	ProgNodeP tmp68_AST_in = _t;
2281 	match(antlr::RefAST(_t),KEYDEF_REF);
2282 	_t = _t->getNextSibling();
2283 	ProgNodeP tmp69_AST_in = _t;
2284 	match(antlr::RefAST(_t),IDENTIFIER);
2285 	_t = _t->getNextSibling();
2286 	_retTree = _t;
2287 }
2288 
r_expr(ProgNodeP _t)2289 BaseGDL*  GDLInterpreter::r_expr(ProgNodeP _t) {
2290 	BaseGDL* res;
2291 	ProgNodeP r_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2292 
2293 	res=_t->Eval();
2294 		_retTree = _t->getNextSibling();
2295 		return res;
2296 
2297 	BaseGDL** refRet; // not used
2298 
2299 
2300 	if (_t == ProgNodeP(antlr::nullAST) )
2301 		_t = ASTNULL;
2302 	switch ( _t->getType()) {
2303 	case EXPR:
2304 	{
2305 		ProgNodeP tmp70_AST_in = _t;
2306 		match(antlr::RefAST(_t),EXPR);
2307 		_t = _t->getNextSibling();
2308 		break;
2309 	}
2310 	case ARRAYDEF:
2311 	{
2312 		ProgNodeP tmp71_AST_in = _t;
2313 		match(antlr::RefAST(_t),ARRAYDEF);
2314 		_t = _t->getNextSibling();
2315 		break;
2316 	}
2317 	case ARRAYDEF_GENERALIZED_INDGEN:
2318 	{
2319 		ProgNodeP tmp72_AST_in = _t;
2320 		match(antlr::RefAST(_t),ARRAYDEF_GENERALIZED_INDGEN);
2321 		_t = _t->getNextSibling();
2322 		break;
2323 	}
2324 	case STRUC:
2325 	{
2326 		ProgNodeP tmp73_AST_in = _t;
2327 		match(antlr::RefAST(_t),STRUC);
2328 		_t = _t->getNextSibling();
2329 		break;
2330 	}
2331 	case NSTRUC:
2332 	{
2333 		ProgNodeP tmp74_AST_in = _t;
2334 		match(antlr::RefAST(_t),NSTRUC);
2335 		_t = _t->getNextSibling();
2336 		break;
2337 	}
2338 	case NSTRUC_REF:
2339 	{
2340 		ProgNodeP tmp75_AST_in = _t;
2341 		match(antlr::RefAST(_t),NSTRUC_REF);
2342 		_t = _t->getNextSibling();
2343 		break;
2344 	}
2345 	case DEC:
2346 	{
2347 		ProgNodeP __t43 = _t;
2348 		ProgNodeP tmp76_AST_in = _t;
2349 		match(antlr::RefAST(_t),DEC);
2350 		_t = _t->getFirstChild();
2351 		refRet=l_decinc_expr(_t, DEC, res);
2352 		_t = _retTree;
2353 		_t = __t43;
2354 		_t = _t->getNextSibling();
2355 		break;
2356 	}
2357 	case INC:
2358 	{
2359 		ProgNodeP __t44 = _t;
2360 		ProgNodeP tmp77_AST_in = _t;
2361 		match(antlr::RefAST(_t),INC);
2362 		_t = _t->getFirstChild();
2363 		refRet=l_decinc_expr(_t, INC, res);
2364 		_t = _retTree;
2365 		_t = __t44;
2366 		_t = _t->getNextSibling();
2367 		break;
2368 	}
2369 	case POSTDEC:
2370 	{
2371 		ProgNodeP __t45 = _t;
2372 		ProgNodeP tmp78_AST_in = _t;
2373 		match(antlr::RefAST(_t),POSTDEC);
2374 		_t = _t->getFirstChild();
2375 		refRet=l_decinc_expr(_t, POSTDEC, res);
2376 		_t = _retTree;
2377 		_t = __t45;
2378 		_t = _t->getNextSibling();
2379 		break;
2380 	}
2381 	case POSTINC:
2382 	{
2383 		ProgNodeP __t46 = _t;
2384 		ProgNodeP tmp79_AST_in = _t;
2385 		match(antlr::RefAST(_t),POSTINC);
2386 		_t = _t->getFirstChild();
2387 		refRet=l_decinc_expr(_t, POSTINC, res);
2388 		_t = _retTree;
2389 		_t = __t46;
2390 		_t = _t->getNextSibling();
2391 		break;
2392 	}
2393 	default:
2394 	{
2395 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2396 	}
2397 	}
2398 	_retTree = _t;
2399 	return res;
2400 }
2401 
l_indexable_expr(ProgNodeP _t)2402 BaseGDL**  GDLInterpreter::l_indexable_expr(ProgNodeP _t) {
2403 	BaseGDL** res;
2404 	ProgNodeP l_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2405 
2406 	res = _t->LEval();
2407 	if( *res == NULL)
2408 	{
2409 	// check not needed for SYSVAR
2410 	assert( _t->getType() != SYSVAR);
2411 	if( _t->getType() == VARPTR)
2412 	throw GDLException( _t, "Common block variable is undefined: "+
2413 	callStack.back()->GetString( *res),true,false);
2414 	if( _t->getType() == VAR)
2415 	throw GDLException( _t, "Variable is undefined: "+
2416 	callStack.back()->GetString(_t->varIx),true,false);
2417 	throw GDLException( _t, "Heap variable is undefined: "+Name(res),true,false);
2418 	}
2419 	_retTree = _t->getNextSibling();
2420 		return res;
2421 
2422 
2423 	if (_t == ProgNodeP(antlr::nullAST) )
2424 		_t = ASTNULL;
2425 	switch ( _t->getType()) {
2426 	case EXPR:
2427 	{
2428 		ProgNodeP tmp80_AST_in = _t;
2429 		match(antlr::RefAST(_t),EXPR);
2430 		_t = _t->getNextSibling();
2431 		break;
2432 	}
2433 	case FCALL:
2434 	case FCALL_LIB:
2435 	case MFCALL:
2436 	case MFCALL_PARENT:
2437 	{
2438 		res=l_function_call_internal(_t);
2439 		_t = _retTree;
2440 		break;
2441 	}
2442 	case ARRAYEXPR_MFCALL:
2443 	{
2444 		res=l_arrayexpr_mfcall_as_mfcall(_t);
2445 		_t = _retTree;
2446 		break;
2447 	}
2448 	case DEREF:
2449 	{
2450 		res=l_deref(_t);
2451 		_t = _retTree;
2452 		break;
2453 	}
2454 	case VAR:
2455 	case VARPTR:
2456 	{
2457 		res=l_defined_simple_var(_t);
2458 		_t = _retTree;
2459 		break;
2460 	}
2461 	case SYSVAR:
2462 	{
2463 		res=l_sys_var(_t);
2464 		_t = _retTree;
2465 		break;
2466 	}
2467 	default:
2468 	{
2469 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2470 	}
2471 	}
2472 	_retTree = _t;
2473 	return res;
2474 }
2475 
l_arrayexpr_mfcall_as_mfcall(ProgNodeP _t)2476  BaseGDL**  GDLInterpreter::l_arrayexpr_mfcall_as_mfcall(ProgNodeP _t) {
2477 	 BaseGDL** res;
2478 	ProgNodeP l_arrayexpr_mfcall_as_mfcall_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2479 	ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
2480 
2481 	// better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
2482 	StackGuard<EnvStackT> guard(callStack);
2483 	BaseGDL *self;
2484 	EnvUDT*   newEnv;
2485 
2486 
2487 	ProgNodeP __t79 = _t;
2488 	ProgNodeP tmp81_AST_in = _t;
2489 	match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
2490 	_t = _t->getFirstChild();
2491 
2492 	_t = _t->getNextSibling(); // skip DOT
2493 
2494 	self=expr(_t);
2495 	_t = _retTree;
2496 	mp2 = _t;
2497 	match(antlr::RefAST(_t),IDENTIFIER);
2498 	_t = _t->getNextSibling();
2499 
2500 	Guard<BaseGDL> self_guard(self);
2501 
2502 	newEnv=new EnvUDT( self, mp2, "", EnvUDT::LFUNCTION);
2503 
2504 	self_guard.release();
2505 
2506 	parameter_def(_t, newEnv);
2507 	_t = _retTree;
2508 	_t = __t79;
2509 	_t = _t->getNextSibling();
2510 
2511 	// push environment onto call stack
2512 	callStack.push_back(newEnv);
2513 
2514 	// make the call
2515 	res=call_lfun(static_cast<DSubUD*>(
2516 	newEnv->GetPro())->GetTree());
2517 
2518 	_retTree = _t;
2519 	return res;
2520 }
2521 
unused_l_array_expr(ProgNodeP _t,BaseGDL * right)2522 BaseGDL**  GDLInterpreter::unused_l_array_expr(ProgNodeP _t,
2523 	BaseGDL* right
2524 ) {
2525 	BaseGDL** res;
2526 	ProgNodeP unused_l_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2527 
2528 	ArrayIndexListT* aL;
2529 
2530 
2531 	ProgNodeP __t35 = _t;
2532 	ProgNodeP tmp82_AST_in = _t;
2533 	match(antlr::RefAST(_t),ARRAYEXPR);
2534 	_t = _t->getFirstChild();
2535 	res=l_indexable_expr(_t);
2536 	_t = _retTree;
2537 	aL=arrayindex_list(_t, false);
2538 	_t = _retTree;
2539 	_t = __t35;
2540 	_t = _t->getNextSibling();
2541 	_retTree = _t;
2542 	return res;
2543 }
2544 
arrayindex_list(ProgNodeP _t,bool noAssoc)2545 ArrayIndexListT*  GDLInterpreter::arrayindex_list(ProgNodeP _t,
2546 	 bool noAssoc
2547 ) {
2548 	ArrayIndexListT* aL;
2549 	ProgNodeP arrayindex_list_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2550 
2551 	// IxExprListT      cleanupList; // for cleanup
2552 	IxExprListT      ixExprList;
2553 	SizeT nExpr;
2554 	BaseGDL* s;
2555 
2556 	//	ProgNodeP retTree = _t->getNextSibling();
2557 		ProgNodeP ax = _t;
2558 	// 	match(antlr::RefAST(_t),ARRAYIX);
2559 		_t = _t->getFirstChild();
2560 
2561 	if( noAssoc)
2562 	aL = ax->arrIxListNoAssoc;
2563 	else
2564 	aL = ax->arrIxList;
2565 		assert( aL != NULL);
2566 
2567 		nExpr = aL->NParam();
2568 		if( nExpr == 0)
2569 		{
2570 	aL->Init();
2571 	_retTree = ax->getNextSibling();//retTree;
2572 	return aL;
2573 		}
2574 
2575 	IxExprListT* cleanupList = aL->GetCleanupIx(); // for cleanup
2576 		while( true) {
2577 
2578 	assert( _t != NULL);
2579 	if( NonCopyNode( _t->getType()))
2580 	{
2581 	s = _t->EvalNC();
2582 	}
2583 	else
2584 	{
2585 	BaseGDL** ref =_t->EvalRefCheck( s);
2586 	if( ref == NULL)
2587 	cleanupList->push_back( s);
2588 	else
2589 	s = *ref;
2590 	}
2591 
2592 	assert( s != NULL);
2593 	ixExprList.push_back( s);
2594 	if( ixExprList.size() == nExpr)
2595 	break; // allows some manual tuning
2596 
2597 	_t = _t->getNextSibling();
2598 		}
2599 
2600 		aL->Init( ixExprList);//, &cleanupList);
2601 
2602 		_retTree = ax->getNextSibling();//retTree;
2603 		return aL;
2604 
2605 
2606 	ProgNodeP tmp83_AST_in = _t;
2607 	match(antlr::RefAST(_t),ARRAYIX);
2608 	_t = _t->getNextSibling();
2609 	_retTree = _t;
2610 	return aL;
2611 }
2612 
l_dot_array_expr(ProgNodeP _t,DotAccessDescT * aD)2613 void GDLInterpreter::l_dot_array_expr(ProgNodeP _t,
2614 	DotAccessDescT* aD
2615 ) {
2616 	ProgNodeP l_dot_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2617 
2618 	ArrayIndexListT* aL;
2619 	BaseGDL**        rP;
2620 
2621 		if( _t->getType() == ARRAYEXPR)
2622 		{
2623 			rP=l_indexable_expr(_t->getFirstChild());
2624 
2625 			aL=arrayindex_list(_retTree,!(*rP)->IsAssoc());
2626 
2627 			_retTree = _t->getNextSibling();
2628 
2629 	SetRootL( _t, aD, *rP, aL);
2630 		}
2631 	else
2632 		// case ARRAYEXPR_MFCALL:
2633 		// case DEREF:
2634 		// case EXPR:
2635 		// case FCALL:
2636 		// case FCALL_LIB:
2637 		// case MFCALL:
2638 		// case MFCALL_PARENT:
2639 		// case SYSVAR:
2640 		// case VAR:
2641 		// case VARPTR:
2642 		{
2643 			rP=l_indexable_expr(_t);
2644 
2645 	SetRootL( _t, aD, *rP, NULL);
2646 		}
2647 	return;
2648 	//	_retTree = _t;
2649 
2650 
2651 	if (_t == ProgNodeP(antlr::nullAST) )
2652 		_t = ASTNULL;
2653 	switch ( _t->getType()) {
2654 	case ARRAYEXPR:
2655 	{
2656 		ProgNodeP __t37 = _t;
2657 		ProgNodeP tmp84_AST_in = _t;
2658 		match(antlr::RefAST(_t),ARRAYEXPR);
2659 		_t = _t->getFirstChild();
2660 		rP=l_indexable_expr(_t);
2661 		_t = _retTree;
2662 		aL=arrayindex_list(_t, false);
2663 		_t = _retTree;
2664 		_t = __t37;
2665 		_t = _t->getNextSibling();
2666 		break;
2667 	}
2668 	case ARRAYEXPR_MFCALL:
2669 	case DEREF:
2670 	case EXPR:
2671 	case FCALL:
2672 	case FCALL_LIB:
2673 	case MFCALL:
2674 	case MFCALL_PARENT:
2675 	case SYSVAR:
2676 	case VAR:
2677 	case VARPTR:
2678 	{
2679 		rP=l_indexable_expr(_t);
2680 		_t = _retTree;
2681 		break;
2682 	}
2683 	default:
2684 	{
2685 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2686 	}
2687 	}
2688 	_retTree = _t;
2689 }
2690 
l_arrayexpr_mfcall(ProgNodeP _t,BaseGDL * right)2691 BaseGDL**  GDLInterpreter::l_arrayexpr_mfcall(ProgNodeP _t,
2692 	BaseGDL* right
2693 ) {
2694 	BaseGDL** res;
2695 	ProgNodeP l_arrayexpr_mfcall_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2696 	ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
2697 	ProgNodeP dot = ProgNodeP(antlr::nullAST);
2698 
2699 	// better than Guard: Guard wouldn't remove newEnv from the stack
2700 	StackGuard<EnvStackT> guard(callStack);
2701 	BaseGDL *self;
2702 	EnvUDT*  newEnv;
2703 	ProgNodeP startNode = _t;
2704 
2705 
2706 	ProgNodeP __t69 = _t;
2707 	ProgNodeP tmp85_AST_in = _t;
2708 	match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
2709 	_t = _t->getFirstChild();
2710 
2711 	ProgNodeP mark = _t;
2712 	_t = _t->getNextSibling(); // skip DOT
2713 
2714 	self=expr(_t);
2715 	_t = _retTree;
2716 	mp2 = _t;
2717 	match(antlr::RefAST(_t),IDENTIFIER);
2718 	_t = _t->getNextSibling();
2719 
2720 	Guard<BaseGDL> self_guard(self);
2721 
2722 	try {
2723 	newEnv=new EnvUDT( self, mp2, "", EnvUDT::LFUNCTION);
2724 	self_guard.release();
2725 	}
2726 	catch( GDLException& ex)
2727 	{
2728 	goto tryARRAYEXPR;
2729 	}
2730 
2731 	parameter_def(_t, newEnv);
2732 	_t = _retTree;
2733 	_t = __t69;
2734 	_t = _t->getNextSibling();
2735 
2736 	// push environment onto call stack
2737 	callStack.push_back(newEnv);
2738 
2739 	// make the call
2740 	res=call_lfun(static_cast<DSubUD*>(
2741 	newEnv->GetPro())->GetTree());
2742 
2743 	_retTree = startNode->getNextSibling();
2744 	return res;
2745 
2746 	tryARRAYEXPR:;
2747 	_t = mark;
2748 
2749 	ProgNodeP __t70 = _t;
2750 	dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2751 	match(antlr::RefAST(_t),DOT);
2752 	_t = _t->getFirstChild();
2753 
2754 	SizeT nDot=dot->nDot;
2755 	Guard<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
2756 
2757 	l_dot_array_expr(_t, aD.Get());
2758 	_t = _retTree;
2759 	{ // ( ... )+
2760 	int _cnt72=0;
2761 	for (;;) {
2762 		if (_t == ProgNodeP(antlr::nullAST) )
2763 			_t = ASTNULL;
2764 		if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
2765 			tag_array_expr(_t, aD.Get());
2766 			_t = _retTree;
2767 		}
2768 		else {
2769 			if ( _cnt72>=1 ) { goto _loop72; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
2770 		}
2771 
2772 		_cnt72++;
2773 	}
2774 	_loop72:;
2775 	}  // ( ... )+
2776 	_t = __t70;
2777 	_t = _t->getNextSibling();
2778 
2779 	if( right == NULL)
2780 	throw GDLException( _t,
2781 	"Struct expression not allowed in this context.",
2782 	true,false);
2783 
2784 	aD.Get()->ADAssign( right);
2785 
2786 	res=NULL;
2787 
2788 	_retTree = startNode->getNextSibling();
2789 	return res;
2790 
2791 	_retTree = _t;
2792 	return res;
2793 }
2794 
tag_expr(ProgNodeP _t,DotAccessDescT * aD)2795 void GDLInterpreter::tag_expr(ProgNodeP _t,
2796 	DotAccessDescT* aD
2797 ) {
2798 	ProgNodeP tag_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2799 
2800 	BaseGDL* e;
2801 
2802 		if( _t->getType() == EXPR)
2803 		{
2804 			ProgNodeP tIn = _t;
2805 			_t = _t->getFirstChild();
2806 			e=expr(_t);
2807 
2808 			Guard<BaseGDL> e_guard(e);
2809 
2810 			SizeT tagIx;
2811 			int ret=e->Scalar2Index(tagIx);
2812 			if( ret < 1) // this is a return code, not the index
2813 	throw GDLException( tIn, "Expression must be a scalar"
2814 	" >= 0 in this context: "+Name(e),true,false);
2815 			aD->ADAdd( tagIx);
2816 
2817 			_retTree = tIn->getNextSibling();
2818 		}
2819 	else
2820 		// case IDENTIFIER:
2821 		{
2822 	assert( _t->getType() == IDENTIFIER);
2823 			std::string tagName=_t->getText();
2824 
2825 			aD->ADAdd( tagName);
2826 
2827 			_retTree = _t->getNextSibling();
2828 		}
2829 	return;
2830 
2831 
2832 	if (_t == ProgNodeP(antlr::nullAST) )
2833 		_t = ASTNULL;
2834 	switch ( _t->getType()) {
2835 	case EXPR:
2836 	{
2837 		ProgNodeP tmp86_AST_in = _t;
2838 		match(antlr::RefAST(_t),EXPR);
2839 		_t = _t->getNextSibling();
2840 		break;
2841 	}
2842 	case IDENTIFIER:
2843 	{
2844 		ProgNodeP tmp87_AST_in = _t;
2845 		match(antlr::RefAST(_t),IDENTIFIER);
2846 		_t = _t->getNextSibling();
2847 		break;
2848 	}
2849 	default:
2850 	{
2851 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2852 	}
2853 	}
2854 	_retTree = _t;
2855 }
2856 
tag_array_expr(ProgNodeP _t,DotAccessDescT * aD)2857 void GDLInterpreter::tag_array_expr(ProgNodeP _t,
2858 	DotAccessDescT* aD
2859 ) {
2860 	ProgNodeP tag_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2861 
2862 	ArrayIndexListT* aL;
2863 
2864 		if( _t->getType() == ARRAYEXPR)
2865 		{
2866 			ProgNodeP tIn = _t;
2867 			_t = _t->getFirstChild();
2868 			tag_expr(_t, aD);
2869 			_t = _retTree;
2870 	// noAssoc==true, as assoc vars cannot be struct members
2871 			aL=arrayindex_list(_t,true);
2872 			//_t = _retTree;
2873 			aD->ADAddIx(aL);
2874 			_retTree = tIn->getNextSibling();
2875 		}
2876 	else
2877 		// case EXPR:
2878 		// case IDENTIFIER:
2879 		{
2880 			tag_expr(_t, aD);
2881 			//_t = _retTree;
2882 			aD->ADAddIx(NULL);
2883 		}
2884 		//_retTree = _t;
2885 	return;
2886 
2887 
2888 	if (_t == ProgNodeP(antlr::nullAST) )
2889 		_t = ASTNULL;
2890 	switch ( _t->getType()) {
2891 	case ARRAYEXPR:
2892 	{
2893 		ProgNodeP __t49 = _t;
2894 		ProgNodeP tmp88_AST_in = _t;
2895 		match(antlr::RefAST(_t),ARRAYEXPR);
2896 		_t = _t->getFirstChild();
2897 		tag_expr(_t, aD);
2898 		_t = _retTree;
2899 		aL=arrayindex_list(_t, true);
2900 		_t = _retTree;
2901 		_t = __t49;
2902 		_t = _t->getNextSibling();
2903 		break;
2904 	}
2905 	case EXPR:
2906 	case IDENTIFIER:
2907 	{
2908 		tag_expr(_t, aD);
2909 		_t = _retTree;
2910 		break;
2911 	}
2912 	default:
2913 	{
2914 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2915 	}
2916 	}
2917 	_retTree = _t;
2918 }
2919 
r_dot_indexable_expr(ProgNodeP _t,DotAccessDescT * aD)2920 BaseGDL*  GDLInterpreter::r_dot_indexable_expr(ProgNodeP _t,
2921 	DotAccessDescT* aD
2922 ) {
2923 	BaseGDL* res;
2924 	ProgNodeP r_dot_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
2925 
2926 	res=NULL;
2927 		switch ( _t->getType()) {
2928 		case EXPR:
2929 		{
2930 			ProgNodeP tIn = _t;
2931 			_t = _t->getFirstChild();
2932 			//res=expr(_t);
2933 	res = _t->Eval();
2934 			aD->SetOwner( true);
2935 			_retTree = tIn->getNextSibling();
2936 			break;
2937 		}
2938 		case VAR:
2939 		case VARPTR:
2940 		{
2941 			BaseGDL** v=l_defined_simple_var(_t);
2942 			//_t = _retTree;
2943 			res = *v;
2944 			break;
2945 		}
2946 		case SYSVAR:
2947 		{
2948 	res = _t->EvalNC();
2949 	_retTree = _t->getNextSibling();
2950 			//res=sys_var_nocopy(_t);
2951 			//_t = _retTree;
2952 			break;
2953 		}
2954 		}
2955 		//_retTree = _t;
2956 		return res;
2957 
2958 	BaseGDL** e;
2959 
2960 
2961 	if (_t == ProgNodeP(antlr::nullAST) )
2962 		_t = ASTNULL;
2963 	switch ( _t->getType()) {
2964 	case EXPR:
2965 	{
2966 		ProgNodeP __t51 = _t;
2967 		ProgNodeP tmp89_AST_in = _t;
2968 		match(antlr::RefAST(_t),EXPR);
2969 		_t = _t->getFirstChild();
2970 		res=expr(_t);
2971 		_t = _retTree;
2972 		aD->SetOwner( true);
2973 		_t = __t51;
2974 		_t = _t->getNextSibling();
2975 		break;
2976 	}
2977 	case VAR:
2978 	case VARPTR:
2979 	{
2980 		e=l_defined_simple_var(_t);
2981 		_t = _retTree;
2982 		break;
2983 	}
2984 	case SYSVAR:
2985 	{
2986 		ProgNodeP tmp90_AST_in = _t;
2987 		match(antlr::RefAST(_t),SYSVAR);
2988 		_t = _t->getNextSibling();
2989 		break;
2990 	}
2991 	default:
2992 	{
2993 		throw antlr::NoViableAltException(antlr::RefAST(_t));
2994 	}
2995 	}
2996 	_retTree = _t;
2997 	return res;
2998 }
2999 
r_dot_array_expr(ProgNodeP _t,DotAccessDescT * aD)3000 void GDLInterpreter::r_dot_array_expr(ProgNodeP _t,
3001 	DotAccessDescT* aD
3002 ) {
3003 	ProgNodeP r_dot_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3004 
3005 	BaseGDL*         r;
3006 	ArrayIndexListT* aL;
3007 
3008 		if( _t->getType() == ARRAYEXPR)
3009 		{
3010 			//match(antlr::RefAST(_t),ARRAYEXPR);
3011 			r=r_dot_indexable_expr(_t->getFirstChild(), aD);
3012 
3013 			aL=arrayindex_list(_retTree,!r->IsAssoc());
3014 			_retTree = _t->getNextSibling();
3015 
3016 			// check here for object and get struct
3017 			SetRootR( _t, aD, r, aL);
3018 		}
3019 	else
3020 		{
3021 			r=r_dot_indexable_expr(_t, aD);
3022 			//_t = _retTree;
3023 
3024 			// check here for object and get struct
3025 			SetRootR( _t, aD, r, NULL);
3026 		}
3027 	return;
3028 
3029 
3030 	if (_t == ProgNodeP(antlr::nullAST) )
3031 		_t = ASTNULL;
3032 	switch ( _t->getType()) {
3033 	case ARRAYEXPR:
3034 	{
3035 		ProgNodeP __t53 = _t;
3036 		ProgNodeP tmp91_AST_in = _t;
3037 		match(antlr::RefAST(_t),ARRAYEXPR);
3038 		_t = _t->getFirstChild();
3039 		r=r_dot_indexable_expr(_t, aD);
3040 		_t = _retTree;
3041 		aL=arrayindex_list(_t, false);
3042 		_t = _retTree;
3043 		_t = __t53;
3044 		_t = _t->getNextSibling();
3045 		break;
3046 	}
3047 	case EXPR:
3048 	case SYSVAR:
3049 	case VAR:
3050 	case VARPTR:
3051 	{
3052 		r=r_dot_indexable_expr(_t, aD);
3053 		_t = _retTree;
3054 		break;
3055 	}
3056 	default:
3057 	{
3058 		throw antlr::NoViableAltException(antlr::RefAST(_t));
3059 	}
3060 	}
3061 	_retTree = _t;
3062 }
3063 
assign_expr(ProgNodeP _t)3064 BaseGDL*  GDLInterpreter::assign_expr(ProgNodeP _t) {
3065 	BaseGDL* res;
3066 	ProgNodeP assign_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3067 
3068 	res = _t->Eval();
3069 		_retTree = _t->getNextSibling();
3070 	return res;
3071 
3072 	BaseGDL** l;
3073 
3074 
3075 	if (_t == ProgNodeP(antlr::nullAST) )
3076 		_t = ASTNULL;
3077 	switch ( _t->getType()) {
3078 	case ASSIGN:
3079 	{
3080 		ProgNodeP tmp92_AST_in = _t;
3081 		match(antlr::RefAST(_t),ASSIGN);
3082 		_t = _t->getNextSibling();
3083 		break;
3084 	}
3085 	case ASSIGN_ARRAYEXPR_MFCALL:
3086 	{
3087 		ProgNodeP tmp93_AST_in = _t;
3088 		match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
3089 		_t = _t->getNextSibling();
3090 		break;
3091 	}
3092 	case ASSIGN_REPLACE:
3093 	{
3094 		ProgNodeP tmp94_AST_in = _t;
3095 		match(antlr::RefAST(_t),ASSIGN_REPLACE);
3096 		_t = _t->getNextSibling();
3097 		break;
3098 	}
3099 	default:
3100 	{
3101 		throw antlr::NoViableAltException(antlr::RefAST(_t));
3102 	}
3103 	}
3104 	_retTree = _t;
3105 	return res;
3106 }
3107 
unused_function_call(ProgNodeP _t)3108  BaseGDL*  GDLInterpreter::unused_function_call(ProgNodeP _t) {
3109 	 BaseGDL* res;
3110 	ProgNodeP unused_function_call_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3111 	res=NULL;
3112 
3113 	if (_t == ProgNodeP(antlr::nullAST) )
3114 		_t = ASTNULL;
3115 	switch ( _t->getType()) {
3116 	case MFCALL:
3117 	{
3118 		ProgNodeP tmp95_AST_in = _t;
3119 		match(antlr::RefAST(_t),MFCALL);
3120 		_t = _t->getNextSibling();
3121 		break;
3122 	}
3123 	case MFCALL_PARENT:
3124 	{
3125 		ProgNodeP tmp96_AST_in = _t;
3126 		match(antlr::RefAST(_t),MFCALL_PARENT);
3127 		_t = _t->getNextSibling();
3128 		break;
3129 	}
3130 	case FCALL:
3131 	{
3132 		ProgNodeP tmp97_AST_in = _t;
3133 		match(antlr::RefAST(_t),FCALL);
3134 		_t = _t->getNextSibling();
3135 		break;
3136 	}
3137 	case ARRAYEXPR_MFCALL:
3138 	{
3139 		ProgNodeP tmp98_AST_in = _t;
3140 		match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
3141 		_t = _t->getNextSibling();
3142 		break;
3143 	}
3144 	default:
3145 	{
3146 		throw antlr::NoViableAltException(antlr::RefAST(_t));
3147 	}
3148 	}
3149 	_retTree = _t;
3150 	return res;
3151 }
3152 
lib_function_call_retnew_internal(ProgNodeP _t)3153  BaseGDL*  GDLInterpreter::lib_function_call_retnew_internal(ProgNodeP _t) {
3154 	 BaseGDL* res;
3155 	ProgNodeP lib_function_call_retnew_internal_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3156 
3157 	res = _t->Eval();
3158 		_retTree = _t->getNextSibling();
3159 		return res; //_t->cData->Dup();
3160 
3161 
3162 	ProgNodeP tmp99_AST_in = _t;
3163 	match(antlr::RefAST(_t),FCALL_LIB_RETNEW);
3164 	_t = _t->getNextSibling();
3165 	_retTree = _t;
3166 	return res;
3167 }
3168 
simple_var(ProgNodeP _t)3169 BaseGDL*  GDLInterpreter::simple_var(ProgNodeP _t) {
3170 	BaseGDL* res;
3171 	ProgNodeP simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3172 
3173 		assert( _t != NULL);
3174 	BaseGDL* vData = _t->EvalNC();
3175 		if( vData == NULL)
3176 	{
3177 	if( _t->getType() == VAR)
3178 	throw GDLException( _t, "Variable is undefined: "+_t->getText(),true,false);
3179 	else // VARPTR
3180 	throw GDLException( _t, "Common block variable is undefined.",true,false);
3181 	}
3182 		_retTree = _t->getNextSibling();
3183 		return vData->Dup();
3184 
3185 
3186 	if (_t == ProgNodeP(antlr::nullAST) )
3187 		_t = ASTNULL;
3188 	switch ( _t->getType()) {
3189 	case VAR:
3190 	{
3191 		ProgNodeP tmp100_AST_in = _t;
3192 		match(antlr::RefAST(_t),VAR);
3193 		_t = _t->getNextSibling();
3194 		break;
3195 	}
3196 	case VARPTR:
3197 	{
3198 		ProgNodeP tmp101_AST_in = _t;
3199 		match(antlr::RefAST(_t),VARPTR);
3200 		_t = _t->getNextSibling();
3201 		break;
3202 	}
3203 	default:
3204 	{
3205 		throw antlr::NoViableAltException(antlr::RefAST(_t));
3206 	}
3207 	}
3208 	_retTree = _t;
3209 	return res;
3210 }
3211 
sys_var(ProgNodeP _t)3212 BaseGDL*  GDLInterpreter::sys_var(ProgNodeP _t) {
3213 	BaseGDL* res;
3214 	ProgNodeP sys_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3215 
3216 	res = _t->Eval();
3217 		_retTree = _t->getNextSibling();
3218 		return res; // no ->Dup()
3219 
3220 
3221 	ProgNodeP tmp102_AST_in = _t;
3222 	match(antlr::RefAST(_t),SYSVAR);
3223 	_t = _t->getNextSibling();
3224 	_retTree = _t;
3225 	return res;
3226 }
3227 
l_arrayexpr_mfcall_as_arrayexpr(ProgNodeP _t,BaseGDL * right)3228 BaseGDL**  GDLInterpreter::l_arrayexpr_mfcall_as_arrayexpr(ProgNodeP _t,
3229 	BaseGDL* right
3230 ) {
3231 	BaseGDL** res;
3232 	ProgNodeP l_arrayexpr_mfcall_as_arrayexpr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3233 	ProgNodeP dot = ProgNodeP(antlr::nullAST);
3234 
3235 	ProgNodeP __t74 = _t;
3236 	ProgNodeP tmp103_AST_in = _t;
3237 	match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
3238 	_t = _t->getFirstChild();
3239 	ProgNodeP __t75 = _t;
3240 	dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3241 	match(antlr::RefAST(_t),DOT);
3242 	_t = _t->getFirstChild();
3243 
3244 	SizeT nDot=dot->nDot;
3245 	Guard<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
3246 
3247 	l_dot_array_expr(_t, aD.Get());
3248 	_t = _retTree;
3249 	{ // ( ... )+
3250 	int _cnt77=0;
3251 	for (;;) {
3252 		if (_t == ProgNodeP(antlr::nullAST) )
3253 			_t = ASTNULL;
3254 		if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
3255 			tag_array_expr(_t, aD.Get());
3256 			_t = _retTree;
3257 		}
3258 		else {
3259 			if ( _cnt77>=1 ) { goto _loop77; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
3260 		}
3261 
3262 		_cnt77++;
3263 	}
3264 	_loop77:;
3265 	}  // ( ... )+
3266 	_t = __t75;
3267 	_t = _t->getNextSibling();
3268 	_t = __t74;
3269 	_t = _t->getNextSibling();
3270 
3271 	if( right == NULL)
3272 	throw GDLException( _t,
3273 	"Struct expression not allowed in this context.",
3274 	true,false);
3275 
3276 	aD.Get()->ADAssign( right);
3277 
3278 	res=NULL;
3279 
3280 	_retTree = _t;
3281 	return res;
3282 }
3283 
parameter_def_n_elements(ProgNodeP _t,EnvBaseT * actEnv)3284 void GDLInterpreter::parameter_def_n_elements(ProgNodeP _t,
3285 	EnvBaseT* actEnv
3286 ) {
3287 	ProgNodeP parameter_def_n_elements_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3288 
3289 	Guard<EnvBaseT> guard(actEnv);
3290 	_retTree = _t;
3291 	//     bool interruptEnableIn = interruptEnable;
3292 	if( _retTree != NULL)
3293 	{
3294 	int nPar = _retTree->GetNParam();
3295 	//int nSub = actEnv->GetPro()->NPar();
3296 	assert(  actEnv->GetPro()->NPar() == 1); // N_ELEMENTS
3297 	// fixed number of parameters
3298 	if( nPar > 1)//nSub) // check here
3299 	{
3300 	throw GDLException( _t, actEnv->GetProName() +
3301 	": Incorrect number of arguments.",
3302 	false, false);
3303 	}
3304 
3305 	if( _retTree->getType() == REF ||
3306 	_retTree->getType() == REF_EXPR ||
3307 	_retTree->getType() == REF_CHECK ||
3308 	_retTree->getType() == PARAEXPR)
3309 	{
3310 	try
3311 	{
3312 	//                     interruptEnable = false;
3313 	static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
3314 	//                     interruptEnable = interruptEnableIn;
3315 	}
3316 	catch( GDLException& e)
3317 	{
3318 	// an error occured -> parameter is undefined
3319 	//                         interruptEnable = interruptEnableIn;
3320 	if( actEnv->NParam() == 0) // not set yet
3321 	{
3322 	BaseGDL* nullP = NULL;
3323 	actEnv->SetNextPar( nullP);
3324 	}
3325 	}
3326 	}
3327 	else // used for error handling: keywords are checked only here in Parameter()
3328 	{
3329 	try
3330 	{
3331 	// as N_ELEMENTS has no keywords this should throw always
3332 	static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
3333 	assert( 0);
3334 	}
3335 	catch( GDLException& e)
3336 	{
3337 	// update line number, currently set to caller->CallingNode()
3338 	// because actEnv is not on the stack yet,
3339 	// report caller->Pro()'s name is ok, because we are not inside
3340 	// the call yet
3341 	e.SetErrorNodeP( actEnv->CallingNode());
3342 	throw e;
3343 	}
3344 	}
3345 	// actEnv->Extra(); // expand _EXTRA
3346 	} // if( _retTree != NULL)
3347 
3348 		guard.release();
3349 
3350 	return;
3351 
3352 
3353 	ProgNodeP tmp104_AST_in = _t;
3354 	match(antlr::RefAST(_t),KEYDEF_REF_EXPR);
3355 	_t = _t->getNextSibling();
3356 	ProgNodeP tmp105_AST_in = _t;
3357 	match(antlr::RefAST(_t),IDENTIFIER);
3358 	_t = _t->getNextSibling();
3359 	_retTree = _t;
3360 }
3361 
parameter_def_nocheck(ProgNodeP _t,EnvBaseT * actEnv)3362 void GDLInterpreter::parameter_def_nocheck(ProgNodeP _t,
3363 	EnvBaseT* actEnv
3364 ) {
3365 	ProgNodeP parameter_def_nocheck_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3366 
3367 	Guard<EnvBaseT> guard(actEnv);
3368 
3369 	EnvBaseT* callerEnv = callStack.back();
3370 	EnvBaseT* oldNewEnv = callerEnv->GetNewEnv();
3371 
3372 	callerEnv->SetNewEnv( actEnv);
3373 
3374 	try{
3375 
3376 	if( _t != NULL)
3377 	{
3378 	_retTree = _t;
3379 	// _retTree != NULL, save one check // 'if' is needed already for Extra()
3380 	static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
3381 	// Parameter does no checking
3382 	while(_retTree != NULL)
3383 	static_cast<ParameterNode*>(_retTree)->Parameter( actEnv);
3384 
3385 	actEnv->ResolveExtra(); // expand _EXTRA
3386 	}
3387 	}
3388 	catch( GDLException& e)
3389 	{
3390 	callerEnv->SetNewEnv( oldNewEnv);
3391 	// update line number, currently set to caller->CallingNode()
3392 	// because actEnv is not on the stack yet,
3393 	// report caller->Pro()'s name is ok, because we are not inside
3394 	// the call yet
3395 	e.SetErrorNodeP( actEnv->CallingNode());
3396 	throw e;
3397 	}
3398 	callerEnv->SetNewEnv( oldNewEnv);
3399 
3400 		guard.release();
3401 
3402 	return;
3403 
3404 
3405 	ProgNodeP tmp106_AST_in = _t;
3406 	match(antlr::RefAST(_t),KEYDEF_REF);
3407 	_t = _t->getNextSibling();
3408 	ProgNodeP tmp107_AST_in = _t;
3409 	match(antlr::RefAST(_t),IDENTIFIER);
3410 	_t = _t->getNextSibling();
3411 	_retTree = _t;
3412 }
3413 
arrayindex_list_overload(ProgNodeP _t,IxExprListT & indexList)3414 void GDLInterpreter::arrayindex_list_overload(ProgNodeP _t,
3415 	IxExprListT& indexList
3416 ) {
3417 	ProgNodeP arrayindex_list_overload_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
3418 
3419 	ArrayIndexListT* aL;
3420 	// IxExprListT      cleanupList; // for cleanup
3421 	IxExprListT      ixExprList;
3422 	SizeT nExpr;
3423 	BaseGDL* s;
3424 
3425 	//	ProgNodeP retTree = _t->getNextSibling();
3426 		ProgNodeP ax = _t;
3427 	// 	match(antlr::RefAST(_t),ARRAYIX);
3428 		_t = _t->getFirstChild();
3429 
3430 		aL = ax->arrIxListNoAssoc;
3431 		assert( aL != NULL);
3432 
3433 		nExpr = aL->NParam();
3434 		if( nExpr == 0)
3435 		{
3436 	aL->InitAsOverloadIndex( ixExprList, /* NULL,*/ indexList);
3437 	_retTree = ax->getNextSibling();//retTree;
3438 	return;
3439 		}
3440 
3441 	IxExprListT* cleanupList = aL->GetCleanupIx();
3442 
3443 		while( true) {
3444 	assert( _t != NULL);
3445 	if( NonCopyNode( _t->getType()))
3446 	{
3447 	s= _t->EvalNCNull(); // in this case (overload) NULL is ok
3448 	//_t = _retTree;
3449 	}
3450 	else
3451 	{
3452 	BaseGDL** ref=_t->EvalRefCheck( s); //indexable_tmp_expr(_t);
3453 	//_t = _retTree;
3454 	if( ref == NULL)
3455 			  cleanupList->push_back( s);
3456 			else
3457 			  s = *ref;
3458 	}
3459 
3460 	ixExprList.push_back( s);
3461 	if( ixExprList.size() == nExpr)
3462 	break; // allows some manual tuning
3463 
3464 	_t = _t->getNextSibling();
3465 		}
3466 
3467 	aL->InitAsOverloadIndex( ixExprList, /*&cleanupList,*/ indexList);
3468 
3469 		_retTree = ax->getNextSibling();//retTree;
3470 		return;
3471 
3472 
3473 
3474 	ProgNodeP tmp108_AST_in = _t;
3475 	match(antlr::RefAST(_t),ARRAYIX);
3476 	_t = _t->getNextSibling();
3477 	_retTree = _t;
3478 }
3479 
initializeASTFactory(antlr::ASTFactory &)3480 void GDLInterpreter::initializeASTFactory( antlr::ASTFactory& )
3481 {
3482 }
3483 const char* GDLInterpreter::tokenNames[] = {
3484 	"<0>",
3485 	"EOF",
3486 	"<2>",
3487 	"NULL_TREE_LOOKAHEAD",
3488 	"ALL",
3489 	"ASSIGN",
3490 	"ASSIGN_INPLACE",
3491 	"ASSIGN_REPLACE",
3492 	"ASSIGN_ARRAYEXPR_MFCALL",
3493 	"ARRAYDEF",
3494 	"ARRAYDEF_CONST",
3495 	"ARRAYDEF_GENERALIZED_INDGEN",
3496 	"ARRAYIX",
3497 	"ARRAYIX_ALL",
3498 	"ARRAYIX_ORANGE",
3499 	"ARRAYIX_RANGE",
3500 	"ARRAYIX_ORANGE_S",
3501 	"ARRAYIX_RANGE_S",
3502 	"ARRAYEXPR",
3503 	"ARRAYEXPR_FCALL",
3504 	"ARRAYEXPR_MFCALL",
3505 	"BLOCK",
3506 	"BREAK",
3507 	"CSBLOCK",
3508 	"CONTINUE",
3509 	"COMMONDECL",
3510 	"COMMONDEF",
3511 	"CONSTANT",
3512 	"DEREF",
3513 	"ELSEBLK",
3514 	"EXPR",
3515 	"\"for\"",
3516 	"FOR_STEP",
3517 	"\"foreach\"",
3518 	"FOREACH_INDEX",
3519 	"FOR_LOOP",
3520 	"FOR_STEP_LOOP",
3521 	"FOREACH_LOOP",
3522 	"FOREACH_INDEX_LOOP",
3523 	"FCALL",
3524 	"FCALL_LIB",
3525 	"FCALL_LIB_DIRECT",
3526 	"FCALL_LIB_N_ELEMENTS",
3527 	"FCALL_LIB_RETNEW",
3528 	"GDLNULL",
3529 	"IF_ELSE",
3530 	"KEYDECL",
3531 	"KEYDEF",
3532 	"KEYDEF_REF",
3533 	"KEYDEF_REF_CHECK",
3534 	"KEYDEF_REF_EXPR",
3535 	"LABEL",
3536 	"MPCALL",
3537 	"MPCALL_PARENT",
3538 	"MFCALL",
3539 	"MFCALL_LIB",
3540 	"MFCALL_LIB_RETNEW",
3541 	"MFCALL_PARENT",
3542 	"MFCALL_PARENT_LIB",
3543 	"MFCALL_PARENT_LIB_RETNEW",
3544 	"NOP",
3545 	"NSTRUC",
3546 	"NSTRUC_REF",
3547 	"ON_IOERROR_NULL",
3548 	"PCALL",
3549 	"PCALL_LIB",
3550 	"PARADECL",
3551 	"PARAEXPR",
3552 	"PARAEXPR_VN",
3553 	"DEC_REF_CHECK",
3554 	"INC_REF_CHECK",
3555 	"POSTDEC",
3556 	"POSTINC",
3557 	"DECSTATEMENT",
3558 	"INCSTATEMENT",
3559 	"REF",
3560 	"REF_VN",
3561 	"REF_CHECK",
3562 	"REF_CHECK_VN",
3563 	"REF_EXPR",
3564 	"REF_EXPR_VN",
3565 	"\"repeat\"",
3566 	"REPEAT_LOOP",
3567 	"RETURN",
3568 	"RETF",
3569 	"RETP",
3570 	"STRUC",
3571 	"SYSVAR",
3572 	"UMINUS",
3573 	"VAR",
3574 	"VARPTR",
3575 	"\"while\"",
3576 	"IDENTIFIER",
3577 	"\"and\"",
3578 	"\"begin\"",
3579 	"\"case\"",
3580 	"\"common\"",
3581 	"\"compile_opt\"",
3582 	"\"do\"",
3583 	"\"else\"",
3584 	"\"end\"",
3585 	"\"endcase\"",
3586 	"\"endelse\"",
3587 	"\"endfor\"",
3588 	"\"endforeach\"",
3589 	"\"endif\"",
3590 	"\"endrep\"",
3591 	"\"endswitch\"",
3592 	"\"endwhile\"",
3593 	"\"eq\"",
3594 	"\"forward_function\"",
3595 	"\"function\"",
3596 	"\"ge\"",
3597 	"\"goto\"",
3598 	"\"gt\"",
3599 	"\"if\"",
3600 	"\"inherits\"",
3601 	"\"le\"",
3602 	"\"lt\"",
3603 	"\"mod\"",
3604 	"\"ne\"",
3605 	"\"not\"",
3606 	"\"of\"",
3607 	"\"on_ioerror\"",
3608 	"\"or\"",
3609 	"\"pro\"",
3610 	"\"switch\"",
3611 	"\"then\"",
3612 	"\"until\"",
3613 	"\"xor\"",
3614 	"METHOD",
3615 	"COMMA",
3616 	"COLON",
3617 	"END_U",
3618 	"EQUAL",
3619 	"DEC",
3620 	"INC",
3621 	"AND_OP_EQ",
3622 	"ASTERIX_EQ",
3623 	"EQ_OP_EQ",
3624 	"GE_OP_EQ",
3625 	"GTMARK_EQ",
3626 	"GT_OP_EQ",
3627 	"LE_OP_EQ",
3628 	"LTMARK_EQ",
3629 	"LT_OP_EQ",
3630 	"MATRIX_OP1_EQ",
3631 	"MATRIX_OP2_EQ",
3632 	"MINUS_EQ",
3633 	"MOD_OP_EQ",
3634 	"NE_OP_EQ",
3635 	"OR_OP_EQ",
3636 	"PLUS_EQ",
3637 	"POW_EQ",
3638 	"SLASH_EQ",
3639 	"XOR_OP_EQ",
3640 	"MEMBER",
3641 	"LBRACE",
3642 	"RBRACE",
3643 	"SLASH",
3644 	"LSQUARE",
3645 	"RSQUARE",
3646 	"SYSVARNAME",
3647 	"EXCLAMATION",
3648 	"LCURLY",
3649 	"RCURLY",
3650 	"CONSTANT_HEX_BYTE",
3651 	"CONSTANT_HEX_LONG",
3652 	"CONSTANT_HEX_LONG64",
3653 	"CONSTANT_HEX_INT",
3654 	"CONSTANT_HEX_I",
3655 	"CONSTANT_HEX_ULONG",
3656 	"CONSTANT_HEX_ULONG64",
3657 	"CONSTANT_HEX_UI",
3658 	"CONSTANT_HEX_UINT",
3659 	"CONSTANT_BYTE",
3660 	"CONSTANT_LONG",
3661 	"CONSTANT_LONG64",
3662 	"CONSTANT_INT",
3663 	"CONSTANT_I",
3664 	"CONSTANT_ULONG",
3665 	"CONSTANT_ULONG64",
3666 	"CONSTANT_UI",
3667 	"CONSTANT_UINT",
3668 	"CONSTANT_OCT_BYTE",
3669 	"CONSTANT_OCT_LONG",
3670 	"CONSTANT_OCT_LONG64",
3671 	"CONSTANT_OCT_INT",
3672 	"CONSTANT_OCT_I",
3673 	"CONSTANT_OCT_ULONG",
3674 	"CONSTANT_OCT_ULONG64",
3675 	"CONSTANT_OCT_UI",
3676 	"CONSTANT_OCT_UINT",
3677 	"CONSTANT_FLOAT",
3678 	"CONSTANT_DOUBLE",
3679 	"CONSTANT_BIN_BYTE",
3680 	"CONSTANT_BIN_LONG",
3681 	"CONSTANT_BIN_LONG64",
3682 	"CONSTANT_BIN_INT",
3683 	"CONSTANT_BIN_I",
3684 	"CONSTANT_BIN_ULONG",
3685 	"CONSTANT_BIN_ULONG64",
3686 	"CONSTANT_BIN_UI",
3687 	"CONSTANT_BIN_UINT",
3688 	"ASTERIX",
3689 	"DOT",
3690 	"STRING_LITERAL",
3691 	"POW",
3692 	"MATRIX_OP1",
3693 	"MATRIX_OP2",
3694 	"PLUS",
3695 	"MINUS",
3696 	"LTMARK",
3697 	"GTMARK",
3698 	"LOG_NEG",
3699 	"LOG_AND",
3700 	"LOG_OR",
3701 	"QUESTION",
3702 	"STRING",
3703 	"INCLUDE",
3704 	"EOL",
3705 	"W",
3706 	"D",
3707 	"L",
3708 	"H",
3709 	"O",
3710 	"B",
3711 	"EXP",
3712 	"DBL_E",
3713 	"DBL",
3714 	"CONSTANT_OR_STRING_LITERAL",
3715 	"COMMENT",
3716 	"END_MARKER",
3717 	"WHITESPACE",
3718 	"SKIP_LINES",
3719 	"CONT_STATEMENT",
3720 	"END_OF_LINE",
3721 	"MAX_TOKEN_NUMBER",
3722 	0
3723 };
3724 
3725 const unsigned long GDLInterpreter::_tokenSet_0_data_[] = { 2170552736UL, 2151161983UL, 2285240323UL, 1208614912UL, 384UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
3726 // ASSIGN ASSIGN_REPLACE ASSIGN_ARRAYEXPR_MFCALL BLOCK BREAK CONTINUE "for"
3727 // FOR_STEP "foreach" FOREACH_INDEX FOR_LOOP FOR_STEP_LOOP FOREACH_LOOP
3728 // FOREACH_INDEX_LOOP IF_ELSE LABEL MPCALL MPCALL_PARENT ON_IOERROR_NULL
3729 // PCALL PCALL_LIB "repeat" REPEAT_LOOP RETF RETP "while" "case" "goto"
3730 // "if" "on_ioerror" "switch" DEC INC
3731 const antlr::BitSet GDLInterpreter::_tokenSet_0(_tokenSet_0_data_,12);
3732 
3733 
3734