Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libcore / abc / Method.h
blob1dd5a2686fd76ef6d3ea505fc587b43db6322d33
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
19 #ifndef GNASH_AS_METHOD_H
20 #define GNASH_AS_METHOD_H
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h"
24 #endif
26 #include "string_table.h"
27 #include "AbcBlock.h"
29 #include <map>
30 #include <vector>
31 #include <list>
33 // Forward declarations
34 namespace gnash {
35 namespace abc {
36 class Machine;
37 class abc_function;
38 class Namespace;
39 class Class;
41 class CodeStream;
42 class as_object;
45 namespace gnash {
46 namespace abc {
48 typedef Property asBinding;
50 /// A class to represent, abstractly, an ActionScript method.
51 ///
52 /// Methods are unnamed until they are bound to an object.
53 class Method
55 public:
57 typedef std::list<Class*> ArgumentList;
59 Method();
61 std::uint32_t methodID() const {
62 return _methodID;
65 void setMethodID(std::uint32_t m) {
66 _methodID = m;
69 void initPrototype(Machine* machine);
71 std::uint32_t getMaxRegisters() { return _maxRegisters;}
73 void setMaxRegisters(std::uint32_t maxRegisters) {
74 _maxRegisters = maxRegisters;
77 std::uint32_t getBodyLength(){ return _bodyLength;}
79 void setBodyLength(std::uint32_t length){ _bodyLength = length;}
81 void setMaxStack(std::uint32_t max) {
82 _maxStack = max;
85 std::uint32_t maxStack() const {
86 return _maxStack;
89 void setMaxScope(std::uint32_t max) {
90 _maxScope = max;
93 std::uint32_t maxScope() const {
94 return _maxScope;
97 void setScopeDepth(std::uint32_t depth) {
98 _scopeDepth = depth;
101 std::uint32_t scopeDepth() const {
102 return _scopeDepth;
105 abc_function* getPrototype() { return _prototype; }
107 /// Add a Trait to this Method.
108 void addTrait(const Trait& t) {
109 _traits.push_back(t);
113 /// Initialize Traits. This is bogus.
115 /// TODO: fix!
116 void initTraits(AbcBlock& bl);
118 asBinding* getBinding(string_table::key name);
120 bool isNative() { return _isNative; }
121 bool hasBody() const { return _body != NULL; }
123 as_object* construct(as_object* /*base_scope*/) {
124 // TODO:
125 return NULL;
128 bool needsActivation() const {
129 return _needsActivation;
132 void setNeedsActivation() {
133 _needsActivation = true;
136 CodeStream *getBody() { return _body; }
137 void setBody(CodeStream *b) { _body = b; }
139 bool addValue(string_table::key name, Namespace *ns,
140 std::uint32_t slotID, Class *type, as_value& val, bool isconst);
142 bool addSlot(string_table::key name, Namespace *ns,
143 std::uint32_t slotID, Class *type);
145 bool addMethod(string_table::key name, Namespace *ns, Method *method);
147 bool addGetter(string_table::key name, Namespace *ns, Method *method);
149 bool addSetter(string_table::key name, Namespace *ns, Method *method);
151 bool addMemberScript(string_table::key name, Namespace *ns,
152 std::uint32_t slotID, Class *type);
154 bool addSlotFunction(string_table::key name, Namespace *ns,
155 std::uint32_t slotID, Method *method);
157 /// \brief
158 /// Set the owner of this method.
159 void setOwner(Class* s);
161 /// \brief
162 /// Get the unique identifier for the return type. 0 is 'anything'.
163 /// (This is the value of any dynamic property.)
164 /// Id reference: Type
165 Class* getReturnType() const;
167 /// Set the return type
169 /// TODO: This is currently a no-op, so find out what it's for and
170 /// implement it.
171 /// NB: the return type of a method can be * (any) or void, neither of
172 /// which are known names, so this may not be an appropriate way to
173 /// handle return type.
174 void setReturnType(Class* t);
176 Method *getSuper();
178 void setSuper(Method* s);
180 /// \brief
181 /// Is the method final? If so, it may not be overridden.
182 bool isFinal() const { return _flags & FLAGS_FINAL; }
184 /// \brief
185 /// Set the method as final.
186 void setFinal() { _flags = _flags | FLAGS_FINAL; }
188 /// \brief
189 /// Unset the method as final. Not final anymore.
190 void unsetFinal() { _flags = _flags & ~FLAGS_FINAL; }
192 /// \brief
193 /// Is the method private?
194 bool isPrivate() const { return _flags & FLAGS_PRIVATE; }
196 /// \brief
197 /// Make the method private.
198 void setPrivate() {
199 _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PROTECTED)) | FLAGS_PRIVATE;
202 /// \brief
203 /// Is the method protected?
204 bool isProtected() const {
205 return _flags & FLAGS_PROTECTED;
208 /// \brief
209 /// Make the method protected.
210 void setProtected() {
211 _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PRIVATE)) | FLAGS_PROTECTED; }
213 /// Is the method public?
214 bool isPublic() const { return _flags & FLAGS_PUBLIC; }
216 /// Make the method public.
217 void setPublic() {
218 _flags = (_flags & ~(FLAGS_PRIVATE | FLAGS_PROTECTED)) | FLAGS_PUBLIC;
221 /// How many arguments are required? -1 means unknown.
222 int minArgumentCount() const { return _minArguments; }
224 /// Set the required minimum arguments.
225 void setMinArgumentCount(int i) { _minArguments = i; }
227 /// How many arguments are allowed? -1 means unknown.
228 int maxArgumentCount() const { return _maxArguments; }
230 /// Set the required maximum arguments.
231 void setMaxArgumentCount(int i) { _maxArguments = i; }
233 /// Push an argument of type t into the method definition
235 /// A value of 0 stands for 'any'.
236 void pushArgument(Class* t) { _arguments.push_back(t); }
238 /// Push an optional argument's default value.
239 void pushOptional(const as_value& v) { _optionalArguments.push_back(v); }
241 /// Are any of the arguments optional?
242 bool optionalArguments() const {
243 return minArgumentCount() != maxArgumentCount();
246 /// Get a reference to a list of argument types.
248 /// NB: Some values may be 0, meaning "any".
249 const ArgumentList& getArgumentList() const { return _arguments; }
251 /// \brief
252 /// Get an object capable of executing this function.
253 /// Note: This may be NULL, because we might have information about this
254 /// function but not actually have it yet.
255 as_function* getImplementation() { return _implementation; }
257 /// \brief
258 /// Print the opcodes that define a method using log_parse.
259 void print_body();
261 private:
263 enum Flag
265 FLAGS_FINAL = 0x01,
266 FLAGS_PROTECTED = 0x02,
267 FLAGS_PUBLIC = 0x04,
268 FLAGS_PRIVATE = 0x08
271 /// A list of type identifiers
272 typedef std::map<string_table::key, asBinding> BindingContainer;
274 bool addBinding(string_table::key name, asBinding b);
276 std::vector<Trait> _traits;
278 std::uint32_t _methodID;
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;
292 std::uint32_t _scopeDepth;
293 std::uint32_t _maxScope;
294 std::uint32_t _maxStack;
296 bool _needsActivation;
300 } // namespace abc
301 } // namespace gnash
303 #endif