Gnash  0.8.11dev
Method.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 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_AS_METHOD_H
20 #define GNASH_AS_METHOD_H
21 
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h"
24 #endif
25 
26 #include "string_table.h"
27 #include "AbcBlock.h"
28 
29 #include <map>
30 #include <vector>
31 #include <list>
32 
33 // Forward declarations
34 namespace gnash {
35  namespace abc {
36  class Machine;
37  class abc_function;
38  class Namespace;
39  class Class;
40  }
41  class CodeStream;
42  class as_object;
43 }
44 
45 namespace gnash {
46 namespace abc {
47 
49 
53 class Method
54 {
55 public:
56 
57  typedef std::list<Class*> ArgumentList;
58 
59  Method();
60 
61  std::uint32_t methodID() const {
62  return _methodID;
63  }
64 
65  void setMethodID(std::uint32_t m) {
66  _methodID = m;
67  }
68 
69  void initPrototype(Machine* machine);
70 
71  std::uint32_t getMaxRegisters() { return _maxRegisters;}
72 
73  void setMaxRegisters(std::uint32_t maxRegisters) {
74  _maxRegisters = maxRegisters;
75  }
76 
77  std::uint32_t getBodyLength(){ return _bodyLength;}
78 
79  void setBodyLength(std::uint32_t length){ _bodyLength = length;}
80 
81  void setMaxStack(std::uint32_t max) {
82  _maxStack = max;
83  }
84 
85  std::uint32_t maxStack() const {
86  return _maxStack;
87  }
88 
89  void setMaxScope(std::uint32_t max) {
90  _maxScope = max;
91  }
92 
93  std::uint32_t maxScope() const {
94  return _maxScope;
95  }
96 
97  void setScopeDepth(std::uint32_t depth) {
98  _scopeDepth = depth;
99  }
100 
101  std::uint32_t scopeDepth() const {
102  return _scopeDepth;
103  }
104 
105  abc_function* getPrototype() { return _prototype; }
106 
108  void addTrait(const Trait& t) {
109  _traits.push_back(t);
110  }
111 
112 
114  //
116  void initTraits(AbcBlock& bl);
117 
119 
120  bool isNative() { return _isNative; }
121  bool hasBody() const { return _body != NULL; }
122 
123  as_object* construct(as_object* /*base_scope*/) {
124  // TODO:
125  return NULL;
126  }
127 
128  bool needsActivation() const {
129  return _needsActivation;
130  }
131 
133  _needsActivation = true;
134  }
135 
136  CodeStream *getBody() { return _body; }
137  void setBody(CodeStream *b) { _body = b; }
138 
140  std::uint32_t slotID, Class *type, as_value& val, bool isconst);
141 
143  std::uint32_t slotID, Class *type);
144 
145  bool addMethod(string_table::key name, Namespace *ns, Method *method);
146 
147  bool addGetter(string_table::key name, Namespace *ns, Method *method);
148 
149  bool addSetter(string_table::key name, Namespace *ns, Method *method);
150 
152  std::uint32_t slotID, Class *type);
153 
155  std::uint32_t slotID, Method *method);
156 
159  void setOwner(Class* s);
160 
166 
168  //
174  void setReturnType(Class* t);
175 
177 
178  void setSuper(Method* s);
179 
182  bool isFinal() const { return _flags & FLAGS_FINAL; }
183 
186  void setFinal() { _flags = _flags | FLAGS_FINAL; }
187 
190  void unsetFinal() { _flags = _flags & ~FLAGS_FINAL; }
191 
194  bool isPrivate() const { return _flags & FLAGS_PRIVATE; }
195 
198  void setPrivate() {
199  _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PROTECTED)) | FLAGS_PRIVATE;
200  }
201 
204  bool isProtected() const {
205  return _flags & FLAGS_PROTECTED;
206  }
207 
210  void setProtected() {
211  _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PRIVATE)) | FLAGS_PROTECTED; }
212 
214  bool isPublic() const { return _flags & FLAGS_PUBLIC; }
215 
217  void setPublic() {
218  _flags = (_flags & ~(FLAGS_PRIVATE | FLAGS_PROTECTED)) | FLAGS_PUBLIC;
219  }
220 
222  int minArgumentCount() const { return _minArguments; }
223 
225  void setMinArgumentCount(int i) { _minArguments = i; }
226 
228  int maxArgumentCount() const { return _maxArguments; }
229 
231  void setMaxArgumentCount(int i) { _maxArguments = i; }
232 
234  //
236  void pushArgument(Class* t) { _arguments.push_back(t); }
237 
239  void pushOptional(const as_value& v) { _optionalArguments.push_back(v); }
240 
242  bool optionalArguments() const {
243  return minArgumentCount() != maxArgumentCount();
244  }
245 
247  //
249  const ArgumentList& getArgumentList() const { return _arguments; }
250 
255  as_function* getImplementation() { return _implementation; }
256 
259  void print_body();
260 
261 private:
262 
263  enum Flag
264  {
265  FLAGS_FINAL = 0x01,
266  FLAGS_PROTECTED = 0x02,
267  FLAGS_PUBLIC = 0x04,
268  FLAGS_PRIVATE = 0x08
269  };
270 
272  typedef std::map<string_table::key, asBinding> BindingContainer;
273 
274  bool addBinding(string_table::key name, asBinding b);
275 
276  std::vector<Trait> _traits;
277 
278  std::uint32_t _methodID;
279 
280  abc_function* _prototype;
281  int _minArguments;
282  int _maxArguments;
283  std::uint32_t _bodyLength;
284  bool _isNative;
285  ArgumentList _arguments;
286  std::list<as_value> _optionalArguments;
287  as_function* _implementation;
288  unsigned char _flags;
289  CodeStream* _body;
290  std::uint32_t _maxRegisters;
291 
292  std::uint32_t _scopeDepth;
293  std::uint32_t _maxScope;
294  std::uint32_t _maxStack;
295 
296  bool _needsActivation;
297 
298 };
299 
300 } // namespace abc
301 } // namespace gnash
302 
303 #endif
gnash::abc::Namespace::getURI
string_table::key getURI() const
What is the Uri of the namespace?
Definition: Namespace.h:76
gnash::abc::Trait
Class describing a static property.
Definition: AbcBlock.h:72
gnash::abc::Method::methodID
std::uint32_t methodID() const
Definition: Method.h:61
string_table.h
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::abc::Method::getSuper
Method * getSuper()
gnash::abc::Method::setScopeDepth
void setScopeDepth(std::uint32_t depth)
Definition: Method.h:97
Class.h
gnash::abc::Method::setPrivate
void setPrivate()
Make the method private.
Definition: Method.h:198
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::abc::Method::addMethod
bool addMethod(string_table::key name, Namespace *ns, Method *method)
Definition: Method.cpp:196
gnash::abc::Method::addValue
bool addValue(string_table::key name, Namespace *ns, std::uint32_t slotID, Class *type, as_value &val, bool isconst)
Definition: Method.cpp:95
gnash::CodeStream::read_as3op
std::uint8_t read_as3op()
Read an opcode for ActionScript 3.
Definition: CodeStream.cpp:54
CodeStream.h
gnash::abc::Method
Definition: Method.h:54
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::abc::Namespace
Represent an ActionScript Namespace.
Definition: Namespace.h:49
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::abc::Method::isPublic
bool isPublic() const
Is the method public?
Definition: Method.h:214
gnash::abc::Method::setOwner
void setOwner(Class *s)
Set the owner of this method.
Definition: Method.cpp:72
gnash::abc::Method::needsActivation
bool needsActivation() const
Definition: Method.h:128
gnash::NSV::CLASS_FUNCTION
@ CLASS_FUNCTION
Definition: namedStrings.h:216
_
#define _(String)
Definition: log.h:44
gnash::abc::Method::addTrait
void addTrait(const Trait &t)
Add a Trait to this Method.
Definition: Method.h:108
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
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::key::g
@ g
Definition: GnashKey.h:153
gnash::abc::Method::isPrivate
bool isPrivate() const
Is the method private?
Definition: Method.h:194
gnash::PropFlags::dontEnum
@ dontEnum
Protect from enumeration.
Definition: PropFlags.h:36
gnash::PropFlags::dontDelete
@ dontDelete
Protect from deletion.
Definition: PropFlags.h:39
gnash::key::m
@ m
Definition: GnashKey.h:159
gnash::key::s
@ s
Definition: GnashKey.h:165
gnash::abc::Method::ArgumentList
std::list< Class * > ArgumentList
Definition: Method.h:57
Global_as.h
gnash::as_object::init_property
void init_property(const std::string &key, as_function &getter, as_function &setter, int flags=DefaultFlags)
Initialize a getter/setter property by name.
Definition: as_object.cpp:690
gnash::abc::Method::getBodyLength
std::uint32_t getBodyLength()
Definition: Method.h:77
gnash::abc::AbcBlock
The ActionScript bytecode of a single ABC tag in a SWF.
Definition: AbcBlock.h:209
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::abc::Method::getMaxRegisters
std::uint32_t getMaxRegisters()
Definition: Method.h:71
gnash::abc::Method::setMaxStack
void setMaxStack(std::uint32_t max)
Definition: Method.h:81
gnash::abc::asBinding
Property asBinding
Definition: Method.h:48
gnash::abc::Method::maxStack
std::uint32_t maxStack() const
Definition: Method.h:85
CLOCK_REALTIME
#define CLOCK_REALTIME
Definition: getclocktime.hpp:44
gmemory.h
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::abc::Method::pushOptional
void pushOptional(const as_value &v)
Push an optional argument's default value.
Definition: Method.h:239
gnash::abc::Method::addSlotFunction
bool addSlotFunction(string_table::key name, Namespace *ns, std::uint32_t slotID, Method *method)
Definition: Method.cpp:180
gnash::abc::Method::getBinding
asBinding * getBinding(string_table::key name)
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::abc::Trait::finalize
bool finalize(AbcBlock *block, abc::Class *cl, bool do_static)
Definition: AbcBlock.cpp:42
gnash::abc::Method::setMaxArgumentCount
void setMaxArgumentCount(int i)
Set the required maximum arguments.
Definition: Method.h:231
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::abc::Class::getPrototype
as_object * getPrototype()
Necessary for the current bogus implementation.
Definition: Class.h:256
gnash::abc::Method::getImplementation
as_function * getImplementation()
Get an object capable of executing this function. Note: This may be NULL, because we might have infor...
Definition: Method.h:255
gnash::abc::Method::Method
Method()
Definition: Method.cpp:36
gnash::key::type
type
Definition: GnashKey.h:330
gnash::abc::Method::setProtected
void setProtected()
Make the method protected.
Definition: Method.h:210
gnash::abc::Method::isNative
bool isNative()
Definition: Method.h:120
gnash::abc::Method::pushArgument
void pushArgument(Class *t)
Push an argument of type t into the method definition.
Definition: Method.h:236
gnash::abc::Method::optionalArguments
bool optionalArguments() const
Are any of the arguments optional?
Definition: Method.h:242
gnash::get
T * get(as_object *o)
Extract the DisplayObject attached to an object.
Definition: as_object.h:842
length
@ length
Definition: klash_part.cpp:329
gnash::CodeStream
Definition: CodeStream.h:41
gnash::abc::Method::initTraits
void initTraits(AbcBlock &bl)
Initialize Traits. This is bogus.
Definition: Method.cpp:82
gnash::Property
An abstract property.
Definition: Property.h:277
gnash::abc::Method::setSuper
void setSuper(Method *s)
gnash::abc::Machine
The virtual machine for executing ABC (ActionScript Bytecode).
Definition: Machine.h:74
gnash::abc::Class
A class to represent AS3 Classes.
Definition: Class.h:76
gnash::abc::Method::unsetFinal
void unsetFinal()
Unset the method as final. Not final anymore.
Definition: Method.h:190
gnash::as_value::to_object
as_object * to_object(VM &vm) const
Return value as an object, converting primitive values as needed.
Definition: as_value.cpp:453
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
VM.h
gnash::abc::Method::addMemberScript
bool addMemberScript(string_table::key name, Namespace *ns, std::uint32_t slotID, Class *type)
Definition: Method.cpp:162
Method.h
gnash::CodeStream::seekTo
void seekTo(unsigned int set)
Set the current position to an absolute value (relative to the start)
Definition: CodeStream.cpp:75
gnash::abc::Method::setFinal
void setFinal()
Set the method as final.
Definition: Method.h:186
gnash::log_parse
void log_parse(StringType msg, Args... args)
Definition: log.h:313
gnash::abc::Method::addGetter
bool addGetter(string_table::key name, Namespace *ns, Method *method)
Definition: Method.cpp:122
log.h
gnash::abc::Method::setPublic
void setPublic()
Make the method public.
Definition: Method.h:217
gnash::abc::Method::scopeDepth
std::uint32_t scopeDepth() const
Definition: Method.h:101
gnash::abc::Method::isFinal
bool isFinal() const
Is the method final? If so, it may not be overridden.
Definition: Method.h:182
gnash::abc::Method::construct
as_object * construct(as_object *)
Definition: Method.h:123
gnashconfig.h
gnash::abc::abc_function
ABC-defined Function.
Definition: abc_function.h:41
gnash::abc::Method::setMaxScope
void setMaxScope(std::uint32_t max)
Definition: Method.h:89
gnash::RcInitFile::getDefaultInstance
static RcInitFile & getDefaultInstance()
Return the default instance of RC file.
Definition: rc.cpp:61
namedStrings.h
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
AbcBlock.h
gnash::as_object::set_member
virtual bool set_member(const ObjectURI &uri, const as_value &val, bool ifFound=false)
Set a member value.
Definition: as_object.cpp:583
test.uri
uri
Definition: test.py:12
gnash::abc::Method::getArgumentList
const ArgumentList & getArgumentList() const
Get a reference to a list of argument types.
Definition: Method.h:249
gnash::abc::Method::addSetter
bool addSetter(string_table::key name, Namespace *ns, Method *method)
Definition: Method.cpp:142
gnash::NSV::INTERNAL_TYPE
@ INTERNAL_TYPE
Definition: namedStrings.h:276
gnash::abc::Method::setMinArgumentCount
void setMinArgumentCount(int i)
Set the required minimum arguments.
Definition: Method.h:225
gnash::abc::Method::setBody
void setBody(CodeStream *b)
Definition: Method.h:137
abc_function.h
gnash::abc::Method::setBodyLength
void setBodyLength(std::uint32_t length)
Definition: Method.h:79
getclocktime.hpp
gnash::string_table::key
std::size_t key
Definition: string_table.h:83
gnash::abc::Method::setReturnType
void setReturnType(Class *t)
Set the return type.
Definition: Method.cpp:89
gnash::abc::Method::addSlot
bool addSlot(string_table::key name, Namespace *ns, std::uint32_t slotID, Class *type)
Definition: Method.cpp:169
gnash::abc::Method::maxScope
std::uint32_t maxScope() const
Definition: Method.h:93
gnash::abc::Method::maxArgumentCount
int maxArgumentCount() const
How many arguments are allowed? -1 means unknown.
Definition: Method.h:228
gnash::abc::Method::hasBody
bool hasBody() const
Definition: Method.h:121
gnash::PropFlags::readOnly
@ readOnly
Protect from assigning a value.
Definition: PropFlags.h:42
gnash::abc::Method::initPrototype
void initPrototype(Machine *machine)
Definition: Method.cpp:190
gnash::NSV::PROP_PROTOTYPE
@ PROP_PROTOTYPE
Definition: namedStrings.h:87
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::as_value::is_object
bool is_object() const
Return true if this value is an object.
Definition: as_value.h:219
gnash::abc::Method::setMethodID
void setMethodID(std::uint32_t m)
Definition: Method.h:65
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::abc::Method::setNeedsActivation
void setNeedsActivation()
Definition: Method.h:132
test.v
v
Definition: test.py:11
gnash::abc::Method::getBody
CodeStream * getBody()
Definition: Method.h:136
gnash::abc::Method::getReturnType
Class * getReturnType() const
Get the unique identifier for the return type. 0 is 'anything'. (This is the value of any dynamic pro...
gnash::abc::Method::print_body
void print_body()
Print the opcodes that define a method using log_parse.
Definition: Method.cpp:56
gnash::abc::Method::isProtected
bool isProtected() const
Is the method protected?
Definition: Method.h:204
gnash::abc::Method::setMaxRegisters
void setMaxRegisters(std::uint32_t maxRegisters)
Definition: Method.h:73
gnash::abc::Method::getPrototype
abc_function * getPrototype()
Definition: Method.h:105
gnash::abc::Method::minArgumentCount
int minArgumentCount() const
How many arguments are required? -1 means unknown.
Definition: Method.h:222
gnash::as_function
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:63
gnash::as_object::getOwnProperty
Property * getOwnProperty(const ObjectURI &uri)
Get this object's own named property, if existing.
Definition: as_object.cpp:926