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