diff options
author | Sergio Martins <smartins@kde.org> | 2019-10-28 20:07:01 +0000 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2019-10-28 20:07:01 +0000 |
commit | a790f6bc569237ca0ce0b1efd99f6f87a8dd0af1 (patch) | |
tree | e503987763373943f81430b223990ca5331c8315 | |
parent | 6b140de078c0dc6f5e6d6732512ad5e454d887d0 (diff) |
Use boost:regex if std::regex is missingupstream/boost_regex
This will fix old-style-connect and suppressions in our AppImage
-rw-r--r-- | CMakeLists.txt | 17 | ||||
-rw-r--r-- | CheckSources.cmake | 4 | ||||
-rw-r--r-- | checks.json | 1 | ||||
-rwxr-xr-x | dev-scripts/generate.py | 9 | ||||
-rw-r--r-- | src/Checks.h | 2 | ||||
-rw-r--r-- | src/SourceCompatibilityHelpers.h | 11 | ||||
-rw-r--r-- | src/SuppressionManager.cpp | 12 | ||||
-rw-r--r-- | src/checks/level2/old-style-connect.cpp | 2 |
8 files changed, 22 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e60d1f5..f8f781d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,13 +67,12 @@ endif() message("Looking for std::regex support...") try_run(RUN_RESULT COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/.cmake_has_regex_test.cpp) -if(RUN_RESULT EQUAL 0) - set(HAS_STD_REGEX TRUE) -else() - set(HAS_STD_REGEX FALSE) - add_definitions(-DNO_STD_REGEX) - message("old-style-connect check is disabled due to missing std::regex support") - message("Suppressions are disabled due to missing std::regex support") +if(NOT RUN_RESULT EQUAL 0) + message("Using boost::regex instead of std::regex") + set(CLAZY_USES_BOOST_REGEX TRUE) + add_definitions(-DCLAZY_USES_BOOST_REGEX) + find_package(Boost REQUIRED COMPONENTS regex) + include_directories(${Boost_INCLUDE_DIRS}) endif() include(ClazySources.cmake) @@ -128,6 +127,10 @@ macro(link_to_llvm name is_standalone) target_link_libraries(${name} clangTooling) target_link_libraries(${name} clangToolingCore) target_link_libraries(${name} ${clang_tooling_refactoring_lib}) + + if (CLAZY_USES_BOOST_REGEX) + target_link_libraries(${name} ${Boost_LIBRARIES}) + endif() endmacro() macro(add_clang_plugin name) diff --git a/CheckSources.cmake b/CheckSources.cmake index 8d310aee..9760eeb4 100644 --- a/CheckSources.cmake +++ b/CheckSources.cmake @@ -83,7 +83,3 @@ set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS} ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/static-pmf.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/virtual-call-ctor.cpp ) - -if(HAS_STD_REGEX OR CLAZY_BUILD_WITH_CLANG) - set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS} ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/old-style-connect.cpp) -endif() diff --git a/checks.json b/checks.json index 86456dd4..898dda77 100644 --- a/checks.json +++ b/checks.json @@ -531,7 +531,6 @@ "name" : "old-style-connect", "level" : 2, "minimum_qt_version" : 50500, - "ifndef" : "NO_STD_REGEX", "categories" : ["performance"], "fixits" : [ { diff --git a/dev-scripts/generate.py b/dev-scripts/generate.py index fd818157..c7f9d3aa 100755 --- a/dev-scripts/generate.py +++ b/dev-scripts/generate.py @@ -317,21 +317,12 @@ void CheckManager::registerChecks() #------------------------------------------------------------------------------- def generate_cmake_file(checks): text = "set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS}\n" - checks_with_regexp = [] for level in [-1, 0, 1, 2, 3]: for check in checks: if check.level == level: text += " ${CMAKE_CURRENT_LIST_DIR}/src/" + check.qualified_cpp_filename() + "\n" - if check.ifndef == "NO_STD_REGEX": - checks_with_regexp.append(check) text += ")\n" - if checks_with_regexp: - text += "\nif(HAS_STD_REGEX OR CLAZY_BUILD_WITH_CLANG)\n" - for check in checks_with_regexp: - text += " set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS} ${CMAKE_CURRENT_LIST_DIR}/src/" + check.qualified_cpp_filename() + ")\n" - text += "endif()\n" - filename = clazy_source_path() + "CheckSources.cmake" old_text = read_file(filename) if old_text != text: diff --git a/src/Checks.h b/src/Checks.h index 48672102..b2dab476 100644 --- a/src/Checks.h +++ b/src/Checks.h @@ -208,10 +208,8 @@ void CheckManager::registerChecks() registerCheck(check<ImplicitCasts>("implicit-casts", CheckLevel2, RegisteredCheck::Option_VisitsStmts)); registerCheck(check<MissingQObjectMacro>("missing-qobject-macro", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check<MissingTypeInfo>("missing-typeinfo", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); -#ifndef NO_STD_REGEX registerCheck(check<OldStyleConnect>("old-style-connect", CheckLevel2, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-old-style-connect", "old-style-connect"); -#endif registerCheck(check<QStringAllocations>("qstring-allocations", CheckLevel2, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-qlatin1string-allocations", "qstring-allocations"); registerFixIt(2, "fix-fromLatin1_fromUtf8-allocations", "qstring-allocations"); diff --git a/src/SourceCompatibilityHelpers.h b/src/SourceCompatibilityHelpers.h index 3397e328..4db141ab 100644 --- a/src/SourceCompatibilityHelpers.h +++ b/src/SourceCompatibilityHelpers.h @@ -31,6 +31,17 @@ #include <clang/Frontend/FrontendDiagnostic.h> #include <clang/Tooling/Core/Diagnostic.h> +#if defined(CLAZY_USES_BOOST_REGEX) +# define BOOST_NO_EXCEPTIONS +# include <boost/throw_exception.hpp> +inline void boost::throw_exception(std::exception const &){} +# include <boost/regex.hpp> +using namespace boost; +#else +# include <regex> +using namespace std; +#endif + namespace clazy { template <typename T> diff --git a/src/SuppressionManager.cpp b/src/SuppressionManager.cpp index ff7753c4..9d774ea6 100644 --- a/src/SuppressionManager.cpp +++ b/src/SuppressionManager.cpp @@ -20,6 +20,7 @@ */ #include "SuppressionManager.h" +#include "SourceCompatibilityHelpers.h" #include "clazy_stl.h" #include <clang/Basic/SourceManager.h> @@ -32,10 +33,6 @@ #include <vector> -#ifndef NO_STD_REGEX -# include <regex> -#endif - using namespace clang; using namespace std; @@ -46,10 +43,6 @@ SuppressionManager::SuppressionManager() bool SuppressionManager::isSuppressed(const std::string &checkName, clang::SourceLocation loc, const clang::SourceManager &sm, const clang::LangOptions &lo) const { -#ifdef NO_STD_REGEX - return false; -#endif - if (loc.isMacroID()) loc = sm.getExpansionLoc(loc); @@ -86,7 +79,6 @@ bool SuppressionManager::isSuppressed(const std::string &checkName, clang::Sourc void SuppressionManager::parseFile(FileID id, const SourceManager &sm, const clang::LangOptions &lo) const { -#ifndef NO_STD_REGEX const unsigned hash = id.getHashValue(); auto it = m_processedFileIDs.insert({hash, Suppressions()}).first; Suppressions &suppressions = (*it).second; @@ -120,7 +112,6 @@ void SuppressionManager::parseFile(FileID id, const SourceManager &sm, const cla suppressions.checksToSkip.insert(checks.cbegin(), checks.cend()); } - const int lineNumber = sm.getSpellingLineNumber(token.getLocation()); if (lineNumber < 0) { llvm::errs() << "SuppressionManager::parseFile: Invalid line number " << lineNumber << "\n"; @@ -137,5 +128,4 @@ void SuppressionManager::parseFile(FileID id, const SourceManager &sm, const cla } } } -#endif } diff --git a/src/checks/level2/old-style-connect.cpp b/src/checks/level2/old-style-connect.cpp index 0fe68c13..235890fd 100644 --- a/src/checks/level2/old-style-connect.cpp +++ b/src/checks/level2/old-style-connect.cpp @@ -52,8 +52,6 @@ #include <llvm/Support/Casting.h> #include <llvm/Support/raw_ostream.h> -#include <regex> - namespace clang { class MacroInfo; } // namespace clang |