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 
118  asBinding* getBinding(string_table::key name);
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 
139  bool addValue(string_table::key name, Namespace *ns,
140  std::uint32_t slotID, Class *type, as_value& val, bool isconst);
141 
142  bool addSlot(string_table::key name, Namespace *ns,
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 
151  bool addMemberScript(string_table::key name, Namespace *ns,
152  std::uint32_t slotID, Class *type);
153 
154  bool addSlotFunction(string_table::key name, Namespace *ns,
155  std::uint32_t slotID, Method *method);
156 
159  void setOwner(Class* s);
160 
165  Class* getReturnType() const;
166 
168  //
174  void setReturnType(Class* t);
175 
176  Method *getSuper();
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
void setFinal()
Set the method as final.
Definition: Method.h:186
bool hasBody() const
Definition: Method.h:121
The ActionScript bytecode of a single ABC tag in a SWF.
Definition: AbcBlock.h:208
Class describing a static property.
Definition: AbcBlock.h:71
CodeStream * getBody()
Definition: Method.h:136
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
bool isNative()
Definition: Method.h:120
void pushArgument(Class *t)
Push an argument of type t into the method definition.
Definition: Method.h:236
ActionScript value type.
Definition: as_value.h:94
An abstract property.
Definition: Property.h:276
void setMaxStack(std::uint32_t max)
Definition: Method.h:81
int maxArgumentCount() const
How many arguments are allowed? -1 means unknown.
Definition: Method.h:228
v
Definition: test.py:11
void setMaxArgumentCount(int i)
Set the required maximum arguments.
Definition: Method.h:231
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setMaxScope(std::uint32_t max)
Definition: Method.h:89
void setMaxRegisters(std::uint32_t maxRegisters)
Definition: Method.h:73
abc_function * getPrototype()
Definition: Method.h:105
type
Definition: GnashKey.h:329
std::uint32_t maxScope() const
Definition: Method.h:93
Represent an ActionScript Namespace.
Definition: Namespace.h:48
void setScopeDepth(std::uint32_t depth)
Definition: Method.h:97
void setPrivate()
Make the method private.
Definition: Method.h:198
The base class for all ActionScript objects.
Definition: as_object.h:161
bool isFinal() const
Is the method final? If so, it may not be overridden.
Definition: Method.h:182
void setBody(CodeStream *b)
Definition: Method.h:137
Definition: CodeStream.h:40
void setMinArgumentCount(int i)
Set the required minimum arguments.
Definition: Method.h:225
Definition: GnashKey.h:166
as_object * construct(as_object *)
Definition: Method.h:123
void setNeedsActivation()
Definition: Method.h:132
A class to represent AS3 Classes.
Definition: Class.h:75
bool isPrivate() const
Is the method private?
Definition: Method.h:194
const ArgumentList & getArgumentList() const
Get a reference to a list of argument types.
Definition: Method.h:249
int minArgumentCount() const
How many arguments are required? -1 means unknown.
Definition: Method.h:222
Property asBinding
Definition: Method.h:48
std::uint32_t scopeDepth() const
Definition: Method.h:101
void setMethodID(std::uint32_t m)
Definition: Method.h:65
Definition: klash_part.cpp:329
void setProtected()
Make the method protected.
Definition: Method.h:210
bool needsActivation() const
Definition: Method.h:128
Definition: GnashKey.h:148
void pushOptional(const as_value &v)
Push an optional argument&#39;s default value.
Definition: Method.h:239
void setBodyLength(std::uint32_t length)
Definition: Method.h:79
The virtual machine for executing ABC (ActionScript Bytecode).
Definition: Machine.h:73
bool isProtected() const
Is the method protected?
Definition: Method.h:204
std::uint32_t methodID() const
Definition: Method.h:61
std::uint32_t getMaxRegisters()
Definition: Method.h:71
bool isPublic() const
Is the method public?
Definition: Method.h:214
void unsetFinal()
Unset the method as final. Not final anymore.
Definition: Method.h:190
Definition: GnashKey.h:155
std::list< Class * > ArgumentList
Definition: Method.h:57
Definition: GnashKey.h:159
std::uint32_t getBodyLength()
Definition: Method.h:77
Definition: GnashKey.h:165
ABC-defined Function.
Definition: abc_function.h:40
Definition: Method.h:53
std::size_t key
Definition: string_table.h:83
std::string name
Definition: LocalConnection_as.cpp:149
std::uint32_t maxStack() const
Definition: Method.h:85
void addTrait(const Trait &t)
Add a Trait to this Method.
Definition: Method.h:108
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:62
bool optionalArguments() const
Are any of the arguments optional?
Definition: Method.h:242
void setPublic()
Make the method public.
Definition: Method.h:217