00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GNASH_AS_CLASS_H
00019 #define GNASH_AS_CLASS_H
00020
00021 #include <list>
00022 #include <map>
00023 #include <vector>
00024 #include "string_table.h"
00025 #include "as_value.h"
00026 #include "CodeStream.h"
00027 #include "Property.h"
00028 #include "as_function.h"
00029
00030 namespace gnash {
00031
00032 class as_function;
00033 class asNamespace;
00034 class asMethod;
00035 class asClass;
00036 class asException;
00037 typedef Property asBinding;
00038
00039 class asBoundValue;
00040 class asBoundAccessor;
00041 class ClassHierarchy;
00042 class Property;
00043
00044 class asName;
00045
00046 class asException
00047 {
00048 public:
00049 void setStart(boost::uint32_t i) { mStart = i; }
00050 void setEnd(boost::uint32_t i) { mEnd = i; }
00051 void setCatch(boost::uint32_t i) { mCatch = i; }
00052 void catchAny() { mCatchAny = true; }
00053 void setCatchType(asClass* p) { mCatchType = p; }
00054 void setNamespace(asNamespace* n) { mNamespace = n; }
00055 void setName(string_table::key name) { mName = name; }
00056
00057 private:
00058 boost::uint32_t mStart;
00059 boost::uint32_t mEnd;
00060 boost::uint32_t mCatch;
00061 bool mCatchAny;
00062 asClass *mCatchType;
00063 asNamespace *mNamespace;
00064 string_table::key mName;
00065 };
00066 #if 0
00068 class asBinding
00069 {
00070 public:
00071 void dump(string_table::key name);
00072
00073 void setConst() { mConst = true; }
00074 void unsetConst() { mConst = false; }
00075 bool isConst() { return mConst; }
00076
00077 void setStatic() { mStatic = true; }
00078 void unsetStatic() { mStatic = false; }
00079 bool isStatic() { return mStatic; }
00080
00081 boost::uint32_t getSlotId() { return mSlotId; }
00082 void setSlotId(boost::uint32_t s) { mSlotId = s; }
00083
00084
00085 string_table::key getName() { return mName; }
00086 void setLexOnly(bool) { }
00087
00089 bool isWriteOnly();
00090
00093 bool isReadOnly();
00094
00095 bool isGetSet() { return getAccessor() != NULL; }
00096
00097
00098 asBinding(Property *, string_table::key name);
00099
00100
00101 asBinding(asNamespace *ns, asMethod *pMethod, bool isstatic = false) :
00102 mNamespace(ns), mType(T_METHOD), mSlotId(0), mConst(true),
00103 mStatic(isstatic), mMethod(pMethod)
00104 {}
00105
00106
00107 asBinding(asNamespace *ns, asMethod *pMethod, boost::uint32_t sid, bool isstatic) :
00108 mNamespace(ns), mType(T_METHOD), mSlotId(sid), mConst(false),
00109 mStatic(isstatic), mMethod(pMethod)
00110 {}
00111
00112 asBinding(asNamespace *ns, asBoundValue *pValue, boost::uint32_t sid, bool isconstant,
00113 bool isstatic) : mNamespace(ns), mType(T_VALUE), mSlotId(sid), mConst(isconstant),
00114 mStatic(isstatic), mValue(pValue)
00115 {}
00116
00117 asBinding(asNamespace *ns, asBoundValue *pValue, boost::uint32_t sid, bool isstatic) :
00118 mNamespace(ns), mType(T_VALUE), mSlotId(sid), mConst(false), mStatic(isstatic),
00119 mValue(pValue)
00120 {}
00121
00122 asBinding(asNamespace *ns, asBoundAccessor *pAccess, bool isstatic) :
00123 mNamespace(ns), mType(T_ACCESS), mSlotId(0), mConst(true), mStatic(isstatic),
00124 mAccess(pAccess)
00125 {}
00126
00127 asBinding(asNamespace *ns, asClass *pClass, boost::uint32_t sid, bool isstatic) :
00128 mNamespace(ns), mType(T_CLASS), mSlotId(sid), mConst(true), mStatic(isstatic),
00129 mClass(pClass)
00130 {}
00131
00132 asBinding() : mNamespace(NULL), mType(T_CLASS), mSlotId(0), mConst(false), mStatic(false),
00133 mClass(NULL)
00134 {}
00135
00136 asBinding(asMethod *);
00137 asBinding(as_function *);
00138
00139 void reset(asBoundAccessor *pAccess, bool isstatic)
00140 {
00141 mType = T_ACCESS;
00142 mAccess = pAccess;
00143 mConst = true;
00144 mStatic = isstatic;
00145 }
00146
00147 asBoundAccessor* getAccessor()
00148 { return mType == T_ACCESS ? mAccess : NULL; }
00149
00150 asBoundValue* getValue()
00151 { return mType == T_VALUE ? mValue : NULL; }
00152
00153 asMethod* getMethod()
00154 { return mType == T_METHOD ? mMethod : NULL; }
00155
00156 asClass* getClass()
00157 { return mType == T_CLASS ? mClass : NULL; }
00158
00159 as_function* getASFunction();
00160
00161 asNamespace *mNamespace;
00162
00163 typedef enum
00164 {
00165 T_CLASS,
00166 T_METHOD,
00167 T_AS_FUNCTION,
00168 T_VALUE,
00169 T_ACCESS
00170 } types;
00171 types mType;
00172
00173 boost::uint32_t mSlotId;
00174 bool mConst;
00175 bool mStatic;
00176 string_table::key mName;
00177 as_object* mOwner;
00178
00179 union
00180 {
00181 asClass *mClass;
00182 asMethod *mMethod;
00183 asBoundValue *mValue;
00184 asBoundAccessor *mAccess;
00185 };
00186 };
00187 #endif // comment out of asBinding
00188
00190 class asNamespace
00191 {
00192 public:
00193 void markReachableResources() const { }
00194
00196 void setParent(asNamespace* p) { mParent = p; }
00197
00198 asNamespace* getParent() { return mParent; }
00199
00201 void setURI(string_table::key name) { mUri = name; }
00202
00204 string_table::key getURI() const { return mUri; }
00205
00207 string_table::key getPrefix() const { return mPrefix; }
00208
00210 asNamespace() : mParent(NULL), mUri(0), mPrefix(0), mClasses(),
00211 mRecursePrevent(false), mPrivate(false), mProtected(false)
00212 {}
00213
00216 bool addClass(string_table::key name, asClass *a)
00217 {
00218 if (getClassInternal(name))
00219 return false;
00220 mClasses[static_cast<std::size_t>(name)] = a;
00221 return true;
00222 }
00223
00224 void stubPrototype(string_table::key name);
00225
00228 asClass *getClass(string_table::key name)
00229 {
00230 if (mRecursePrevent)
00231 return NULL;
00232
00233 asClass *found = getClassInternal(name);
00234 if (found || !getParent())
00235 return found;
00236
00237 mRecursePrevent = true;
00238 found = getParent()->getClass(name);
00239 mRecursePrevent = false;
00240 return found;
00241 }
00242
00243 void setPrivate() { mPrivate = true; }
00244 void unsetPrivate() { mPrivate = false; }
00245 bool isPrivate() { return mPrivate; }
00246
00247 void setProtected() { mProtected = true; }
00248 void unsetProtected() { mProtected = false; }
00249 bool isProtected() { return mProtected; }
00250
00251 private:
00252 asNamespace *mParent;
00253 string_table::key mUri;
00254 string_table::key mPrefix;
00255
00256 typedef std::map<string_table::key, asClass*> container;
00257 container mClasses;
00258 mutable bool mRecursePrevent;
00259
00260 bool mPrivate;
00261 bool mProtected;
00262
00263 asClass *getClassInternal(string_table::key name) const
00264 {
00265 container::const_iterator i;
00266 if (mClasses.empty())
00267 return NULL;
00268
00269 i = mClasses.find(name);
00270 if (i == mClasses.end())
00271 return NULL;
00272 return i->second;
00273 }
00274 };
00275
00276 class asBoundValue;
00277
00278 class asBoundAccessor
00279 {
00280 public:
00281 bool setGetter(asMethod *p) { mGetter = p; return true; }
00282 bool setSetter(asMethod *p) { mSetter = p; return true; }
00283 bool setValue(asBoundValue *p) { mValue = p; return true; }
00284
00285 asBoundValue* getValue() { return mValue; }
00286 asMethod *getGetter() { return mGetter; }
00287 asMethod *getSetter() { return mSetter; }
00288
00289 private:
00290 asMethod *mGetter;
00291 asMethod *mSetter;
00292 asBoundValue *mValue;
00293 };
00294
00295 class asBoundValue
00296 {
00297 public:
00298 asBoundValue() : mConst(false), mValue()
00299 { mValue.set_undefined(); }
00300 void setValue(as_value &v) { mValue = v; }
00301 as_value getCurrentValue() { return mValue; }
00302
00303 void setType(asClass *t) { mType = t; }
00304 asClass *getType() { return mType; }
00305
00306 private:
00307 bool mConst;
00308 asClass *mType;
00309 as_value mValue;
00310 };
00311
00315 class asMethod
00316 {
00317 private:
00318 as_function* mPrototype;
00319
00320 typedef enum
00321 {
00322 FLAGS_FINAL = 0x01,
00323 FLAGS_PROTECTED = 0x02,
00324 FLAGS_PUBLIC = 0x04,
00325 FLAGS_PRIVATE = 0x08
00326 } flags;
00328 typedef std::list<asClass*> argumentList;
00329 typedef std::map<string_table::key, asBinding> binding_container;
00330
00331 int mMinArguments;
00332 int mMaxArguments;
00333 bool mIsNative;
00334 argumentList mArguments;
00335 std::list<as_value> mOptionalArguments;
00336 as_function *mImplementation;
00337 unsigned char mFlags;
00338 CodeStream *mBody;
00339
00340 bool addBinding(string_table::key name, asBinding b);
00341
00342 public:
00343 as_function* getPrototype() { return mPrototype; }
00344
00345 asBinding* getBinding(string_table::key name);
00346
00347 asMethod();
00348
00349 bool isNative() { return mIsNative; }
00350 bool hasBody() const { return mBody != NULL; }
00351
00352 as_object* construct(as_object* ) { return NULL; }
00353
00354 bool hasActivation();
00355
00356 CodeStream *getBody() { return mBody; }
00357 void setBody(CodeStream *b) { mBody = b; }
00358
00359 bool addValue(string_table::key name, asNamespace *ns, boost::uint32_t slotId,
00360 asClass *type, as_value& val, bool isconst);
00361
00362 bool addSlot(string_table::key name, asNamespace *ns, boost::uint32_t slotId,
00363 asClass *type);
00364
00365 bool addMethod(string_table::key name, asNamespace *ns, asMethod *method);
00366
00367 bool addGetter(string_table::key name, asNamespace *ns, asMethod *method);
00368
00369 bool addSetter(string_table::key name, asNamespace *ns, asMethod *method);
00370
00371 bool addMemberClass(string_table::key name, asNamespace *ns,
00372 boost::uint32_t slotId, asClass *type);
00373
00374 bool addSlotFunction(string_table::key name, asNamespace *ns,
00375 boost::uint32_t slotId, asMethod *method);
00376
00379 void setOwner(asClass* s);
00380
00385 asClass* getReturnType() const;
00386
00388 void setReturnType(asClass* t);
00389
00390 asMethod *getSuper();
00391
00392 void setSuper(asMethod* s);
00393
00396 bool isFinal() const { return mFlags & FLAGS_FINAL; }
00397
00400 void setFinal() { mFlags = mFlags | FLAGS_FINAL; }
00401
00404 void unsetFinal() { mFlags = mFlags & ~FLAGS_FINAL; }
00405
00408 bool isPrivate() const { return mFlags & FLAGS_PRIVATE; }
00409
00412 void setPrivate()
00413 { mFlags = (mFlags & ~(FLAGS_PUBLIC | FLAGS_PROTECTED)) | FLAGS_PRIVATE; }
00414
00417 bool isProtected() const { return mFlags & FLAGS_PROTECTED; }
00418
00421 void setProtected()
00422 { mFlags = (mFlags & ~(FLAGS_PUBLIC | FLAGS_PRIVATE)) | FLAGS_PROTECTED; }
00423
00426 bool isPublic() const { return mFlags & FLAGS_PUBLIC; }
00427
00430 void setPublic()
00431 { mFlags = (mFlags & ~(FLAGS_PRIVATE | FLAGS_PROTECTED)) | FLAGS_PUBLIC; }
00432
00435 int minArgumentCount() const { return mMinArguments; }
00436
00439 void setMinArgumentCount(int i) { mMinArguments = i; }
00440
00443 int maxArgumentCount() const { return mMaxArguments; }
00444
00446 void setMaxArgumentCount(int i) { mMaxArguments = i; }
00447
00450 void pushArgument(asClass *t) { mArguments.push_back(t); }
00451
00454 void pushOptional(const as_value& v) { mOptionalArguments.push_back(v); }
00455
00458 bool optionalArguments() const
00459 { return minArgumentCount() != maxArgumentCount(); }
00460
00463 argumentList& getArgumentList() { return mArguments; }
00464
00469 as_function* getImplementation() { return mImplementation; }
00470 };
00471
00478 class asClass
00479 {
00480 public:
00481 as_object* getPrototype() { return mPrototype; }
00482
00483 void dump();
00484
00485 bool addValue(string_table::key name, asNamespace *ns, boost::uint32_t slotId,
00486 asClass *type, as_value& val, bool isconst, bool isstatic);
00487
00488 bool addSlot(string_table::key name, asNamespace *ns, boost::uint32_t slotId,
00489 asClass *type, bool isstatic);
00490
00491 bool addMethod(string_table::key name, asNamespace *ns, asMethod *method,
00492 bool isstatic);
00493
00494 bool addGetter(string_table::key name, asNamespace *ns, asMethod *method,
00495 bool isstatic);
00496
00497 bool addSetter(string_table::key name, asNamespace *ns, asMethod *method,
00498 bool isstatic);
00499
00500 bool addMemberClass(string_table::key name, asNamespace *ns,
00501 boost::uint32_t slotId, asClass *type, bool isstatic);
00502
00503
00504 bool addSlotFunction(string_table::key name, asNamespace *ns,
00505 boost::uint32_t slotId, asMethod *method, bool isstatic);
00506
00508 bool isFinal() const { return mFinal; }
00509
00511 void setFinal() { mFinal = true; }
00512
00514 void unsetFinal() { mFinal = false; }
00515
00517 bool isSealed() const { return mSealed; }
00518
00520 void setSealed() { mSealed = true; }
00521
00522
00523 void unsetSealed() { mSealed = false; }
00524
00526 bool isInterface() const { return mInterface; }
00527
00529 void setInterface() { mInterface = true; }
00530
00532 void unsetInterface() { mInterface = false; }
00533
00535 bool isDynamic() const { return mDynamic; }
00536
00538 void setDynamic() { mDynamic = true; }
00539
00541 void unsetDynamic() { mDynamic = false; }
00542
00544 bool hasProtectedNs() const { return mProtectedNs != NULL; }
00545
00547 asNamespace *getProtectedNs() { return mProtectedNs; }
00548
00550 void setProtectedNs(asNamespace *n) { mProtectedNs = n; }
00551
00552 string_table::key getName() const { return mName; }
00553
00555 void setName(string_table::key name) { mName = name; }
00556
00558 asClass* getSuper() const { return mSuper; }
00559
00561 void pushInterface(asClass* p) { mInterfaces.push_back(p); }
00562
00564 void setConstructor(asMethod *m) { mConstructor = m; }
00565 asMethod *getConstructor() { return mConstructor; }
00566
00567 void setStaticConstructor(asMethod *m) { mStaticConstructor = m; }
00568
00569 void setSuper(asClass *p) { mSuper = p; }
00570
00572 void buildFromPrototype(as_object *o, string_table::key name,
00573 ClassHierarchy *);
00574
00575 void setDeclared() { mDeclared = true; }
00576 bool isDeclared() { return mDeclared; }
00577 void setInherited() { mInherited = true; }
00578 bool isInherited() { return mInherited; }
00579
00580 void setSystem() { mSystem = true; }
00581 void unsetSystem() { mSystem = false; }
00582 bool isSystem() { return mSystem; }
00583
00584 asClass() : mFinal(false), mSealed(false), mDynamic(false),
00585 mInterface(false), mName(0), mInterfaces(), mProtectedNs(NULL),
00586 mSuper(NULL), mConstructor(NULL), mStaticConstructor(NULL),
00587 mBindings(), mStaticBindings(), mDeclared(false), mInherited(false),
00588 mSystem(false)
00589 {}
00590
00591
00592 asBinding *getBinding(string_table::key name)
00593 {
00594 binding_container::iterator i;
00595 if (mBindings.empty())
00596 return NULL;
00597 i = mBindings.find(name);
00598 if (i == mBindings.end())
00599 return NULL;
00600 return &i->second;
00601 }
00602
00603 asBinding* getGetBinding(as_value& v, asName& n);
00604 asBinding* getSetBinding(as_value& v, asName& n);
00605
00606 private:
00607 as_object *mPrototype;
00608
00609 bool addBinding(string_table::key name, asBinding b)
00610 { mBindings[name] = b; return true; }
00611 bool addStaticBinding(string_table::key name, asBinding b)
00612 { mStaticBindings[name] = b; return true; }
00613
00614 asBinding *getStaticBinding(string_table::key name)
00615 {
00616 binding_container::iterator i;
00617 if (mStaticBindings.empty())
00618 return NULL;
00619 i = mStaticBindings.find(name);
00620 if (i == mStaticBindings.end())
00621 return NULL;
00622 return &i->second;
00623 }
00624
00625 bool mFinal;
00626 bool mSealed;
00627 bool mDynamic;
00628 bool mInterface;
00629 string_table::key mName;
00630 std::list<asClass*> mInterfaces;
00631 asNamespace *mProtectedNs;
00632 asClass *mSuper;
00633 asMethod *mConstructor;
00634 asMethod *mStaticConstructor;
00635
00636 typedef std::map<string_table::key, asBinding> binding_container;
00637
00638 binding_container mBindings;
00639 binding_container mStaticBindings;
00640 bool mDeclared;
00641 bool mInherited;
00642 bool mSystem;
00643 };
00644
00645 }
00646
00647 #endif