00001
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
namespace KJS {
00026
00027
class ObjectImp;
00028
00029
class ScopeChainNode {
00030
public:
00031 ScopeChainNode(ScopeChainNode *n, ObjectImp *o)
00032 :
next(n), object(o), refCount(1) { }
00033
00034 ScopeChainNode *
next;
00035 ObjectImp *object;
00036
int refCount;
00037 };
00038
00039
class ScopeChain {
00040
public:
00041 ScopeChain() : _node(0) { }
00042 ~ScopeChain() { deref(); }
00043
00044 ScopeChain(
const ScopeChain &c) : _node(c._node)
00045 {
if (_node) ++_node->refCount; }
00046 ScopeChain &operator=(
const ScopeChain &);
00047
00048
bool isEmpty()
const {
return !_node; }
00049 ObjectImp *top()
const {
return _node->object; }
00050 ObjectImp *bottom()
const {
const ScopeChainNode *n = _node;
00051
while (n->next) n = n->next;
00052
return n->object; }
00053
00054
void clear() { deref(); _node = 0; }
00055
void push(ObjectImp *);
00056
void pop();
00057
00058
void mark();
00059
00060
private:
00061 ScopeChainNode *_node;
00062
00063
void deref() {
if (_node && --_node->refCount == 0) release(); }
00064
void ref() const;
00065
00066
void release();
00067 };
00068
00069 }
00070
00071 #endif