[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.

llvm-svn: 373330
This commit is contained in:
Raphael Isemann
2019-10-01 12:55:37 +00:00
parent d01b4a7862
commit c73bfc98f8
4 changed files with 16 additions and 17 deletions

View File

@@ -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();

View File

@@ -585,9 +585,7 @@ ClangExpressionParser::ClangExpressionParser(
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");

View File

@@ -163,9 +163,7 @@ ClangModulesDeclVendorImpl::ClangModulesDeclVendorImpl(
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(

View File

@@ -528,6 +528,14 @@ ClangASTContext::ClangASTContext(llvm::StringRef target_triple)
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::RemoveExternalSource() {
}
}
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;