diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 63238362..d0ed54dc 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -198,7 +198,7 @@ Parser::Arguments Project::getParserArguments() const utility::append(args.systemHeaderSearchPaths, projSettings->getAbsoluteHeaderSearchPaths()); - utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPaths()); + utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded()); // Add all subdirectories of the header search paths if (projSettings->getUseSourcePathsForHeaderSearch()) @@ -215,7 +215,7 @@ Parser::Arguments Project::getParserArguments() const } utility::append(args.frameworkSearchPaths, projSettings->getAbsoluteFrameworkSearchPaths()); - utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPaths()); + utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded()); args.language = projSettings->getLanguage(); args.languageStandard = projSettings->getStandard(); diff --git a/src/lib/data/parser/ParserClientImpl.cpp b/src/lib/data/parser/ParserClientImpl.cpp index 50f03fbd..27bd9830 100644 --- a/src/lib/data/parser/ParserClientImpl.cpp +++ b/src/lib/data/parser/ParserClientImpl.cpp @@ -431,7 +431,7 @@ Id ParserClientImpl::onCommentParsed(const ParseLocation& location) // TODO: mov { log("comment", "no name", location); - Id fileNodeId = addFile(location.filePath.str()); + addFile(location.filePath.str()); addCommentLocation(location); return 0; @@ -475,7 +475,6 @@ Id ParserClientImpl::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nam } Id parentNodeId = 0; - bool nodeMayExist = true; NameHierarchy currentNameHierarchy; for (size_t i = 0; i < nameHierarchy.size(); i++) diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index cadf3b54..b2db77fa 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -28,6 +28,13 @@ std::vector ApplicationSettings::getHeaderSearchPaths() const return getPathValues("source/header_search_paths/header_search_path"); } +std::vector ApplicationSettings::getHeaderSearchPathsExpanded() const +{ + std::vector paths = getPathValues("source/header_search_paths/header_search_path"); + expandPaths(paths); + return paths; +} + bool ApplicationSettings::setHeaderSearchPaths(const std::vector& headerSearchPaths) { return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths); @@ -38,6 +45,13 @@ std::vector ApplicationSettings::getFrameworkSearchPaths() const return getPathValues("source/framework_search_paths/framework_search_path"); } +std::vector ApplicationSettings::getFrameworkSearchPathsExpanded() const +{ + std::vector paths = getPathValues("source/framework_search_paths/framework_search_path"); + expandPaths(paths); + return paths; +} + bool ApplicationSettings::setFrameworkSearchPaths(const std::vector& frameworkSearchPaths) { return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths); diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index c15039df..71d18981 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -16,9 +16,11 @@ public: // source std::vector getHeaderSearchPaths() const; + std::vector getHeaderSearchPathsExpanded() const; bool setHeaderSearchPaths(const std::vector& headerSearchPaths); std::vector getFrameworkSearchPaths() const; + std::vector getFrameworkSearchPathsExpanded() const; bool setFrameworkSearchPaths(const std::vector& frameworkSearchPaths); std::vector getCompilerFlags() const; diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index ca5c0644..9ec0839c 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -93,6 +93,7 @@ std::vector ProjectSettings::getSourcePaths() const std::vector ProjectSettings::getAbsoluteSourcePaths() const { std::vector paths = getSourcePaths(); + expandPaths(paths); makePathsAbsolute(paths); return paths; } @@ -110,6 +111,7 @@ std::vector ProjectSettings::getHeaderSearchPaths() const std::vector ProjectSettings::getAbsoluteHeaderSearchPaths() const { std::vector paths = getHeaderSearchPaths(); + expandPaths(paths); makePathsAbsolute(paths); return paths; } @@ -127,6 +129,7 @@ std::vector ProjectSettings::getFrameworkSearchPaths() const std::vector ProjectSettings::getAbsoluteFrameworkSearchPaths() const { std::vector paths = getFrameworkSearchPaths(); + expandPaths(paths); makePathsAbsolute(paths); return paths; } @@ -242,7 +245,6 @@ void ProjectSettings::makePathsAbsolute(std::vector& paths) const FilePath basePath = getFilePath().parentDirectory(); for (size_t i = 0; i < paths.size(); i++) { - paths[i] = paths[i].expandEnvironmentVariables(); if (!paths[i].isAbsolute()) { paths[i] = basePath.concat(paths[i]).canonical(); diff --git a/src/lib/settings/Settings.cpp b/src/lib/settings/Settings.cpp index 5f3beec9..43803967 100644 --- a/src/lib/settings/Settings.cpp +++ b/src/lib/settings/Settings.cpp @@ -102,6 +102,14 @@ std::vector Settings::getPathValues(const std::string& key) const return paths; } +void Settings::expandPaths(std::vector& paths) const +{ + for (FilePath& path : paths) + { + path = path.expandEnvironmentVariables(); + } +} + bool Settings::setPathValues(const std::string& key, const std::vector& paths) { std::vector values; diff --git a/src/lib/settings/Settings.h b/src/lib/settings/Settings.h index 99108044..68290339 100644 --- a/src/lib/settings/Settings.h +++ b/src/lib/settings/Settings.h @@ -34,6 +34,7 @@ protected: std::vector getValues(const std::string& key, std::vector defaultValues) const; std::vector getPathValues(const std::string& key) const; + void expandPaths(std::vector& paths) const; template bool setValue(const std::string& key, T value); diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index 562d9b17..eb2f613d 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -26,14 +26,8 @@ void FileManager::setPaths( std::vector sourceExtensions, std::vector includeExtensions ){ - for ( FilePath path : sourcePaths ) - { - m_sourcePaths.push_back(path.expandEnvironmentVariables()); - } - for ( FilePath path : headerPaths ) - { - m_headerPaths.push_back(path.expandEnvironmentVariables()); - } + m_sourcePaths = sourcePaths; + m_headerPaths = headerPaths; m_sourceExtensions = sourceExtensions; m_includeExtensions = includeExtensions; } diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index bc6da114..fdca6e8c 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -1,32 +1,34 @@ #include "utility/file/FilePath.h" #include + #include "utility/logging/logging.h" FilePath::FilePath() : m_exists(false) + , m_checkedExists(false) { } FilePath::FilePath(const char* filePath) : m_path(filePath) , m_exists(false) + , m_checkedExists(false) { - init(); } FilePath::FilePath(const std::string& filePath) : m_path(filePath) , m_exists(false) + , m_checkedExists(false) { - init(); } FilePath::FilePath(const boost::filesystem::path& filePath) : m_path(filePath) , m_exists(false) + , m_checkedExists(false) { - init(); } boost::filesystem::path FilePath::path() const @@ -41,6 +43,12 @@ bool FilePath::empty() const bool FilePath::exists() const { + if (!m_checkedExists) + { + m_exists = boost::filesystem::exists(m_path); + m_checkedExists = true; + } + return m_exists; } @@ -103,25 +111,22 @@ FilePath FilePath::canonical() const FilePath FilePath::expandEnvironmentVariables() const { - return FilePath(expandEnvironmentVariables(str())); -} + std::string text = str(); -std::string FilePath::expandEnvironmentVariables(const std::string& path) const -{ - std::string text = path; - - static std::regex env( "\\$\\{([^}]+)\\}|%([0-9A-Za-z\\/]*)%" ); + static std::regex env("\\$\\{([^}]+)\\}|%([0-9A-Za-z\\/]*)%"); std::smatch match; - while ( std::regex_search( text, match, env ) ) { - const char * s = getenv( match[1].str().c_str() ); + while (std::regex_search(text, match, env)) + { + const char * s = getenv(match[1].str().c_str()); if (s == nullptr) { LOG_ERROR(match[1].str() + " is no a environment variable"); - return path; + return FilePath(); } text.replace( match[0].first, match[0].second, s); } - return text; + + return FilePath(text); } FilePath FilePath::relativeTo(const FilePath& other) const @@ -188,7 +193,7 @@ FilePath FilePath::withoutExtension() const return FilePath(boost::filesystem::path(m_path).replace_extension()); } -FilePath FilePath::replaceExtension(const std::string& extension) +FilePath FilePath::replaceExtension(const std::string& extension) const { return FilePath(boost::filesystem::path(m_path).replace_extension(extension)); } @@ -225,12 +230,3 @@ bool FilePath::operator<(const FilePath& other) const { return m_path.compare(other.m_path) < 0; } - -void FilePath::init() -{ - boost::filesystem::path p(expandEnvironmentVariables(m_path.generic_string())); - if (boost::filesystem::exists(p)) - { - m_exists = true; - } -} diff --git a/src/lib/utility/file/FilePath.h b/src/lib/utility/file/FilePath.h index b0381a4c..c6b959d5 100644 --- a/src/lib/utility/file/FilePath.h +++ b/src/lib/utility/file/FilePath.h @@ -27,14 +27,13 @@ public: FilePath relativeTo(const FilePath& other) const; FilePath concat(const FilePath& other) const; FilePath expandEnvironmentVariables() const; - std::string expandEnvironmentVariables(const std::string & path) const; std::string str() const; std::string fileName() const; std::string extension() const; FilePath withoutExtension() const; - FilePath replaceExtension(const std::string& extension); + FilePath replaceExtension(const std::string& extension) const; bool hasExtension(const std::vector& extensions) const; bool operator==(const FilePath& other) const; @@ -42,10 +41,10 @@ public: bool operator<(const FilePath& other) const; private: - void init(); - boost::filesystem::path m_path; - bool m_exists; + + mutable bool m_exists; + mutable bool m_checkedExists; }; #endif // FILE_PATH_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 724028e5..49e250f8 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -92,6 +92,34 @@ QSize QtProjectWizzardContentPaths::preferredWindowSize() const return QSize(750, 500); } +bool QtProjectWizzardContentPaths::check() +{ + QString missingPaths; + for (FilePath f : m_list->getList()) + { + f = f.expandEnvironmentVariables(); + + if (!f.exists()) + { + if (!missingPaths.isEmpty()) + { + missingPaths.append("\n"); + } + missingPaths.append(f.str().c_str()); + } + + if (!missingPaths.isEmpty()) + { + QMessageBox msgBox; + msgBox.setText("These paths do not exist:\n" + missingPaths); + msgBox.exec(); + return false; + } + } + + return true; +} + void QtProjectWizzardContentPaths::setInfo(const QString& title, const QString& description, const QString& help) { m_titleString = title; @@ -208,27 +236,8 @@ bool QtProjectWizzardContentPathsSource::check() msgBox.exec(); return false; } - QString missingPaths; - for(FilePath f : m_list->getList()) - { - if(!f.exists()) - { - if(!missingPaths.isEmpty()) - { - missingPaths.append("\n"); - } - missingPaths.append(f.expandEnvironmentVariables().str().c_str()); - } - if(!missingPaths.isEmpty()) - { - QMessageBox msgBox; - msgBox.setText("The following paths do not exist:\n" + missingPaths ); - msgBox.exec(); - return false; - } - } - return true; + return QtProjectWizzardContentPaths::check(); } QStringList QtProjectWizzardContentPathsSource::getFileNames() const @@ -309,11 +318,6 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader( ); } -bool QtProjectWizzardContentPathsCDBHeader::check() -{ - return true; -} - QStringList QtProjectWizzardContentPathsCDBHeader::getFileNames() const { return getSourceFileNames(true); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index 375a96b4..fe019301 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -26,6 +26,8 @@ public: virtual QSize preferredWindowSize() const override; + virtual bool check() override; + protected: void setInfo(const QString& title, const QString& description, const QString& help); void setTitleString(const QString& title); @@ -86,8 +88,6 @@ public: QtProjectWizzardContentPathsCDBHeader(ProjectSettings* settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation - virtual bool check() override; - virtual QStringList getFileNames() const override; virtual QString getFileNamesTitle() const override; virtual QString getFileNamesDescription() const override; diff --git a/src/lib_parser/data/parser/cxx/ASTVisitor.cpp b/src/lib_parser/data/parser/cxx/ASTVisitor.cpp index 7c167a47..3c74b727 100644 --- a/src/lib_parser/data/parser/cxx/ASTVisitor.cpp +++ b/src/lib_parser/data/parser/cxx/ASTVisitor.cpp @@ -991,10 +991,10 @@ bool ASTVisitor::VisitTypeLoc(clang::TypeLoc tl) /////////////////////////////////////////////////////////////////////////////// // Reference recording -static inline bool isNamedDeclUnnamed(clang::NamedDecl *d) -{ - return d->getDeclName().isIdentifier() && d->getIdentifier() == NULL; -} +// static inline bool isNamedDeclUnnamed(clang::NamedDecl *d) +// { +// return d->getDeclName().isIdentifier() && d->getIdentifier() == NULL; +// } ParseLocation ASTVisitor::getDeclRefRange(clang::NamedDecl *decl, clang::SourceLocation loc) {