Gnash 0.8.10dev
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00003 // 2011 Free Software 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_SWF_FUNCTION_H 00020 #define GNASH_SWF_FUNCTION_H 00021 00022 #include <vector> 00023 #include <cassert> 00024 #include <string> 00025 00026 #include "UserFunction.h" 00027 #include "ObjectURI.h" 00028 00029 // Forward declarations 00030 namespace gnash { 00031 class action_buffer; 00032 class as_object; 00033 } 00034 00035 namespace gnash { 00036 00037 class TargetGuard 00038 { 00039 public: 00040 00041 // @param ch : target to set temporarely 00042 // @param och : original target to set temporarily 00043 TargetGuard(as_environment& e, DisplayObject* ch, DisplayObject* och); 00044 ~TargetGuard(); 00045 00046 private: 00047 00048 as_environment& env; 00049 DisplayObject* from; 00050 DisplayObject* from_orig; 00051 00052 }; 00053 00055 // 00059 // 00061 class Function : public UserFunction 00062 { 00063 00064 public: 00065 00066 typedef std::vector<as_object*> ScopeStack; 00067 00071 // 00072 Function(const action_buffer& ab, as_environment& env, size_t start, 00073 const ScopeStack& with_stack); 00074 00075 virtual ~Function() {} 00076 00077 const ScopeStack& getScopeStack() const { 00078 return _scopeStack; 00079 } 00080 00081 const action_buffer& getActionBuffer() const { 00082 return _action_buffer; 00083 } 00084 00085 size_t getStartPC() const { 00086 return _startPC; 00087 } 00088 00089 size_t getLength() const { 00090 return _length; 00091 } 00092 00094 // 00096 virtual boost::uint8_t registers() const { 00097 return 0; 00098 } 00099 00101 // 00104 // 00107 // 00110 void add_arg(boost::uint8_t reg, const ObjectURI& name) { 00111 _args.push_back(Argument(reg, name)); 00112 } 00113 00115 void setLength(size_t len); 00116 00118 virtual as_value call(const fn_call& fn); 00119 00121 // 00125 virtual void markReachableResources() const; 00126 00127 protected: 00128 00129 struct Argument 00130 { 00131 Argument(boost::uint8_t r, const ObjectURI& n) : reg(r), name(n) {} 00132 boost::uint8_t reg; 00133 ObjectURI name; 00134 }; 00135 00136 std::vector<Argument> _args; 00137 00139 as_environment& _env; 00140 00141 private: 00142 00144 const action_buffer& _action_buffer; 00145 00147 ScopeStack _scopeStack; 00148 00152 size_t _startPC; 00153 00155 // 00159 size_t _length; 00160 00161 00162 }; 00163 00165 // 00168 as_object* getArguments(Function& callee, as_object& args, 00169 const fn_call& fn, as_object* caller); 00170 00171 00172 } // end of gnash namespace 00173 00174 #endif 00175