summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2019-12-26 14:52:43 +0100
committerRaphael Isemann <teemperor@gmail.com>2019-12-26 16:23:40 +0100
commit37339d1426d1092aeb6ba3a4939b9efd6c1e2987 (patch)
treeababab36e6488a0fc7b8adeb47138586759f733a
parent54c522420347e58aa7bae1892cf5c5672b57c875 (diff)
downloadbcm5719-llvm-37339d1426d1092aeb6ba3a4939b9efd6c1e2987.tar.gz
bcm5719-llvm-37339d1426d1092aeb6ba3a4939b9efd6c1e2987.zip
[lldb][NFC] Use ClangASTContext in AppleObjCRuntime interfaces
This code actually needs a ClangASTContext but instead takes a clang::ASTContext and then retrieves the original ClangASTContext via the global map of ClangASTContexts. Let's change it so that it takes a ClangASTContext which is simpler and faster.
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp14
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp62
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h20
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp6
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h5
5 files changed, 46 insertions, 61 deletions
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
index 063b995ff79..54f8397e1da 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -311,7 +311,8 @@ public:
}
clang::ObjCMethodDecl *
- BuildMethod(clang::ObjCInterfaceDecl *interface_decl, const char *name,
+ BuildMethod(ClangASTContext &clang_ast_ctxt,
+ clang::ObjCInterfaceDecl *interface_decl, const char *name,
bool instance,
ObjCLanguageRuntime::EncodingToTypeSP type_realizer_sp) {
if (!m_is_valid || m_type_vector.size() < 3)
@@ -360,8 +361,7 @@ public:
clang::QualType ret_type =
ClangUtil::GetQualType(type_realizer_sp->RealizeType(
- interface_decl->getASTContext(), m_type_vector[0].c_str(),
- for_expression));
+ clang_ast_ctxt, m_type_vector[0].c_str(), for_expression));
if (ret_type.isNull())
return nullptr;
@@ -378,7 +378,7 @@ public:
const bool for_expression = true;
clang::QualType arg_type =
ClangUtil::GetQualType(type_realizer_sp->RealizeType(
- ast_ctx, m_type_vector[ai].c_str(), for_expression));
+ clang_ast_ctxt, m_type_vector[ai].c_str(), for_expression));
if (arg_type.isNull())
return nullptr; // well, we just wasted a bunch of time. Wish we could
@@ -455,8 +455,8 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) {
ObjCRuntimeMethodType method_type(types);
- clang::ObjCMethodDecl *method_decl =
- method_type.BuildMethod(interface_decl, name, true, m_type_realizer_sp);
+ clang::ObjCMethodDecl *method_decl = method_type.BuildMethod(
+ m_ast_ctx, interface_decl, name, true, m_type_realizer_sp);
LLDB_LOGF(log, "[ AOTV::FD] Instance method [%s] [%s]", name, types);
@@ -474,7 +474,7 @@ bool AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl) {
ObjCRuntimeMethodType method_type(types);
clang::ObjCMethodDecl *method_decl = method_type.BuildMethod(
- interface_decl, name, false, m_type_realizer_sp);
+ m_ast_ctx, interface_decl, name, false, m_type_realizer_sp);
LLDB_LOGF(log, "[ AOTV::FD] Class method [%s] [%s]", name, types);
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
index 76375e22ad6..5fa4073f40b 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
@@ -63,7 +63,7 @@ AppleObjCTypeEncodingParser::StructElement::StructElement()
: name(""), type(clang::QualType()), bitfield(0) {}
AppleObjCTypeEncodingParser::StructElement
-AppleObjCTypeEncodingParser::ReadStructElement(clang::ASTContext &ast_ctx,
+AppleObjCTypeEncodingParser::ReadStructElement(ClangASTContext &ast_ctx,
StringLexer &type,
bool for_expression) {
StructElement retval;
@@ -78,19 +78,19 @@ AppleObjCTypeEncodingParser::ReadStructElement(clang::ASTContext &ast_ctx,
}
clang::QualType AppleObjCTypeEncodingParser::BuildStruct(
- clang::ASTContext &ast_ctx, StringLexer &type, bool for_expression) {
+ ClangASTContext &ast_ctx, StringLexer &type, bool for_expression) {
return BuildAggregate(ast_ctx, type, for_expression, '{', '}',
clang::TTK_Struct);
}
clang::QualType AppleObjCTypeEncodingParser::BuildUnion(
- clang::ASTContext &ast_ctx, StringLexer &type, bool for_expression) {
+ ClangASTContext &ast_ctx, StringLexer &type, bool for_expression) {
return BuildAggregate(ast_ctx, type, for_expression, '(', ')',
clang::TTK_Union);
}
clang::QualType AppleObjCTypeEncodingParser::BuildAggregate(
- clang::ASTContext &ast_ctx, StringLexer &type, bool for_expression,
+ ClangASTContext &ast_ctx, StringLexer &type, bool for_expression,
char opener, char closer, uint32_t kind) {
if (!type.NextIf(opener))
return clang::QualType();
@@ -124,10 +124,7 @@ clang::QualType AppleObjCTypeEncodingParser::BuildAggregate(
if (is_templated)
return clang::QualType(); // This is where we bail out. Sorry!
- ClangASTContext *lldb_ctx = ClangASTContext::GetASTContext(&ast_ctx);
- if (!lldb_ctx)
- return clang::QualType();
- CompilerType union_type(lldb_ctx->CreateRecordType(
+ CompilerType union_type(ast_ctx.CreateRecordType(
nullptr, lldb::eAccessPublic, name, kind, lldb::eLanguageTypeC));
if (union_type) {
ClangASTContext::StartTagDeclarationDefinition(union_type);
@@ -141,8 +138,7 @@ clang::QualType AppleObjCTypeEncodingParser::BuildAggregate(
}
ClangASTContext::AddFieldToRecordType(
union_type, element.name.c_str(),
- CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
- element.type.getAsOpaquePtr()),
+ CompilerType(&ast_ctx, element.type.getAsOpaquePtr()),
lldb::eAccessPublic, element.bitfield);
++count;
}
@@ -152,20 +148,15 @@ clang::QualType AppleObjCTypeEncodingParser::BuildAggregate(
}
clang::QualType AppleObjCTypeEncodingParser::BuildArray(
- clang::ASTContext &ast_ctx, StringLexer &type, bool for_expression) {
+ ClangASTContext &ast_ctx, StringLexer &type, bool for_expression) {
if (!type.NextIf('['))
return clang::QualType();
uint32_t size = ReadNumber(type);
clang::QualType element_type(BuildType(ast_ctx, type, for_expression));
if (!type.NextIf(']'))
return clang::QualType();
- ClangASTContext *lldb_ctx = ClangASTContext::GetASTContext(&ast_ctx);
- if (!lldb_ctx)
- return clang::QualType();
- CompilerType array_type(lldb_ctx->CreateArrayType(
- CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
- element_type.getAsOpaquePtr()),
- size, false));
+ CompilerType array_type(ast_ctx.CreateArrayType(
+ CompilerType(&ast_ctx, element_type.getAsOpaquePtr()), size, false));
return ClangUtil::GetQualType(array_type);
}
@@ -175,10 +166,12 @@ clang::QualType AppleObjCTypeEncodingParser::BuildArray(
// consume but ignore the type info and always return an 'id'; if anything,
// dynamic typing will resolve things for us anyway
clang::QualType AppleObjCTypeEncodingParser::BuildObjCObjectPointerType(
- clang::ASTContext &ast_ctx, StringLexer &type, bool for_expression) {
+ ClangASTContext &clang_ast_ctx, StringLexer &type, bool for_expression) {
if (!type.NextIf('@'))
return clang::QualType();
+ clang::ASTContext &ast_ctx = clang_ast_ctx.getASTContext();
+
std::string name;
if (type.NextIf('"')) {
@@ -257,23 +250,25 @@ clang::QualType AppleObjCTypeEncodingParser::BuildObjCObjectPointerType(
}
clang::QualType
-AppleObjCTypeEncodingParser::BuildType(clang::ASTContext &ast_ctx,
+AppleObjCTypeEncodingParser::BuildType(ClangASTContext &clang_ast_ctx,
StringLexer &type, bool for_expression,
uint32_t *bitfield_bit_size) {
if (!type.HasAtLeast(1))
return clang::QualType();
+ clang::ASTContext &ast_ctx = clang_ast_ctx.getASTContext();
+
switch (type.Peek()) {
default:
break;
case '{':
- return BuildStruct(ast_ctx, type, for_expression);
+ return BuildStruct(clang_ast_ctx, type, for_expression);
case '[':
- return BuildArray(ast_ctx, type, for_expression);
+ return BuildArray(clang_ast_ctx, type, for_expression);
case '(':
- return BuildUnion(ast_ctx, type, for_expression);
+ return BuildUnion(clang_ast_ctx, type, for_expression);
case '@':
- return BuildObjCObjectPointerType(ast_ctx, type, for_expression);
+ return BuildObjCObjectPointerType(clang_ast_ctx, type, for_expression);
}
switch (type.Next()) {
@@ -289,10 +284,7 @@ AppleObjCTypeEncodingParser::BuildType(clang::ASTContext &ast_ctx,
case 'l':
return ast_ctx.getIntTypeForBitwidth(32, true);
// this used to be done like this:
- // ClangASTContext *lldb_ctx = ClangASTContext::GetASTContext(&ast_ctx);
- // if (!lldb_ctx)
- // return clang::QualType();
- // return lldb_ctx->GetIntTypeFromBitSize(32, true).GetQualType();
+ // return clang_ast_ctx->GetIntTypeFromBitSize(32, true).GetQualType();
// which uses one of the constants if one is available, but we don't think
// all this work is necessary.
case 'q':
@@ -331,7 +323,8 @@ AppleObjCTypeEncodingParser::BuildType(clang::ASTContext &ast_ctx,
return clang::QualType();
}
case 'r': {
- clang::QualType target_type = BuildType(ast_ctx, type, for_expression);
+ clang::QualType target_type =
+ BuildType(clang_ast_ctx, type, for_expression);
if (target_type.isNull())
return clang::QualType();
else if (target_type == ast_ctx.UnknownAnyTy)
@@ -348,7 +341,8 @@ AppleObjCTypeEncodingParser::BuildType(clang::ASTContext &ast_ctx,
// practical cases
return ast_ctx.VoidPtrTy;
} else {
- clang::QualType target_type = BuildType(ast_ctx, type, for_expression);
+ clang::QualType target_type =
+ BuildType(clang_ast_ctx, type, for_expression);
if (target_type.isNull())
return clang::QualType();
else if (target_type == ast_ctx.UnknownAnyTy)
@@ -362,13 +356,13 @@ AppleObjCTypeEncodingParser::BuildType(clang::ASTContext &ast_ctx,
}
}
-CompilerType AppleObjCTypeEncodingParser::RealizeType(
- clang::ASTContext &ast_ctx, const char *name, bool for_expression) {
+CompilerType AppleObjCTypeEncodingParser::RealizeType(ClangASTContext &ast_ctx,
+ const char *name,
+ bool for_expression) {
if (name && name[0]) {
StringLexer lexer(name);
clang::QualType qual_type = BuildType(ast_ctx, lexer, for_expression);
- return CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
- qual_type.getAsOpaquePtr());
+ return CompilerType(&ast_ctx, qual_type.getAsOpaquePtr());
}
return CompilerType();
}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h
index 590bc4ba9ea..e43711bf4ee 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.h
@@ -22,7 +22,7 @@ public:
AppleObjCTypeEncodingParser(ObjCLanguageRuntime &runtime);
~AppleObjCTypeEncodingParser() override = default;
- CompilerType RealizeType(clang::ASTContext &ast_ctx, const char *name,
+ CompilerType RealizeType(ClangASTContext &ast_ctx, const char *name,
bool for_expression) override;
private:
@@ -35,29 +35,29 @@ private:
~StructElement() = default;
};
- clang::QualType BuildType(clang::ASTContext &ast_ctx, StringLexer &type,
+ clang::QualType BuildType(ClangASTContext &clang_ast_ctx, StringLexer &type,
bool for_expression,
uint32_t *bitfield_bit_size = nullptr);
- clang::QualType BuildStruct(clang::ASTContext &ast_ctx, StringLexer &type,
+ clang::QualType BuildStruct(ClangASTContext &ast_ctx, StringLexer &type,
bool for_expression);
- clang::QualType BuildAggregate(clang::ASTContext &ast_ctx, StringLexer &type,
- bool for_expression, char opener, char closer,
- uint32_t kind);
+ clang::QualType BuildAggregate(ClangASTContext &clang_ast_ctx,
+ StringLexer &type, bool for_expression,
+ char opener, char closer, uint32_t kind);
- clang::QualType BuildUnion(clang::ASTContext &ast_ctx, StringLexer &type,
+ clang::QualType BuildUnion(ClangASTContext &ast_ctx, StringLexer &type,
bool for_expression);
- clang::QualType BuildArray(clang::ASTContext &ast_ctx, StringLexer &type,
+ clang::QualType BuildArray(ClangASTContext &ast_ctx, StringLexer &type,
bool for_expression);
std::string ReadStructName(StringLexer &type);
- StructElement ReadStructElement(clang::ASTContext &ast_ctx, StringLexer &type,
+ StructElement ReadStructElement(ClangASTContext &ast_ctx, StringLexer &type,
bool for_expression);
- clang::QualType BuildObjCObjectPointerType(clang::ASTContext &ast_ctx,
+ clang::QualType BuildObjCObjectPointerType(ClangASTContext &clang_ast_ctx,
StringLexer &type,
bool for_expression);
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
index 399bb120d7a..335ef996419 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -313,12 +313,6 @@ ObjCLanguageRuntime::EncodingToType::RealizeType(const char *name,
return CompilerType();
}
-CompilerType ObjCLanguageRuntime::EncodingToType::RealizeType(
- ClangASTContext &ast_ctx, const char *name, bool for_expression) {
- clang::ASTContext &clang_ast = ast_ctx.getASTContext();
- return RealizeType(clang_ast, name, for_expression);
-}
-
ObjCLanguageRuntime::EncodingToType::~EncodingToType() {}
ObjCLanguageRuntime::EncodingToTypeSP ObjCLanguageRuntime::GetEncodingToType() {
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
index 39acd6e9f26..069ce7facf5 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -145,12 +145,9 @@ public:
virtual ~EncodingToType();
virtual CompilerType RealizeType(ClangASTContext &ast_ctx, const char *name,
- bool for_expression);
+ bool for_expression) = 0;
virtual CompilerType RealizeType(const char *name, bool for_expression);
- virtual CompilerType RealizeType(clang::ASTContext &ast_ctx,
- const char *name, bool for_expression) = 0;
-
protected:
std::unique_ptr<ClangASTContext> m_scratch_ast_ctx_up;
};
OpenPOWER on IntegriCloud