* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
, m_continueTarget(continueTarget)
{
}
-
- void ref() { ++m_refCount; }
- void deref()
- {
- --m_refCount;
- ASSERT(m_refCount >= 0);
- }
int refCount() const { return m_refCount; }
Label* breakTarget() const { return m_breakTarget.get(); }
int scopeDepth() const { return m_scopeDepth; }
private:
+ friend class LabelScopePtr;
+
+ void ref() { ++m_refCount; }
+ void deref()
+ {
+ --m_refCount;
+ ASSERT(m_refCount >= 0);
+ }
+
int m_refCount;
Type m_type;
const Identifier* m_name;
RefPtr<Label> m_continueTarget;
};
+ typedef Vector<LabelScope, 8> LabelScopeStore;
+
+ class LabelScopePtr {
+ public:
+ LabelScopePtr()
+ : m_owner(0)
+ , m_index(0)
+ {
+ }
+ LabelScopePtr(LabelScopeStore& owner, size_t index)
+ : m_owner(&owner)
+ , m_index(index)
+ {
+ m_owner->at(index).ref();
+ }
+
+ LabelScopePtr(const LabelScopePtr& other)
+ : m_owner(other.m_owner)
+ , m_index(other.m_index)
+ {
+ if (m_owner)
+ m_owner->at(m_index).ref();
+ }
+
+ const LabelScopePtr& operator=(const LabelScopePtr& other)
+ {
+ if (other.m_owner)
+ other.m_owner->at(other.m_index).ref();
+ if (m_owner)
+ m_owner->at(m_index).deref();
+ m_owner = other.m_owner;
+ m_index = other.m_index;
+ return *this;
+ }
+
+ ~LabelScopePtr()
+ {
+ if (m_owner)
+ m_owner->at(m_index).deref();
+ }
+
+ bool operator!() const { return !m_owner; }
+
+ LabelScope& operator*() { ASSERT(m_owner); return m_owner->at(m_index); }
+ LabelScope* operator->() { ASSERT(m_owner); return &m_owner->at(m_index); }
+ const LabelScope& operator*() const { ASSERT(m_owner); return m_owner->at(m_index); }
+ const LabelScope* operator->() const { ASSERT(m_owner); return &m_owner->at(m_index); }
+
+ static LabelScopePtr null() { return LabelScopePtr(); }
+
+ private:
+ LabelScopeStore* m_owner;
+ size_t m_index;
+ };
+
} // namespace JSC
#endif // LabelScope_h