Adapt to various Clang 18 trunk enum rework

<a9070f22a2>
"[clang][NFC] Refactor `CXXConstructExpr::ConstructionKind`",
<c23aaa4103>
"[clang][NFC] Refactor `CharacterLiteral::CharacterKind`",
<3e6ce58701>
"[clang][NFC] Refactor `StringLiteral::StringKind`",
<edd690b02e>
"[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>
This commit is contained in:
Stephan Bergmann 2023-11-06 10:51:31 +01:00
parent 0c54c09aeb
commit c9cedde7c0
7 changed files with 58 additions and 12 deletions

View File

@ -16,6 +16,8 @@
#include <clang/AST/Type.h> #include <clang/AST/Type.h>
#include <clang/Basic/OperatorKinds.h> #include <clang/Basic/OperatorKinds.h>
#include "compat.hxx"
namespace loplugin { namespace loplugin {
class ContextCheck; class ContextCheck;
@ -188,7 +190,7 @@ ContextCheck TypeCheck::Class(llvm::StringRef id)
if (!type_.isNull()) { if (!type_.isNull()) {
auto const t = type_->getAs<clang::RecordType>(); auto const t = type_->getAs<clang::RecordType>();
if (t != nullptr) { if (t != nullptr) {
return detail::checkRecordDecl(t->getDecl(), clang::TTK_Class, id); return detail::checkRecordDecl(t->getDecl(), compat::TagTypeKind::Class, id);
} }
} }
return ContextCheck(); return ContextCheck();
@ -199,7 +201,7 @@ ContextCheck TypeCheck::Struct(llvm::StringRef id) const
if (!type_.isNull()) { if (!type_.isNull()) {
auto const t = type_->getAs<clang::RecordType>(); auto const t = type_->getAs<clang::RecordType>();
if (t != nullptr) { if (t != nullptr) {
return detail::checkRecordDecl(t->getDecl(), clang::TTK_Struct, id); return detail::checkRecordDecl(t->getDecl(), compat::TagTypeKind::Struct, id);
} }
} }
return ContextCheck(); return ContextCheck();
@ -231,12 +233,12 @@ ContextCheck TypeCheck::Typedef(llvm::StringRef id) const
ContextCheck DeclCheck::Class(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 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 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 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 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 ContextCheck ContextCheck::Class(llvm::StringRef id) const
{ {
return detail::checkRecordDecl( 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 ContextCheck ContextCheck::Struct(llvm::StringRef id) const
{ {
return detail::checkRecordDecl( 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); bool isExtraWarnUnusedType(clang::QualType type);

View File

@ -82,6 +82,24 @@ constexpr clang::ExprValueKind VK_PRValue = clang::VK_PRValue;
constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue; constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue;
#endif #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 namespace ElaboratedTypeKeyword
{ {
#if CLANG_VERSION >= 180000 #if CLANG_VERSION >= 180000
@ -102,6 +120,28 @@ constexpr clang::Linkage Module = clang::ModuleLinkage;
#endif #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) { inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) {
clang::Expr::EvalResult res; clang::Expr::EvalResult res;
bool b = expr->EvaluateAsInt(res, ctx); bool b = expr->EvaluateAsInt(res, ctx);

View File

@ -12,6 +12,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "config_clang.h" #include "config_clang.h"
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
#include <fstream> #include <fstream>
@ -129,7 +130,7 @@ bool MergeClasses::VisitCXXConstructExpr( const CXXConstructExpr* pCXXConstructE
return true; return true;
} }
// ignore calls when a sub-class is constructing its superclass // 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; return true;
} }
const CXXConstructorDecl* pCXXConstructorDecl = pCXXConstructExpr->getConstructor(); const CXXConstructorDecl* pCXXConstructorDecl = pCXXConstructExpr->getConstructor();

View File

@ -9,6 +9,7 @@
#ifndef LO_CLANG_SHARED_PLUGINS #ifndef LO_CLANG_SHARED_PLUGINS
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
namespace { namespace {
@ -33,7 +34,7 @@ void PrivateBase::run() {
bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) { bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition() if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition()
|| decl->getTagKind() != TTK_Class) || decl->getTagKind() != compat::TagTypeKind::Class)
{ {
return true; return true;
} }

View File

@ -609,7 +609,7 @@ bool RedundantCast::VisitCXXReinterpretCastExpr(
{ {
if (loplugin::TypeCheck(sub->getType()).Pointer().Const().Char()) { if (loplugin::TypeCheck(sub->getType()).Pointer().Const().Char()) {
if (auto const lit = dyn_cast<clang::StringLiteral>(expr->getSubExprAsWritten())) { 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 // Don't warn about
// //
// redundant_cast<char const *>(u8"...") // redundant_cast<char const *>(u8"...")

View File

@ -9,13 +9,14 @@
#ifndef LO_CLANG_SHARED_PLUGINS #ifndef LO_CLANG_SHARED_PLUGINS
#include "check.hxx" #include "check.hxx"
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
namespace { namespace {
bool isAsciiCharacterLiteral(Expr const * expr) { bool isAsciiCharacterLiteral(Expr const * expr) {
if (auto const e = dyn_cast<CharacterLiteral>(expr)) { if (auto const e = dyn_cast<CharacterLiteral>(expr)) {
return e->getKind() == CharacterLiteral::Ascii; return e->getKind() == compat::CharacterLiteralKind::Ascii;
} }
return false; return false;
} }

View File

@ -13,6 +13,7 @@
#include "plugin.hxx" #include "plugin.hxx"
#include "check.hxx" #include "check.hxx"
#include "compat.hxx"
#include "config_clang.h" #include "config_clang.h"
#include "clang/AST/CXXInheritance.h" #include "clang/AST/CXXInheritance.h"
@ -849,7 +850,7 @@ bool VCLWidgets::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr )
if (ignoreLocation(constructExpr)) { if (ignoreLocation(constructExpr)) {
return true; return true;
} }
if (constructExpr->getConstructionKind() != CXXConstructExpr::CK_Complete) { if (constructExpr->getConstructionKind() != compat::CXXConstructionKind::Complete) {
return true; return true;
} }
const CXXConstructorDecl* pConstructorDecl = constructExpr->getConstructor(); const CXXConstructorDecl* pConstructorDecl = constructExpr->getConstructor();