Gnash  0.8.10
Class.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_ABC_CLASS_H
00020 #define GNASH_ABC_CLASS_H
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025 
00026 #include <list>
00027 #include <map>
00028 #include <vector>
00029 #include "string_table.h"
00030 #include "Property.h"
00031 #include "AbcBlock.h"
00032 
00033 namespace gnash {
00034     namespace abc {
00035         class Machine;
00036         class MultiName;
00037         class abc_function;
00038         class BoundValue;
00039         class BoundAccessor;
00040         class Method;
00041         class Class;
00042         class Namespace;
00043     }
00044     class ClassHierarchy;
00045     class Property;
00046     class as_value;
00047 }
00048 
00049 namespace gnash {
00050 namespace abc {
00051 
00053 //
00057 //
00059 //
00062 //
00070 //
00075 class Class
00076 {
00077 public:
00078 
00079         Class()
00080         :
00081         _prototype(0),
00082         _final(false),
00083         _sealed(false),
00084         _dynamic(false),
00085                 _interface(false),
00086         _name(0),
00087         _interfaces(),
00088         _protectedNs(0),
00089                 _super(0),
00090         _constructor(0),
00091         _staticConstructor(0),
00092                 _bindings(),
00093         _staticBindings(),
00094         _declared(false),
00095         _inherited(false),
00096                 _system(false)
00097         {}
00098         
00099     void setDeclared() { _declared = true; }
00100         bool isDeclared() { return _declared; }
00101         void setInherited() { _inherited = true; }
00102         bool isInherited() { return _inherited; }
00103 
00104         void setSystem() { _system = true; }
00105         void unsetSystem() { _system = false; }
00106         bool isSystem() { return _system; }
00107         
00109         void setName(string_table::key name) { _name = name; }
00110 
00111         void dump();
00112 
00113         bool addValue(string_table::key name, Namespace *ns,
00114             boost::uint32_t slotID, Class *type, as_value& val,
00115             bool isconst, bool isstatic);
00116 
00117         bool addSlot(string_table::key name, Namespace *ns,
00118             boost::uint32_t slotID, Class *type, bool isstatic);
00119 
00120         bool addMethod(string_table::key name, Namespace *ns, Method *method,
00121                 bool isstatic);
00122 
00123         bool addGetter(string_table::key name, Namespace *ns, Method *method,
00124                 bool isstatic);
00125 
00126         bool addSetter(string_table::key name, Namespace *ns, Method *method,
00127                 bool isstatic);
00128 
00129         bool addMemberScript(string_table::key name, Namespace *ns,
00130                 boost::uint32_t slotID, Class *type, bool isstatic);
00131 
00132         // TODO: Figure out how this differs from addMethod
00133         bool addSlotFunction(string_table::key name, Namespace *ns,
00134                 boost::uint32_t slotID, Method *method, bool isstatic);
00135 
00137         bool isFinal() const { return _final; }
00138 
00140         void setFinal() { _final = true; }
00141 
00143         void unsetFinal() { _final = false; }
00144 
00146         bool isSealed() const { return _sealed; }
00147 
00149         void setSealed() { _sealed = true; }
00150 
00151         // Set the class as not sealed.
00152         void unsetSealed() { _sealed = false; }
00153 
00155         bool isInterface() const { return _interface; }
00156 
00158         void setInterface() { _interface = true; }
00159 
00161         void unsetInterface() { _interface = false; }
00162 
00164         bool isDynamic() const { return _dynamic; }
00165 
00167         void setDynamic() { _dynamic = true; }
00168 
00170         void unsetDynamic() { _dynamic = false; }
00171 
00173         bool hasProtectedNs() const { return _protectedNs; }
00174 
00176         Namespace* getProtectedNs() { return _protectedNs; }
00177 
00179         void setProtectedNs(Namespace *n) { _protectedNs = n; }
00180 
00182         string_table::key getName() const { return _name; }
00183         
00185     Class* getSuper() const { return _super; }
00186 
00188     //
00190         void setSuper(Class *p) { _super = p; }
00191 
00193         void pushInterface(Class* p) { _interfaces.push_back(p); }
00194 
00196     //
00198         void setConstructor(Method *m) { _constructor = m; }
00199 
00201     //
00204         Method* getConstructor() const {
00205         return _constructor;
00206     }
00207 
00209     //
00211         void setStaticConstructor(Method *m) { _staticConstructor = m; }
00212 
00214     //
00216     Method* getStaticConstructor() const { 
00217         return _staticConstructor;
00218     }
00219 
00220     void addStaticTrait(const Trait& t) {
00221         _staticTraits.push_back(t);
00222     }
00223 
00224     void addInstanceTrait(const Trait& t) {
00225         _instanceTraits.push_back(t);
00226     }
00227 
00228         Property* getBinding(string_table::key name)
00229         {
00230                 BindingContainer::iterator i;
00231                 if (_bindings.empty()) return NULL;
00232                 i = _bindings.find(name);
00233                 if (i == _bindings.end())
00234                         return NULL;
00235                 return &i->second;
00236         }
00237 
00238         Property* getGetBinding(as_value& v, abc::MultiName& n);
00239         Property* getSetBinding(as_value& v, abc::MultiName& n);
00240 
00242     //
00245     void initTraits(AbcBlock& bl);
00246 
00248     void setPrototype(as_object* prototype) {
00249         _prototype = prototype;
00250     }
00251 
00253         void initPrototype();
00254 
00256         as_object* getPrototype() { return _prototype; }
00257 
00258 private:
00259 
00260         bool addBinding(string_table::key name, const Property& b) {
00261         _bindings.insert(std::make_pair(name, b));
00262         return true;
00263     }
00264 
00265         bool addStaticBinding(string_table::key name, const Property& b) {
00266         _staticBindings.insert(std::make_pair(name, b));
00267         return true;
00268     }
00269 
00270         Property *getStaticBinding(string_table::key name)
00271         {
00272                 if (_staticBindings.empty()) return 0;
00273                 BindingContainer::iterator i = _staticBindings.find(name);
00274                 if (i == _staticBindings.end()) return 0;
00275                 return &i->second;
00276         }
00277 
00278     
00280     std::vector<Trait> _instanceTraits;
00281 
00283     std::vector<Trait> _staticTraits;
00284 
00285         
00286         typedef std::map<string_table::key, Property> BindingContainer;
00287 
00288     as_object *_prototype;
00289         bool _final;
00290         bool _sealed;
00291         bool _dynamic;
00292         bool _interface;
00293         string_table::key _name;
00294         std::list<Class*> _interfaces;
00295         Namespace* _protectedNs;
00296         Class* _super;
00297         Method* _constructor;
00298         Method* _staticConstructor;
00299 
00300         BindingContainer _bindings;
00301         BindingContainer _staticBindings;
00302         bool _declared;
00303         bool _inherited;
00304         bool _system;
00305 };
00306 
00307 } // namespace abc 
00308 } // namespace gnash
00309 
00310 #endif