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 
113  bool addValue(string_table::key name, Namespace *ns,
114  std::uint32_t slotID, Class *type, as_value& val,
115  bool isconst, bool isstatic);
116 
117  bool addSlot(string_table::key name, Namespace *ns,
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 
129  bool addMemberScript(string_table::key name, Namespace *ns,
130  std::uint32_t slotID, Class *type, bool isstatic);
131 
132  // TODO: Figure out how this differs from addMethod
133  bool addSlotFunction(string_table::key name, Namespace *ns,
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 
238  Property* getGetBinding(as_value& v, abc::MultiName& n);
239  Property* getSetBinding(as_value& v, abc::MultiName& n);
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
void unsetDynamic()
Set the class as not dynamic.
Definition: Class.h:170
void unsetInterface()
Set the class as not an interface.
Definition: Class.h:161
void unsetFinal()
Set the class as not final.
Definition: Class.h:143
Namespace * getProtectedNs()
Get the protected namespace.
Definition: Class.h:176
The ActionScript bytecode of a single ABC tag in a SWF.
Definition: AbcBlock.h:208
void setStaticConstructor(Method *m)
Set the cinit method.
Definition: Class.h:211
Class describing a static property.
Definition: AbcBlock.h:71
bool isDynamic() const
Is the class dynamic?
Definition: Class.h:164
ActionScript value type.
Definition: as_value.h:94
An abstract property.
Definition: Property.h:276
bool isFinal() const
Is the class final?
Definition: Class.h:137
void setConstructor(Method *m)
Set the iinit method.
Definition: Class.h:198
v
Definition: test.py:11
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
type
Definition: GnashKey.h:329
Represent an ActionScript Namespace.
Definition: Namespace.h:48
Class()
Definition: Class.h:79
The base class for all ActionScript objects.
Definition: as_object.h:161
bool isDeclared()
Definition: Class.h:100
bool isSealed() const
Is the class sealed?
Definition: Class.h:146
Method * getStaticConstructor() const
Get the cinit method or &#39;static constructor&#39;.
Definition: Class.h:216
void addStaticTrait(const Trait &t)
Definition: Class.h:220
Property * getBinding(string_table::key name)
Definition: Class.h:228
void setSystem()
Definition: Class.h:104
Definition: GnashKey.h:160
void unsetSealed()
Definition: Class.h:152
Definition: GnashKey.h:166
A class to represent AS3 Classes.
Definition: Class.h:75
bool isInherited()
Definition: Class.h:102
void setPrototype(as_object *prototype)
Necessary for the current bogus implementation.
Definition: Class.h:248
void setDynamic()
Set the class as dynamic.
Definition: Class.h:167
void setInterface()
Set the class as an interface.
Definition: Class.h:158
bool isSystem()
Definition: Class.h:106
bool hasProtectedNs() const
Does the class have a protected namespace to be inherited?
Definition: Class.h:173
Method * getConstructor() const
Get the iinit method or &#39;constructor&#39;.
Definition: Class.h:204
void setSuper(Class *p)
Set the Super Class.
Definition: Class.h:190
Definition: GnashKey.h:148
void setFinal()
Set the class as final.
Definition: Class.h:140
void unsetSystem()
Definition: Class.h:105
void setSealed()
Set the class as sealed.
Definition: Class.h:149
bool isInterface() const
Is the class an interface type?
Definition: Class.h:155
string_table::key getName() const
The global name of the class.
Definition: Class.h:182
void setInherited()
Definition: Class.h:101
Definition: GnashKey.h:162
Definition: GnashKey.h:155
An MultiName represents a single ABC multiname.
Definition: MultiName.h:51
void setName(string_table::key name)
Set our Name.
Definition: Class.h:109
Definition: GnashKey.h:159
void setProtectedNs(Namespace *n)
Set the protected namespace.
Definition: Class.h:179
as_object * getPrototype()
Necessary for the current bogus implementation.
Definition: Class.h:256
Definition: Method.h:53
void pushInterface(Class *p)
We implement this interface.
Definition: Class.h:193
void setDeclared()
Definition: Class.h:99
std::size_t key
Definition: string_table.h:83
std::string name
Definition: LocalConnection_as.cpp:149
Class * getSuper() const
Retrieve the Class from which this Class derives.
Definition: Class.h:185
void addInstanceTrait(const Trait &t)
Definition: Class.h:224