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  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 std::uint8_t registers() const {
99  return 0;
100  }
101 
103  //
106  //
109  //
112  void add_arg(std::uint8_t reg, const ObjectURI& name) {
113  _args.emplace_back(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(std::uint8_t r, ObjectURI n) : reg(r), name(std::move(n)) {}
134  std::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 
action_buffer.h
gnash::Function::_args
std::vector< Argument > _args
Definition: Function.h:138
gnash::action_buffer::size
size_t size() const
Definition: action_buffer.h:65
gnash::fn_call::super
as_object * super
The "super" object in this function call context.
Definition: fn_call.h:175
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
ObjectURI.h
gnash::FrameGuard::callFrame
CallFrame & callFrame()
Get the CallFrame we've just pushed.
Definition: VM.h:329
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::setLocal
void setLocal(CallFrame &c, const ObjectURI &name, const as_value &val)
Set a local variable in this CallFrame.
Definition: CallStack.cpp:80
gnash::Function
A simple SWF-defined Function.
Definition: Function.h:64
gnash::Function::Argument::name
ObjectURI name
Definition: Function.h:135
CallStack.h
gnash::Function::~Function
virtual ~Function()
Definition: Function.h:77
gnash::as_environment
Provides information about timeline context.
Definition: as_environment.h:51
gnash::Function::call
virtual as_value call(const fn_call &fn)
Dispatch.
Definition: Function.cpp:70
gnash::as_object::init_member
void init_member(const std::string &name, const as_value &val, int flags=DefaultFlags)
Initialize a member value by string.
Definition: as_object.cpp:669
gnash::VM
The AVM1 virtual machine.
Definition: VM.h:72
gnash::NSV::PROP_CALLEE
@ PROP_CALLEE
Definition: namedStrings.h:64
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
ActionExec.h
gnash::NSV::PROP_SUPER
@ PROP_SUPER
Definition: namedStrings.h:93
_env
const as_environment & _env
Definition: Array_as.cpp:682
gnash::Function::registers
virtual std::uint8_t registers() const
Get the number of registers required for function execution.
Definition: Function.h:98
NativeFunction.h
gnash::key::n
@ n
Definition: GnashKey.h:160
start
@ start
Definition: klash_part.cpp:330
Global_as.h
gnash::ActionExec
Executor of an action_buffer.
Definition: ActionExec.h:119
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
gnash::NSV::PROP_PUSH
@ PROP_PUSH
Definition: namedStrings.h:88
gnash::fn_call
Parameters/environment for builtin or user-defined functions callable from ActionScript.
Definition: fn_call.h:118
gnash::callMethod
as_value callMethod(fn_call::Args &args, as_object *obj, const ObjectURI &uri)
Call a member function of this object in an AS-compatible way.
Definition: Global_as.h:219
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::UserFunction
A UserFunction is a callable function defined in ActionScript.
Definition: UserFunction.h:38
gnash::Function::getLength
size_t getLength() const
Definition: Function.h:91
gnash::Function::getScopeStack
const ScopeStack & getScopeStack() const
Definition: Function.h:79
gnash::TargetGuard::TargetGuard
TargetGuard(as_environment &e, DisplayObject *ch, DisplayObject *och)
Definition: Function.cpp:50
gnash::Function::add_arg
void add_arg(std::uint8_t reg, const ObjectURI &name)
Add an expected argument for the function.
Definition: Function.h:112
gnash::Function::Argument::reg
std::uint8_t reg
Definition: Function.h:134
gnash::Function::Function
Function(const action_buffer &ab, as_environment &env, size_t start, ScopeStack with_stack)
Create an ActionScript function as defined in an action_buffer starting at offset 'start'.
Definition: Function.cpp:36
gnash::Function::setLength
void setLength(size_t len)
Set the length in bytes of the function code.
Definition: Function.cpp:150
gnash::Function::_env
as_environment & _env
@ might need some kind of ref count here, but beware cycles
Definition: Function.h:141
gnash::ConstantPool
std::vector< const char * > ConstantPool
An indexed list of strings (must match the definition in action_buffer.h)
Definition: ConstantPool.h:27
gnash::as_environment::set_original_target
void set_original_target(DisplayObject *target)
Definition: as_environment.h:73
gnash::as_environment::markReachableResources
void markReachableResources() const
Mark all reachable resources.
Definition: as_environment.cpp:282
gnash::Function::markReachableResources
virtual void markReachableResources() const
Mark reachable resources. Override from as_object.
Definition: Function.cpp:157
gnash::fn_call::nargs
Args::size_type nargs
Number of arguments to this ActionScript function call.
Definition: fn_call.h:178
gnash::as_environment::target
DisplayObject * target() const
Definition: as_environment.h:61
gnash::VM::calling
bool calling() const
Whether a function call is in progress.
Definition: VM.h:240
gnash::Function::ScopeStack
std::vector< as_object * > ScopeStack
Definition: Function.h:68
gnash::TargetGuard
Definition: Function.h:40
gnash::NSV::PROP_CALLER
@ PROP_CALLER
Definition: namedStrings.h:65
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::Global_as::createArray
as_object * createArray()
Construct an Array.
Definition: Global_as.cpp:207
gnash::getArguments
as_object * getArguments(Function &callee, as_object &args, const fn_call &fn, as_object *caller)
Add properties to an 'arguments' object.
Definition: Function.cpp:169
VM.h
gnash::NSV::PROP_ARGUMENTS
@ PROP_ARGUMENTS
Definition: namedStrings.h:60
gnash::Function::getStartPC
size_t getStartPC() const
Definition: Function.h:87
gnash::Function::getActionBuffer
const action_buffer & getActionBuffer() const
Definition: Function.h:83
gnash::CallFrame::function
UserFunction & function()
Get the function for which this CallFrame provides a scope.
Definition: CallStack.h:78
gnash::fn_call::arg
const Args::value_type & arg(unsigned int n) const
Access a particular argument.
Definition: fn_call.h:194
gnash::Function::_pool
const ConstantPool * _pool
The ConstantPool in effect at time of function definition.
Definition: Function.h:144
gnash::FrameGuard
Definition: VM.h:318
gnash::as_object::vm
VM & vm() const
Return a reference to this as_object's global object.
Definition: as_object.h:205
DisplayObject.h
ConstantPool.h
log.h
fn_call.h
gnash::as_environment::get_original_target
DisplayObject * get_original_target() const
Definition: as_environment.h:77
namedStrings.h
gnash::as_environment::set_target
void set_target(DisplayObject *target)
Set default target for timeline opcodes.
Definition: as_environment.h:68
gnash::getSWFVersion
int getSWFVersion(const as_environment &env)
Definition: as_environment.cpp:657
gnash::Function::Argument
Definition: Function.h:132
gnash::as_object::markReachableResources
virtual void markReachableResources() const
Mark all reachable resources, override from GcResource.
Definition: as_object.cpp:1011
Function.h
gnash::PoolGuard
Definition: ConstantPool.h:35
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::action_buffer
A code segment.
Definition: action_buffer.h:50
gnash::declareLocal
void declareLocal(CallFrame &c, const ObjectURI &name)
Declare a local variable in this CallFrame.
Definition: CallStack.cpp:71
gnash::CallFrame
A CallFrame is an element of a CallStack.
Definition: CallStack.h:44
gnash::TargetGuard::~TargetGuard
~TargetGuard()
Definition: Function.cpp:62
gnash::Function::Argument::Argument
Argument(std::uint8_t r, ObjectURI n)
Definition: Function.h:133
gnash::fn_call::this_ptr
as_object * this_ptr
Definition: fn_call.h:170
UserFunction.h
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::NSV::PROP_THIS
@ PROP_THIS
Definition: namedStrings.h:96
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::as_object::get_super
virtual as_object * get_super(const ObjectURI &fname)
Definition: as_object.cpp:445
gnash::VM::currentCall
CallFrame & currentCall()
Return the CallFrame of the currently executing function.
Definition: VM.cpp:229
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92