Gnash  0.8.11dev
Function.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_SWF_FUNCTION_H
20 #define GNASH_SWF_FUNCTION_H
21 
22 #include <vector>
23 #include <cassert>
24 #include <string>
25 
26 #include "ConstantPool.h"
27 #include "UserFunction.h"
28 #include "ObjectURI.h"
29 
30 // Forward declarations
31 namespace gnash {
32  class action_buffer;
33  class as_object;
34  class VM;
35 }
36 
37 namespace gnash {
38 
40 {
41 public:
42 
43  // @param ch : target to set temporarely
44  // @param och : original target to set temporarily
46  ~TargetGuard();
47 
48 private:
49 
50  as_environment& env;
51  DisplayObject* from;
52  DisplayObject* from_orig;
53 
54 };
55 
57 //
61 //
63 class Function : public UserFunction
64 {
65 
66 public:
67 
68  typedef std::vector<as_object*> ScopeStack;
69 
73  //
74  Function(const action_buffer& ab, as_environment& env, size_t start,
75  const ScopeStack& with_stack);
76 
77  virtual ~Function() {}
78 
79  const ScopeStack& getScopeStack() const {
80  return _scopeStack;
81  }
82 
83  const action_buffer& getActionBuffer() const {
84  return _action_buffer;
85  }
86 
87  size_t getStartPC() const {
88  return _startPC;
89  }
90 
91  size_t getLength() const {
92  return _length;
93  }
94 
96  //
98  virtual boost::uint8_t registers() const {
99  return 0;
100  }
101 
103  //
106  //
109  //
112  void add_arg(boost::uint8_t reg, const ObjectURI& name) {
113  _args.push_back(Argument(reg, name));
114  }
115 
117  void setLength(size_t len);
118 
120  virtual as_value call(const fn_call& fn);
121 
123  //
127  virtual void markReachableResources() const;
128 
129 protected:
130 
131  struct Argument
132  {
133  Argument(boost::uint8_t r, const ObjectURI& n) : reg(r), name(n) {}
134  boost::uint8_t reg;
136  };
137 
138  std::vector<Argument> _args;
139 
142 
145 
146 private:
147 
149  const action_buffer& _action_buffer;
150 
152  ScopeStack _scopeStack;
153 
157  size_t _startPC;
158 
160  //
164  size_t _length;
165 
166 };
167 
169 //
172 as_object* getArguments(Function& callee, as_object& args,
173  const fn_call& fn, as_object* caller);
174 
175 
176 } // end of gnash namespace
177 
178 #endif
179 
virtual ~Function()
Definition: Function.h:77
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
const action_buffer & getActionBuffer() const
Definition: Function.h:83
virtual as_value call(const fn_call &fn)
Dispatch.
Definition: Function.cpp:70
Definition: klash_part.cpp:330
ActionScript value type.
Definition: as_value.h:95
boost::uint8_t reg
Definition: Function.h:134
std::vector< Argument > _args
Definition: Function.h:138
virtual boost::uint8_t registers() const
Get the number of registers required for function execution.
Definition: Function.h:98
void add_arg(boost::uint8_t reg, const ObjectURI &name)
Add an expected argument for the function.
Definition: Function.h:112
virtual void markReachableResources() const
Mark reachable resources. Override from as_object.
Definition: Function.cpp:157
Definition: Function.h:39
~TargetGuard()
Definition: Function.cpp:62
as_object * getArguments(Function &callee, as_object &args, const fn_call &fn, as_object *caller)
Add properties to an &#39;arguments&#39; object.
Definition: Function.cpp:169
A simple SWF-defined Function.
Definition: Function.h:63
The base class for all ActionScript objects.
Definition: as_object.h:161
Argument(boost::uint8_t r, const ObjectURI &n)
Definition: Function.h:133
A URI for describing as_objects.
Definition: ObjectURI.h:44
Definition: GnashKey.h:160
Definition: GnashKey.h:164
Provides information about timeline context.
Definition: as_environment.h:50
TargetGuard(as_environment &e, DisplayObject *ch, DisplayObject *och)
Definition: Function.cpp:50
void setLength(size_t len)
Set the length in bytes of the function code.
Definition: Function.cpp:150
size_t getStartPC() const
Definition: Function.h:87
std::vector< as_object * > ScopeStack
Definition: Function.h:68
const ScopeStack & getScopeStack() const
Definition: Function.h:79
A UserFunction is a callable function defined in ActionScript.
Definition: UserFunction.h:37
as_environment & _env
@ might need some kind of ref count here, but beware cycles
Definition: Function.h:141
ObjectURI name
Definition: Function.h:135
size_t getLength() const
Definition: Function.h:91
const ConstantPool * _pool
The ConstantPool in effect at time of function definition.
Definition: Function.h:144
Definition: Function.h:131
Definition: GnashKey.h:151
A code segment.
Definition: action_buffer.h:49
Parameters/environment for builtin or user-defined functions callable from ActionScript.
Definition: fn_call.h:107
Function(const action_buffer &ab, as_environment &env, size_t start, const ScopeStack &with_stack)
Create an ActionScript function as defined in an action_buffer starting at offset &#39;start&#39;...
Definition: Function.cpp:36
std::string name
Definition: LocalConnection_as.cpp:151
std::vector< const char * > ConstantPool
An indexed list of strings (must match the definition in action_buffer.h)
Definition: ConstantPool.h:27