Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

skInterpreterp.h

00001 /*
00002         Interpreter implementation class
00003         $Id: skInterpreterp.h,v 1.32 2002/12/13 17:21:54 sdw Exp $
00004         Copyright 1996-2002
00005         Simon Whiteside
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 */
00022 
00023 #include "skParseNode.h"
00024 #include "skExecutableIterator.h"
00025 #include "skRValueTable.h"
00026 
00030 class P_Interpreter 
00031 {   
00032  public:
00034   P_Interpreter(skInterpreter * owner);
00036   ~P_Interpreter();
00037                                                 
00038 
00039     // Expression evaluation
00040   
00047   skRValue evaluate(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skExprNode * n);
00054   skRValue evalMethod(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skIdListNode * ids);
00065   void makeMethodCall(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00066   
00067     // Statement execution
00068 
00075   void executeAssignStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skAssignNode * n);
00076   
00077     // the statements below return true to halt further processing (i.e. a return statement has been encountered)
00078 
00087   bool executeStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skStatNode * pstat,skRValue& r);
00088 
00097   bool executeStats(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skStatListNode * n,skRValue& r);
00098 
00107   bool executeReturnStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skReturnNode * n,skRValue& r);
00108 
00117   bool executeIfStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skIfNode * n,skRValue& r);
00118 
00127   bool executeWhileStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skWhileNode * n,skRValue& r);
00128 
00137   bool executeSwitchStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skSwitchNode * n,skRValue& r);
00138 
00147   bool executeForEachStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skForEachNode * n,skRValue& r);
00148 
00157   bool executeForStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skForNode * n,skRValue& r);
00158 
00159   // Misc runtime routines
00160 
00166     void addLocalVariable(skRValueTable& var,const skString& name,skRValue value); 
00173     skString checkIndirectId(skContext& ctxt,skiExecutable * obj,skRValueTable& var,const skString& name); 
00183   skRValue findValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,const skString& name,skExprNode * array_index,const skString& attribute); 
00189   void runtimeError(skContext& ctxt,const skString& s); 
00197   void followIdList(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skIdListNode * idList,skRValue& object); 
00198 
00202   void trace(const skString& s);
00203 
00214   bool extractFieldArrayValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00224   bool extractArrayValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00232   bool extractValue(skContext& ctxt,skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00233 
00242   bool insertArrayValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00250   bool insertValue(skContext& ctxt,skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00251 
00252   // Variables
00254   skRValueTable m_GlobalVars; 
00256   bool m_Tracing; 
00258   skTraceCallback * m_TraceCallback; 
00260   skStatementStepper * m_StatementStepper; // the statement stepper
00261   skInterpreter * pown;
00262 };    
00263 
00264 //---------------------------------------------------
00265 inline skString P_Interpreter::checkIndirectId(skContext& ctxt,skiExecutable * obj,skRValueTable& var,const skString& name)
00266 //---------------------------------------------------
00267 {
00268   // look for an initial "@" in a field name, and de-reference it if necessary
00269   skString ret=name;
00270   if (name.at(0)=='@'){
00271     ret=name.substr(1,name.length()-1);
00272     skRValue new_name=findValue(ctxt,obj,var,ret,0,skString());
00273     ret=new_name.str();
00274   }
00275   return ret;
00276 }       

Generated on Mon Dec 16 16:30:12 2002 for Simkin by doxygen1.3-rc1