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
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
00026
00027 void executeAssignStat(skExecutable * obj,skRValueTable& var,skAssignNode * n);
00028
00029
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
00041
00042 void addLocalVariable(skRValueTable& var,const skString& name,skRValue value);
00043 skString checkIndirectId(skExecutable * obj,skRValueTable& var,const skString& name);
00044
00045 skRValue findValue(skExecutable * obj,skRValueTable& var,const skString& name,skExprNode * array_index,const skString& attribute);
00046 void runtimeError(const skString& s);
00047 void followIdList(skExecutable * obj,skRValueTable& var,skIdListNode * idList,skRValue& object);
00048 void trace(const skString& s);
00049
00050
00051 bool extractFieldArrayValue(skExecutable * obj,skRValueTable& var,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00052
00053 bool extractArrayValue(skExecutable * obj,skRValueTable& var,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00054
00055 bool extractValue(skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00056
00057
00058 bool insertArrayValue(skExecutable * obj,skRValueTable& var,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00059
00060 bool insertValue(skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00061
00062
00063 skRValueTable m_GlobalVars;
00064 unsigned int m_StackDepth;
00065 bool m_Tracing;
00066
00067 skTraceCallback * m_TraceCallback;
00068 skStatementStepper * m_StatementStepper;
00069 skString m_Location;
00070 int m_LineNum;
00071 THREAD static skInterpreter * g_GlobalInterpreter;
00072
00073 };
00074
00075
00076 inline skString P_Interpreter::checkIndirectId(skExecutable * obj,skRValueTable& var,const skString& name)
00077
00078 {
00079
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 }