diff --git a/formatters/astyle/lib/ASBeautifier.cpp b/formatters/astyle/3rdparty/libastyle/ASBeautifier.cpp similarity index 100% rename from formatters/astyle/lib/ASBeautifier.cpp rename to formatters/astyle/3rdparty/libastyle/ASBeautifier.cpp diff --git a/formatters/astyle/lib/ASEnhancer.cpp b/formatters/astyle/3rdparty/libastyle/ASEnhancer.cpp similarity index 100% rename from formatters/astyle/lib/ASEnhancer.cpp rename to formatters/astyle/3rdparty/libastyle/ASEnhancer.cpp diff --git a/formatters/astyle/lib/ASFormatter.cpp b/formatters/astyle/3rdparty/libastyle/ASFormatter.cpp similarity index 100% rename from formatters/astyle/lib/ASFormatter.cpp rename to formatters/astyle/3rdparty/libastyle/ASFormatter.cpp diff --git a/formatters/astyle/lib/ASLocalizer.cpp b/formatters/astyle/3rdparty/libastyle/ASLocalizer.cpp similarity index 100% rename from formatters/astyle/lib/ASLocalizer.cpp rename to formatters/astyle/3rdparty/libastyle/ASLocalizer.cpp diff --git a/formatters/astyle/lib/ASLocalizer.h b/formatters/astyle/3rdparty/libastyle/ASLocalizer.h similarity index 100% rename from formatters/astyle/lib/ASLocalizer.h rename to formatters/astyle/3rdparty/libastyle/ASLocalizer.h diff --git a/formatters/astyle/lib/ASResource.cpp b/formatters/astyle/3rdparty/libastyle/ASResource.cpp similarity index 100% rename from formatters/astyle/lib/ASResource.cpp rename to formatters/astyle/3rdparty/libastyle/ASResource.cpp diff --git a/formatters/astyle/lib/CMakeLists.txt b/formatters/astyle/3rdparty/libastyle/CMakeLists.txt similarity index 100% rename from formatters/astyle/lib/CMakeLists.txt rename to formatters/astyle/3rdparty/libastyle/CMakeLists.txt diff --git a/formatters/astyle/lib/README b/formatters/astyle/3rdparty/libastyle/README similarity index 100% rename from formatters/astyle/lib/README rename to formatters/astyle/3rdparty/libastyle/README diff --git a/formatters/astyle/lib/astyle.h b/formatters/astyle/3rdparty/libastyle/astyle.h similarity index 100% rename from formatters/astyle/lib/astyle.h rename to formatters/astyle/3rdparty/libastyle/astyle.h diff --git a/formatters/astyle/CMakeLists.txt b/formatters/astyle/CMakeLists.txt index 32dbb5ec35..78cba0a68b 100644 --- a/formatters/astyle/CMakeLists.txt +++ b/formatters/astyle/CMakeLists.txt @@ -1,36 +1,36 @@ include_directories(lib) ecm_qt_declare_logging_category(kdevastyle_LOG_SRCS HEADER debug.h IDENTIFIER KDEV_ASTYLE CATEGORY_NAME "kdevelop.formatters.astyle" ) set(kdevastyle_PART_SRCS astyle_plugin.cpp astyle_preferences.cpp astyle_formatter.cpp astyle_stringiterator.cpp ${kdevastyle_LOG_SRCS} ) set(astyle_preferences_UI astyle_preferences.ui ) ki18n_wrap_ui(kdevastyle_PART_SRCS ${astyle_preferences_UI} ) kdevplatform_add_plugin(kdevastyle JSON kdevastyle.json SOURCES ${kdevastyle_PART_SRCS}) target_link_libraries(kdevastyle astylelib KF5::Parts KF5::KIOWidgets KF5::TextEditor KDev::Interfaces KDev::Util) -add_subdirectory(lib) +add_subdirectory(3rdparty/libastyle) if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/kdevplatform/language/duchain/types/typerepository.cpp b/kdevplatform/language/duchain/types/typerepository.cpp index f3c5a247c2..717b4acb4c 100644 --- a/kdevplatform/language/duchain/types/typerepository.cpp +++ b/kdevplatform/language/duchain/types/typerepository.cpp @@ -1,155 +1,157 @@ /* Copyright 2008 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "typerepository.h" #include #include #include #include "../types/typesystemdata.h" #include "../types/typeregister.h" #include #include #define DEBUG_TYPE_REPOSITORY #define ASSERT_ON_PROBLEM namespace KDevelop { class AbstractTypeDataRequest { public: AbstractTypeDataRequest(const AbstractType& type) : m_item(type) { } enum { AverageSize = sizeof(AbstractTypeData) + 12 }; unsigned int hash() const { return m_item.hash(); } uint itemSize() const { return TypeSystem::self().dynamicSize(*m_item.d_ptr); } void createItem(AbstractTypeData* item) const { TypeSystem::self().copy(*m_item.d_ptr, *item, true); Q_ASSERT(!item->m_dynamic); #ifdef DEBUG_TYPE_REPOSITORY AbstractType::Ptr otherType( TypeSystem::self().create(const_cast(item)) ); if(!otherType->equals(&m_item)) { //For debugging, so one can trace what happened qCWarning(LANGUAGE) << "created type in repository does not equal source type:" << m_item.toString() << otherType->toString(); TypeSystem::self().copy(*m_item.d_ptr, *item, true); otherType->equals(&m_item); } #ifdef ASSERT_ON_PROBLEM Q_ASSERT(otherType->equals(&m_item)); #endif #endif item->inRepository = true; } static void destroy(AbstractTypeData* item, KDevelop::AbstractItemRepository&) { TypeSystem::self().callDestructor(item); } static bool persistent(const AbstractTypeData* item) { // Don't try to delete release items for which the factory is not loaded, as that will lead to a crash/assertion later return (bool)item->refCount || !TypeSystem::self().isFactoryLoaded(*item); } bool equals(const AbstractTypeData* item) const { + if (!TypeSystem::self().isFactoryLoaded(*item)) + return false; + AbstractType::Ptr otherType( TypeSystem::self().create(const_cast(item)) ); - if(!otherType) - return false; + Q_ASSERT(otherType); return m_item.equals(otherType.data()); } const AbstractType& m_item; }; //The object is created in a function, to prevent initialization-order issues static RepositoryManager< ItemRepository, false>& typeRepository() { static RepositoryManager< ItemRepository, false> repository(QStringLiteral("Type Repository")); return repository; } void initTypeRepository() { typeRepository(); } AbstractRepositoryManager* typeRepositoryManager() { return &typeRepository(); } uint TypeRepository::indexForType(const AbstractType::Ptr& input) { if(!input) return 0; uint i = typeRepository()->index(AbstractTypeDataRequest(*input)); #ifdef DEBUG_TYPE_REPOSITORY AbstractType::Ptr t = typeForIndex(i); if(!t->equals(input.data())) { qCWarning(LANGUAGE) << "found type in repository does not equal source type:" << input->toString() << t->toString(); t->equals(input.data()); } #ifdef ASSERT_ON_PROBLEM Q_ASSERT(t->equals(input.data())); Q_ASSERT(input->equals(t.data())); #endif #endif return i; } AbstractType::Ptr TypeRepository::typeForIndex(uint index) { if(index == 0) return AbstractType::Ptr(); return AbstractType::Ptr( TypeSystem::self().create(const_cast(typeRepository()->itemFromIndex(index))) ); } void TypeRepository::increaseReferenceCount(uint index, ReferenceCountManager* manager) { if(!index) return; QMutexLocker lock(typeRepository()->mutex()); AbstractTypeData* data = typeRepository()->dynamicItemFromIndexSimple(index); Q_ASSERT(data); if(manager) manager->increase(data->refCount, index); else ++data->refCount; } void TypeRepository::decreaseReferenceCount(uint index, ReferenceCountManager* manager) { if(!index) return; QMutexLocker lock(typeRepository()->mutex()); AbstractTypeData* data = typeRepository()->dynamicItemFromIndexSimple(index); Q_ASSERT(data); Q_ASSERT(data->refCount > 0); if(manager) manager->decrease(data->refCount, index); else --data->refCount; } }