2
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
#ifndef __GNASH_SWF_FUNCTION_H__
19
#define __GNASH_SWF_FUNCTION_H__
22
#include "gnashconfig.h"
26
#include "as_function.h" // for inheritance
27
#include "as_object.h" // for composition (vector element)
28
#include "VM.h" //fow SWF version
29
//#include "with_stack_entry.h" // for composition (vector element)
31
#include <boost/algorithm/string/case_conv.hpp>
35
// Forward declarations
39
class as_array_object;
44
/// SWF-defined Function
45
class swf_function : public as_function
50
/// Action buffer containing the function definition
51
const action_buffer* m_action_buffer;
53
/// @@ might need some kind of ref count here, but beware cycles
54
as_environment* m_env;
56
typedef std::vector< boost::intrusive_ptr<as_object> > ScopeStack;
58
/// Scope stack on function definition.
59
ScopeStack _scopeStack;
62
/// Offset within the action_buffer where
63
/// start of the function is found.
66
/// Length of the function within the action_buffer
68
/// This is currently expressed in bytes as the
69
/// action_buffer is just a blog of memory corresponding
70
/// to a DoAction block
78
std::vector<arg_spec> m_args;
80
boost::uint8_t m_local_register_count;
82
/// used by function2 to control implicit arg register assignments
84
/// See http://sswf.sourceforge.net/SWFalexref.html#action_declare_function2
85
boost::uint16_t m_function2_flags;
87
/// Return an 'arguments' object.
89
/// The 'arguments' variable is an array with an additional
90
/// 'callee' member, set to the function being called.
92
/// NOTE: the callee as_object will be stored in an as_value, thus
93
/// getting wrapped into an intrusive_ptr. Make sure you have
94
/// a reference on it!
97
static as_array_object* getArguments(swf_function& callee, const fn_call& fn);
101
enum SWFDefineFunction2Flags
103
/// Bind one register to "this"
104
PRELOAD_THIS = 0x01, // 1
106
/// No "this" variable accessible by-name
107
SUPPRESS_THIS = 0x02, // 2
109
/// Bind one register to "arguments"
110
PRELOAD_ARGUMENTS = 0x04, // 4
112
/// No "argument" variable accessible by-name
113
SUPPRESS_ARGUMENTS = 0x08, // 8
115
/// Bind one register to "super"
116
PRELOAD_SUPER = 0x10, // 16
118
/// No "super" variable accessible by-name
119
SUPPRESS_SUPER = 0x20, // 32
121
/// Bind one register to "_root"
122
PRELOAD_ROOT = 0x40, // 64
124
/// Bind one register to "_parent"
125
PRELOAD_PARENT = 0x80, // 128
127
/// Bind one register to "_global"
129
/// TODO: check this. See http://sswf.sourceforge.net/SWFalexref.html#action_declare_function2
130
/// Looks like flags would look swapped
131
PRELOAD_GLOBAL = 256 // 0x100
138
/// Default constructor
140
/// Creates a Function object inheriting
141
/// the Function interface (apply,call)
145
/// Construct a Built-in ActionScript class
147
/// The provided export_iface as_object is what will end
148
/// up being the class's 'prototype' member, caller must
149
/// make sure to provide it with a 'constructor' member
150
/// pointing to the function that creates an instance of
152
/// All built-in classes derive from the Function
153
/// built-in class, whose exported interface will be
154
/// accessible trought their __proto__ member.
156
/// @param export_iface the exported interface
158
//swf_function(as_object* export_iface);
159
// USE THE builtin_function instead!
162
/// Create an ActionScript function as defined in an
163
/// action_buffer starting at offset 'start'
165
/// NULL environment is allowed -- if so, then
166
/// functions will be executed in the caller's
167
/// environment, rather than the environment where they
170
swf_function(const action_buffer* ab,
173
const ScopeStack& with_stack);
175
const ScopeStack& getScopeStack() const
180
const action_buffer& getActionBuffer() const
182
assert(m_action_buffer);
183
return *m_action_buffer;
186
size_t getStartPC() const
191
size_t getLength() const
196
bool isFunction2() const
198
return m_is_function2;
201
void set_is_function2() { m_is_function2 = true; }
203
void set_local_register_count(boost::uint8_t ct) { assert(m_is_function2); m_local_register_count = ct; }
205
void set_function2_flags(boost::uint16_t flags) { assert(m_is_function2); m_function2_flags = flags; }
207
void add_arg(int arg_register, const char* name)
209
assert(arg_register == 0 || m_is_function2 == true);
210
m_args.resize(m_args.size() + 1);
211
m_args.back().m_register = arg_register;
212
m_args.back().m_name = PROPNAME(name);
215
void set_length(int len);
218
as_value operator()(const fn_call& fn);
220
//void lazy_create_properties();
223
/// Mark reachable resources. Override from as_function.
225
/// Reachable resources from this object is it's scope stack
226
/// and the prototype.
228
virtual void markReachableResources() const;
229
#endif // GNASH_USE_GC
233
} // end of gnash namespace
235
// __GNASH_SWF_FUNCTION_H__