diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-11-06 10:51:31 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-11-06 21:17:59 +0100 |
commit | c9cedde7c0ba396dadfabbf644c6329e65afebf9 (patch) | |
tree | 34cd71285b8b102eeb1e0b4f48ef256381f2725b /compilerplugins/clang | |
parent | 0c54c09aeb7e170512195c8f619ab2ded98c1ec5 (diff) |
Adapt to various Clang 18 trunk enum rework
<https://github.com/llvm/llvm-project/commit/a9070f22a29e28f7d6f83c24a8dd88f3a94969ae>
"[clang][NFC] Refactor `CXXConstructExpr::ConstructionKind`",
<https://github.com/llvm/llvm-project/commit/c23aaa410358b9f9c364ddaaeb6b2069b185a99b>
"[clang][NFC] Refactor `CharacterLiteral::CharacterKind`",
<https://github.com/llvm/llvm-project/commit/3e6ce58701a3a8463b53fb3fd2023c02b4e90554>
"[clang][NFC] Refactor `StringLiteral::StringKind`",
<https://github.com/llvm/llvm-project/commit/edd690b02e16e991393bf7f67631196942369aed>
"[clang][NFC] Refactor `TagTypeKind` (#71160)"
Change-Id: Ice802f6d662494781ad22fcf11ea5006de918254
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158983
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/check.hxx | 16 | ||||
-rw-r--r-- | compilerplugins/clang/compat.hxx | 40 | ||||
-rw-r--r-- | compilerplugins/clang/mergeclasses.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/privatebase.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/redundantcast.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/salunicodeliteral.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/vclwidgets.cxx | 3 |
7 files changed, 58 insertions, 12 deletions
diff --git a/compilerplugins/clang/check.hxx b/compilerplugins/clang/check.hxx index a7b7ba820d09..af6cd355a416 100644 --- a/compilerplugins/clang/check.hxx +++ b/compilerplugins/clang/check.hxx @@ -16,6 +16,8 @@ #include <clang/AST/Type.h> #include <clang/Basic/OperatorKinds.h> +#include "compat.hxx" + namespace loplugin { class ContextCheck; @@ -188,7 +190,7 @@ ContextCheck TypeCheck::Class(llvm::StringRef id) if (!type_.isNull()) { auto const t = type_->getAs<clang::RecordType>(); if (t != nullptr) { - return detail::checkRecordDecl(t->getDecl(), clang::TTK_Class, id); + return detail::checkRecordDecl(t->getDecl(), compat::TagTypeKind::Class, id); } } return ContextCheck(); @@ -199,7 +201,7 @@ ContextCheck TypeCheck::Struct(llvm::StringRef id) const if (!type_.isNull()) { auto const t = type_->getAs<clang::RecordType>(); if (t != nullptr) { - return detail::checkRecordDecl(t->getDecl(), clang::TTK_Struct, id); + return detail::checkRecordDecl(t->getDecl(), compat::TagTypeKind::Struct, id); } } return ContextCheck(); @@ -231,12 +233,12 @@ ContextCheck TypeCheck::Typedef(llvm::StringRef id) const ContextCheck DeclCheck::Class(llvm::StringRef id) const { - return detail::checkRecordDecl(decl_, clang::TTK_Class, id); + return detail::checkRecordDecl(decl_, compat::TagTypeKind::Class, id); } ContextCheck DeclCheck::Struct(llvm::StringRef id) const { - return detail::checkRecordDecl(decl_, clang::TTK_Struct, id); + return detail::checkRecordDecl(decl_, compat::TagTypeKind::Struct, id); } ContextCheck DeclCheck::ClassOrStruct(llvm::StringRef id) const @@ -250,7 +252,7 @@ ContextCheck DeclCheck::ClassOrStruct(llvm::StringRef id) const ContextCheck DeclCheck::Union(llvm::StringRef id) const { - return detail::checkRecordDecl(decl_, clang::TTK_Union, id); + return detail::checkRecordDecl(decl_, compat::TagTypeKind::Union, id); } ContextCheck DeclCheck::Function(llvm::StringRef id) const @@ -294,13 +296,13 @@ ContextCheck ContextCheck::Namespace(llvm::StringRef id) const ContextCheck ContextCheck::Class(llvm::StringRef id) const { return detail::checkRecordDecl( - llvm::dyn_cast_or_null<clang::Decl>(context_), clang::TTK_Class, id); + llvm::dyn_cast_or_null<clang::Decl>(context_), compat::TagTypeKind::Class, id); } ContextCheck ContextCheck::Struct(llvm::StringRef id) const { return detail::checkRecordDecl( - llvm::dyn_cast_or_null<clang::Decl>(context_), clang::TTK_Struct, id); + llvm::dyn_cast_or_null<clang::Decl>(context_), compat::TagTypeKind::Struct, id); } bool isExtraWarnUnusedType(clang::QualType type); diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index df4052ef108a..d122933eeaaf 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -82,6 +82,24 @@ constexpr clang::ExprValueKind VK_PRValue = clang::VK_PRValue; constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue; #endif +namespace CXXConstructionKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::CXXConstructionKind Complete = clang::CXXConstructionKind::Complete; +#else +constexpr clang::CXXConstructExpr::ConstructionKind Complete = clang::CXXConstructExpr::CK_Complete; +#endif +} + +namespace CharacterLiteralKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::CharacterLiteralKind Ascii = clang::CharacterLiteralKind::Ascii; +#else +constexpr clang::CharacterLiteral::CharacterKind Ascii = clang::CharacterLiteral::Ascii; +#endif +} + namespace ElaboratedTypeKeyword { #if CLANG_VERSION >= 180000 @@ -102,6 +120,28 @@ constexpr clang::Linkage Module = clang::ModuleLinkage; #endif } +namespace StringLiteralKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::StringLiteralKind UTF8 = clang::StringLiteralKind::UTF8; +#else +constexpr clang::StringLiteral::StringKind UTF8 = clang::StringLiteral::UTF8; +#endif +} + +namespace TagTypeKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::TagTypeKind Class = clang::TagTypeKind::Class; +constexpr clang::TagTypeKind Struct = clang::TagTypeKind::Struct; +constexpr clang::TagTypeKind Union = clang::TagTypeKind::Union; +#else +constexpr clang::TagTypeKind Class = clang::TTK_Class; +constexpr clang::TagTypeKind Struct = clang::TTK_Struct; +constexpr clang::TagTypeKind Union = clang::TTK_Union; +#endif +} + inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) { clang::Expr::EvalResult res; bool b = expr->EvaluateAsInt(res, ctx); diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx index dae8724bd3bf..5ac69bc52397 100644 --- a/compilerplugins/clang/mergeclasses.cxx +++ b/compilerplugins/clang/mergeclasses.cxx @@ -12,6 +12,7 @@ #include <string> #include <iostream> #include "config_clang.h" +#include "compat.hxx" #include "plugin.hxx" #include <fstream> @@ -129,7 +130,7 @@ bool MergeClasses::VisitCXXConstructExpr( const CXXConstructExpr* pCXXConstructE return true; } // ignore calls when a sub-class is constructing its superclass - if (pCXXConstructExpr->getConstructionKind() != CXXConstructExpr::ConstructionKind::CK_Complete) { + if (pCXXConstructExpr->getConstructionKind() != compat::CXXConstructionKind::Complete) { return true; } const CXXConstructorDecl* pCXXConstructorDecl = pCXXConstructExpr->getConstructor(); diff --git a/compilerplugins/clang/privatebase.cxx b/compilerplugins/clang/privatebase.cxx index 210ce6376d66..677461302b15 100644 --- a/compilerplugins/clang/privatebase.cxx +++ b/compilerplugins/clang/privatebase.cxx @@ -9,6 +9,7 @@ #ifndef LO_CLANG_SHARED_PLUGINS +#include "compat.hxx" #include "plugin.hxx" namespace { @@ -33,7 +34,7 @@ void PrivateBase::run() { bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) { if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition() - || decl->getTagKind() != TTK_Class) + || decl->getTagKind() != compat::TagTypeKind::Class) { return true; } diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index eea609005228..6bace5282275 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -609,7 +609,7 @@ bool RedundantCast::VisitCXXReinterpretCastExpr( { if (loplugin::TypeCheck(sub->getType()).Pointer().Const().Char()) { if (auto const lit = dyn_cast<clang::StringLiteral>(expr->getSubExprAsWritten())) { - if (lit->getKind() == clang::StringLiteral::UTF8) { + if (lit->getKind() == compat::StringLiteralKind::UTF8) { // Don't warn about // // redundant_cast<char const *>(u8"...") diff --git a/compilerplugins/clang/salunicodeliteral.cxx b/compilerplugins/clang/salunicodeliteral.cxx index aa0a3950c8fa..0a8eeea4885b 100644 --- a/compilerplugins/clang/salunicodeliteral.cxx +++ b/compilerplugins/clang/salunicodeliteral.cxx @@ -9,13 +9,14 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" +#include "compat.hxx" #include "plugin.hxx" namespace { bool isAsciiCharacterLiteral(Expr const * expr) { if (auto const e = dyn_cast<CharacterLiteral>(expr)) { - return e->getKind() == CharacterLiteral::Ascii; + return e->getKind() == compat::CharacterLiteralKind::Ascii; } return false; } diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx index 2f5d6c57ab59..422041688a78 100644 --- a/compilerplugins/clang/vclwidgets.cxx +++ b/compilerplugins/clang/vclwidgets.cxx @@ -13,6 +13,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "compat.hxx" #include "config_clang.h" #include "clang/AST/CXXInheritance.h" @@ -849,7 +850,7 @@ bool VCLWidgets::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ) if (ignoreLocation(constructExpr)) { return true; } - if (constructExpr->getConstructionKind() != CXXConstructExpr::CK_Complete) { + if (constructExpr->getConstructionKind() != compat::CXXConstructionKind::Complete) { return true; } const CXXConstructorDecl* pConstructorDecl = constructExpr->getConstructor(); |