diff --git a/CMakeLists.txt b/CMakeLists.txt index 479fc3b5..d672a15d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,11 +234,8 @@ target_link_libraries(${LIB_PROJECT_NAME} ${Boost_LIBRARIES} ${LIB_LICENSE_PROJE add_subdirectory(src/lib_cxx) -set_source_files_properties(${CLANG_FILES} PROPERTIES COMPILE_FLAGS "-fno-rtti") +add_library(${LIB_CXX_PROJECT_NAME} ${LIB_CXX_FILES}) -add_library(${LIB_CXX_PROJECT_NAME} ${CLANG_FILES} ${LIB_CXX_FILES}) - -create_source_groups(${CLANG_FILES}) create_source_groups(${LIB_CXX_FILES}) set_property( diff --git a/src/app/main.cpp b/src/app/main.cpp index c5bd0369..7064c14d 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -3,6 +3,14 @@ #include "ProjectFactoryModuleC.h" #include "ProjectFactoryModuleCpp.h" #include "ProjectFactoryModuleJava.h" + +#include "data/indexer/IndexerFactory.h" +#include "data/indexer/IndexerFactoryModuleJava.h" +#include "data/indexer/IndexerFactoryModuleCxxCdb.h" +#include "data/indexer/IndexerFactoryModuleCxxManual.h" + + + #include "includes.h" // defines 'void setup(int argc, char *argv[])' #include "LicenseChecker.h" #include "qt/network/QtNetworkFactory.h" @@ -141,6 +149,10 @@ int main(int argc, char *argv[]) Application::getInstance()->addProjectFactoryModule(std::make_shared()); Application::getInstance()->addProjectFactoryModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + std::shared_ptr checker = LicenseChecker::getInstance(); if (commandLineParser.startedWithLicense()) @@ -198,6 +210,10 @@ int main(int argc, char *argv[]) Application::getInstance()->addProjectFactoryModule(std::make_shared()); Application::getInstance()->addProjectFactoryModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + if (commandLineParser.hasError()) { Application::getInstance()->handleDialog(commandLineParser.getError()); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 4e77dc28..3e2b1efa 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -135,6 +135,22 @@ add_files( data/graph/Node.h data/graph/Token.cpp data/graph/Token.h + + data/indexer/Indexer.h + data/indexer/IndexerBase.cpp + data/indexer/IndexerBase.h + data/indexer/IndexerCommand.cpp + data/indexer/IndexerCommand.h + data/indexer/IndexerCommandList.cpp + data/indexer/IndexerCommandList.h + data/indexer/IndexerComposite.cpp + data/indexer/IndexerComposite.h + data/indexer/IndexerFactory.cpp + data/indexer/IndexerFactory.h + data/indexer/IndexerFactoryModule.cpp + data/indexer/IndexerFactoryModule.h + data/indexer/TaskBuildIndex.cpp + data/indexer/TaskBuildIndex.h data/location/LocationType.cpp data/location/LocationType.h @@ -166,8 +182,6 @@ add_files( data/parser/ReferenceKind.h data/parser/SymbolKind.cpp data/parser/SymbolKind.h - data/parser/TaskParse.cpp - data/parser/TaskParse.h data/parser/TaskParseWrapper.cpp data/parser/TaskParseWrapper.h @@ -205,6 +219,8 @@ add_files( data/TaskFinishParsing.h data/TaskInjectStorage.cpp data/TaskInjectStorage.h + data/TaskMergeStorages.cpp + data/TaskMergeStorages.h data/TaskShowStatusDialog.cpp data/TaskShowStatusDialog.h @@ -236,6 +252,8 @@ add_files( utility/file/FilePath.h utility/file/FileRegister.cpp utility/file/FileRegister.h + utility/file/FileRegisterStateData.cpp + utility/file/FileRegisterStateData.h utility/file/FileSystem.cpp utility/file/FileSystem.h @@ -377,6 +395,7 @@ add_files( utility/scheduling/TaskRunner.h utility/scheduling/TaskScheduler.cpp utility/scheduling/TaskScheduler.h + utility/scheduling/TaskSetValue.h utility/solution/ISolutionParser.cpp utility/solution/ISolutionParser.h diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 51456ae7..171eb8a4 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -2,18 +2,21 @@ #include "component/view/DialogView.h" #include "data/access/StorageAccessProxy.h" +#include "data/indexer/IndexerCommand.h" +#include "data/indexer/IndexerCommandList.h" +#include "data/indexer/TaskBuildIndex.h" #include "data/parser/TaskParseWrapper.h" -#include "data/parser/java/TaskParseJava.h" #include "data/StorageProvider.h" #include "data/PersistentStorage.h" #include "data/TaskCleanStorage.h" +#include "data/TaskMergeStorages.h" #include "data/TaskShowStatusDialog.h" #include "data/TaskFinishParsing.h" #include "data/TaskInjectStorage.h" #include "settings/ApplicationSettings.h" #include "settings/ProjectSettings.h" -#include "utility/file/FileRegister.h" +#include "utility/file/FileRegisterStateData.h" #include "utility/messaging/type/MessageClearErrorCount.h" #include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" #include "utility/messaging/type/MessageFinishedParsing.h" @@ -24,6 +27,7 @@ #include "utility/scheduling/TaskGroupSequence.h" #include "utility/scheduling/TaskGroupParallel.h" #include "utility/scheduling/TaskReturnSuccessWhile.h" +#include "utility/scheduling/TaskSetValue.h" #include "utility/text/TextAccess.h" #include "utility/utility.h" #include "utility/utilityString.h" @@ -152,6 +156,13 @@ std::string Project::getDescription() const return getProjectSettings()->getDescription(); } +#include "utility/file/FileSystem.h" + +std::set Project::getSourceFilePaths() const +{ + return m_fileManager.getSourceFilePaths(); +} + bool Project::settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const { return getProjectSettings()->equalsExceptNameAndLocation(otherSettings); @@ -177,7 +188,7 @@ DialogView* Project::getDialogView() const return m_dialogView; } -const std::vector& Project::getSourcePaths() const +std::vector Project::getSourcePaths() const { return m_fileManager.getSourcePaths(); } @@ -287,7 +298,7 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) } // handle referenced paths - std::set staticSourceFiles = fileSets.allFiles; + std::set staticSourceFiles = fileSets.allSourceFilePaths; for (const FilePath& path : fileSets.updatedFiles) { staticSourceFiles.erase(path); @@ -313,7 +324,7 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) if (Application::getInstance()->hasGUI()) { DialogView::IndexMode mode = m_dialogView->startIndexingDialog( - filesToClean.size(), filesToIndex.size(), fileSets.allFiles.size(), + filesToClean.size(), filesToIndex.size(), fileSets.allSourceFilePaths.size(), forceRefresh, needsFullRefresh ); @@ -333,7 +344,7 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) if (fullRefresh) { filesToClean.clear(); - filesToIndex = fileSets.allFiles; + filesToIndex = fileSets.allSourceFilePaths; } if (!filesToClean.size() && !filesToIndex.size()) @@ -362,6 +373,7 @@ void Project::buildIndex(const std::set& filesToClean, const std::set< std::shared_ptr taskSequential = std::make_shared(); + // add task for cleaning the database if (!filesToClean.empty()) { taskSequential->addTask(std::make_shared( @@ -371,17 +383,31 @@ void Project::buildIndex(const std::set& filesToClean, const std::set< ); } - const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount(); - - std::shared_ptr fileRegister = std::make_shared(&m_fileManager, indexerThreadCount > 1); - if (!filesToIndex.empty()) { - fileRegister->setFilePaths(utility::toVector(filesToIndex)); + const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount(); + + std::shared_ptr indexerCommandList = std::make_shared(); + for (std::shared_ptr indexerCommand: getIndexerCommands(filesToIndex)) + { + indexerCommandList->addCommand(indexerCommand); + } + if (indexerThreadCount > 1) + { + indexerCommandList->shuffle(); + } + + std::shared_ptr fileRegisterStateData = std::make_shared(); + + std::shared_ptr storageProvider = std::make_shared(); + + // add tasks for setting some variables on the blackboard that are used during indexing + taskSequential->addTask(std::make_shared>("source_file_count", indexerCommandList->size())); + taskSequential->addTask(std::make_shared>("indexed_source_file_count", 0)); + taskSequential->addTask(std::make_shared>("indexer_count", 0)); std::shared_ptr taskParserWrapper = std::make_shared( m_storage.get(), - fileRegister, m_dialogView ); taskSequential->addTask(taskParserWrapper); @@ -389,17 +415,32 @@ void Project::buildIndex(const std::set& filesToClean, const std::set< std::shared_ptr taskParallelIndexing = std::make_shared(); taskParserWrapper->setTask(taskParallelIndexing); - std::shared_ptr storageProvider = std::make_shared(); - + // add tasks for indexing and merging for (size_t i = 0; i < indexerThreadCount && i < filesToIndex.size(); i++) { taskParallelIndexing->addChildTasks( std::make_shared(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask( - createIndexerTask(storageProvider, fileRegister) + std::make_shared(indexerCommandList, storageProvider, fileRegisterStateData, getDialogView()) ) ); } + // add task for merging the intermediate storages + taskParallelIndexing->addTask( + std::make_shared()->addChildTasks( + std::make_shared(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask( + std::make_shared>("indexer_count", TaskReturnSuccessWhile::CONDITION_EQUALS, 0) + ), + std::make_shared(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask( + std::make_shared()->addChildTasks( + std::make_shared(storageProvider), + std::make_shared>("indexer_count", TaskReturnSuccessWhile::CONDITION_GREATER_THAN, 0) + ) + ) + ) + ); + + // add task for injecting the intermediate storages into the persistent storage taskParallelIndexing->addTask( std::make_shared()->addChildTasks( std::make_shared(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask( @@ -419,10 +460,12 @@ void Project::buildIndex(const std::set& filesToClean, const std::set< ) ); + // add task that notifies the user of what's going on taskSequential->addTask( // we don't need to hide this dialog again, because it's overridden by other dialogs later on. std::make_shared("Finish Indexing", "Saving\nRemaining Data", m_dialogView) ); + // add task that injects the remaining intermediate storages into the persistent storage taskSequential->addTask( std::make_shared(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask( std::make_shared(storageProvider, m_storage) @@ -430,7 +473,7 @@ void Project::buildIndex(const std::set& filesToClean, const std::set< ); } - taskSequential->addTask(std::make_shared(m_storage.get(), m_storageAccessProxy, fileRegister, m_dialogView)); + taskSequential->addTask(std::make_shared(m_storage.get(), m_storageAccessProxy, m_dialogView)); Task::dispatch(taskSequential); } @@ -444,3 +487,28 @@ bool Project::prepareRefresh() { return true; } + +std::vector> Project::getIndexerCommands(const std::set& sourceFiles) +{ + struct special_compare : public std::unary_function + { + explicit special_compare(const FilePath& baseline) : m_baseline(baseline) {} + bool operator() (const FilePath& arg) + { + return arg.str() == m_baseline.str(); + } + const FilePath m_baseline; + }; + + std::vector> indexerCommands; + for (std::shared_ptr indexerCommand: getIndexerCommands()) + { + if (std::find_if(sourceFiles.begin(), sourceFiles.end(), special_compare(indexerCommand->getSourceFilePath())) != sourceFiles.end()) + { + indexerCommands.push_back(indexerCommand); + } + } + + return indexerCommands; +} + diff --git a/src/lib/Project.h b/src/lib/Project.h index af4a1b82..3864f31d 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -16,7 +16,7 @@ class PersistentStorage; class StorageProvider; class ProjectSettings; class StorageAccessProxy; -class Task; +class IndexerCommand; class Project { @@ -29,13 +29,15 @@ public: LanguageType getLanguage() const; std::string getDescription() const; + std::set getSourceFilePaths() const; + bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const; void setStateSettingsUpdated(); protected: Project(StorageAccessProxy* storageAccessProxy, DialogView* dialogView); DialogView* getDialogView() const; - const std::vector& getSourcePaths() const; + std::vector getSourcePaths() const; virtual std::shared_ptr getProjectSettings() = 0; virtual const std::shared_ptr getProjectSettings() const = 0; @@ -63,9 +65,8 @@ private: virtual bool prepareIndexing(); virtual bool prepareRefresh(); - virtual std::shared_ptr createIndexerTask( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister) = 0; + virtual std::vector> getIndexerCommands() = 0; + std::vector> getIndexerCommands(const std::set& sourceFiles); virtual void updateFileManager(FileManager& fileManager) = 0; StorageAccessProxy* const m_storageAccessProxy; diff --git a/src/lib/data/StorageProvider.cpp b/src/lib/data/StorageProvider.cpp index 70160f50..7cc5c2b2 100644 --- a/src/lib/data/StorageProvider.cpp +++ b/src/lib/data/StorageProvider.cpp @@ -8,7 +8,7 @@ int StorageProvider::getStorageCount() const return m_storages.size(); } -void StorageProvider::pushIndexerTarget(std::shared_ptr storage) +void StorageProvider::insert(std::shared_ptr storage) { const std::size_t storageSize = storage->getSourceLocationCount(); std::list>::iterator it; @@ -24,7 +24,7 @@ void StorageProvider::pushIndexerTarget(std::shared_ptr sto m_storages.insert(it, storage); } -std::shared_ptr StorageProvider::popIndexerTarget() +std::shared_ptr StorageProvider::consumeSecondLargestStorage() { std::shared_ptr ret; { @@ -36,15 +36,11 @@ std::shared_ptr StorageProvider::popIndexerTarget() ret = *it; m_storages.erase(it); } - else - { - ret = std::make_shared(); - } } return ret; } -std::shared_ptr StorageProvider::popInjectionSource() +std::shared_ptr StorageProvider::consumeLargestStorage() { std::shared_ptr ret; { diff --git a/src/lib/data/StorageProvider.h b/src/lib/data/StorageProvider.h index 3d19e6db..9b24ff06 100644 --- a/src/lib/data/StorageProvider.h +++ b/src/lib/data/StorageProvider.h @@ -10,13 +10,14 @@ class StorageProvider { public: int getStorageCount() const; - void pushIndexerTarget(std::shared_ptr storage); - // always returns a usable storage - std::shared_ptr popIndexerTarget(); + void insert(std::shared_ptr storage); // returns empty shared_ptr if no storages available - std::shared_ptr popInjectionSource(); + std::shared_ptr consumeSecondLargestStorage(); + + // returns empty shared_ptr if no storages available + std::shared_ptr consumeLargestStorage(); void logCurrentState() const; diff --git a/src/lib/data/TaskFinishParsing.cpp b/src/lib/data/TaskFinishParsing.cpp index 359d90cf..f17f5ecb 100644 --- a/src/lib/data/TaskFinishParsing.cpp +++ b/src/lib/data/TaskFinishParsing.cpp @@ -10,12 +10,10 @@ TaskFinishParsing::TaskFinishParsing( PersistentStorage* storage, StorageAccess* storageAccess, - std::shared_ptr fileRegister, DialogView* dialogView ) : m_storage(storage) , m_storageAccess(storageAccess) - , m_fileRegister(fileRegister) , m_dialogView(dialogView) { } @@ -58,9 +56,15 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr blackboa time += indexTime; } + int indexedSourceFileCount = 0; + blackboard->get("indexed_source_file_count", indexedSourceFileCount); + + int sourceFileCount = 0; + blackboard->get("source_file_count", sourceFileCount); + m_dialogView->finishedIndexingDialog( - m_fileRegister->getParsedSourceFilesCount(), - m_fileRegister->getSourceFilesCount(), + indexedSourceFileCount, + sourceFileCount, time, m_storageAccess->getErrorCount() ); diff --git a/src/lib/data/TaskFinishParsing.h b/src/lib/data/TaskFinishParsing.h index e2632d6b..10e1e6a2 100644 --- a/src/lib/data/TaskFinishParsing.h +++ b/src/lib/data/TaskFinishParsing.h @@ -18,7 +18,6 @@ public: TaskFinishParsing( PersistentStorage* storage, StorageAccess* storageAccess, - std::shared_ptr fileRegister, DialogView* dialogView ); @@ -32,7 +31,6 @@ private: PersistentStorage* m_storage; StorageAccess* m_storageAccess; - std::shared_ptr m_fileRegister; DialogView* m_dialogView; }; diff --git a/src/lib/data/TaskInjectStorage.cpp b/src/lib/data/TaskInjectStorage.cpp index 82bbcd81..d2df93bc 100644 --- a/src/lib/data/TaskInjectStorage.cpp +++ b/src/lib/data/TaskInjectStorage.cpp @@ -23,7 +23,7 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr blackboa { if (m_storageProvider->getStorageCount() > 0) { - std::shared_ptr source = m_storageProvider->popInjectionSource(); + std::shared_ptr source = m_storageProvider->consumeLargestStorage(); if (source) { m_target->inject(source.get()); diff --git a/src/lib/data/TaskMergeStorages.cpp b/src/lib/data/TaskMergeStorages.cpp new file mode 100644 index 00000000..a739bde8 --- /dev/null +++ b/src/lib/data/TaskMergeStorages.cpp @@ -0,0 +1,58 @@ +#include "data/TaskMergeStorages.h" + +#include +#include + +#include "data/StorageProvider.h" + +TaskMergeStorages::TaskMergeStorages( + std::shared_ptr storageProvider +) + : m_storageProvider(storageProvider) +{ +} + +void TaskMergeStorages::doEnter(std::shared_ptr blackboard) +{ +} + +Task::TaskState TaskMergeStorages::doUpdate(std::shared_ptr blackboard) +{ + if (m_storageProvider->getStorageCount() > 2) // largest storage won't be touched here + { + std::shared_ptr target = m_storageProvider->consumeSecondLargestStorage(); + std::shared_ptr source = m_storageProvider->consumeSecondLargestStorage(); + if (target && source) + { + target->inject(source.get()); + m_storageProvider->insert(target); + return STATE_SUCCESS; + } + else + { + if (target) + { + m_storageProvider->insert(target); + } + if (source) + { + m_storageProvider->insert(source); + } + } + } + else + { + const int SLEEP_TIME_MS = 25; + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + } + + return STATE_FAILURE; +} + +void TaskMergeStorages::doExit(std::shared_ptr blackboard) +{ +} + +void TaskMergeStorages::doReset(std::shared_ptr blackboard) +{ +} diff --git a/src/lib/data/TaskMergeStorages.h b/src/lib/data/TaskMergeStorages.h new file mode 100644 index 00000000..8d191cea --- /dev/null +++ b/src/lib/data/TaskMergeStorages.h @@ -0,0 +1,27 @@ +#ifndef TASK_MERGE_STORAGES_H +#define TASK_MERGE_STORAGES_H + +#include + +#include "utility/scheduling/Task.h" + +class StorageProvider; + +class TaskMergeStorages + : public Task +{ +public: + TaskMergeStorages( + std::shared_ptr storageProvider + ); + +private: + virtual void doEnter(std::shared_ptr blackboard); + virtual TaskState doUpdate(std::shared_ptr blackboard); + virtual void doExit(std::shared_ptr blackboard); + virtual void doReset(std::shared_ptr blackboard); + + std::shared_ptr m_storageProvider; +}; + +#endif // TASK_MERGE_STORAGES_H diff --git a/src/lib/data/indexer/Indexer.h b/src/lib/data/indexer/Indexer.h new file mode 100644 index 00000000..15a34f67 --- /dev/null +++ b/src/lib/data/indexer/Indexer.h @@ -0,0 +1,46 @@ +#ifndef INDEXER_H +#define INDEXER_H + +#include + +#include "data/indexer/IndexerBase.h" +#include "utility/logging/logging.h" + +template +class Indexer: public IndexerBase +{ +public: + virtual ~Indexer(); + + virtual std::string getKindString() const; + + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister); + +private: + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) = 0; +}; + +template +Indexer::~Indexer() +{ +} + +template +std::string Indexer::getKindString() const +{ + return IndexerCommandType::getIndexerKindString(); +} + +template +std::shared_ptr Indexer::index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) +{ + if (std::shared_ptr castedCommand = std::dynamic_pointer_cast(indexerCommand)) + { + return index(castedCommand, fileRegister); + } + + LOG_ERROR("Trying to process " + indexerCommand->getKindString() + " indexer command with " + getKindString() + " indexer."); + return std::shared_ptr(); +} + +#endif // INDEXER_H diff --git a/src/lib/data/indexer/IndexerBase.cpp b/src/lib/data/indexer/IndexerBase.cpp new file mode 100644 index 00000000..348aa9ff --- /dev/null +++ b/src/lib/data/indexer/IndexerBase.cpp @@ -0,0 +1,20 @@ +#include "data/indexer/IndexerBase.h" + +IndexerBase::IndexerBase() + : m_interrupted(false) +{ +} + +IndexerBase::~IndexerBase() +{ +} + +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 new file mode 100644 index 00000000..014f3652 --- /dev/null +++ b/src/lib/data/indexer/IndexerBase.h @@ -0,0 +1,29 @@ +#ifndef INDEXER_BASE_H +#define INDEXER_BASE_H + +#include + +#include "data/indexer/IndexerCommand.h" +#include "data/IntermediateStorage.h" + +class FileRegister; + +class IndexerBase +{ +public: + IndexerBase(); + virtual ~IndexerBase(); + + virtual std::string getKindString() const = 0; + + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) = 0; + + virtual void interrupt(); + + bool interrupted() const; + +private: + bool m_interrupted; +}; + +#endif // INDEXER_BASE_H diff --git a/src/lib/data/indexer/IndexerCommand.cpp b/src/lib/data/indexer/IndexerCommand.cpp new file mode 100644 index 00000000..d28633a3 --- /dev/null +++ b/src/lib/data/indexer/IndexerCommand.cpp @@ -0,0 +1,28 @@ +#include "data/indexer/IndexerCommand.h" + +IndexerCommand::IndexerCommand(const FilePath& sourceFilePath, const std::set& indexedPaths, const std::set& excludedPaths) + : m_sourceFilePath(sourceFilePath) + , m_indexedPaths(indexedPaths) + , m_excludedPaths(excludedPaths) +{ +} + + +IndexerCommand::~IndexerCommand() +{ +} + +FilePath IndexerCommand::getSourceFilePath() const +{ + return m_sourceFilePath; +} + +std::set IndexerCommand::getIndexedPaths() const +{ + return m_indexedPaths; +} + +std::set IndexerCommand::getExcludedPath() const +{ + return m_excludedPaths; +} diff --git a/src/lib/data/indexer/IndexerCommand.h b/src/lib/data/indexer/IndexerCommand.h new file mode 100644 index 00000000..53b6f30a --- /dev/null +++ b/src/lib/data/indexer/IndexerCommand.h @@ -0,0 +1,27 @@ +#ifndef INDEXER_COMMAND_H +#define INDEXER_COMMAND_H + +#include +#include + +#include "utility/file/FilePath.h" + +class IndexerCommand +{ +public: + IndexerCommand(const FilePath& sourceFilePath, const std::set& indexedPaths, const std::set& excludedPaths); + virtual ~IndexerCommand(); + + virtual std::string getKindString() const = 0; + + FilePath getSourceFilePath() const; + std::set getIndexedPaths() const; + std::set getExcludedPath() const; + +private: + FilePath m_sourceFilePath; + std::set m_indexedPaths; + std::set m_excludedPaths; +}; + +#endif // INDEXER_COMMAND_H diff --git a/src/lib/data/indexer/IndexerCommandList.cpp b/src/lib/data/indexer/IndexerCommandList.cpp new file mode 100644 index 00000000..d184efe3 --- /dev/null +++ b/src/lib/data/indexer/IndexerCommandList.cpp @@ -0,0 +1,34 @@ +#include "data/indexer/IndexerCommandList.h" + +#include +#include + +void IndexerCommandList::addCommand(std::shared_ptr command) +{ + std::lock_guard lock(m_commandsMutex); + m_commands.push_back(command); +} + +int IndexerCommandList::size() const +{ + return m_commands.size(); +} + +void IndexerCommandList::shuffle() +{ + srand(unsigned(time(NULL))); + std::lock_guard lock(m_commandsMutex); + std::random_shuffle(m_commands.begin(), m_commands.end()); +} + +std::shared_ptr IndexerCommandList::consumeCommand() +{ + std::lock_guard lock(m_commandsMutex); + std::shared_ptr ret; + if (!m_commands.empty()) + { + ret = m_commands.front(); + m_commands.pop_front(); + } + return ret; +} diff --git a/src/lib/data/indexer/IndexerCommandList.h b/src/lib/data/indexer/IndexerCommandList.h new file mode 100644 index 00000000..ca242095 --- /dev/null +++ b/src/lib/data/indexer/IndexerCommandList.h @@ -0,0 +1,26 @@ +#ifndef INDEXER_COMMAND_LIST_H +#define INDEXER_COMMAND_LIST_H + +#include +#include +#include + +#include "data/indexer/IndexerCommand.h" + +class IndexerCommandList +{ +public: + void addCommand(std::shared_ptr command); + + int size() const; + + void shuffle(); + + std::shared_ptr consumeCommand(); + +private: + std::deque> m_commands; + std::mutex m_commandsMutex; +}; + +#endif // INDEXER_COMMAND_LIST_H diff --git a/src/lib/data/indexer/IndexerComposite.cpp b/src/lib/data/indexer/IndexerComposite.cpp new file mode 100644 index 00000000..73f5a45e --- /dev/null +++ b/src/lib/data/indexer/IndexerComposite.cpp @@ -0,0 +1,37 @@ +#include "data/indexer/IndexerComposite.h" +#include "utility/logging/logging.h" + +IndexerComposite::~IndexerComposite() +{ +} + +std::string IndexerComposite::getKindString() const +{ + return "composite"; +} + +void IndexerComposite::addIndexer(std::shared_ptr indexer) +{ + m_indexers.emplace(indexer->getKindString(), indexer); +} + +std::shared_ptr IndexerComposite::index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) +{ + auto it = m_indexers.find(indexerCommand->getKindString()); + if (it != m_indexers.end()) + { + return it->second->index(indexerCommand, fileRegister); + } + + LOG_ERROR("No indexer found to handle " + indexerCommand->getKindString() + " indexer command."); + return std::shared_ptr(); +} + +void IndexerComposite::interrupt() +{ + for (auto it: m_indexers) + { + it.second->interrupt(); + } + IndexerBase::interrupt(); +} diff --git a/src/lib/data/indexer/IndexerComposite.h b/src/lib/data/indexer/IndexerComposite.h new file mode 100644 index 00000000..f22d8532 --- /dev/null +++ b/src/lib/data/indexer/IndexerComposite.h @@ -0,0 +1,26 @@ +#ifndef INDEXER_COMPOSITE_H +#define INDEXER_COMPOSITE_H + +#include +#include + +#include "data/indexer/IndexerBase.h" + +class IndexerComposite: public IndexerBase +{ +public: + virtual ~IndexerComposite(); + + virtual std::string getKindString() const; + + void addIndexer(std::shared_ptr indexer); + + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister); + + virtual void interrupt(); + +private: + std::unordered_map> m_indexers; +}; + +#endif // INDEXER_COMPOSITE_H diff --git a/src/lib/data/indexer/IndexerFactory.cpp b/src/lib/data/indexer/IndexerFactory.cpp new file mode 100644 index 00000000..21bd832f --- /dev/null +++ b/src/lib/data/indexer/IndexerFactory.cpp @@ -0,0 +1,41 @@ +#include "data/indexer/IndexerFactory.h" + +#include "data/indexer/IndexerBase.h" +#include "data/indexer/IndexerComposite.h" +#include "IndexerFactoryModule.h" + +std::shared_ptr IndexerFactory::getInstance() +{ + if (!s_instance) + { + s_instance = std::shared_ptr(new IndexerFactory()); + } + return s_instance; +} + +void IndexerFactory::destroyInstance() +{ + s_instance.reset(); +} + + +void IndexerFactory::addModule(std::shared_ptr module) +{ + m_modules.push_back(module); +} + +std::shared_ptr IndexerFactory::createCompositeIndexerForAllRegisteredModules() +{ + std::shared_ptr composite = std::make_shared(); + for (auto it: m_modules) + { + composite->addIndexer(it->createIndexer()); + } + return composite; +} + +std::shared_ptr IndexerFactory::s_instance; + +IndexerFactory::IndexerFactory() +{ +} diff --git a/src/lib/data/indexer/IndexerFactory.h b/src/lib/data/indexer/IndexerFactory.h new file mode 100644 index 00000000..a0b96a81 --- /dev/null +++ b/src/lib/data/indexer/IndexerFactory.h @@ -0,0 +1,29 @@ +#ifndef INDEXER_FACTORY_H +#define INDEXER_FACTORY_H + +#include +#include + +#include "settings/LanguageType.h" + +class IndexerBase; +class IndexerComposite; +class IndexerFactoryModule; + +class IndexerFactory +{ +public: + static std::shared_ptr getInstance(); + static void destroyInstance(); + + void addModule(std::shared_ptr module); + std::shared_ptr createCompositeIndexerForAllRegisteredModules(); + +private: + static std::shared_ptr s_instance; + IndexerFactory(); + + std::vector> m_modules; +}; + +#endif // INDEXER_FACTORY_H diff --git a/src/lib/data/indexer/IndexerFactoryModule.cpp b/src/lib/data/indexer/IndexerFactoryModule.cpp new file mode 100644 index 00000000..72b69bbd --- /dev/null +++ b/src/lib/data/indexer/IndexerFactoryModule.cpp @@ -0,0 +1,5 @@ +#include "data/indexer/IndexerFactoryModule.h" + +IndexerFactoryModule::~IndexerFactoryModule() +{ +} diff --git a/src/lib/data/indexer/IndexerFactoryModule.h b/src/lib/data/indexer/IndexerFactoryModule.h new file mode 100644 index 00000000..a6b2c85f --- /dev/null +++ b/src/lib/data/indexer/IndexerFactoryModule.h @@ -0,0 +1,17 @@ +#ifndef INDEXER_FACTORY_MODULE_H +#define INDEXER_FACTORY_MODULE_H + +#include + +#include "settings/LanguageType.h" + +class IndexerBase; + +class IndexerFactoryModule +{ +public: + virtual ~IndexerFactoryModule(); + virtual std::shared_ptr createIndexer() = 0; +}; + +#endif // INDEXER_FACTORY_MODULE_H diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp new file mode 100644 index 00000000..f3b5c2bb --- /dev/null +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -0,0 +1,109 @@ +#include "data/indexer/TaskBuildIndex.h" + +#include "data/indexer/IndexerFactory.h" +#include "data/indexer/IndexerCommandList.h" +#include "data/indexer/IndexerComposite.h" +#include "data/StorageProvider.h" +#include "component/view/DialogView.h" +#include "utility/file/FileRegister.h" +#include "utility/file/FileRegisterStateData.h" +#include "utility/scheduling/Blackboard.h" +#include "ApplicationStateMonitor.h" + +TaskBuildIndex::TaskBuildIndex( + std::shared_ptr indexerCommandList, + std::shared_ptr storageProvider, + std::shared_ptr fileRegisterStateData, + DialogView* dialogView +) + : m_indexerCommandList(indexerCommandList) + , m_storageProvider(storageProvider) + , m_fileRegisterStateData(fileRegisterStateData) + , m_dialogView(dialogView) +{ + m_indexer = IndexerFactory::getInstance()->createCompositeIndexerForAllRegisteredModules(); +} + +void TaskBuildIndex::doEnter(std::shared_ptr blackboard) +{ + std::lock_guard lock(blackboard->getMutex()); + + int indexerCount = 0; + if (blackboard->get("indexer_count", indexerCount)) + { + indexerCount++; + blackboard->set("indexer_count", indexerCount); + } +} + +Task::TaskState TaskBuildIndex::doUpdate(std::shared_ptr blackboard) +{ + std::shared_ptr indexerCommand = m_indexerCommandList->consumeCommand(); + + if (!indexerCommand) + { + return STATE_FAILURE; + } + else + { + ApplicationStateMonitor::getInstance()->addIndexingFile(indexerCommand->getSourceFilePath()); + + { + std::lock_guard lock(blackboard->getMutex()); + + int sourceFileCount = 0; + blackboard->get("source_file_count", sourceFileCount); + + int indexedSourceFileCount = 0; + blackboard->get("indexed_source_file_count", indexedSourceFileCount); + + m_dialogView->updateIndexingDialog( + indexedSourceFileCount, sourceFileCount, indexerCommand->getSourceFilePath().str() + ); + } + + // file register only copies the DileRegisterStateData + std::shared_ptr fileRegister = std::make_shared( + *(m_fileRegisterStateData.get()), indexerCommand->getIndexedPaths(), indexerCommand->getExcludedPath() + ); + + std::shared_ptr storage = m_indexer->index(indexerCommand, fileRegister); + if (storage) + { + // only write back the changes made to FileRegisterStateData if the indexer actually succeeded + m_fileRegisterStateData->inject(fileRegister->getStateData()); + + m_storageProvider->insert(storage); + + std::lock_guard lock(blackboard->getMutex()); + int indexedSourceFileCount = 0; + blackboard->get("indexed_source_file_count", indexedSourceFileCount); + blackboard->set("indexed_source_file_count", indexedSourceFileCount + 1); + } + + ApplicationStateMonitor::getInstance()->removeIndexingFile(indexerCommand->getSourceFilePath()); + } + + return (m_indexer->interrupted() ? STATE_FAILURE : STATE_SUCCESS); +} + +void TaskBuildIndex::doExit(std::shared_ptr blackboard) +{ + std::lock_guard lock(blackboard->getMutex()); + + int indexerCount = 0; + if (blackboard->get("indexer_count", indexerCount)) + { + indexerCount--; + blackboard->set("indexer_count", indexerCount); + } +} + +void TaskBuildIndex::doReset(std::shared_ptr blackboard) +{ +} + +void TaskBuildIndex::handleMessage(MessageInterruptTasks* message) +{ + m_indexer->interrupt(); +} diff --git a/src/lib/data/parser/TaskParse.h b/src/lib/data/indexer/TaskBuildIndex.h similarity index 64% rename from src/lib/data/parser/TaskParse.h rename to src/lib/data/indexer/TaskBuildIndex.h index 9c3b5936..ae635e89 100644 --- a/src/lib/data/parser/TaskParse.h +++ b/src/lib/data/indexer/TaskBuildIndex.h @@ -1,5 +1,5 @@ -#ifndef TASK_PARSE_H -#define TASK_PARSE_H +#ifndef TASK_BUILD_INDEX_H +#define TASK_BUILD_INDEX_H #include "data/parser/Parser.h" #include "utility/scheduling/Task.h" @@ -8,18 +8,20 @@ class CxxParser; class DialogView; -class FileRegister; +class FileRegisterStateData; class StorageProvider; +class IndexerCommandList; +class IndexerBase; -class TaskParse +class TaskBuildIndex : public Task , public MessageListener { public: - TaskParse( + TaskBuildIndex( + std::shared_ptr indexerCommandList, std::shared_ptr storageProvider, - std::shared_ptr fileRegister, - const Parser::Arguments& arguments, + std::shared_ptr fileRegisterStateData, DialogView* dialogView ); @@ -30,15 +32,13 @@ protected: virtual void doReset(std::shared_ptr blackboard); virtual void handleMessage(MessageInterruptTasks* message); - virtual void indexFile(FilePath sourcePath) = 0; + std::shared_ptr m_indexerCommandList; std::shared_ptr m_storageProvider; - std::shared_ptr m_fileRegister; - - const Parser::Arguments m_arguments; + std::shared_ptr m_fileRegisterStateData; DialogView* m_dialogView; - bool m_interrupted; + std::shared_ptr m_indexer; }; #endif // TASK_PARSE_H diff --git a/src/lib/data/parser/Parser.cpp b/src/lib/data/parser/Parser.cpp index 721ee5e6..82722ca2 100644 --- a/src/lib/data/parser/Parser.cpp +++ b/src/lib/data/parser/Parser.cpp @@ -1,11 +1,7 @@ #include "data/parser/Parser.h" -Parser::Arguments::Arguments() - : logErrors(true) -{ -} -Parser::Parser(ParserClient* client) +Parser::Parser(std::shared_ptr client) : m_client(client) { } diff --git a/src/lib/data/parser/Parser.h b/src/lib/data/parser/Parser.h index e1a615d5..88a7112f 100644 --- a/src/lib/data/parser/Parser.h +++ b/src/lib/data/parser/Parser.h @@ -13,33 +13,11 @@ class TextAccess; class Parser { public: - struct Arguments - { - Arguments(); - - std::vector javaClassPaths; - - std::vector headerSearchPaths; - std::vector systemHeaderSearchPaths; - std::vector frameworkSearchPaths; - std::vector compilerFlags; - - bool logErrors; - - std::string language; - std::string languageStandard; - - FilePath compilationDatabasePath; - }; - - Parser(ParserClient* client); + Parser(std::shared_ptr client); virtual ~Parser(); - virtual void parseFiles(const std::vector& filePaths, const Arguments& arguments) = 0; - virtual void parseFile(const FilePath& filePath, std::shared_ptr textAccess, const Arguments& arguments) = 0; - protected: - ParserClient* m_client; + std::shared_ptr m_client; }; #endif // PARSER_H diff --git a/src/lib/data/parser/TaskParse.cpp b/src/lib/data/parser/TaskParse.cpp deleted file mode 100644 index 80606102..00000000 --- a/src/lib/data/parser/TaskParse.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "data/parser/TaskParse.h" - -#include "component/view/DialogView.h" -#include "utility/file/FileRegister.h" -#include "utility/scheduling/Blackboard.h" -#include "ApplicationStateMonitor.h" - -TaskParse::TaskParse( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister, - const Parser::Arguments& arguments, - DialogView* dialogView -) - : m_storageProvider(storageProvider) - , m_fileRegister(fileRegister) - , m_arguments(arguments) - , m_dialogView(dialogView) - , m_interrupted(false) -{ -} - -void TaskParse::doEnter(std::shared_ptr blackboard) -{ - std::lock_guard lock(blackboard->getMutex()); - - int indexerCount = 0; - if (blackboard->get("indexer_count", indexerCount)) - { - indexerCount++; - blackboard->set("indexer_count", indexerCount); - } -} - -Task::TaskState TaskParse::doUpdate(std::shared_ptr blackboard) -{ - FilePath sourcePath = m_fileRegister->consumeSourceFile(); - - if (sourcePath.empty()) - { - return STATE_FAILURE; - } - else - { - ApplicationStateMonitor::getInstance()->addIndexingFile(sourcePath); - m_dialogView->updateIndexingDialog( - m_fileRegister->getParsedSourceFilesCount(), m_fileRegister->getSourceFilesCount(), sourcePath.str() - ); - - indexFile(sourcePath); - ApplicationStateMonitor::getInstance()->removeIndexingFile(sourcePath); - } - - return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS); -} - -void TaskParse::doExit(std::shared_ptr blackboard) -{ - std::lock_guard lock(blackboard->getMutex()); - - int indexerCount = 0; - if (blackboard->get("indexer_count", indexerCount)) - { - indexerCount--; - blackboard->set("indexer_count", indexerCount); - } -} - -void TaskParse::doReset(std::shared_ptr blackboard) -{ -} - -void TaskParse::handleMessage(MessageInterruptTasks* message) -{ - m_interrupted = true; -} diff --git a/src/lib/data/parser/TaskParseWrapper.cpp b/src/lib/data/parser/TaskParseWrapper.cpp index 19a13e0c..448c9e03 100644 --- a/src/lib/data/parser/TaskParseWrapper.cpp +++ b/src/lib/data/parser/TaskParseWrapper.cpp @@ -2,17 +2,14 @@ #include "component/view/DialogView.h" #include "data/PersistentStorage.h" -#include "utility/file/FileRegister.h" #include "utility/scheduling/Blackboard.h" #include "utility/utility.h" TaskParseWrapper::TaskParseWrapper( PersistentStorage* storage, - std::shared_ptr fileRegister, DialogView* dialogView ) : m_storage(storage) - , m_fileRegister(fileRegister) , m_dialogView(dialogView) { } @@ -31,9 +28,8 @@ void TaskParseWrapper::setTask(std::shared_ptr task) void TaskParseWrapper::doEnter(std::shared_ptr blackboard) { - blackboard->set("indexer_count", 0); - - const size_t sourceFileCount = m_fileRegister->getSourceFilesCount(); + int sourceFileCount = 0; + blackboard->get("source_file_count", sourceFileCount); m_dialogView->updateIndexingDialog(0, sourceFileCount, ""); m_start = utility::durationStart(); @@ -51,7 +47,6 @@ Task::TaskState TaskParseWrapper::doUpdate(std::shared_ptr blackboar void TaskParseWrapper::doExit(std::shared_ptr blackboard) { - blackboard->clear("indexer_count"); blackboard->set("index_time", utility::duration(m_start)); } diff --git a/src/lib/data/parser/TaskParseWrapper.h b/src/lib/data/parser/TaskParseWrapper.h index 645cfa0a..a907b0ee 100644 --- a/src/lib/data/parser/TaskParseWrapper.h +++ b/src/lib/data/parser/TaskParseWrapper.h @@ -20,7 +20,6 @@ class TaskParseWrapper public: TaskParseWrapper( PersistentStorage* storage, - std::shared_ptr fileRegister, DialogView* dialogView ); virtual ~TaskParseWrapper(); @@ -34,7 +33,6 @@ private: virtual void doReset(std::shared_ptr blackboard); PersistentStorage* m_storage; - std::shared_ptr m_fileRegister; DialogView* m_dialogView; TimePoint m_start; diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index 8e2c6814..12bc421c 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -114,7 +114,7 @@ bool ProjectSettings::setStandard(const std::string& standard) return setValue("language_settings/standard", standard); } -std::vector ProjectSettings::getSourcePaths() const +std::vector ProjectSettings::getSourcePaths() const // TODO: rename to getIndexedPaths { return getPathValues("source/source_paths/source_path"); } diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index 1b65a8fe..4f8f1c30 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -15,11 +15,6 @@ FileManager::~FileManager() { } -const std::vector& FileManager::getSourcePaths() const -{ - return m_sourcePaths; -} - void FileManager::setPaths( std::vector sourcePaths, std::vector headerPaths, @@ -34,24 +29,26 @@ void FileManager::setPaths( FileManager::FileSets FileManager::fetchFilePaths(const std::vector& oldFileInfos) { - m_files.clear(); + m_filesInfos.clear(); for (FileInfo oldFileInfo: oldFileInfos) { - m_files.emplace(oldFileInfo.path, oldFileInfo); + m_filesInfos.emplace(oldFileInfo.path, oldFileInfo); } FileSets fileSets; - for (std::map::iterator it = m_files.begin(); it != m_files.end(); it++) + // update old files that have been modified + // remove old files that don't exist anymore + for (std::map::iterator it = m_filesInfos.begin(); it != m_filesInfos.end(); it++) { const FilePath& filePath = it->first; if (filePath.exists() && !hasSourceFilePath(filePath)) { - FileInfo fileInfo = FileSystem::getFileInfoForPath(filePath); + FileInfo newFileInfo = FileSystem::getFileInfoForPath(filePath); - if (fileInfo.lastWriteTime > it->second.lastWriteTime) + if (newFileInfo.lastWriteTime > it->second.lastWriteTime) { - it->second.lastWriteTime = fileInfo.lastWriteTime; + it->second.lastWriteTime = newFileInfo.lastWriteTime; fileSets.updatedFiles.insert(filePath); } } @@ -70,10 +67,10 @@ FileManager::FileSets FileManager::fetchFilePaths(const std::vector& o continue; } - fileSets.allFiles.insert(filePath); + fileSets.allSourceFilePaths.insert(filePath); - std::map::iterator it = m_files.find(filePath); - if (it != m_files.end()) + std::map::iterator it = m_filesInfos.find(filePath); + if (it != m_filesInfos.end()) { fileSets.removedFiles.erase(filePath); if (fileInfo.lastWriteTime > it->second.lastWriteTime) @@ -84,47 +81,39 @@ FileManager::FileSets FileManager::fetchFilePaths(const std::vector& o } else { - m_files.insert(std::pair(filePath, fileInfo)); + m_filesInfos.insert(std::pair(filePath, fileInfo)); fileSets.addedFiles.insert(filePath); } } for (const FilePath& filePath : fileSets.removedFiles) { - m_files.erase(filePath); + m_filesInfos.erase(filePath); } - m_sourceFiles = fileSets.allFiles; + m_sourceFilePaths = fileSets.allSourceFilePaths; return fileSets; } -bool FileManager::hasFilePath(const FilePath& filePath) const +std::vector FileManager::getSourcePaths() const { - if (hasSourceFilePath(filePath)) - { - return true; - } + return m_sourcePaths; +} - if (isExcluded(filePath)) +std::set FileManager::getSourceFilePaths() const +{ + std::set sourceFilePaths; + for (const FileInfo& fileInfo: FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions)) { - return false; + sourceFilePaths.emplace(fileInfo.path); } - - for (FilePath path : m_headerPaths) - { - if (path == filePath || path.contains(filePath)) - { - return true; - } - } - - return false; + return sourceFilePaths; } bool FileManager::hasSourceFilePath(const FilePath& filePath) const { - if (m_sourceFiles.find(filePath) != m_sourceFiles.end()) + if (m_sourceFilePaths.find(filePath) != m_sourceFilePaths.end()) { return true; } @@ -132,18 +121,6 @@ bool FileManager::hasSourceFilePath(const FilePath& filePath) const return false; } -const FileInfo FileManager::getFileInfo(const FilePath& filePath) const -{ - std::map::const_iterator it = m_files.find(filePath); - - if (it == m_files.end()) - { - return FileSystem::getFileInfoForPath(filePath); - } - - return it->second; -} - std::vector FileManager::makeCanonical(const std::vector& filePaths) { std::vector ret; diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h index c7008d27..035d63b0 100644 --- a/src/lib/utility/file/FileManager.h +++ b/src/lib/utility/file/FileManager.h @@ -12,17 +12,15 @@ class FileManager public: struct FileSets { - std::set allFiles; std::set addedFiles; std::set updatedFiles; std::set removedFiles; + std::set allSourceFilePaths; }; FileManager(); virtual ~FileManager(); - const std::vector& getSourcePaths() const; - void setPaths( std::vector sourcePaths, std::vector headerPaths, @@ -32,24 +30,27 @@ public: FileSets fetchFilePaths(const std::vector& oldFileInfos); - virtual bool hasFilePath(const FilePath& filePath) const; - virtual bool hasSourceFilePath(const FilePath& filePath) const; + // returns a list of source paths (can be directories) specified in the project settings + std::vector getSourcePaths() const; - virtual const FileInfo getFileInfo(const FilePath& filePath) const; + // returns a list of paths to all files that reside in the non-excluded source paths + std::set getSourceFilePaths() const; + + // checks if file is in non-excluded source directory + virtual bool hasSourceFilePath(const FilePath& filePath) const; private: std::vector makeCanonical(const std::vector& filePaths); bool isExcluded(const FilePath& filePath) const; - std::map m_files; - std::vector m_sourcePaths; std::vector m_headerPaths; std::vector m_excludePaths; - std::vector m_sourceExtensions; - std::set m_sourceFiles; + std::map m_filesInfos; + + std::set m_sourceFilePaths; }; #endif // FILE_MANAGER_H diff --git a/src/lib/utility/file/FileRegister.cpp b/src/lib/utility/file/FileRegister.cpp index d871cf13..a04f2ee6 100644 --- a/src/lib/utility/file/FileRegister.cpp +++ b/src/lib/utility/file/FileRegister.cpp @@ -1,246 +1,75 @@ #include "utility/file/FileRegister.h" -#include "utility/file/FileManager.h" -#include "utility/file/FileSystem.h" +FileRegister::FileRegister(const FileRegisterStateData& stateData, const std::set& indexedPaths, const std::set& excludedPaths) + : m_stateData(stateData) + , m_indexedPaths(indexedPaths) + , m_excludedPaths(excludedPaths) + , m_hasFilePathCache( + [&](std::string filePath){ + bool ret = false; + for (const FilePath& indexedPath: m_indexedPaths) + { + if (indexedPath.contains(filePath)) + { + ret = true; + break; + } + } -FileRegister::FileRegister(const FileManager* fileManager, bool randomizeParseOrder) - : m_fileManager(fileManager) - , m_randomizeParseOrder(randomizeParseOrder) + if (ret) + { + for (const FilePath& excluded: m_excludedPaths) + { + if (excluded.isDirectory()) + { + if (excluded.contains(filePath)) + { + ret = false; + break; + } + } + else + { + if (excluded == filePath) + { + ret = false; + break; + } + } + } + } + return ret; + } + ) { } -void FileRegister::setFilePaths(const std::vector& filePaths) + +FileRegister::~FileRegister() { - { - std::lock_guard lock(m_sourceFileMutex); - m_sourceFilePaths.clear(); +} - for (const FilePath& p : filePaths) - { - FilePath path = p.exists() ? p.absolute() : p; +FileRegisterStateData FileRegister::getStateData() const +{ + return m_stateData; +} - if (m_fileManager->hasSourceFilePath(path)) - { - m_sourceFilePaths.emplace(path, STATE_UNPARSED); - } - } - } +void FileRegister::markFileIndexing(const FilePath& filePath) +{ + m_stateData.markFileIndexing(filePath); +} - { - std::lock_guard lock(m_includeFileMutex); - m_includeFilePaths.clear(); - } +void FileRegister::markIndexingFilesIndexed() +{ + m_stateData.markIndexingFilesIndexed(); +} - { - std::lock_guard lock(m_threadFileMutex); - m_threadParsingFiles.clear(); - } +bool FileRegister::fileIsIndexed(const FilePath& filePath) const +{ + return m_stateData.fileIsIndexed(filePath); } bool FileRegister::hasFilePath(const FilePath& filePath) const { - std::lock_guard lock(m_projectFilesMutex); - std::unordered_map::iterator it = m_projectFiles.find(filePath.str()); - if (it != m_projectFiles.end()) - { - return it->second; - } - - bool has = m_fileManager->hasFilePath(filePath); - m_projectFiles.emplace(filePath.str(), has); - - return has; -} - -const FileInfo FileRegister::getFileInfo(const FilePath& filePath) const -{ - std::lock_guard lock(m_projectFileInfosMutex); - std::unordered_map::iterator it = m_projectFileInfos.find(filePath.str()); - if (it != m_projectFileInfos.end()) - { - return it->second; - } - - FileInfo info = m_fileManager->getFileInfo(filePath); - m_projectFileInfos.emplace(filePath.str(), info); - - return info; -} - -std::vector FileRegister::getUnparsedSourceFilePaths() const -{ - std::lock_guard lock(m_sourceFileMutex); - - std::vector files; - - for (std::pair&& p : m_sourceFilePaths) - { - if (p.second == STATE_UNPARSED) - { - files.push_back(p.first); - } - } - - return files; -} - -bool FileRegister::hasIncludeFile(const FilePath& filePath) const -{ - std::lock_guard lock(m_includeFileMutex); - - std::map::const_iterator it = m_includeFilePaths.find(filePath); - return (it != m_includeFilePaths.end()); -} - -bool FileRegister::fileIsParsed(const FilePath& filePath) const -{ - return sourceFileIsParsed(filePath) || includeFileIsParsed(filePath); -} - -bool FileRegister::sourceFileIsParsed(const FilePath& filePath) const -{ - std::lock_guard lock(m_sourceFileMutex); - - std::map::const_iterator it = m_sourceFilePaths.find(filePath); - if (it == m_sourceFilePaths.end()) - { - return false; - } - - if (it->second == STATE_PARSED) - { - return true; - } - - return false; -} - -bool FileRegister::includeFileIsParsed(const FilePath& filePath) const -{ - std::lock_guard lock(m_includeFileMutex); - - std::map::const_iterator it = m_includeFilePaths.find(filePath); - if (it == m_includeFilePaths.end()) - { - return false; - } - - if (it->second == STATE_PARSED) - { - return true; - } - - return false; -} - -FilePath FileRegister::consumeSourceFile() -{ - std::lock_guard lock(m_consumeFileMutex); - - std::vector paths = getUnparsedSourceFilePaths(); - - FilePath path; - - if (paths.size()) - { - if (m_randomizeParseOrder) - { - path = paths[rand() % paths.size()]; - } - else - { - path = paths[0]; - } - - std::lock_guard lock(m_sourceFileMutex); - m_sourceFilePaths[path] = STATE_PARSING; - } - - if (!path.empty()) - { - std::lock_guard lock(m_threadFileMutex); - m_threadParsingFiles[std::this_thread::get_id()].insert(path); - } - - return path; -} - -void FileRegister::markIncludeFileParsing(const FilePath& filePath) -{ - bool unparsed = false; - { - std::lock_guard lock(m_includeFileMutex); - std::map::iterator it = m_includeFilePaths.find(filePath); - - if (it != m_includeFilePaths.end()) - { - if (it->second == STATE_UNPARSED) - { - it->second = STATE_PARSING; - unparsed = true; - } - } - else - { - m_includeFilePaths.emplace(filePath, STATE_PARSING); - unparsed = true; - } - } - - if (unparsed) - { - std::lock_guard lock(m_threadFileMutex); - m_threadParsingFiles[std::this_thread::get_id()].insert(filePath); - } -} - -void FileRegister::markThreadFilesParsed() -{ - std::lock_guard sourceFileLock(m_sourceFileMutex); - std::lock_guard includeFileLock(m_includeFileMutex); - std::lock_guard threadFileLock(m_threadFileMutex); - - std::set& threadFiles = m_threadParsingFiles[std::this_thread::get_id()]; - - for (std::set::iterator it = threadFiles.begin(); it != threadFiles.end(); it++) - { - std::map::iterator it2; - it2 = m_sourceFilePaths.find(*it); - if (it2 != m_sourceFilePaths.end()) - { - it2->second = STATE_PARSED; - continue; - } - - it2 = m_includeFilePaths.find(*it); - if (it2 != m_includeFilePaths.end()) - { - it2->second = STATE_PARSED; - } - } - - threadFiles.clear(); -} - -size_t FileRegister::getSourceFilesCount() const -{ - std::lock_guard lock(m_sourceFileMutex); - return m_sourceFilePaths.size(); -} - -size_t FileRegister::getParsedSourceFilesCount() const -{ - std::lock_guard lock(m_sourceFileMutex); - - size_t count = 0; - - for (std::pair&& p : m_sourceFilePaths) - { - if (p.second == STATE_PARSED) - { - count++; - } - } - - return count; + return m_hasFilePathCache.getValue(filePath.str()); } diff --git a/src/lib/utility/file/FileRegister.h b/src/lib/utility/file/FileRegister.h index 6f7e0535..885cc596 100644 --- a/src/lib/utility/file/FileRegister.h +++ b/src/lib/utility/file/FileRegister.h @@ -1,72 +1,29 @@ #ifndef FILE_REGISTER_H #define FILE_REGISTER_H -#include -#include -#include #include -#include -#include -#include -#include "utility/file/FileInfo.h" -#include "utility/file/FilePath.h" - -class FileManager; +#include "utility/file/FileRegisterStateData.h" +#include "utility/Cache.h" class FileRegister { public: - explicit FileRegister(const FileManager* fileManager, bool randomizeParseOrder); + FileRegister(const FileRegisterStateData& stateData, const std::set& indexedPaths, const std::set& excludedPaths); + virtual ~FileRegister(); - void setFilePaths(const std::vector& filePaths); + FileRegisterStateData getStateData() const; - bool hasFilePath(const FilePath& filePath) const; - const FileInfo getFileInfo(const FilePath& filePath) const; - - std::vector getUnparsedSourceFilePaths() const; - - bool hasIncludeFile(const FilePath& filePath) const; - - bool fileIsParsed(const FilePath& filePath) const; - bool includeFileIsParsed(const FilePath& filePath) const; - bool sourceFileIsParsed(const FilePath& filePath) const; - - FilePath consumeSourceFile(); - - void markIncludeFileParsing(const FilePath& filePath); - void markThreadFilesParsed(); - - size_t getSourceFilesCount() const; - size_t getParsedSourceFilesCount() const; + void markFileIndexing(const FilePath& filePath); + void markIndexingFilesIndexed(); + virtual bool fileIsIndexed(const FilePath& filePath) const; + virtual bool hasFilePath(const FilePath& filePath) const; private: - enum ParseState - { - STATE_UNPARSED, - STATE_PARSING, - STATE_PARSED - }; - - const FileManager* m_fileManager; - bool m_randomizeParseOrder; - - mutable std::unordered_map m_projectFiles; - mutable std::mutex m_projectFilesMutex; - - mutable std::unordered_map m_projectFileInfos; - mutable std::mutex m_projectFileInfosMutex; - - std::map m_sourceFilePaths; - std::map m_includeFilePaths; - - std::map> m_threadParsingFiles; - - mutable std::mutex m_sourceFileMutex; - mutable std::mutex m_includeFileMutex; - mutable std::mutex m_threadFileMutex; - - std::mutex m_consumeFileMutex; + FileRegisterStateData m_stateData; + const std::set m_indexedPaths; + const std::set m_excludedPaths; + mutable Cache m_hasFilePathCache; }; #endif // FILE_REGISTER_H diff --git a/src/lib/utility/file/FileRegisterStateData.cpp b/src/lib/utility/file/FileRegisterStateData.cpp new file mode 100644 index 00000000..91e2f2f2 --- /dev/null +++ b/src/lib/utility/file/FileRegisterStateData.cpp @@ -0,0 +1,61 @@ +#include "utility/file/FileRegisterStateData.h" + +FileRegisterStateData::FileRegisterStateData() +{ +} + +FileRegisterStateData::FileRegisterStateData(const FileRegisterStateData& o) +{ + this->inject(o); +} + +void FileRegisterStateData::inject(const FileRegisterStateData& o) +{ + std::lock_guard oLock(o.m_filePathsMutex); + std::lock_guard thisLock(m_filePathsMutex); + for (const auto& it: o.m_filePaths) + { + if (it.second == STATE_INDEXED) + { + m_filePaths[it.first] = STATE_INDEXED; + } + } +} + +void FileRegisterStateData::markFileIndexing(const FilePath& filePath) +{ + std::lock_guard lock(m_filePathsMutex); + auto it = m_filePaths.find(filePath); + if (it != m_filePaths.end()) + { + it->second = STATE_INDEXING; + } + else + { + m_filePaths.insert(std::make_pair(filePath, STATE_INDEXING)); + } +} + +void FileRegisterStateData::markIndexingFilesIndexed() +{ + std::lock_guard lock(m_filePathsMutex); + for (auto it: m_filePaths) + { + if (it.second == STATE_INDEXING) + { + it.second = STATE_INDEXED; + } + } +} + +bool FileRegisterStateData::fileIsIndexed(const FilePath& filePath) const +{ + std::lock_guard lock(m_filePathsMutex); + auto it = m_filePaths.find(filePath); + if (it != m_filePaths.end()) + { + return it->second == STATE_INDEXED; + } + + return false; +} diff --git a/src/lib/utility/file/FileRegisterStateData.h b/src/lib/utility/file/FileRegisterStateData.h new file mode 100644 index 00000000..2ac35ae8 --- /dev/null +++ b/src/lib/utility/file/FileRegisterStateData.h @@ -0,0 +1,33 @@ +#ifndef FILE_REGISTER_STATE_DATA_H +#define FILE_REGISTER_STATE_DATA_H + +#include +#include + +#include "utility/file/FilePath.h" + +class FileRegisterStateData +{ +public: + FileRegisterStateData(); + FileRegisterStateData(const FileRegisterStateData& o); + + void inject(const FileRegisterStateData& o); + + void markFileIndexing(const FilePath& filePath); + void markIndexingFilesIndexed(); + bool fileIsIndexed(const FilePath& filePath) const; + +private: + enum IndexingState + { + STATE_NON_INDEXED, + STATE_INDEXING, + STATE_INDEXED + }; + + std::map m_filePaths; + mutable std::mutex m_filePathsMutex; +}; + +#endif // FILE_REGISTER_STATE_DATA_H diff --git a/src/lib/utility/interprocess/InterprocessDataManager.cpp b/src/lib/utility/interprocess/InterprocessDataManager.cpp index ee53a6b5..6eb4137b 100644 --- a/src/lib/utility/interprocess/InterprocessDataManager.cpp +++ b/src/lib/utility/interprocess/InterprocessDataManager.cpp @@ -39,51 +39,51 @@ void InterprocessDataManager::initialize() } } -void InterprocessDataManager::pushParserArguments(const Parser::Arguments& arguments) -{ - IF_INITIALIZED() - { - SharedParserArguments::VoidAllocator allocator(m_parserArguments.getSegmentManager()); - SharedParserArguments args(allocator); - - args.setCompilationDatabasePath(arguments.compilationDatabasePath.str()); - args.setCompilerFlags(arguments.compilerFlags); - args.setFrameworkSearchPaths(arguments.frameworkSearchPaths); - args.setHeaderSearchPaths(arguments.headerSearchPaths); - args.setJavaClassPaths(arguments.javaClassPaths); - args.setLanguage(arguments.language); - args.setLanguageStandard(arguments.languageStandard); - args.setLogErrors(arguments.logErrors); - args.setSystemHeaderSearchPaths(arguments.systemHeaderSearchPaths); - - m_parserArguments.pushValue(args); - } -} - -Parser::Arguments InterprocessDataManager::popParserArguments() -{ - IF_INITIALIZED(Parser::Arguments()) - { - if (m_parserArguments.size() > 0) - { - SharedParserArguments args = m_parserArguments.popValue(); - - Parser::Arguments result; - - result.compilationDatabasePath = FilePath(args.getCompilationDatabasePath()); - result.compilerFlags = args.getCompilerFlags(); - result.frameworkSearchPaths = args.getFrameworkSearchPaths(); - result.headerSearchPaths = args.getHeaderSearchPaths(); - result.javaClassPaths = args.getJavaClassPaths(); - result.language = args.getLanguage(); - result.languageStandard = args.getLanguageStandard(); - result.logErrors = args.getLogErrors(); - result.systemHeaderSearchPaths = args.getSystemHeaderSearchPaths(); - - return result; - } - } -} +//void InterprocessDataManager::pushParserArguments(const Parser::Arguments& arguments) +//{ +// IF_INITIALIZED() +// { +// SharedParserArguments::VoidAllocator allocator(m_parserArguments.getSegmentManager()); +// SharedParserArguments args(allocator); +// +// args.setCompilationDatabasePath(arguments.compilationDatabasePath.str()); +// args.setCompilerFlags(arguments.compilerFlags); +// args.setFrameworkSearchPaths(arguments.frameworkSearchPaths); +// args.setHeaderSearchPaths(arguments.headerSearchPaths); +// args.setJavaClassPaths(arguments.javaClassPaths); +// args.setLanguage(arguments.language); +// args.setLanguageStandard(arguments.languageStandard); +// args.setLogErrors(arguments.logErrors); +// args.setSystemHeaderSearchPaths(arguments.systemHeaderSearchPaths); +// +// m_parserArguments.pushValue(args); +// } +//} +// +//Parser::Arguments InterprocessDataManager::popParserArguments() +//{ +// IF_INITIALIZED(Parser::Arguments()) +// { +// if (m_parserArguments.size() > 0) +// { +// SharedParserArguments args = m_parserArguments.popValue(); +// +// Parser::Arguments result; +// +// result.compilationDatabasePath = FilePath(args.getCompilationDatabasePath()); +// result.compilerFlags = args.getCompilerFlags(); +// result.frameworkSearchPaths = args.getFrameworkSearchPaths(); +// result.headerSearchPaths = args.getHeaderSearchPaths(); +// result.javaClassPaths = args.getJavaClassPaths(); +// result.language = args.getLanguage(); +// result.languageStandard = args.getLanguageStandard(); +// result.logErrors = args.getLogErrors(); +// result.systemHeaderSearchPaths = args.getSystemHeaderSearchPaths(); +// +// return result; +// } +// } +//} unsigned int InterprocessDataManager::parserArgumentCount() const { diff --git a/src/lib/utility/interprocess/InterprocessDataManager.h b/src/lib/utility/interprocess/InterprocessDataManager.h index 225e6a4e..d95aee8d 100644 --- a/src/lib/utility/interprocess/InterprocessDataManager.h +++ b/src/lib/utility/interprocess/InterprocessDataManager.h @@ -15,8 +15,13 @@ public: void initialize(); - void pushParserArguments(const Parser::Arguments& arguments); - Parser::Arguments popParserArguments(); + // TODO: use IndexerCommands here and rename SharedParserArguments to SharedIndexerCommand + // TODO: either make one SharedIndexerCommand that stores everything or make + // SharedIndexerCommandJava, SharedIndexerCommandCxxManual, ..., each having a separate datastructure here + + //void pushParserArguments(const Parser::Arguments& arguments); + //Parser::Arguments popParserArguments(); + unsigned int parserArgumentCount() const; private: diff --git a/src/lib/utility/scheduling/TaskReturnSuccessWhile.h b/src/lib/utility/scheduling/TaskReturnSuccessWhile.h index f85eea48..74882f1b 100644 --- a/src/lib/utility/scheduling/TaskReturnSuccessWhile.h +++ b/src/lib/utility/scheduling/TaskReturnSuccessWhile.h @@ -1,8 +1,6 @@ #ifndef TASK_RETURN_SUCCESS_WHILE_H #define TASK_RETURN_SUCCESS_WHILE_H -#include - #include "utility/scheduling/Task.h" #include "utility/scheduling/Blackboard.h" diff --git a/src/lib/utility/scheduling/TaskSetValue.h b/src/lib/utility/scheduling/TaskSetValue.h new file mode 100644 index 00000000..10487132 --- /dev/null +++ b/src/lib/utility/scheduling/TaskSetValue.h @@ -0,0 +1,54 @@ +#ifndef TASK_SET_VALUE_H +#define TASK_SET_VALUE_H + +#include "utility/scheduling/Task.h" +#include "utility/scheduling/Blackboard.h" + +template +class TaskSetValue: + public Task +{ +public: + TaskSetValue(const std::string& valueName, T value); + +private: + virtual void doEnter(std::shared_ptr blackboard); + virtual TaskState doUpdate(std::shared_ptr blackboard); + virtual void doExit(std::shared_ptr blackboard); + virtual void doReset(std::shared_ptr blackboard); + + const std::string m_valueName; + const T m_value; +}; + +template +TaskSetValue::TaskSetValue(const std::string& valueName, T value) + : m_valueName(valueName) + , m_value(value) +{ +} + +template +void TaskSetValue::doEnter(std::shared_ptr blackboard) +{ +} + +template +Task::TaskState TaskSetValue::doUpdate(std::shared_ptr blackboard) +{ + std::lock_guard lock(blackboard->getMutex()); + blackboard->set(m_valueName, m_value); + return STATE_SUCCESS; +} + +template +void TaskSetValue::doExit(std::shared_ptr blackboard) +{ +} + +template +void TaskSetValue::doReset(std::shared_ptr blackboard) +{ +} + +#endif // TASK_SET_VALUE_H diff --git a/src/lib_cxx/CMakeLists.txt b/src/lib_cxx/CMakeLists.txt index 241c5d6d..f93c0aa3 100644 --- a/src/lib_cxx/CMakeLists.txt +++ b/src/lib_cxx/CMakeLists.txt @@ -1,7 +1,20 @@ add_files( - CLANG_FILES - + LIB_CXX_FILES + + data/indexer/IndexerCommandCxxCdb.cpp + data/indexer/IndexerCommandCxxCdb.h + data/indexer/IndexerCommandCxxManual.cpp + data/indexer/IndexerCommandCxxManual.h + data/indexer/IndexerCxxCdb.cpp + data/indexer/IndexerCxxCdb.h + data/indexer/IndexerCxxManual.cpp + data/indexer/IndexerCxxManual.h + data/indexer/IndexerFactoryModuleCxxCdb.cpp + data/indexer/IndexerFactoryModuleCxxCdb.h + data/indexer/IndexerFactoryModuleCxxManual.cpp + data/indexer/IndexerFactoryModuleCxxManual.h + data/parser/cxx/name/CxxDeclName.cpp data/parser/cxx/name/CxxDeclName.h data/parser/cxx/name/CxxFunctionDeclName.cpp @@ -61,17 +74,9 @@ add_files( utility/CompilationDatabase.cpp utility/CompilationDatabase.h -) - -add_files( - LIB_CXX_FILES - - data/parser/cxx/TaskParseCxx.cpp - data/parser/cxx/TaskParseCxx.h - + CxxProject.cpp CxxProject.h - ProjectFactoryModuleCpp.cpp ProjectFactoryModuleCpp.h ProjectFactoryModuleC.cpp diff --git a/src/lib_cxx/CxxProject.cpp b/src/lib_cxx/CxxProject.cpp index cce83e28..f30c2e0e 100644 --- a/src/lib_cxx/CxxProject.cpp +++ b/src/lib_cxx/CxxProject.cpp @@ -1,8 +1,13 @@ #include "CxxProject.h" -#include "data/parser/cxx/TaskParseCxx.h" +#include "clang/Tooling/Tooling.h" +#include "clang/Tooling/CompilationDatabase.h" +#include "clang/Tooling/JSONCompilationDatabase.h" + #include "settings/ApplicationSettings.h" +#include "data/indexer/IndexerCommandCxxManual.h" +#include "data/indexer/IndexerCxxCdb.h" #include "utility/file/FileRegister.h" #include "utility/file/FileSystem.h" #include "utility/messaging/type/MessageStatus.h" @@ -53,16 +58,102 @@ bool CxxProject::prepareRefresh() return true; } -std::shared_ptr CxxProject::createIndexerTask( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister) +std::vector> CxxProject::getIndexerCommands() { - return std::make_shared( - storageProvider, - fileRegister, - getParserArguments(), - getDialogView() - ); + std::shared_ptr appSettings = ApplicationSettings::getInstance(); + + std::string languageStandard = m_projectSettings->getStandard(); + + std::vector systemHeaderSearchPaths; + utility::append(systemHeaderSearchPaths, m_projectSettings->getAbsoluteHeaderSearchPaths()); + utility::append(systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded()); + + // Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files. + for (const FilePath& sourcePath : getSourcePaths()) + { + if (sourcePath.isDirectory()) + { + systemHeaderSearchPaths.push_back(sourcePath); + } + } + + // Add all subdirectories of the header search paths + if (m_projectSettings->getUseSourcePathsForHeaderSearch()) + { + std::vector headerSearchSubPaths; + for (const FilePath& sourcePath : getSourcePaths()) + { + utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(sourcePath)); + } + + utility::append(systemHeaderSearchPaths, utility::unique(headerSearchSubPaths)); + } + + std::vector frameworkSearchPaths; + utility::append(frameworkSearchPaths, m_projectSettings->getAbsoluteFrameworkSearchPaths()); + utility::append(frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded()); + + std::vector compilerFlags = m_projectSettings->getCompilerFlags(); + + std::set indexedPaths; + for (FilePath p: m_projectSettings->getAbsoluteSourcePaths()) + { + if (p.exists()) + { + indexedPaths.insert(p); + } + } + + std::set excludedPaths; + for (FilePath p: m_projectSettings->getAbsoluteExcludePaths()) + { + if (p.exists()) + { + excludedPaths.insert(p); + } + } + + std::vector> indexerCommands; + + FilePath cdbPath = m_projectSettings->getAbsoluteCompilationDatabasePath(); + if (cdbPath.exists()) + { + std::string error; + std::shared_ptr cdb = std::shared_ptr + (clang::tooling::JSONCompilationDatabase::loadFromFile(cdbPath.str(), error)); + for (clang::tooling::CompileCommand command: cdb->getAllCompileCommands()) + { + std::vector currentCompilerFlags = compilerFlags; + currentCompilerFlags.insert(currentCompilerFlags.end(), command.CommandLine.begin(), command.CommandLine.end()); + + indexerCommands.push_back(std::make_shared( + FilePath(command.Filename), + indexedPaths, + excludedPaths, + FilePath(command.Directory), + currentCompilerFlags, + systemHeaderSearchPaths, + frameworkSearchPaths + )); + } + } + else + { + for (const FilePath& sourcePath: getSourceFilePaths()) + { + indexerCommands.push_back(std::make_shared( + sourcePath, + indexedPaths, + excludedPaths, + languageStandard, + systemHeaderSearchPaths, + frameworkSearchPaths, + compilerFlags + )); + } + } + + return indexerCommands; } void CxxProject::updateFileManager(FileManager& fileManager) @@ -75,7 +166,7 @@ void CxxProject::updateFileManager(FileManager& fileManager) FilePath cdbPath = m_projectSettings->getAbsoluteCompilationDatabasePath(); if (cdbPath.exists()) { - sourcePaths = TaskParseCxx::getSourceFilesFromCDB(cdbPath); + sourcePaths = IndexerCxxCdb::getSourceFilesFromCDB(cdbPath); } else { @@ -86,46 +177,3 @@ void CxxProject::updateFileManager(FileManager& fileManager) fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions); } - -Parser::Arguments CxxProject::getParserArguments() const -{ - std::shared_ptr appSettings = ApplicationSettings::getInstance(); - - Parser::Arguments args; - - utility::append(args.compilerFlags, m_projectSettings->getCompilerFlags()); - - // Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files. - for (const FilePath& sourcePath : getSourcePaths()) - { - if (sourcePath.isDirectory()) - { - args.systemHeaderSearchPaths.push_back(sourcePath); - } - } - - utility::append(args.systemHeaderSearchPaths, m_projectSettings->getAbsoluteHeaderSearchPaths()); - - utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded()); - - // Add all subdirectories of the header search paths - if (m_projectSettings->getUseSourcePathsForHeaderSearch()) - { - std::vector headerSearchSubPaths; - for (const FilePath& sourcePath : getSourcePaths()) - { - utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(sourcePath)); - } - - utility::append(args.systemHeaderSearchPaths, utility::unique(headerSearchSubPaths)); - } - - utility::append(args.frameworkSearchPaths, m_projectSettings->getAbsoluteFrameworkSearchPaths()); - utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded()); - - args.language = languageTypeToString(m_projectSettings->getLanguage()); - args.languageStandard = m_projectSettings->getStandard(); - args.compilationDatabasePath = m_projectSettings->getAbsoluteCompilationDatabasePath(); - - return args; -} diff --git a/src/lib_cxx/CxxProject.h b/src/lib_cxx/CxxProject.h index 91e8b071..70a390b7 100644 --- a/src/lib_cxx/CxxProject.h +++ b/src/lib_cxx/CxxProject.h @@ -25,14 +25,10 @@ private: virtual bool prepareRefresh(); - virtual std::shared_ptr createIndexerTask( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister); + virtual std::vector> getIndexerCommands(); virtual void updateFileManager(FileManager& fileManager); - Parser::Arguments getParserArguments() const; - std::shared_ptr m_projectSettings; diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp new file mode 100644 index 00000000..119502df --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp @@ -0,0 +1,54 @@ +#include "data/indexer/IndexerCommandCxxCdb.h" + +#include "clang/Tooling/CompilationDatabase.h" + +std::string IndexerCommandCxxCdb::getIndexerKindString() +{ + return "CxxCdb"; +} + +IndexerCommandCxxCdb::IndexerCommandCxxCdb( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const FilePath& workingDirectory, + const std::vector& compilerFlags, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths +) + : IndexerCommand(sourceFilePath, indexedPaths, excludedPaths) + , m_workingDirectory(workingDirectory) + , m_compilerFlags(compilerFlags) + , m_systemHeaderSearchPaths(systemHeaderSearchPaths) + , m_frameworkSearchPaths(frameworkSearchPaths) +{ +} + +IndexerCommandCxxCdb::~IndexerCommandCxxCdb() +{ +} + +std::string IndexerCommandCxxCdb::getKindString() const +{ + return getIndexerKindString(); +} + +FilePath IndexerCommandCxxCdb::getWorkingDirectory() const +{ + return m_workingDirectory; +} + +std::vector IndexerCommandCxxCdb::getCompilerFlags() const +{ + return m_compilerFlags; +} + +std::vector IndexerCommandCxxCdb::getSystemHeaderSearchPaths() const +{ + return m_systemHeaderSearchPaths; +} + +std::vector IndexerCommandCxxCdb::getFrameworkSearchPaths() const +{ + return m_frameworkSearchPaths; +} diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h new file mode 100644 index 00000000..19ffc216 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h @@ -0,0 +1,46 @@ +#ifndef INDEXER_COMMAND_CXX_CDB_H +#define INDEXER_COMMAND_CXX_CDB_H + +#include + +#include "data/indexer/IndexerCommand.h" +#include "utility/file/FilePath.h" + +namespace clang +{ + namespace tooling + { + struct CompileCommand; + } +} + +class IndexerCommandCxxCdb: public IndexerCommand +{ +public: + static std::string getIndexerKindString(); + + IndexerCommandCxxCdb( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const FilePath& workingDirectory, + const std::vector& compilerFlags, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths); + virtual ~IndexerCommandCxxCdb(); + + virtual std::string getKindString() const; + + FilePath getWorkingDirectory() const; + std::vector getCompilerFlags() const; + std::vector getSystemHeaderSearchPaths() const; + std::vector getFrameworkSearchPaths() const; + +private: + FilePath m_workingDirectory; + std::vector m_compilerFlags; + std::vector m_systemHeaderSearchPaths; + std::vector m_frameworkSearchPaths; +}; + +#endif // INDEXER_COMMAND_CXX_CDB_H diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp new file mode 100644 index 00000000..3b6b3500 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp @@ -0,0 +1,53 @@ +#include "data/indexer/IndexerCommandCxxManual.h" + + +std::string IndexerCommandCxxManual::getIndexerKindString() +{ + return "CxxManual"; +} + +IndexerCommandCxxManual::IndexerCommandCxxManual( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const std::string& languageStandard, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths, + const std::vector& compilerFlags +) + : IndexerCommand(sourceFilePath, indexedPaths, excludedPaths) + , m_languageStandard(languageStandard) + , m_systemHeaderSearchPaths(systemHeaderSearchPaths) + , m_frameworkSearchPaths(frameworkSearchPaths) + , m_compilerFlags(compilerFlags) +{ +} + +IndexerCommandCxxManual::~IndexerCommandCxxManual() +{ +} + +std::string IndexerCommandCxxManual::getKindString() const +{ + return getIndexerKindString(); +} + +std::string IndexerCommandCxxManual::getLanguageStandard() const +{ + return m_languageStandard; +} + +std::vector IndexerCommandCxxManual::getSystemHeaderSearchPaths() const +{ + return m_systemHeaderSearchPaths; +} + +std::vector IndexerCommandCxxManual::getFrameworkSearchPaths() const +{ + return m_frameworkSearchPaths; +} + +std::vector IndexerCommandCxxManual::getCompilerFlags() const +{ + return m_compilerFlags; +} diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h new file mode 100644 index 00000000..c1ab5f85 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h @@ -0,0 +1,39 @@ +#ifndef INDEXER_COMMAND_CXX_MANUAL_H +#define INDEXER_COMMAND_CXX_MANUAL_H + +#include +#include + +#include "data/indexer/IndexerCommand.h" +#include "utility/file/FilePath.h" + +class IndexerCommandCxxManual: public IndexerCommand +{ +public: + static std::string getIndexerKindString(); + + IndexerCommandCxxManual( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const std::string& languageStandard, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths, + const std::vector& compilerFlags); + virtual ~IndexerCommandCxxManual(); + + virtual std::string getKindString() const; + + std::string getLanguageStandard() const; + std::vector getSystemHeaderSearchPaths() const; + std::vector getFrameworkSearchPaths() const; + std::vector getCompilerFlags() const; + +private: + std::string m_languageStandard; + std::vector m_systemHeaderSearchPaths; + std::vector m_frameworkSearchPaths; + std::vector m_compilerFlags; +}; + +#endif // INDEXER_COMMAND_CXX_MANUAL_H diff --git a/src/lib_cxx/data/indexer/IndexerCxxCdb.cpp b/src/lib_cxx/data/indexer/IndexerCxxCdb.cpp new file mode 100644 index 00000000..3bcb8f8a --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCxxCdb.cpp @@ -0,0 +1,47 @@ +#include "data/indexer/IndexerCxxCdb.h" + +#include "clang/Tooling/JSONCompilationDatabase.h" +#include "data/parser/ParserClientImpl.h" +#include "data/parser/cxx/CxxParser.h" +#include "utility/file/FileRegister.h" + +std::vector IndexerCxxCdb::getSourceFilesFromCDB(const FilePath& compilationDatabasePath) +{ + std::string error; + std::shared_ptr cdb = std::shared_ptr + (clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error)); + + std::vector filePaths; + if (cdb) + { + std::vector files = cdb->getAllFiles(); + for (const std::string& file : files) + { + filePaths.push_back(FilePath(file)); + } + } + return filePaths; +} + +std::shared_ptr IndexerCxxCdb::index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) +{ + std::shared_ptr parserClient = std::make_shared(); + std::shared_ptr parser = std::make_shared(parserClient, fileRegister); + + std::shared_ptr storage = std::make_shared(); + parserClient->setStorage(storage); + parserClient->startParsingFile(); + + parser->buildIndex(indexerCommand); + fileRegister->markIndexingFilesIndexed(); + + parserClient->finishParsingFile(); + parserClient->resetStorage(); + + if (interrupted()) + { + return std::shared_ptr(); + } + + return storage; +} diff --git a/src/lib_cxx/data/indexer/IndexerCxxCdb.h b/src/lib_cxx/data/indexer/IndexerCxxCdb.h new file mode 100644 index 00000000..7af3bb84 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCxxCdb.h @@ -0,0 +1,20 @@ +#ifndef INDEXER_CXX_CDB_H +#define INDEXER_CXX_CDB_H + +#include + +#include "data/indexer/Indexer.h" +#include "data/indexer/IndexerCommandCxxCdb.h" +#include "utility/file/FilePath.h" + +class IndexerCxxCdb: public Indexer +{ +public: + static std::vector getSourceFilesFromCDB(const FilePath& compilationDatabasePath); + +private: + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister); + +}; + +#endif // INDEXER_CXX_CDB_H diff --git a/src/lib_cxx/data/indexer/IndexerCxxManual.cpp b/src/lib_cxx/data/indexer/IndexerCxxManual.cpp new file mode 100644 index 00000000..d550e6e5 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCxxManual.cpp @@ -0,0 +1,28 @@ +#include "data/indexer/IndexerCxxManual.h" + +#include "data/parser/ParserClientImpl.h" +#include "data/parser/cxx/CxxParser.h" +#include "utility/file/FileRegister.h" + +std::shared_ptr IndexerCxxManual::index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) +{ + std::shared_ptr parserClient = std::make_shared(); + std::shared_ptr parser = std::make_shared(parserClient, fileRegister); + + std::shared_ptr storage = std::make_shared(); + parserClient->setStorage(storage); + parserClient->startParsingFile(); + + parser->buildIndex(indexerCommand); + fileRegister->markIndexingFilesIndexed(); + + parserClient->finishParsingFile(); + parserClient->resetStorage(); + + if (interrupted()) + { + return std::shared_ptr(); + } + + return storage; +} diff --git a/src/lib_cxx/data/indexer/IndexerCxxManual.h b/src/lib_cxx/data/indexer/IndexerCxxManual.h new file mode 100644 index 00000000..3c38cfa3 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCxxManual.h @@ -0,0 +1,13 @@ +#ifndef INDEXER_CXX_MANUAL_H +#define INDEXER_CXX_MANUAL_H + +#include "data/indexer/Indexer.h" +#include "data/indexer/IndexerCommandCxxManual.h" + +class IndexerCxxManual: public Indexer +{ +private: + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister); +}; + +#endif // INDEXER_CXX_MANUAL_H diff --git a/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxCdb.cpp b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxCdb.cpp new file mode 100644 index 00000000..56b1f4ce --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxCdb.cpp @@ -0,0 +1,12 @@ +#include "data/indexer/IndexerFactoryModuleCxxCdb.h" + +#include "data/indexer/IndexerCxxCdb.h" + +IndexerFactoryModuleCxxCdb::~IndexerFactoryModuleCxxCdb() +{ +} + +std::shared_ptr IndexerFactoryModuleCxxCdb::createIndexer() +{ + return std::make_shared(); +} diff --git a/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxCdb.h b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxCdb.h new file mode 100644 index 00000000..330505e3 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxCdb.h @@ -0,0 +1,13 @@ +#ifndef INDEXER_FACTORY_MODULE_CXX_CDB_H +#define INDEXER_FACTORY_MODULE_CXX_CDB_H + +#include "data/indexer/IndexerFactoryModule.h" + +class IndexerFactoryModuleCxxCdb: public IndexerFactoryModule +{ +public: + virtual ~IndexerFactoryModuleCxxCdb(); + virtual std::shared_ptr createIndexer(); +}; + +#endif // INDEXER_FACTORY_MODULE_CXX_CDB_H diff --git a/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxManual.cpp b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxManual.cpp new file mode 100644 index 00000000..30bda838 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxManual.cpp @@ -0,0 +1,12 @@ +#include "data/indexer/IndexerFactoryModuleCxxManual.h" + +#include "data/indexer/IndexerCxxManual.h" + +IndexerFactoryModuleCxxManual::~IndexerFactoryModuleCxxManual() +{ +} + +std::shared_ptr IndexerFactoryModuleCxxManual::createIndexer() +{ + return std::make_shared(); +} diff --git a/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxManual.h b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxManual.h new file mode 100644 index 00000000..655e46e2 --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerFactoryModuleCxxManual.h @@ -0,0 +1,13 @@ +#ifndef INDEXER_FACTORY_MODULE_CXX_MANUAL_H +#define INDEXER_FACTORY_MODULE_CXX_MANUAL_H + +#include "data/indexer/IndexerFactoryModule.h" + +class IndexerFactoryModuleCxxManual: public IndexerFactoryModule +{ +public: + virtual ~IndexerFactoryModuleCxxManual(); + virtual std::shared_ptr createIndexer(); +}; + +#endif // INDEXER_FACTORY_MODULE_CXX_MANUAL_H diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.cpp b/src/lib_cxx/data/parser/cxx/ASTAction.cpp index 10d09a26..5e6c7d47 100644 --- a/src/lib_cxx/data/parser/cxx/ASTAction.cpp +++ b/src/lib_cxx/data/parser/cxx/ASTAction.cpp @@ -5,7 +5,7 @@ #include "data/parser/cxx/CommentHandler.h" #include "data/parser/cxx/PreprocessorCallbacks.h" -ASTAction::ASTAction(ParserClient* client, FileRegister* fileRegister) +ASTAction::ASTAction(std::shared_ptr client, std::shared_ptr fileRegister) : m_client(client) , m_fileRegister(fileRegister) , m_commentHandler(client, fileRegister) diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.h b/src/lib_cxx/data/parser/cxx/ASTAction.h index 9487622a..c73565a7 100644 --- a/src/lib_cxx/data/parser/cxx/ASTAction.h +++ b/src/lib_cxx/data/parser/cxx/ASTAction.h @@ -1,6 +1,8 @@ #ifndef AST_ACTION_H #define AST_ACTION_H +#include + #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" @@ -11,7 +13,7 @@ class ASTAction : public clang::ASTFrontendAction { public: - explicit ASTAction(ParserClient* client, FileRegister* fileRegister); + explicit ASTAction(std::shared_ptr client, std::shared_ptr fileRegister); virtual ~ASTAction(); protected: @@ -20,8 +22,8 @@ protected: virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath); private: - ParserClient* m_client; - FileRegister* m_fileRegister; + std::shared_ptr m_client; + std::shared_ptr m_fileRegister; CommentHandler m_commentHandler; }; diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp index 957641f2..2565a352 100644 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp +++ b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp @@ -1,6 +1,6 @@ #include "data/parser/cxx/ASTActionFactory.h" -ASTActionFactory::ASTActionFactory(ParserClient* client, FileRegister* fileRegister) +ASTActionFactory::ASTActionFactory(std::shared_ptr client, std::shared_ptr fileRegister) : m_client(client) , m_fileRegister(fileRegister) { diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h index aa120071..9bbb45b4 100644 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h +++ b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h @@ -9,14 +9,14 @@ class ASTActionFactory : public clang::tooling::FrontendActionFactory { public: - explicit ASTActionFactory(ParserClient* client, FileRegister* fileRegister); + explicit ASTActionFactory(std::shared_ptr client, std::shared_ptr fileRegister); virtual ~ASTActionFactory(); virtual clang::FrontendAction* create(); private: - ParserClient* m_client; - FileRegister* m_fileRegister; + std::shared_ptr m_client; + std::shared_ptr m_fileRegister; }; #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 7607fe65..704e6812 100644 --- a/src/lib_cxx/data/parser/cxx/ASTConsumer.cpp +++ b/src/lib_cxx/data/parser/cxx/ASTConsumer.cpp @@ -3,7 +3,7 @@ #include "data/parser/cxx/CxxVerboseAstVisitor.h" #include "settings/ApplicationSettings.h" -ASTConsumer::ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister) +ASTConsumer::ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, std::shared_ptr fileRegister) { if (ApplicationSettings::getInstance()->getLoggingEnabled() && ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled()) { diff --git a/src/lib_cxx/data/parser/cxx/ASTConsumer.h b/src/lib_cxx/data/parser/cxx/ASTConsumer.h index 54cfb6a4..3ff2416d 100644 --- a/src/lib_cxx/data/parser/cxx/ASTConsumer.h +++ b/src/lib_cxx/data/parser/cxx/ASTConsumer.h @@ -13,7 +13,7 @@ class ASTConsumer : public clang::ASTConsumer { public: - explicit ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister); + explicit ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, std::shared_ptr fileRegister); virtual ~ASTConsumer(); virtual void HandleTranslationUnit(clang::ASTContext& context); diff --git a/src/lib_cxx/data/parser/cxx/CommentHandler.cpp b/src/lib_cxx/data/parser/cxx/CommentHandler.cpp index a8df6c59..d3ab4f69 100644 --- a/src/lib_cxx/data/parser/cxx/CommentHandler.cpp +++ b/src/lib_cxx/data/parser/cxx/CommentHandler.cpp @@ -4,7 +4,7 @@ #include "data/parser/ParserClient.h" #include "utility/file/FileRegister.h" -CommentHandler::CommentHandler(ParserClient* client, FileRegister* fileRegister) +CommentHandler::CommentHandler(std::shared_ptr client, std::shared_ptr fileRegister) : m_client(client) , m_fileRegister(fileRegister) { @@ -21,7 +21,7 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false); FilePath filePath = FilePath(presumedBegin.getFilename()); - if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath)) + if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsIndexed(filePath)) { m_client->onCommentParsed(ParseLocation( presumedBegin.getFilename(), diff --git a/src/lib_cxx/data/parser/cxx/CommentHandler.h b/src/lib_cxx/data/parser/cxx/CommentHandler.h index 0c49f35e..11afbd48 100644 --- a/src/lib_cxx/data/parser/cxx/CommentHandler.h +++ b/src/lib_cxx/data/parser/cxx/CommentHandler.h @@ -10,14 +10,14 @@ class CommentHandler : public clang::CommentHandler { public: - CommentHandler(ParserClient* client, FileRegister* fileRegister); + CommentHandler(std::shared_ptr client, std::shared_ptr fileRegister); virtual ~CommentHandler(); virtual bool HandleComment(clang::Preprocessor& preprocessor, clang::SourceRange sourceRange); private: - ParserClient* m_client; - FileRegister* m_fileRegister; + std::shared_ptr m_client; + std::shared_ptr m_fileRegister; }; #endif // COMMENT_HANDLER_H diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp index 7ef0f713..1bdde658 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp @@ -15,7 +15,7 @@ #include "data/parser/ParseLocation.h" -CxxAstVisitor::CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister) +CxxAstVisitor::CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr client, std::shared_ptr fileRegister) : m_astContext(astContext) , m_preprocessor(preprocessor) , m_client(client) diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h index 7975c072..7dc19f80 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.h @@ -33,7 +33,7 @@ class CxxAstVisitorComponentIndexer; class CxxAstVisitor: public clang::RecursiveASTVisitor { public: - CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister); + CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr client, std::shared_ptr fileRegister); virtual ~CxxAstVisitor(); template @@ -134,8 +134,8 @@ private: clang::ASTContext* m_astContext; clang::Preprocessor* m_preprocessor; - ParserClient* m_client; - FileRegister* m_fileRegister; + std::shared_ptr m_client; + std::shared_ptr m_fileRegister; MessageInterruptTasksCounter m_interruptCounter; diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp index e89aaaed..e9618b1b 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp @@ -14,7 +14,9 @@ #include "data/parser/ParserClient.h" #include "utility/file/FileRegister.h" -CxxAstVisitorComponentIndexer::CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, ParserClient* client, FileRegister* fileRegister) +CxxAstVisitorComponentIndexer::CxxAstVisitorComponentIndexer( + CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr client, std::shared_ptr fileRegister +) : CxxAstVisitorComponent(astVisitor) , m_astContext(astContext) , m_client(client) @@ -768,9 +770,9 @@ bool CxxAstVisitorComponentIndexer::isLocatedInUnparsedProjectFile(clang::Source std::string fileName = fileEntry->getName(); FilePath filePath = FilePath(fileName).canonical(); - if (m_fileRegister->hasIncludeFile(filePath)) + if (m_fileRegister->hasFilePath(filePath)) { - ret = !(m_fileRegister->includeFileIsParsed(filePath)); + ret = !(m_fileRegister->fileIsIndexed(filePath)); } } diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.h b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.h index 4b059c7b..130da10b 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.h +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.h @@ -12,7 +12,7 @@ class CxxAstVisitorComponentIndexer: public CxxAstVisitorComponent { public: - CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, ParserClient* client, FileRegister* fileRegister); + CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr client, std::shared_ptr fileRegister); virtual ~CxxAstVisitorComponentIndexer(); virtual void beginTraverseNestedNameSpecifierLoc(const clang::NestedNameSpecifierLoc& loc); @@ -68,8 +68,8 @@ private: bool isLocatedInProjectFile(clang::SourceLocation loc); clang::ASTContext* m_astContext; - ParserClient* m_client; - FileRegister* m_fileRegister; + std::shared_ptr m_client; + std::shared_ptr m_fileRegister; std::unordered_map m_inUnparsedProjectFileMap; std::unordered_map m_inProjectFileMap; diff --git a/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp b/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp index 3a473a01..f397ccef 100644 --- a/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp @@ -10,8 +10,8 @@ CxxDiagnosticConsumer::CxxDiagnosticConsumer( clang::raw_ostream &os, clang::DiagnosticOptions *diags, - ParserClient* client, - FileRegister* fileRegister, + std::shared_ptr client, + std::shared_ptr fileRegister, bool useLogging ) : clang::TextDiagnosticPrinter(os, diags) diff --git a/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.h b/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.h index d9259936..40e72475 100644 --- a/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.h +++ b/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.h @@ -13,8 +13,8 @@ public: CxxDiagnosticConsumer( clang::raw_ostream &os, clang::DiagnosticOptions *diags, - ParserClient* client, - FileRegister* fileRegister, + std::shared_ptr client, + std::shared_ptr fileRegister, bool useLogging = true ); @@ -24,8 +24,8 @@ public: void HandleDiagnostic(clang::DiagnosticsEngine::Level level, const clang::Diagnostic& info); private: - ParserClient* m_client; - FileRegister* m_register; + std::shared_ptr m_client; + std::shared_ptr m_register; bool m_isParsingFile; bool m_useLogging; diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.cpp b/src/lib_cxx/data/parser/cxx/CxxParser.cpp index 562de869..5362fbd7 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxParser.cpp @@ -7,6 +7,8 @@ #include "utility/text/TextAccess.h" #include "utility/tracing.h" +#include "data/indexer/IndexerCommandCxxCdb.h" +#include "data/indexer/IndexerCommandCxxManual.h" #include "data/parser/cxx/ASTActionFactory.h" #include "data/parser/cxx/CxxCompilationDatabaseSingle.h" #include "data/parser/cxx/CxxDiagnosticConsumer.h" @@ -52,8 +54,7 @@ namespace } } - -CxxParser::CxxParser(ParserClient* client, std::shared_ptr fileRegister) +CxxParser::CxxParser(std::shared_ptr client, std::shared_ptr fileRegister) : Parser(client) , m_fileRegister(fileRegister) { @@ -63,34 +64,62 @@ CxxParser::~CxxParser() { } -void CxxParser::parseFiles(const std::vector& filePaths, const Arguments& arguments) +void CxxParser::buildIndex(std::shared_ptr indexerCommand) { - m_fileRegister->setFilePaths(filePaths); - setupParsing(arguments); + clang::tooling::CompileCommand compileCommand; + compileCommand.Filename = indexerCommand->getSourceFilePath().str(); + compileCommand.Directory = indexerCommand->getWorkingDirectory().str(); + compileCommand.CommandLine = indexerCommand->getCompilerFlags(); - std::vector sourcePaths; - for (const FilePath& path : m_fileRegister->getUnparsedSourceFilePaths()) // filter headers { - sourcePaths.push_back(path.absolute().str()); + std::vector args = getCommandlineArgumentsEssential( + std::vector(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths() + ); + compileCommand.CommandLine.insert(compileCommand.CommandLine.end(), args.begin(), args.end()); } - runTool(sourcePaths); + CxxCompilationDatabaseSingle compilationDatabase(compileCommand); + clang::tooling::ClangTool tool(compilationDatabase, std::vector(1, indexerCommand->getSourceFilePath().str())); + + std::shared_ptr diagnostics = getDiagnostics(true); + tool.setDiagnosticConsumer(diagnostics.get()); + + ASTActionFactory actionFactory(m_client, m_fileRegister); + tool.run(&actionFactory); } -void CxxParser::parseFile(const FilePath& filePath, std::shared_ptr textAccess, const Arguments& arguments) +void CxxParser::buildIndex(std::shared_ptr indexerCommand) { - m_fileRegister->setFilePaths(std::vector(1, filePath)); - setupParsing(arguments); + std::shared_ptr compilationDatabase = getCompilationDatabase(indexerCommand); - std::vector args = getCommandlineArguments(arguments); - std::shared_ptr diagnostics = getDiagnostics(arguments); + clang::tooling::ClangTool tool(*compilationDatabase, std::vector(1, indexerCommand->getSourceFilePath().str())); - ASTActionFactory actionFactory(m_client, m_fileRegister.get()); - runToolOnCodeWithArgs(diagnostics.get(), actionFactory.create(), textAccess->getText(), args); + std::shared_ptr diagnostics = getDiagnostics(true); + tool.setDiagnosticConsumer(diagnostics.get()); + + ASTActionFactory actionFactory(m_client, m_fileRegister); + tool.run(&actionFactory); } -std::vector CxxParser::getCommandlineArgumentsEssential(const Arguments& arguments) const +void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr fileContent) { + std::shared_ptr diagnostics = getDiagnostics(false); + ASTActionFactory actionFactory(m_client, m_fileRegister); + + std::vector args = getCommandlineArgumentsEssential(std::vector(1, "-std=c++1z"), std::vector(), std::vector()); + + runToolOnCodeWithArgs( + diagnostics.get(), + actionFactory.create(), + fileContent->getText(), + args, + fileName + ); +} + +std::vector CxxParser::getCommandlineArgumentsEssential( + const std::vector& compilerFlags, const std::vector& systemHeaderSearchPaths, const std::vector& frameworkSearchPaths +) const { std::vector args; // verbose @@ -108,24 +137,19 @@ std::vector CxxParser::getCommandlineArgumentsEssential(const Argum // The option -w disables all warnings. args.push_back("-w"); - + // This option tells clang just to continue parsing no matter how manny errors have been thrown. args.push_back("-ferror-limit=0"); - args.insert(args.end(), arguments.compilerFlags.begin(), arguments.compilerFlags.end()); + args.insert(args.end(), compilerFlags.begin(), compilerFlags.end()); - for (const FilePath& path : arguments.headerSearchPaths) - { - args.push_back("-I" + path.str()); - } - - for (const FilePath& path : arguments.systemHeaderSearchPaths) + for (const FilePath& path: systemHeaderSearchPaths) { args.push_back("-isystem"); args.push_back(path.str()); } - for (const FilePath& path : arguments.frameworkSearchPaths) + for (const FilePath& path: frameworkSearchPaths) { args.push_back("-iframework"); args.push_back(path.str()); @@ -134,22 +158,24 @@ std::vector CxxParser::getCommandlineArgumentsEssential(const Argum return args; } -std::vector CxxParser::getCommandlineArguments(const Arguments& arguments) const +std::vector CxxParser::getCommandlineArguments(std::shared_ptr indexerCommand) const { - std::vector args = getCommandlineArgumentsEssential(arguments); + std::vector args = getCommandlineArgumentsEssential( + indexerCommand->getCompilerFlags(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths() + ); // Set language standard - std::string standard = "-std=" + arguments.languageStandard; + std::string standard = "-std=" + indexerCommand->getLanguageStandard(); args.push_back(standard); return args; } std::shared_ptr CxxParser::getCompilationDatabase( - const Arguments& arguments + std::shared_ptr indexerCommand ) const { // Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool. - std::vector args = getCommandlineArguments(arguments); + std::vector args = getCommandlineArguments(indexerCommand); args.insert(args.begin(), "app"); args.insert(args.begin() + 1, "--"); @@ -175,56 +201,9 @@ std::shared_ptr CxxParser::getCompilat return compilationDatabase; } -std::shared_ptr CxxParser::getDiagnostics(const Arguments& arguments) const +std::shared_ptr CxxParser::getDiagnostics(bool logErrors) const { llvm::IntrusiveRefCntPtr options = new clang::DiagnosticOptions(); return std::make_shared( - llvm::errs(), &*options, m_client, m_fileRegister.get(), arguments.logErrors); -} - -void CxxParser::setupParsing(const Arguments& arguments) -{ - m_compilationDatabase = getCompilationDatabase(arguments); - m_diagnostics = getDiagnostics(arguments); -} - -void CxxParser::setupParsingCDB(const Arguments& arguments) -{ - m_diagnostics = getDiagnostics(arguments); -} - -void CxxParser::runTool(const std::vector& files) -{ - TRACE(); - - clang::tooling::ClangTool tool(*m_compilationDatabase, files); - tool.setDiagnosticConsumer(m_diagnostics.get()); - - ASTActionFactory actionFactory(m_client, m_fileRegister.get()); - tool.run(&actionFactory); -} - -void CxxParser::runTool(clang::tooling::CompileCommand command, const Arguments& arguments) -{ - TRACE(); - - std::vector args = getCommandlineArgumentsEssential(arguments); - command.CommandLine.insert(command.CommandLine.end(), args.begin(), args.end()); - - CxxCompilationDatabaseSingle compilationDatabase(command); - clang::tooling::ClangTool tool(compilationDatabase, std::vector(1, command.Filename)); - tool.setDiagnosticConsumer(m_diagnostics.get()); - - ASTActionFactory actionFactory(m_client, m_fileRegister.get()); - tool.run(&actionFactory); -} - -FileRegister* CxxParser::getFileRegister() -{ - return m_fileRegister.get(); -} - -ParserClient* CxxParser::getParserClient() -{ - return m_client; + llvm::errs(), &*options, m_client, m_fileRegister, logErrors); } diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.h b/src/lib_cxx/data/parser/cxx/CxxParser.h index 70f6a38f..a8f84cd6 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.h +++ b/src/lib_cxx/data/parser/cxx/CxxParser.h @@ -6,42 +6,35 @@ class CxxDiagnosticConsumer; class FileRegister; -class FileRegister; +class IndexerCommandCxxCdb; +class IndexerCommandCxxManual; class TaskParseCxx; class CxxParser: public Parser { public: - CxxParser(ParserClient* client, std::shared_ptr fileRegister); + CxxParser(std::shared_ptr client, std::shared_ptr fileRegister); ~CxxParser(); - // ParserClient implementation - virtual void parseFiles(const std::vector& filePaths, const Arguments& arguments); - virtual void parseFile(const FilePath& filePath, std::shared_ptr textAccess, const Arguments& arguments); + void buildIndex(std::shared_ptr indexerCommand); + void buildIndex(std::shared_ptr indexerCommand); + void buildIndex(const std::string& fileName, std::shared_ptr fileContent); + private: - std::vector getCommandlineArgumentsEssential(const Arguments& arguments) const; - std::vector getCommandlineArguments(const Arguments& arguments) const; - std::shared_ptr getCompilationDatabase(const Arguments& arguments) const; + std::vector getCommandlineArgumentsEssential( + const std::vector& compilerFlags, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths) const; + std::vector getCommandlineArguments(std::shared_ptr indexerCommand) const; + std::shared_ptr getCompilationDatabase(std::shared_ptr indexerCommand) const; - std::shared_ptr getDiagnostics(const Arguments& arguments) const; - - // Accessed by TaskParseCxx - void setupParsing(const Arguments& arguments); - void setupParsingCDB(const Arguments& arguments); - - void runTool(const std::vector& files); - void runTool(clang::tooling::CompileCommand command, const Arguments& arguments); - - FileRegister* getFileRegister(); - ParserClient* getParserClient(); + std::shared_ptr getDiagnostics(bool logErrors) const; friend class TaskParseCxx; std::shared_ptr m_fileRegister; - std::shared_ptr m_compilationDatabase; - std::shared_ptr m_diagnostics; }; #endif // CXX_PARSER_H diff --git a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp index 13027952..7f65b688 100644 --- a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.cpp @@ -12,7 +12,7 @@ #include "utility/logging/logging.h" #include "utility/ScopedSwitcher.h" -CxxVerboseAstVisitor::CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister) +CxxVerboseAstVisitor::CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, std::shared_ptr fileRegister) : base(context, preprocessor, client, fileRegister) , m_currentFilePath("") , m_indentation(0) diff --git a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h index 4a2199c0..69d00e4a 100644 --- a/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h +++ b/src/lib_cxx/data/parser/cxx/CxxVerboseAstVisitor.h @@ -11,7 +11,7 @@ class FileRegister; class CxxVerboseAstVisitor: public CxxAstVisitor { public: - CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister); + CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr client, std::shared_ptr fileRegister); virtual ~CxxVerboseAstVisitor(); private: diff --git a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp index 50b6e429..86972692 100644 --- a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp +++ b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.cpp @@ -4,13 +4,14 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Lex/MacroArgs.h" +#include "utility/file/FileSystem.h" #include "utility/file/FileRegister.h" #include "data/parser/ParserClient.h" #include "data/parser/ParseLocation.h" PreprocessorCallbacks::PreprocessorCallbacks( - clang::SourceManager& sourceManager, ParserClient* client, FileRegister* fileRegister + clang::SourceManager& sourceManager, std::shared_ptr client, std::shared_ptr fileRegister ) : m_sourceManager(sourceManager) , m_client(client) @@ -32,14 +33,14 @@ void PreprocessorCallbacks::FileChanged( const bool fileIsInProject = m_fileRegister->hasFilePath(filePath); if (!filePath.empty() && fileIsInProject) { - m_client->onFileParsed(m_fileRegister->getFileInfo(filePath)); - if (reason == EnterFile && !m_fileRegister->includeFileIsParsed(filePath)) + m_client->onFileParsed(FileSystem::getFileInfoForPath(filePath)); // todo: fix for tests + if (reason == EnterFile && !m_fileRegister->fileIsIndexed(filePath)) { - m_fileRegister->markIncludeFileParsing(filePath); + m_fileRegister->markFileIndexing(filePath); } } - if (!filePath.empty() && fileIsInProject && !m_fileRegister->fileIsParsed(filePath)) + if (!filePath.empty() && fileIsInProject && !m_fileRegister->fileIsIndexed(filePath)) { m_currentPath = filePath; } diff --git a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.h b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.h index 0d69c92f..c6de726b 100644 --- a/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.h +++ b/src/lib_cxx/data/parser/cxx/PreprocessorCallbacks.h @@ -1,6 +1,8 @@ #ifndef PREPROCESSOR_CALLBACKS_H #define PREPROCESSOR_CALLBACKS_H +#include + #include "clang/Basic/SourceManager.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/PPCallbacks.h" @@ -17,7 +19,7 @@ class PreprocessorCallbacks : public clang::PPCallbacks { public: - explicit PreprocessorCallbacks(clang::SourceManager& sourceManager, ParserClient* client, FileRegister* fileRegister); + explicit PreprocessorCallbacks(clang::SourceManager& sourceManager, std::shared_ptr client, std::shared_ptr fileRegister); virtual void FileChanged( clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID); @@ -50,8 +52,8 @@ private: ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const; const clang::SourceManager& m_sourceManager; - ParserClient* m_client; - FileRegister* m_fileRegister; + std::shared_ptr m_client; + std::shared_ptr m_fileRegister; FilePath m_currentPath; }; diff --git a/src/lib_cxx/data/parser/cxx/TaskParseCxx.cpp b/src/lib_cxx/data/parser/cxx/TaskParseCxx.cpp deleted file mode 100644 index 68867b91..00000000 --- a/src/lib_cxx/data/parser/cxx/TaskParseCxx.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "data/parser/cxx/TaskParseCxx.h" - -#include "clang/Tooling/JSONCompilationDatabase.h" - -#include "data/parser/cxx/CxxParser.h" -#include "data/parser/ParserClientImpl.h" -#include "data/StorageProvider.h" -#include "utility/file/FileRegister.h" -#include "utility/scheduling/Blackboard.h" - -std::vector TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath) -{ - std::string error; - std::shared_ptr cdb = std::shared_ptr - (clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error)); - - std::vector filePaths; - if (cdb) - { - std::vector files = cdb->getAllFiles(); - for (const std::string& file : files) - { - filePaths.push_back(FilePath(file)); - } - } - return filePaths; -} - -TaskParseCxx::TaskParseCxx( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister, - const Parser::Arguments& arguments, - DialogView* dialogView -) - : TaskParse(storageProvider, fileRegister, arguments, dialogView) - , m_isCDB(false) -{ - if (arguments.compilationDatabasePath.exists()) - { - m_isCDB = true; - } - m_parserClient = std::make_shared(); // todo: create one parserclient per file - m_parser = std::make_shared(m_parserClient.get(), fileRegister); -} - -void TaskParseCxx::doEnter(std::shared_ptr blackboard) -{ - TaskParse::doEnter(blackboard); - - if (m_isCDB) - { - std::string error; - m_cdb = std::shared_ptr - (clang::tooling::JSONCompilationDatabase::loadFromFile(m_arguments.compilationDatabasePath.str(), error)); - - m_parser->setupParsingCDB(m_arguments); - } - else - { - m_parser->setupParsing(m_arguments); - } -} - -void TaskParseCxx::indexFile(FilePath sourcePath) -{ - FileRegister* fileRegister = m_parser->getFileRegister(); - - std::shared_ptr storage = m_storageProvider->popIndexerTarget(); - m_parserClient->setStorage(storage); - m_parserClient->startParsingFile(); - - if (m_isCDB) - { - std::vector commands = m_cdb->getCompileCommands(sourcePath.str()); - if (commands.size() > 0) - { - m_parser->runTool(commands[0], m_arguments); - } - } - else - { - m_parser->runTool(std::vector(1, sourcePath.str())); - } - - m_parserClient->finishParsingFile(); - m_parserClient->resetStorage(); - - if (!m_interrupted) - { - fileRegister->markThreadFilesParsed(); - m_storageProvider->pushIndexerTarget(storage); - } -} diff --git a/src/lib_cxx/data/parser/cxx/TaskParseCxx.h b/src/lib_cxx/data/parser/cxx/TaskParseCxx.h deleted file mode 100644 index 37d98ace..00000000 --- a/src/lib_cxx/data/parser/cxx/TaskParseCxx.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef TASK_PARSE_CXX_H -#define TASK_PARSE_CXX_H - -#include "data/parser/TaskParse.h" - -class CxxParser; -class ParserClientImpl; - -namespace clang -{ - namespace tooling - { - class JSONCompilationDatabase; - } -} - -class TaskParseCxx - : public TaskParse -{ -public: - static std::vector getSourceFilesFromCDB(const FilePath& compilationDatabasePath); - - TaskParseCxx( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister, - const Parser::Arguments& arguments, - DialogView* dialogView - ); - -private: - virtual void doEnter(std::shared_ptr blackboard); - - virtual void indexFile(FilePath sourcePath); - - std::shared_ptr m_parser; - std::shared_ptr m_parserClient; - - bool m_isCDB; - std::shared_ptr m_cdb; -}; - -#endif // TASK_PARSE_CXX_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp index d9d8e4db..94d857d0 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp @@ -1,7 +1,7 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h" -#include "data/parser/cxx/TaskParseCxx.h" #include "settings/CxxProjectSettings.h" +#include "data/indexer/IndexerCxxCdb.h" QtProjectWizzardContentCDBSource::QtProjectWizzardContentCDBSource( std::shared_ptr settings, QtProjectWizzardWindow* window @@ -35,8 +35,7 @@ void QtProjectWizzardContentCDBSource::load() std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); if (cxxSettings) { - std::vector filePaths = - TaskParseCxx::getSourceFilesFromCDB(cxxSettings->getAbsoluteCompilationDatabasePath()); + std::vector filePaths = IndexerCxxCdb::getSourceFilesFromCDB(cxxSettings->getAbsoluteCompilationDatabasePath()); for (FilePath path : filePaths) { diff --git a/src/lib_java/CMakeLists.txt b/src/lib_java/CMakeLists.txt index a1eef2d0..5ac11e24 100644 --- a/src/lib_java/CMakeLists.txt +++ b/src/lib_java/CMakeLists.txt @@ -2,14 +2,19 @@ add_files( LIB_JAVA_FILES + data/indexer/IndexerCommandJava.cpp + data/indexer/IndexerCommandJava.h + data/indexer/IndexerFactoryModuleJava.cpp + data/indexer/IndexerFactoryModuleJava.h + data/indexer/IndexerJava.cpp + data/indexer/IndexerJava.h + data/parser/java/JavaParser.cpp data/parser/java/JavaParser.h data/parser/java/JavaEnvironment.cpp data/parser/java/JavaEnvironment.h data/parser/java/JavaEnvironmentFactory.cpp data/parser/java/JavaEnvironmentFactory.h - data/parser/java/TaskParseJava.cpp - data/parser/java/TaskParseJava.h JavaProject.cpp JavaProject.h diff --git a/src/lib_java/JavaProject.cpp b/src/lib_java/JavaProject.cpp index d636c6d4..39057114 100644 --- a/src/lib_java/JavaProject.cpp +++ b/src/lib_java/JavaProject.cpp @@ -1,9 +1,9 @@ #include "JavaProject.h" #include "component/view/DialogView.h" +#include "data/indexer/IndexerCommandJava.h" #include "data/parser/java/JavaEnvironmentFactory.h" #include "data/parser/java/JavaEnvironment.h" -#include "data/parser/java/TaskParseJava.h" #include "utility/file/FileRegister.h" #include "utility/text/TextAccess.h" #include "utility/messaging/type/MessageStatus.h" @@ -81,17 +81,15 @@ bool JavaProject::prepareIndexing() return true; } -std::shared_ptr JavaProject::createIndexerTask( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister) +std::vector> JavaProject::getIndexerCommands() { - Parser::Arguments arguments; + std::vector classPath; - for (FilePath classpath: m_projectSettings->getAbsoluteClasspaths()) + for (FilePath p: m_projectSettings->getAbsoluteClasspaths()) { - if (classpath.exists()) + if (p.exists()) { - arguments.javaClassPaths.push_back(classpath.str()); + classPath.push_back(p); } } @@ -106,18 +104,38 @@ std::shared_ptr JavaProject::createIndexerTask( { if (rootDirectory.exists()) { - arguments.javaClassPaths.push_back(rootDirectory.str()); + classPath.push_back(rootDirectory.str()); } } - return std::make_shared( - storageProvider, - fileRegister, - arguments, - getDialogView() - ); + std::set indexedPaths; + for (FilePath p: m_projectSettings->getAbsoluteSourcePaths()) + { + if (p.exists()) + { + indexedPaths.insert(p); + } + } + + std::set excludedPaths; + for (FilePath p: m_projectSettings->getAbsoluteExcludePaths()) + { + if (p.exists()) + { + excludedPaths.insert(p); + } + } + + std::vector> indexerCommands; + for (const FilePath& sourcePath: getSourceFilePaths()) + { + indexerCommands.push_back(std::make_shared(sourcePath, indexedPaths, excludedPaths, classPath)); + } + + return indexerCommands; } + void JavaProject::updateFileManager(FileManager& fileManager) { std::vector sourcePaths = m_projectSettings->getAbsoluteSourcePaths(); diff --git a/src/lib_java/JavaProject.h b/src/lib_java/JavaProject.h index 14fb33e1..8dc9cc36 100644 --- a/src/lib_java/JavaProject.h +++ b/src/lib_java/JavaProject.h @@ -25,12 +25,10 @@ private: virtual bool prepareIndexing(); - virtual std::shared_ptr createIndexerTask( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister); + virtual std::vector> getIndexerCommands(); virtual void updateFileManager(FileManager& fileManager); - + void fetchRootDirectories(); std::shared_ptr m_projectSettings; diff --git a/src/lib_java/data/indexer/IndexerCommandJava.cpp b/src/lib_java/data/indexer/IndexerCommandJava.cpp new file mode 100644 index 00000000..27fa8a75 --- /dev/null +++ b/src/lib_java/data/indexer/IndexerCommandJava.cpp @@ -0,0 +1,31 @@ +#include "data/indexer/IndexerCommandJava.h" + +std::string IndexerCommandJava::getIndexerKindString() +{ + return "Java"; +} + +IndexerCommandJava::IndexerCommandJava( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const std::vector& classPath +) + : IndexerCommand(sourceFilePath, indexedPaths, excludedPaths) + , m_classPath(classPath) +{ +} + +IndexerCommandJava::~IndexerCommandJava() +{ +} + +std::string IndexerCommandJava::getKindString() const +{ + return getIndexerKindString(); +} + +std::vector IndexerCommandJava::getClassPath() const +{ + return m_classPath; +} diff --git a/src/lib_java/data/indexer/IndexerCommandJava.h b/src/lib_java/data/indexer/IndexerCommandJava.h new file mode 100644 index 00000000..681d4fb0 --- /dev/null +++ b/src/lib_java/data/indexer/IndexerCommandJava.h @@ -0,0 +1,29 @@ +#ifndef INDEXER_COMMAND_JAVA_H +#define INDEXER_COMMAND_JAVA_H + +#include + +#include "data/indexer/IndexerCommand.h" +#include "utility/file/FilePath.h" + +class IndexerCommandJava: public IndexerCommand +{ +public: + static std::string getIndexerKindString(); + + IndexerCommandJava( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const std::vector& classPath); + virtual ~IndexerCommandJava(); + + virtual std::string getKindString() const; + + std::vector getClassPath() const; + +private: + std::vector m_classPath; +}; + +#endif // INDEXER_COMMAND_JAVA_H diff --git a/src/lib_java/data/indexer/IndexerFactoryModuleJava.cpp b/src/lib_java/data/indexer/IndexerFactoryModuleJava.cpp new file mode 100644 index 00000000..cb68183f --- /dev/null +++ b/src/lib_java/data/indexer/IndexerFactoryModuleJava.cpp @@ -0,0 +1,12 @@ +#include "data/indexer/IndexerFactoryModuleJava.h" + +#include "data/indexer/IndexerJava.h" + +IndexerFactoryModuleJava::~IndexerFactoryModuleJava() +{ +} + +std::shared_ptr IndexerFactoryModuleJava::createIndexer() +{ + return std::make_shared(); +} diff --git a/src/lib_java/data/indexer/IndexerFactoryModuleJava.h b/src/lib_java/data/indexer/IndexerFactoryModuleJava.h new file mode 100644 index 00000000..f2cdc79c --- /dev/null +++ b/src/lib_java/data/indexer/IndexerFactoryModuleJava.h @@ -0,0 +1,13 @@ +#ifndef INDEXER_FACTORY_MODULE_JAVA_H +#define INDEXER_FACTORY_MODULE_JAVA_H + +#include "data/indexer/IndexerFactoryModule.h" + +class IndexerFactoryModuleJava: public IndexerFactoryModule +{ +public: + virtual ~IndexerFactoryModuleJava(); + virtual std::shared_ptr createIndexer(); +}; + +#endif // INDEXER_FACTORY_MODULE_JAVA_H diff --git a/src/lib_java/data/indexer/IndexerJava.cpp b/src/lib_java/data/indexer/IndexerJava.cpp new file mode 100644 index 00000000..f4d51ed8 --- /dev/null +++ b/src/lib_java/data/indexer/IndexerJava.cpp @@ -0,0 +1,37 @@ +#include "data/indexer/IndexerJava.h" + +#include "data/parser/ParserClientImpl.h" +#include "data/parser/java/JavaParser.h" +#include "utility/file/FileRegister.h" + +IndexerJava::IndexerJava() +{ +} + +IndexerJava::~IndexerJava() +{ +} + +std::shared_ptr IndexerJava::index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister) +{ + std::shared_ptr parserClient = std::make_shared(); + std::shared_ptr parser = std::make_shared(parserClient); + + std::shared_ptr storage = std::make_shared(); + parserClient->setStorage(storage); + parserClient->startParsingFile(); + + fileRegister->markFileIndexing(indexerCommand->getSourceFilePath()); + parser->buildIndex(indexerCommand); + fileRegister->markIndexingFilesIndexed(); + + parserClient->finishParsingFile(); + parserClient->resetStorage(); + + if (interrupted()) + { + return std::shared_ptr(); + } + + return storage; +} diff --git a/src/lib_java/data/indexer/IndexerJava.h b/src/lib_java/data/indexer/IndexerJava.h new file mode 100644 index 00000000..0a09febd --- /dev/null +++ b/src/lib_java/data/indexer/IndexerJava.h @@ -0,0 +1,17 @@ +#ifndef INDEXER_JAVA_H +#define INDEXER_JAVA_H + +#include "data/indexer/Indexer.h" +#include "data/indexer/IndexerCommandJava.h" + +class IndexerJava: public Indexer +{ +public: + IndexerJava(); + virtual ~IndexerJava(); + +private: + virtual std::shared_ptr index(std::shared_ptr indexerCommand, std::shared_ptr fileRegister); +}; + +#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 e3e213ab..329f7e02 100644 --- a/src/lib_java/data/parser/java/JavaParser.cpp +++ b/src/lib_java/data/parser/java/JavaParser.cpp @@ -11,7 +11,7 @@ #include "utility/text/TextAccess.h" #include "utility/utilityString.h" -JavaParser::JavaParser(ParserClient* client) +JavaParser::JavaParser(std::shared_ptr client) : Parser(client) , m_id(s_nextParserId++) , m_currentFilePath("") @@ -47,32 +47,30 @@ JavaParser::~JavaParser() s_parsers.erase(m_id); } -void JavaParser::parseFiles(const std::vector& filePaths, const Arguments& arguments) +void JavaParser::buildIndex(std::shared_ptr indexerCommand) { - //m_fileRegister->setFilePaths(filePaths); - //setupParsing(arguments); + std::string classPath = ""; + for (const FilePath& path: indexerCommand->getClassPath()) + { + // the separator used here should be the same as the one used in JavaIndexer.java + classPath += path.str() + ";"; + } - //std::vector sourcePaths; - //for (const FilePath& path : m_fileRegister->getUnparsedSourceFilePaths()) // filter headers - //{ - // sourcePaths.push_back(path.absolute().str()); - //} - - //runTool(sourcePaths); + buildIndex(indexerCommand->getSourceFilePath(), classPath, TextAccess::createFromFile(indexerCommand->getSourceFilePath().str())); } -void JavaParser::parseFile(const FilePath& filePath, std::shared_ptr textAccess, const Arguments& arguments) +void JavaParser::buildIndex(const FilePath& filePath, std::shared_ptr textAccess) +{ + buildIndex(filePath, "", textAccess); +} + +void JavaParser::buildIndex(const FilePath& sourceFilePath, const std::string& classPath, std::shared_ptr textAccess) { if (m_javaEnvironment) { - m_currentFilePath = filePath.str(); - m_client->onFileParsed(FileSystem::getFileInfoForPath(filePath)); - std::string classPath = ""; - for (const FilePath& path: arguments.javaClassPaths) - { - // the separator used here should be the same as the one used in JavaIndexer.java - classPath += path.str() + ";"; - } + m_currentFilePath = sourceFilePath.str(); + + m_client->onFileParsed(FileSystem::getFileInfoForPath(sourceFilePath)); // remove tabs because they screw with javaparser's location resolver std::string fileContent = utility::replace(textAccess->getText(), "\t", " "); @@ -84,7 +82,7 @@ void JavaParser::parseFile(const FilePath& filePath, std::shared_ptr "io/coati/JavaIndexer", "processFile", m_id, - filePath.str(), + m_currentFilePath, fileContent, classPath, verbose @@ -92,13 +90,6 @@ void JavaParser::parseFile(const FilePath& filePath, std::shared_ptr } } - - - - - - - int JavaParser::s_nextParserId = 0; std::map JavaParser::s_parsers; diff --git a/src/lib_java/data/parser/java/JavaParser.h b/src/lib_java/data/parser/java/JavaParser.h index c8080fe4..2ddb8361 100644 --- a/src/lib_java/data/parser/java/JavaParser.h +++ b/src/lib_java/data/parser/java/JavaParser.h @@ -4,6 +4,7 @@ #include #include +#include "data/indexer/IndexerCommandJava.h" #include "data/parser/Parser.h" #include "data/parser/java/JavaEnvironment.h" #include "utility/logging/logging.h" @@ -28,15 +29,14 @@ class FileRegister; class JavaParser: public Parser { public: - JavaParser(ParserClient* client); + JavaParser(std::shared_ptr client); ~JavaParser(); - // ParserClient implementation - virtual void parseFiles(const std::vector& filePaths, const Arguments& arguments); - virtual void parseFile(const FilePath& filePath, std::shared_ptr textAccess, const Arguments& arguments); - + void buildIndex(std::shared_ptr indexerCommand); + void buildIndex(const FilePath& filePath, std::shared_ptr textAccess); private: + void buildIndex(const FilePath& sourceFilePath, const std::string& classPath, std::shared_ptr textAccess); // This macro makes available a variable T, the passed-in t. blablabla TODO: write somethign real here #define MAKE_PARAMS_0() diff --git a/src/lib_java/data/parser/java/TaskParseJava.cpp b/src/lib_java/data/parser/java/TaskParseJava.cpp deleted file mode 100644 index 6b57d3af..00000000 --- a/src/lib_java/data/parser/java/TaskParseJava.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "data/parser/java/TaskParseJava.h" - -#include "component/view/DialogView.h" -#include "data/parser/java/JavaParser.h" -#include "data/parser/ParserClientImpl.h" -#include "data/StorageProvider.h" -#include "utility/file/FileRegister.h" -#include "utility/text/TextAccess.h" - -TaskParseJava::TaskParseJava( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister, - const Parser::Arguments& arguments, - DialogView* dialogView -) - : TaskParse(storageProvider, fileRegister, arguments, dialogView) -{ -} - -void TaskParseJava::indexFile(FilePath sourcePath) -{ - std::shared_ptr parserClient = std::make_shared(); - std::shared_ptr parser = std::make_shared(parserClient.get()); - - std::shared_ptr storage = m_storageProvider->popIndexerTarget(); - parserClient->setStorage(storage); - parserClient->startParsingFile(); - - parser->parseFile(sourcePath, TextAccess::createFromFile(sourcePath.str()), m_arguments); - - parserClient->finishParsingFile(); - parserClient->resetStorage(); - - if (!m_interrupted) - { - m_fileRegister->markThreadFilesParsed(); // todo: rename to markThreadFilesProcessed - m_storageProvider->pushIndexerTarget(storage); - } -} diff --git a/src/lib_java/data/parser/java/TaskParseJava.h b/src/lib_java/data/parser/java/TaskParseJava.h deleted file mode 100644 index 1c46cc67..00000000 --- a/src/lib_java/data/parser/java/TaskParseJava.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef TASK_PARSE_JAVA_H -#define TASK_PARSE_JAVA_H - -#include "data/parser/TaskParse.h" - -class TaskParseJava - : public TaskParse -{ -public: - TaskParseJava( - std::shared_ptr storageProvider, - std::shared_ptr fileRegister, - const Parser::Arguments& arguments, - DialogView* dialogView - ); - -private: - void indexFile(FilePath sourcePath); -}; - -#endif // TASK_PARSE_JAVA_H diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index ff85681b..0bf1f20b 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,8 +1,8 @@ add_files( TEST_FILES - helper/TestFileManager.cpp - helper/TestFileManager.h + helper/TestFileRegister.cpp + helper/TestFileRegister.h helper/TestParserClient.h TestSuiteFixture.cpp diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 575be6ce..8203db6f 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -5,11 +5,12 @@ #include "utility/utility.h" #include "utility/utilityString.h" +#include "data/indexer/IndexerCommandCxxManual.h" #include "data/parser/cxx/CxxParser.h" #include "data/parser/ParseLocation.h" #include "data/parser/ParserClient.h" -#include "helper/TestFileManager.h" +#include "helper/TestFileRegister.h" #include "helper/TestParserClient.h" class CxxParserTestSuite: public CxxTest::TestSuite @@ -3301,40 +3302,44 @@ public: void test_cxx_parser_parses_multiple_files() { - TestFileManager fm; - std::shared_ptr fr = std::make_shared(&fm, false); - TestParserClient client; - CxxParser parser(&client, fr); + std::set indexedPaths; + indexedPaths.insert("data/CxxParserTestSuite/"); - std::vector filePaths; - filePaths.push_back(FilePath("data/CxxParserTestSuite/code.cpp")); + std::shared_ptr indexerCommand = std::make_shared( + FilePath("data/CxxParserTestSuite/code.cpp"), + indexedPaths, + std::set(), + "c++1z", + std::vector(), + std::vector(), + std::vector() + ); - Parser::Arguments args; - args.language = "c++"; - args.languageStandard = "c++1z"; + std::shared_ptr client = std::make_shared(); + CxxParser parser(client, std::make_shared()); - parser.parseFiles(filePaths, args); + parser.buildIndex(indexerCommand); - TS_ASSERT_EQUALS(client.errors.size(), 0); + TS_ASSERT_EQUALS(client->errors.size(), 0); - TS_ASSERT_EQUALS(client.typedefs.size(), 1); - TS_ASSERT_EQUALS(client.classes.size(), 5); - TS_ASSERT_EQUALS(client.enums.size(), 1); - TS_ASSERT_EQUALS(client.enumConstants.size(), 2); - TS_ASSERT_EQUALS(client.functions.size(), 5); // used methods are also recorded as functions (these get overridden in the intermediate storage) - TS_ASSERT_EQUALS(client.fields.size(), 4); - TS_ASSERT_EQUALS(client.globalVariables.size(), 2); - TS_ASSERT_EQUALS(client.methods.size(), 15); - TS_ASSERT_EQUALS(client.namespaces.size(), 2); - TS_ASSERT_EQUALS(client.structs.size(), 1); + TS_ASSERT_EQUALS(client->typedefs.size(), 1); + TS_ASSERT_EQUALS(client->classes.size(), 5); + TS_ASSERT_EQUALS(client->enums.size(), 1); + TS_ASSERT_EQUALS(client->enumConstants.size(), 2); + TS_ASSERT_EQUALS(client->functions.size(), 5); // used methods are also recorded as functions (these get overridden in the intermediate storage) + TS_ASSERT_EQUALS(client->fields.size(), 4); + TS_ASSERT_EQUALS(client->globalVariables.size(), 2); + TS_ASSERT_EQUALS(client->methods.size(), 15); + TS_ASSERT_EQUALS(client->namespaces.size(), 2); + TS_ASSERT_EQUALS(client->structs.size(), 1); - TS_ASSERT_EQUALS(client.inheritances.size(), 1); - TS_ASSERT_EQUALS(client.calls.size(), 3); - TS_ASSERT_EQUALS(client.usages.size(), 3); - TS_ASSERT_EQUALS(client.typeUses.size(), 17); + TS_ASSERT_EQUALS(client->inheritances.size(), 1); + TS_ASSERT_EQUALS(client->calls.size(), 3); + TS_ASSERT_EQUALS(client->usages.size(), 3); + TS_ASSERT_EQUALS(client->typeUses.size(), 17); - TS_ASSERT_EQUALS(client.files.size(), 2); - TS_ASSERT_EQUALS(client.includes.size(), 1); + TS_ASSERT_EQUALS(client->files.size(), 2); + TS_ASSERT_EQUALS(client->includes.size(), 1); } void test_cxx_parser_catches_error() @@ -3393,17 +3398,10 @@ private: { NameHierarchy::setDelimiter("::"); - m_args.logErrors = logErrors; - m_args.language = "c++"; - m_args.languageStandard = "c++1z"; - - TestFileManager fm; - std::shared_ptr fr = std::make_shared(&fm, false); - std::shared_ptr client = std::make_shared(); - CxxParser parser(client.get(), fr); - parser.parseFile("input.cc", TextAccess::createFromString(code), m_args); - return client; + std::shared_ptr fileRegister = std::make_shared(); + std::shared_ptr parserClient = std::make_shared(); + CxxParser parser(parserClient, fileRegister); + parser.buildIndex("input.cc", TextAccess::createFromString(code)); + return parserClient; } - - Parser::Arguments m_args; }; diff --git a/src/test/JavaParserTestSuite.h b/src/test/JavaParserTestSuite.h index d0ddf3d1..f5c02f6a 100644 --- a/src/test/JavaParserTestSuite.h +++ b/src/test/JavaParserTestSuite.h @@ -10,7 +10,7 @@ #include "data/parser/java/JavaEnvironmentFactory.h" #include "data/parser/java/JavaParser.h" -#include "helper/TestFileManager.h" +#include "helper/TestFileRegister.h" #include "helper/TestParserClient.h" @@ -835,23 +835,15 @@ private: { NameHierarchy::setDelimiter("."); - m_args.logErrors = logErrors; - m_args.language = "Java"; - m_args.languageStandard = "1.8"; - - TestFileManager fm; - std::shared_ptr fr = std::make_shared(&fm, false); - std::shared_ptr client = std::make_shared(); + std::shared_ptr parserClient = std::make_shared(); std::shared_ptr textAccess = TextAccess::createFromString(code); setupJavaEnvironmentFactory(); - JavaParser parser(client.get()); - parser.parseFile("input.cc", textAccess, m_args); + JavaParser parser(parserClient); + parser.buildIndex("input.cc", textAccess); - return client; + return parserClient; } - - Parser::Arguments m_args; }; diff --git a/src/test/helper/TestFileManager.cpp b/src/test/helper/TestFileManager.cpp deleted file mode 100644 index 25c42f3b..00000000 --- a/src/test/helper/TestFileManager.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "TestFileManager.h" - -TestFileManager::TestFileManager() -{ -} - -bool TestFileManager::hasFilePath(const FilePath& filePath) const -{ - return true; -} - -bool TestFileManager::hasSourceFilePath(const FilePath& filePath) const -{ - return true; -} - -const FileInfo TestFileManager::getFileInfo(const FilePath& filePath) const -{ - return FileInfo(filePath); -} diff --git a/src/test/helper/TestFileManager.h b/src/test/helper/TestFileManager.h deleted file mode 100644 index 071aec4f..00000000 --- a/src/test/helper/TestFileManager.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TEST_FILE_MANAGER_H -#define TEST_FILE_MANAGER_H - -#include "utility/file/FileManager.h" - -class TestFileManager - : public FileManager -{ -public: - TestFileManager(); - - virtual bool hasFilePath(const FilePath& filePath) const; - virtual bool hasSourceFilePath(const FilePath& filePath) const; - - virtual const FileInfo getFileInfo(const FilePath& filePath) const; -}; - -#endif // TEST_FILE_MANAGER_H diff --git a/src/test/helper/TestFileRegister.cpp b/src/test/helper/TestFileRegister.cpp new file mode 100644 index 00000000..b89cedb1 --- /dev/null +++ b/src/test/helper/TestFileRegister.cpp @@ -0,0 +1,20 @@ +#include "TestFileRegister.h" + +TestFileRegister::TestFileRegister() + : FileRegister(FileRegisterStateData(), std::set(), std::set()) +{ +} + +TestFileRegister::~TestFileRegister() +{ +} + +bool TestFileRegister::fileIsIndexed(const FilePath& filePath) const +{ + return false; +} + +bool TestFileRegister::hasFilePath(const FilePath& filePath) const +{ + return true; +} diff --git a/src/test/helper/TestFileRegister.h b/src/test/helper/TestFileRegister.h new file mode 100644 index 00000000..371cdfbf --- /dev/null +++ b/src/test/helper/TestFileRegister.h @@ -0,0 +1,17 @@ +#ifndef TEST_FILE_MANAGER_H +#define TEST_FILE_MANAGER_H + +#include "utility/file/FileRegister.h" + +class TestFileRegister + : public FileRegister +{ +public: + TestFileRegister(); + virtual ~TestFileRegister(); + + virtual bool fileIsIndexed(const FilePath& filePath) const; + virtual bool hasFilePath(const FilePath& filePath) const; +}; + +#endif // TEST_FILE_MANAGER_H