|
14 | 14 | #include "clang/Frontend/CompilerInstance.h" |
15 | 15 | #include "clang/Tooling/CommonOptionsParser.h" |
16 | 16 | #include "clang/Tooling/Tooling.h" |
| 17 | +#include "llvm/Config/llvm-config.h" |
17 | 18 | #include "llvm/Support/Casting.h" |
18 | 19 | #include "llvm/Support/CommandLine.h" |
19 | 20 | #include "llvm/Support/ErrorHandling.h" |
|
23 | 24 | #include <string> |
24 | 25 | #include <unordered_map> |
25 | 26 |
|
| 27 | +// LLVM 16 renamed dyn_cast_or_null to dyn_cast_if_present |
| 28 | +#if LLVM_VERSION_MAJOR < 16 |
| 29 | +#define dyn_cast_if_present dyn_cast_or_null |
| 30 | +#endif |
| 31 | + |
26 | 32 | using namespace clang; |
27 | 33 |
|
28 | 34 | // MacroDef/MacroMap hold information about macros defined in the file. |
@@ -203,7 +209,7 @@ bool Indexer::TraverseCallExpr(CallExpr* CE) { |
203 | 209 | } |
204 | 210 |
|
205 | 211 | bool Indexer::VisitDeclRefExpr(const DeclRefExpr* DeclRef) { |
206 | | - if (const auto* Func = dyn_cast<FunctionDecl>(DeclRef->getDecl())) |
| 212 | + if (const auto* Func = dyn_cast_if_present<FunctionDecl>(DeclRef->getDecl())) |
207 | 213 | EmitReference(DeclRef->getBeginLoc(), DeclRef->getDecl(), EntityKindFunction, |
208 | 214 | InCallee ? RefKindCall : RefKindTakesAddr); |
209 | 215 | return true; |
@@ -246,25 +252,25 @@ bool Indexer::VisitTypedefType(const TypedefType* T) { |
246 | 252 | return true; |
247 | 253 | EmitReference(TypeRefingLocation, T->getDecl(), EntityKindTypedef, RefKindUses); |
248 | 254 | // If it's a struct typedef, also note the struct use. |
249 | | - if (const auto* Tag = dyn_cast<TagType>(T->getCanonicalTypeInternal().getTypePtr())) |
| 255 | + if (const auto* Tag = dyn_cast_if_present<TagType>(T->getCanonicalTypeInternal().getTypePtr())) |
250 | 256 | VisitTagType(Tag); |
251 | 257 | return true; |
252 | 258 | } |
253 | 259 |
|
254 | 260 | bool Indexer::VisitMemberExpr(const MemberExpr* E) { |
255 | 261 | auto* Record = E->getBase()->getType()->getAsRecordDecl(); |
256 | | - if (auto* Ptr = dyn_cast<PointerType>(E->getBase()->getType())) |
| 262 | + if (auto* Ptr = dyn_cast_if_present<PointerType>(E->getBase()->getType())) |
257 | 263 | Record = Ptr->getPointeeType()->getAsRecordDecl(); |
258 | 264 | if (!Record) |
259 | 265 | return true; |
260 | 266 | const std::string Field = Record->getNameAsString() + "::" + E->getMemberDecl()->getNameAsString(); |
261 | 267 | const char* RefKind = RefKindRead; |
262 | 268 | const Stmt* P = GetParent(E); |
263 | | - if (auto* BO = dyn_cast<BinaryOperator>(P)) { |
| 269 | + if (auto* BO = dyn_cast_if_present<BinaryOperator>(P)) { |
264 | 270 | if (E == BO->getLHS() && (BO->isAssignmentOp() || BO->isCompoundAssignmentOp() || BO->isShiftAssignOp())) |
265 | 271 | RefKind = RefKindWrite; |
266 | 272 | } |
267 | | - if (auto* UO = dyn_cast<UnaryOperator>(P)) |
| 273 | + if (auto* UO = dyn_cast_if_present<UnaryOperator>(P)) |
268 | 274 | RefKind = RefKindTakesAddr; |
269 | 275 | EmitReference(E->getMemberLoc(), Field, EntityKindField, RefKind); |
270 | 276 | return true; |
|
0 commit comments