Skip to content

Commit a12ac70

Browse files
committed
[lldb][NFC] Move ClangASTContext::m_scratch_ast_source_up to the appropriate class
m_scratch_ast_source_up is only used by ClangASTContextForExpressions so it should also be declared only in that class. Also make all other members of ClangASTContext private and move the initialization code for ClangASTContextForExpressions into the constructor.
1 parent f58f391 commit a12ac70

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lldb/include/lldb/Symbol/ClangASTContext.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ class ClangASTContext : public TypeSystem {
943943
clang::DeclarationName
944944
GetDeclarationName(const char *name, const CompilerType &function_clang_type);
945945

946-
protected:
946+
private:
947947
const clang::ClassTemplateSpecializationDecl *
948948
GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type);
949949

@@ -962,7 +962,6 @@ class ClangASTContext : public TypeSystem {
962962
std::unique_ptr<clang::Builtin::Context> m_builtins_up;
963963
std::unique_ptr<DWARFASTParserClang> m_dwarf_ast_parser_up;
964964
std::unique_ptr<PDBASTParser> m_pdb_ast_parser_up;
965-
std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
966965
std::unique_ptr<clang::MangleContext> m_mangle_ctx_up;
967966
uint32_t m_pointer_byte_size = 0;
968967
bool m_ast_owned = false;
@@ -980,7 +979,6 @@ class ClangASTContext : public TypeSystem {
980979
/// ASTContext wasn't created by parsing source code.
981980
clang::Sema *m_sema = nullptr;
982981

983-
private:
984982
// For ClangASTContext only
985983
ClangASTContext(const ClangASTContext &);
986984
const ClangASTContext &operator=(const ClangASTContext &);
@@ -995,6 +993,8 @@ class ClangASTContextForExpressions : public ClangASTContext {
995993

996994
~ClangASTContextForExpressions() override = default;
997995

996+
void Finalize() override;
997+
998998
UserExpression *
999999
GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
10001000
lldb::LanguageType language,
@@ -1016,6 +1016,7 @@ class ClangASTContextForExpressions : public ClangASTContext {
10161016
std::unique_ptr<PersistentExpressionState>
10171017
m_persistent_variables; // These are the persistent variables associated
10181018
// with this process for the expression parser
1019+
std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
10191020
};
10201021

10211022
} // namespace lldb_private

lldb/source/Symbol/ClangASTContext.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,6 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
569569
} else if (target && target->IsValid()) {
570570
std::shared_ptr<ClangASTContextForExpressions> ast_sp(
571571
new ClangASTContextForExpressions(*target, fixed_arch));
572-
ast_sp->m_scratch_ast_source_up.reset(new ClangASTSource(
573-
target->shared_from_this(), target->GetClangASTImporter()));
574-
ast_sp->m_scratch_ast_source_up->InstallASTContext(*ast_sp);
575-
llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
576-
ast_sp->m_scratch_ast_source_up->CreateProxy());
577-
ast_sp->SetExternalSource(proxy_ast_source);
578572
return ast_sp;
579573
}
580574
return lldb::TypeSystemSP();
@@ -630,7 +624,6 @@ void ClangASTContext::Finalize() {
630624
m_diagnostics_engine_up.reset();
631625
m_source_manager_up.reset();
632626
m_language_options_up.reset();
633-
m_scratch_ast_source_up.reset();
634627
}
635628

636629
void ClangASTContext::setSema(Sema *s) {
@@ -9381,7 +9374,19 @@ ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) {
93819374
ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target,
93829375
ArchSpec arch)
93839376
: ClangASTContext(arch), m_target_wp(target.shared_from_this()),
9384-
m_persistent_variables(new ClangPersistentVariables) {}
9377+
m_persistent_variables(new ClangPersistentVariables) {
9378+
m_scratch_ast_source_up.reset(new ClangASTSource(
9379+
target.shared_from_this(), target.GetClangASTImporter()));
9380+
m_scratch_ast_source_up->InstallASTContext(*this);
9381+
llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
9382+
m_scratch_ast_source_up->CreateProxy());
9383+
SetExternalSource(proxy_ast_source);
9384+
}
9385+
9386+
void ClangASTContextForExpressions::Finalize() {
9387+
ClangASTContext::Finalize();
9388+
m_scratch_ast_source_up.reset();
9389+
}
93859390

93869391
UserExpression *ClangASTContextForExpressions::GetUserExpression(
93879392
llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,

0 commit comments

Comments
 (0)