language/duchain
duchainbase.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "duchainbase.h"
00021
00022 #include <QMutexLocker>
00023 #include <QThreadStorage>
00024
00025 #include "duchainpointer.h"
00026 #include "indexedstring.h"
00027 #include "topducontext.h"
00028 #include "duchainregister.h"
00029 #include <qthread.h>
00030
00031 namespace KDevelop
00032 {
00033 REGISTER_DUCHAIN_ITEM(DUChainBase);
00034
00035 uint DUChainBaseData::classSize() const {
00036 return DUChainItemSystem::self().dataClassSize(*this);
00037 }
00038
00039 DUChainBase::DUChainBase(const SimpleRange& range)
00040 : KDevelop::DocumentRangeObject(*new DUChainBaseData, range), m_ptr( 0L )
00041 {
00042 d_func_dynamic()->setClassId(this);
00043 }
00044
00045 DUChainBase::DUChainBase( DUChainBaseData & dd, const SimpleRange& range )
00046 : KDevelop::DocumentRangeObject( dd, range ), m_ptr( 0 )
00047 {
00048 }
00049
00050 DUChainBase::DUChainBase( DUChainBaseData & dd )
00051 : KDevelop::DocumentRangeObject( dd ), m_ptr( 0 )
00052 {
00053 }
00054
00055 DUChainBase::DUChainBase( DUChainBase& rhs )
00056 : KDevelop::DocumentRangeObject( rhs ), m_ptr( 0 )
00057 {
00058 }
00059
00060 IndexedString DUChainBase::url() const
00061 {
00062 TopDUContext* top = topContext();
00063 if(top)
00064 return top->TopDUContext::url();
00065 else
00066 return IndexedString();
00067 }
00068
00069 void DUChainBase::setData(DocumentRangeObjectData* data, bool constructorCalled)
00070 {
00071 if(constructorCalled)
00072 KDevelop::DUChainItemSystem::self().callDestructor(static_cast<DUChainBaseData*>(d_ptr));
00073
00074 DocumentRangeObject::setData(data, constructorCalled);
00075 }
00076
00077 DUChainBase::~DUChainBase()
00078 {
00079 if(d_func()->m_dynamic)
00080 KDevelop::DUChainItemSystem::self().callDestructor(d_func_dynamic());
00081
00082 if (m_ptr)
00083 m_ptr->m_base = 0;
00084 }
00085
00086 TopDUContext* DUChainBase::topContext() const
00087 {
00088 return 0;
00089 }
00090
00091 const KSharedPtr<DUChainPointerData>& DUChainBase::weakPointer() const
00092 {
00093 QMutexLocker lock(mutex());
00094
00095 if (!m_ptr) {
00096 m_ptr = new DUChainPointerData(const_cast<DUChainBase*>(this));
00097 m_ptr->m_base = const_cast<DUChainBase*>(this);
00098 }
00099
00100 return m_ptr;
00101 }
00102
00103 void DUChainBase::rebuildDynamicData(DUContext* parent, uint ownIndex)
00104 {
00105 Q_UNUSED(parent)
00106 Q_UNUSED(ownIndex)
00107 }
00108
00109 void DUChainBase::aboutToWriteData() {
00110 makeDynamic();
00111 }
00112
00113 bool DUChainBase::canWriteData() const {
00114 return d_func()->m_dynamic;
00115 }
00116
00117 void DUChainBase::makeDynamic() {
00118 Q_ASSERT(d_ptr);
00119 if(!d_func()->m_dynamic) {
00120 Q_ASSERT(d_func()->classId);
00121 DUChainBaseData* newData = DUChainItemSystem::self().cloneData(*d_func());
00122 enableDUChainReferenceCounting(d_ptr, DUChainItemSystem::self().dynamicSize(*static_cast<DUChainBaseData*>(d_ptr)));
00123
00124
00125 KDevelop::DUChainItemSystem::self().callDestructor(static_cast<DUChainBaseData*>(d_ptr));
00126 disableDUChainReferenceCounting(d_ptr);
00127 d_ptr = newData;
00128 Q_ASSERT(d_ptr);
00129 Q_ASSERT(d_func()->m_dynamic);
00130 Q_ASSERT(d_func()->classId);
00131 }
00132 }
00133
00134 QMutex shouldCreateConstantDataStorageMutex;
00135 QSet<Qt::HANDLE> shouldCreateConstantDataStorage;
00136
00137 bool DUChainBaseData::shouldCreateConstantData() {
00138 shouldCreateConstantDataStorageMutex.lock();
00139 bool ret = shouldCreateConstantDataStorage.contains( QThread::currentThreadId() );
00140 shouldCreateConstantDataStorageMutex.unlock();
00141 return ret;
00142 }
00143
00144 void DUChainBaseData::setShouldCreateConstantData(bool should) {
00145 shouldCreateConstantDataStorageMutex.lock();
00146
00147 if(should)
00148 shouldCreateConstantDataStorage.insert(QThread::currentThreadId());
00149 else
00150 shouldCreateConstantDataStorage.remove(QThread::currentThreadId());
00151
00152 shouldCreateConstantDataStorageMutex.unlock();
00153 }
00154
00155 }
00156
00157
00158