diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-12-30 21:20:01 +0100 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2020-01-02 11:54:45 +0100 |
commit | fe8e25a48a2a0f8f508499ba950181dba3d600b0 (patch) | |
tree | 00b7970625121b4b408d3b7de6f1b97f55a78a48 /lldb/source/Plugins/LanguageRuntime | |
parent | a2976c490da3b6d7253d4034ae507a760457ea18 (diff) | |
download | bcm5719-llvm-fe8e25a48a2a0f8f508499ba950181dba3d600b0.tar.gz bcm5719-llvm-fe8e25a48a2a0f8f508499ba950181dba3d600b0.zip |
[lldb][NFC] Create type-safe function for creating a CompilerType from a QualType
LLDB frequently converts QualType to CompilerType. This is currently done like this:
result = CompilerType(this, qual_type_var.getAsOpaquePtr())
There are a few shortcomings in this current approach:
1. CompilerType's constructor takes a void* pointer so it isn't type safe.
2. We can't add any sanity checks to the CompilerType constructor (e.g. that the type
actually belongs to the passed ClangASTContext) without expanding the TypeSystem API.
3. The logic for converting QualType->CompilerType is spread out over all of LLDB so
changing it is difficult (e.g., what if we want to just pass the type ptr and not the
1type_ptr | qual_flags1 to CompilerType).
This patch adds a `ClangASTContext::GetType` function similar to the other GetTypeForDecl
functions that does this conversion in a type safe way.
It also adds a sanity check for Tag-based types that the type actually belongs to the
current ClangASTContext (Types don't seem to know their ASTContext, so we have to
workaround by looking at the decl for the underlying TagDecl. This doesn't cover all types
we construct but it's better than no sanity check).
Diffstat (limited to 'lldb/source/Plugins/LanguageRuntime')
-rw-r--r-- | lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp index 5fa4073f40b..d92f782c72e 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp @@ -137,8 +137,7 @@ clang::QualType AppleObjCTypeEncodingParser::BuildAggregate( element.name = elem_name.GetString(); } ClangASTContext::AddFieldToRecordType( - union_type, element.name.c_str(), - CompilerType(&ast_ctx, element.type.getAsOpaquePtr()), + union_type, element.name.c_str(), ast_ctx.GetType(element.type), lldb::eAccessPublic, element.bitfield); ++count; } @@ -362,7 +361,7 @@ CompilerType AppleObjCTypeEncodingParser::RealizeType(ClangASTContext &ast_ctx, if (name && name[0]) { StringLexer lexer(name); clang::QualType qual_type = BuildType(ast_ctx, lexer, for_expression); - return CompilerType(&ast_ctx, qual_type.getAsOpaquePtr()); + return ast_ctx.GetType(qual_type); } return CompilerType(); } |