From b17a3472ad103b246afcef4f5ab48aa797559338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Thu, 23 May 2024 17:55:17 +0200 Subject: [PATCH] Path: removed deprecated functions / renamed `isHeader2()` to `isHeader()` (#6427) --- cli/cmdlineparser.cpp | 2 +- gui/resultstree.cpp | 2 +- gui/resultsview.cpp | 2 +- lib/path.cpp | 34 +------------- lib/path.h | 26 +---------- test/testpath.cpp | 105 ++++++------------------------------------ 6 files changed, 18 insertions(+), 153 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 481b9dfd4dc..6772a81a38c 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -184,7 +184,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) // Output a warning for the user if he tries to exclude headers const std::vector& ignored = getIgnoredPaths(); const bool warn = std::any_of(ignored.cbegin(), ignored.cend(), [](const std::string& i) { - return Path::isHeader2(i); + return Path::isHeader(i); }); if (warn) { mLogger.printMessage("filename exclusion does not apply to header (.h and .hpp) files."); diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index a822be0b3d1..731ac9cc1f6 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -964,7 +964,7 @@ void ResultsTree::recheckSelectedFiles() askFileDir(currentFile); return; } - if (Path::isHeader2(currentFile.toStdString())) { + if (Path::isHeader(currentFile.toStdString())) { if (!data[FILE0].toString().isEmpty() && !selectedItems.contains(data[FILE0].toString())) { selectedItems<<((!mCheckPath.isEmpty() && (data[FILE0].toString().indexOf(mCheckPath) != 0)) ? (mCheckPath + "/" + data[FILE0].toString()) : data[FILE0].toString()); if (!selectedItems.contains(fileNameWithCheckPath)) diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 2fb4f7a3757..fd1bcf5855d 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -462,7 +462,7 @@ void ResultsView::updateDetails(const QModelIndex &index) QString formattedMsg = message; const QString file0 = data["file0"].toString(); - if (!file0.isEmpty() && Path::isHeader2(data["file"].toString().toStdString())) + if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString())) formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0)); if (data["cwe"].toInt() > 0) diff --git a/lib/path.cpp b/lib/path.cpp index f7d69803462..3857517fc7d 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -207,44 +207,12 @@ static const std::unordered_set header_exts = { ".h", ".hpp", ".h++", ".hxx", ".hh" }; -bool Path::isC(const std::string &path) -{ - // In unix, ".C" is considered C++ file - const std::string extension = getFilenameExtension(path); - return extension == ".c" || - extension == ".cl"; -} - -bool Path::isCPP(const std::string &path) -{ - const std::string extension = getFilenameExtensionInLowerCase(path); - return extension == ".cpp" || - extension == ".cxx" || - extension == ".cc" || - extension == ".c++" || - extension == ".hpp" || - extension == ".hxx" || - extension == ".hh" || - extension == ".tpp" || - extension == ".txx" || - extension == ".ipp" || - extension == ".ixx" || - getFilenameExtension(path) == ".C"; // In unix, ".C" is considered C++ file -} - bool Path::acceptFile(const std::string &path, const std::set &extra) { bool header = false; return (identify(path, &header) != Standards::Language::None && !header) || extra.find(getFilenameExtension(path)) != extra.end(); } -// cppcheck-suppress unusedFunction -bool Path::isHeader(const std::string &path) -{ - const std::string extension = getFilenameExtensionInLowerCase(path); - return startsWith(extension, ".h"); -} - Standards::Language Path::identify(const std::string &path, bool *header) { // cppcheck-suppress uninitvar - TODO: FP @@ -274,7 +242,7 @@ Standards::Language Path::identify(const std::string &path, bool *header) return Standards::Language::None; } -bool Path::isHeader2(const std::string &path) +bool Path::isHeader(const std::string &path) { bool header; (void)Path::identify(path, &header); diff --git a/lib/path.h b/lib/path.h index 9e0e733046c..59af20b1154 100644 --- a/lib/path.h +++ b/lib/path.h @@ -153,36 +153,12 @@ class CPPCHECKLIB Path { */ static bool acceptFile(const std::string &path, const std::set &extra); - /** - * @brief Identify language based on file extension. - * @param path filename to check. path info is optional - * @return true if extension is meant for C files - * @deprecated does not account for headers - use @identify() instead - */ - static DEPRECATED bool isC(const std::string &path); - - /** - * @brief Identify language based on file extension. - * @param path filename to check. path info is optional - * @return true if extension is meant for C++ files - * @deprecated returns true for some header extensions - use @identify() instead - */ - static DEPRECATED bool isCPP(const std::string &path); - - /** - * @brief Is filename a header based on file extension - * @param path filename to check. path info is optional - * @return true if filename extension is meant for headers - * @deprecated returns only heuristic result - use @identify() or @isHeader2() instead - */ - static DEPRECATED bool isHeader(const std::string &path); - /** * @brief Is filename a header based on file extension * @param path filename to check. path info is optional * @return true if filename extension is meant for headers */ - static bool isHeader2(const std::string &path); + static bool isHeader(const std::string &path); /** * @brief Identify the language based on the file extension diff --git a/test/testpath.cpp b/test/testpath.cpp index 0bd3ae2f5f9..9a61b0959d2 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -38,9 +38,6 @@ class TestPath : public TestFixture { TEST_CASE(getCurrentExecutablePath); TEST_CASE(isAbsolute); TEST_CASE(getRelative); - TEST_CASE(is_c); - TEST_CASE(is_cpp); - TEST_CASE(is_header); TEST_CASE(get_path_from_filename); TEST_CASE(join); TEST_CASE(isDirectory); @@ -48,7 +45,7 @@ class TestPath : public TestFixture { TEST_CASE(sameFileName); TEST_CASE(getFilenameExtension); TEST_CASE(identify); - TEST_CASE(is_header_2); + TEST_CASE(is_header); } void removeQuotationMarks() const { @@ -131,82 +128,6 @@ class TestPath : public TestFixture { ASSERT_EQUALS("C:/foobar/test.cpp", Path::getRelativePath("C:/foobar/test.cpp", basePaths)); } -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif - - void is_c() const { - ASSERT(Path::isC("index.c")); - ASSERT(Path::isC("index.cl")); - ASSERT(Path::isC("C:\\foo\\index.c")); - ASSERT(Path::isC("/mnt/c/foo/index.c")); - - // In unix .C is considered C++ -#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) - ASSERT_EQUALS(true, Path::isC("C:\\foo\\index.C")); -#else - ASSERT_EQUALS(false, Path::isC("C:\\foo\\index.C")); -#endif - - ASSERT(Path::isC("index.cpp")==false); - ASSERT(Path::isC("")==false); - ASSERT(Path::isC("c")==false); - - // unlike isCPP() it does not account for headers - ASSERT(Path::isC(".h")==false); - } - - void is_cpp() const { - ASSERT(Path::isCPP("index.cpp")); - ASSERT(Path::isCPP("index.cxx")); - ASSERT(Path::isCPP("index.cc")); - ASSERT(Path::isCPP("index.c++")); - ASSERT(Path::isCPP("index.tpp")); - ASSERT(Path::isCPP("index.txx")); - ASSERT(Path::isCPP("index.ipp")); - ASSERT(Path::isCPP("index.ixx")); - ASSERT(Path::isCPP("C:\\foo\\index.cpp")); - ASSERT(Path::isCPP("C:\\foo\\index.Cpp")); - ASSERT(Path::isCPP("/mnt/c/foo/index.cpp")); - ASSERT(Path::isCPP("/mnt/c/foo/index.Cpp")); - - // In unix .C is considered C++ -#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__)) - ASSERT_EQUALS(false, Path::isCPP("index.C")); -#else - ASSERT_EQUALS(true, Path::isCPP("index.C")); -#endif - - ASSERT(Path::isCPP("index.c")==false); - - // C++ headers are also considered C++ - ASSERT(Path::isCPP("index.hpp")); - // .h++ is missing in the list of C++ headers - ASSERT(Path::isCPP("index.h++")==false); - } - - void is_header() const { - ASSERT(Path::isHeader("index.h")); - ASSERT(Path::isHeader("index.hpp")); - ASSERT(Path::isHeader("index.hxx")); - ASSERT(Path::isHeader("index.h++")); - ASSERT(Path::isHeader("index.hh")); - - ASSERT(Path::isHeader("index.c")==false); - ASSERT(Path::isHeader("index.cpp")==false); - - // function uses heuristic approach which causes these false positives - // no need to fix - function is deprecated and was replaced by identify() - TODO_ASSERT(Path::isHeader("index.header")==false); - TODO_ASSERT(Path::isHeader("index.htm")==false); - TODO_ASSERT(Path::isHeader("index.html")==false); - } - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - void get_path_from_filename() const { ASSERT_EQUALS("", Path::getPathFromFilename("index.h")); ASSERT_EQUALS("/tmp/", Path::getPathFromFilename("/tmp/index.h")); @@ -368,18 +289,18 @@ class TestPath : public TestFixture { ASSERT_EQUALS(Standards::Language::None, Path::identify("index.html")); } - void is_header_2() const { - ASSERT(Path::isHeader2("index.h")); - ASSERT(Path::isHeader2("index.hpp")); - ASSERT(Path::isHeader2("index.hxx")); - ASSERT(Path::isHeader2("index.h++")); - ASSERT(Path::isHeader2("index.hh")); - - ASSERT(Path::isHeader2("index.c")==false); - ASSERT(Path::isHeader2("index.cpp")==false); - ASSERT(Path::isHeader2("index.header")==false); - ASSERT(Path::isHeader2("index.htm")==false); - ASSERT(Path::isHeader2("index.html")==false); + void is_header() const { + ASSERT(Path::isHeader("index.h")); + ASSERT(Path::isHeader("index.hpp")); + ASSERT(Path::isHeader("index.hxx")); + ASSERT(Path::isHeader("index.h++")); + ASSERT(Path::isHeader("index.hh")); + + ASSERT(Path::isHeader("index.c")==false); + ASSERT(Path::isHeader("index.cpp")==false); + ASSERT(Path::isHeader("index.header")==false); + ASSERT(Path::isHeader("index.htm")==false); + ASSERT(Path::isHeader("index.html")==false); } };