Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00003 // 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 "ConstantPool.h" 00027 #include "UserFunction.h" 00028 #include "ObjectURI.h" 00029 00030 // Forward declarations 00031 namespace gnash { 00032 class action_buffer; 00033 class as_object; 00034 class VM; 00035 } 00036 00037 namespace gnash { 00038 00039 class TargetGuard 00040 { 00041 public: 00042 00043 // @param ch : target to set temporarely 00044 // @param och : original target to set temporarily 00045 TargetGuard(as_environment& e, DisplayObject* ch, DisplayObject* och); 00046 ~TargetGuard(); 00047 00048 private: 00049 00050 as_environment& env; 00051 DisplayObject* from; 00052 DisplayObject* from_orig; 00053 00054 }; 00055 00057 // 00061 // 00063 class Function : public UserFunction 00064 { 00065 00066 public: 00067 00068 typedef std::vector<as_object*> ScopeStack; 00069 00073 // 00074 Function(const action_buffer& ab, as_environment& env, size_t start, 00075 const ScopeStack& with_stack); 00076 00077 virtual ~Function() {} 00078 00079 const ScopeStack& getScopeStack() const { 00080 return _scopeStack; 00081 } 00082 00083 const action_buffer& getActionBuffer() const { 00084 return _action_buffer; 00085 } 00086 00087 size_t getStartPC() const { 00088 return _startPC; 00089 } 00090 00091 size_t getLength() const { 00092 return _length; 00093 } 00094 00096 // 00098 virtual boost::uint8_t registers() const { 00099 return 0; 00100 } 00101 00103 // 00106 // 00109 // 00112 void add_arg(boost::uint8_t reg, const ObjectURI& name) { 00113 _args.push_back(Argument(reg, name)); 00114 } 00115 00117 void setLength(size_t len); 00118 00120 virtual as_value call(const fn_call& fn); 00121 00123 // 00127 virtual void markReachableResources() const; 00128 00129 protected: 00130 00131 struct Argument 00132 { 00133 Argument(boost::uint8_t r, const ObjectURI& n) : reg(r), name(n) {} 00134 boost::uint8_t reg; 00135 ObjectURI name; 00136 }; 00137 00138 std::vector<Argument> _args; 00139 00141 as_environment& _env; 00142 00144 const ConstantPool* _pool; 00145 00146 private: 00147 00149 const action_buffer& _action_buffer; 00150 00152 ScopeStack _scopeStack; 00153 00157 size_t _startPC; 00158 00160 // 00164 size_t _length; 00165 00166 }; 00167 00169 // 00172 as_object* getArguments(Function& callee, as_object& args, 00173 const fn_call& fn, as_object* caller); 00174 00175 00176 } // end of gnash namespace 00177 00178 #endif 00179