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

skInterpreterp.h

00001 /*
00002         Interpreter implementation class
00003         $Id: skInterpreterp_8h-source.html,v 1.5 2003/01/23 15:31:03 simkin_cvs Exp $
00004         Copyright 1996-2003
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   
00045   skRValue evaluate(skStackFrame& frame,skExprNode * n);
00050   skRValue evalMethod(skStackFrame& frame,skIdListNode * ids);
00060   void makeMethodCall(skStackFrame& frame,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00061   
00062     // Statement execution
00063 
00068   void executeAssignStat(skStackFrame& frame,skAssignNode * n);
00069   
00070     // the statements below return true to halt further processing (i.e. a return statement has been encountered)
00071 
00078   bool executeStat(skStackFrame& frame,skStatNode * pstat,skRValue& r);
00079 
00086   bool executeStats(skStackFrame& frame,skStatListNode * n,skRValue& r);
00087 
00094   bool executeReturnStat(skStackFrame& frame,skReturnNode * n,skRValue& r);
00095 
00102   bool executeIfStat(skStackFrame& frame,skIfNode * n,skRValue& r);
00103 
00110   bool executeWhileStat(skStackFrame& frame,skWhileNode * n,skRValue& r);
00111 
00118   bool executeSwitchStat(skStackFrame& frame,skSwitchNode * n,skRValue& r);
00119 
00126   bool executeForEachStat(skStackFrame& frame,skForEachNode * n,skRValue& r);
00127 
00134   bool executeForStat(skStackFrame& frame,skForNode * n,skRValue& r);
00135 
00136   // Misc runtime routines
00137 
00143     void addLocalVariable(skRValueTable& var,const skString& name,skRValue value); 
00150     skString checkIndirectId(skStackFrame& frame,const skString& name); 
00158   skRValue findValue(skStackFrame& frame,const skString& name,skExprNode * array_index,const skString& attribute); 
00164   void runtimeError(skStackFrame& frame,const skString& s); 
00170   void followIdList(skStackFrame& frame,skIdListNode * idList,skRValue& object); 
00171 
00175   void trace(const skString& s);
00176 
00185   bool extractFieldArrayValue(skStackFrame& frame,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00193   bool extractArrayValue(skStackFrame& frame,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00201   bool extractValue(skStackFrame& frame,skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00202 
00210   bool insertArrayValue(skStackFrame& frame,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00218   bool insertValue(skStackFrame& frame,skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00219 
00220   // Variables
00222   skRValueTable m_GlobalVars; 
00224   bool m_Tracing; 
00226   skTraceCallback * m_TraceCallback; 
00228   skStatementStepper * m_StatementStepper; // the statement stepper
00229   skInterpreter * pown;
00230 };    
00231 
00232 //---------------------------------------------------
00233 inline skString P_Interpreter::checkIndirectId(skStackFrame& frame,const skString& name)
00234 //---------------------------------------------------
00235 {
00236   // look for an initial "@" in a field name, and de-reference it if necessary
00237   skString ret=name;
00238   if (name.at(0)=='@'){
00239     ret=name.substr(1,name.length()-1);
00240     skRValue new_name=findValue(frame,ret,0,skString());
00241     ret=new_name.str();
00242   }
00243   return ret;
00244 }       

Generated on Thu Jan 23 15:25:38 2003 for Simkin by doxygen1.3-rc1