2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
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.
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.
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
23 #include "gnashconfig.h"
26 #include "string_table.h"
33 // Forward declarations
48 typedef Property asBinding
;
50 /// A class to represent, abstractly, an ActionScript method.
52 /// Methods are unnamed until they are bound to an object.
57 typedef std::list
<Class
*> ArgumentList
;
61 std::uint32_t methodID() const {
65 void setMethodID(std::uint32_t 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
) {
85 std::uint32_t maxStack() const {
89 void setMaxScope(std::uint32_t max
) {
93 std::uint32_t maxScope() const {
97 void setScopeDepth(std::uint32_t depth
) {
101 std::uint32_t scopeDepth() const {
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.
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*/) {
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
);
158 /// Set the owner of this method.
159 void setOwner(Class
* s
);
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
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
);
178 void setSuper(Method
* s
);
181 /// Is the method final? If so, it may not be overridden.
182 bool isFinal() const { return _flags
& FLAGS_FINAL
; }
185 /// Set the method as final.
186 void setFinal() { _flags
= _flags
| FLAGS_FINAL
; }
189 /// Unset the method as final. Not final anymore.
190 void unsetFinal() { _flags
= _flags
& ~FLAGS_FINAL
; }
193 /// Is the method private?
194 bool isPrivate() const { return _flags
& FLAGS_PRIVATE
; }
197 /// Make the method private.
199 _flags
= (_flags
& ~(FLAGS_PUBLIC
| FLAGS_PROTECTED
)) | FLAGS_PRIVATE
;
203 /// Is the method protected?
204 bool isProtected() const {
205 return _flags
& FLAGS_PROTECTED
;
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.
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
; }
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
; }
258 /// Print the opcodes that define a method using log_parse.
266 FLAGS_PROTECTED
= 0x02,
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
;
283 std::uint32_t _bodyLength
;
285 ArgumentList _arguments
;
286 std::list
<as_value
> _optionalArguments
;
287 as_function
* _implementation
;
288 unsigned char _flags
;
290 std::uint32_t _maxRegisters
;
292 std::uint32_t _scopeDepth
;
293 std::uint32_t _maxScope
;
294 std::uint32_t _maxStack
;
296 bool _needsActivation
;