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

skInterpreterp.h

00001 
00008 #include "skParseNode.h"
00009 
00010 #include "skHashTable.h"
00011 #include "skExecutableIterator.h"
00012 
00013 class skRValueTable: public skTHashTable<skString,skRValue>
00014 {
00015  public:
00016     skRValueTable(unsigned short  size);
00017     skRValueTable();
00018     ~skRValueTable();
00019 
00020 };
00021 
00022 const unsigned int MAX_LOCAL_VARS_CACHE=5;
00023 
00024 
00025 class P_Interpreter 
00026 {   
00027  public:
00028     P_Interpreter();
00029     ~P_Interpreter();
00030                                                 
00031 
00032     // Expression evaluation
00033   
00034     skRValue evaluate(skExecutable * obj,skRValueTable& var,skExprNode * n);
00035     skRValue evalMethod(skExecutable * obj,skRValueTable& var,skIdListNode * ids);
00036     void makeMethodCall(skExecutable * obj,skRValueTable& var,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00037 
00038     // Statement execution
00039 
00040     void executeAssignStat(skExecutable * obj,skRValueTable& var,skAssignNode * n);
00041 
00042     // the statements below return true to halt further processing (i.e. a return statement has been encountered)
00043 
00044     bool executeStat(skExecutable * obj,skRValueTable& var,skStatNode * pstat,skRValue& r);
00045     bool executeStats(skExecutable * obj,skRValueTable& var,skStatListNode * n,skRValue& r);
00046     bool executeReturnStat(skExecutable * obj,skRValueTable& var,skReturnNode * n,skRValue& r);
00047     bool executeIfStat(skExecutable * obj,skRValueTable& var,skIfNode * n,skRValue& r);
00048     bool executeWhileStat(skExecutable * obj,skRValueTable& var,skWhileNode * n,skRValue& r);
00049     bool executeSwitchStat(skExecutable * obj,skRValueTable& var,skSwitchNode * n,skRValue& r);
00050     bool executeForEachStat(skExecutable * obj,skRValueTable& var,skForEachNode * n,skRValue& r);
00051 
00052     // Misc runtime routines
00053 
00054     void addLocalVariable(skRValueTable& var,const skString& name,skRValue value); // adds a local variable to the current list
00055     skString checkIndirectId(skExecutable * obj,skRValueTable& var,const skString& name); // checks whether a field name includes the indirection character
00056     // tries to find a the value of the named variable
00057     skRValue findValue(skExecutable * obj,skRValueTable& var,const skString& name,skExprNode * array_index,const skString& attribute); 
00058     void runtimeError(const skString& s); // creates and throws a skRuntimeException
00059     void followIdList(skExecutable * obj,skRValueTable& var,skIdListNode * idList,skRValue& object); // follows a dotted list of id's
00060 
00061     // extracts a value of the form foo[1] - first dereferencing foo
00062     bool extractFieldArrayValue(skExecutable * obj,skRValueTable& var,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00063     // extracts a value of the form robject[1] - assumes robject is already a collection object
00064     bool extractArrayValue(skExecutable * obj,skRValueTable& var,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00065     // extracts an instance variable with the given name
00066     bool extractValue(skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00067     
00068     // wrapper around setValueAt
00069     bool insertArrayValue(skExecutable * obj,skRValueTable& var,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00070     // wrapper around setValue
00071     bool insertValue(skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00072 
00073     // Variables
00074     skRValueTable m_GlobalVars; // the global variables
00075     skRValueTable m_LocalVars[MAX_LOCAL_VARS_CACHE]; // a pool of local variable tables
00076     unsigned int m_StackDepth; // the current stack depth
00077     bool m_Tracing; // flag for tracing method calls
00078 
00079     skString m_Location; // location during script execution
00080     int m_LineNum; // line number during script execution
00081     THREAD static skInterpreter * g_GlobalInterpreter;  //      used by clients - one per thread (on Windows only at the moment)
00082 
00083 };    
00084 
00085 //---------------------------------------------------
00086 inline skString P_Interpreter::checkIndirectId(skExecutable * obj,skRValueTable& var,const skString& name)
00087 //---------------------------------------------------
00088 {
00089   // look for an initial "@" in a field name, and de-reference it if necessary
00090     skString ret=name;
00091     if (name.at(0)=='@'){
00092         ret=name.substr(1,name.length()-1);
00093         skRValue new_name=findValue(obj,var,ret,0,skString());
00094         ret=new_name.str();
00095     }
00096     return ret;
00097 }       

Generated at Fri Jun 22 11:10:42 2001 for Simkin by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000