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

skInterpreter.h

00001 /*
00002   Copyright 1996-2003
00003   Simon Whiteside
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 * $Id: skInterpreter_8h-source.html,v 1.4 2003/05/27 17:41:57 simkin_cvs Exp $
00020 */
00021 #ifndef skINTERPRETER_H
00022 #define skINTERPRETER_H
00023 
00024 #include "skRValueTable.h"
00025 #include "skiExecutable.h"
00026 #include "skNull.h"
00027 #include "skParseNode.h"
00028 #include "skExecutableIterator.h"
00029 #include "skRValueTable.h"
00030 
00031 class CLASSEXPORT skRValueArray;
00032 class CLASSEXPORT skExprNode;
00033 class CLASSEXPORT skStringList;
00034 class CLASSEXPORT skMethodDefNode;
00035 class CLASSEXPORT skTraceCallback;
00036 class CLASSEXPORT skStatementStepper;
00037 
00038 #ifndef EXCEPTIONS_DEFINED
00039 #include "skScriptError.h"
00040 #endif
00041 
00042 class CLASSEXPORT skStackFrame;
00043 
00051 class CLASSEXPORT skInterpreter : public skExecutable
00052 { 
00053  public:
00054   //------------------------
00055   // Parsing and Executing methods
00056   //------------------------
00057 
00069   IMPORT_C skMethodDefNode * parseString(const skString& location,const skString& code,skExecutableContext& ctxt);       
00082   IMPORT_C skMethodDefNode * parseExternalParams(const skString& location,skStringList& paramNames,const skString& code,skExecutableContext& ctxt);
00097   IMPORT_C void executeString(const skString& location,skiExecutable * obj,const skString& code,skRValueArray&  args,skRValue& return_value,skMethodDefNode ** parseTree,skExecutableContext& ctxt);
00098 
00113   IMPORT_C void executeStringExternalParams(const skString& location,skiExecutable * obj,skStringList& paramNames,const skString& code,skRValueArray&  args,skRValue& r,skMethodDefNode ** keepParseTree,skExecutableContext& ctxt);
00114 
00126   IMPORT_C void executeParseTree(const skString& location,skiExecutable * obj,skMethodDefNode * parseTree,skRValueArray&  args,skRValue& return_value,skExecutableContext& ctxt);
00127 
00128 
00141   IMPORT_C void evaluateExpression(const skString& location,skiExecutable * obj,
00142                       const skString& expression,skRValueTable&  vars,
00143                       skRValue& return_value,skExecutableContext& ctxt);
00156 #ifdef EXECUTE_PARSENODES
00157   IMPORT_C void evaluateExpression(const skString& location,skiExecutable * obj,
00158                       skExprNode * expression,skRValueTable&  vars,
00159                       skRValue& return_value,skExecutableContext& ctxt);
00160 #else
00161   IMPORT_C void evaluateExpression(const skString& location,skiExecutable * obj,
00162                           skCompiledCode& code,skRValueTable&  vars,
00163                           skRValue& return_value,skExecutableContext& ctxt);
00164 #endif
00165 
00166   //------------------------
00167   // Global Variable methods
00168   //------------------------
00169    
00176   IMPORT_C void addGlobalVariable(const skString& name,const skRValue& value);
00181   IMPORT_C void removeGlobalVariable(const skString& name);
00182 #ifdef __SYMBIAN32__
00183 
00190   IMPORT_C void addGlobalVariable(const TDesC& name,const skRValue& value);
00196   IMPORT_C void removeGlobalVariable(const TDesC& name);
00197 #endif
00198 
00205   IMPORT_C bool findGlobalVariable(const skString& name,skRValue& return_value);
00206 
00211   IMPORT_C const skRValueTable& getGlobalVariables() const;
00212 
00213   //--------------------------------------------------------
00214   // Interpreter is an Executable which exposes some fields
00215   //--------------------------------------------------------
00216     
00221   virtual IMPORT_C bool setValue(const skString& s,const skString& attribute,const skRValue& v);
00227   virtual IMPORT_C bool getValue(const skString& s,const skString& attribute,skRValue& v);
00239   virtual IMPORT_C bool method(const skString& method_name,skRValueArray& arguments,skRValue& return_value,skExecutableContext& ctxt);
00240 
00246   virtual void getInstanceVariables(skRValueTable& table);
00247     
00248   //------------------------
00249   // Tracing methods
00250   //------------------------
00251 
00255   IMPORT_C void trace(const skString& msg);
00259   IMPORT_C void trace(const Char * msg);
00263   IMPORT_C void setTraceCallback(skTraceCallback * callback);
00264 
00268   IMPORT_C void setStatementStepper(skStatementStepper * stepper);
00269 
00276   IMPORT_C void runtimeError(skStackFrame& ctxt,const skString& msg); 
00283   IMPORT_C void runtimeError(skStackFrame& ctxt,const Char * msg); 
00284 
00285   //---------------------------
00286   // Constructor and Destructor
00287   //---------------------------
00288     
00294   IMPORT_C skInterpreter();
00298   virtual IMPORT_C ~skInterpreter();
00304   IMPORT_C void init();
00305     
00306   inline skNull& getNull();
00307 
00308  private:
00309 
00310   //--------------------
00311   // copying not allowed
00312   //--------------------
00313 
00317   skInterpreter(const skInterpreter&);
00321   skInterpreter& operator=(const skInterpreter&);
00322 
00323 #ifdef EXECUTE_PARSENODES
00324 
00335   skExprNode * parseExpression(const skString& location,const skString& expression,skExecutableContext& ctxt);  
00336 #else
00337 
00348   skCompiledExprNode * parseExpression(const skString& location,const skString& expression,skExecutableContext& ctxt);  
00349 #endif
00350     // Expression evaluation
00351   
00357 #ifdef EXECUTE_PARSENODES
00358   skRValue evaluate(skStackFrame& frame,skExprNode * n);
00359 #else
00360   skRValue evaluate(skStackFrame& frame,skCompiledCode& code,USize& pc);
00361 #endif
00362 
00367 #ifdef EXECUTE_PARSENODES
00368   skRValue evalMethod(skStackFrame& frame,skIdListNode * ids);
00369 #else
00370   skRValue evalMethod(skStackFrame& frame,skCompiledCode& code,USize& pc);
00371 #endif
00372 
00382 #ifdef EXECUTE_PARSENODES
00383   void makeMethodCall(skStackFrame& frame,skRValue& robject,const skString& method_name,skExprNode * array_index, const skString& attribute,skExprListNode * exprs,skRValue& ret);
00384 #else
00385   void makeMethodCall(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& robject,const skString& method_name,bool has_array_index,const skString& attribute, skRValue& ret);
00386 #endif
00387   
00388     // Statement execution
00389 
00395 #ifdef EXECUTE_PARSENODES
00396   void executeAssignStat(skStackFrame& frame,skAssignNode * n);
00397 #else
00398   void executeAssignStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r);
00399 #endif
00400   
00401     // the statements below return true to halt further processing (i.e. a return statement has been encountered)
00402 
00410 #ifdef EXECUTE_PARSENODES
00411   bool executeStats(skStackFrame& frame,skStatListNode * n,skRValue& r);
00412 #else
00413 
00423   bool executeStats(skStackFrame& frame,skCompiledCode& code,USize& pc,int& num_bytes,bool execute_bytes,skRValue& r);
00424 #endif
00425 
00432 #ifdef EXECUTE_PARSENODES
00433   bool executeReturnStat(skStackFrame& frame,skReturnNode * n,skRValue& r);
00434 #else
00435   bool executeReturnStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_expr);
00436 #endif
00437 
00445 #ifdef EXECUTE_PARSENODES
00446   bool executeIfStat(skStackFrame& frame,skIfNode * n,skRValue& r);
00447 #else
00448   bool executeIfStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_else);
00449 #endif
00450 
00458 #ifdef EXECUTE_PARSENODES
00459   bool executeWhileStat(skStackFrame& frame,skWhileNode * n,skRValue& r);
00460 #else
00461   bool executeWhileStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r);
00462 #endif
00463 
00471 #ifdef EXECUTE_PARSENODES
00472   bool executeSwitchStat(skStackFrame& frame,skSwitchNode * n,skRValue& r);
00473 #else
00474   bool executeSwitchStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_default);
00475 #endif
00476 
00484 #ifdef EXECUTE_PARSENODES
00485   bool executeForEachStat(skStackFrame& frame,skForEachNode * n,skRValue& r);
00486 #else
00487   bool executeForEachStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,USize id_index);
00488 #endif
00489 
00497 #ifdef EXECUTE_PARSENODES
00498   bool executeForStat(skStackFrame& frame,skForNode * n,skRValue& r);
00499 #else
00500   bool executeForStat(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& r,bool has_step);
00501 #endif
00502 
00503   // Misc runtime routines
00504 
00511   void addLocalVariable(skRValueTable& var,const skString& name,skRValue value); 
00519   inline skString checkIndirectId(skStackFrame& frame,const skString& name); 
00528 #ifdef EXECUTE_PARSENODES
00529   skRValue findValue(skStackFrame& frame,const skString& name,skExprNode * array_index,const skString& attribute); 
00530 #else
00531   skRValue findValue(skStackFrame& frame,const skString& name,const skRValue * array_index,const skString& attribute); 
00532 #endif
00533 
00539 #ifdef EXECUTE_PARSENODES
00540   void followIdList(skStackFrame& frame,skIdListNode * idList,skRValue& object); 
00541 #else
00542   void followIdList(skStackFrame& frame,skCompiledCode& code,USize& pc,int num_ids,skRValue& object); 
00543 #endif
00544 
00545 
00555 #ifdef EXECUTE_PARSENODES
00556   bool extractFieldArrayValue(skStackFrame& frame,skRValue& robject,const skString& field_name,skExprNode * array_index,const skString& attrib,skRValue& ret);
00557 #else
00558   bool extractFieldArrayValue(skStackFrame& frame,skRValue& robject,const skString& field_name,const skRValue& array_index,const skString& attrib,skRValue& ret);
00559 #endif
00560 
00567 #ifdef EXECUTE_PARSENODES
00568   bool extractArrayValue(skStackFrame& frame,skRValue& robject,skExprNode * array_index,const skString& attrib,skRValue& ret) ;
00569 #else
00570   bool extractArrayValue(skStackFrame& frame,skRValue& robject,const skRValue& array_index,const skString& attrib,skRValue& ret) ;
00571 #endif
00572 
00580   bool extractValue(skStackFrame& frame,skRValue& robject,const skString& name,const skString& attrib,skRValue& ret) ;
00581 
00590 #ifdef EXECUTE_PARSENODES
00591   bool insertArrayValue(skStackFrame& frame,skRValue& robject, skExprNode * array_index,const skString& attr,const skRValue& value);
00592 #else
00593   bool insertArrayValue(skStackFrame& frame,skCompiledCode& code,USize& pc,skRValue& robject, const skString& attr,const skRValue& value);
00594 #endif
00595 
00603   bool insertValue(skStackFrame& frame,skRValue& robject,const skString& name, const skString& attr,const skRValue& value);
00604 
00605 #ifndef EXECUTE_PARSENODES
00606   void getIdNode(skCompiledCode& code,USize& pc,skString& id,bool& has_array,bool& is_method);
00607   void getIdNodes(skCompiledCode& code,USize& pc,int& num_ids,skString& attribute);
00608 #endif
00609 
00610   // Variables
00612   skRValueTable m_GlobalVars; 
00614   bool m_Tracing; 
00616   skTraceCallback * m_TraceCallback; 
00618   skStatementStepper * m_StatementStepper; // the statement stepper
00622   skNull m_Null;
00623 };      
00624 //---------------------------------------------------
00625 inline skString skInterpreter::checkIndirectId(skStackFrame& frame,const skString& name)
00626 //---------------------------------------------------
00627 {
00628   // look for an initial "@" in a field name, and de-reference it if necessary
00629   skString ret=name;
00630   if (name.at(0)=='@'){
00631     ret=name.substr(1,name.length()-1);
00632     skRValue new_name=findValue(frame,ret,0,skString());
00633     ret=new_name.str();
00634   }
00635   return ret;
00636 }       
00637 //---------------------------------------------------
00638 inline skNull& skInterpreter::getNull()
00639 //---------------------------------------------------
00640 {
00641   return m_Null;
00642 }
00643 
00644 xskNAMED_LITERAL(OnANonObject,skSTR(" on a non-object\n"));
00645 
00646 #endif
00647 
00648 

Generated on Tue May 27 18:40:51 2003 for Simkin C++ for Symbian by doxygen1.3