Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ lldb_private::ASTConsumerForwarder::~ASTConsumerForwarder() = default;

void lldb_private::ASTConsumerForwarder::PrintStats() { m_c->PrintStats(); }

lldb_private::SemaSourceWithPriorities::~SemaSourceWithPriorities() = default;
lldb_private::SemaSourceWithPriorities::~SemaSourceWithPriorities() {
for (auto *Source : Sources)
Source->Release();
}

void lldb_private::SemaSourceWithPriorities::PrintStats() {
for (size_t i = 0; i < Sources.size(); ++i)
Expand Down
27 changes: 19 additions & 8 deletions lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "clang/Sema/MultiplexExternalSemaSource.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaConsumer.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include <optional>

namespace clang {
Expand All @@ -24,13 +25,15 @@ class Module;

namespace lldb_private {

/// Wraps an ExternalASTSource into an ExternalSemaSource. Doesn't take
/// ownership of the provided source.
/// Wraps an ExternalASTSource into an ExternalSemaSource.
///
/// Assumes shared ownership of the underlying source.
class ExternalASTSourceWrapper : public clang::ExternalSemaSource {
ExternalASTSource *m_Source;
llvm::IntrusiveRefCntPtr<ExternalASTSource> m_Source;

public:
ExternalASTSourceWrapper(ExternalASTSource *Source) : m_Source(Source) {
explicit ExternalASTSourceWrapper(ExternalASTSource *Source)
: m_Source(Source) {
assert(m_Source && "Can't wrap nullptr ExternalASTSource");
}

Expand Down Expand Up @@ -256,10 +259,18 @@ class SemaSourceWithPriorities : public clang::ExternalSemaSource {
/// Construct a SemaSourceWithPriorities with a 'high quality' source that
/// has the higher priority and a 'low quality' source that will be used
/// as a fallback.
SemaSourceWithPriorities(clang::ExternalSemaSource &high_quality_source,
clang::ExternalSemaSource &low_quality_source) {
Sources.push_back(&high_quality_source);
Sources.push_back(&low_quality_source);
///
/// This class assumes shared ownership of the sources provided to it.
SemaSourceWithPriorities(clang::ExternalSemaSource *high_quality_source,
clang::ExternalSemaSource *low_quality_source) {
assert(high_quality_source);
assert(low_quality_source);

high_quality_source->Retain();
low_quality_source->Retain();

Sources.push_back(high_quality_source);
Sources.push_back(low_quality_source);
}

~SemaSourceWithPriorities() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,15 +1224,15 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
clang::ExternalASTSource *ast_source = decl_map->CreateProxy();

if (ast_context.getExternalSource()) {
auto module_wrapper =
auto *module_wrapper =
new ExternalASTSourceWrapper(ast_context.getExternalSource());

auto ast_source_wrapper = new ExternalASTSourceWrapper(ast_source);
auto *ast_source_wrapper = new ExternalASTSourceWrapper(ast_source);

auto multiplexer =
new SemaSourceWithPriorities(*module_wrapper, *ast_source_wrapper);
IntrusiveRefCntPtr<ExternalASTSource> Source(multiplexer);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes in this file are drive-by stylistic changes.

ast_context.setExternalSource(Source);
auto *multiplexer =
new SemaSourceWithPriorities(module_wrapper, ast_source_wrapper);

ast_context.setExternalSource(multiplexer);
} else {
ast_context.setExternalSource(ast_source);
}
Expand Down
Loading