Use LLVM casting for TypeSystem so you can cast it to subclasses.
This will keep our code cleaner and it removes the need for intrusive additions to TypeSystem like:
class TypeSystem
{
virtual ClangASTContext *
AsClangASTContext() = 0;
}
As you can now just use the llvm::dyn_cast and other casts.
llvm-svn: 247041
diff --git a/lldb/source/Expression/ClangASTSource.cpp b/lldb/source/Expression/ClangASTSource.cpp
index 6d853f3..ef778a1 100644
--- a/lldb/source/Expression/ClangASTSource.cpp
+++ b/lldb/source/Expression/ClangASTSource.cpp
@@ -1889,15 +1889,12 @@
CompilerType
ClangASTSource::GuardedCopyType (const CompilerType &src_type)
{
- if (!ClangASTContext::IsClangType(src_type))
+ ClangASTContext *src_ast = llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
+ if (src_ast == nullptr)
return CompilerType();
-
+
ClangASTMetrics::RegisterLLDBImport();
- ClangASTContext* src_ast = src_type.GetTypeSystem()->AsClangASTContext();
- if (!src_ast)
- return CompilerType();
-
SetImportInProgress(true);
QualType copied_qual_type = m_ast_importer->CopyType (m_ast_context, src_ast->getASTContext(), ClangASTContext::GetQualType(src_type));
@@ -1920,7 +1917,7 @@
if (!type.IsValid())
return NULL;
- ClangASTContext* lldb_ast = type.GetTypeSystem()->AsClangASTContext();
+ ClangASTContext* lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
if (!lldb_ast)
return NULL;
@@ -1952,7 +1949,7 @@
if (m_function_types.count(type))
return NULL;
- ClangASTContext* lldb_ast = type.GetTypeSystem()->AsClangASTContext();
+ ClangASTContext* lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
if (!lldb_ast)
return NULL;
diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp
index cba1122..42696a0 100644
--- a/lldb/source/Expression/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp
@@ -194,19 +194,23 @@
{
assert (m_parser_vars.get());
+ ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(parser_type.GetTypeSystem());
+ if (ast == nullptr)
+ return false;
+
if (m_parser_vars->m_materializer && is_result)
{
Error err;
ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
Target *target = exe_ctx.GetTargetPtr();
- if (target == NULL)
+ if (target == nullptr)
return false;
ClangASTContext *context(target->GetScratchClangASTContext());
TypeFromUser user_type(m_ast_importer->DeportType(context->getASTContext(),
- parser_type.GetTypeSystem()->AsClangASTContext()->getASTContext(),
+ ast->getASTContext(),
parser_type.GetOpaqueQualType()),
context);
@@ -247,7 +251,7 @@
ClangASTContext *context(target->GetScratchClangASTContext());
TypeFromUser user_type(m_ast_importer->DeportType(context->getASTContext(),
- parser_type.GetTypeSystem()->AsClangASTContext()->getASTContext(),
+ ast->getASTContext(),
parser_type.GetOpaqueQualType()),
context);