00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GNASH_ABC_CLASS_H
00019 #define GNASH_ABC_CLASS_H
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include "gnashconfig.h"
00023 #endif
00024
00025 #include <list>
00026 #include <map>
00027 #include <vector>
00028 #include "string_table.h"
00029 #include "Property.h"
00030 #include "AbcBlock.h"
00031
00032 namespace gnash {
00033 namespace abc {
00034 class Machine;
00035 class MultiName;
00036 class abc_function;
00037 class BoundValue;
00038 class BoundAccessor;
00039 class Method;
00040 class Class;
00041 class Namespace;
00042 }
00043 class ClassHierarchy;
00044 class Property;
00045 class as_value;
00046 }
00047
00048 namespace gnash {
00049 namespace abc {
00050
00052
00056
00058
00061
00069
00074 class Class
00075 {
00076 public:
00077
00078 Class()
00079 :
00080 _prototype(0),
00081 _final(false),
00082 _sealed(false),
00083 _dynamic(false),
00084 _interface(false),
00085 _name(0),
00086 _interfaces(),
00087 _protectedNs(0),
00088 _super(0),
00089 _constructor(0),
00090 _staticConstructor(0),
00091 _bindings(),
00092 _staticBindings(),
00093 _declared(false),
00094 _inherited(false),
00095 _system(false)
00096 {}
00097
00098 void setDeclared() { _declared = true; }
00099 bool isDeclared() { return _declared; }
00100 void setInherited() { _inherited = true; }
00101 bool isInherited() { return _inherited; }
00102
00103 void setSystem() { _system = true; }
00104 void unsetSystem() { _system = false; }
00105 bool isSystem() { return _system; }
00106
00108 void setName(string_table::key name) { _name = name; }
00109
00110 void dump();
00111
00112 bool addValue(string_table::key name, Namespace *ns,
00113 boost::uint32_t slotID, Class *type, as_value& val,
00114 bool isconst, bool isstatic);
00115
00116 bool addSlot(string_table::key name, Namespace *ns,
00117 boost::uint32_t slotID, Class *type, bool isstatic);
00118
00119 bool addMethod(string_table::key name, Namespace *ns, Method *method,
00120 bool isstatic);
00121
00122 bool addGetter(string_table::key name, Namespace *ns, Method *method,
00123 bool isstatic);
00124
00125 bool addSetter(string_table::key name, Namespace *ns, Method *method,
00126 bool isstatic);
00127
00128 bool addMemberScript(string_table::key name, Namespace *ns,
00129 boost::uint32_t slotID, Class *type, bool isstatic);
00130
00131
00132 bool addSlotFunction(string_table::key name, Namespace *ns,
00133 boost::uint32_t slotID, Method *method, bool isstatic);
00134
00136 bool isFinal() const { return _final; }
00137
00139 void setFinal() { _final = true; }
00140
00142 void unsetFinal() { _final = false; }
00143
00145 bool isSealed() const { return _sealed; }
00146
00148 void setSealed() { _sealed = true; }
00149
00150
00151 void unsetSealed() { _sealed = false; }
00152
00154 bool isInterface() const { return _interface; }
00155
00157 void setInterface() { _interface = true; }
00158
00160 void unsetInterface() { _interface = false; }
00161
00163 bool isDynamic() const { return _dynamic; }
00164
00166 void setDynamic() { _dynamic = true; }
00167
00169 void unsetDynamic() { _dynamic = false; }
00170
00172 bool hasProtectedNs() const { return _protectedNs; }
00173
00175 Namespace* getProtectedNs() { return _protectedNs; }
00176
00178 void setProtectedNs(Namespace *n) { _protectedNs = n; }
00179
00181 string_table::key getName() const { return _name; }
00182
00184 Class* getSuper() const { return _super; }
00185
00187
00189 void setSuper(Class *p) { _super = p; }
00190
00192 void pushInterface(Class* p) { _interfaces.push_back(p); }
00193
00195
00197 void setConstructor(Method *m) { _constructor = m; }
00198
00200
00203 Method* getConstructor() const {
00204 return _constructor;
00205 }
00206
00208
00210 void setStaticConstructor(Method *m) { _staticConstructor = m; }
00211
00213
00215 Method* getStaticConstructor() const {
00216 return _staticConstructor;
00217 }
00218
00219 void addStaticTrait(const Trait& t) {
00220 _staticTraits.push_back(t);
00221 }
00222
00223 void addInstanceTrait(const Trait& t) {
00224 _instanceTraits.push_back(t);
00225 }
00226
00227 Property* getBinding(string_table::key name)
00228 {
00229 BindingContainer::iterator i;
00230 if (_bindings.empty()) return NULL;
00231 i = _bindings.find(name);
00232 if (i == _bindings.end())
00233 return NULL;
00234 return &i->second;
00235 }
00236
00237 Property* getGetBinding(as_value& v, abc::MultiName& n);
00238 Property* getSetBinding(as_value& v, abc::MultiName& n);
00239
00241
00244 void initTraits(AbcBlock& bl);
00245
00247 void setPrototype(as_object* prototype) {
00248 _prototype = prototype;
00249 }
00250
00252 void initPrototype();
00253
00255 as_object* getPrototype() { return _prototype; }
00256
00257 private:
00258
00259 bool addBinding(string_table::key name, const Property& b) {
00260 _bindings.insert(std::make_pair(name, b));
00261 return true;
00262 }
00263
00264 bool addStaticBinding(string_table::key name, const Property& b) {
00265 _staticBindings.insert(std::make_pair(name, b));
00266 return true;
00267 }
00268
00269 Property *getStaticBinding(string_table::key name)
00270 {
00271 if (_staticBindings.empty()) return 0;
00272 BindingContainer::iterator i = _staticBindings.find(name);
00273 if (i == _staticBindings.end()) return 0;
00274 return &i->second;
00275 }
00276
00277
00279 std::vector<Trait> _instanceTraits;
00280
00282 std::vector<Trait> _staticTraits;
00283
00284
00285 typedef std::map<string_table::key, Property> BindingContainer;
00286
00287 as_object *_prototype;
00288 bool _final;
00289 bool _sealed;
00290 bool _dynamic;
00291 bool _interface;
00292 string_table::key _name;
00293 std::list<Class*> _interfaces;
00294 Namespace* _protectedNs;
00295 Class* _super;
00296 Method* _constructor;
00297 Method* _staticConstructor;
00298
00299 BindingContainer _bindings;
00300 BindingContainer _staticBindings;
00301 bool _declared;
00302 bool _inherited;
00303 bool _system;
00304 };
00305
00306 }
00307 }
00308
00309 #endif