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

skInterpreterp.h

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

Generated at Thu Jul 5 10:55:42 2001 for Simkin by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000