2014-01-31 09:37:27 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-08-06 14:32:54 +00:00
|
|
|
#pragma once
|
2014-01-31 09:37:27 +01:00
|
|
|
|
2021-06-14 13:03:34 +02:00
|
|
|
#include <string>
|
2018-05-03 21:13:35 +02:00
|
|
|
#include <utility>
|
2014-02-25 10:15:28 +01:00
|
|
|
|
2014-01-31 09:37:27 +01:00
|
|
|
#include "clang/AST/Decl.h"
|
2018-08-10 12:35:21 +02:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2014-02-21 23:59:04 +01:00
|
|
|
#include "clang/AST/Expr.h"
|
2017-05-19 23:51:46 +02:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2014-04-02 17:53:43 +02:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2021-06-10 14:27:49 +02:00
|
|
|
#include "clang/Basic/Specifiers.h"
|
2021-06-14 13:03:34 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2021-01-20 08:02:19 +01:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2022-02-15 13:29:04 +01:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2014-01-31 09:37:27 +01:00
|
|
|
|
2016-02-26 12:50:16 +01:00
|
|
|
#include "config_clang.h"
|
|
|
|
|
2014-01-31 10:31:30 +01:00
|
|
|
// Compatibility wrapper to abstract over (trivial) changes in the Clang API:
|
2014-01-31 09:37:27 +01:00
|
|
|
namespace compat {
|
|
|
|
|
2021-01-20 08:02:19 +01:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-06-14 13:03:34 +02:00
|
|
|
inline std::string toString(llvm::APSInt const & i, unsigned radix) {
|
|
|
|
#if CLANG_VERSION >= 130000
|
|
|
|
return llvm::toString(i, radix);
|
|
|
|
#else
|
|
|
|
return i.toString(radix);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-08-10 12:35:21 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-05-03 21:13:35 +02:00
|
|
|
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
|
|
|
|
}
|
2014-09-23 13:46:24 +02:00
|
|
|
|
2017-12-10 19:52:57 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:48:39 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-09-09 12:07:25 +02:00
|
|
|
/// Utility method
|
|
|
|
inline clang::Expr const * IgnoreParenImplicit(clang::Expr const * expr) {
|
|
|
|
return compat::IgnoreImplicit(compat::IgnoreImplicit(expr)->IgnoreParens());
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:48:39 +02:00
|
|
|
inline bool CPlusPlus17(clang::LangOptions const & opts) {
|
|
|
|
#if CLANG_VERSION >= 60000
|
|
|
|
return opts.CPlusPlus17;
|
|
|
|
#else
|
|
|
|
return opts.CPlusPlus1z;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:27:49 +02:00
|
|
|
#if CLANG_VERSION >= 130000
|
|
|
|
constexpr clang::ExprValueKind VK_PRValue = clang::VK_PRValue;
|
|
|
|
#else
|
|
|
|
constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue;
|
|
|
|
#endif
|
|
|
|
|
2018-11-27 12:56:12 +02:00
|
|
|
inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) {
|
2018-11-29 09:54:32 +01:00
|
|
|
#if CLANG_VERSION >= 80000
|
2018-11-27 12:56:12 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-28 08:14:49 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:04:02 +01:00
|
|
|
inline clang::Expr * getSubExpr(clang::MaterializeTemporaryExpr const * expr) {
|
|
|
|
#if CLANG_VERSION >= 100000
|
|
|
|
return expr->getSubExpr();
|
|
|
|
#else
|
|
|
|
return expr->GetTemporaryExpr();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-08-31 22:01:15 +02:00
|
|
|
#if CLANG_VERSION < 80000
|
|
|
|
inline clang::Expr const * getSubExprAsWritten(clang::CastExpr const * expr)
|
|
|
|
{ return expr->getSubExprAsWritten(); }
|
|
|
|
#else
|
|
|
|
// Work around CastExpr::getSubExprAsWritten firing
|
Turn OStringLiteral into a consteval'ed, static-refcound rtl_String
...from which an OString can cheaply be instantiated.
The one downside is that OStringLiteral now needs to be a template abstracting
over the string length. But any uses for which that is a problem (e.g., as the
element type of a containers that would no longer be homogeneous, or in the
signature of a function that shall not be turned into a template for one reason
or another) can be replaced with std::string_view, without loss of efficiency
compared to the original OStringLiteral, and without loss of expressivity (esp.
with the newly introduced OString(std::string_view) ctor).
The new OStringLiteral ctor code would probably not be very efficient if it were
ever executed at runtime, but it is intended to be only executed at compile
time. Where available, C++20 "consteval" is used to statically ensure that.
The intended use of the new OStringLiteral is in all cases where an
object that shall itself not be an OString (e.g., because it shall be a
global static variable for which the OString ctor/dtor would be detrimental at
library load/unload) must be converted to an OString instance in at least one
place. Other string literal abstractions could use std::string_view (or just
plain char const[N]), but interestingly OStringLiteral might be more efficient
than constexpr std::string_view even for such cases, as it should not need any
relocations at library load time. For now, no existing uses of OUStringLiteral
have been changed to some other abstraction (unless technically necessary as
discussed above), and no additional places that would benefit from
OUStringLiteral have been changed to use it.
sal/qa/rtl/strings/test_ostring_concat.cxx documents some workarounds for GCC
bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96878> "Failed class template
argument deduction in unevaluated, parenthesized context". Those places, as
well as uses of OStringLiteral in incodemaker/source/javamaker/javaoptions.cxx
and i18npool/source/breakiterator/breakiterator_unicode.cxx, which have been
replaced with OString::Concat (and which is arguably a better choice, anyway),
also caused failures with at least Clang 5.0.2 (but would not have caused
failures with at least recent Clang 12 trunk, so appear to be bugs in Clang that
have meanwhile been fixed).
This change also revealed a bug in at least recent Clang 12 trunk
CastExpr::getSubExprAsWritten (still to be reported to LLVM), triggered at least
in some calls from loplugin code (for which it can be fixed for now in the
existing compat::getSubStringAsWritten).
A similar commit for OUStringLiteral is planned, too.
Change-Id: Ib192f4ed4c44769512a16364cb55c25627bae6f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101814
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-31 21:19:22 +02:00
|
|
|
//
|
|
|
|
// include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*)
|
|
|
|
// [with X = clang::CXXConstructExpr; Y = clang::Expr;
|
|
|
|
// typename llvm::cast_retty<X, Y*>::ret_type = clang::CXXConstructExpr*]: Assertion
|
|
|
|
// `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
|
|
|
|
//
|
|
|
|
// for CastExprs involving ConstantExpr (introduced with
|
|
|
|
// <https://github.com/llvm/llvm-project/commit/7c44da279e399d302a685c500e7f802f8adf9762> "Create
|
|
|
|
// ConstantExpr class" towards LLVM 8) like
|
|
|
|
//
|
|
|
|
// CXXFunctionalCastExpr 0xc01c4e8 'class rtl::OStringLiteral<9>':'class rtl::OStringLiteral<9>' functional cast to OStringLiteral <ConstructorConversion>
|
|
|
|
// `-ConstantExpr 0xc01c380 'class rtl::OStringLiteral<9>':'class rtl::OStringLiteral<9>'
|
|
|
|
// |-value: Struct
|
|
|
|
// | |-fields: Int 1073741824, Int 8
|
|
|
|
// | `-field: Array size=9
|
|
|
|
// | |-elements: Int 46, Int 111, Int 115, Int 108
|
|
|
|
// | |-elements: Int 45, Int 116, Int 109, Int 112
|
|
|
|
// | `-element: Int 0
|
|
|
|
// `-CXXConstructExpr 0xc01c350 'class rtl::OStringLiteral<9>':'class rtl::OStringLiteral<9>' 'void (const char (&)[9])'
|
|
|
|
// `-StringLiteral 0xc019ad8 'const char [9]' lvalue ".osl-tmp"
|
|
|
|
//
|
2017-05-19 23:51:46 +02:00
|
|
|
// Copies code from Clang's lib/AST/Expr.cpp:
|
|
|
|
namespace detail {
|
|
|
|
inline clang::Expr *skipImplicitTemporary(clang::Expr *expr) {
|
|
|
|
// Skip through reference binding to temporary.
|
|
|
|
if (clang::MaterializeTemporaryExpr *Materialize
|
|
|
|
= clang::dyn_cast<clang::MaterializeTemporaryExpr>(expr))
|
2019-11-25 13:04:02 +01:00
|
|
|
expr = compat::getSubExpr(Materialize);
|
2017-05-19 23:51:46 +02:00
|
|
|
|
|
|
|
// Skip any temporary bindings; they're implicit.
|
|
|
|
if (clang::CXXBindTemporaryExpr *Binder = clang::dyn_cast<clang::CXXBindTemporaryExpr>(expr))
|
|
|
|
expr = Binder->getSubExpr();
|
|
|
|
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline clang::Expr *getSubExprAsWritten(clang::CastExpr *This) {
|
|
|
|
clang::Expr *SubExpr = nullptr;
|
|
|
|
clang::CastExpr *E = This;
|
|
|
|
do {
|
|
|
|
SubExpr = detail::skipImplicitTemporary(E->getSubExpr());
|
|
|
|
|
|
|
|
// Conversions by constructor and conversion functions have a
|
|
|
|
// subexpression describing the call; strip it off.
|
|
|
|
if (E->getCastKind() == clang::CK_ConstructorConversion)
|
|
|
|
SubExpr =
|
Turn OStringLiteral into a consteval'ed, static-refcound rtl_String
...from which an OString can cheaply be instantiated.
The one downside is that OStringLiteral now needs to be a template abstracting
over the string length. But any uses for which that is a problem (e.g., as the
element type of a containers that would no longer be homogeneous, or in the
signature of a function that shall not be turned into a template for one reason
or another) can be replaced with std::string_view, without loss of efficiency
compared to the original OStringLiteral, and without loss of expressivity (esp.
with the newly introduced OString(std::string_view) ctor).
The new OStringLiteral ctor code would probably not be very efficient if it were
ever executed at runtime, but it is intended to be only executed at compile
time. Where available, C++20 "consteval" is used to statically ensure that.
The intended use of the new OStringLiteral is in all cases where an
object that shall itself not be an OString (e.g., because it shall be a
global static variable for which the OString ctor/dtor would be detrimental at
library load/unload) must be converted to an OString instance in at least one
place. Other string literal abstractions could use std::string_view (or just
plain char const[N]), but interestingly OStringLiteral might be more efficient
than constexpr std::string_view even for such cases, as it should not need any
relocations at library load time. For now, no existing uses of OUStringLiteral
have been changed to some other abstraction (unless technically necessary as
discussed above), and no additional places that would benefit from
OUStringLiteral have been changed to use it.
sal/qa/rtl/strings/test_ostring_concat.cxx documents some workarounds for GCC
bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96878> "Failed class template
argument deduction in unevaluated, parenthesized context". Those places, as
well as uses of OStringLiteral in incodemaker/source/javamaker/javaoptions.cxx
and i18npool/source/breakiterator/breakiterator_unicode.cxx, which have been
replaced with OString::Concat (and which is arguably a better choice, anyway),
also caused failures with at least Clang 5.0.2 (but would not have caused
failures with at least recent Clang 12 trunk, so appear to be bugs in Clang that
have meanwhile been fixed).
This change also revealed a bug in at least recent Clang 12 trunk
CastExpr::getSubExprAsWritten (still to be reported to LLVM), triggered at least
in some calls from loplugin code (for which it can be fixed for now in the
existing compat::getSubStringAsWritten).
A similar commit for OUStringLiteral is planned, too.
Change-Id: Ib192f4ed4c44769512a16364cb55c25627bae6f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101814
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-31 21:19:22 +02:00
|
|
|
detail::skipImplicitTemporary(clang::cast<clang::CXXConstructExpr>(SubExpr->IgnoreImplicit())->getArg(0));
|
2017-05-19 23:51:46 +02:00
|
|
|
else if (E->getCastKind() == clang::CK_UserDefinedConversion) {
|
|
|
|
assert((clang::isa<clang::CXXMemberCallExpr>(SubExpr) ||
|
|
|
|
clang::isa<clang::BlockExpr>(SubExpr)) &&
|
|
|
|
"Unexpected SubExpr for CK_UserDefinedConversion.");
|
|
|
|
if (clang::isa<clang::CXXMemberCallExpr>(SubExpr))
|
|
|
|
SubExpr = clang::cast<clang::CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the subexpression we're left with is an implicit cast, look
|
|
|
|
// through that, too.
|
|
|
|
} while ((E = clang::dyn_cast<clang::ImplicitCastExpr>(SubExpr)));
|
|
|
|
|
|
|
|
return SubExpr;
|
|
|
|
}
|
|
|
|
inline const clang::Expr *getSubExprAsWritten(const clang::CastExpr *This) {
|
|
|
|
return getSubExprAsWritten(const_cast<clang::CastExpr *>(This));
|
|
|
|
}
|
2020-08-31 22:01:15 +02:00
|
|
|
#endif
|
2017-05-19 23:51:46 +02:00
|
|
|
|
2019-10-14 11:42:20 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-05-15 08:39:40 +02:00
|
|
|
inline bool isExplicitSpecified(clang::CXXConstructorDecl const * decl) {
|
2019-05-26 13:49:23 +02:00
|
|
|
#if CLANG_VERSION >= 90000
|
2019-05-15 08:39:40 +02:00
|
|
|
return decl->getExplicitSpecifier().isExplicit();
|
|
|
|
#else
|
|
|
|
return decl->isExplicitSpecified();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isExplicitSpecified(clang::CXXConversionDecl const * decl) {
|
2019-05-26 13:49:23 +02:00
|
|
|
#if CLANG_VERSION >= 90000
|
2019-05-15 08:39:40 +02:00
|
|
|
return decl->getExplicitSpecifier().isExplicit();
|
|
|
|
#else
|
|
|
|
return decl->isExplicitSpecified();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-30 17:59:29 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:45:36 +02:00
|
|
|
inline bool isComparisonOp(clang::CXXOperatorCallExpr const * callExpr)
|
|
|
|
{
|
2022-02-15 15:21:06 +01:00
|
|
|
#if CLANG_VERSION >= 110000
|
|
|
|
return callExpr->isComparisonOp();
|
|
|
|
#else
|
2020-08-04 08:45:36 +02:00
|
|
|
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;
|
2022-02-15 15:21:06 +01:00
|
|
|
#endif
|
2020-08-04 08:45:36 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 16:37:50 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-22 08:10:58 +02:00
|
|
|
#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
|
|
|
|
|
2015-03-25 15:37:53 +02:00
|
|
|
}
|
|
|
|
|
2014-01-31 09:37:27 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|