mirror of
https://github.com/intel/llvm.git
synced 2026-01-29 21:26:59 +08:00
[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:
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user