summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp')
-rw-r--r--contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp67
1 files changed, 53 insertions, 14 deletions
diff --git a/contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp b/contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp
index addff1a..ad4337f 100644
--- a/contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp
+++ b/contrib/llvm/tools/lldb/source/Symbol/ClangASTContext.cpp
@@ -11,6 +11,7 @@
// C Includes
// C++ Includes
+#include <mutex>
#include <string>
// Other libraries and framework includes
@@ -62,6 +63,7 @@
#include "lldb/Core/Flags.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/RegularExpression.h"
+#include "lldb/Core/ThreadSafeDenseMap.h"
#include "lldb/Core/UniqueCStringMap.h"
#include "lldb/Expression/ASTDumper.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
@@ -79,13 +81,17 @@ using namespace lldb_private;
using namespace llvm;
using namespace clang;
-typedef llvm::DenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap;
+typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap;
static ClangASTMap &
GetASTMap()
{
- static ClangASTMap g_map;
- return g_map;
+ static ClangASTMap *g_map_ptr = nullptr;
+ static std::once_flag g_once_flag;
+ std::call_once(g_once_flag, []() {
+ g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins
+ });
+ return *g_map_ptr;
}
@@ -303,7 +309,7 @@ ClangASTContext::~ClangASTContext()
{
if (m_ast_ap.get())
{
- GetASTMap().erase(m_ast_ap.get());
+ GetASTMap().Erase(m_ast_ap.get());
}
m_builtins_ap.reset();
@@ -409,7 +415,7 @@ ClangASTContext::getASTContext()
m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false);
- GetASTMap().insert(std::make_pair(m_ast_ap.get(), this));
+ GetASTMap().Insert(m_ast_ap.get(), this);
}
return m_ast_ap.get();
}
@@ -417,7 +423,7 @@ ClangASTContext::getASTContext()
ClangASTContext*
ClangASTContext::GetASTContext (clang::ASTContext* ast)
{
- ClangASTContext *clang_ast = GetASTMap().lookup(ast);
+ ClangASTContext *clang_ast = GetASTMap().Lookup(ast);
return clang_ast;
}
@@ -883,6 +889,13 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
break;
case DW_ATE_float:
+ if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
+ return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr());
+ if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
+ return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr());
+ if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
+ return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr());
+ // Fall back to not requring a name match
if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr());
if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
@@ -1119,6 +1132,16 @@ ClangASTContext::AreTypesSame (ClangASTType type1,
return ast->hasSameType (type1_qual, type2_qual);
}
+ClangASTType
+ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl)
+{
+ if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
+ return GetTypeForDecl(interface_decl);
+ if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
+ return GetTypeForDecl(tag_decl);
+ return ClangASTType();
+}
+
ClangASTType
ClangASTContext::GetTypeForDecl (TagDecl *decl)
@@ -1126,7 +1149,7 @@ ClangASTContext::GetTypeForDecl (TagDecl *decl)
// No need to call the getASTContext() accessor (which can create the AST
// if it isn't created yet, because we can't have created a decl in this
// AST if our AST didn't already exist...
- ASTContext *ast = m_ast_ap.get();
+ ASTContext *ast = &decl->getASTContext();
if (ast)
return ClangASTType (ast, ast->getTagDeclType(decl).getAsOpaquePtr());
return ClangASTType();
@@ -1138,7 +1161,7 @@ ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl)
// No need to call the getASTContext() accessor (which can create the AST
// if it isn't created yet, because we can't have created a decl in this
// AST if our AST didn't already exist...
- ASTContext *ast = m_ast_ap.get();
+ ASTContext *ast = &decl->getASTContext();
if (ast)
return ClangASTType (ast, ast->getObjCInterfaceType(decl).getAsOpaquePtr());
return ClangASTType();
@@ -1733,7 +1756,7 @@ ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
DeclarationName (&ast->Idents.get(name)),
function_clang_type.GetQualType(),
nullptr,
- (FunctionDecl::StorageClass)storage,
+ (clang::StorageClass)storage,
is_inline,
hasWrittenPrototype,
isConstexprSpecified);
@@ -1747,7 +1770,7 @@ ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
DeclarationName (),
function_clang_type.GetQualType(),
nullptr,
- (FunctionDecl::StorageClass)storage,
+ (clang::StorageClass)storage,
is_inline,
hasWrittenPrototype,
isConstexprSpecified);
@@ -1801,7 +1824,7 @@ ClangASTContext::CreateParameterDeclaration (const char *name, const ClangASTTyp
name && name[0] ? &ast->Idents.get(name) : nullptr,
param_type.GetQualType(),
nullptr,
- (VarDecl::StorageClass)storage,
+ (clang::StorageClass)storage,
nullptr);
}
@@ -1851,7 +1874,23 @@ ClangASTContext::CreateArrayType (const ClangASTType &element_type,
return ClangASTType();
}
-
+ClangASTType
+ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name,
+ const std::initializer_list< std::pair < const char *, ClangASTType > >& type_fields,
+ bool packed)
+{
+ ClangASTType type;
+ if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
+ return type;
+ type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC);
+ type.StartTagDeclarationDefinition();
+ for (const auto& field : type_fields)
+ type.AddFieldToRecordType(field.first, field.second, lldb::eAccessPublic, 0);
+ if (packed)
+ type.SetIsPacked();
+ type.CompleteTagDeclarationDefinition();
+ return type;
+}
#pragma mark Enumeration Types
@@ -2069,7 +2108,7 @@ ClangASTContext::SetMetadata (clang::ASTContext *ast,
ClangASTMetadata &metadata)
{
ClangExternalASTSourceCommon *external_source =
- static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource());
+ ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
if (external_source)
external_source->SetMetadata(object, metadata);
@@ -2080,7 +2119,7 @@ ClangASTContext::GetMetadata (clang::ASTContext *ast,
const void *object)
{
ClangExternalASTSourceCommon *external_source =
- static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource());
+ ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
if (external_source && external_source->HasMetadata(object))
return external_source->GetMetadata(object);
OpenPOWER on IntegriCloud