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  boost::uint32_t slotID, Class *type, as_value& val,
115  bool isconst, bool isstatic);
116 
118  boost::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  boost::uint32_t slotID, Class *type, bool isstatic);
131 
132  // TODO: Figure out how this differs from addMethod
134  boost::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