Gnash 0.8.9

Function.h

Go to the documentation of this file.
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 "smart_ptr.h"
00028 #include "ObjectURI.h"
00029 
00030 // Forward declarations
00031 namespace gnash {
00032     class action_buffer;
00033     class as_object;
00034 }
00035 
00036 namespace gnash {
00037 
00038 class TargetGuard
00039 {
00040 public:
00041 
00042         // @param ch : target to set temporarely
00043         // @param och : original target to set temporarily
00044         TargetGuard(as_environment& e, DisplayObject* ch, DisplayObject* och);
00045         ~TargetGuard();
00046 
00047 private:
00048 
00049     as_environment& env;
00050     DisplayObject* from;
00051     DisplayObject* from_orig;
00052 
00053 };
00054 
00056 //
00060 //
00062 class Function : public UserFunction
00063 {
00064 
00065 public:
00066 
00067         typedef std::vector<as_object*> ScopeStack;
00068 
00072         //
00073         Function(const action_buffer& ab, as_environment& env, size_t start,
00074                 const ScopeStack& with_stack);
00075 
00076         virtual ~Function() {}
00077 
00078         const ScopeStack& getScopeStack() const {
00079                 return _scopeStack;
00080         }
00081 
00082         const action_buffer& getActionBuffer() const {
00083                 return _action_buffer;
00084         }
00085 
00086         size_t getStartPC() const {
00087                 return _startPC;
00088         }
00089 
00090         size_t getLength() const {
00091                 return _length;
00092         }
00093 
00095     //
00097     virtual boost::uint8_t registers() const {
00098         return 0;
00099     }
00100 
00102     //
00105     //
00108     //
00111         void add_arg(boost::uint8_t reg, const ObjectURI& name) {
00112         _args.push_back(Argument(reg, name));
00113         }
00114 
00116         void setLength(size_t len);
00117 
00119         virtual as_value call(const fn_call& fn);
00120 
00122         //
00126         virtual void markReachableResources() const;
00127 
00128 protected:
00129         
00130     struct Argument
00131         {
00132         Argument(boost::uint8_t r, const ObjectURI& n) : reg(r), name(n) {}
00133         boost::uint8_t reg;
00134         ObjectURI name;
00135         };
00136 
00137         std::vector<Argument> _args;
00138 
00140         as_environment& _env;
00141 
00142 private:
00143 
00145         const action_buffer& _action_buffer;
00146 
00148         ScopeStack _scopeStack;
00149 
00153         size_t  _startPC;
00154 
00156         //
00160         size_t _length;
00161 
00162 
00163 };
00164 
00166 //
00169 as_object* getArguments(Function& callee, as_object& args, 
00170         const fn_call& fn, as_object* caller);
00171 
00172 
00173 } // end of gnash namespace
00174 
00175 #endif
00176