[lldb][NFC] Move ClangASTContext::m_scratch_ast_source_up to the appropriate class
authorRaphael Isemann <teemperor@gmail.com>
Tue, 24 Dec 2019 08:31:45 +0000 (09:31 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Tue, 24 Dec 2019 15:32:40 +0000 (16:32 +0100)
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.

lldb/include/lldb/Symbol/ClangASTContext.h
lldb/source/Symbol/ClangASTContext.cpp

index 59abe19..c56a497 100644 (file)
@@ -943,7 +943,7 @@ public:
   clang::DeclarationName
   GetDeclarationName(const char *name, const CompilerType &function_clang_type);
 
-protected:
+private:
   const clang::ClassTemplateSpecializationDecl *
   GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type);
 
@@ -962,7 +962,6 @@ protected:
   std::unique_ptr<clang::Builtin::Context> m_builtins_up;
   std::unique_ptr<DWARFASTParserClang> m_dwarf_ast_parser_up;
   std::unique_ptr<PDBASTParser> m_pdb_ast_parser_up;
-  std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
   std::unique_ptr<clang::MangleContext> m_mangle_ctx_up;
   uint32_t m_pointer_byte_size = 0;
   bool m_ast_owned = false;
@@ -980,7 +979,6 @@ protected:
   /// ASTContext wasn't created by parsing source code.
   clang::Sema *m_sema = nullptr;
 
-private:
   // For ClangASTContext only
   ClangASTContext(const ClangASTContext &);
   const ClangASTContext &operator=(const ClangASTContext &);
@@ -995,6 +993,8 @@ public:
 
   ~ClangASTContextForExpressions() override = default;
 
+  void Finalize() override;
+
   UserExpression *
   GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
                     lldb::LanguageType language,
@@ -1016,6 +1016,7 @@ private:
   std::unique_ptr<PersistentExpressionState>
       m_persistent_variables; // These are the persistent variables associated
                               // with this process for the expression parser
+  std::unique_ptr<ClangASTSource> m_scratch_ast_source_up;
 };
 
 } // namespace lldb_private
index f98e088..937951c 100644 (file)
@@ -569,12 +569,6 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
   } else if (target && target->IsValid()) {
     std::shared_ptr<ClangASTContextForExpressions> ast_sp(
         new ClangASTContextForExpressions(*target, fixed_arch));
-    ast_sp->m_scratch_ast_source_up.reset(new ClangASTSource(
-        target->shared_from_this(), target->GetClangASTImporter()));
-    ast_sp->m_scratch_ast_source_up->InstallASTContext(*ast_sp);
-    llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
-        ast_sp->m_scratch_ast_source_up->CreateProxy());
-    ast_sp->SetExternalSource(proxy_ast_source);
     return ast_sp;
   }
   return lldb::TypeSystemSP();
@@ -630,7 +624,6 @@ void ClangASTContext::Finalize() {
   m_diagnostics_engine_up.reset();
   m_source_manager_up.reset();
   m_language_options_up.reset();
-  m_scratch_ast_source_up.reset();
 }
 
 void ClangASTContext::setSema(Sema *s) {
@@ -9381,7 +9374,19 @@ ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) {
 ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target,
                                                              ArchSpec arch)
     : ClangASTContext(arch), m_target_wp(target.shared_from_this()),
-      m_persistent_variables(new ClangPersistentVariables) {}
+      m_persistent_variables(new ClangPersistentVariables) {
+  m_scratch_ast_source_up.reset(new ClangASTSource(
+      target.shared_from_this(), target.GetClangASTImporter()));
+  m_scratch_ast_source_up->InstallASTContext(*this);
+  llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
+      m_scratch_ast_source_up->CreateProxy());
+  SetExternalSource(proxy_ast_source);
+}
+
+void ClangASTContextForExpressions::Finalize() {
+  ClangASTContext::Finalize();
+  m_scratch_ast_source_up.reset();
+}
 
 UserExpression *ClangASTContextForExpressions::GetUserExpression(
     llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,