logic: indexer commands

* replaced parser arguments by project specific IndexerCommands that know everything the indexer needs to know to do its job
* added different language and project specific indexers that know how to handle a certain kind of indexer command
* refactored FileManager and FileRegister to have less overhead
* removed no-rtti restriction for clang files in lib cxx
* uncommented deprecated interprocess code.

fortune cookie message = Happiness will bring you good luck.
This commit is contained in:
malte_langkabel
2017-02-22 16:42:20 +01:00
parent 650cd8101e
commit 4563cbe90a
101 changed files with 1908 additions and 1120 deletions
+1 -4
View File
@@ -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(
+16
View File
@@ -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<ProjectFactoryModuleCpp>());
Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleJava>());
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleJava>());
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleCxxCdb>());
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleCxxManual>());
std::shared_ptr<LicenseChecker> checker = LicenseChecker::getInstance();
if (commandLineParser.startedWithLicense())
@@ -198,6 +210,10 @@ int main(int argc, char *argv[])
Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleCpp>());
Application::getInstance()->addProjectFactoryModule(std::make_shared<ProjectFactoryModuleJava>());
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleJava>());
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleCxxCdb>());
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleCxxManual>());
if (commandLineParser.hasError())
{
Application::getInstance()->handleDialog(commandLineParser.getError());
+21 -2
View File
@@ -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
+84 -16
View File
@@ -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<FilePath> 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<FilePath>& Project::getSourcePaths() const
std::vector<FilePath> Project::getSourcePaths() const
{
return m_fileManager.getSourcePaths();
}
@@ -287,7 +298,7 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh)
}
// handle referenced paths
std::set<FilePath> staticSourceFiles = fileSets.allFiles;
std::set<FilePath> 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<FilePath>& filesToClean, const std::set<
std::shared_ptr<TaskGroupSequence> taskSequential = std::make_shared<TaskGroupSequence>();
// add task for cleaning the database
if (!filesToClean.empty())
{
taskSequential->addTask(std::make_shared<TaskCleanStorage>(
@@ -371,17 +383,31 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
);
}
const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(&m_fileManager, indexerThreadCount > 1);
if (!filesToIndex.empty())
{
fileRegister->setFilePaths(utility::toVector(filesToIndex));
const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
std::shared_ptr<IndexerCommandList> indexerCommandList = std::make_shared<IndexerCommandList>();
for (std::shared_ptr<IndexerCommand> indexerCommand: getIndexerCommands(filesToIndex))
{
indexerCommandList->addCommand(indexerCommand);
}
if (indexerThreadCount > 1)
{
indexerCommandList->shuffle();
}
std::shared_ptr<FileRegisterStateData> fileRegisterStateData = std::make_shared<FileRegisterStateData>();
std::shared_ptr<StorageProvider> storageProvider = std::make_shared<StorageProvider>();
// add tasks for setting some variables on the blackboard that are used during indexing
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("source_file_count", indexerCommandList->size()));
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("indexed_source_file_count", 0));
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("indexer_count", 0));
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(
m_storage.get(),
fileRegister,
m_dialogView
);
taskSequential->addTask(taskParserWrapper);
@@ -389,17 +415,32 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
std::shared_ptr<TaskGroupParallel> taskParallelIndexing = std::make_shared<TaskGroupParallel>();
taskParserWrapper->setTask(taskParallelIndexing);
std::shared_ptr<StorageProvider> storageProvider = std::make_shared<StorageProvider>();
// add tasks for indexing and merging
for (size_t i = 0; i < indexerThreadCount && i < filesToIndex.size(); i++)
{
taskParallelIndexing->addChildTasks(
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
createIndexerTask(storageProvider, fileRegister)
std::make_shared<TaskBuildIndex>(indexerCommandList, storageProvider, fileRegisterStateData, getDialogView())
)
);
}
// add task for merging the intermediate storages
taskParallelIndexing->addTask(
std::make_shared<TaskGroupSequence>()->addChildTasks(
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_EQUALS, 0)
),
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
std::make_shared<TaskGroupSelector>()->addChildTasks(
std::make_shared<TaskMergeStorages>(storageProvider),
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_GREATER_THAN, 0)
)
)
)
);
// add task for injecting the intermediate storages into the persistent storage
taskParallelIndexing->addTask(
std::make_shared<TaskGroupSequence>()->addChildTasks(
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
@@ -419,10 +460,12 @@ void Project::buildIndex(const std::set<FilePath>& 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<TaskShowStatusDialog>("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>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
std::make_shared<TaskInjectStorage>(storageProvider, m_storage)
@@ -430,7 +473,7 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
);
}
taskSequential->addTask(std::make_shared<TaskFinishParsing>(m_storage.get(), m_storageAccessProxy, fileRegister, m_dialogView));
taskSequential->addTask(std::make_shared<TaskFinishParsing>(m_storage.get(), m_storageAccessProxy, m_dialogView));
Task::dispatch(taskSequential);
}
@@ -444,3 +487,28 @@ bool Project::prepareRefresh()
{
return true;
}
std::vector<std::shared_ptr<IndexerCommand>> Project::getIndexerCommands(const std::set<FilePath>& sourceFiles)
{
struct special_compare : public std::unary_function<FilePath, bool>
{
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<std::shared_ptr<IndexerCommand>> indexerCommands;
for (std::shared_ptr<IndexerCommand> indexerCommand: getIndexerCommands())
{
if (std::find_if(sourceFiles.begin(), sourceFiles.end(), special_compare(indexerCommand->getSourceFilePath())) != sourceFiles.end())
{
indexerCommands.push_back(indexerCommand);
}
}
return indexerCommands;
}
+6 -5
View File
@@ -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<FilePath> getSourceFilePaths() const;
bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const;
void setStateSettingsUpdated();
protected:
Project(StorageAccessProxy* storageAccessProxy, DialogView* dialogView);
DialogView* getDialogView() const;
const std::vector<FilePath>& getSourcePaths() const;
std::vector<FilePath> getSourcePaths() const;
virtual std::shared_ptr<ProjectSettings> getProjectSettings() = 0;
virtual const std::shared_ptr<ProjectSettings> getProjectSettings() const = 0;
@@ -63,9 +65,8 @@ private:
virtual bool prepareIndexing();
virtual bool prepareRefresh();
virtual std::shared_ptr<Task> createIndexerTask(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister) = 0;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands() = 0;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& sourceFiles);
virtual void updateFileManager(FileManager& fileManager) = 0;
StorageAccessProxy* const m_storageAccessProxy;
+3 -7
View File
@@ -8,7 +8,7 @@ int StorageProvider::getStorageCount() const
return m_storages.size();
}
void StorageProvider::pushIndexerTarget(std::shared_ptr<IntermediateStorage> storage)
void StorageProvider::insert(std::shared_ptr<IntermediateStorage> storage)
{
const std::size_t storageSize = storage->getSourceLocationCount();
std::list<std::shared_ptr<IntermediateStorage>>::iterator it;
@@ -24,7 +24,7 @@ void StorageProvider::pushIndexerTarget(std::shared_ptr<IntermediateStorage> sto
m_storages.insert(it, storage);
}
std::shared_ptr<IntermediateStorage> StorageProvider::popIndexerTarget()
std::shared_ptr<IntermediateStorage> StorageProvider::consumeSecondLargestStorage()
{
std::shared_ptr<IntermediateStorage> ret;
{
@@ -36,15 +36,11 @@ std::shared_ptr<IntermediateStorage> StorageProvider::popIndexerTarget()
ret = *it;
m_storages.erase(it);
}
else
{
ret = std::make_shared<IntermediateStorage>();
}
}
return ret;
}
std::shared_ptr<IntermediateStorage> StorageProvider::popInjectionSource()
std::shared_ptr<IntermediateStorage> StorageProvider::consumeLargestStorage()
{
std::shared_ptr<IntermediateStorage> ret;
{
+5 -4
View File
@@ -10,13 +10,14 @@ class StorageProvider
{
public:
int getStorageCount() const;
void pushIndexerTarget(std::shared_ptr<IntermediateStorage> storage);
// always returns a usable storage
std::shared_ptr<IntermediateStorage> popIndexerTarget();
void insert(std::shared_ptr<IntermediateStorage> storage);
// returns empty shared_ptr if no storages available
std::shared_ptr<IntermediateStorage> popInjectionSource();
std::shared_ptr<IntermediateStorage> consumeSecondLargestStorage();
// returns empty shared_ptr if no storages available
std::shared_ptr<IntermediateStorage> consumeLargestStorage();
void logCurrentState() const;
+8 -4
View File
@@ -10,12 +10,10 @@
TaskFinishParsing::TaskFinishParsing(
PersistentStorage* storage,
StorageAccess* storageAccess,
std::shared_ptr<FileRegister> 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<Blackboard> 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()
);
-2
View File
@@ -18,7 +18,6 @@ public:
TaskFinishParsing(
PersistentStorage* storage,
StorageAccess* storageAccess,
std::shared_ptr<FileRegister> fileRegister,
DialogView* dialogView
);
@@ -32,7 +31,6 @@ private:
PersistentStorage* m_storage;
StorageAccess* m_storageAccess;
std::shared_ptr<FileRegister> m_fileRegister;
DialogView* m_dialogView;
};
+1 -1
View File
@@ -23,7 +23,7 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboa
{
if (m_storageProvider->getStorageCount() > 0)
{
std::shared_ptr<IntermediateStorage> source = m_storageProvider->popInjectionSource();
std::shared_ptr<IntermediateStorage> source = m_storageProvider->consumeLargestStorage();
if (source)
{
m_target->inject(source.get());
+58
View File
@@ -0,0 +1,58 @@
#include "data/TaskMergeStorages.h"
#include <chrono>
#include <thread>
#include "data/StorageProvider.h"
TaskMergeStorages::TaskMergeStorages(
std::shared_ptr<StorageProvider> storageProvider
)
: m_storageProvider(storageProvider)
{
}
void TaskMergeStorages::doEnter(std::shared_ptr<Blackboard> blackboard)
{
}
Task::TaskState TaskMergeStorages::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
if (m_storageProvider->getStorageCount() > 2) // largest storage won't be touched here
{
std::shared_ptr<IntermediateStorage> target = m_storageProvider->consumeSecondLargestStorage();
std::shared_ptr<IntermediateStorage> 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> blackboard)
{
}
void TaskMergeStorages::doReset(std::shared_ptr<Blackboard> blackboard)
{
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef TASK_MERGE_STORAGES_H
#define TASK_MERGE_STORAGES_H
#include <vector>
#include "utility/scheduling/Task.h"
class StorageProvider;
class TaskMergeStorages
: public Task
{
public:
TaskMergeStorages(
std::shared_ptr<StorageProvider> storageProvider
);
private:
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
std::shared_ptr<StorageProvider> m_storageProvider;
};
#endif // TASK_MERGE_STORAGES_H
+46
View File
@@ -0,0 +1,46 @@
#ifndef INDEXER_H
#define INDEXER_H
#include <memory>
#include "data/indexer/IndexerBase.h"
#include "utility/logging/logging.h"
template <typename IndexerCommandType>
class Indexer: public IndexerBase
{
public:
virtual ~Indexer();
virtual std::string getKindString() const;
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
private:
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommandType> indexerCommand, std::shared_ptr<FileRegister> fileRegister) = 0;
};
template <typename IndexerCommandType>
Indexer<IndexerCommandType>::~Indexer()
{
}
template <typename IndexerCommandType>
std::string Indexer<IndexerCommandType>::getKindString() const
{
return IndexerCommandType::getIndexerKindString();
}
template <typename IndexerCommandType>
std::shared_ptr<IntermediateStorage> Indexer<IndexerCommandType>::index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
{
if (std::shared_ptr<IndexerCommandType> castedCommand = std::dynamic_pointer_cast<IndexerCommandType>(indexerCommand))
{
return index(castedCommand, fileRegister);
}
LOG_ERROR("Trying to process " + indexerCommand->getKindString() + " indexer command with " + getKindString() + " indexer.");
return std::shared_ptr<IntermediateStorage>();
}
#endif // INDEXER_H
+20
View File
@@ -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;
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef INDEXER_BASE_H
#define INDEXER_BASE_H
#include <memory>
#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<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister) = 0;
virtual void interrupt();
bool interrupted() const;
private:
bool m_interrupted;
};
#endif // INDEXER_BASE_H
+28
View File
@@ -0,0 +1,28 @@
#include "data/indexer/IndexerCommand.h"
IndexerCommand::IndexerCommand(const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths)
: m_sourceFilePath(sourceFilePath)
, m_indexedPaths(indexedPaths)
, m_excludedPaths(excludedPaths)
{
}
IndexerCommand::~IndexerCommand()
{
}
FilePath IndexerCommand::getSourceFilePath() const
{
return m_sourceFilePath;
}
std::set<FilePath> IndexerCommand::getIndexedPaths() const
{
return m_indexedPaths;
}
std::set<FilePath> IndexerCommand::getExcludedPath() const
{
return m_excludedPaths;
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef INDEXER_COMMAND_H
#define INDEXER_COMMAND_H
#include <set>
#include <string>
#include "utility/file/FilePath.h"
class IndexerCommand
{
public:
IndexerCommand(const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths);
virtual ~IndexerCommand();
virtual std::string getKindString() const = 0;
FilePath getSourceFilePath() const;
std::set<FilePath> getIndexedPaths() const;
std::set<FilePath> getExcludedPath() const;
private:
FilePath m_sourceFilePath;
std::set<FilePath> m_indexedPaths;
std::set<FilePath> m_excludedPaths;
};
#endif // INDEXER_COMMAND_H
@@ -0,0 +1,34 @@
#include "data/indexer/IndexerCommandList.h"
#include <algorithm>
#include <random>
void IndexerCommandList::addCommand(std::shared_ptr<IndexerCommand> command)
{
std::lock_guard<std::mutex> 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<std::mutex> lock(m_commandsMutex);
std::random_shuffle(m_commands.begin(), m_commands.end());
}
std::shared_ptr<IndexerCommand> IndexerCommandList::consumeCommand()
{
std::lock_guard<std::mutex> lock(m_commandsMutex);
std::shared_ptr<IndexerCommand> ret;
if (!m_commands.empty())
{
ret = m_commands.front();
m_commands.pop_front();
}
return ret;
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef INDEXER_COMMAND_LIST_H
#define INDEXER_COMMAND_LIST_H
#include <memory>
#include <mutex>
#include <deque>
#include "data/indexer/IndexerCommand.h"
class IndexerCommandList
{
public:
void addCommand(std::shared_ptr<IndexerCommand> command);
int size() const;
void shuffle();
std::shared_ptr<IndexerCommand> consumeCommand();
private:
std::deque<std::shared_ptr<IndexerCommand>> m_commands;
std::mutex m_commandsMutex;
};
#endif // INDEXER_COMMAND_LIST_H
+37
View File
@@ -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<IndexerBase> indexer)
{
m_indexers.emplace(indexer->getKindString(), indexer);
}
std::shared_ptr<IntermediateStorage> IndexerComposite::index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> 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<IntermediateStorage>();
}
void IndexerComposite::interrupt()
{
for (auto it: m_indexers)
{
it.second->interrupt();
}
IndexerBase::interrupt();
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef INDEXER_COMPOSITE_H
#define INDEXER_COMPOSITE_H
#include <memory>
#include <unordered_map>
#include "data/indexer/IndexerBase.h"
class IndexerComposite: public IndexerBase
{
public:
virtual ~IndexerComposite();
virtual std::string getKindString() const;
void addIndexer(std::shared_ptr<IndexerBase> indexer);
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
virtual void interrupt();
private:
std::unordered_map<std::string, std::shared_ptr<IndexerBase>> m_indexers;
};
#endif // INDEXER_COMPOSITE_H
+41
View File
@@ -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> IndexerFactory::getInstance()
{
if (!s_instance)
{
s_instance = std::shared_ptr<IndexerFactory>(new IndexerFactory());
}
return s_instance;
}
void IndexerFactory::destroyInstance()
{
s_instance.reset();
}
void IndexerFactory::addModule(std::shared_ptr<IndexerFactoryModule> module)
{
m_modules.push_back(module);
}
std::shared_ptr<IndexerComposite> IndexerFactory::createCompositeIndexerForAllRegisteredModules()
{
std::shared_ptr<IndexerComposite> composite = std::make_shared<IndexerComposite>();
for (auto it: m_modules)
{
composite->addIndexer(it->createIndexer());
}
return composite;
}
std::shared_ptr<IndexerFactory> IndexerFactory::s_instance;
IndexerFactory::IndexerFactory()
{
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef INDEXER_FACTORY_H
#define INDEXER_FACTORY_H
#include <memory>
#include <vector>
#include "settings/LanguageType.h"
class IndexerBase;
class IndexerComposite;
class IndexerFactoryModule;
class IndexerFactory
{
public:
static std::shared_ptr<IndexerFactory> getInstance();
static void destroyInstance();
void addModule(std::shared_ptr<IndexerFactoryModule> module);
std::shared_ptr<IndexerComposite> createCompositeIndexerForAllRegisteredModules();
private:
static std::shared_ptr<IndexerFactory> s_instance;
IndexerFactory();
std::vector<std::shared_ptr<IndexerFactoryModule>> m_modules;
};
#endif // INDEXER_FACTORY_H
@@ -0,0 +1,5 @@
#include "data/indexer/IndexerFactoryModule.h"
IndexerFactoryModule::~IndexerFactoryModule()
{
}
@@ -0,0 +1,17 @@
#ifndef INDEXER_FACTORY_MODULE_H
#define INDEXER_FACTORY_MODULE_H
#include <memory>
#include "settings/LanguageType.h"
class IndexerBase;
class IndexerFactoryModule
{
public:
virtual ~IndexerFactoryModule();
virtual std::shared_ptr<IndexerBase> createIndexer() = 0;
};
#endif // INDEXER_FACTORY_MODULE_H
+109
View File
@@ -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> indexerCommandList,
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegisterStateData> 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> blackboard)
{
std::lock_guard<std::mutex> 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> blackboard)
{
std::shared_ptr<IndexerCommand> indexerCommand = m_indexerCommandList->consumeCommand();
if (!indexerCommand)
{
return STATE_FAILURE;
}
else
{
ApplicationStateMonitor::getInstance()->addIndexingFile(indexerCommand->getSourceFilePath());
{
std::lock_guard<std::mutex> 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> fileRegister = std::make_shared<FileRegister>(
*(m_fileRegisterStateData.get()), indexerCommand->getIndexedPaths(), indexerCommand->getExcludedPath()
);
std::shared_ptr<IntermediateStorage> 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<std::mutex> 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> blackboard)
{
std::lock_guard<std::mutex> 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> blackboard)
{
}
void TaskBuildIndex::handleMessage(MessageInterruptTasks* message)
{
m_indexer->interrupt();
}
@@ -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<MessageInterruptTasks>
{
public:
TaskParse(
TaskBuildIndex(
std::shared_ptr<IndexerCommandList> indexerCommandList,
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister,
const Parser::Arguments& arguments,
std::shared_ptr<FileRegisterStateData> fileRegisterStateData,
DialogView* dialogView
);
@@ -30,15 +32,13 @@ protected:
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
virtual void handleMessage(MessageInterruptTasks* message);
virtual void indexFile(FilePath sourcePath) = 0;
std::shared_ptr<IndexerCommandList> m_indexerCommandList;
std::shared_ptr<StorageProvider> m_storageProvider;
std::shared_ptr<FileRegister> m_fileRegister;
const Parser::Arguments m_arguments;
std::shared_ptr<FileRegisterStateData> m_fileRegisterStateData;
DialogView* m_dialogView;
bool m_interrupted;
std::shared_ptr<IndexerBase> m_indexer;
};
#endif // TASK_PARSE_H
+1 -5
View File
@@ -1,11 +1,7 @@
#include "data/parser/Parser.h"
Parser::Arguments::Arguments()
: logErrors(true)
{
}
Parser::Parser(ParserClient* client)
Parser::Parser(std::shared_ptr<ParserClient> client)
: m_client(client)
{
}
+2 -24
View File
@@ -13,33 +13,11 @@ class TextAccess;
class Parser
{
public:
struct Arguments
{
Arguments();
std::vector<FilePath> javaClassPaths;
std::vector<FilePath> headerSearchPaths;
std::vector<FilePath> systemHeaderSearchPaths;
std::vector<FilePath> frameworkSearchPaths;
std::vector<std::string> compilerFlags;
bool logErrors;
std::string language;
std::string languageStandard;
FilePath compilationDatabasePath;
};
Parser(ParserClient* client);
Parser(std::shared_ptr<ParserClient> client);
virtual ~Parser();
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments) = 0;
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments) = 0;
protected:
ParserClient* m_client;
std::shared_ptr<ParserClient> m_client;
};
#endif // PARSER_H
-75
View File
@@ -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> storageProvider,
std::shared_ptr<FileRegister> 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> blackboard)
{
std::lock_guard<std::mutex> 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> 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> blackboard)
{
std::lock_guard<std::mutex> 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> blackboard)
{
}
void TaskParse::handleMessage(MessageInterruptTasks* message)
{
m_interrupted = true;
}
+2 -7
View File
@@ -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> fileRegister,
DialogView* dialogView
)
: m_storage(storage)
, m_fileRegister(fileRegister)
, m_dialogView(dialogView)
{
}
@@ -31,9 +28,8 @@ void TaskParseWrapper::setTask(std::shared_ptr<Task> task)
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> 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<Blackboard> blackboar
void TaskParseWrapper::doExit(std::shared_ptr<Blackboard> blackboard)
{
blackboard->clear("indexer_count");
blackboard->set("index_time", utility::duration(m_start));
}
-2
View File
@@ -20,7 +20,6 @@ class TaskParseWrapper
public:
TaskParseWrapper(
PersistentStorage* storage,
std::shared_ptr<FileRegister> fileRegister,
DialogView* dialogView
);
virtual ~TaskParseWrapper();
@@ -34,7 +33,6 @@ private:
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
PersistentStorage* m_storage;
std::shared_ptr<FileRegister> m_fileRegister;
DialogView* m_dialogView;
TimePoint m_start;
+1 -1
View File
@@ -114,7 +114,7 @@ bool ProjectSettings::setStandard(const std::string& standard)
return setValue<std::string>("language_settings/standard", standard);
}
std::vector<FilePath> ProjectSettings::getSourcePaths() const
std::vector<FilePath> ProjectSettings::getSourcePaths() const // TODO: rename to getIndexedPaths
{
return getPathValues("source/source_paths/source_path");
}
+24 -47
View File
@@ -15,11 +15,6 @@ FileManager::~FileManager()
{
}
const std::vector<FilePath>& FileManager::getSourcePaths() const
{
return m_sourcePaths;
}
void FileManager::setPaths(
std::vector<FilePath> sourcePaths,
std::vector<FilePath> headerPaths,
@@ -34,24 +29,26 @@ void FileManager::setPaths(
FileManager::FileSets FileManager::fetchFilePaths(const std::vector<FileInfo>& 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<FilePath, FileInfo>::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<FilePath, FileInfo>::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<FileInfo>& o
continue;
}
fileSets.allFiles.insert(filePath);
fileSets.allSourceFilePaths.insert(filePath);
std::map<FilePath, FileInfo>::iterator it = m_files.find(filePath);
if (it != m_files.end())
std::map<FilePath, FileInfo>::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<FileInfo>& o
}
else
{
m_files.insert(std::pair<FilePath, FileInfo>(filePath, fileInfo));
m_filesInfos.insert(std::pair<FilePath, FileInfo>(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<FilePath> FileManager::getSourcePaths() const
{
if (hasSourceFilePath(filePath))
{
return true;
}
return m_sourcePaths;
}
if (isExcluded(filePath))
std::set<FilePath> FileManager::getSourceFilePaths() const
{
std::set<FilePath> 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<FilePath, FileInfo>::const_iterator it = m_files.find(filePath);
if (it == m_files.end())
{
return FileSystem::getFileInfoForPath(filePath);
}
return it->second;
}
std::vector<FilePath> FileManager::makeCanonical(const std::vector<FilePath>& filePaths)
{
std::vector<FilePath> ret;
+11 -10
View File
@@ -12,17 +12,15 @@ class FileManager
public:
struct FileSets
{
std::set<FilePath> allFiles;
std::set<FilePath> addedFiles;
std::set<FilePath> updatedFiles;
std::set<FilePath> removedFiles;
std::set<FilePath> allSourceFilePaths;
};
FileManager();
virtual ~FileManager();
const std::vector<FilePath>& getSourcePaths() const;
void setPaths(
std::vector<FilePath> sourcePaths,
std::vector<FilePath> headerPaths,
@@ -32,24 +30,27 @@ public:
FileSets fetchFilePaths(const std::vector<FileInfo>& 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<FilePath> 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<FilePath> getSourceFilePaths() const;
// checks if file is in non-excluded source directory
virtual bool hasSourceFilePath(const FilePath& filePath) const;
private:
std::vector<FilePath> makeCanonical(const std::vector<FilePath>& filePaths);
bool isExcluded(const FilePath& filePath) const;
std::map<FilePath, FileInfo> m_files;
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_headerPaths;
std::vector<FilePath> m_excludePaths;
std::vector<std::string> m_sourceExtensions;
std::set<FilePath> m_sourceFiles;
std::map<FilePath, FileInfo> m_filesInfos;
std::set<FilePath> m_sourceFilePaths;
};
#endif // FILE_MANAGER_H
+59 -230
View File
@@ -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<FilePath>& indexedPaths, const std::set<FilePath>& 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<FilePath>& filePaths)
FileRegister::~FileRegister()
{
{
std::lock_guard<std::mutex> 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<std::mutex> lock(m_includeFileMutex);
m_includeFilePaths.clear();
}
void FileRegister::markIndexingFilesIndexed()
{
m_stateData.markIndexingFilesIndexed();
}
{
std::lock_guard<std::mutex> 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<std::mutex> lock(m_projectFilesMutex);
std::unordered_map<std::string, bool>::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<std::mutex> lock(m_projectFileInfosMutex);
std::unordered_map<std::string, FileInfo>::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<FilePath> FileRegister::getUnparsedSourceFilePaths() const
{
std::lock_guard<std::mutex> lock(m_sourceFileMutex);
std::vector<FilePath> files;
for (std::pair<FilePath, ParseState>&& 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<std::mutex> lock(m_includeFileMutex);
std::map<FilePath, ParseState>::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<std::mutex> lock(m_sourceFileMutex);
std::map<FilePath, ParseState>::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<std::mutex> lock(m_includeFileMutex);
std::map<FilePath, ParseState>::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<std::mutex> lock(m_consumeFileMutex);
std::vector<FilePath> paths = getUnparsedSourceFilePaths();
FilePath path;
if (paths.size())
{
if (m_randomizeParseOrder)
{
path = paths[rand() % paths.size()];
}
else
{
path = paths[0];
}
std::lock_guard<std::mutex> lock(m_sourceFileMutex);
m_sourceFilePaths[path] = STATE_PARSING;
}
if (!path.empty())
{
std::lock_guard<std::mutex> 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<std::mutex> lock(m_includeFileMutex);
std::map<FilePath, ParseState>::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<std::mutex> lock(m_threadFileMutex);
m_threadParsingFiles[std::this_thread::get_id()].insert(filePath);
}
}
void FileRegister::markThreadFilesParsed()
{
std::lock_guard<std::mutex> sourceFileLock(m_sourceFileMutex);
std::lock_guard<std::mutex> includeFileLock(m_includeFileMutex);
std::lock_guard<std::mutex> threadFileLock(m_threadFileMutex);
std::set<FilePath>& threadFiles = m_threadParsingFiles[std::this_thread::get_id()];
for (std::set<FilePath>::iterator it = threadFiles.begin(); it != threadFiles.end(); it++)
{
std::map<FilePath, ParseState>::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<std::mutex> lock(m_sourceFileMutex);
return m_sourceFilePaths.size();
}
size_t FileRegister::getParsedSourceFilesCount() const
{
std::lock_guard<std::mutex> lock(m_sourceFileMutex);
size_t count = 0;
for (std::pair<FilePath, ParseState>&& p : m_sourceFilePaths)
{
if (p.second == STATE_PARSED)
{
count++;
}
}
return count;
return m_hasFilePathCache.getValue(filePath.str());
}
+13 -56
View File
@@ -1,72 +1,29 @@
#ifndef FILE_REGISTER_H
#define FILE_REGISTER_H
#include <map>
#include <unordered_map>
#include <mutex>
#include <set>
#include <string>
#include <thread>
#include <vector>
#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<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths);
virtual ~FileRegister();
void setFilePaths(const std::vector<FilePath>& filePaths);
FileRegisterStateData getStateData() const;
bool hasFilePath(const FilePath& filePath) const;
const FileInfo getFileInfo(const FilePath& filePath) const;
std::vector<FilePath> 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<std::string, bool> m_projectFiles;
mutable std::mutex m_projectFilesMutex;
mutable std::unordered_map<std::string, FileInfo> m_projectFileInfos;
mutable std::mutex m_projectFileInfosMutex;
std::map<FilePath, ParseState> m_sourceFilePaths;
std::map<FilePath, ParseState> m_includeFilePaths;
std::map<std::thread::id, std::set<FilePath>> 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<FilePath> m_indexedPaths;
const std::set<FilePath> m_excludedPaths;
mutable Cache<std::string, bool> m_hasFilePathCache;
};
#endif // FILE_REGISTER_H
@@ -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<std::mutex> oLock(o.m_filePathsMutex);
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(m_filePathsMutex);
auto it = m_filePaths.find(filePath);
if (it != m_filePaths.end())
{
return it->second == STATE_INDEXED;
}
return false;
}
@@ -0,0 +1,33 @@
#ifndef FILE_REGISTER_STATE_DATA_H
#define FILE_REGISTER_STATE_DATA_H
#include <mutex>
#include <map>
#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<FilePath, IndexingState> m_filePaths;
mutable std::mutex m_filePathsMutex;
};
#endif // FILE_REGISTER_STATE_DATA_H
@@ -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
{
@@ -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:
@@ -1,8 +1,6 @@
#ifndef TASK_RETURN_SUCCESS_WHILE_H
#define TASK_RETURN_SUCCESS_WHILE_H
#include <vector>
#include "utility/scheduling/Task.h"
#include "utility/scheduling/Blackboard.h"
+54
View File
@@ -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 <typename T>
class TaskSetValue:
public Task
{
public:
TaskSetValue(const std::string& valueName, T value);
private:
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
const std::string m_valueName;
const T m_value;
};
template <typename T>
TaskSetValue<T>::TaskSetValue(const std::string& valueName, T value)
: m_valueName(valueName)
, m_value(value)
{
}
template <typename T>
void TaskSetValue<T>::doEnter(std::shared_ptr<Blackboard> blackboard)
{
}
template <typename T>
Task::TaskState TaskSetValue<T>::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
std::lock_guard<std::mutex> lock(blackboard->getMutex());
blackboard->set<T>(m_valueName, m_value);
return STATE_SUCCESS;
}
template <typename T>
void TaskSetValue<T>::doExit(std::shared_ptr<Blackboard> blackboard)
{
}
template <typename T>
void TaskSetValue<T>::doReset(std::shared_ptr<Blackboard> blackboard)
{
}
#endif // TASK_SET_VALUE_H
+16 -11
View File
@@ -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
+102 -54
View File
@@ -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<Task> CxxProject::createIndexerTask(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister)
std::vector<std::shared_ptr<IndexerCommand>> CxxProject::getIndexerCommands()
{
return std::make_shared<TaskParseCxx>(
storageProvider,
fileRegister,
getParserArguments(),
getDialogView()
);
std::shared_ptr<ApplicationSettings> appSettings = ApplicationSettings::getInstance();
std::string languageStandard = m_projectSettings->getStandard();
std::vector<FilePath> 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<FilePath> headerSearchSubPaths;
for (const FilePath& sourcePath : getSourcePaths())
{
utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(sourcePath));
}
utility::append(systemHeaderSearchPaths, utility::unique(headerSearchSubPaths));
}
std::vector<FilePath> frameworkSearchPaths;
utility::append(frameworkSearchPaths, m_projectSettings->getAbsoluteFrameworkSearchPaths());
utility::append(frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
std::vector<std::string> compilerFlags = m_projectSettings->getCompilerFlags();
std::set<FilePath> indexedPaths;
for (FilePath p: m_projectSettings->getAbsoluteSourcePaths())
{
if (p.exists())
{
indexedPaths.insert(p);
}
}
std::set<FilePath> excludedPaths;
for (FilePath p: m_projectSettings->getAbsoluteExcludePaths())
{
if (p.exists())
{
excludedPaths.insert(p);
}
}
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
FilePath cdbPath = m_projectSettings->getAbsoluteCompilationDatabasePath();
if (cdbPath.exists())
{
std::string error;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
(clang::tooling::JSONCompilationDatabase::loadFromFile(cdbPath.str(), error));
for (clang::tooling::CompileCommand command: cdb->getAllCompileCommands())
{
std::vector<std::string> currentCompilerFlags = compilerFlags;
currentCompilerFlags.insert(currentCompilerFlags.end(), command.CommandLine.begin(), command.CommandLine.end());
indexerCommands.push_back(std::make_shared<IndexerCommandCxxCdb>(
FilePath(command.Filename),
indexedPaths,
excludedPaths,
FilePath(command.Directory),
currentCompilerFlags,
systemHeaderSearchPaths,
frameworkSearchPaths
));
}
}
else
{
for (const FilePath& sourcePath: getSourceFilePaths())
{
indexerCommands.push_back(std::make_shared<IndexerCommandCxxManual>(
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<ApplicationSettings> 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<FilePath> 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;
}
+1 -5
View File
@@ -25,14 +25,10 @@ private:
virtual bool prepareRefresh();
virtual std::shared_ptr<Task> createIndexerTask(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister);
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands();
virtual void updateFileManager(FileManager& fileManager);
Parser::Arguments getParserArguments() const;
std::shared_ptr<CxxProjectSettings> m_projectSettings;
@@ -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<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const FilePath& workingDirectory,
const std::vector<std::string>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& 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<std::string> IndexerCommandCxxCdb::getCompilerFlags() const
{
return m_compilerFlags;
}
std::vector<FilePath> IndexerCommandCxxCdb::getSystemHeaderSearchPaths() const
{
return m_systemHeaderSearchPaths;
}
std::vector<FilePath> IndexerCommandCxxCdb::getFrameworkSearchPaths() const
{
return m_frameworkSearchPaths;
}
@@ -0,0 +1,46 @@
#ifndef INDEXER_COMMAND_CXX_CDB_H
#define INDEXER_COMMAND_CXX_CDB_H
#include <vector>
#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<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const FilePath& workingDirectory,
const std::vector<std::string>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths);
virtual ~IndexerCommandCxxCdb();
virtual std::string getKindString() const;
FilePath getWorkingDirectory() const;
std::vector<std::string> getCompilerFlags() const;
std::vector<FilePath> getSystemHeaderSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPaths() const;
private:
FilePath m_workingDirectory;
std::vector<std::string> m_compilerFlags;
std::vector<FilePath> m_systemHeaderSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
};
#endif // INDEXER_COMMAND_CXX_CDB_H
@@ -0,0 +1,53 @@
#include "data/indexer/IndexerCommandCxxManual.h"
std::string IndexerCommandCxxManual::getIndexerKindString()
{
return "CxxManual";
}
IndexerCommandCxxManual::IndexerCommandCxxManual(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const std::string& languageStandard,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& 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<FilePath> IndexerCommandCxxManual::getSystemHeaderSearchPaths() const
{
return m_systemHeaderSearchPaths;
}
std::vector<FilePath> IndexerCommandCxxManual::getFrameworkSearchPaths() const
{
return m_frameworkSearchPaths;
}
std::vector<std::string> IndexerCommandCxxManual::getCompilerFlags() const
{
return m_compilerFlags;
}
@@ -0,0 +1,39 @@
#ifndef INDEXER_COMMAND_CXX_MANUAL_H
#define INDEXER_COMMAND_CXX_MANUAL_H
#include <vector>
#include <string>
#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<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const std::string& languageStandard,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags);
virtual ~IndexerCommandCxxManual();
virtual std::string getKindString() const;
std::string getLanguageStandard() const;
std::vector<FilePath> getSystemHeaderSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<std::string> getCompilerFlags() const;
private:
std::string m_languageStandard;
std::vector<FilePath> m_systemHeaderSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
std::vector<std::string> m_compilerFlags;
};
#endif // INDEXER_COMMAND_CXX_MANUAL_H
@@ -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<FilePath> IndexerCxxCdb::getSourceFilesFromCDB(const FilePath& compilationDatabasePath)
{
std::string error;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
(clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error));
std::vector<FilePath> filePaths;
if (cdb)
{
std::vector<std::string> files = cdb->getAllFiles();
for (const std::string& file : files)
{
filePaths.push_back(FilePath(file));
}
}
return filePaths;
}
std::shared_ptr<IntermediateStorage> IndexerCxxCdb::index(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<CxxParser> parser = std::make_shared<CxxParser>(parserClient, fileRegister);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
parserClient->startParsingFile();
parser->buildIndex(indexerCommand);
fileRegister->markIndexingFilesIndexed();
parserClient->finishParsingFile();
parserClient->resetStorage();
if (interrupted())
{
return std::shared_ptr<IntermediateStorage>();
}
return storage;
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef INDEXER_CXX_CDB_H
#define INDEXER_CXX_CDB_H
#include <vector>
#include "data/indexer/Indexer.h"
#include "data/indexer/IndexerCommandCxxCdb.h"
#include "utility/file/FilePath.h"
class IndexerCxxCdb: public Indexer<IndexerCommandCxxCdb>
{
public:
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
private:
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
};
#endif // INDEXER_CXX_CDB_H
@@ -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<IntermediateStorage> IndexerCxxManual::index(std::shared_ptr<IndexerCommandCxxManual> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<CxxParser> parser = std::make_shared<CxxParser>(parserClient, fileRegister);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
parserClient->startParsingFile();
parser->buildIndex(indexerCommand);
fileRegister->markIndexingFilesIndexed();
parserClient->finishParsingFile();
parserClient->resetStorage();
if (interrupted())
{
return std::shared_ptr<IntermediateStorage>();
}
return storage;
}
@@ -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<IndexerCommandCxxManual>
{
private:
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommandCxxManual> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
};
#endif // INDEXER_CXX_MANUAL_H
@@ -0,0 +1,12 @@
#include "data/indexer/IndexerFactoryModuleCxxCdb.h"
#include "data/indexer/IndexerCxxCdb.h"
IndexerFactoryModuleCxxCdb::~IndexerFactoryModuleCxxCdb()
{
}
std::shared_ptr<IndexerBase> IndexerFactoryModuleCxxCdb::createIndexer()
{
return std::make_shared<IndexerCxxCdb>();
}
@@ -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<IndexerBase> createIndexer();
};
#endif // INDEXER_FACTORY_MODULE_CXX_CDB_H
@@ -0,0 +1,12 @@
#include "data/indexer/IndexerFactoryModuleCxxManual.h"
#include "data/indexer/IndexerCxxManual.h"
IndexerFactoryModuleCxxManual::~IndexerFactoryModuleCxxManual()
{
}
std::shared_ptr<IndexerBase> IndexerFactoryModuleCxxManual::createIndexer()
{
return std::make_shared<IndexerCxxManual>();
}
@@ -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<IndexerBase> createIndexer();
};
#endif // INDEXER_FACTORY_MODULE_CXX_MANUAL_H
+1 -1
View File
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: m_client(client)
, m_fileRegister(fileRegister)
, m_commentHandler(client, fileRegister)
+5 -3
View File
@@ -1,6 +1,8 @@
#ifndef AST_ACTION_H
#define AST_ACTION_H
#include <memory>
#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<ParserClient> client, std::shared_ptr<FileRegister> 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<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
CommentHandler m_commentHandler;
};
@@ -1,6 +1,6 @@
#include "data/parser/cxx/ASTActionFactory.h"
ASTActionFactory::ASTActionFactory(ParserClient* client, FileRegister* fileRegister)
ASTActionFactory::ASTActionFactory(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: m_client(client)
, m_fileRegister(fileRegister)
{
@@ -9,14 +9,14 @@
class ASTActionFactory : public clang::tooling::FrontendActionFactory
{
public:
explicit ASTActionFactory(ParserClient* client, FileRegister* fileRegister);
explicit ASTActionFactory(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
virtual ~ASTActionFactory();
virtual clang::FrontendAction* create();
private:
ParserClient* m_client;
FileRegister* m_fileRegister;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
};
#endif // AST_ACTION_FACTORY
+1 -1
View File
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
{
if (ApplicationSettings::getInstance()->getLoggingEnabled() && ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled())
{
+1 -1
View File
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
virtual ~ASTConsumer();
virtual void HandleTranslationUnit(clang::ASTContext& context);
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> 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(),
+3 -3
View File
@@ -10,14 +10,14 @@ class CommentHandler
: public clang::CommentHandler
{
public:
CommentHandler(ParserClient* client, FileRegister* fileRegister);
CommentHandler(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
virtual ~CommentHandler();
virtual bool HandleComment(clang::Preprocessor& preprocessor, clang::SourceRange sourceRange);
private:
ParserClient* m_client;
FileRegister* m_fileRegister;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
};
#endif // COMMENT_HANDLER_H
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: m_astContext(astContext)
, m_preprocessor(preprocessor)
, m_client(client)
+3 -3
View File
@@ -33,7 +33,7 @@ class CxxAstVisitorComponentIndexer;
class CxxAstVisitor: public clang::RecursiveASTVisitor<CxxAstVisitor>
{
public:
CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister);
CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
virtual ~CxxAstVisitor();
template <typename T>
@@ -134,8 +134,8 @@ private:
clang::ASTContext* m_astContext;
clang::Preprocessor* m_preprocessor;
ParserClient* m_client;
FileRegister* m_fileRegister;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
MessageInterruptTasksCounter m_interruptCounter;
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> 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));
}
}
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> 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<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inUnparsedProjectFileMap;
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inProjectFileMap;
@@ -10,8 +10,8 @@
CxxDiagnosticConsumer::CxxDiagnosticConsumer(
clang::raw_ostream &os,
clang::DiagnosticOptions *diags,
ParserClient* client,
FileRegister* fileRegister,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
bool useLogging
)
: clang::TextDiagnosticPrinter(os, diags)
@@ -13,8 +13,8 @@ public:
CxxDiagnosticConsumer(
clang::raw_ostream &os,
clang::DiagnosticOptions *diags,
ParserClient* client,
FileRegister* fileRegister,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> 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<ParserClient> m_client;
std::shared_ptr<FileRegister> m_register;
bool m_isParsingFile;
bool m_useLogging;
+59 -80
View File
@@ -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> fileRegister)
CxxParser::CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: Parser(client)
, m_fileRegister(fileRegister)
{
@@ -63,34 +64,62 @@ CxxParser::~CxxParser()
{
}
void CxxParser::parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments)
void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> 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<std::string> sourcePaths;
for (const FilePath& path : m_fileRegister->getUnparsedSourceFilePaths()) // filter headers
{
sourcePaths.push_back(path.absolute().str());
std::vector<std::string> args = getCommandlineArgumentsEssential(
std::vector<std::string>(), 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<std::string>(1, indexerCommand->getSourceFilePath().str()));
std::shared_ptr<CxxDiagnosticConsumer> 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> textAccess, const Arguments& arguments)
void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerCommand)
{
m_fileRegister->setFilePaths(std::vector<FilePath>(1, filePath));
setupParsing(arguments);
std::shared_ptr<clang::tooling::CompilationDatabase> compilationDatabase = getCompilationDatabase(indexerCommand);
std::vector<std::string> args = getCommandlineArguments(arguments);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(arguments);
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
ASTActionFactory actionFactory(m_client, m_fileRegister.get());
runToolOnCodeWithArgs(diagnostics.get(), actionFactory.create(), textAccess->getText(), args);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
tool.setDiagnosticConsumer(diagnostics.get());
ASTActionFactory actionFactory(m_client, m_fileRegister);
tool.run(&actionFactory);
}
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(const Arguments& arguments) const
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent)
{
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(false);
ASTActionFactory actionFactory(m_client, m_fileRegister);
std::vector<std::string> args = getCommandlineArgumentsEssential(std::vector<std::string>(1, "-std=c++1z"), std::vector<FilePath>(), std::vector<FilePath>());
runToolOnCodeWithArgs(
diagnostics.get(),
actionFactory.create(),
fileContent->getText(),
args,
fileName
);
}
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(
const std::vector<std::string>& compilerFlags, const std::vector<FilePath>& systemHeaderSearchPaths, const std::vector<FilePath>& frameworkSearchPaths
) const {
std::vector<std::string> args;
// verbose
@@ -108,24 +137,19 @@ std::vector<std::string> 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<std::string> CxxParser::getCommandlineArgumentsEssential(const Argum
return args;
}
std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arguments) const
std::vector<std::string> CxxParser::getCommandlineArguments(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const
{
std::vector<std::string> args = getCommandlineArgumentsEssential(arguments);
std::vector<std::string> 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<clang::tooling::FixedCompilationDatabase> CxxParser::getCompilationDatabase(
const Arguments& arguments
std::shared_ptr<IndexerCommandCxxManual> indexerCommand
) const {
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
std::vector<std::string> args = getCommandlineArguments(arguments);
std::vector<std::string> args = getCommandlineArguments(indexerCommand);
args.insert(args.begin(), "app");
args.insert(args.begin() + 1, "--");
@@ -175,56 +201,9 @@ std::shared_ptr<clang::tooling::FixedCompilationDatabase> CxxParser::getCompilat
return compilationDatabase;
}
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(const Arguments& arguments) const
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(bool logErrors) const
{
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
return std::make_shared<CxxDiagnosticConsumer>(
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<std::string>& 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<std::string> args = getCommandlineArgumentsEssential(arguments);
command.CommandLine.insert(command.CommandLine.end(), args.begin(), args.end());
CxxCompilationDatabaseSingle compilationDatabase(command);
clang::tooling::ClangTool tool(compilationDatabase, std::vector<std::string>(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);
}
+14 -21
View File
@@ -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> fileRegister);
CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
~CxxParser();
// ParserClient implementation
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments);
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
void buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand);
void buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerCommand);
void buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent);
private:
std::vector<std::string> getCommandlineArgumentsEssential(const Arguments& arguments) const;
std::vector<std::string> getCommandlineArguments(const Arguments& arguments) const;
std::shared_ptr<clang::tooling::FixedCompilationDatabase> getCompilationDatabase(const Arguments& arguments) const;
std::vector<std::string> getCommandlineArgumentsEssential(
const std::vector<std::string>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths) const;
std::vector<std::string> getCommandlineArguments(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const;
std::shared_ptr<clang::tooling::FixedCompilationDatabase> getCompilationDatabase(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(const Arguments& arguments) const;
// Accessed by TaskParseCxx
void setupParsing(const Arguments& arguments);
void setupParsingCDB(const Arguments& arguments);
void runTool(const std::vector<std::string>& files);
void runTool(clang::tooling::CompileCommand command, const Arguments& arguments);
FileRegister* getFileRegister();
ParserClient* getParserClient();
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(bool logErrors) const;
friend class TaskParseCxx;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<clang::tooling::CompilationDatabase> m_compilationDatabase;
std::shared_ptr<CxxDiagnosticConsumer> m_diagnostics;
};
#endif // CXX_PARSER_H
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: base(context, preprocessor, client, fileRegister)
, m_currentFilePath("")
, m_indentation(0)
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
virtual ~CxxVerboseAstVisitor();
private:
@@ -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<ParserClient> client, std::shared_ptr<FileRegister> 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;
}
@@ -1,6 +1,8 @@
#ifndef PREPROCESSOR_CALLBACKS_H
#define PREPROCESSOR_CALLBACKS_H
#include <memory>
#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<ParserClient> client, std::shared_ptr<FileRegister> 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<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
FilePath m_currentPath;
};
@@ -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<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath)
{
std::string error;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
(clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error));
std::vector<FilePath> filePaths;
if (cdb)
{
std::vector<std::string> files = cdb->getAllFiles();
for (const std::string& file : files)
{
filePaths.push_back(FilePath(file));
}
}
return filePaths;
}
TaskParseCxx::TaskParseCxx(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> 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<ParserClientImpl>(); // todo: create one parserclient per file
m_parser = std::make_shared<CxxParser>(m_parserClient.get(), fileRegister);
}
void TaskParseCxx::doEnter(std::shared_ptr<Blackboard> blackboard)
{
TaskParse::doEnter(blackboard);
if (m_isCDB)
{
std::string error;
m_cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
(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<IntermediateStorage> storage = m_storageProvider->popIndexerTarget();
m_parserClient->setStorage(storage);
m_parserClient->startParsingFile();
if (m_isCDB)
{
std::vector<clang::tooling::CompileCommand> commands = m_cdb->getCompileCommands(sourcePath.str());
if (commands.size() > 0)
{
m_parser->runTool(commands[0], m_arguments);
}
}
else
{
m_parser->runTool(std::vector<std::string>(1, sourcePath.str()));
}
m_parserClient->finishParsingFile();
m_parserClient->resetStorage();
if (!m_interrupted)
{
fileRegister->markThreadFilesParsed();
m_storageProvider->pushIndexerTarget(storage);
}
}
@@ -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<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
TaskParseCxx(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister,
const Parser::Arguments& arguments,
DialogView* dialogView
);
private:
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
virtual void indexFile(FilePath sourcePath);
std::shared_ptr<CxxParser> m_parser;
std::shared_ptr<ParserClientImpl> m_parserClient;
bool m_isCDB;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_cdb;
};
#endif // TASK_PARSE_CXX_H
@@ -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<ProjectSettings> settings, QtProjectWizzardWindow* window
@@ -35,8 +35,7 @@ void QtProjectWizzardContentCDBSource::load()
std::shared_ptr<CxxProjectSettings> cxxSettings = std::dynamic_pointer_cast<CxxProjectSettings>(m_settings);
if (cxxSettings)
{
std::vector<FilePath> filePaths =
TaskParseCxx::getSourceFilesFromCDB(cxxSettings->getAbsoluteCompilationDatabasePath());
std::vector<FilePath> filePaths = IndexerCxxCdb::getSourceFilesFromCDB(cxxSettings->getAbsoluteCompilationDatabasePath());
for (FilePath path : filePaths)
{
+7 -2
View File
@@ -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
+33 -15
View File
@@ -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<Task> JavaProject::createIndexerTask(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister)
std::vector<std::shared_ptr<IndexerCommand>> JavaProject::getIndexerCommands()
{
Parser::Arguments arguments;
std::vector<FilePath> 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<Task> JavaProject::createIndexerTask(
{
if (rootDirectory.exists())
{
arguments.javaClassPaths.push_back(rootDirectory.str());
classPath.push_back(rootDirectory.str());
}
}
return std::make_shared<TaskParseJava>(
storageProvider,
fileRegister,
arguments,
getDialogView()
);
std::set<FilePath> indexedPaths;
for (FilePath p: m_projectSettings->getAbsoluteSourcePaths())
{
if (p.exists())
{
indexedPaths.insert(p);
}
}
std::set<FilePath> excludedPaths;
for (FilePath p: m_projectSettings->getAbsoluteExcludePaths())
{
if (p.exists())
{
excludedPaths.insert(p);
}
}
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (const FilePath& sourcePath: getSourceFilePaths())
{
indexerCommands.push_back(std::make_shared<IndexerCommandJava>(sourcePath, indexedPaths, excludedPaths, classPath));
}
return indexerCommands;
}
void JavaProject::updateFileManager(FileManager& fileManager)
{
std::vector<FilePath> sourcePaths = m_projectSettings->getAbsoluteSourcePaths();
+2 -4
View File
@@ -25,12 +25,10 @@ private:
virtual bool prepareIndexing();
virtual std::shared_ptr<Task> createIndexerTask(
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegister> fileRegister);
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands();
virtual void updateFileManager(FileManager& fileManager);
void fetchRootDirectories();
std::shared_ptr<JavaProjectSettings> m_projectSettings;
@@ -0,0 +1,31 @@
#include "data/indexer/IndexerCommandJava.h"
std::string IndexerCommandJava::getIndexerKindString()
{
return "Java";
}
IndexerCommandJava::IndexerCommandJava(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const std::vector<FilePath>& classPath
)
: IndexerCommand(sourceFilePath, indexedPaths, excludedPaths)
, m_classPath(classPath)
{
}
IndexerCommandJava::~IndexerCommandJava()
{
}
std::string IndexerCommandJava::getKindString() const
{
return getIndexerKindString();
}
std::vector<FilePath> IndexerCommandJava::getClassPath() const
{
return m_classPath;
}
@@ -0,0 +1,29 @@
#ifndef INDEXER_COMMAND_JAVA_H
#define INDEXER_COMMAND_JAVA_H
#include <vector>
#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<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const std::vector<FilePath>& classPath);
virtual ~IndexerCommandJava();
virtual std::string getKindString() const;
std::vector<FilePath> getClassPath() const;
private:
std::vector<FilePath> m_classPath;
};
#endif // INDEXER_COMMAND_JAVA_H
@@ -0,0 +1,12 @@
#include "data/indexer/IndexerFactoryModuleJava.h"
#include "data/indexer/IndexerJava.h"
IndexerFactoryModuleJava::~IndexerFactoryModuleJava()
{
}
std::shared_ptr<IndexerBase> IndexerFactoryModuleJava::createIndexer()
{
return std::make_shared<IndexerJava>();
}
@@ -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<IndexerBase> createIndexer();
};
#endif // INDEXER_FACTORY_MODULE_JAVA_H
+37
View File
@@ -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<IntermediateStorage> IndexerJava::index(std::shared_ptr<IndexerCommandJava> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
parserClient->startParsingFile();
fileRegister->markFileIndexing(indexerCommand->getSourceFilePath());
parser->buildIndex(indexerCommand);
fileRegister->markIndexingFilesIndexed();
parserClient->finishParsingFile();
parserClient->resetStorage();
if (interrupted())
{
return std::shared_ptr<IntermediateStorage>();
}
return storage;
}
+17
View File
@@ -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<IndexerCommandJava>
{
public:
IndexerJava();
virtual ~IndexerJava();
private:
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommandJava> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
};
#endif // INDEXER_JAVA_H
+19 -28
View File
@@ -11,7 +11,7 @@
#include "utility/text/TextAccess.h"
#include "utility/utilityString.h"
JavaParser::JavaParser(ParserClient* client)
JavaParser::JavaParser(std::shared_ptr<ParserClient> 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<FilePath>& filePaths, const Arguments& arguments)
void JavaParser::buildIndex(std::shared_ptr<IndexerCommandJava> 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<std::string> 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> textAccess, const Arguments& arguments)
void JavaParser::buildIndex(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess)
{
buildIndex(filePath, "", textAccess);
}
void JavaParser::buildIndex(const FilePath& sourceFilePath, const std::string& classPath, std::shared_ptr<TextAccess> 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<TextAccess>
"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<TextAccess>
}
}
int JavaParser::s_nextParserId = 0;
std::map<int, JavaParser*> JavaParser::s_parsers;
+5 -5
View File
@@ -4,6 +4,7 @@
#include <map>
#include <mutex>
#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<ParserClient> client);
~JavaParser();
// ParserClient implementation
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments);
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
void buildIndex(std::shared_ptr<IndexerCommandJava> indexerCommand);
void buildIndex(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess);
private:
void buildIndex(const FilePath& sourceFilePath, const std::string& classPath, std::shared_ptr<TextAccess> textAccess);
// This macro makes available a variable T, the passed-in t. blablabla TODO: write somethign real here
#define MAKE_PARAMS_0()
@@ -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> storageProvider,
std::shared_ptr<FileRegister> fileRegister,
const Parser::Arguments& arguments,
DialogView* dialogView
)
: TaskParse(storageProvider, fileRegister, arguments, dialogView)
{
}
void TaskParseJava::indexFile(FilePath sourcePath)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient.get());
std::shared_ptr<IntermediateStorage> 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);
}
}
@@ -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> storageProvider,
std::shared_ptr<FileRegister> fileRegister,
const Parser::Arguments& arguments,
DialogView* dialogView
);
private:
void indexFile(FilePath sourcePath);
};
#endif // TASK_PARSE_JAVA_H
+2 -2
View File
@@ -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
+38 -40
View File
@@ -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<FileRegister> fr = std::make_shared<FileRegister>(&fm, false);
TestParserClient client;
CxxParser parser(&client, fr);
std::set<FilePath> indexedPaths;
indexedPaths.insert("data/CxxParserTestSuite/");
std::vector<FilePath> filePaths;
filePaths.push_back(FilePath("data/CxxParserTestSuite/code.cpp"));
std::shared_ptr<IndexerCommandCxxManual> indexerCommand = std::make_shared<IndexerCommandCxxManual>(
FilePath("data/CxxParserTestSuite/code.cpp"),
indexedPaths,
std::set<FilePath>(),
"c++1z",
std::vector<FilePath>(),
std::vector<FilePath>(),
std::vector<std::string>()
);
Parser::Arguments args;
args.language = "c++";
args.languageStandard = "c++1z";
std::shared_ptr<TestParserClient> client = std::make_shared<TestParserClient>();
CxxParser parser(client, std::make_shared<TestFileRegister>());
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<FileRegister> fr = std::make_shared<FileRegister>(&fm, false);
std::shared_ptr<TestParserClient> client = std::make_shared<TestParserClient>();
CxxParser parser(client.get(), fr);
parser.parseFile("input.cc", TextAccess::createFromString(code), m_args);
return client;
std::shared_ptr<TestFileRegister> fileRegister = std::make_shared<TestFileRegister>();
std::shared_ptr<TestParserClient> parserClient = std::make_shared<TestParserClient>();
CxxParser parser(parserClient, fileRegister);
parser.buildIndex("input.cc", TextAccess::createFromString(code));
return parserClient;
}
Parser::Arguments m_args;
};
+5 -13
View File
@@ -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<FileRegister> fr = std::make_shared<FileRegister>(&fm, false);
std::shared_ptr<TestParserClient> client = std::make_shared<TestParserClient>();
std::shared_ptr<TestParserClient> parserClient = std::make_shared<TestParserClient>();
std::shared_ptr<TextAccess> 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;
};
-20
View File
@@ -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);
}
-18
View File
@@ -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
+20
View File
@@ -0,0 +1,20 @@
#include "TestFileRegister.h"
TestFileRegister::TestFileRegister()
: FileRegister(FileRegisterStateData(), std::set<FilePath>(), std::set<FilePath>())
{
}
TestFileRegister::~TestFileRegister()
{
}
bool TestFileRegister::fileIsIndexed(const FilePath& filePath) const
{
return false;
}
bool TestFileRegister::hasFilePath(const FilePath& filePath) const
{
return true;
}

Some files were not shown because too many files have changed in this diff Show More