[Lldb-commits] [lldb] 09217b6 - [lldb][NFC] Add a CompilerDecl->clang::Decl conversion function to ClangUtil
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 31 04:20:23 PST 2020
Author: Raphael Isemann
Date: 2020-01-31T13:20:02+01:00
New Revision: 09217b60fcf1301e0333a69c37c6408d81c46ca5
URL: https://github.com/llvm/llvm-project/commit/09217b60fcf1301e0333a69c37c6408d81c46ca5
DIFF: https://github.com/llvm/llvm-project/commit/09217b60fcf1301e0333a69c37c6408d81c46ca5.diff
LOG: [lldb][NFC] Add a CompilerDecl->clang::Decl conversion function to ClangUtil
This automatically does the type checking for the cast.
Added:
Modified:
lldb/include/lldb/Symbol/ClangUtil.h
lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
lldb/source/Symbol/ClangUtil.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Symbol/ClangUtil.h b/lldb/include/lldb/Symbol/ClangUtil.h
index 5ffbce340e59..31e86cae5c3e 100644
--- a/lldb/include/lldb/Symbol/ClangUtil.h
+++ b/lldb/include/lldb/Symbol/ClangUtil.h
@@ -24,6 +24,10 @@ namespace lldb_private {
struct ClangUtil {
static bool IsClangType(const CompilerType &ct);
+ /// Returns the clang::Decl of the given CompilerDecl.
+ /// CompilerDecl has to be valid and represent a clang::Decl.
+ static clang::Decl *GetDecl(const CompilerDecl &decl);
+
static clang::QualType GetQualType(const CompilerType &ct);
static clang::QualType GetCanonicalQualType(const CompilerType &ct);
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
index 54865ae3ea13..f5b0c216902a 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangDeclVendor.cpp
@@ -8,6 +8,7 @@
#include "Plugins/ExpressionParser/Clang/ClangDeclVendor.h"
+#include "lldb/Symbol/ClangUtil.h"
#include "lldb/Symbol/TypeSystemClang.h"
#include "lldb/Utility/ConstString.h"
@@ -22,7 +23,7 @@ uint32_t ClangDeclVendor::FindDecls(ConstString name, bool append,
std::vector<CompilerDecl> compiler_decls;
uint32_t ret = FindDecls(name, /*append*/ false, max_matches, compiler_decls);
for (CompilerDecl compiler_decl : compiler_decls) {
- clang::Decl *d = static_cast<clang::Decl *>(compiler_decl.GetOpaqueDecl());
+ clang::Decl *d = ClangUtil::GetDecl(compiler_decl);
clang::NamedDecl *nd = llvm::cast<clang::NamedDecl>(d);
decls.push_back(nd);
}
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
index 806f7b60bfff..aa9fff3e4acb 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -1347,7 +1347,7 @@ PdbAstBuilder::ToCompilerDeclContext(clang::DeclContext &context) {
}
clang::Decl * PdbAstBuilder::FromCompilerDecl(CompilerDecl decl) {
- return static_cast<clang::Decl *>(decl.GetOpaqueDecl());
+ return ClangUtil::GetDecl(decl);
}
clang::DeclContext *
diff --git a/lldb/source/Symbol/ClangUtil.cpp b/lldb/source/Symbol/ClangUtil.cpp
index 74d95bac4a97..2f3307ee1a5d 100644
--- a/lldb/source/Symbol/ClangUtil.cpp
+++ b/lldb/source/Symbol/ClangUtil.cpp
@@ -28,6 +28,11 @@ bool ClangUtil::IsClangType(const CompilerType &ct) {
return true;
}
+clang::Decl *ClangUtil::GetDecl(const CompilerDecl &decl) {
+ assert(llvm::isa<TypeSystemClang>(decl.GetTypeSystem()));
+ return static_cast<clang::Decl *>(decl.GetOpaqueDecl());
+}
+
QualType ClangUtil::GetQualType(const CompilerType &ct) {
// Make sure we have a clang type before making a clang::QualType
if (!IsClangType(ct))
More information about the lldb-commits
mailing list