Gnash  0.8.11dev
Class.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
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.
9 //
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.
14 //
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
18 
19 #ifndef GNASH_ABC_CLASS_H
20 #define GNASH_ABC_CLASS_H
21 
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h"
24 #endif
25 
26 #include <list>
27 #include <map>
28 #include <vector>
29 #include "string_table.h"
30 #include "Property.h"
31 #include "AbcBlock.h"
32 
33 namespace gnash {
34  namespace abc {
35  class Machine;
36  class MultiName;
37  class abc_function;
38  class BoundValue;
39  class BoundAccessor;
40  class Method;
41  class Class;
42  class Namespace;
43  }
44  class ClassHierarchy;
45  class Property;
46  class as_value;
47 }
48 
49 namespace gnash {
50 namespace abc {
51 
53 //
57 //
59 //
62 //
70 //
75 class Class
76 {
77 public:
78 
80  :
81  _prototype(0),
82  _final(false),
83  _sealed(false),
84  _dynamic(false),
85  _interface(false),
86  _name(0),
87  _interfaces(),
88  _protectedNs(0),
89  _super(0),
90  _constructor(0),
91  _staticConstructor(0),
92  _bindings(),
93  _staticBindings(),
94  _declared(false),
95  _inherited(false),
96  _system(false)
97  {}
98 
99  void setDeclared() { _declared = true; }
100  bool isDeclared() { return _declared; }
101  void setInherited() { _inherited = true; }
102  bool isInherited() { return _inherited; }
103 
104  void setSystem() { _system = true; }
105  void unsetSystem() { _system = false; }
106  bool isSystem() { return _system; }
107 
109  void setName(string_table::key name) { _name = name; }
110 
111  void dump();
112 
114  std::uint32_t slotID, Class *type, as_value& val,
115  bool isconst, bool isstatic);
116 
118  std::uint32_t slotID, Class *type, bool isstatic);
119 
120  bool addMethod(string_table::key name, Namespace *ns, Method *method,
121  bool isstatic);
122 
123  bool addGetter(string_table::key name, Namespace *ns, Method *method,
124  bool isstatic);
125 
126  bool addSetter(string_table::key name, Namespace *ns, Method *method,
127  bool isstatic);
128 
130  std::uint32_t slotID, Class *type, bool isstatic);
131 
132  // TODO: Figure out how this differs from addMethod
134  std::uint32_t slotID, Method *method, bool isstatic);
135 
137  bool isFinal() const { return _final; }
138 
140  void setFinal() { _final = true; }
141 
143  void unsetFinal() { _final = false; }
144 
146  bool isSealed() const { return _sealed; }
147 
149  void setSealed() { _sealed = true; }
150 
151  // Set the class as not sealed.
152  void unsetSealed() { _sealed = false; }
153 
155  bool isInterface() const { return _interface; }
156 
158  void setInterface() { _interface = true; }
159 
161  void unsetInterface() { _interface = false; }
162 
164  bool isDynamic() const { return _dynamic; }
165 
167  void setDynamic() { _dynamic = true; }
168 
170  void unsetDynamic() { _dynamic = false; }
171 
173  bool hasProtectedNs() const { return _protectedNs; }
174 
176  Namespace* getProtectedNs() { return _protectedNs; }
177 
179  void setProtectedNs(Namespace *n) { _protectedNs = n; }
180 
182  string_table::key getName() const { return _name; }
183 
185  Class* getSuper() const { return _super; }
186 
188  //
190  void setSuper(Class *p) { _super = p; }
191 
193  void pushInterface(Class* p) { _interfaces.push_back(p); }
194 
196  //
198  void setConstructor(Method *m) { _constructor = m; }
199 
201  //
205  return _constructor;
206  }
207 
209  //
211  void setStaticConstructor(Method *m) { _staticConstructor = m; }
212 
214  //
217  return _staticConstructor;
218  }
219 
220  void addStaticTrait(const Trait& t) {
221  _staticTraits.push_back(t);
222  }
223 
224  void addInstanceTrait(const Trait& t) {
225  _instanceTraits.push_back(t);
226  }
227 
229  {
230  BindingContainer::iterator i;
231  if (_bindings.empty()) return NULL;
232  i = _bindings.find(name);
233  if (i == _bindings.end())
234  return NULL;
235  return &i->second;
236  }
237 
240 
242  //
245  void initTraits(AbcBlock& bl);
246 
248  void setPrototype(as_object* prototype) {
249  _prototype = prototype;
250  }
251 
253  void initPrototype();
254 
256  as_object* getPrototype() { return _prototype; }
257 
258 private:
259 
260  bool addBinding(string_table::key name, const Property& b) {
261  _bindings.insert(std::make_pair(name, b));
262  return true;
263  }
264 
265  bool addStaticBinding(string_table::key name, const Property& b) {
266  _staticBindings.insert(std::make_pair(name, b));
267  return true;
268  }
269 
270  Property *getStaticBinding(string_table::key name)
271  {
272  if (_staticBindings.empty()) return 0;
273  BindingContainer::iterator i = _staticBindings.find(name);
274  if (i == _staticBindings.end()) return 0;
275  return &i->second;
276  }
277 
278 
280  std::vector<Trait> _instanceTraits;
281 
283  std::vector<Trait> _staticTraits;
284 
285 
286  typedef std::map<string_table::key, Property> BindingContainer;
287 
288  as_object *_prototype;
289  bool _final;
290  bool _sealed;
291  bool _dynamic;
292  bool _interface;
293  string_table::key _name;
294  std::list<Class*> _interfaces;
295  Namespace* _protectedNs;
296  Class* _super;
297  Method* _constructor;
298  Method* _staticConstructor;
299 
300  BindingContainer _bindings;
301  BindingContainer _staticBindings;
302  bool _declared;
303  bool _inherited;
304  bool _system;
305 };
306 
307 } // namespace abc
308 } // namespace gnash
309 
310 #endif
gnash::abc::Class::setName
void setName(string_table::key name)
Set our Name.
Definition: Class.h:109
gnash::abc::Class::isFinal
bool isFinal() const
Is the class final?
Definition: Class.h:137
gnash::abc::Class::getName
string_table::key getName() const
The global name of the class.
Definition: Class.h:182
gnash::abc::Class::unsetInterface
void unsetInterface()
Set the class as not an interface.
Definition: Class.h:161
gnash::abc::Namespace::getURI
string_table::key getURI() const
What is the Uri of the namespace?
Definition: Namespace.h:76
gnash::abc::Trait
Class describing a static property.
Definition: AbcBlock.h:72
gnash::abc::Class::setConstructor
void setConstructor(Method *m)
Set the iinit method.
Definition: Class.h:198
string_table.h
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::abc::Class::setPrototype
void setPrototype(as_object *prototype)
Necessary for the current bogus implementation.
Definition: Class.h:248
Class.h
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::abc::Class::addSlotFunction
bool addSlotFunction(string_table::key name, Namespace *ns, std::uint32_t slotID, Method *method, bool isstatic)
Definition: Class.cpp:97
as_object.h
gnash::abc::Class::getSuper
Class * getSuper() const
Retrieve the Class from which this Class derives.
Definition: Class.h:185
gnash::abc::Method
Definition: Method.h:54
gnash::abc::Class::addInstanceTrait
void addInstanceTrait(const Trait &t)
Definition: Class.h:224
Namespace.h
gnash::abc::Class::getConstructor
Method * getConstructor() const
Get the iinit method or 'constructor'.
Definition: Class.h:204
gnash::abc::Namespace
Represent an ActionScript Namespace.
Definition: Namespace.h:49
gnash::abc::Class::dump
void dump()
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::NSV::CLASS_FUNCTION
@ CLASS_FUNCTION
Definition: namedStrings.h:216
gnash::abc::Class::addSlot
bool addSlot(string_table::key name, Namespace *ns, std::uint32_t slotID, Class *type, bool isstatic)
Definition: Class.cpp:107
gnash::abc::Class::initTraits
void initTraits(AbcBlock &bl)
This initializes all the traits.
Definition: Class.cpp:80
gnash::as_object::init_member
void init_member(const std::string &name, const as_value &val, int flags=DefaultFlags)
Initialize a member value by string.
Definition: as_object.cpp:669
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::abc::MultiName
An MultiName represents a single ABC multiname.
Definition: MultiName.h:52
gnash::key::g
@ g
Definition: GnashKey.h:153
gnash::abc::Class::getProtectedNs
Namespace * getProtectedNs()
Get the protected namespace.
Definition: Class.h:176
gnash::PropFlags::dontEnum
@ dontEnum
Protect from enumeration.
Definition: PropFlags.h:36
gnash::abc::Class::setDynamic
void setDynamic()
Set the class as dynamic.
Definition: Class.h:167
gnash::PropFlags::dontDelete
@ dontDelete
Protect from deletion.
Definition: PropFlags.h:39
gnash::abc::Class::addSetter
bool addSetter(string_table::key name, Namespace *ns, Method *method, bool isstatic)
Definition: Class.cpp:154
gnash::key::m
@ m
Definition: GnashKey.h:159
as_value.h
gnash::key::n
@ n
Definition: GnashKey.h:160
Global_as.h
gnash::as_object::init_property
void init_property(const std::string &key, as_function &getter, as_function &setter, int flags=DefaultFlags)
Initialize a getter/setter property by name.
Definition: as_object.cpp:690
gnash::abc::AbcBlock
The ActionScript bytecode of a single ABC tag in a SWF.
Definition: AbcBlock.h:209
gnash::abc::Class::addGetter
bool addGetter(string_table::key name, Namespace *ns, Method *method, bool isstatic)
Definition: Class.cpp:134
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
gnash::abc::Class::isDeclared
bool isDeclared()
Definition: Class.h:100
gnash::abc::Class::setProtectedNs
void setProtectedNs(Namespace *n)
Set the protected namespace.
Definition: Class.h:179
gnash::abc::asBinding
Property asBinding
Definition: Method.h:48
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::abc::Class::hasProtectedNs
bool hasProtectedNs() const
Does the class have a protected namespace to be inherited?
Definition: Class.h:173
gnash::abc::Class::addValue
bool addValue(string_table::key name, Namespace *ns, std::uint32_t slotID, Class *type, as_value &val, bool isconst, bool isstatic)
Definition: Class.cpp:42
gnash::abc::Class::initPrototype
void initPrototype()
Necessary for the current bogus implementation.
Definition: Class.cpp:72
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::abc::Trait::finalize
bool finalize(AbcBlock *block, abc::Class *cl, bool do_static)
Definition: AbcBlock.cpp:42
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::abc::Class::getPrototype
as_object * getPrototype()
Necessary for the current bogus implementation.
Definition: Class.h:256
Property.h
gnash::abc::Class::setSystem
void setSystem()
Definition: Class.h:104
gnash::key::type
type
Definition: GnashKey.h:330
gnash::abc::Class::unsetSealed
void unsetSealed()
Definition: Class.h:152
gnash::abc::Class::unsetSystem
void unsetSystem()
Definition: Class.h:105
gnash::abc::Class::setFinal
void setFinal()
Set the class as final.
Definition: Class.h:140
gnash::get
T * get(as_object *o)
Extract the DisplayObject attached to an object.
Definition: as_object.h:842
gnash::abc::Class::setSealed
void setSealed()
Set the class as sealed.
Definition: Class.h:149
gnash::abc::Class::addMemberScript
bool addMemberScript(string_table::key name, Namespace *ns, std::uint32_t slotID, Class *type, bool isstatic)
Definition: Class.cpp:90
gnash::Property
An abstract property.
Definition: Property.h:277
as_class.h
gnash::abc::Class::isInterface
bool isInterface() const
Is the class an interface type?
Definition: Class.h:155
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::abc::Class::isDynamic
bool isDynamic() const
Is the class dynamic?
Definition: Class.h:164
gnash::abc::Class::getStaticConstructor
Method * getStaticConstructor() const
Get the cinit method or 'static constructor'.
Definition: Class.h:216
gnash::abc::Class
A class to represent AS3 Classes.
Definition: Class.h:76
gnash::as_value::to_object
as_object * to_object(VM &vm) const
Return value as an object, converting primitive values as needed.
Definition: as_value.cpp:453
gnash::abc::Class::setStaticConstructor
void setStaticConstructor(Method *m)
Set the cinit method.
Definition: Class.h:211
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::abc::Class::unsetFinal
void unsetFinal()
Set the class as not final.
Definition: Class.h:143
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::abc::Class::unsetDynamic
void unsetDynamic()
Set the class as not dynamic.
Definition: Class.h:170
VM.h
Method.h
gnash::abc::Class::getSetBinding
Property * getSetBinding(as_value &v, abc::MultiName &n)
gnash::abc::Class::getBinding
Property * getBinding(string_table::key name)
Definition: Class.h:228
gnash::abc::Class::isInherited
bool isInherited()
Definition: Class.h:102
gnash::abc::Class::addMethod
bool addMethod(string_table::key name, Namespace *ns, Method *method, bool isstatic)
Definition: Class.cpp:123
ClassHierarchy.h
gnash::abc::Class::setInterface
void setInterface()
Set the class as an interface.
Definition: Class.h:158
gnash::abc::Class::pushInterface
void pushInterface(Class *p)
We implement this interface.
Definition: Class.h:193
gnashconfig.h
gnash::abc::abc_function
ABC-defined Function.
Definition: abc_function.h:41
namedStrings.h
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
AbcBlock.h
gnash::as_object::set_member
virtual bool set_member(const ObjectURI &uri, const as_value &val, bool ifFound=false)
Set a member value.
Definition: as_object.cpp:583
test.uri
uri
Definition: test.py:12
gnash::abc::Class::setSuper
void setSuper(Class *p)
Set the Super Class.
Definition: Class.h:190
gnash::NSV::INTERNAL_TYPE
@ INTERNAL_TYPE
Definition: namedStrings.h:276
gnash::abc::Class::Class
Class()
Definition: Class.h:79
abc_function.h
gnash::string_table::key
std::size_t key
Definition: string_table.h:83
gnash::abc::as_class
The implementation of a 'Class' type in ActionScript 3.
Definition: as_class.h:48
gnash::ClassHierarchy
Register all of the ActionScript classes, with their dependencies.
Definition: ClassHierarchy.h:41
gnash::abc::Class::setInherited
void setInherited()
Definition: Class.h:101
gnash::PropFlags::readOnly
@ readOnly
Protect from assigning a value.
Definition: PropFlags.h:42
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::as_value::is_object
bool is_object() const
Return true if this value is an object.
Definition: as_value.h:219
gnash::key::b
@ b
Definition: GnashKey.h:148
test.v
v
Definition: test.py:11
gnash::abc::Class::setDeclared
void setDeclared()
Definition: Class.h:99
gnash::abc::Method::getPrototype
abc_function * getPrototype()
Definition: Method.h:105
gnash::abc::Class::getGetBinding
Property * getGetBinding(as_value &v, abc::MultiName &n)
gnash::abc::Class::isSystem
bool isSystem()
Definition: Class.h:106
gnash::abc::Class::addStaticTrait
void addStaticTrait(const Trait &t)
Definition: Class.h:220
gnash::abc::Class::isSealed
bool isSealed() const
Is the class sealed?
Definition: Class.h:146
gnash::as_object::getOwnProperty
Property * getOwnProperty(const ObjectURI &uri)
Get this object's own named property, if existing.
Definition: as_object.cpp:926