scope_chain.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KJS_SCOPE_CHAIN_H
00023 #define KJS_SCOPE_CHAIN_H
00024
00025 #include "global.h"
00026
00027 namespace KJS {
00028
00029 class ObjectImp;
00030
00034 class KJS_EXPORT ScopeChainNode {
00035 public:
00036 ScopeChainNode(ScopeChainNode *n, ObjectImp *o)
00037 : next(n), object(o), refCount(1) { }
00038
00039 ScopeChainNode *next;
00040 ObjectImp *object;
00041 int refCount;
00042 };
00043
00047 class KJS_EXPORT ScopeChain {
00048 public:
00049 ScopeChain() : _node(0) { }
00050 ~ScopeChain() { deref(); }
00051
00052 ScopeChain(const ScopeChain &c) : _node(c._node)
00053 { if (_node) ++_node->refCount; }
00054 ScopeChain &operator=(const ScopeChain &);
00055
00056 bool isEmpty() const { return !_node; }
00057 ObjectImp *top() const { return _node->object; }
00058 ObjectImp *bottom() const { const ScopeChainNode *n = _node;
00059 while (n->next) n = n->next;
00060 return n->object; }
00061
00062 void clear() { deref(); _node = 0; }
00063 void push(ObjectImp *);
00064 void pop();
00065
00066 void mark();
00067
00068 private:
00069 ScopeChainNode *_node;
00070
00071 void deref() { if (_node && --_node->refCount == 0) release(); }
00072 void ref() const;
00073
00074 void release();
00075 };
00076
00077 }
00078
00079 #endif // KJS_SCOPE_CHAIN_H
|