00001
00002
00003
00004
00005
00006
00007
00008 #include "skParseNode.h"
00009 #include "skExecutableIterator.h"
00010 #include "skRValueTable.h"
00011
00015 class P_Interpreter
00016 {
00017 public:
00019 P_Interpreter();
00021 ~P_Interpreter();
00022
00023
00024
00025
00032 skRValue evaluate(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skExprNode * n);
00039 skRValue evalMethod(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skIdListNode * ids);
00050 void makeMethodCall(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00051
00052
00053
00060 void executeAssignStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skAssignNode * n);
00061
00062
00063
00072 bool executeStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skStatNode * pstat,skRValue& r);
00073
00082 bool executeStats(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skStatListNode * n,skRValue& r);
00083
00092 bool executeReturnStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skReturnNode * n,skRValue& r);
00093
00102 bool executeIfStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skIfNode * n,skRValue& r);
00103
00112 bool executeWhileStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skWhileNode * n,skRValue& r);
00113
00122 bool executeSwitchStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skSwitchNode * n,skRValue& r);
00123
00132 bool executeForEachStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skForEachNode * n,skRValue& r);
00133
00142 bool executeForStat(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skForNode * n,skRValue& r);
00143
00144
00145
00151 void addLocalVariable(skRValueTable& var,const skString& name,skRValue value);
00158 skString checkIndirectId(skContext& ctxt,skiExecutable * obj,skRValueTable& var,const skString& name);
00168 skRValue findValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,const skString& name,skExprNode * array_index,const skString& attribute);
00174 void runtimeError(skContext& ctxt,const skString& s);
00182 void followIdList(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skIdListNode * idList,skRValue& object);
00183
00187 void trace(const skString& s);
00188
00199 bool extractFieldArrayValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00209 bool extractArrayValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00217 bool extractValue(skContext& ctxt,skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00218
00227 bool insertArrayValue(skContext& ctxt,skiExecutable * obj,skRValueTable& var,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00235 bool insertValue(skContext& ctxt,skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00236
00237
00239 skRValueTable m_GlobalVars;
00241 bool m_Tracing;
00243 skTraceCallback * m_TraceCallback;
00245 skStatementStepper * m_StatementStepper;
00247 THREAD static skInterpreter * g_GlobalInterpreter;
00248
00249 };
00250
00251
00252 inline skString P_Interpreter::checkIndirectId(skContext& ctxt,skiExecutable * obj,skRValueTable& var,const skString& name)
00253
00254 {
00255
00256 skString ret=name;
00257 if (name.at(0)=='@'){
00258 ret=name.substr(1,name.length()-1);
00259 skRValue new_name=findValue(ctxt,obj,var,ret,0,skString());
00260 ret=new_name.str();
00261 }
00262 return ret;
00263 }