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  boost::uint32_t methodID() const {
62  return _methodID;
63  }
64 
65  void setMethodID(boost::uint32_t m) {
66  _methodID = m;
67  }
68 
69  void initPrototype(Machine* machine);
70 
71  boost::uint32_t getMaxRegisters() { return _maxRegisters;}
72 
73  void setMaxRegisters(boost::uint32_t maxRegisters) {
74  _maxRegisters = maxRegisters;
75  }
76 
77  boost::uint32_t getBodyLength(){ return _bodyLength;}
78 
79  void setBodyLength(boost::uint32_t length){ _bodyLength = length;}
80 
81  void setMaxStack(boost::uint32_t max) {
82  _maxStack = max;
83  }
84 
85  boost::uint32_t maxStack() const {
86  return _maxStack;
87  }
88 
89  void setMaxScope(boost::uint32_t max) {
90  _maxScope = max;
91  }
92 
93  boost::uint32_t maxScope() const {
94  return _maxScope;
95  }
96 
97  void setScopeDepth(boost::uint32_t depth) {
98  _scopeDepth = depth;
99  }
100 
101  boost::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 
139  bool addValue(string_table::key name, Namespace *ns,
140  boost::uint32_t slotID, Class *type, as_value& val, bool isconst);
141 
142  bool addSlot(string_table::key name, Namespace *ns,
143  boost::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  boost::uint32_t slotID, Class *type);
153 
155  boost::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  boost::uint32_t _methodID;
279 
280  abc_function* _prototype;
281  int _minArguments;
282  int _maxArguments;
283  boost::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  boost::uint32_t _maxRegisters;
291 
292  boost::uint32_t _scopeDepth;
293  boost::uint32_t _maxScope;
294  boost::uint32_t _maxStack;
295 
296  bool _needsActivation;
297 
298 };
299 
300 } // namespace abc
301 } // namespace gnash
302 
303 #endif