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

skInterpreterp.h

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

Generated at Mon Nov 5 19:22:25 2001 for Simkin by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000