diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java b/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java index 3877e5ef..af740d1d 100644 --- a/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java +++ b/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java @@ -97,6 +97,8 @@ public class JavaIndexer visitor = new ContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu); } + astVisitorClient.logInfo("starting AST traversal"); + cu.accept(visitor); for (IProblem problem: cu.getProblems()) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 8776575f..a2e8509b 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -172,6 +172,7 @@ add_files( data/indexer/IndexerCommandType.h data/indexer/IndexerComposite.cpp data/indexer/IndexerComposite.h + data/indexer/IndexerStateInfo.h data/indexer/MemoryIndexerCommandProvider.cpp data/indexer/MemoryIndexerCommandProvider.h data/indexer/TaskBuildIndex.cpp @@ -510,8 +511,6 @@ add_files( utility/messaging/MessageBase.cpp utility/messaging/MessageBase.h utility/messaging/MessageFilter.h - utility/messaging/MessageInterruptTasksCounter.cpp - utility/messaging/MessageInterruptTasksCounter.h utility/messaging/MessageListener.h utility/messaging/MessageListenerBase.cpp utility/messaging/MessageListenerBase.h diff --git a/src/lib/data/TaskInjectStorage.cpp b/src/lib/data/TaskInjectStorage.cpp index 48d89e73..5e79db28 100644 --- a/src/lib/data/TaskInjectStorage.cpp +++ b/src/lib/data/TaskInjectStorage.cpp @@ -35,8 +35,7 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr blackboa } else { - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } return STATE_FAILURE; diff --git a/src/lib/data/TaskMergeStorages.cpp b/src/lib/data/TaskMergeStorages.cpp index 31b3bcfe..8b40118b 100644 --- a/src/lib/data/TaskMergeStorages.cpp +++ b/src/lib/data/TaskMergeStorages.cpp @@ -42,8 +42,7 @@ Task::TaskState TaskMergeStorages::doUpdate(std::shared_ptr blackboa } else { - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } return STATE_FAILURE; diff --git a/src/lib/data/indexer/Indexer.h b/src/lib/data/indexer/Indexer.h index 00665ec2..77edd59d 100644 --- a/src/lib/data/indexer/Indexer.h +++ b/src/lib/data/indexer/Indexer.h @@ -13,12 +13,13 @@ class Indexer { public: IndexerCommandType getSupportedIndexerCommandType() const override; - std::shared_ptr index(std::shared_ptr indexerCommand) override; +private: virtual std::shared_ptr doIndex(std::shared_ptr indexerCommand) = 0; }; + template IndexerCommandType Indexer::getSupportedIndexerCommandType() const { diff --git a/src/lib/data/indexer/IndexerBase.cpp b/src/lib/data/indexer/IndexerBase.cpp index 7dc0de38..22298f7f 100644 --- a/src/lib/data/indexer/IndexerBase.cpp +++ b/src/lib/data/indexer/IndexerBase.cpp @@ -1,16 +1,5 @@ #include "IndexerBase.h" IndexerBase::IndexerBase() - : m_interrupted(false) { } - -void IndexerBase::interrupt() -{ - m_interrupted = true; -} - -bool IndexerBase::interrupted() const -{ - return m_interrupted; -} diff --git a/src/lib/data/indexer/IndexerBase.h b/src/lib/data/indexer/IndexerBase.h index 5f5199d8..a2c5e060 100644 --- a/src/lib/data/indexer/IndexerBase.h +++ b/src/lib/data/indexer/IndexerBase.h @@ -15,17 +15,9 @@ class IndexerBase public: IndexerBase(); virtual ~IndexerBase() = default; - virtual IndexerCommandType getSupportedIndexerCommandType() const = 0; - virtual std::shared_ptr index(std::shared_ptr indexerCommand) = 0; - - virtual void interrupt(); - - bool interrupted() const; - -private: - bool m_interrupted; + virtual void interrupt() = 0; }; #endif // INDEXER_BASE_H diff --git a/src/lib/data/indexer/IndexerComposite.cpp b/src/lib/data/indexer/IndexerComposite.cpp index 30d3cdbe..530c6db9 100644 --- a/src/lib/data/indexer/IndexerComposite.cpp +++ b/src/lib/data/indexer/IndexerComposite.cpp @@ -36,5 +36,4 @@ void IndexerComposite::interrupt() { it.second->interrupt(); } - IndexerBase::interrupt(); } diff --git a/src/lib/data/indexer/IndexerComposite.h b/src/lib/data/indexer/IndexerComposite.h index a8c353a2..a6296054 100644 --- a/src/lib/data/indexer/IndexerComposite.h +++ b/src/lib/data/indexer/IndexerComposite.h @@ -11,13 +11,13 @@ class IndexerComposite: public IndexerBase public: virtual ~IndexerComposite(); - virtual IndexerCommandType getSupportedIndexerCommandType() const; + IndexerCommandType getSupportedIndexerCommandType() const override; void addIndexer(std::shared_ptr indexer); - virtual std::shared_ptr index(std::shared_ptr indexerCommand); + std::shared_ptr index(std::shared_ptr indexerCommand) override; - virtual void interrupt(); + void interrupt() override; private: std::map> m_indexers; diff --git a/src/lib/data/indexer/IndexerStateInfo.h b/src/lib/data/indexer/IndexerStateInfo.h new file mode 100644 index 00000000..452fcb20 --- /dev/null +++ b/src/lib/data/indexer/IndexerStateInfo.h @@ -0,0 +1,10 @@ +#ifndef INDEXER_STATE_INFO_H +#define INDEXER_STATE_INFO_H + +struct IndexerStateInfo +{ +public: + bool indexingInterrupted; +}; + +#endif // INDEXER_STATE_INFO_H diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp index aa6b1907..020f29f5 100644 --- a/src/lib/data/indexer/TaskBuildIndex.cpp +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -41,6 +41,8 @@ TaskBuildIndex::TaskBuildIndex( void TaskBuildIndex::doEnter(std::shared_ptr blackboard) { + m_interprocessIndexingStatusManager.setIndexingInterrupted(false); + m_indexingFileCount = 0; updateIndexingDialog(blackboard, std::vector()); @@ -104,8 +106,7 @@ Task::TaskState TaskBuildIndex::doUpdate(std::shared_ptr blackboard) updateIndexingDialog(blackboard, std::vector()); } - const int SLEEP_TIME_MS = 50; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); return STATE_RUNNING; } @@ -154,6 +155,8 @@ void TaskBuildIndex::handleMessage(MessageInterruptTasks* message) { if (!m_dialogView->dialogsHidden()) { + LOG_INFO("sending indexer interrupt command."); + m_interprocessIndexingStatusManager.setIndexingInterrupted(true); m_interrupted = true; } } @@ -232,8 +235,7 @@ bool TaskBuildIndex::fetchIntermediateStorages(std::shared_ptr black { LOG_INFO_STREAM(<< "waiting, too many storages queued: " << providerStorageCount); - const int SLEEP_TIME_MS = 100; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); return true; } diff --git a/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp b/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp index 5a125821..9f432320 100644 --- a/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp +++ b/src/lib/data/indexer/TaskFillIndexerCommandQueue.cpp @@ -82,8 +82,7 @@ Task::TaskState TaskFillIndexerCommandsQueue::doUpdate(std::shared_ptr updaterThread; + std::shared_ptr indexer; + try { LOG_INFO(std::to_wstring(m_processId) + L" starting up indexer"); - std::shared_ptr indexer = LanguagePackageManager::getInstance()->instantiateSupportedIndexers(); + indexer = LanguagePackageManager::getInstance()->instantiateSupportedIndexers(); + + updaterThread = std::make_shared([&]() + { + updaterThreadRunning = true; + while (updaterThreadRunning) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + if (m_interprocessIndexingStatusManager.getIndexingInterrupted()) + { + LOG_INFO("received indexer interrupt command."); + if (indexer) + { + indexer->interrupt(); + } + updaterThreadRunning = false; + } + } + }); + + ScopedFunctor threadStopper([&]() + { + updaterThreadRunning = false; + if (updaterThread) + { + updaterThread->join(); + updaterThread.reset(); + } + }); while (std::shared_ptr indexerCommand = m_interprocessIndexerCommandManager.popIndexerCommand()) { @@ -29,7 +62,7 @@ void InterprocessIndexer::work() while (true) { - size_t storageCount = m_interprocessIntermediateStorageManager.getIntermediateStorageCount(); + const size_t storageCount = m_interprocessIntermediateStorageManager.getIntermediateStorageCount(); if (storageCount < 10) { break; @@ -37,8 +70,7 @@ void InterprocessIndexer::work() LOG_INFO_STREAM(<< m_processId << " waits, too many intermediate storages: " << storageCount); - const int SLEEP_TIME_MS = 200; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); } LOG_INFO_STREAM(<< m_processId << " updating indexer status with currently indexed filepath"); @@ -47,8 +79,11 @@ void InterprocessIndexer::work() LOG_INFO_STREAM(<< m_processId << " starting to index current file"); std::shared_ptr result = indexer->index(indexerCommand); - LOG_INFO_STREAM(<< m_processId << " pushing index to shared memory"); - m_interprocessIntermediateStorageManager.pushIntermediateStorage(result); + if (result) + { + LOG_INFO_STREAM(<< m_processId << " pushing index to shared memory"); + m_interprocessIntermediateStorageManager.pushIntermediateStorage(result); + } LOG_INFO_STREAM(<< m_processId << " finalizing indexer status for current file"); m_interprocessIndexingStatusManager.finishIndexingSourceFile(); diff --git a/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp b/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp index c2564672..71c54344 100644 --- a/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp +++ b/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.cpp @@ -9,6 +9,7 @@ const char* InterprocessIndexingStatusManager::s_indexingFilesKeyName = "indexin const char* InterprocessIndexingStatusManager::s_currentFilesKeyName = "current_files"; const char* InterprocessIndexingStatusManager::s_crashedFilesKeyName = "crashed_files"; const char* InterprocessIndexingStatusManager::s_finishedProcessIdsKeyName = "finished_process_ids"; +const char* InterprocessIndexingStatusManager::s_indexingInterruptedKeyName = "indexing_interrupted_flag"; InterprocessIndexingStatusManager::InterprocessIndexingStatusManager(const std::string& instanceUuid, Id processId, bool isOwner) : BaseInterprocessDataManager(s_sharedMemoryNamePrefix + instanceUuid, 1048576 /* 1 MB */, instanceUuid, processId, isOwner) @@ -97,6 +98,32 @@ void InterprocessIndexingStatusManager::finishIndexingSourceFile() } } +void InterprocessIndexingStatusManager::setIndexingInterrupted(bool interrupted) +{ + SharedMemory::ScopedAccess access(&m_sharedMemory); + + bool* indexingInterruptedPtr = + access.accessValue(s_indexingInterruptedKeyName); + if (indexingInterruptedPtr) + { + *indexingInterruptedPtr = interrupted; + } +} + +bool InterprocessIndexingStatusManager::getIndexingInterrupted() +{ + SharedMemory::ScopedAccess access(&m_sharedMemory); + + bool* indexingInterruptedPtr = + access.accessValue(s_indexingInterruptedKeyName); + if (indexingInterruptedPtr) + { + return *indexingInterruptedPtr; + } + + return false; +} + Id InterprocessIndexingStatusManager::getNextFinishedProcessId() { SharedMemory::ScopedAccess access(&m_sharedMemory); diff --git a/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.h b/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.h index 742329e1..cd9cc620 100644 --- a/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.h +++ b/src/lib/data/indexer/interprocess/InterprocessIndexingStatusManager.h @@ -16,6 +16,9 @@ public: void startIndexingSourceFile(const FilePath& filePath); void finishIndexingSourceFile(); + void setIndexingInterrupted(bool interrupted); + bool getIndexingInterrupted(); + Id getNextFinishedProcessId(); std::vector getCurrentlyIndexedSourceFilePaths(); @@ -28,6 +31,7 @@ private: static const char* s_currentFilesKeyName; static const char* s_crashedFilesKeyName; static const char* s_finishedProcessIdsKeyName; + static const char* s_indexingInterruptedKeyName; }; #endif // INTERPROCESS_INDEXING_STATUS_MANAGER_H diff --git a/src/lib/utility/interprocess/SharedMemory.h b/src/lib/utility/interprocess/SharedMemory.h index 42b5da43..863a9222 100644 --- a/src/lib/utility/interprocess/SharedMemory.h +++ b/src/lib/utility/interprocess/SharedMemory.h @@ -116,5 +116,4 @@ private: AccessMode m_mode; }; - #endif // SHARED_MEMORY_H diff --git a/src/lib/utility/messaging/MessageInterruptTasksCounter.cpp b/src/lib/utility/messaging/MessageInterruptTasksCounter.cpp deleted file mode 100644 index bf3dbb47..00000000 --- a/src/lib/utility/messaging/MessageInterruptTasksCounter.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "MessageInterruptTasksCounter.h" - -#include "MessageInterruptTasks.h" -#include "MessageListener.h" - -MessageInterruptTasksCounter::MessageInterruptTasksCounter() - : m_count(0) -{ - class InterruptListener: public MessageListener - { - public: - InterruptListener(size_t& counter) - : m_counter(counter) - {} - - private: - virtual void handleMessage(MessageInterruptTasks* message) - { - m_counter++; - } - - size_t& m_counter; - }; - - m_listener = std::make_shared(m_count); -} - -MessageInterruptTasksCounter::~MessageInterruptTasksCounter() -{ -} - -void MessageInterruptTasksCounter::reset() -{ - m_count = 0; -} - -size_t MessageInterruptTasksCounter::getCount() const -{ - return m_count; -} diff --git a/src/lib/utility/messaging/MessageInterruptTasksCounter.h b/src/lib/utility/messaging/MessageInterruptTasksCounter.h deleted file mode 100644 index 4c1137f8..00000000 --- a/src/lib/utility/messaging/MessageInterruptTasksCounter.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef MESSAGE_INTERRUPT_TASKS_COUNTER_H -#define MESSAGE_INTERRUPT_TASKS_COUNTER_H - -#include - -class MessageListenerBase; - -class MessageInterruptTasksCounter -{ -public: - MessageInterruptTasksCounter(); - virtual ~MessageInterruptTasksCounter(); - - void reset(); - size_t getCount() const; - -private: - std::shared_ptr m_listener; - - size_t m_count; -}; - -#endif // MESSAGE_INTERRUPT_TASKS_COUNTER_H diff --git a/src/lib/utility/messaging/MessageQueue.cpp b/src/lib/utility/messaging/MessageQueue.cpp index 4f63ab29..b6946d6b 100644 --- a/src/lib/utility/messaging/MessageQueue.cpp +++ b/src/lib/utility/messaging/MessageQueue.cpp @@ -140,8 +140,7 @@ void MessageQueue::startMessageLoop() } } - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } { @@ -176,8 +175,7 @@ void MessageQueue::stopMessageLoop() } } - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } } diff --git a/src/lib/utility/scheduling/TaskGroupParallel.cpp b/src/lib/utility/scheduling/TaskGroupParallel.cpp index d9483c1b..f810131a 100644 --- a/src/lib/utility/scheduling/TaskGroupParallel.cpp +++ b/src/lib/utility/scheduling/TaskGroupParallel.cpp @@ -35,8 +35,7 @@ void TaskGroupParallel::doEnter(std::shared_ptr blackboard) Task::TaskState TaskGroupParallel::doUpdate(std::shared_ptr blackboard) { - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); if (m_tasks.size() != 0 && getActiveTaskCount() > 0) { diff --git a/src/lib/utility/scheduling/TaskScheduler.cpp b/src/lib/utility/scheduling/TaskScheduler.cpp index dd64eb1e..87ccb8c0 100644 --- a/src/lib/utility/scheduling/TaskScheduler.cpp +++ b/src/lib/utility/scheduling/TaskScheduler.cpp @@ -71,8 +71,7 @@ void TaskScheduler::startSchedulerLoop() } } - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } { @@ -107,8 +106,7 @@ void TaskScheduler::stopSchedulerLoop() } } - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } } diff --git a/src/lib_cxx/data/indexer/IndexerCxx.cpp b/src/lib_cxx/data/indexer/IndexerCxx.cpp index 85801bcc..80999c7c 100644 --- a/src/lib_cxx/data/indexer/IndexerCxx.cpp +++ b/src/lib_cxx/data/indexer/IndexerCxx.cpp @@ -1,8 +1,20 @@ #include "IndexerCxx.h" #include "CxxParser.h" -#include "ParserClientImpl.h" #include "FileRegister.h" +#include "IndexerStateInfo.h" +#include "ParserClientImpl.h" + +IndexerCxx::IndexerCxx() + : m_indexerStateInfo(std::make_shared()) +{ + m_indexerStateInfo->indexingInterrupted = false; +} + +void IndexerCxx::interrupt() +{ + m_indexerStateInfo->indexingInterrupted = true; +} std::shared_ptr IndexerCxx::doIndex(std::shared_ptr indexerCommand) { @@ -12,7 +24,8 @@ std::shared_ptr IndexerCxx::doIndex(std::shared_ptr( indexerCommand->getSourceFilePath(), indexerCommand->getIndexedPaths(), indexerCommand->getExcludeFilters() - ) + ), + m_indexerStateInfo ); std::shared_ptr storage = std::make_shared(); @@ -31,7 +44,7 @@ std::shared_ptr IndexerCxx::doIndex(std::shared_ptrsetFilesWithErrorsIncomplete(); } - if (IndexerBase::interrupted()) + if (m_indexerStateInfo->indexingInterrupted) { return std::shared_ptr(); } diff --git a/src/lib_cxx/data/indexer/IndexerCxx.h b/src/lib_cxx/data/indexer/IndexerCxx.h index 1368586f..dea00077 100644 --- a/src/lib_cxx/data/indexer/IndexerCxx.h +++ b/src/lib_cxx/data/indexer/IndexerCxx.h @@ -2,14 +2,23 @@ #define INDEXER_CXX_H #include +#include -#include "IndexerCommandCxx.h" #include "Indexer.h" +#include "IndexerCommandCxx.h" + +struct IndexerStateInfo; class IndexerCxx: public Indexer { public: + IndexerCxx(); + void interrupt() override; + +private: std::shared_ptr doIndex(std::shared_ptr indexerCommand) override; + + std::shared_ptr m_indexerStateInfo; }; #endif // INDEXER_CXX_H diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.h b/src/lib_cxx/data/parser/cxx/ASTAction.h index 794cffa1..e8a73d22 100644 --- a/src/lib_cxx/data/parser/cxx/ASTAction.h +++ b/src/lib_cxx/data/parser/cxx/ASTAction.h @@ -18,10 +18,12 @@ class ASTAction public: explicit ASTAction( std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ) : m_client(client) , m_canonicalFilePathCache(canonicalFilePathCache) + , m_indexerStateInfo(indexerStateInfo) , m_commentHandler(client, canonicalFilePathCache) {} @@ -31,7 +33,7 @@ protected: virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) override { return std::unique_ptr( - new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_canonicalFilePathCache)); + new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_canonicalFilePathCache, m_indexerStateInfo)); } virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler) override @@ -46,6 +48,7 @@ protected: private: std::shared_ptr m_client; std::shared_ptr m_canonicalFilePathCache; + std::shared_ptr m_indexerStateInfo; CommentHandler m_commentHandler; }; diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp index f9605a5f..a4f32443 100644 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp +++ b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp @@ -6,10 +6,12 @@ ASTActionFactory::ASTActionFactory( std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ) : m_client(client) , m_canonicalFilePathCache(canonicalFilePathCache) + , m_indexerStateInfo(indexerStateInfo) { } @@ -19,5 +21,5 @@ ASTActionFactory::~ASTActionFactory() clang::FrontendAction* ASTActionFactory::create() { - return new ASTAction(m_client, m_canonicalFilePathCache); + return new ASTAction(m_client, m_canonicalFilePathCache, m_indexerStateInfo); } diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h index fcfde9e9..a798edaa 100644 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h +++ b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h @@ -1,8 +1,12 @@ #ifndef AST_ACTION_FACTORY #define AST_ACTION_FACTORY +#include + #include +#include "IndexerStateInfo.h" + class CanonicalFilePathCache; class ParserClient; @@ -12,7 +16,8 @@ class ASTActionFactory public: explicit ASTActionFactory( std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ); virtual ~ASTActionFactory(); @@ -22,6 +27,7 @@ public: private: std::shared_ptr m_client; std::shared_ptr m_canonicalFilePathCache; + std::shared_ptr m_indexerStateInfo; }; #endif // AST_ACTION_FACTORY diff --git a/src/lib_cxx/data/parser/cxx/ASTConsumer.cpp b/src/lib_cxx/data/parser/cxx/ASTConsumer.cpp index bad40ded..2a17b174 100644 --- a/src/lib_cxx/data/parser/cxx/ASTConsumer.cpp +++ b/src/lib_cxx/data/parser/cxx/ASTConsumer.cpp @@ -8,18 +8,19 @@ ASTConsumer::ASTConsumer( clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ) { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); if (appSettings->getLoggingEnabled() && appSettings->getVerboseIndexerLoggingEnabled()) { - m_visitor = std::make_shared(context, preprocessor, client, canonicalFilePathCache); + m_visitor = std::make_shared(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo); } else { - m_visitor = std::make_shared(context, preprocessor, client, canonicalFilePathCache); + m_visitor = std::make_shared(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo); } } diff --git a/src/lib_cxx/data/parser/cxx/ASTConsumer.h b/src/lib_cxx/data/parser/cxx/ASTConsumer.h index cce90f06..c5214ed2 100644 --- a/src/lib_cxx/data/parser/cxx/ASTConsumer.h +++ b/src/lib_cxx/data/parser/cxx/ASTConsumer.h @@ -7,6 +7,7 @@ class CanonicalFilePathCache; class CxxAstVisitor; class ParserClient; +struct IndexerStateInfo; class ASTConsumer : public clang::ASTConsumer @@ -16,7 +17,8 @@ public: clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ); virtual ~ASTConsumer(); @@ -25,6 +27,7 @@ public: private: std::shared_ptr m_visitor; + std::shared_ptr m_indexerStateInfo; }; #endif // AST_CONSUMER_H diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp index 6c65994e..db710c66 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp @@ -3,32 +3,34 @@ #include #include +#include "CanonicalFilePathCache.h" #include "CxxDeclNameResolver.h" #include "CxxTypeNameResolver.h" - -#include "CanonicalFilePathCache.h" -#include "utilityClang.h" +#include "IndexerStateInfo.h" +#include "logging.h" #include "ParserClient.h" #include "ParseLocation.h" - +#include "utilityClang.h" #include "utilityString.h" CxxAstVisitor::CxxAstVisitor( clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ) : m_astContext(astContext) , m_preprocessor(preprocessor) , m_client(client) + , m_indexerStateInfo(indexerStateInfo) + , m_canonicalFilePathCache(canonicalFilePathCache) , m_contextComponent(this) , m_declRefKindComponent(this) , m_typeRefKindComponent(this) , m_implicitCodeComponent(this) , m_indexerComponent(this, astContext, client) , m_braceRecorderComponent(this, astContext, client) - , m_canonicalFilePathCache(canonicalFilePathCache) , m_declNameCache([&](const clang::NamedDecl* decl) -> NameHierarchy { if (decl) @@ -99,6 +101,7 @@ CanonicalFilePathCache* CxxAstVisitor::getCanonicalFilePathCache() void CxxAstVisitor::indexDecl(clang::Decl* d) { + LOG_INFO("starting AST traversal"); this->TraverseDecl(d); } @@ -194,7 +197,12 @@ bool CxxAstVisitor::TraverseDecl(clang::Decl* decl) FOREACH_COMPONENT(endTraverseDecl(decl)); } - return m_interruptCounter.getCount() == 0; + if (m_indexerStateInfo && m_indexerStateInfo->indexingInterrupted) + { + LOG_INFO("interrupting AST traversal"); + return false; + } + return true; } // same as Base::TraverseQualifiedTypeLoc(..) but we need to make sure to call this.TraverseTypeLoc(..) diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h index 78079ceb..89e9cf55 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h @@ -5,8 +5,6 @@ #include -#include "MessageInterruptTasksCounter.h" - #include "CxxAstVisitorComponentBraceRecorder.h" #include "CxxAstVisitorComponentContext.h" #include "CxxAstVisitorComponentDeclRefKind.h" @@ -17,9 +15,10 @@ class CanonicalFilePathCache; class ParserClient; -struct ParseLocation; class FilePath; +struct IndexerStateInfo; +struct ParseLocation; // methods are called in this order: // TraverseDecl() @@ -40,7 +39,8 @@ public: clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ); virtual ~CxxAstVisitor() = default; @@ -159,6 +159,8 @@ private: clang::ASTContext* m_astContext; clang::Preprocessor* m_preprocessor; std::shared_ptr m_client; + std::shared_ptr m_indexerStateInfo; + std::shared_ptr m_canonicalFilePathCache; CxxAstVisitorComponentContext m_contextComponent; CxxAstVisitorComponentDeclRefKind m_declRefKindComponent; @@ -167,9 +169,6 @@ private: CxxAstVisitorComponentIndexer m_indexerComponent; CxxAstVisitorComponentBraceRecorder m_braceRecorderComponent; - MessageInterruptTasksCounter m_interruptCounter; - - std::shared_ptr m_canonicalFilePathCache; DeclNameCache m_declNameCache; TypeNameCache m_typeNameCache; }; diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.cpp b/src/lib_cxx/data/parser/cxx/CxxParser.cpp index 3d5219c6..5e0a6e74 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxParser.cpp @@ -130,9 +130,14 @@ namespace } } -CxxParser::CxxParser(std::shared_ptr client, std::shared_ptr fileRegister) +CxxParser::CxxParser( + std::shared_ptr client, + std::shared_ptr fileRegister, + std::shared_ptr indexerStateInfo +) : Parser(client) , m_fileRegister(fileRegister) + , m_indexerStateInfo(indexerStateInfo) { llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmParser(); @@ -161,7 +166,7 @@ void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr(m_fileRegister); std::shared_ptr diagnostics = getDiagnostics(FilePath(), canonicalFilePathCache, false); - ASTActionFactory actionFactory(m_client, canonicalFilePathCache); + ASTActionFactory actionFactory(m_client, canonicalFilePathCache, m_indexerStateInfo); std::vector args = getCommandlineArgumentsEssential(compilerFlags); @@ -191,7 +196,7 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase LOG_INFO("Clang Invocation errors: " + info.errors); } - ASTActionFactory actionFactory(m_client, canonicalFilePathCache); + ASTActionFactory actionFactory(m_client, canonicalFilePathCache, m_indexerStateInfo); tool.run(&actionFactory); } diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.h b/src/lib_cxx/data/parser/cxx/CxxParser.h index d03626c7..a253c750 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.h +++ b/src/lib_cxx/data/parser/cxx/CxxParser.h @@ -21,10 +21,12 @@ namespace clang { } } +struct IndexerStateInfo; + class CxxParser: public Parser { public: - CxxParser(std::shared_ptr client, std::shared_ptr fileRegister); + CxxParser(std::shared_ptr client, std::shared_ptr fileRegister, std::shared_ptr indexerStateInfo); void buildIndex(std::shared_ptr indexerCommand); void buildIndex(const std::wstring& fileName, std::shared_ptr fileContent, std::vector compilerFlags = {}); @@ -40,6 +42,7 @@ private: friend class TaskParseCxx; std::shared_ptr m_fileRegister; + std::shared_ptr m_indexerStateInfo; }; diff --git a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp index 9c57dd23..58ae4a70 100644 --- a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp @@ -15,18 +15,15 @@ CxxVerboseAstVisitor::CxxVerboseAstVisitor( clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ) - : base(context, preprocessor, client, canonicalFilePathCache) + : base(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo) , m_currentFilePath(L"") , m_indentation(0) { } -CxxVerboseAstVisitor::~CxxVerboseAstVisitor() -{ -} - bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl* d) { if (d) diff --git a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h index 961665ef..3e759a6d 100644 --- a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h +++ b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h @@ -16,11 +16,10 @@ public: clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, - std::shared_ptr canonicalFilePathCache + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo ); - virtual ~CxxVerboseAstVisitor(); - private: typedef CxxAstVisitor base; diff --git a/src/lib_gui/qt/view/QtDialogView.cpp b/src/lib_gui/qt/view/QtDialogView.cpp index 116a0c4e..3aeb4dec 100644 --- a/src/lib_gui/qt/view/QtDialogView.cpp +++ b/src/lib_gui/qt/view/QtDialogView.cpp @@ -298,8 +298,7 @@ DatabasePolicy QtDialogView::finishedIndexingDialog( while (!m_resultReady) { - const int SLEEP_TIME_MS = 25; - std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); } return policy; @@ -338,8 +337,7 @@ int QtDialogView::confirm(const std::string& message, const std::vector()) +{ + m_indexerStateInfo->indexingInterrupted = false; +} IndexerJava::~IndexerJava() { JavaParser::clearCaches(); } +void IndexerJava::interrupt() +{ + m_indexerStateInfo->indexingInterrupted = true; +} + std::shared_ptr IndexerJava::doIndex(std::shared_ptr indexerCommand) { std::shared_ptr parserClient = std::make_shared(); - std::shared_ptr parser = std::make_shared(parserClient); + std::shared_ptr parser = std::make_shared(parserClient, m_indexerStateInfo); std::shared_ptr storage = std::make_shared(); parserClient->setStorage(storage); @@ -31,7 +43,7 @@ std::shared_ptr IndexerJava::doIndex(std::shared_ptrsetFilesWithErrorsIncomplete(); } - if (interrupted()) + if (m_indexerStateInfo->indexingInterrupted) { return std::shared_ptr(); } diff --git a/src/lib_java/data/indexer/IndexerJava.h b/src/lib_java/data/indexer/IndexerJava.h index 662f2c31..788a8617 100644 --- a/src/lib_java/data/indexer/IndexerJava.h +++ b/src/lib_java/data/indexer/IndexerJava.h @@ -3,14 +3,22 @@ #include -#include "IndexerCommandJava.h" #include "Indexer.h" +#include "IndexerCommandJava.h" + +struct IndexerStateInfo; class IndexerJava: public Indexer { public: + IndexerJava(); virtual ~IndexerJava(); + void interrupt() override; + +private: std::shared_ptr doIndex(std::shared_ptr indexerCommand) override; + + std::shared_ptr m_indexerStateInfo; }; #endif // INDEXER_JAVA_H diff --git a/src/lib_java/data/parser/java/JavaParser.cpp b/src/lib_java/data/parser/java/JavaParser.cpp index 4b726404..6b27c5fc 100644 --- a/src/lib_java/data/parser/java/JavaParser.cpp +++ b/src/lib_java/data/parser/java/JavaParser.cpp @@ -2,14 +2,15 @@ #include -#include "NameHierarchy.h" -#include "JavaEnvironmentFactory.h" -#include "ParseLocation.h" -#include "ReferenceKind.h" -#include "ParserClient.h" #include "ApplicationSettings.h" -#include "TextAccess.h" +#include "IndexerStateInfo.h" +#include "JavaEnvironmentFactory.h" +#include "NameHierarchy.h" +#include "ParseLocation.h" +#include "ParserClient.h" +#include "ReferenceKind.h" #include "ResourcePaths.h" +#include "TextAccess.h" #include "utilityJava.h" #include "utilityString.h" @@ -29,8 +30,9 @@ void JavaParser::clearCaches() } } -JavaParser::JavaParser(std::shared_ptr client) +JavaParser::JavaParser(std::shared_ptr client, std::shared_ptr indexerStateInfo) : Parser(client) + , m_indexerStateInfo(indexerStateInfo) , m_id(s_nextParserId++) { const std::string errorString = utility::prepareJavaEnvironment(); @@ -140,7 +142,7 @@ std::mutex JavaParser::s_parsersMutex; bool JavaParser::doGetInterrupted() { - return m_interruptCounter.getCount() > 0; + return m_indexerStateInfo->indexingInterrupted; } void JavaParser::doLogInfo(jstring jInfo) diff --git a/src/lib_java/data/parser/java/JavaParser.h b/src/lib_java/data/parser/java/JavaParser.h index 96e59246..5c930b1a 100644 --- a/src/lib_java/data/parser/java/JavaParser.h +++ b/src/lib_java/data/parser/java/JavaParser.h @@ -5,12 +5,12 @@ #include #include -#include "IndexerCommandJava.h" -#include "Parser.h" -#include "JavaEnvironment.h" #include "FilePath.h" +#include "IndexerCommandJava.h" +#include "IndexerStateInfo.h" +#include "JavaEnvironment.h" #include "logging.h" -#include "MessageInterruptTasksCounter.h" +#include "Parser.h" struct JNIEnv_; typedef JNIEnv_ JNIEnv; @@ -35,7 +35,7 @@ class JavaParser: public Parser public: static void clearCaches(); - JavaParser(std::shared_ptr client); + JavaParser(std::shared_ptr client, std::shared_ptr indexerStateInfo); ~JavaParser(); void buildIndex(std::shared_ptr indexerCommand); @@ -231,7 +231,7 @@ private: const int m_id; FilePath m_currentFilePath; - MessageInterruptTasksCounter m_interruptCounter; + std::shared_ptr m_indexerStateInfo; }; #endif // JAVA_PARSER_H diff --git a/src/test/CxxIndexSampleProjectsTestSuite.h b/src/test/CxxIndexSampleProjectsTestSuite.h index 2e5e0a77..0ee9bd1f 100644 --- a/src/test/CxxIndexSampleProjectsTestSuite.h +++ b/src/test/CxxIndexSampleProjectsTestSuite.h @@ -176,7 +176,7 @@ private: std::shared_ptr parserClient = std::make_shared(); - CxxParser parser(parserClient, fileRegister); + CxxParser parser(parserClient, fileRegister, std::make_shared()); std::shared_ptr command = std::make_shared( sourceFilePath, diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 8c20b754..8828e036 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -4128,7 +4128,7 @@ public: ); std::shared_ptr client = std::make_shared(); - CxxParser parser(client, std::make_shared()); + CxxParser parser(client, std::make_shared(), std::make_shared()); parser.buildIndex(indexerCommand); @@ -4398,9 +4398,8 @@ public: private: std::shared_ptr parseCode(std::string code, std::vector compilerFlags = {}) { - std::shared_ptr fileRegister = std::make_shared(); std::shared_ptr parserClient = std::make_shared(); - CxxParser parser(parserClient, fileRegister); + CxxParser parser(parserClient, std::make_shared(), std::make_shared()); parser.buildIndex(L"input.cc", TextAccess::createFromString(code), utility::concat(compilerFlags, std::vector(1, L"-std=c++1z"))); return parserClient; } diff --git a/src/test/JavaIndexSampleProjectsTestSuite.h b/src/test/JavaIndexSampleProjectsTestSuite.h index f8286f9b..2807c1bc 100644 --- a/src/test/JavaIndexSampleProjectsTestSuite.h +++ b/src/test/JavaIndexSampleProjectsTestSuite.h @@ -273,7 +273,7 @@ private: { std::shared_ptr parserClient = std::make_shared(); - JavaParser parser(parserClient); + JavaParser parser(parserClient, std::make_shared()); std::shared_ptr command = std::make_shared(sourceFilePath, L"8", classpath); TimeStamp startTime = TimeStamp::now(); diff --git a/src/test/JavaParserTestSuite.h b/src/test/JavaParserTestSuite.h index 66f66206..46c7e483 100644 --- a/src/test/JavaParserTestSuite.h +++ b/src/test/JavaParserTestSuite.h @@ -1909,7 +1909,7 @@ private: setupJavaEnvironmentFactory(); - JavaParser parser(parserClient); + JavaParser parser(parserClient, std::make_shared()); parser.buildIndex(FilePath(L"input.cc"), textAccess); return parserClient; diff --git a/src/test/SharedMemoryTestSuite.h b/src/test/SharedMemoryTestSuite.h index fcb18946..ebd56905 100644 --- a/src/test/SharedMemoryTestSuite.h +++ b/src/test/SharedMemoryTestSuite.h @@ -1,5 +1,8 @@ #include +#include +#include + #include "SharedMemory.h" class SharedMemoryTestSuite : public CxxTest::TestSuite