Author: teemperor
Date: Tue Oct  1 05:55:37 2019
New Revision: 373330

URL: http://llvm.org/viewvc/llvm-project?rev=373330&view=rev
Log:
[lldb][NFC] Disallow changing the ASTContext of an ClangASTContext after 
construction.

We have no use case in LLDB where we actually do want to change the ASTContext 
after
it the ClangASTContext has been constructed. All callers of setASTContext are 
just setting
the ASTContext directly after construction, so we might as well make this a 
Constructor
instead of supporting this tricky use case.

Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=373330&r1=373329&r2=373330&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Tue Oct  1 05:55:37 2019
@@ -54,6 +54,12 @@ public:
   // Constructors and Destructors
   ClangASTContext(llvm::StringRef triple = "");
 
+  /// Constructs a ClangASTContext that uses an existing ASTContext internally.
+  /// Useful when having an existing ASTContext created by Clang.
+  ///
+  /// \param existing_ctxt An existing ASTContext.
+  explicit ClangASTContext(clang::ASTContext &existing_ctxt);
+
   ~ClangASTContext() override;
 
   void Finalize() override;
@@ -79,8 +85,6 @@ public:
 
   clang::ASTContext *getASTContext();
 
-  void setASTContext(clang::ASTContext *ast_ctx);
-
   clang::Builtin::Context *getBuiltinContext();
 
   clang::IdentifierTable *getIdentifierTable();

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=373330&r1=373329&r2=373330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
Tue Oct  1 05:55:37 2019
@@ -585,9 +585,7 @@ ClangExpressionParser::ClangExpressionPa
   m_compiler->createASTContext();
   clang::ASTContext &ast_context = m_compiler->getASTContext();
 
-  m_ast_context.reset(
-      new ClangASTContext(m_compiler->getTargetOpts().Triple.c_str()));
-  m_ast_context->setASTContext(&ast_context);
+  m_ast_context.reset(new ClangASTContext(ast_context));
 
   std::string module_name("$__lldb_module");
 

Modified: 
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=373330&r1=373329&r2=373330&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp 
Tue Oct  1 05:55:37 2019
@@ -163,9 +163,7 @@ ClangModulesDeclVendorImpl::ClangModules
       m_parser(std::move(parser)), m_origin_map() {
 
   // Initialize our ClangASTContext.
-  auto target_opts = m_compiler_invocation->getTargetOpts();
-  m_ast_context.reset(new ClangASTContext(target_opts.Triple.c_str()));
-  m_ast_context->setASTContext(&m_compiler_instance->getASTContext());
+  m_ast_context.reset(new 
ClangASTContext(m_compiler_instance->getASTContext()));
 }
 
 void ClangModulesDeclVendorImpl::ReportModuleExportsHelper(

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=373330&r1=373329&r2=373330&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Oct  1 05:55:37 2019
@@ -528,6 +528,14 @@ ClangASTContext::ClangASTContext(llvm::S
     SetTargetTriple(target_triple);
 }
 
+ClangASTContext::ClangASTContext(ASTContext &existing_ctxt)
+  : TypeSystem(TypeSystem::eKindClang) {
+  SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
+
+  m_ast_up.reset(&existing_ctxt);
+  GetASTMap().Insert(&existing_ctxt, this);
+}
+
 // Destructor
 ClangASTContext::~ClangASTContext() { Finalize(); }
 
@@ -706,15 +714,6 @@ void ClangASTContext::RemoveExternalSour
   }
 }
 
-void ClangASTContext::setASTContext(clang::ASTContext *ast_ctx) {
-  if (!m_ast_owned) {
-    m_ast_up.release();
-  }
-  m_ast_owned = false;
-  m_ast_up.reset(ast_ctx);
-  GetASTMap().Insert(ast_ctx, this);
-}
-
 ASTContext *ClangASTContext::getASTContext() {
   if (m_ast_up == nullptr) {
     m_ast_owned = true;


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to