File indexing completed on 2024-04-21 05:38:48

0001 /*
0002     SPDX-FileCopyrightText: 2018 Sergio Martins <smartins@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef SOURCE_COMPAT_HELPERS
0008 #define SOURCE_COMPAT_HELPERS
0009 
0010 #include <clang/AST/Attr.h>
0011 #include <clang/AST/Decl.h>
0012 #include <clang/AST/DeclCXX.h>
0013 #include <clang/AST/Expr.h>
0014 #include <clang/Basic/SourceLocation.h>
0015 #include <clang/Basic/SourceManager.h>
0016 #include <clang/Frontend/FrontendDiagnostic.h>
0017 #include <clang/Lex/Lexer.h>
0018 #include <clang/Tooling/Core/Diagnostic.h>
0019 
0020 namespace clazy
0021 {
0022 
0023 inline auto getBuffer(const clang::SourceManager &sm, clang::FileID id, bool *invalid)
0024 {
0025 #if LLVM_VERSION_MAJOR >= 16
0026     auto buffer = sm.getBufferOrNone(id);
0027     *invalid = !buffer.has_value();
0028     return buffer;
0029 #elif LLVM_VERSION_MAJOR >= 12
0030     auto buffer = sm.getBufferOrNone(id);
0031     *invalid = !buffer.hasValue();
0032     return buffer;
0033 #else
0034     return sm.getBuffer(id, invalid);
0035 #endif
0036 }
0037 
0038 #if LLVM_VERSION_MAJOR >= 16
0039 #define GET_LEXER(id, inputFile, sm, lo) clang::Lexer(id, inputFile.value(), sm, lo)
0040 #elif LLVM_VERSION_MAJOR >= 12
0041 #define GET_LEXER(id, inputFile, sm, lo) clang::Lexer(id, inputFile.getValue(), sm, lo)
0042 #else
0043 #define GET_LEXER(id, inputFile, sm, lo) clang::Lexer(id, inputFile, sm, lo)
0044 #endif
0045 
0046 inline bool contains_lower(clang::StringRef haystack, clang::StringRef needle)
0047 {
0048 #if LLVM_VERSION_MAJOR >= 13
0049     return haystack.contains_insensitive(needle);
0050 #else
0051     return haystack.contains_lower(needle);
0052 #endif
0053 }
0054 
0055 inline bool isAscii(clang::StringLiteral *lt)
0056 {
0057 #if LLVM_VERSION_MAJOR >= 15
0058     return lt->isOrdinary();
0059 #else
0060     return lt->isAscii();
0061 #endif
0062 }
0063 
0064 }
0065 
0066 #endif