/gdl-0.9.2/src/GDLInterpreter.cpp.cvs
# · Unknown · 5517 lines · 4959 code · 558 blank · 0 comment · 0 complexity · 34ac64aaa160190a9fa9d9d390b2093a MD5 · raw file
Large files are truncated click here to view the full file
- /* $ANTLR 2.7.7 (20110618): "gdlc.i.g" -> "GDLInterpreter.cpp"$ */
- // gets inserted before the antlr generated includes in the cpp file
- #include "includefirst.hpp"
- #include "GDLInterpreter.hpp"
- #include <antlr/Token.hpp>
- #include <antlr/AST.hpp>
- #include <antlr/NoViableAltException.hpp>
- #include <antlr/MismatchedTokenException.hpp>
- #include <antlr/SemanticException.hpp>
- #include <antlr/BitSet.hpp>
- // gets inserted after the antlr generated includes in the cpp file
- #include "dinterpreter.hpp"
- #include "prognodeexpr.hpp"
- #include <cassert>
- // tweaking ANTLR
- #define ASTNULL NULLProgNodeP
- #define ProgNodeP( xxx ) NULL /* ProgNodeP(antlr::nullAST) */
- #define RefAST( xxx) ConvertAST( xxx) /* antlr::RefAST( Ref type) */
- #define match( a, b) /* remove from source */
- using namespace std;
- GDLInterpreter::GDLInterpreter()
- : antlr::TreeParser() {
- }
- RetCode GDLInterpreter::interactive(ProgNodeP _t) {
- RetCode retCode;
- ProgNodeP interactive_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- for (; _t != NULL;) {
-
- //_t->setLine(0);
- retCode=statement(_t);
- _t = _retTree;
-
- if( retCode != RC_OK) break; // break out if non-regular
- }
- _retTree = _t;
- return retCode;
-
-
- { // ( ... )+
- int _cnt3=0;
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_tokenSet_0.member(_t->getType()))) {
- retCode=statement(_t);
- _t = _retTree;
-
- if( retCode != RC_OK) break; // break out if non-regular
-
- }
- else {
- if ( _cnt3>=1 ) { goto _loop3; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
- }
-
- _cnt3++;
- }
- _loop3:;
- } // ( ... )+
- _retTree = _t;
- return retCode;
- }
- RetCode GDLInterpreter::statement(ProgNodeP _t) {
- RetCode retCode;
- ProgNodeP statement_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- // ProgNodeP& actPos = statement_AST_in;
- assert( _t != NULL);
- ProgNodeP last;
- _retTree = _t;
- // if( callStack.back()->GetLineNumber() == 0)
- // if( _t->getLine() != 0)
- // callStack.back()->SetLineNumber( _t->getLine());
-
-
- try { // for error handling
-
- do {
- // if( _t->getLine() != 0)
- // callStack.back()->SetLineNumber( _t->getLine());
-
- last = _retTree;
-
- // track actual line number
- callStack.back()->SetLineNumber( last->getLine());
-
- retCode = last->Run(); // Run() sets _retTree
-
- }
- while(
- _retTree != NULL &&
- retCode == RC_OK &&
- !(sigControlC && interruptEnable) &&
- (debugMode == DEBUG_CLEAR));
-
- if( _retTree != NULL)
- last = _retTree;
-
- goto afterStatement;
-
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ASSIGN:
- {
- ProgNodeP tmp1_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN);
- _t = _t->getNextSibling();
- break;
- }
- case ASSIGN_ARRAYEXPR_MFCALL:
- {
- ProgNodeP tmp2_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
- _t = _t->getNextSibling();
- break;
- }
- case ASSIGN_REPLACE:
- {
- ProgNodeP tmp3_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN_REPLACE);
- _t = _t->getNextSibling();
- break;
- }
- case PCALL_LIB:
- {
- ProgNodeP tmp4_AST_in = _t;
- match(antlr::RefAST(_t),PCALL_LIB);
- _t = _t->getNextSibling();
- break;
- }
- case MPCALL:
- {
- ProgNodeP tmp5_AST_in = _t;
- match(antlr::RefAST(_t),MPCALL);
- _t = _t->getNextSibling();
- break;
- }
- case MPCALL_PARENT:
- {
- ProgNodeP tmp6_AST_in = _t;
- match(antlr::RefAST(_t),MPCALL_PARENT);
- _t = _t->getNextSibling();
- break;
- }
- case PCALL:
- {
- ProgNodeP tmp7_AST_in = _t;
- match(antlr::RefAST(_t),PCALL);
- _t = _t->getNextSibling();
- break;
- }
- case DEC:
- {
- ProgNodeP tmp8_AST_in = _t;
- match(antlr::RefAST(_t),DEC);
- _t = _t->getNextSibling();
- break;
- }
- case INC:
- {
- ProgNodeP tmp9_AST_in = _t;
- match(antlr::RefAST(_t),INC);
- _t = _t->getNextSibling();
- break;
- }
- case FOR:
- {
- ProgNodeP tmp10_AST_in = _t;
- match(antlr::RefAST(_t),FOR);
- _t = _t->getNextSibling();
- break;
- }
- case FOR_LOOP:
- {
- ProgNodeP tmp11_AST_in = _t;
- match(antlr::RefAST(_t),FOR_LOOP);
- _t = _t->getNextSibling();
- break;
- }
- case FOREACH:
- {
- ProgNodeP tmp12_AST_in = _t;
- match(antlr::RefAST(_t),FOREACH);
- _t = _t->getNextSibling();
- break;
- }
- case FOREACH_LOOP:
- {
- ProgNodeP tmp13_AST_in = _t;
- match(antlr::RefAST(_t),FOREACH_LOOP);
- _t = _t->getNextSibling();
- break;
- }
- case FOREACH_INDEX:
- {
- ProgNodeP tmp14_AST_in = _t;
- match(antlr::RefAST(_t),FOREACH_INDEX);
- _t = _t->getNextSibling();
- break;
- }
- case FOREACH_INDEX_LOOP:
- {
- ProgNodeP tmp15_AST_in = _t;
- match(antlr::RefAST(_t),FOREACH_INDEX_LOOP);
- _t = _t->getNextSibling();
- break;
- }
- case FOR_STEP:
- {
- ProgNodeP tmp16_AST_in = _t;
- match(antlr::RefAST(_t),FOR_STEP);
- _t = _t->getNextSibling();
- break;
- }
- case FOR_STEP_LOOP:
- {
- ProgNodeP tmp17_AST_in = _t;
- match(antlr::RefAST(_t),FOR_STEP_LOOP);
- _t = _t->getNextSibling();
- break;
- }
- case REPEAT:
- {
- ProgNodeP tmp18_AST_in = _t;
- match(antlr::RefAST(_t),REPEAT);
- _t = _t->getNextSibling();
- break;
- }
- case REPEAT_LOOP:
- {
- ProgNodeP tmp19_AST_in = _t;
- match(antlr::RefAST(_t),REPEAT_LOOP);
- _t = _t->getNextSibling();
- break;
- }
- case WHILE:
- {
- ProgNodeP tmp20_AST_in = _t;
- match(antlr::RefAST(_t),WHILE);
- _t = _t->getNextSibling();
- break;
- }
- case IF:
- {
- ProgNodeP tmp21_AST_in = _t;
- match(antlr::RefAST(_t),IF);
- _t = _t->getNextSibling();
- break;
- }
- case IF_ELSE:
- {
- ProgNodeP tmp22_AST_in = _t;
- match(antlr::RefAST(_t),IF_ELSE);
- _t = _t->getNextSibling();
- break;
- }
- case CASE:
- {
- ProgNodeP tmp23_AST_in = _t;
- match(antlr::RefAST(_t),CASE);
- _t = _t->getNextSibling();
- break;
- }
- case SWITCH:
- {
- ProgNodeP tmp24_AST_in = _t;
- match(antlr::RefAST(_t),SWITCH);
- _t = _t->getNextSibling();
- break;
- }
- case BLOCK:
- {
- ProgNodeP tmp25_AST_in = _t;
- match(antlr::RefAST(_t),BLOCK);
- _t = _t->getNextSibling();
- break;
- }
- case LABEL:
- {
- ProgNodeP tmp26_AST_in = _t;
- match(antlr::RefAST(_t),LABEL);
- _t = _t->getNextSibling();
- break;
- }
- case ON_IOERROR_NULL:
- {
- ProgNodeP tmp27_AST_in = _t;
- match(antlr::RefAST(_t),ON_IOERROR_NULL);
- _t = _t->getNextSibling();
- break;
- }
- case ON_IOERROR:
- {
- ProgNodeP tmp28_AST_in = _t;
- match(antlr::RefAST(_t),ON_IOERROR);
- _t = _t->getNextSibling();
- break;
- }
- case BREAK:
- {
- ProgNodeP tmp29_AST_in = _t;
- match(antlr::RefAST(_t),BREAK);
- _t = _t->getNextSibling();
- break;
- }
- case CONTINUE:
- {
- ProgNodeP tmp30_AST_in = _t;
- match(antlr::RefAST(_t),CONTINUE);
- _t = _t->getNextSibling();
- break;
- }
- case GOTO:
- {
- ProgNodeP tmp31_AST_in = _t;
- match(antlr::RefAST(_t),GOTO);
- _t = _t->getNextSibling();
- break;
- }
- case RETF:
- {
- ProgNodeP tmp32_AST_in = _t;
- match(antlr::RefAST(_t),RETF);
- _t = _t->getNextSibling();
- break;
- }
- case RETP:
- {
- ProgNodeP tmp33_AST_in = _t;
- match(antlr::RefAST(_t),RETP);
- _t = _t->getNextSibling();
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
-
- afterStatement:;
-
- // possible optimization: make sigControlC a debugMode
- if( interruptEnable && sigControlC)
- {
- DebugMsg( last, "Interrupted at: ");
-
- sigControlC = false;
-
- retCode = NewInterpreterInstance( last->getLine());//-1);
- }
- else if( debugMode != DEBUG_CLEAR)
- {
- if( debugMode == DEBUG_STOP)
- {
- DebugMsg( last, "Stop encountered: ");
- if( !interruptEnable)
- debugMode = DEBUG_PROCESS_STOP;
- }
-
- if( debugMode == DEBUG_STEP)
- {
- if( stepCount == 1)
- {
- stepCount = 0;
- DebugMsg( last, "Stepped to: ");
-
- debugMode = DEBUG_CLEAR;
-
- retCode = NewInterpreterInstance( last->getLine());//-1);
- }
- else
- {
- --stepCount;
- #ifdef GDL_DEBUG
- std::cout << "stepCount-- = " << stepCount << std::endl;
- #endif
- }
- }
- else
- if( interruptEnable)
- {
- if( debugMode == DEBUG_PROCESS_STOP)
- {
- DebugMsg( last, "Stepped to: ");
- }
-
- debugMode = DEBUG_CLEAR;
-
- retCode = NewInterpreterInstance( last->getLine());//-1);
- }
- else
- {
- retCode = RC_ABORT;
- }
- }
- return retCode;
-
- }
- catch ( GDLException& e) {
-
- // reset _retTree to last statement
- // (might otherwise be inside an expression in which case
- // .CONTINUE does not work)
- _retTree = last;
-
- if( dynamic_cast< GDLIOException*>( &e) != NULL)
- {
- // set the jump target - also logs the jump
- ProgNodeP onIOErr =
- static_cast<EnvUDT*>(callStack.back())->GetIOError();
- if( onIOErr != NULL)
- {
- SysVar::SetErr_String( e.getMessage());
-
- _retTree = onIOErr;
- return RC_OK;
- }
- }
-
- EnvUDT* targetEnv = e.GetTargetEnv();
- if( targetEnv == NULL)
- {
- // initial exception, set target env
- // look if ON_ERROR is set somewhere
- for( EnvStackT::reverse_iterator i = callStack.rbegin();
- i != callStack.rend(); ++i)
- {
- DLong oE = -1;
- EnvUDT* envUD = dynamic_cast<EnvUDT*>(*i);
- if( envUD != NULL)
- oE = envUD->GetOnError();
-
- if( oE != -1)
- { // oE was set
-
- // 0 -> stop here
- if( oE == 0)
- targetEnv = static_cast<EnvUDT*>(callStack.back());
- // 1 -> $MAIN$
- else if( oE == 1)
- {
- EnvUDT* cS_begin =
- static_cast<EnvUDT*>(*callStack.begin());
- targetEnv = cS_begin;
- }
- // 2 -> caller of routine which called ON_ERROR
- else if( oE == 2)
- {
- // set to caller, handle nested
- while( static_cast<EnvUDT*>(*(++i))->GetOnError() == 2
- && i != callStack.rend());
-
- if( i == callStack.rend())
- {
- EnvUDT* cS_begin =
- static_cast<EnvUDT*>(*callStack.begin());
- targetEnv = cS_begin;
- }
- else
- {
- EnvUDT* iUDT = static_cast<EnvUDT*>(*i);
- targetEnv = iUDT;
- }
- }
- // 3 -> routine which called ON_ERROR
- else if( oE == 3)
- {
- EnvUDT* iUDT = static_cast<EnvUDT*>(*i);
- targetEnv = iUDT;
- }
-
-
- // State where error occured
- // if( e.getLine() == 0 && _t != NULL)
- // e.SetLine( _t->getLine());
- // if( e.getLine() == 0 && _retTree != NULL)
- // e.SetLine( _retTree->getLine());
- if( e.getLine() == 0 && last != NULL)
- e.SetLine( last->getLine());
-
- if( interruptEnable)
- ReportError(e, "Error occurred at:");
-
- // remeber where to stop
- e.SetTargetEnv( targetEnv);
-
- if( targetEnv->GetLineNumber() != 0)
- e.SetLine( targetEnv->GetLineNumber());
-
- // ProgNodeP errorNodeP = targetEnv->CallingNode();
- // e.SetErrorNodeP( errorNodeP);
-
- // break on first occurence of set oE
- break;
- }
- }
- }
-
- if( targetEnv != NULL && targetEnv != callStack.back())
- {
- throw e; // rethrow
- }
- lib::write_journal( GetClearActualLine());
-
- // many low level routines don't have errorNode info
- // set line number here in this case
- // if( e.getLine() == 0 && _t != NULL)
- // e.SetLine( _t->getLine());
- // if( e.getLine() == 0 && _retTree != NULL)
- // e.SetLine( _retTree->getLine());
- // if( e.getLine() == 0 && actPos != NULL)
- // e.SetLine( actPos->getLine());
-
- if( interruptEnable)
- {
- // tell where we are
- ReportError(e, "Execution halted at:", targetEnv == NULL);
-
- retCode = NewInterpreterInstance(e.getLine());//-1);
- }
- else
- {
-
- DString msgPrefix = SysVar::MsgPrefix();
- if( e.Prefix())
- {
- std::cerr << msgPrefix << e.toString() << std::endl;
- lib::write_journal_comment(msgPrefix+e.toString());
- }
- else
- {
- std::cerr << e.toString() << std::endl;
- lib::write_journal_comment(e.toString());
- }
-
- retCode = RC_ABORT;
- }
-
- return retCode;
-
- }
- _retTree = _t;
- return retCode;
- }
- RetCode GDLInterpreter::execute(ProgNodeP _t) {
- RetCode retCode;
- ProgNodeP execute_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- // RetCode retCode;
- ValueGuard<bool> guard( interruptEnable);
- interruptEnable = false;
-
- return statement_list(_t);
-
-
- retCode=statement_list(_t);
- _t = _retTree;
- _retTree = _t;
- return retCode;
- }
- RetCode GDLInterpreter::statement_list(ProgNodeP _t) {
- RetCode retCode;
- ProgNodeP statement_list_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- for (; _t != NULL;) {
-
- retCode=statement(_t);
- _t = _retTree;
-
- if( retCode != RC_OK) break; // break out if non-regular
- }
- _retTree = _t;
- return retCode;
-
-
- { // ( ... )+
- int _cnt16=0;
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_tokenSet_0.member(_t->getType()))) {
- retCode=statement(_t);
- _t = _retTree;
- }
- else {
- if ( _cnt16>=1 ) { goto _loop16; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
- }
-
- _cnt16++;
- }
- _loop16:;
- } // ( ... )+
- _retTree = _t;
- return retCode;
- }
- BaseGDL* GDLInterpreter::call_fun(ProgNodeP _t) {
- BaseGDL* res;
- ProgNodeP call_fun_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
-
- res = NULL;
- returnValue = NULL;
- RetCode retCode;
-
- for (; _t != NULL;) {
-
- retCode=statement(_t);
-
- // if( retCode == RC_RETURN)
- if( retCode >= RC_RETURN)
- {
- res=returnValue;
- returnValue=NULL;
-
- break;
- }
-
- _t = _retTree;
- }
-
- // default return value if none was set
- if( res == NULL) res = new DIntGDL( 0);
-
- _retTree = _t;
- return res;
-
-
- { // ( ... )*
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_tokenSet_0.member(_t->getType()))) {
- retCode=statement(_t);
- _t = _retTree;
-
- // if( retCode == RC_RETURN)
- if( retCode >= RC_RETURN)
- {
- res=returnValue;
- returnValue=NULL;
-
- break;
- }
-
- }
- else {
- goto _loop7;
- }
-
- }
- _loop7:;
- } // ( ... )*
-
- // default return value if none was set
- if( res == NULL) res = new DIntGDL( 0);
-
- _retTree = _t;
- return res;
- }
- BaseGDL** GDLInterpreter::call_lfun(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP call_lfun_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- res = NULL;
- returnValueL = NULL;
- RetCode retCode;
-
- ProgNodeP in = _t;
-
- for (; _t != NULL;) {
- retCode=statement(_t);
- _t = _retTree;
-
- // if( retCode == RC_RETURN)
- if( retCode >= RC_RETURN)
- {
- res=returnValueL;
- returnValueL=NULL;
- break;
- }
-
- }
-
- // default return value if none was set
- if( res == NULL)
- throw GDLException( in, "Function "+
- callStack.back()->GetProName()+
- " must return a left-value in this context.",false,false);
-
- _retTree = _t;
- return res;
-
-
- { // ( ... )*
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_tokenSet_0.member(_t->getType()))) {
- retCode=statement(_t);
- _t = _retTree;
- }
- else {
- goto _loop10;
- }
-
- }
- _loop10:;
- } // ( ... )*
- _retTree = _t;
- return res;
- }
- void GDLInterpreter::call_pro(ProgNodeP _t) {
- ProgNodeP call_pro_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- RetCode retCode;
-
- for (; _t != NULL;) {
- retCode=statement(_t);
- _t = _retTree;
-
- // added RC_ABORT here
- if( retCode >= RC_RETURN) break;
- }
- _retTree = _t;
- return;
-
-
- { // ( ... )*
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_tokenSet_0.member(_t->getType()))) {
- retCode=statement(_t);
- _t = _retTree;
- }
- else {
- goto _loop13;
- }
-
- }
- _loop13:;
- } // ( ... )*
- _retTree = _t;
- }
- BaseGDL** GDLInterpreter::l_deref(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP l_deref_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- ProgNodeP retTree = _t->getNextSibling();
-
- EnvBaseT* actEnv = callStack.back()->GetNewEnv();
- if( actEnv == NULL) actEnv = callStack.back();
-
- assert( actEnv != NULL);
-
- auto_ptr<BaseGDL> e1_guard;
- BaseGDL* e1;
- ProgNodeP evalExpr = _t->getFirstChild();
- if( NonCopyNode( evalExpr->getType()))
- {
- e1 = evalExpr->EvalNC();
- }
- else if( evalExpr->getType() == GDLTokenTypes::FCALL_LIB)
- {
- e1=lib_function_call(evalExpr);
-
- if( e1 == NULL) // ROUTINE_NAMES
- throw GDLException( evalExpr, "Undefined return value", true, false);
-
- if( !callStack.back()->Contains( e1))
- {
- // if( actEnv != NULL)
- actEnv->Guard( e1);
- // else
- // e1_guard.reset( e1);
- }
- }
- else
- {
- e1 = evalExpr->Eval();
-
- // if( actEnv != NULL)
- actEnv->Guard( e1);
- // else
- // e1_guard.reset(e1);
- }
-
- if( e1 == NULL || e1->Type() != PTR)
- throw GDLException( evalExpr, "Pointer type required"
- " in this context: "+Name(e1),true,false);
-
- DPtrGDL* ptr=static_cast<DPtrGDL*>(e1);
-
- DPtr sc;
- if( !ptr->Scalar(sc))
- throw GDLException( _t, "Expression must be a "
- "scalar in this context: "+Name(e1),true,false);
- if( sc == 0)
- throw GDLException( _t, "Unable to dereference"
- " NULL pointer: "+Name(e1),true,false);
-
- try
- {
- res = &GetHeap(sc);
- }
- catch( HeapException)
- {
- throw GDLException( _t, "Invalid pointer: "+Name(e1),true,false);
- }
-
- _retTree = retTree;
- return res;
-
-
- {
- ProgNodeP tmp34_AST_in = _t;
- match(antlr::RefAST(_t),DEREF);
- _t = _t->getNextSibling();
- }
- _retTree = _t;
- return res;
- }
- BaseGDL** GDLInterpreter::l_ret_expr(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP l_ret_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- ProgNodeP varPtr = ProgNodeP(antlr::nullAST);
- ProgNodeP var = ProgNodeP(antlr::nullAST);
-
- BaseGDL* e1;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case DEREF:
- {
- res=l_deref(_t);
- _t = _retTree;
- break;
- }
- case QUESTION:
- {
- ProgNodeP __t22 = _t;
- ProgNodeP tmp35_AST_in = _t;
- match(antlr::RefAST(_t),QUESTION);
- _t = _t->getFirstChild();
- e1=expr(_t);
- _t = _retTree;
-
- auto_ptr<BaseGDL> e1_guard(e1);
- if( e1->True())
- {
- res=l_ret_expr(_t);
- }
- else
- {
- _t=_t->GetNextSibling(); // jump over 1st expression
- res=l_ret_expr(_t);
- }
-
- _t = __t22;
- _t = _t->getNextSibling();
- break;
- }
- case ARRAYEXPR_MFCALL:
- {
- res=l_arrayexpr_mfcall_as_mfcall(_t);
- _t = _retTree;
- break;
- }
- case FCALL:
- case FCALL_LIB:
- case MFCALL:
- case MFCALL_PARENT:
- {
- res=l_function_call(_t);
- _t = _retTree;
- // here a local to the actual environment could be returned
- if( callStack.back()->IsLocalKW( res))
- throw GDLException( _t,
- "Attempt to return indirectly a local variable "
- "from left-function.",true,false);
-
- break;
- }
- case VARPTR:
- {
- varPtr = _t;
- match(antlr::RefAST(_t),VARPTR);
- _t = _t->getNextSibling();
-
- res=&varPtr->var->Data(); // returns BaseGDL* of var (DVar*)
-
- break;
- }
- case VAR:
- {
- var = _t;
- match(antlr::RefAST(_t),VAR);
- _t = _t->getNextSibling();
- // check if variable is non-local
- // (because it will be invalid after return otherwise)
- if( !callStack.back()->GlobalKW(var->varIx))
- throw GDLException( _t,
- "Attempt to return a non-global variable from left-function.",true,false);
-
- res=&callStack.back()->GetKW(var->varIx);
-
- break;
- }
- case ASSIGN:
- {
- ProgNodeP __t23 = _t;
- ProgNodeP tmp36_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN);
- _t = _t->getFirstChild();
-
- auto_ptr<BaseGDL> r_guard;
-
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case CONSTANT:
- case DEREF:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case SYSVAR:
- case VAR:
- case VARPTR:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- e1=tmp_expr(_t);
- _t = _retTree;
-
- r_guard.reset( e1);
-
- break;
- }
- case FCALL_LIB:
- {
- e1=lib_function_call(_t);
- _t = _retTree;
-
- if( !callStack.back()->Contains( e1))
- r_guard.reset( e1);
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
- res=l_ret_expr(_t);
- _t = _retTree;
-
- if( e1 != (*res))
- {
- delete *res;
- *res = e1;
- }
- r_guard.release();
-
- _t = __t23;
- _t = _t->getNextSibling();
- break;
- }
- case ASSIGN_ARRAYEXPR_MFCALL:
- {
- ProgNodeP __t25 = _t;
- ProgNodeP tmp37_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
- _t = _t->getFirstChild();
-
- auto_ptr<BaseGDL> r_guard;
-
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case CONSTANT:
- case DEREF:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case SYSVAR:
- case VAR:
- case VARPTR:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- e1=tmp_expr(_t);
- _t = _retTree;
-
- r_guard.reset( e1);
-
- break;
- }
- case FCALL_LIB:
- {
- e1=lib_function_call(_t);
- _t = _retTree;
-
- if( !callStack.back()->Contains( e1))
- r_guard.reset( e1);
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
- res=l_arrayexpr_mfcall_as_mfcall(_t);
- _t = _retTree;
-
- if( e1 != (*res))
- {
- delete *res;
- *res = e1;
- }
- r_guard.release();
-
- _t = __t25;
- _t = _t->getNextSibling();
- break;
- }
- case ASSIGN_REPLACE:
- {
- ProgNodeP __t27 = _t;
- ProgNodeP tmp38_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN_REPLACE);
- _t = _t->getFirstChild();
-
- auto_ptr<BaseGDL> r_guard;
-
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case CONSTANT:
- case DEREF:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case SYSVAR:
- case VAR:
- case VARPTR:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- e1=tmp_expr(_t);
- _t = _retTree;
-
- r_guard.reset( e1);
-
- break;
- }
- case FCALL_LIB:
- {
- e1=lib_function_call(_t);
- _t = _retTree;
-
- if( !callStack.back()->Contains( e1))
- r_guard.reset( e1);
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
- res=l_ret_expr(_t);
- _t = _retTree;
-
- if( e1 != (*res))
- {
- delete *res;
- *res = e1;
- }
- r_guard.release();
-
- _t = __t27;
- _t = _t->getNextSibling();
- break;
- }
- case ARRAYEXPR:
- {
- ProgNodeP __t29 = _t;
- ProgNodeP tmp39_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYEXPR);
- _t = _t->getFirstChild();
-
- throw GDLException( _t,
- "Indexed expression not allowed as left-function"
- " return value.",true,false);
-
- _t = __t29;
- _t = _t->getNextSibling();
- break;
- }
- case DOT:
- {
- ProgNodeP __t30 = _t;
- ProgNodeP tmp40_AST_in = _t;
- match(antlr::RefAST(_t),DOT);
- _t = _t->getFirstChild();
-
- throw GDLException( _t,
- "Struct expression not allowed as left-function"
- " return value.",true,false);
-
- _t = __t30;
- _t = _t->getNextSibling();
- break;
- }
- case SYSVAR:
- {
- ProgNodeP tmp41_AST_in = _t;
- match(antlr::RefAST(_t),SYSVAR);
- _t = _t->getNextSibling();
-
- throw GDLException( _t,
- "System variable not allowed as left-function"
- " return value.",true,false);
-
- break;
- }
- case ARRAYDEF:
- case EXPR:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case DEC:
- case INC:
- {
- e1=r_expr(_t);
- _t = _retTree;
-
- delete e1;
- throw GDLException( _t,
- "Expression not allowed as left-function return value.",true,false);
-
- break;
- }
- case CONSTANT:
- {
- ProgNodeP tmp42_AST_in = _t;
- match(antlr::RefAST(_t),CONSTANT);
- _t = _t->getNextSibling();
-
- throw GDLException( _t,
- "Constant not allowed as left-function return value.",true,false);
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL* GDLInterpreter::expr(ProgNodeP _t) {
- BaseGDL* res;
- ProgNodeP expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- assert( _t != NULL);
-
- res = _t->Eval();
- _retTree = _t->getNextSibling();
- return res; //tmp_expr(_t);
-
- // if ( _t->getType() == FCALL_LIB)
- // {
- // BaseGDL* res=lib_function_call(_t);
- // if( callStack.back()->Contains( res))
- // res = res->Dup();
- // return res;
- // }
- // else
- // {
- // BaseGDL* res = _t->Eval();
- // _retTree = _t->getNextSibling();
- // return res; //tmp_expr(_t);
- // }
- // // finish
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case CONSTANT:
- case DEREF:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case SYSVAR:
- case VAR:
- case VARPTR:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- res=tmp_expr(_t);
- _t = _retTree;
- break;
- }
- case FCALL_LIB:
- {
- res=lib_function_call(_t);
- _t = _retTree;
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL** GDLInterpreter::l_arrayexpr_mfcall_as_mfcall(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP l_arrayexpr_mfcall_as_mfcall_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
-
- // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
- StackGuard<EnvStackT> guard(callStack);
- BaseGDL *self;
- EnvUDT* newEnv;
-
-
- ProgNodeP __t126 = _t;
- ProgNodeP tmp43_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYEXPR_MFCALL);
- _t = _t->getFirstChild();
-
- _t = _t->getNextSibling(); // skip DOT
-
- self=expr(_t);
- _t = _retTree;
- mp2 = _t;
- match(antlr::RefAST(_t),IDENTIFIER);
- _t = _t->getNextSibling();
-
- auto_ptr<BaseGDL> self_guard(self);
-
- newEnv=new EnvUDT( self, mp2, "", true);
-
- self_guard.release();
-
- parameter_def(_t, newEnv);
- _t = _retTree;
- _t = __t126;
- _t = _t->getNextSibling();
-
- // push environment onto call stack
- callStack.push_back(newEnv);
-
- // make the call
- res=call_lfun(static_cast<DSubUD*>(
- newEnv->GetPro())->GetTree());
-
- _retTree = _t;
- return res;
- }
- BaseGDL** GDLInterpreter::l_function_call(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP l_function_call_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- res = _t->LEval();
- _retTree = _t->getNextSibling();
- return res;
-
- BaseGDL *self;
- EnvUDT* newEnv;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case FCALL_LIB:
- {
- ProgNodeP __t128 = _t;
- ProgNodeP tmp44_AST_in = _t;
- match(antlr::RefAST(_t),FCALL_LIB);
- _t = _t->getFirstChild();
- parameter_def(_t, newEnv);
- _t = _retTree;
- _t = __t128;
- _t = _t->getNextSibling();
- break;
- }
- case FCALL:
- case MFCALL:
- case MFCALL_PARENT:
- {
- {
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case MFCALL:
- {
- ProgNodeP __t131 = _t;
- ProgNodeP tmp45_AST_in = _t;
- match(antlr::RefAST(_t),MFCALL);
- _t = _t->getFirstChild();
- self=expr(_t);
- _t = _retTree;
- ProgNodeP tmp46_AST_in = _t;
- match(antlr::RefAST(_t),IDENTIFIER);
- _t = _t->getNextSibling();
- parameter_def(_t, newEnv);
- _t = _retTree;
- _t = __t131;
- _t = _t->getNextSibling();
- break;
- }
- case MFCALL_PARENT:
- {
- ProgNodeP __t132 = _t;
- ProgNodeP tmp47_AST_in = _t;
- match(antlr::RefAST(_t),MFCALL_PARENT);
- _t = _t->getFirstChild();
- self=expr(_t);
- _t = _retTree;
- ProgNodeP tmp48_AST_in = _t;
- match(antlr::RefAST(_t),IDENTIFIER);
- _t = _t->getNextSibling();
- ProgNodeP tmp49_AST_in = _t;
- match(antlr::RefAST(_t),IDENTIFIER);
- _t = _t->getNextSibling();
- parameter_def(_t, newEnv);
- _t = _retTree;
- _t = __t132;
- _t = _t->getNextSibling();
- break;
- }
- case FCALL:
- {
- ProgNodeP __t133 = _t;
- ProgNodeP tmp50_AST_in = _t;
- match(antlr::RefAST(_t),FCALL);
- _t = _t->getFirstChild();
- parameter_def(_t, newEnv);
- _t = _retTree;
- _t = __t133;
- _t = _t->getNextSibling();
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
- }
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL* GDLInterpreter::tmp_expr(ProgNodeP _t) {
- BaseGDL* res;
- ProgNodeP tmp_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- ProgNodeP q = ProgNodeP(antlr::nullAST);
-
- res = _t->Eval();
- _retTree = _t->getNextSibling();
- return res;
-
- BaseGDL** e2;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case DEREF:
- {
- e2=l_deref(_t);
- _t = _retTree;
- break;
- }
- case QUESTION:
- {
- ProgNodeP __t90 = _t;
- q = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- match(antlr::RefAST(_t),QUESTION);
- _t = _t->getFirstChild();
- res=q->Eval();
- _t = __t90;
- _t = _t->getNextSibling();
- break;
- }
- case ARRAYEXPR:
- {
- {
- ProgNodeP tmp51_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYEXPR);
- _t = _t->getNextSibling();
- }
- break;
- }
- case DOT:
- {
- res=dot_expr(_t);
- _t = _retTree;
- break;
- }
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- {
- res=assign_expr(_t);
- _t = _retTree;
- break;
- }
- case ARRAYEXPR_MFCALL:
- case FCALL:
- case MFCALL:
- case MFCALL_PARENT:
- {
- res=unused_function_call(_t);
- _t = _retTree;
- break;
- }
- case ARRAYDEF:
- case EXPR:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case DEC:
- case INC:
- {
- res=r_expr(_t);
- _t = _retTree;
- break;
- }
- case CONSTANT:
- {
- res=constant(_t);
- _t = _retTree;
- break;
- }
- case VAR:
- case VARPTR:
- {
- res=simple_var(_t);
- _t = _retTree;
- break;
- }
- case SYSVAR:
- {
- res=sys_var(_t);
- _t = _retTree;
- break;
- }
- case FCALL_LIB_RETNEW:
- {
- res=lib_function_call_retnew(_t);
- _t = _retTree;
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL* GDLInterpreter::lib_function_call(ProgNodeP _t) {
- BaseGDL* res;
- ProgNodeP lib_function_call_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- assert( _t->getType() == FCALL_LIB);
- res = static_cast<FCALL_LIBNode*>(_t)->EvalFCALL_LIB();
- _retTree = _t->getNextSibling();
- return res;
-
- // // better than auto_ptr: auto_ptr wouldn't remove newEnv from the stack
- // StackGuard<EnvStackT> guard(callStack);
-
- // ProgNodeP rTree = _t->getNextSibling();
- // // match(antlr::RefAST(_t),FCALL_LIB);
-
- // ProgNodeP& fl = _t;
- // EnvT* newEnv=new EnvT( fl, fl->libFun);//libFunList[fl->funIx]);
-
- // parameter_def(_t->getFirstChild(), newEnv);
-
- // // push id.pro onto call stack
- // callStack.push_back(newEnv);
- // // make the call
-
- // res=static_cast<DLibFun*>(newEnv->GetPro())->Fun()(newEnv);
- // // *** MUST always return a defined expression
- // assert( res != NULL);
- // _retTree = rTree;
- // return res;
- EnvT* newEnv;
-
-
- ProgNodeP __t106 = _t;
- ProgNodeP tmp52_AST_in = _t;
- match(antlr::RefAST(_t),FCALL_LIB);
- _t = _t->getFirstChild();
- parameter_def(_t, newEnv);
- _t = _retTree;
- _t = __t106;
- _t = _t->getNextSibling();
- _retTree = _t;
- return res;
- }
- BaseGDL* GDLInterpreter::r_expr(ProgNodeP _t) {
- BaseGDL* res;
- ProgNodeP r_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- res=_t->Eval();
- _retTree = _t->getNextSibling();
- return res;
-
- // switch ( _t->getType()) {
- // case EXPR:
- // case ARRAYDEF:
- // case STRUC:
- // case NSTRUC:
- // case NSTRUC_REF:
- // {
- // res = _t->Eval();
- // break;
- // }
- // case DEC:
- // {
- // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), DEC);
- // break;
- // }
- // case INC:
- // {
- // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), INC);
- // break;
- // }
- // case POSTDEC:
- // {
- // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), POSTDEC);
- // break;
- // }
- // case POSTINC:
- // {
- // res=_t->Eval(); //l_decinc_expr( _t->getFirstChild(), POSTINC);
- // break;
- // }
- // // default:
- // // {
- // // throw antlr::NoViableAltException(antlr::RefAST(_t));
- // // }
- // }
- // _retTree = _t->getNextSibling();
- // return res;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case EXPR:
- {
- ProgNodeP tmp53_AST_in = _t;
- match(antlr::RefAST(_t),EXPR);
- _t = _t->getNextSibling();
- break;
- }
- case ARRAYDEF:
- {
- ProgNodeP tmp54_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYDEF);
- _t = _t->getNextSibling();
- break;
- }
- case STRUC:
- {
- ProgNodeP tmp55_AST_in = _t;
- match(antlr::RefAST(_t),STRUC);
- _t = _t->getNextSibling();
- break;
- }
- case NSTRUC:
- {
- ProgNodeP tmp56_AST_in = _t;
- match(antlr::RefAST(_t),NSTRUC);
- _t = _t->getNextSibling();
- break;
- }
- case NSTRUC_REF:
- {
- ProgNodeP tmp57_AST_in = _t;
- match(antlr::RefAST(_t),NSTRUC_REF);
- _t = _t->getNextSibling();
- break;
- }
- case DEC:
- {
- ProgNodeP __t68 = _t;
- ProgNodeP tmp58_AST_in = _t;
- match(antlr::RefAST(_t),DEC);
- _t = _t->getFirstChild();
- res=l_decinc_expr(_t, DEC);
- _t = _retTree;
- _t = __t68;
- _t = _t->getNextSibling();
- break;
- }
- case INC:
- {
- ProgNodeP __t69 = _t;
- ProgNodeP tmp59_AST_in = _t;
- match(antlr::RefAST(_t),INC);
- _t = _t->getFirstChild();
- res=l_decinc_expr(_t, INC);
- _t = _retTree;
- _t = __t69;
- _t = _t->getNextSibling();
- break;
- }
- case POSTDEC:
- {
- ProgNodeP __t70 = _t;
- ProgNodeP tmp60_AST_in = _t;
- match(antlr::RefAST(_t),POSTDEC);
- _t = _t->getFirstChild();
- res=l_decinc_expr(_t, POSTDEC);
- _t = _retTree;
- _t = __t70;
- _t = _t->getNextSibling();
- break;
- }
- case POSTINC:
- {
- ProgNodeP __t71 = _t;
- ProgNodeP tmp61_AST_in = _t;
- match(antlr::RefAST(_t),POSTINC);
- _t = _t->getFirstChild();
- res=l_decinc_expr(_t, POSTINC);
- _t = _retTree;
- _t = __t71;
- _t = _t->getNextSibling();
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL* GDLInterpreter::l_decinc_indexable_expr(ProgNodeP _t,
- int dec_inc
- ) {
- BaseGDL* res;
- ProgNodeP l_decinc_indexable_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- BaseGDL** e;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case FCALL:
- case FCALL_LIB:
- case MFCALL:
- case MFCALL_PARENT:
- {
- e=l_function_call(_t);
- _t = _retTree;
-
- res = *e;
- if( res == NULL)
- throw GDLException( _t, "Variable is undefined: "+Name(e),true,false);
-
- break;
- }
- case DEREF:
- {
- e=l_deref(_t);
- _t = _retTree;
-
- res = *e;
- if( res == NULL)
- throw GDLException( _t, "Variable is undefined: "+Name(e),true,false);
-
- break;
- }
- case VAR:
- case VARPTR:
- {
- e=l_defined_simple_var(_t);
- _t = _retTree;
- res = *e;
- break;
- }
- case SYSVAR:
- {
- e=l_sys_var(_t);
- _t = _retTree;
- res = *e;
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL** GDLInterpreter::l_defined_simple_var(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP l_defined_simple_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- assert( _t != NULL);
- res = _t->LEval();
- _retTree = _t->getNextSibling();
- if( *res == NULL)
- {
- if( _t->getType() == VAR)
- throw GDLException( _t, "Variable is undefined: "+
- callStack.back()->GetString(_t->varIx),true,false);
- else
- throw GDLException( _t, "Common block variable is undefined: "+
- callStack.back()->GetString( *res),true,false);
- }
- return res;
-
- // if( _t->getType() == VAR)
- // {
- // res=&callStack.back()->GetKW(_t->varIx);
- // if( *res == NULL)
- // throw GDLException( _t, "Variable is undefined: "+
- // callStack.back()->GetString(_t->varIx),true,false);
-
- // }
- // else
- // {
- // res=&_t->var->Data(); // returns BaseGDL* of var (DVar*)
- // if( *res == NULL)
- // throw GDLException( _t, "Variable is undefined: "+
- // callStack.back()->GetString( *res),true,false);
-
- // }
- // _retTree = _t->getNextSibling();
- // return res;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case VAR:
- {
- ProgNodeP tmp62_AST_in = _t;
- match(antlr::RefAST(_t),VAR);
- _t = _t->getNextSibling();
- break;
- }
- case VARPTR:
- {
- ProgNodeP tmp63_AST_in = _t;
- match(antlr::RefAST(_t),VARPTR);
- _t = _t->getNextSibling();
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- BaseGDL** GDLInterpreter::l_sys_var(ProgNodeP _t) {
- BaseGDL** res;
- ProgNodeP l_sys_var_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- ProgNodeP sysVar = ProgNodeP(antlr::nullAST);
-
- sysVar = _t;
- match(antlr::RefAST(_t),SYSVAR);
- _t = _t->getNextSibling();
-
- res=sysVar->LEval();
- _retTree = sysVar->getNextSibling();
-
- _retTree = _t;
- return res;
- }
- BaseGDL* GDLInterpreter::l_decinc_array_expr(ProgNodeP _t,
- int dec_inc
- ) {
- BaseGDL* res;
- ProgNodeP l_decinc_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- ArrayIndexListT* aL;
- BaseGDL* e;
- ArrayIndexListGuard guard;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ARRAYEXPR:
- {
- ProgNodeP __t33 = _t;
- ProgNodeP tmp64_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYEXPR);
- _t = _t->getFirstChild();
- e=l_decinc_indexable_expr(_t, dec_inc);
- _t = _retTree;
- aL=arrayindex_list(_t);
- _t = _retTree;
- _t = __t33;
- _t = _t->getNextSibling();
-
- guard.reset( aL);
- aL->SetVariable( e);
-
- if( dec_inc == DECSTATEMENT)
- {
- e->DecAt( aL);
- res = NULL;
- break;
- }
- if( dec_inc == INCSTATEMENT)
- {
- e->IncAt( aL);
- res = NULL;
- break;
- }
-
- if( dec_inc == DEC) e->DecAt( aL);
- else if( dec_inc == INC) e->IncAt( aL);
- //
- res=e->Index( aL);
-
- if( dec_inc == POSTDEC) e->DecAt( aL);
- else if( dec_inc == POSTINC) e->IncAt( aL);
-
- break;
- }
- case DEREF:
- case FCALL:
- case FCALL_LIB:
- case MFCALL:
- case MFCALL_PARENT:
- case SYSVAR:
- case VAR:
- case VARPTR:
- {
- e=l_decinc_indexable_expr(_t, dec_inc);
- _t = _retTree;
-
- if( dec_inc == DECSTATEMENT)
- {
- e->Dec();
- res = NULL;
- break;
- }
- if( dec_inc == INCSTATEMENT)
- {
- e->Inc();
- res = NULL;
- break;
- }
-
- if( dec_inc == DEC) e->Dec();
- else if( dec_inc == INC) e->Inc();
- //
- res = e->Dup();
-
- if( dec_inc == POSTDEC) e->Dec();
- else if( dec_inc == POSTINC) e->Inc();
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- return res;
- }
- ArrayIndexListT* GDLInterpreter::arrayindex_list(ProgNodeP _t) {
- ArrayIndexListT* aL;
- ProgNodeP arrayindex_list_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- IxExprListT cleanupList; // for cleanup
- IxExprListT ixExprList;
- SizeT nExpr;
- BaseGDL* s;
-
- // ProgNodeP retTree = _t->getNextSibling();
- ProgNodeP ax = _t;
- // match(antlr::RefAST(_t),ARRAYIX);
- _t = _t->getFirstChild();
-
- aL = ax->arrIxList;
- assert( aL != NULL);
-
- nExpr = aL->NParam();
- if( nExpr == 0)
- {
- aL->Init();
- _retTree = ax->getNextSibling();//retTree;
- return aL;
- }
-
- while( true) {
- assert( _t != NULL);
- if( NonCopyNode( _t->getType()))
- {
- s= _t->EvalNC(); //indexable_expr(_t);
- //_t = _retTree;
- }
- else if( _t->getType() == GDLTokenTypes::FCALL_LIB)
- {
- s=lib_function_call(_t);
- //_t = _retTree;
- if( !callStack.back()->Contains( s))
- cleanupList.push_back( s);
- }
- else
- {
- s=_t->Eval(); //indexable_tmp_expr(_t);
- //_t = _retTree;
- cleanupList.push_back( s);
- }
-
- ixExprList.push_back( s);
- if( ixExprList.size() == nExpr)
- break; // allows some manual tuning
-
- _t = _t->getNextSibling();
- }
-
- aL->Init( ixExprList, &cleanupList);
-
- _retTree = ax->getNextSibling();//retTree;
- return aL;
-
-
- ProgNodeP __t143 = _t;
- ProgNodeP tmp65_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYIX);
- _t = _t->getFirstChild();
- { // ( ... )*
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_tokenSet_1.member(_t->getType()))) {
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case CONSTANT:
- case DEREF:
- case SYSVAR:
- case VAR:
- case VARPTR:
- {
- s=indexable_expr(_t);
- _t = _retTree;
- break;
- }
- case FCALL_LIB:
- {
- s=lib_function_call(_t);
- _t = _retTree;
- break;
- }
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- s=indexable_tmp_expr(_t);
- _t = _retTree;
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
- }
- else {
- goto _loop146;
- }
-
- }
- _loop146:;
- } // ( ... )*
- _t = __t143;
- _t = _t->getNextSibling();
- _retTree = _t;
- return aL;
- }
- BaseGDL* GDLInterpreter::l_decinc_dot_expr(ProgNodeP _t,
- int dec_inc
- ) {
- BaseGDL* res;
- ProgNodeP l_decinc_dot_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- ProgNodeP dot = ProgNodeP(antlr::nullAST);
-
- ProgNodeP __t35 = _t;
- dot = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- match(antlr::RefAST(_t),DOT);
- _t = _t->getFirstChild();
-
- SizeT nDot=dot->nDot;
- auto_ptr<DotAccessDescT> aD( new DotAccessDescT(nDot+1));
-
- l_dot_array_expr(_t, aD.get());
- _t = _retTree;
- { // ( ... )+
- int _cnt37=0;
- for (;;) {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- if ((_t->getType() == ARRAYEXPR || _t->getType() == EXPR || _t->getType() == IDENTIFIER)) {
- tag_array_expr(_t, aD.get());
- _t = _retTree;
- }
- else {
- if ( _cnt37>=1 ) { goto _loop37; } else {throw antlr::NoViableAltException(antlr::RefAST(_t));}
- }
-
- _cnt37++;
- }
- _loop37:;
- } // ( ... )+
- _t = __t35;
- _t = _t->getNextSibling();
-
- if( dec_inc == DECSTATEMENT)
- {
- aD->Dec();
- res = NULL;
- }
- else if( dec_inc == INCSTATEMENT)
- {
- aD->Inc();
- res = NULL;
- }
- else
- {
- if( dec_inc == DEC) aD->Dec(); //*** aD->Assign( dec_inc);
- else if( dec_inc == INC) aD->Inc();
- //
- res=aD->Resolve();
-
- if( dec_inc == POSTDEC) aD->Dec();
- else if( dec_inc == POSTINC) aD->Inc();
- }
-
- _retTree = _t;
- return res;
- }
- void GDLInterpreter::l_dot_array_expr(ProgNodeP _t,
- DotAccessDescT* aD
- ) {
- ProgNodeP l_dot_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- ArrayIndexListT* aL;
- BaseGDL** rP;
- DStructGDL* structR;
- ArrayIndexListGuard guard;
-
- if( _t->getType() == ARRAYEXPR)
- {
- rP=l_indexable_expr(_t->getFirstChild());
- aL=arrayindex_list(_retTree);
- guard.reset(aL);
-
- _retTree = _t->getNextSibling();
-
- // check here for object and get struct
- structR=dynamic_cast<DStructGDL*>(*rP);
- if( structR == NULL)
- {
- bool isObj = callStack.back()->IsObject();
- if( isObj)
- {
- DStructGDL* oStruct = ObjectStructCheckAccess( *rP, _t);
- // oStruct cannot be "Assoc_"
- aD->Root( oStruct, guard.release());
- }
- else
- {
- throw GDLException( _t, "Expression must be a"
- " STRUCT in this context: "+Name(*rP),
- true,false);
- }
- }
- else
- {
- if( (*rP)->IsAssoc())
- throw GDLException( _t, "File expression not allowed "
- "in this context: "+Name(*rP),true,false);
- aD->Root( structR, guard.release() /* aL */);
- }
- }
- else
- // case ARRAYEXPR_MFCALL:
- // case DEREF:
- // case EXPR:
- // case FCALL:
- // case FCALL_LIB:
- // case MFCALL:
- // case MFCALL_PARENT:
- // case SYSVAR:
- // case VAR:
- // case VARPTR:
- {
- rP=l_indexable_expr(_t);
- //_t = _retTree; _retTree set ok
-
- // check here for object and get struct
- structR = dynamic_cast<DStructGDL*>(*rP);
- if( structR == NULL)
- {
- bool isObj = callStack.back()->IsObject();
- if( isObj) // member access to object?
- {
- DStructGDL* oStruct = ObjectStructCheckAccess( *rP, _t);
- // oStruct cannot be "Assoc_"
- aD->Root( oStruct);
- }
- else
- {
- throw GDLException( _t, "Expression must be a"
- " STRUCT in this context: "+Name(*rP),
- true,false);
- }
- }
- else
- {
- if( (*rP)->IsAssoc())
- {
- throw GDLException( _t, "File expression not allowed "
- "in this context: "+Name(*rP),true,false);
- }
- aD->Root(structR);
- }
- }
- // _retTree = _t;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ARRAYEXPR:
- {
- ProgNodeP __t52 = _t;
- ProgNodeP tmp66_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYEXPR);
- _t = _t->getFirstChild();
- rP=l_indexable_expr(_t);
- _t = _retTree;
- aL=arrayindex_list(_t);
- _t = _retTree;
- _t = __t52;
- _t = _t->getNextSibling();
- break;
- }
- case ARRAYEXPR_MFCALL:
- case DEREF:
- case EXPR:
- case FCALL:
- case FCALL_LIB:
- case MFCALL:
- case MFCALL_PARENT:
- case SYSVAR:
- case VAR:
- case VARPTR:
- {
- rP=l_indexable_expr(_t);
- _t = _retTree;
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- }
- void GDLInterpreter::tag_array_expr(ProgNodeP _t,
- DotAccessDescT* aD
- ) {
- ProgNodeP tag_array_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
-
- ArrayIndexListT* aL;
-
- if( _t->getType() == ARRAYEXPR)
- {
- ProgNodeP tIn = _t;
- _t = _t->getFirstChild();
- tag_expr(_t, aD);
- _t = _retTree;
- aL=arrayindex_list(_t);
- _t = _retTree;
- aD->AddIx(aL);
- _retTree = tIn->getNextSibling();
- }
- else
- // case EXPR:
- // case IDENTIFIER:
- {
- tag_expr(_t, aD);
- //_t = _retTree;
- aD->AddIx(NULL);
- }
- //_retTree = _t;
- return;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case ARRAYEXPR:
- {
- ProgNodeP __t75 = _t;
- ProgNodeP tmp67_AST_in = _t;
- match(antlr::RefAST(_t),ARRAYEXPR);
- _t = _t->getFirstChild();
- tag_expr(_t, aD);
- _t = _retTree;
- aL=arrayindex_list(_t);
- _t = _retTree;
- aD->AddIx(aL);
- _t = __t75;
- _t = _t->getNextSibling();
- break;
- }
- case EXPR:
- case IDENTIFIER:
- {
- tag_expr(_t, aD);
- _t = _retTree;
- aD->AddIx(NULL);
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- _retTree = _t;
- }
- BaseGDL* GDLInterpreter::l_decinc_expr(ProgNodeP _t,
- int dec_inc
- ) {
- BaseGDL* res;
- ProgNodeP l_decinc_expr_AST_in = (_t == ProgNodeP(ASTNULL)) ? ProgNodeP(antlr::nullAST) : _t;
- ProgNodeP mp2 = ProgNodeP(antlr::nullAST);
-
- BaseGDL* e1;
- ProgNodeP startNode = _t;
-
-
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case QUESTION:
- {
- ProgNodeP __t39 = _t;
- ProgNodeP tmp68_AST_in = _t;
- match(antlr::RefAST(_t),QUESTION);
- _t = _t->getFirstChild();
- e1=expr(_t);
- _t = _retTree;
-
- auto_ptr<BaseGDL> e1_guard(e1);
-
- if( e1->True())
- {
- res=l_decinc_expr(_t, dec_inc);
- }
- else
- {
- _t=_t->GetNextSibling(); // jump over 1st expression
- res=l_decinc_expr(_t, dec_inc);
- }
-
- _t = __t39;
- _t = _t->getNextSibling();
- break;
- }
- case ASSIGN:
- {
- ProgNodeP __t40 = _t;
- ProgNodeP tmp69_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN);
- _t = _t->getFirstChild();
-
- auto_ptr<BaseGDL> r_guard;
-
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case CONSTANT:
- case DEREF:
- case SYSVAR:
- case VAR:
- case VARPTR:
- {
- e1=indexable_expr(_t);
- _t = _retTree;
- break;
- }
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- e1=indexable_tmp_expr(_t);
- _t = _retTree;
- r_guard.reset( e1);
- break;
- }
- case FCALL_LIB:
- {
- e1=lib_function_call(_t);
- _t = _retTree;
-
- if( !callStack.back()->Contains( e1))
- r_guard.reset( e1); // guard if no global data
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
-
- ProgNodeP l = _t;
-
- BaseGDL** tmp;
-
- tmp=l_expr(_t, e1);
- _t = _retTree;
-
- _t = l;
-
- res=l_decinc_expr(_t, dec_inc);
- _t = _retTree;
- _t = __t40;
- _t = _t->getNextSibling();
- break;
- }
- case ASSIGN_ARRAYEXPR_MFCALL:
- {
- ProgNodeP __t42 = _t;
- ProgNodeP tmp70_AST_in = _t;
- match(antlr::RefAST(_t),ASSIGN_ARRAYEXPR_MFCALL);
- _t = _t->getFirstChild();
-
- auto_ptr<BaseGDL> r_guard;
-
- {
- if (_t == ProgNodeP(antlr::nullAST) )
- _t = ASTNULL;
- switch ( _t->getType()) {
- case CONSTANT:
- case DEREF:
- case SYSVAR:
- case VAR:
- case VARPTR:
- {
- e1=indexable_expr(_t);
- _t = _retTree;
- break;
- }
- case ASSIGN:
- case ASSIGN_REPLACE:
- case ASSIGN_ARRAYEXPR_MFCALL:
- case ARRAYDEF:
- case ARRAYEXPR:
- case ARRAYEXPR_MFCALL:
- case EXPR:
- case FCALL:
- case FCALL_LIB_RETNEW:
- case MFCALL:
- case MFCALL_PARENT:
- case NSTRUC:
- case NSTRUC_REF:
- case POSTDEC:
- case POSTINC:
- case STRUC:
- case DEC:
- case INC:
- case DOT:
- case QUESTION:
- {
- e1=indexable_tmp_expr(_t);
- _t = _retTree;
- r_guard.reset( e1);
- break;
- }
- case FCALL_LIB:
- {
- e1=lib_function_call(_t);
- _t = _retTree;
-
- if( !callStack.back()->Contains( e1))
- r_guard.reset( e1); // guard if no global data
-
- break;
- }
- default:
- {
- throw antlr::NoViableAltException(antlr::RefAST(_t));
- }
- }
- }
-
- ProgNodeP l = _t;
-
- BaseGDL** tmp;
-
- // try M…