diff --git a/CMakeLists.txt b/CMakeLists.txt index eacc9e8d..65bd0517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,7 @@ set_property( "${CMAKE_SOURCE_DIR}/src/app" "${CMAKE_SOURCE_DIR}/build/src/app" "${CMAKE_SOURCE_DIR}/src/external" + ${Boost_INCLUDE_DIRS} ) # Use the Widgets module from Qt 5. @@ -213,6 +214,7 @@ if (CXXTEST_FOUND) "${CMAKE_SOURCE_DIR}/src/lib" "${CXXTEST_INCLUDE_DIR}" "${CMAKE_SOURCE_DIR}/src/external" + ${Boost_INCLUDE_DIRS} ) endif (CXXTEST_FOUND) diff --git a/bin/app/data/src/test2/main.cpp b/bin/app/data/src/test2/main.cpp index 443517fc..f5129aef 100644 --- a/bin/app/data/src/test2/main.cpp +++ b/bin/app/data/src/test2/main.cpp @@ -1,6 +1,5 @@ #include "header.h" - int main() { TemplateTestClass t2; diff --git a/bin/test/data/FileManagerTestSuite/include/b.hpp b/bin/test/data/FileManagerTestSuite/include/b.hpp new file mode 100644 index 00000000..e69de29b diff --git a/bin/test/data/FileManagerTestSuite/include/c.h b/bin/test/data/FileManagerTestSuite/include/c.h new file mode 100644 index 00000000..77c430a5 --- /dev/null +++ b/bin/test/data/FileManagerTestSuite/include/c.h @@ -0,0 +1 @@ +update \ No newline at end of file diff --git a/bin/test/data/FileManagerTestSuite/src/a.cpp b/bin/test/data/FileManagerTestSuite/src/a.cpp new file mode 100644 index 00000000..e69de29b diff --git a/bin/test/data/FileManagerTestSuite/src/d.c b/bin/test/data/FileManagerTestSuite/src/d.c new file mode 100644 index 00000000..e69de29b diff --git a/src/app/qt/element/QtCodeFile.cpp b/src/app/qt/element/QtCodeFile.cpp index a0b78083..9193dd73 100644 --- a/src/app/qt/element/QtCodeFile.cpp +++ b/src/app/qt/element/QtCodeFile.cpp @@ -5,7 +5,7 @@ #include "qt/element/QtCodeFileList.h" #include "qt/element/QtCodeSnippet.h" -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" QtCodeFile::QtCodeFile(const std::string& filePath, QtCodeFileList* parent) : QWidget(parent) diff --git a/src/app/qt/element/QtCodeFileList.cpp b/src/app/qt/element/QtCodeFileList.cpp index 80c7ccbb..64bed1f0 100644 --- a/src/app/qt/element/QtCodeFileList.cpp +++ b/src/app/qt/element/QtCodeFileList.cpp @@ -5,7 +5,7 @@ #include "data/location/TokenLocationFile.h" #include "qt/element/QtCodeFile.h" -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" QtCodeFileList::QtCodeFileList(QWidget* parent) : QScrollArea(parent) diff --git a/src/app/qt/utility/utilityQt.cpp b/src/app/qt/utility/utilityQt.cpp index e043c96c..23811d5b 100644 --- a/src/app/qt/utility/utilityQt.cpp +++ b/src/app/qt/utility/utilityQt.cpp @@ -5,7 +5,7 @@ #include #include -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" #include "utility/logging/logging.h" namespace utility diff --git a/src/app/qt/view/QtCodeView.cpp b/src/app/qt/view/QtCodeView.cpp index 22837cc2..ba19ee88 100644 --- a/src/app/qt/view/QtCodeView.cpp +++ b/src/app/qt/view/QtCodeView.cpp @@ -4,7 +4,7 @@ #include "qt/element/QtCodeFileList.h" #include "qt/view/QtViewWidgetWrapper.h" -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" #include "utility/text/TextAccess.h" QtCodeView::QtCodeView(ViewLayout* viewLayout) diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index b4a1d6df..759b0980 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -46,7 +46,7 @@ void Application::loadProject(const std::string& projectSettingsFilePath) m_project = Project::create(m_graphAccessProxy.get(), m_locationAccessProxy.get()); m_project->loadProjectSettings(projectSettingsFilePath); - m_project->parseCode(false); + m_project->parseCode(); } void Application::loadSource(const std::string& sourceDirectoryPath) @@ -55,12 +55,12 @@ void Application::loadSource(const std::string& sourceDirectoryPath) m_project->clearProjectSettings(); m_project->setSourceDirectoryPath(sourceDirectoryPath); - m_project->parseCode(false); + m_project->parseCode(); } void Application::reloadProject() { - m_project->parseCode(true); + m_project->parseCode(); } void Application::saveProject(const std::string& projectSettingsFilePath) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 70499397..7fadc607 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -184,6 +184,13 @@ add_files( data/Storage.cpp data/Storage.h + utility/file/FileInfo.cpp + utility/file/FileInfo.h + utility/file/FileManager.cpp + utility/file/FileManager.h + utility/file/FileSystem.cpp + utility/file/FileSystem.h + utility/logging/ConsoleLogger.cpp utility/logging/ConsoleLogger.h utility/logging/FileLogger.cpp @@ -240,8 +247,6 @@ add_files( utility/ConfigManager.cpp utility/ConfigManager.h - utility/FileSystem.cpp - utility/FileSystem.h utility/Property.h utility/types.h utility/utilityString.cpp diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 030ce032..0df79b0e 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -11,9 +11,9 @@ #include "data/access/LocationAccessProxy.h" #include "data/graph/Token.h" #include "data/parser/cxx/CxxParser.h" -#include "utility/FileSystem.h" -#include "utility/messaging/type/MessageFinishedParsing.h" #include "utility/logging/logging.h" +#include "utility/messaging/type/MessageFinishedParsing.h" +#include "utility/file/FileSystem.h" std::shared_ptr Project::create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy) { @@ -77,60 +77,71 @@ void Project::clearStorage() Token::resetNextId(); } -void Project::parseCode(bool refresh) +void Project::parseCode() { std::string sourcePath = ProjectSettings::getInstance()->getSourcePath(); if (sourcePath.size()) { - std::vector extensions; - extensions.push_back(".cpp"); - extensions.push_back(".cc"); - extensions.push_back(".h"); - extensions.push_back(".hpp"); - - // Add the SourcePath as HeaderSearchPath as well. - std::vector headerSearchPaths = ProjectSettings::getInstance()->getHeaderSearchPaths(); - headerSearchPaths.push_back(sourcePath); - - std::vector filePaths; - if (refresh) + std::vector includePaths; + includePaths.push_back(sourcePath); + if (!m_fileManager) { - filePaths = FileSystem::getFileNamesFromDirectoryUpdatedAfter(sourcePath, extensions, m_lastParseTimeString); + std::vector sourcePaths; + sourcePaths.push_back(sourcePath); + std::vector sourceExtensions; + sourceExtensions.push_back(".cpp"); + sourceExtensions.push_back(".cc"); + std::vector includeExtensions; + includeExtensions.push_back(".h"); + includeExtensions.push_back(".hpp"); + m_fileManager = std::make_shared(sourcePaths, includePaths, sourceExtensions, includeExtensions); // todo: move this creation to another place (after projectsettings have been loaded) + } + + m_fileManager->fetchFilePaths(); + std::vector addedFilePaths = m_fileManager->getAddedFilePaths(); + std::vector updatedFilePaths = m_fileManager->getUpdatedFilePaths(); + std::vector removedFilePaths = m_fileManager->getRemovedFilePaths(); + + m_storage->clearFileData(addedFilePaths); + m_storage->clearFileData(updatedFilePaths); + m_storage->clearFileData(removedFilePaths); + + std::vector filesToParse = addedFilePaths; + for (std::string updatedFilePath: updatedFilePaths) + { + filesToParse.push_back(updatedFilePath); + } + + if (filesToParse.size() == 0) + { + MessageFinishedParsing(0, 0, m_storage->getErrorCount()).dispatch(); } else { - filePaths = FileSystem::getFileNamesFromDirectory(sourcePath, extensions); + // Add the SourcePaths as HeaderSearchPaths as well, so clang will also look here when searching include files. + std::vector headerSearchPaths = ProjectSettings::getInstance()->getHeaderSearchPaths(); + for (int i = 0; i < includePaths.size(); i++) + { + headerSearchPaths.push_back(includePaths[i]); + } + + CxxParser parser(m_storage.get(), m_fileManager.get()); + clock_t time = clock(); + parser.parseFiles( + filesToParse, + ApplicationSettings::getInstance()->getHeaderSearchPaths(), + headerSearchPaths + ); + time = clock() - time; + + // m_storage->logGraph(); + // m_storage->logLocations(); + + double parseTime = (double)(time) / CLOCKS_PER_SEC; + LOG_INFO_STREAM(<< "parse time: " << parseTime); + + MessageFinishedParsing(filesToParse.size(), parseTime, m_storage->getErrorCount()).dispatch(); } - - if (!filePaths.size()) - { - MessageFinishedParsing(0, 0, m_storage->getErrorCount()).dispatch(); - return; - } - - m_lastParseTimeString = FileSystem::getTimeStringNow(); - - if (refresh) - { - m_storage->clearFileData(filePaths); - } - - CxxParser parser(m_storage.get()); - clock_t time = clock(); - parser.parseFiles( - filePaths, - ApplicationSettings::getInstance()->getHeaderSearchPaths(), - headerSearchPaths - ); - time = clock() - time; - - // m_storage->logGraph(); - // m_storage->logLocations(); - - double parseTime = (double)(time) / CLOCKS_PER_SEC; - LOG_INFO_STREAM(<< "parse time: " << parseTime); - - MessageFinishedParsing(filePaths.size(), parseTime, m_storage->getErrorCount()).dispatch(); } } diff --git a/src/lib/Project.h b/src/lib/Project.h index edd1989a..92c86d68 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -4,6 +4,7 @@ #include #include "data/Storage.h" +#include "utility/file/FileManager.h" #include "ProjectSettings.h" class GraphAccessProxy; @@ -23,7 +24,7 @@ public: bool setSourceDirectoryPath(const std::string& sourceDirectoryPath); void clearStorage(); - void parseCode(bool refresh); + void parseCode(); private: Project(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy); @@ -36,8 +37,7 @@ private: LocationAccessProxy* const m_locationAccessProxy; std::shared_ptr m_storage; - - std::string m_lastParseTimeString; + std::shared_ptr m_fileManager; }; #endif // PROJECT_H diff --git a/src/lib/Settings.cpp b/src/lib/Settings.cpp index 434719ee..d0b55519 100644 --- a/src/lib/Settings.cpp +++ b/src/lib/Settings.cpp @@ -1,6 +1,6 @@ #include "Settings.h" -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" #include "utility/logging/logging.h" #include "utility/text/TextAccess.h" #include "utility/utilityString.h" diff --git a/src/lib/component/view/CodeView.cpp b/src/lib/component/view/CodeView.cpp index 674c0c7c..21ff0ef1 100644 --- a/src/lib/component/view/CodeView.cpp +++ b/src/lib/component/view/CodeView.cpp @@ -1,7 +1,7 @@ #include "component/view/CodeView.h" #include "component/controller/CodeController.h" -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" CodeView::CodeSnippetParams::CodeSnippetParams() : startLineNumber(0) diff --git a/src/lib/data/location/TokenLocationCollection.cpp b/src/lib/data/location/TokenLocationCollection.cpp index 6fc12f20..e6194ec6 100644 --- a/src/lib/data/location/TokenLocationCollection.cpp +++ b/src/lib/data/location/TokenLocationCollection.cpp @@ -2,7 +2,7 @@ #include -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" #include "utility/logging/logging.h" #include "data/location/TokenLocation.h" diff --git a/src/lib/data/parser/cxx/ASTAction.cpp b/src/lib/data/parser/cxx/ASTAction.cpp index 1466ea78..db37e4e1 100644 --- a/src/lib/data/parser/cxx/ASTAction.cpp +++ b/src/lib/data/parser/cxx/ASTAction.cpp @@ -1,7 +1,8 @@ #include "data/parser/cxx/ASTAction.h" -ASTAction::ASTAction(ParserClient* client) +ASTAction::ASTAction(ParserClient* client, FileManager* fileManager) : m_client(client) + , m_fileManager(fileManager) { } @@ -11,5 +12,5 @@ ASTAction::~ASTAction() std::unique_ptr ASTAction::CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) { - return std::unique_ptr(new ASTConsumer(&compiler.getASTContext(), m_client)); + return std::unique_ptr(new ASTConsumer(&compiler.getASTContext(), m_client, m_fileManager)); } diff --git a/src/lib/data/parser/cxx/ASTAction.h b/src/lib/data/parser/cxx/ASTAction.h index b9b7b64c..60ab5690 100644 --- a/src/lib/data/parser/cxx/ASTAction.h +++ b/src/lib/data/parser/cxx/ASTAction.h @@ -5,17 +5,19 @@ #include "clang/Frontend/FrontendAction.h" #include "data/parser/cxx/ASTConsumer.h" +#include "utility/file/FileManager.h" class ASTAction : public clang::ASTFrontendAction { public: - explicit ASTAction(ParserClient* client); + explicit ASTAction(ParserClient* client, FileManager* fileManager); virtual ~ASTAction(); virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile); private: ParserClient* m_client; + FileManager* m_fileManager; }; #endif // AST_ACTION_H diff --git a/src/lib/data/parser/cxx/ASTActionFactory.cpp b/src/lib/data/parser/cxx/ASTActionFactory.cpp index 1e921fc4..32c9b158 100644 --- a/src/lib/data/parser/cxx/ASTActionFactory.cpp +++ b/src/lib/data/parser/cxx/ASTActionFactory.cpp @@ -1,7 +1,8 @@ #include "data/parser/cxx/ASTActionFactory.h" -ASTActionFactory::ASTActionFactory(ParserClient* client) +ASTActionFactory::ASTActionFactory(ParserClient* client, FileManager* fileManager) : m_client(client) + , m_fileManager(fileManager) { } @@ -11,5 +12,5 @@ ASTActionFactory::~ASTActionFactory() clang::FrontendAction* ASTActionFactory::create() { - return new ASTAction(m_client); + return new ASTAction(m_client, m_fileManager); } diff --git a/src/lib/data/parser/cxx/ASTActionFactory.h b/src/lib/data/parser/cxx/ASTActionFactory.h index 321cb125..82614498 100644 --- a/src/lib/data/parser/cxx/ASTActionFactory.h +++ b/src/lib/data/parser/cxx/ASTActionFactory.h @@ -4,17 +4,19 @@ #include "clang/Tooling/Tooling.h" #include "data/parser/cxx/ASTAction.h" +#include "utility/file/FileManager.h" class ASTActionFactory : public clang::tooling::FrontendActionFactory { public: - explicit ASTActionFactory(ParserClient* client); + explicit ASTActionFactory(ParserClient* client, FileManager* fileManager); virtual ~ASTActionFactory(); virtual clang::FrontendAction* create(); private: ParserClient* m_client; + FileManager* m_fileManager; }; #endif // AST_ACTION_FACTORY diff --git a/src/lib/data/parser/cxx/ASTConsumer.cpp b/src/lib/data/parser/cxx/ASTConsumer.cpp index 381a2a1d..eafe7c26 100644 --- a/src/lib/data/parser/cxx/ASTConsumer.cpp +++ b/src/lib/data/parser/cxx/ASTConsumer.cpp @@ -2,8 +2,8 @@ #include "data/parser/ParserClient.h" -ASTConsumer::ASTConsumer(clang::ASTContext* context, ParserClient* client) - : m_visitor(context, client) +ASTConsumer::ASTConsumer(clang::ASTContext* context, ParserClient* client, FileManager* fileManager) + : m_visitor(context, client, fileManager) { } diff --git a/src/lib/data/parser/cxx/ASTConsumer.h b/src/lib/data/parser/cxx/ASTConsumer.h index 5d5cbc85..e930e18a 100644 --- a/src/lib/data/parser/cxx/ASTConsumer.h +++ b/src/lib/data/parser/cxx/ASTConsumer.h @@ -5,11 +5,12 @@ #include "clang/AST/ASTContext.h" #include "data/parser/cxx/ASTVisitor.h" +#include "utility/file/FileManager.h" class ASTConsumer : public clang::ASTConsumer { public: - explicit ASTConsumer(clang::ASTContext* context, ParserClient* client); + explicit ASTConsumer(clang::ASTContext* context, ParserClient* client, FileManager* fileManager); virtual ~ASTConsumer(); virtual void HandleTranslationUnit(clang::ASTContext& context); diff --git a/src/lib/data/parser/cxx/ASTVisitor.cpp b/src/lib/data/parser/cxx/ASTVisitor.cpp index cba0f003..d873ffd2 100644 --- a/src/lib/data/parser/cxx/ASTVisitor.cpp +++ b/src/lib/data/parser/cxx/ASTVisitor.cpp @@ -10,12 +10,14 @@ #include "data/parser/ParseTypeUsage.h" #include "data/parser/ParseVariable.h" #include "data/type/DataType.h" +#include "utility/file/FileSystem.h" #include "utility/logging/logging.h" #include "utility/utilityString.h" -ASTVisitor::ASTVisitor(clang::ASTContext* context, ParserClient* client) +ASTVisitor::ASTVisitor(clang::ASTContext* context, ParserClient* client, FileManager* fileManager) : m_context(context) , m_client(client) + , m_fileManager(fileManager) { } @@ -30,7 +32,7 @@ bool ASTVisitor::VisitStmt(const clang::Stmt* statement) bool ASTVisitor::VisitTypedefDecl(clang::TypedefDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { m_client->onTypedefParsed( getParseLocationForNamedDecl(declaration), @@ -45,7 +47,7 @@ bool ASTVisitor::VisitTypedefDecl(clang::TypedefDecl* declaration) bool ASTVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { if (declaration->isClass()) { @@ -94,7 +96,7 @@ bool ASTVisitor::VisitVarDecl(clang::VarDecl* declaration) return true; } - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { clang::AccessSpecifier access = declaration->getAccess(); @@ -126,7 +128,7 @@ bool ASTVisitor::VisitVarDecl(clang::VarDecl* declaration) bool ASTVisitor::VisitFieldDecl(clang::FieldDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { m_client->onFieldParsed( getParseLocationForNamedDecl(declaration), @@ -146,7 +148,7 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration) return true; } - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { m_client->onFunctionParsed( getParseLocationForNamedDecl(declaration), @@ -166,7 +168,7 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration) bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { ParserClient::AbstractionType abstraction = ParserClient::ABSTRACTION_NONE; if (declaration->isPure()) @@ -198,7 +200,7 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration) bool ASTVisitor::VisitCXXConstructorDecl(clang::CXXConstructorDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { for (clang::CXXConstructorDecl::init_const_iterator it = declaration->init_begin(); it != declaration->init_end(); it++) { @@ -232,7 +234,7 @@ bool ASTVisitor::VisitCXXConstructorDecl(clang::CXXConstructorDecl* declaration) bool ASTVisitor::VisitNamespaceDecl(clang::NamespaceDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { m_client->onNamespaceParsed( declaration->isAnonymousNamespace() ? ParseLocation() : getParseLocationForNamedDecl(declaration), @@ -245,7 +247,7 @@ bool ASTVisitor::VisitNamespaceDecl(clang::NamespaceDecl* declaration) bool ASTVisitor::VisitEnumDecl(clang::EnumDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { m_client->onEnumParsed( getParseLocationForNamedDecl(declaration), @@ -259,7 +261,7 @@ bool ASTVisitor::VisitEnumDecl(clang::EnumDecl* declaration) bool ASTVisitor::VisitEnumConstantDecl(clang::EnumConstantDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { m_client->onEnumFieldParsed( getParseLocation(declaration->getSourceRange()), @@ -283,14 +285,15 @@ bool ASTVisitor::VisitTemplateTypeParmDecl(clang::TemplateTypeParmDecl *declarat bool ASTVisitor::VisitClassTemplateDecl(clang::ClassTemplateDecl* declaration) { - if (hasValidLocation(declaration)) + std::vector rarchy = utility::getDeclNameHierarchy(declaration); + if (isLocatedInMainFile(declaration)) { std::vector templateRecordNameHierarchy = utility::getDeclNameHierarchy(declaration); clang::TemplateParameterList* parameterList = declaration->getTemplateParameters(); for (size_t i = 0; i < parameterList->size(); i++) { clang::NamedDecl* namedDecl = parameterList->getParam(i); - if (hasValidLocation(namedDecl)) + if (isLocatedInMainFile(namedDecl)) { m_client->onTemplateRecordParameterTypeParsed( getParseLocationForNamedDecl(namedDecl), @@ -303,27 +306,34 @@ bool ASTVisitor::VisitClassTemplateDecl(clang::ClassTemplateDecl* declaration) // for implicit template specializations we do not need a valid location of the original template class definition (since that file could be included) // handles explicit specializations and implicit specializations but no explicit partial specializations - for (clang::ClassTemplateDecl::spec_iterator it = declaration->specializations().begin(); - it != declaration->specializations().end(); it++ - ) + if (isLocatedInSourceFile(declaration)) { - clang::ClassTemplateSpecializationDecl* specializationDecl = *it; - - std::vector specializationParentNameHierarchy = utility::getTemplateSpecializationParentNameHierarchy(specializationDecl); - - ParserClient::RecordType specializedRecordType = specializationDecl->isStruct() ? ParserClient::RECORD_STRUCT : ParserClient::RECORD_CLASS; - std::vector specializedRecordNameHierarchy = utility::getDeclNameHierarchy(specializationDecl); - m_client->onTemplateRecordSpecializationParsed( - getParseLocationForNamedDecl(*it), specializedRecordNameHierarchy, specializedRecordType, specializationParentNameHierarchy - ); - - const clang::TemplateArgumentList &argList = specializationDecl->getTemplateArgs(); - for (int i = 0; i < argList.size(); i++) + for (clang::ClassTemplateDecl::spec_iterator it = declaration->specializations().begin(); + it != declaration->specializations().end(); it++ + ) { - std::vector argumentNameHierarchy = utility::templateArgumentToDataType(argList.get(i)).getTypeNameHierarchy(); - if (argumentNameHierarchy.size()) // FIXME: Some TemplateArgument kinds are not handled yet. + clang::ClassTemplateSpecializationDecl* specializationDecl = *it; + + std::vector specializationParentNameHierarchy = utility::getTemplateSpecializationParentNameHierarchy(specializationDecl); + + ParserClient::RecordType specializedRecordType = specializationDecl->isStruct() ? ParserClient::RECORD_STRUCT : ParserClient::RECORD_CLASS; + std::vector specializedRecordNameHierarchy = utility::getDeclNameHierarchy(specializationDecl); + m_client->onTemplateRecordSpecializationParsed( + getParseLocationForNamedDecl(*it), specializedRecordNameHierarchy, specializedRecordType, specializationParentNameHierarchy + ); + + const clang::TemplateArgumentList &argList = specializationDecl->getTemplateArgs(); + for (int i = 0; i < argList.size(); i++) { - m_client->onTemplateRecordArgumentTypeParsed(ParseLocation(), argumentNameHierarchy, specializedRecordNameHierarchy); // TODO: What about the ParseLocation + std::vector argumentNameHierarchy = utility::templateArgumentToDataType(argList.get(i)).getTypeNameHierarchy(); + if (argumentNameHierarchy.size()) // FIXME: Some TemplateArgument kinds are not handled yet. + { + m_client->onTemplateRecordArgumentTypeParsed( + ParseLocation(), // TODO: Find a valid ParseLocation here! + argumentNameHierarchy, + specializedRecordNameHierarchy + ); + } } } } @@ -332,7 +342,7 @@ bool ASTVisitor::VisitClassTemplateDecl(clang::ClassTemplateDecl* declaration) bool ASTVisitor::VisitClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl* declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { std::vector specializedRecordNameHierarchy = utility::getDeclNameHierarchy(declaration); std::vector specializationParentNameHierarchy = utility::getTemplateSpecializationParentNameHierarchy(declaration); @@ -346,7 +356,7 @@ bool ASTVisitor::VisitClassTemplatePartialSpecializationDecl(clang::ClassTemplat for (size_t i = 0; i < parameterList->size(); i++) { clang::NamedDecl* namedDecl = parameterList->getParam(i); - if (hasValidLocation(namedDecl)) + if (isLocatedInMainFile(namedDecl)) { m_client->onTemplateRecordParameterTypeParsed( getParseLocationForNamedDecl(namedDecl), @@ -373,7 +383,7 @@ bool ASTVisitor::VisitClassTemplatePartialSpecializationDecl(clang::ClassTemplat bool ASTVisitor::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *declaration) { - if (hasValidLocation(declaration)) + if (isLocatedInMainFile(declaration)) { const ParseFunction templateFunction = getParseFunction(declaration->getTemplatedDecl()); for (clang::FunctionTemplateDecl::spec_iterator it = declaration->specializations().begin(); it != declaration->specializations().end(); it++) @@ -393,7 +403,7 @@ bool ASTVisitor::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *declarat { clang::NamedDecl* namedDecl = parameterList->getParam(i); - if (hasValidLocation(namedDecl)) + if (isLocatedInMainFile(namedDecl)) { std::string templateParameterTypeName = namedDecl->getNameAsString(); @@ -604,12 +614,24 @@ void ASTVisitor::VisitVarDeclInDeclBody(clang::FunctionDecl* decl, clang::VarDec ); } -bool ASTVisitor::hasValidLocation(const clang::Decl* declaration) const +bool ASTVisitor::isLocatedInMainFile(const clang::Decl* declaration) const { const clang::SourceLocation& location = declaration->getLocStart(); return location.isValid() && m_context->getSourceManager().isWrittenInMainFile(location); } +bool ASTVisitor::isLocatedInSourceFile(const clang::Decl* declaration) const +{ + const clang::SourceLocation& location = declaration->getLocStart(); + if (location.isValid()) + { + const clang::SourceManager& sourceManager = m_context->getSourceManager(); + std::string filePath = FileSystem::absoluteFilePath(sourceManager.getFilename(location)); + return m_fileManager->hasFilePath(filePath); + } + return false; +} + ParserClient::AccessType ASTVisitor::convertAccessType(clang::AccessSpecifier access) const { switch (access) diff --git a/src/lib/data/parser/cxx/ASTVisitor.h b/src/lib/data/parser/cxx/ASTVisitor.h index f4ca6361..dd3951ea 100644 --- a/src/lib/data/parser/cxx/ASTVisitor.h +++ b/src/lib/data/parser/cxx/ASTVisitor.h @@ -6,13 +6,14 @@ #include "data/parser/cxx/ASTBodyVisitorClient.h" #include "data/parser/ParserClient.h" +#include "utility/file/FileManager.h" class ASTVisitor : public clang::RecursiveASTVisitor , public ASTBodyVisitorClient { public: - ASTVisitor(clang::ASTContext* context, ParserClient* client); + ASTVisitor(clang::ASTContext* context, ParserClient* client, FileManager* fileManager); virtual ~ASTVisitor(); // Left for debugging purposes. Uncomment to see a colored ast-dump of the parsed file. @@ -56,7 +57,8 @@ public: virtual void VisitVarDeclInDeclBody(clang::FunctionDecl* decl, clang::VarDecl* varDecl); // type usages private: - bool hasValidLocation(const clang::Decl* declaration) const; + bool isLocatedInMainFile(const clang::Decl* declaration) const; + bool isLocatedInSourceFile(const clang::Decl* declaration) const; ParserClient::AccessType convertAccessType(clang::AccessSpecifier) const; ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const; @@ -74,6 +76,7 @@ private: clang::ASTContext* m_context; ParserClient* m_client; + FileManager* m_fileManager; }; #endif // AST_VISITOR_H diff --git a/src/lib/data/parser/cxx/CxxParser.cpp b/src/lib/data/parser/cxx/CxxParser.cpp index 49bc76a4..b87c9778 100644 --- a/src/lib/data/parser/cxx/CxxParser.cpp +++ b/src/lib/data/parser/cxx/CxxParser.cpp @@ -49,8 +49,9 @@ static bool runToolOnCodeWithArgs( } -CxxParser::CxxParser(ParserClient* client) +CxxParser::CxxParser(ParserClient* client, FileManager* fileManager) : Parser(client) + , m_fileManager(fileManager) { } @@ -117,7 +118,7 @@ void CxxParser::parseFiles( CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client); tool.setDiagnosticConsumer(&reporter); - ASTActionFactory actionFactory(m_client); + ASTActionFactory actionFactory(m_client, m_fileManager); tool.run(&actionFactory); } @@ -129,6 +130,6 @@ void CxxParser::parseFile(std::shared_ptr textAccess) llvm::IntrusiveRefCntPtr options = new clang::DiagnosticOptions(); CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, false); - ASTActionFactory actionFactory(m_client); + ASTActionFactory actionFactory(m_client, m_fileManager); runToolOnCodeWithArgs(&reporter, actionFactory.create(), textAccess->getText(), args); } diff --git a/src/lib/data/parser/cxx/CxxParser.h b/src/lib/data/parser/cxx/CxxParser.h index 1853e846..931a2284 100644 --- a/src/lib/data/parser/cxx/CxxParser.h +++ b/src/lib/data/parser/cxx/CxxParser.h @@ -2,11 +2,12 @@ #define CXX_PARSER_H #include "data/parser/Parser.h" +#include "utility/file/FileManager.h" class CxxParser: public Parser { public: - CxxParser(ParserClient* client); + CxxParser(ParserClient* client, FileManager* fileManager); ~CxxParser(); virtual void parseFiles( @@ -14,6 +15,9 @@ public: const std::vector& systemHeaderSearchPaths, const std::vector& headerSearchPaths); virtual void parseFile(std::shared_ptr textAccess); + +private: + FileManager* m_fileManager; }; #endif // CXX_PARSER_H diff --git a/src/lib/utility/file/FileInfo.cpp b/src/lib/utility/file/FileInfo.cpp new file mode 100644 index 00000000..7a0d5ce6 --- /dev/null +++ b/src/lib/utility/file/FileInfo.cpp @@ -0,0 +1,7 @@ +#include "FileInfo.h" + +FileInfo::FileInfo(std::string path, boost::posix_time::ptime lastWriteTime) + : path(path) + , lastWriteTime(lastWriteTime) +{ +} diff --git a/src/lib/utility/file/FileInfo.h b/src/lib/utility/file/FileInfo.h new file mode 100644 index 00000000..1dd06f21 --- /dev/null +++ b/src/lib/utility/file/FileInfo.h @@ -0,0 +1,15 @@ +#ifndef FILE_INFO_H +#define FILE_INFO_H + +#include +#include "boost/date_time.hpp" + +struct FileInfo +{ + FileInfo(std::string path, boost::posix_time::ptime lastWriteTime); + + std::string path; + boost::posix_time::ptime lastWriteTime; +}; + +#endif // FILE_INFO_H diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp new file mode 100644 index 00000000..6b3f9f3d --- /dev/null +++ b/src/lib/utility/file/FileManager.cpp @@ -0,0 +1,99 @@ +#include "utility/file/FileManager.h" + +#include +#include + +#include "utility/file/FileSystem.h" +#include "ProjectSettings.h" + +FileManager::FileManager( + std::vector sourcePaths, + std::vector includePaths, + std::vector sourceExtensions, + std::vector includeExtensions +) + : m_sourcePaths(sourcePaths) + , m_includePaths(includePaths) + , m_sourceExtensions(sourceExtensions) + , m_includeExtensions(includeExtensions) +{ +} + +FileManager::~FileManager() +{ +} + +void FileManager::reset() +{ + m_files.clear(); + m_addedFiles.clear(); + m_updatedFiles.clear(); + m_removedFiles.clear(); +} + +void FileManager::fetchFilePaths() +{ + m_addedFiles.clear(); + m_updatedFiles.clear(); + m_removedFiles.clear(); + + std::set removedFileNames; + for (std::map::iterator it = m_files.begin(); it != m_files.end(); it++) + { + removedFileNames.insert(it->first); + } + + std::vector, std::vector>> pathsExtensionsPairs; + pathsExtensionsPairs.push_back(std::make_pair(m_includePaths, m_includeExtensions)); + pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_sourceExtensions)); + + for (int i = 0; i < pathsExtensionsPairs.size(); i++) + { + std::vector fileInfos = FileSystem::getFileInfosFromDirectoryPaths(pathsExtensionsPairs[i].first, pathsExtensionsPairs[i].second); + for (FileInfo fileInfo: fileInfos) + { + const std::string& filePath = fileInfo.path; + std::map::iterator it = m_files.find(filePath); + if (it != m_files.end()) + { + removedFileNames.erase(filePath); + if (fileInfo.lastWriteTime > it->second.lastWriteTime) + { + it->second.lastWriteTime = fileInfo.lastWriteTime; + m_updatedFiles.push_back(filePath); + } + } + else + { + m_files.insert(std::pair(filePath, fileInfo)); + m_addedFiles.push_back(filePath); + } + } + } + + for (std::set::iterator it = removedFileNames.begin(); it != removedFileNames.end(); it++) + { + m_files.erase(it->data()); + m_removedFiles.push_back(it->data()); + } +} + +std::vector FileManager::getAddedFilePaths() const +{ + return m_addedFiles; +} + +std::vector FileManager::getUpdatedFilePaths() const +{ + return m_updatedFiles; +} + +std::vector FileManager::getRemovedFilePaths() const +{ + return m_removedFiles; +} + +bool FileManager::hasFilePath(const std::string& filePath) const +{ + return (m_files.find(filePath) != m_files.end()); +} diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h new file mode 100644 index 00000000..aa715a10 --- /dev/null +++ b/src/lib/utility/file/FileManager.h @@ -0,0 +1,40 @@ +#ifndef FILE_MANAGER_H +#define FILE_MANAGER_H + +#include +#include + +#include "FileInfo.h" + +class FileManager +{ +public: + FileManager( + std::vector sourcePaths, + std::vector includePaths, + std::vector sourceExtensions, + std::vector includeExtensions + ); + ~FileManager(); + + void reset(); + void fetchFilePaths(); + std::vector getAddedFilePaths() const; + std::vector getUpdatedFilePaths() const; + std::vector getRemovedFilePaths() const; + + virtual bool hasFilePath(const std::string& filePath) const; + +private: + std::vector m_sourcePaths; + std::vector m_includePaths; + std::vector m_sourceExtensions; + std::vector m_includeExtensions; + + std::map m_files; + std::vector m_addedFiles; + std::vector m_updatedFiles; + std::vector m_removedFiles; +}; + +#endif // FILE_MANAGER_H diff --git a/src/lib/utility/FileSystem.cpp b/src/lib/utility/file/FileSystem.cpp similarity index 76% rename from src/lib/utility/FileSystem.cpp rename to src/lib/utility/file/FileSystem.cpp index a9aebc7a..fcc3f49a 100644 --- a/src/lib/utility/FileSystem.cpp +++ b/src/lib/utility/file/FileSystem.cpp @@ -1,4 +1,4 @@ -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" #include "boost/date_time.hpp" #include "boost/filesystem.hpp" @@ -53,6 +53,31 @@ std::vector FileSystem::getFileNamesFromDirectoryUpdatedAfter( return files; } +std::vector FileSystem::getFileInfosFromDirectoryPaths( + const std::vector& directoryPaths, const std::vector& fileExtensions) +{ + std::vector files; + for (const std::string& directoryPath: directoryPaths) + { + if (boost::filesystem::is_directory(directoryPath)) + { + boost::filesystem::recursive_directory_iterator it(directoryPath); + boost::filesystem::recursive_directory_iterator endit; + while (it != endit) + { + if (boost::filesystem::is_regular_file(*it) && isValidExtension(it->path().string(), fileExtensions)) + { + std::time_t t = boost::filesystem::last_write_time(*it); + boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t); + files.push_back(FileInfo(absoluteFilePath(it->path().generic_string()), lastWriteTime)); + } + ++it; + } + } + } + return files; +} + std::string FileSystem::getTimeStringNow() { return boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time()); diff --git a/src/lib/utility/FileSystem.h b/src/lib/utility/file/FileSystem.h similarity index 83% rename from src/lib/utility/FileSystem.h rename to src/lib/utility/file/FileSystem.h index 9d1cf468..f3c4935e 100644 --- a/src/lib/utility/FileSystem.h +++ b/src/lib/utility/file/FileSystem.h @@ -4,6 +4,8 @@ #include #include +#include "utility/file/FileInfo.h" + class FileSystem { public: @@ -12,6 +14,9 @@ public: static std::vector getFileNamesFromDirectoryUpdatedAfter( const std::string& path, const std::vector& extensions, const std::string& timeString); + static std::vector getFileInfosFromDirectoryPaths( + const std::vector& directoryPaths, const std::vector& fileExtensions); + static std::string getTimeStringNow(); static bool exists(const std::string& path); diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 6dda2dce..dc28570e 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,16 +1,19 @@ add_files( TEST_FILES + helper/TestFileManager.cpp + helper/TestFileManager.h + helper/TestStorage.cpp + helper/TestStorage.h + TestSuiteFixture.cpp TestSuiteFixture.h - TestStorage.cpp - TestStorage.h - ConfigManagerTestSuite.h CxxParserTestSuite.h DataTypeTestSuite.h DictionaryTestSuite.h + FileManagerTestSuite.h FileSystemTestSuite.h GraphTestSuite.h GraphFilterTestSuite.h diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index a8caf8b9..2c79b3bd 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -9,6 +9,8 @@ #include "utility/text/TextAccess.h" #include "utility/utilityString.h" +#include "helper/TestFileManager.h" + class CxxParserTestSuite: public CxxTest::TestSuite { public: @@ -1531,8 +1533,9 @@ public: void test_cxx_parser_parses_multiple_files() { + TestFileManager fm; TestParserClient client; - CxxParser parser(&client); + CxxParser parser(&client, &fm); std::vector filePaths; filePaths.push_back("data/CxxParserTestSuite/header.h"); @@ -1839,8 +1842,9 @@ private: std::shared_ptr parseCode(std::string code) const { + TestFileManager fm; std::shared_ptr client = std::make_shared(); - CxxParser parser(client.get()); + CxxParser parser(client.get(), &fm); parser.parseFile(TextAccess::createFromString(code)); return client; } diff --git a/src/test/FileManagerTestSuite.h b/src/test/FileManagerTestSuite.h new file mode 100644 index 00000000..ca9e93c0 --- /dev/null +++ b/src/test/FileManagerTestSuite.h @@ -0,0 +1,110 @@ +#include "cxxtest/TestSuite.h" + +#include "utility/file/FileManager.h" + +class FileManagerTestSuite : public CxxTest::TestSuite +{ +public: + void test_file_manager_is_created_empty() + { + std::vector sourcePaths; + sourcePaths.push_back("./data/FileManagerTestSuite/src/"); + std::vector includePaths; + includePaths.push_back("./data/FileManagerTestSuite/include/"); + std::vector sourceExtensions; + sourceExtensions.push_back(".cpp"); + sourceExtensions.push_back(".c"); + std::vector includeExtensions; + includeExtensions.push_back(".hpp"); + includeExtensions.push_back(".h"); + + FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions); + + std::vector addedFilePaths = fm.getAddedFilePaths(); + std::vector updatedFilePaths = fm.getUpdatedFilePaths(); + std::vector removedFilePaths = fm.getRemovedFilePaths(); + + TS_ASSERT_EQUALS(addedFilePaths.size(), 0); + TS_ASSERT_EQUALS(updatedFilePaths.size(), 0); + TS_ASSERT_EQUALS(removedFilePaths.size(), 0); + } + + void test_file_manager_has_added_file_paths_after_first_fetch() + { + std::vector sourcePaths; + sourcePaths.push_back("./data/FileManagerTestSuite/src/"); + std::vector includePaths; + includePaths.push_back("./data/FileManagerTestSuite/include/"); + std::vector sourceExtensions; + sourceExtensions.push_back(".cpp"); + sourceExtensions.push_back(".c"); + std::vector includeExtensions; + includeExtensions.push_back(".hpp"); + includeExtensions.push_back(".h"); + + FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions); + fm.fetchFilePaths(); + + std::vector addedFilePaths = fm.getAddedFilePaths(); + std::vector updatedFilePaths = fm.getUpdatedFilePaths(); + std::vector removedFilePaths = fm.getRemovedFilePaths(); + + TS_ASSERT_EQUALS(addedFilePaths.size(), 4); + } + + void test_file_manager_has_no_added_file_paths_after_second_fetch() + { + std::vector sourcePaths; + sourcePaths.push_back("./data/FileManagerTestSuite/src/"); + std::vector includePaths; + includePaths.push_back("./data/FileManagerTestSuite/include/"); + std::vector sourceExtensions; + sourceExtensions.push_back(".cpp"); + sourceExtensions.push_back(".c"); + std::vector includeExtensions; + includeExtensions.push_back(".hpp"); + includeExtensions.push_back(".h"); + + FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions); + fm.fetchFilePaths(); + fm.fetchFilePaths(); + + std::vector addedFilePaths = fm.getAddedFilePaths(); + std::vector updatedFilePaths = fm.getUpdatedFilePaths(); + std::vector removedFilePaths = fm.getRemovedFilePaths(); + + TS_ASSERT_EQUALS(addedFilePaths.size(), 0); + } + + void test_file_manager_has_updated_file_paths_after_second_fetch() + { + std::vector sourcePaths; + sourcePaths.push_back("./data/FileManagerTestSuite/src/"); + std::vector includePaths; + includePaths.push_back("./data/FileManagerTestSuite/include/"); + std::vector sourceExtensions; + sourceExtensions.push_back(".cpp"); + sourceExtensions.push_back(".c"); + std::vector includeExtensions; + includeExtensions.push_back(".hpp"); + includeExtensions.push_back(".h"); + + FileManager fm = FileManager(sourcePaths, includePaths, sourceExtensions, includeExtensions); + fm.fetchFilePaths(); + + std::fstream fileStream; + fileStream.open("./data/FileManagerTestSuite/include/c.h"); + fileStream << "update"; + fileStream.close(); + + fm.fetchFilePaths(); + + std::vector addedFilePaths = fm.getAddedFilePaths(); + std::vector updatedFilePaths = fm.getUpdatedFilePaths(); + std::vector removedFilePaths = fm.getRemovedFilePaths(); + + TS_ASSERT_EQUALS(addedFilePaths.size(), 0); + TS_ASSERT_EQUALS(updatedFilePaths.size(), 1); + TS_ASSERT_EQUALS(removedFilePaths.size(), 0); + } +}; diff --git a/src/test/FileSystemTestSuite.h b/src/test/FileSystemTestSuite.h index 4fe22477..2b9411dc 100644 --- a/src/test/FileSystemTestSuite.h +++ b/src/test/FileSystemTestSuite.h @@ -5,7 +5,7 @@ #include #include -#include "utility/FileSystem.h" +#include "utility/file/FileSystem.h" class FileSystemTestSuite : public CxxTest::TestSuite { @@ -71,6 +71,22 @@ public: TS_ASSERT_EQUALS(sourceFiles[0], "data/FileSystemTestSuite/update.c"); } + void test_find_file_infos() + { + std::vector extensions; + extensions.push_back(".h"); + extensions.push_back(".hpp"); + extensions.push_back(".cpp"); + + std::vector directoryPaths; + directoryPaths.push_back("./data/FileSystemTestSuite"); + + std::vector files = + FileSystem::getFileInfosFromDirectoryPaths(directoryPaths, extensions); + + TS_ASSERT_EQUALS(files.size(), 5); + } + void test_filesystem_finds_existing_files() { TS_ASSERT(FileSystem::exists("data/FileSystemTestSuite")); diff --git a/src/test/GraphFilterConductorTestSuite.h b/src/test/GraphFilterConductorTestSuite.h index 3d6f58cd..14b9bf9b 100644 --- a/src/test/GraphFilterConductorTestSuite.h +++ b/src/test/GraphFilterConductorTestSuite.h @@ -2,7 +2,8 @@ #include "data/graph/filter/GraphFilterConductor.h" #include "data/query/QueryTree.h" -#include "TestStorage.h" + +#include "helper/TestStorage.h" class GraphFilterConductorTestSuite : public CxxTest::TestSuite { diff --git a/src/test/GraphFilterTestSuite.h b/src/test/GraphFilterTestSuite.h index 7fa96305..43f445fe 100644 --- a/src/test/GraphFilterTestSuite.h +++ b/src/test/GraphFilterTestSuite.h @@ -2,7 +2,8 @@ #include "data/graph/filter/GraphFilter.h" #include "data/graph/filter/GraphFilterImplementations.h" -#include "TestStorage.h" + +#include "helper/TestStorage.h" class GraphFilterTestSuite : public CxxTest::TestSuite { diff --git a/src/test/helper/TestFileManager.cpp b/src/test/helper/TestFileManager.cpp new file mode 100644 index 00000000..2673d44b --- /dev/null +++ b/src/test/helper/TestFileManager.cpp @@ -0,0 +1,16 @@ +#include "TestFileManager.h" + +TestFileManager::TestFileManager() + : FileManager( + std::vector(), + std::vector(), + std::vector(), + std::vector() + ) +{ +} + +bool TestFileManager::hasFilePath(const std::string& filePath) const +{ + return true; +} diff --git a/src/test/helper/TestFileManager.h b/src/test/helper/TestFileManager.h new file mode 100644 index 00000000..194cc4f9 --- /dev/null +++ b/src/test/helper/TestFileManager.h @@ -0,0 +1,13 @@ +#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 std::string& filePath) const; +}; + +#endif // TEST_FILE_MANAGER_H diff --git a/src/test/TestStorage.cpp b/src/test/helper/TestStorage.cpp similarity index 78% rename from src/test/TestStorage.cpp rename to src/test/helper/TestStorage.cpp index a9a8a52a..f6c25678 100644 --- a/src/test/TestStorage.cpp +++ b/src/test/helper/TestStorage.cpp @@ -2,11 +2,13 @@ #include "utility/text/TextAccess.h" #include "data/parser/cxx/CxxParser.h" +#include "TestFileManager.h" void TestStorage::parseCxxCode(std::string code) { clear(); - CxxParser parser(this); + TestFileManager fm; + CxxParser parser(this, &fm); parser.parseFile(TextAccess::createFromString(code)); } diff --git a/src/test/TestStorage.h b/src/test/helper/TestStorage.h similarity index 100% rename from src/test/TestStorage.h rename to src/test/helper/TestStorage.h