• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

ActionExec.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program 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
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_ACTIONEXEC_H
00020 #define GNASH_ACTIONEXEC_H
00021 
00022 #include <string>
00023 #include <list>
00024 #include <vector>
00025 #include <boost/noncopyable.hpp>
00026 
00027 #include "as_environment.h" 
00028 #include "SWF.h"
00029 #include "action_buffer.h"
00030 
00031 // Forward declarations
00032 namespace gnash {
00033         class as_value;
00034         class Function;
00035         class ActionExec;
00036 }
00037 
00038 namespace gnash {
00039 
00040 class TryBlock
00041 {
00042 public:
00043         friend class ActionExec;
00044 
00045         enum tryState
00046         {
00047                 TRY_TRY, // In a try block.
00048                 TRY_CATCH, // In a catch block.
00049                 TRY_FINALLY, // In a finally block.
00050                 TRY_END // Finished with finally
00051         };
00052 
00053     TryBlock(size_t cur_off, size_t try_size, size_t catch_size,
00054                 size_t finally_size, std::string catchName)
00055                 :
00056                 _catchOffset(cur_off + try_size),
00057                 _finallyOffset(cur_off + try_size + catch_size),
00058                 _afterTriedOffset(cur_off + try_size + catch_size + finally_size),
00059                 _hasName(true),
00060                 _name(catchName),
00061                 _registerIndex(0),
00062                 _tryState(TryBlock::TRY_TRY),
00063                 _lastThrow()
00064         {}
00065 
00066         TryBlock(size_t cur_off, size_t try_size, size_t catch_size,
00067                 size_t finally_size, boost::uint8_t register_index)
00068                 :
00069                 _catchOffset(cur_off + try_size),
00070                 _finallyOffset(cur_off + try_size + catch_size),
00071                 _afterTriedOffset(cur_off + try_size + catch_size + finally_size),
00072                 _hasName(false),
00073                 _name(),
00074                 _registerIndex(register_index),
00075                 _tryState(TryBlock::TRY_TRY),
00076                 _lastThrow()
00077         {}
00078 
00079 private:
00080         size_t _catchOffset;
00081         size_t _finallyOffset;
00082         size_t _afterTriedOffset;
00083         size_t _savedEndOffset;
00084         bool _hasName;
00085         std::string _name;
00086         unsigned int _registerIndex;
00087         tryState _tryState;
00088         as_value _lastThrow;
00089 };
00090 
00091 class With
00092 {
00093 public: 
00094 
00095         With(as_object* obj, size_t end)
00096                 :
00097                 _object(obj),
00098                 _block_end_pc(end)
00099         {
00100         }
00101 
00102         size_t end_pc() const {
00103                 return _block_end_pc;
00104         }
00105 
00106         as_object* object() const {
00107                 return _object;
00108         }
00109 
00110 private:
00111         as_object* _object;
00112         size_t _block_end_pc;
00113 };
00114 
00116 class ActionExec : boost::noncopyable
00117 {
00118 
00119     typedef as_environment::ScopeStack ScopeStack;
00120 
00121 public:
00122 
00124         //
00136         ActionExec(const action_buffer& abuf, as_environment& newEnv,
00137             bool abortOnUnloaded = true);
00138 
00140         //
00145         ActionExec(const Function& func, as_environment& newEnv,
00146             as_value* nRetVal, as_object* this_ptr);
00147 
00151         void pushTryBlock(TryBlock t);
00152 
00155         void pushReturn(const as_value& t);
00156 
00158         //
00161         const action_buffer& code;
00162 
00164         as_environment& env;
00165 
00167         as_value* retval;
00168 
00170         bool isFunction() const { return _func != 0; }
00171 
00173         as_object* getThisPointer();
00174 
00176         const ScopeStack& getScopeStack() const
00177         {
00178                 return _scopeStack;
00179         }
00180 
00182         //
00185         bool pushWith(const With& entry);
00186 
00188         //
00191         void skip_actions(size_t offset);
00192 
00194         //
00199         bool delVariable(const std::string& name);
00200 
00202         //
00212         bool delObjectMember(as_object& obj, const std::string& name);
00213 
00215         //
00220         void setVariable(const std::string& name, const as_value& val);
00221 
00225         //
00230         void setLocalVariable(const std::string& name, const as_value& val);
00231 
00233         //
00238         as_value getVariable(const std::string& name);
00239 
00241         //
00252         as_value getVariable(const std::string& name, as_object** target);
00253 
00255         //
00264         as_object* getTarget();
00265 
00267         void operator()();
00268 
00269     // TODO: cut down these accessors.
00270     bool atActionTag(SWF::ActionType t) { return code[pc] == t; }
00271         
00272         size_t getCurrentPC() const { return pc; }
00273         
00274         void skipRemainingBuffer() { next_pc = stop_pc; }
00275         
00276         void adjustNextPC(int offset);
00277         
00278         size_t getNextPC() const { return next_pc; }
00279         
00280         void setNextPC(size_t pc) { next_pc = pc; }
00281         
00282         size_t getStopPC() const { return stop_pc; }
00283         
00284 private: 
00285 
00289         //
00299         void dumpActions(size_t start, size_t end, std::ostream& os);
00300 
00302     //
00311     //
00313     //
00315     bool processExceptions(TryBlock& t);
00316 
00319         //
00332         void cleanupAfterRun();
00333 
00335         std::vector<With> _withStack;
00336 
00338         ScopeStack _scopeStack;
00339 
00348         const Function* _func;
00349 
00351         as_object* _this_ptr;
00352 
00354         size_t _initialStackSize;
00355 
00356         DisplayObject* _originalTarget;
00357 
00358         int _origExecSWFVersion;
00359 
00360         std::list<TryBlock> _tryList;
00361 
00362         bool _returning;
00363 
00364         bool _abortOnUnload;
00365 
00367         size_t pc;
00368 
00370         size_t next_pc;
00371 
00374         size_t stop_pc;
00375 
00376 };
00377 
00378 } // namespace gnash
00379 
00380 #endif // GNASH_ACTIONEXEC_H
00381 
00382 // Local Variables:
00383 // mode: C++
00384 // indent-tabs-mode: t
00385 // End:

Generated on Fri Mar 16 2012 15:46:08 for Gnash by  doxygen 1.7.1