summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/compat.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/compat.hxx')
-rw-r--r--compilerplugins/clang/compat.hxx236
1 files changed, 2 insertions, 234 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx
index bc1c5dfcd2ee..350263da6854 100644
--- a/compilerplugins/clang/compat.hxx
+++ b/compilerplugins/clang/compat.hxx
@@ -12,15 +12,11 @@
#include <string>
#include <utility>
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/Compiler.h"
#include "llvm/Support/FileSystem.h"
#include "config_clang.h"
@@ -28,18 +24,6 @@
// Compatibility wrapper to abstract over (trivial) changes in the Clang API:
namespace compat {
-// Copies code from LLVM's include/llvm/Support/Casting.h:
-template<typename... X, typename Y> LLVM_NODISCARD inline bool isa_and_nonnull(Y const & Val) {
-#if CLANG_VERSION >= 90000
- return llvm::isa_and_nonnull<X...>(Val);
-#else
- if (!Val) {
- return false;
- }
- return llvm::isa<X...>(Val);
-#endif
-}
-
inline std::string toString(llvm::APSInt const & i, unsigned radix) {
#if CLANG_VERSION >= 130000
return llvm::toString(i, radix);
@@ -48,138 +32,17 @@ inline std::string toString(llvm::APSInt const & i, unsigned radix) {
#endif
}
-inline clang::SourceLocation getBeginLoc(clang::Decl const * decl) {
-#if CLANG_VERSION >= 80000
- return decl->getBeginLoc();
-#else
- return decl->getLocStart();
-#endif
-}
-
-inline clang::SourceLocation getEndLoc(clang::Decl const * decl) {
-#if CLANG_VERSION >= 80000
- return decl->getEndLoc();
-#else
- return decl->getLocEnd();
-#endif
-}
-
-inline clang::SourceLocation getBeginLoc(clang::DeclarationNameInfo const & info) {
-#if CLANG_VERSION >= 80000
- return info.getBeginLoc();
-#else
- return info.getLocStart();
-#endif
-}
-
-inline clang::SourceLocation getEndLoc(clang::DeclarationNameInfo const & info) {
-#if CLANG_VERSION >= 80000
- return info.getEndLoc();
-#else
- return info.getLocEnd();
-#endif
-}
-
-inline clang::SourceLocation getBeginLoc(clang::Stmt const * stmt) {
-#if CLANG_VERSION >= 80000
- return stmt->getBeginLoc();
-#else
- return stmt->getLocStart();
-#endif
-}
-
-inline clang::SourceLocation getEndLoc(clang::Stmt const * stmt) {
-#if CLANG_VERSION >= 80000
- return stmt->getEndLoc();
-#else
- return stmt->getLocEnd();
-#endif
-}
-
-inline clang::SourceLocation getBeginLoc(clang::CXXBaseSpecifier const * spec) {
-#if CLANG_VERSION >= 80000
- return spec->getBeginLoc();
-#else
- return spec->getLocStart();
-#endif
-}
-
-inline clang::SourceLocation getEndLoc(clang::CXXBaseSpecifier const * spec) {
-#if CLANG_VERSION >= 80000
- return spec->getEndLoc();
-#else
- return spec->getLocEnd();
-#endif
-}
-
inline std::pair<clang::SourceLocation, clang::SourceLocation> getImmediateExpansionRange(
clang::SourceManager const & SM, clang::SourceLocation Loc)
{
-#if CLANG_VERSION >= 70000
auto const csr = SM.getImmediateExpansionRange(Loc);
if (csr.isCharRange()) { /*TODO*/ }
return {csr.getBegin(), csr.getEnd()};
-#else
- return SM.getImmediateExpansionRange(Loc);
-#endif
-}
-
-inline bool isPointWithin(
- clang::SourceManager const & SM, clang::SourceLocation Location, clang::SourceLocation Start,
- clang::SourceLocation End)
-{
-#if CLANG_VERSION >= 60000
- return SM.isPointWithin(Location, Start, End);
-#else
- return
- Location == Start || Location == End
- || (SM.isBeforeInTranslationUnit(Start, Location)
- && SM.isBeforeInTranslationUnit(Location, End));
-#endif
-}
-
-inline clang::Expr const * IgnoreImplicit(clang::Expr const * expr) {
-#if CLANG_VERSION >= 80000
- return expr->IgnoreImplicit();
-#else
- using namespace clang;
- // Copy from Clang's lib/AST/Stmt.cpp, including <https://reviews.llvm.org/D50666> "Fix
- // Stmt::ignoreImplicit":
- Stmt const *s = expr;
-
- Stmt const *lasts = nullptr;
-
- while (s != lasts) {
- lasts = s;
-
- if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
- s = ewc->getSubExpr();
-
- if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
- s = mte->GetTemporaryExpr();
-
- if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
- s = bte->getSubExpr();
-
- if (auto *ice = dyn_cast<ImplicitCastExpr>(s))
- s = ice->getSubExpr();
- }
-
- return static_cast<Expr const *>(s);
-#endif
}
/// Utility method
inline clang::Expr const * IgnoreParenImplicit(clang::Expr const * expr) {
- return compat::IgnoreImplicit(compat::IgnoreImplicit(expr)->IgnoreParens());
-}
-
-inline bool CPlusPlus17(clang::LangOptions const & opts) {
-#if CLANG_VERSION >= 60000
- return opts.CPlusPlus17;
-#else
- return opts.CPlusPlus1z;
-#endif
+ return expr->IgnoreImplicit()->IgnoreParens()->IgnoreImplicit();
}
#if CLANG_VERSION >= 130000
@@ -189,40 +52,13 @@ constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue;
#endif
inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) {
-#if CLANG_VERSION >= 80000
clang::Expr::EvalResult res;
bool b = expr->EvaluateAsInt(res, ctx);
if (b && res.Val.isInt())
intRes = res.Val.getInt();
return b;
-#else
- return expr->EvaluateAsInt(intRes, ctx);
-#endif
}
-inline llvm::Optional<llvm::APSInt> getIntegerConstantExpr(
- clang::Expr const * expr, clang::ASTContext const & context)
-{
-#if CLANG_VERSION >= 120000
- return expr->getIntegerConstantExpr(context);
-#else
- llvm::APSInt res;
- return expr->isIntegerConstantExpr(res, context) ? res : llvm::Optional<llvm::APSInt>();
-#endif
-}
-
-inline clang::Expr * getSubExpr(clang::MaterializeTemporaryExpr const * expr) {
-#if CLANG_VERSION >= 100000
- return expr->getSubExpr();
-#else
- return expr->GetTemporaryExpr();
-#endif
-}
-
-#if CLANG_VERSION < 80000
-inline clang::Expr const * getSubExprAsWritten(clang::CastExpr const * expr)
-{ return expr->getSubExprAsWritten(); }
-#else
// Work around CastExpr::getSubExprAsWritten firing
//
// include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*)
@@ -251,7 +87,7 @@ namespace detail {
// Skip through reference binding to temporary.
if (clang::MaterializeTemporaryExpr *Materialize
= clang::dyn_cast<clang::MaterializeTemporaryExpr>(expr))
- expr = compat::getSubExpr(Materialize);
+ expr = Materialize->getSubExpr();
// Skip any temporary bindings; they're implicit.
if (clang::CXXBindTemporaryExpr *Binder = clang::dyn_cast<clang::CXXBindTemporaryExpr>(expr))
@@ -288,74 +124,6 @@ inline clang::Expr *getSubExprAsWritten(clang::CastExpr *This) {
inline const clang::Expr *getSubExprAsWritten(const clang::CastExpr *This) {
return getSubExprAsWritten(const_cast<clang::CastExpr *>(This));
}
-#endif
-
-inline clang::QualType getObjectType(clang::CXXMemberCallExpr const * expr) {
-#if CLANG_VERSION >= 100000
- return expr->getObjectType();
-#else
- // <https://github.com/llvm/llvm-project/commit/88559637641e993895337e1047a0bd787fecc647>
- // "[OpenCL] Improve destructor support in C++ for OpenCL":
- clang::QualType Ty = expr->getImplicitObjectArgument()->getType();
- if (Ty->isPointerType())
- Ty = Ty->getPointeeType();
- return Ty;
-#endif
-}
-
-inline bool isExplicitSpecified(clang::CXXConstructorDecl const * decl) {
-#if CLANG_VERSION >= 90000
- return decl->getExplicitSpecifier().isExplicit();
-#else
- return decl->isExplicitSpecified();
-#endif
-}
-
-inline bool isExplicitSpecified(clang::CXXConversionDecl const * decl) {
-#if CLANG_VERSION >= 90000
- return decl->getExplicitSpecifier().isExplicit();
-#else
- return decl->isExplicitSpecified();
-#endif
-}
-
-inline clang::QualType getDeclaredReturnType(clang::FunctionDecl const * decl) {
-#if CLANG_VERSION >= 80000
- return decl->getDeclaredReturnType();
-#else
- // <https://github.com/llvm/llvm-project/commit/4576a77b809649f5b8d0ff8c7a4be57eeee0ecf9>
- // "PR33222: Require the declared return type not the actual return type to":
- auto *TSI = decl->getTypeSourceInfo();
- clang::QualType T = TSI ? TSI->getType() : decl->getType();
- return T->castAs<clang::FunctionType>()->getReturnType();
-#endif
-}
-
-inline bool isComparisonOp(clang::CXXOperatorCallExpr const * callExpr)
-{
-#if CLANG_VERSION >= 110000
- return callExpr->isComparisonOp();
-#else
- using namespace clang;
- auto op = callExpr->getOperator();
- return op == OO_Less || op == OO_Greater || op == OO_LessEqual || op == OO_GreaterEqual
- || op == OO_EqualEqual || op == OO_ExclaimEqual;
-#endif
-}
-
-inline bool isPtrMemOp(clang::BinaryOperatorKind op) {
-#if CLANG_VERSION >= 80000
- return clang::BinaryOperator::isPtrMemOp(op);
-#else
- return op == clang::BO_PtrMemD || op == clang::BO_PtrMemI;
-#endif
-}
-
-#if CLANG_VERSION >= 70000
-constexpr llvm::sys::fs::OpenFlags OF_None = llvm::sys::fs::OF_None;
-#else
-constexpr llvm::sys::fs::OpenFlags OF_None = llvm::sys::fs::F_None;
-#endif
}