Gnash  0.8.10
Method.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_AS_METHOD_H
00020 #define GNASH_AS_METHOD_H
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025 
00026 #include "string_table.h"
00027 #include "AbcBlock.h"
00028 
00029 #include <map>
00030 #include <vector>
00031 #include <list>
00032 
00033 // Forward declarations
00034 namespace gnash {
00035     namespace abc {
00036         class Machine;
00037         class abc_function;
00038         class Namespace;
00039         class Class;
00040     }
00041     class CodeStream;
00042     class as_object;
00043 }
00044 
00045 namespace gnash {
00046 namespace abc {
00047 
00048 typedef Property asBinding;
00049 
00053 class Method
00054 {
00055 public:
00056         
00057     typedef std::list<Class*> ArgumentList;
00058 
00059         Method();
00060 
00061     boost::uint32_t methodID() const {
00062         return _methodID;
00063     }
00064 
00065     void setMethodID(boost::uint32_t m) {
00066         _methodID = m;
00067     }
00068 
00069         void initPrototype(Machine* machine);
00070 
00071         boost::uint32_t getMaxRegisters() { return _maxRegisters;}
00072 
00073         void setMaxRegisters(boost::uint32_t maxRegisters) { 
00074         _maxRegisters = maxRegisters;
00075     }
00076 
00077         boost::uint32_t getBodyLength(){ return _bodyLength;}
00078 
00079         void setBodyLength(boost::uint32_t length){ _bodyLength = length;}
00080 
00081     void setMaxStack(boost::uint32_t max) {
00082         _maxStack = max;
00083     }
00084  
00085     boost::uint32_t maxStack() const {
00086         return _maxStack;
00087     }
00088 
00089     void setMaxScope(boost::uint32_t max) {
00090         _maxScope = max;
00091     }
00092  
00093     boost::uint32_t maxScope() const {
00094         return _maxScope;
00095     }
00096     
00097     void setScopeDepth(boost::uint32_t depth) {
00098         _scopeDepth = depth;
00099     }
00100  
00101     boost::uint32_t scopeDepth() const {
00102         return _scopeDepth;
00103     }
00104 
00105     abc_function* getPrototype() { return _prototype; }
00106 
00108     void addTrait(const Trait& t) {
00109         _traits.push_back(t);
00110     }
00111 
00112 
00114     //
00116     void initTraits(AbcBlock& bl);
00117 
00118         asBinding* getBinding(string_table::key name);
00119 
00120         bool isNative() { return _isNative; }
00121         bool hasBody() const { return _body != NULL; }
00122 
00123         as_object* construct(as_object* /*base_scope*/) {
00124         // TODO:
00125         return NULL;
00126     }
00127 
00128         bool needsActivation() const {
00129         return _needsActivation;
00130     }
00131 
00132     void setNeedsActivation() {
00133         _needsActivation = true;
00134     }
00135 
00136         CodeStream *getBody() { return _body; }
00137         void setBody(CodeStream *b) { _body = b; }
00138 
00139         bool addValue(string_table::key name, Namespace *ns,
00140             boost::uint32_t slotID, Class *type, as_value& val, bool isconst);
00141 
00142         bool addSlot(string_table::key name, Namespace *ns,
00143             boost::uint32_t slotID, Class *type);
00144 
00145         bool addMethod(string_table::key name, Namespace *ns, Method *method);
00146 
00147         bool addGetter(string_table::key name, Namespace *ns, Method *method);
00148 
00149         bool addSetter(string_table::key name, Namespace *ns, Method *method);
00150 
00151         bool addMemberScript(string_table::key name, Namespace *ns,
00152                 boost::uint32_t slotID, Class *type);
00153         
00154         bool addSlotFunction(string_table::key name, Namespace *ns,
00155                 boost::uint32_t slotID, Method *method);
00156 
00159         void setOwner(Class* s);
00160 
00165         Class* getReturnType() const;
00166 
00168     //
00174         void setReturnType(Class* t);
00175 
00176         Method *getSuper();
00177 
00178         void setSuper(Method* s);
00179 
00182         bool isFinal() const { return _flags & FLAGS_FINAL; }
00183 
00186         void setFinal() { _flags = _flags | FLAGS_FINAL; }
00187 
00190         void unsetFinal() { _flags = _flags & ~FLAGS_FINAL; }
00191 
00194         bool isPrivate() const { return _flags & FLAGS_PRIVATE; }
00195 
00198         void setPrivate() {
00199         _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PROTECTED)) | FLAGS_PRIVATE;
00200     }
00201 
00204         bool isProtected() const {
00205         return _flags & FLAGS_PROTECTED;
00206     }
00207 
00210         void setProtected() {
00211         _flags = (_flags & ~(FLAGS_PUBLIC | FLAGS_PRIVATE)) | FLAGS_PROTECTED; }
00212 
00214         bool isPublic() const { return _flags & FLAGS_PUBLIC; }
00215 
00217         void setPublic() {
00218         _flags = (_flags & ~(FLAGS_PRIVATE | FLAGS_PROTECTED)) | FLAGS_PUBLIC;
00219     }
00220 
00222         int minArgumentCount() const { return _minArguments; }
00223 
00225         void setMinArgumentCount(int i) { _minArguments = i; }
00226 
00228         int maxArgumentCount() const { return _maxArguments; }
00229 
00231         void setMaxArgumentCount(int i) { _maxArguments = i; }
00232 
00234     //
00236         void pushArgument(Class* t) { _arguments.push_back(t); }
00237 
00239         void pushOptional(const as_value& v) { _optionalArguments.push_back(v); }
00240 
00242         bool optionalArguments() const {
00243         return minArgumentCount() != maxArgumentCount();
00244     }
00245 
00247     //
00249         const ArgumentList& getArgumentList() const { return _arguments; }
00250 
00255         as_function* getImplementation() { return _implementation; }
00256 
00259         void print_body();
00260 
00261 private:
00262 
00263         enum Flag
00264         {
00265                 FLAGS_FINAL = 0x01,
00266                 FLAGS_PROTECTED = 0x02,
00267                 FLAGS_PUBLIC = 0x04,
00268                 FLAGS_PRIVATE = 0x08
00269         };
00270 
00272         typedef std::map<string_table::key, asBinding> BindingContainer;
00273 
00274         bool addBinding(string_table::key name, asBinding b);
00275     
00276     std::vector<Trait> _traits;
00277         
00278     boost::uint32_t _methodID;
00279 
00280     abc_function* _prototype;
00281         int _minArguments;
00282         int _maxArguments;
00283         boost::uint32_t _bodyLength;
00284         bool _isNative;
00285         ArgumentList _arguments;
00286         std::list<as_value> _optionalArguments;
00287         as_function* _implementation;
00288         unsigned char _flags;
00289         CodeStream* _body;
00290         boost::uint32_t _maxRegisters;
00291 
00292     boost::uint32_t _scopeDepth;
00293     boost::uint32_t _maxScope;
00294     boost::uint32_t _maxStack;
00295 
00296     bool _needsActivation;
00297 
00298 };
00299 
00300 } // namespace abc
00301 } // namespace gnash
00302 
00303 #endif