10000 [Symbol] Decouple clang from CompilerType · adrian-prantl/llvm-project@bddab07 · GitHub
[go: up one dir, main page]

Skip to content

Commit bddab07

Browse files
committed
[Symbol] Decouple clang from CompilerType
Summary: Ideally CompilerType would have no knowledge of clang or any individual TypeSystem. Decoupling clang is relatively straightforward. Differential Revision: https://reviews.llvm.org/D66102 llvm-svn: 368741
1 parent 0fed494 commit bddab07

File tree

11 files changed

+584
-494
lines changed

11 files changed

+584
-494
lines changed

lldb/include/lldb/Symbol/ClangASTContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ class ClangASTContext : public TypeSystem {
229229
if (const RecordDeclType *record_decl =
230230
llvm::dyn_cast<RecordDeclType>(named_decl))
231231
compiler_type.SetCompilerType(
232-
ast, clang::QualType(record_decl->getTypeForDecl(), 0));
232+
this, clang::QualType(record_decl->getTypeForDecl(), 0)
233+
.getAsOpaquePtr());
233234
}
234235
}
235236
}

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <string>
1414
#include <vector>
1515

16-
#include "lldb/Core/ClangForward.h"
1716
#include "lldb/lldb-private.h"
1817
#include "llvm/ADT/APSInt.h"
1918

@@ -32,7 +31,6 @@ class CompilerType {
3231
public:
3332
// Constructors and Destructors
3433
CompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type);
35-
CompilerType(clang::ASTContext *ast_context, clang::QualType qual_type);
3634

3735
CompilerType(const CompilerType &rhs)
3836
: m_type(rhs.m_type), m_type_system(rhs.m_type_system) {}
@@ -169,8 +167,6 @@ class CompilerType {
169167
void SetCompilerType(TypeSystem *type_system,
170168
lldb::opaque_compiler_type_t type);
171169

172-
void SetCompilerType(clang::ASTContext *ast, clang::QualType qual_type);
173-
174170
unsigned GetTypeQualifiers() const;
175171

176172
// Creating related types

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,8 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
20662066
// seems to be generating bad types on occasion.
20672067
return CompilerType();
20682068

2069-
return CompilerType(m_ast_context, copied_qual_type);
2069+
return CompilerType(ClangASTContext::GetASTContext(m_ast_context),
2070+
copied_qual_type.getAsOpaquePtr());
20702071
}
20712072

20722073
clang::NamedDecl *NameSearchContext::AddVarDecl(const CompilerType &type) {
@@ -2194,7 +2195,9 @@ clang::NamedDecl *NameSearchContext::AddGenericFunDecl() {
21942195
proto_info));
21952196

21962197
return AddFunDecl(
2197-
CompilerType(m_ast_source.m_ast_context, generic_function_type), true);
2198+
CompilerType(ClangASTContext::GetASTContext(m_ast_source.m_ast_context),
2199+
generic_function_type.getAsOpaquePtr()),
2200+
true);
21982201
}
21992202

22002203
clang::NamedDecl *

lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,10 @@ bool IRForTarget::MaybeHandleVariable(Value *llvm_value_ptr) {
12881288
if (value_decl == nullptr)
12891289
return false;
12901290

1291-
lldb_private::CompilerType compiler_type(&value_decl->getASTContext(),
1292-
value_decl->getType());
1291+
lldb_private::CompilerType compiler_type(
1292+
lldb_private::ClangASTContext::GetASTContext(
1293+
&value_decl->getASTContext()),
1294+
value_decl->getType().getAsOpaquePtr());
12931295

12941296
const Type *value_type = nullptr;
12951297

lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef liblldb_IRForTarget_h_
1111
#define liblldb_IRForTarget_h_
1212

13+
#include "lldb/Core/ClangForward.h"
1314
#include "lldb/Symbol/TaggedASTType.h"
1415
#include "lldb/Utility/ConstString.h"
1516
#include "lldb/Utility/Status.h"

lldb/source/Plugins/Language/ObjC/NSArray.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,13 @@ lldb_private::formatters::NSArrayMSyntheticFrontEndBase::NSArrayMSyntheticFrontE
461461
: SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8),
462462
m_id_type() {
463463
if (valobj_sp) {
464-
clang::ASTContext *ast = valobj_sp->GetExecutionContextRef()
465-
.GetTargetSP()
466-
->GetScratchClangASTContext()
467-
->getASTContext();
468-
if (ast)
469-
m_id_type = CompilerType(ast, ast->ObjCBuiltinIdTy);
464+
auto *clang_ast_context = valobj_sp->GetExecutionContextRef()
465+
.GetTargetSP()
466+
->GetScratchClangASTContext();
467+
if (clang_ast_context)
468+
m_id_type = CompilerType(
469+
clang_ast_context,
470+
clang_ast_context->getASTContext()->ObjCBuiltinIdTy.getAsOpaquePtr());
470471
if (valobj_sp->GetProcessSP())
471472
m_ptr_size = valobj_sp->GetProcessSP()->GetAddressByteSize();
472473
}
@@ -609,12 +610,13 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<D32, D64, Inline>::
609610
if (valobj_sp) {
610611
CompilerType type = valobj_sp->GetCompilerType();
611612
if (type) {
612-
ClangASTContext *ast = valobj_sp->GetExecutionContextRef()
613-
.GetTargetSP()
614-
->GetScratchClangASTContext();
615-
if (ast)
616-
m_id_type = CompilerType(ast->getASTContext(),
617-
ast->getASTContext()->ObjCBuiltinIdTy);
613+
auto *clang_ast_context = valobj_sp->GetExecutionContextRef()
614+
.GetTargetSP()
615+
->GetScratchClangASTContext();
616+
if (clang_ast_context)
617+
m_id_type = CompilerType(clang_ast_context,
618+
clang_ast_context->getASTContext()
619+
->ObjCBuiltinIdTy.getAsOpaquePtr());
618620
}
619621
}
620622
}

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ clang::QualType AppleObjCTypeEncodingParser::BuildAggregate(
149149
}
150150
ClangASTContext::AddFieldToRecordType(
151151
union_type, element.name.c_str(),
152-
CompilerType(&ast_ctx, element.type), lldb::eAccessPublic,
153-
element.bitfield);
152+
CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
153+
element.type.getAsOpaquePtr()),
154+
lldb::eAccessPublic, element.bitfield);
154155
++count;
155156
}
156157
ClangASTContext::CompleteTagDeclarationDefinition(union_type);
@@ -172,7 +173,9 @@ AppleObjCTypeEncodingParser::BuildArray(clang::ASTContext &ast_ctx,
172173
if (!lldb_ctx)
173174
return clang::QualType();
174175
CompilerType array_type(lldb_ctx->CreateArrayType(
175-
CompilerType(&ast_ctx, element_type), size, false));
176+
CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
177+
element_type.getAsOpaquePtr()),
178+
size, false));
176179
return ClangUtil::GetQualType(array_type);
177180
}
178181

@@ -375,7 +378,8 @@ CompilerType AppleObjCTypeEncodingParser::RealizeType(
375378
if (name && name[0]) {
376379
StringLexer lexer(name);
377380
clang::QualType qual_type = BuildType(ast_ctx, lexer, for_expression);
378-
return CompilerType(&ast_ctx, qual_type);
381+
return CompilerType(ClangASTContext::GetASTContext(&ast_ctx),
382+
qual_type.getAsOpaquePtr());
379383
}
380384
return CompilerType();
381385
}

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,31 @@ GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast,
120120
return clang_ast.GetBasicType(eBasicTypeBool);
121121
case PDB_BuiltinType::Long:
122122
if (width == ast->getTypeSize(ast->LongTy))
123-
return CompilerType(ast, ast->LongTy);
123+
return CompilerType(ClangASTContext::GetASTContext(ast),
124+
ast->LongTy.getAsOpaquePtr());
124125
if (width == ast->getTypeSize(ast->LongLongTy))
125-
return CompilerType(ast, ast->LongLongTy);
126+
return CompilerType(ClangASTContext::GetASTContext(ast),
127+
ast->LongLongTy.getAsOpaquePtr());
126128
break;
127129
case PDB_BuiltinType::ULong:
128130
if (width == ast->getTypeSize(ast->UnsignedLongTy))
129-
return CompilerType(ast, ast->UnsignedLongTy);
131+
return CompilerType(ClangASTContext::GetASTContext(ast),
132+
ast->UnsignedLongTy.getAsOpaquePtr());
130133
if (width == ast->getTypeSize(ast->UnsignedLongLongTy))
131-
return CompilerType(ast, ast->UnsignedLongLongTy);
134+
return CompilerType(ClangASTContext::GetASTContext(ast),
135+
ast->UnsignedLongLongTy.getAsOpaquePtr());
132136
break;
133137
case PDB_BuiltinType::WCharT:
134138
if (width == ast->getTypeSize(ast->WCharTy))
135-
return CompilerType(ast, ast->WCharTy);
139+
return CompilerType(ClangASTContext::GetASTContext(ast),
140+
ast->WCharTy.getAsOpaquePtr());
136141
break;
137142
case PDB_BuiltinType::Char16:
138-
return CompilerType(ast, ast->Char16Ty);
143+
return CompilerType(ClangASTContext::GetASTContext(ast),
144+
ast->Char16Ty.getAsOpaquePtr());
139145
case PDB_BuiltinType::Char32:
140-
return CompilerType(ast, ast->Char32Ty);
146+
return CompilerType(ClangASTContext::GetASTContext(ast),
147+
ast->Char32Ty.getAsOpaquePtr());
141148
case PDB_BuiltinType::Float:
142149
// Note: types `long double` and `double` have same bit size in MSVC and
143150
// there is no information in the PDB to distinguish them. So when falling

0 commit comments

Comments
 (0)
0