Skip to content

Commit 09217b6

Browse files
committed
[lldb][NFC] Add a CompilerDecl->clang::Decl conversion function to ClangUtil
This automatically does the type checking for the cast.
1 parent 1ccc702 commit 09217b6

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

lldb/include/lldb/Symbol/ClangUtil.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ namespace lldb_private {
2424
struct ClangUtil {
2525
static bool IsClangType(const CompilerType &ct);
2626

27+
/// Returns the clang::Decl of the given CompilerDecl.
28+
/// CompilerDecl has to be valid and represent a clang::Decl.
29+
static clang::Decl *GetDecl(const CompilerDecl &decl);
30+
2731
static clang::QualType GetQualType(const CompilerType &ct);
2832

2933
static clang::QualType GetCanonicalQualType(const CompilerType &ct);

lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h"
1010

11+
#include "lldb/Symbol/ClangUtil.h"
1112
#include "lldb/Symbol/TypeSystemClang.h"
1213
#include "lldb/Utility/ConstString.h"
1314

@@ -22,7 +23,7 @@ uint32_t ClangDeclVendor::FindDecls(ConstString name, bool append,
2223
std::vector<CompilerDecl> compiler_decls;
2324
uint32_t ret = FindDecls(name, /*append*/ false, max_matches, compiler_decls);
2425
for (CompilerDecl compiler_decl : compiler_decls) {
25-
clang::Decl *d = static_cast<clang::Decl *>(compiler_decl.GetOpaqueDecl());
26+
clang::Decl *d = ClangUtil::GetDecl(compiler_decl);
2627
clang::NamedDecl *nd = llvm::cast<clang::NamedDecl>(d);
2728
decls.push_back(nd);
2829
}

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ PdbAstBuilder::ToCompilerDeclContext(clang::DeclContext &context) {
13471347
}
13481348

13491349
clang::Decl * PdbAstBuilder::FromCompilerDecl(CompilerDecl decl) {
1350-
return static_cast<clang::Decl *>(decl.GetOpaqueDecl());
1350+
return ClangUtil::GetDecl(decl);
13511351
}
13521352

13531353
clang::DeclContext *

lldb/source/Symbol/ClangUtil.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ bool ClangUtil::IsClangType(const CompilerType &ct) {
2828
return true;
2929
}
3030

31+
clang::Decl *ClangUtil::GetDecl(const CompilerDecl &decl) {
32+
assert(llvm::isa<TypeSystemClang>(decl.GetTypeSystem()));
33+
return static_cast<clang::Decl *>(decl.GetOpaqueDecl());
34+
}
35+
3136
QualType ClangUtil::GetQualType(const CompilerType &ct) {
3237
// Make sure we have a clang type before making a clang::QualType
3338
if (!IsClangType(ct))

0 commit comments

Comments
 (0)