Skip to content

Commit

Permalink
[core] Remove never used code from the callbacks.
Browse files Browse the repository at this point in the history
This will allow us to simplify our ASTConsumer model instead of creating many
multiplexers that are not needed. That should simplify adoption of latest
versions of clad.
  • Loading branch information
vgvassilev committed May 2, 2024
1 parent e83e0e9 commit 95674f4
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 120 deletions.
13 changes: 0 additions & 13 deletions core/metacling/src/TClingCallbacks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1059,19 +1059,6 @@ void TClingCallbacks::DefinitionShadowed(const clang::NamedDecl *D) {
TCling__InvalidateGlobal(D);
}

void TClingCallbacks::DeclDeserialized(const clang::Decl* D) {
if (const RecordDecl* RD = dyn_cast<RecordDecl>(D)) {
// FIXME: Our AutoLoading doesn't work (load the library) when the looked
// up decl is found in the PCH/PCM. We have to do that extra step, which
// loads the corresponding library when a decl was deserialized.
//
// Unfortunately we cannot do that with the current implementation,
// because the library load will pull in the header files of the library
// as well, even though they are in the PCH/PCM and available.
(void)RD;//TCling__AutoLoadCallback(RD->getNameAsString().c_str());
}
}

void TClingCallbacks::LibraryLoaded(const void* dyLibHandle,
llvm::StringRef canonicalName) {
TCling__LibraryLoadedRTTI(dyLibHandle, canonicalName);
Expand Down
4 changes: 0 additions & 4 deletions core/metacling/src/TClingCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ class TClingCallbacks : public cling::InterpreterCallbacks {
/// data about the old (global) decl.
void DefinitionShadowed(const clang::NamedDecl *D) override;

// Used to inform client about a new decl read by the ASTReader.
//
void DeclDeserialized(const clang::Decl *D) override;

void LibraryLoaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;
void LibraryUnloaded(const void *dyLibHandle, llvm::StringRef canonicalName) override;

Expand Down
25 changes: 0 additions & 25 deletions interpreter/cling/include/cling/Interpreter/InterpreterCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <memory>

namespace clang {
class ASTDeserializationListener;
class Decl;
class DeclContext;
class DeclarationName;
Expand All @@ -37,7 +36,6 @@ namespace clang {
namespace cling {
class Interpreter;
class InterpreterCallbacks;
class InterpreterDeserializationListener;
class InterpreterExternalSemaSource;
class InterpreterPPCallbacks;
class Transaction;
Expand All @@ -57,12 +55,6 @@ namespace cling {
///
InterpreterExternalSemaSource* m_ExternalSemaSource;

///\brief Our custom ASTDeserializationListener, translating interesting
/// events into callbacks.
///
std::unique_ptr
<InterpreterDeserializationListener> m_DeserializationListener;

///\brief Our custom PPCallbacks, translating interesting
/// events into interpreter callbacks.
///
Expand All @@ -83,25 +75,18 @@ namespace cling {
///\param[in] interp - an interpreter.
///\param[in] enableExternalSemaSourceCallbacks - creates a default
/// InterpreterExternalSemaSource and attaches it to Sema.
///\param[in] enableDeserializationListenerCallbacks - creates a default
/// InterpreterDeserializationListener and attaches it to the
/// ModuleManager if it is set.
///\param[in] enablePPCallbacks - creates a default InterpreterPPCallbacks
/// and attaches it to the Preprocessor.
///
InterpreterCallbacks(Interpreter* interp,
bool enableExternalSemaSourceCallbacks = false,
bool enableDeserializationListenerCallbacks = false,
bool enablePPCallbacks = false);

virtual ~InterpreterCallbacks();

cling::Interpreter* getInterpreter() const { return m_Interpreter; }
clang::ExternalSemaSource* getInterpreterExternalSemaSource() const;

clang::ASTDeserializationListener*
getInterpreterDeserializationListener() const;

virtual void InclusionDirective(clang::SourceLocation /*HashLoc*/,
const clang::Token& /*IncludeTok*/,
llvm::StringRef /*FileName*/,
Expand Down Expand Up @@ -174,16 +159,6 @@ namespace cling {
///\param[in] - The declaration that has been shadowed.
virtual void DefinitionShadowed(const clang::NamedDecl*) {}

/// \brief Used to inform client about a new decl read by the ASTReader.
///
///\param[in] - The Decl read by the ASTReader.
virtual void DeclDeserialized(const clang::Decl*) {}

/// \brief Used to inform client about a new type read by the ASTReader.
///
///\param[in] - The Type read by the ASTReader.
virtual void TypeDeserialized(const clang::Type*) {}

virtual void LibraryLoaded(const void*, llvm::StringRef) {}
virtual void LibraryUnloaded(const void*, llvm::StringRef) {}

Expand Down
67 changes: 2 additions & 65 deletions interpreter/cling/lib/Interpreter/InterpreterCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

#include "clang/AST/ASTContext.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/MultiplexExternalSemaSource.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTDeserializationListener.h"
#include "clang/Serialization/ASTReader.h"

#include <optional>
Expand All @@ -27,8 +25,8 @@ using namespace clang;

namespace cling {

///\brief Translates 'interesting' for the interpreter
/// ASTDeserializationListener events into interpreter callback.
///\brief Translates 'interesting' for the interpreter into interpreter
/// callback.
///
class InterpreterPPCallbacks : public PPCallbacks {
private:
Expand Down Expand Up @@ -69,40 +67,6 @@ namespace cling {
}
};

///\brief Translates 'interesting' for the interpreter
/// ASTDeserializationListener events into interpreter callback.
///
class InterpreterDeserializationListener : public ASTDeserializationListener {
private:
cling::InterpreterCallbacks* m_Callbacks;
public:
InterpreterDeserializationListener(InterpreterCallbacks* C)
: m_Callbacks(C) {}

void DeclRead(serialization::DeclID, const Decl *D) override {
if (m_Callbacks)
m_Callbacks->DeclDeserialized(D);
}

void TypeRead(serialization::TypeIdx, QualType T) override {
if (m_Callbacks)
m_Callbacks->TypeDeserialized(T.getTypePtr());
}
};

/// \brief Wraps an ASTDeserializationListener in an ASTConsumer so that
/// it can be used with a MultiplexConsumer.
class DeserializationListenerWrapper : public ASTConsumer {
ASTDeserializationListener* m_Listener;

public:
DeserializationListenerWrapper(ASTDeserializationListener* Listener)
: m_Listener(Listener) {}
ASTDeserializationListener* GetASTDeserializationListener() override {
return m_Listener;
}
};

/// \brief wraps an ExternalASTSource in an ExternalSemaSource. No functional
/// difference between the original source and this wrapper intended.
class ExternalASTSourceWrapper : public ExternalSemaSource {
Expand Down Expand Up @@ -297,7 +261,6 @@ namespace cling {

InterpreterCallbacks::InterpreterCallbacks(Interpreter* interp,
bool enableExternalSemaSourceCallbacks/* = false*/,
bool enableDeserializationListenerCallbacks/* = false*/,
bool enablePPCallbacks/* = false*/)
: m_Interpreter(interp), m_ExternalSemaSource(nullptr), m_PPCallbacks(nullptr),
m_IsRuntime(false) {
Expand Down Expand Up @@ -340,27 +303,6 @@ namespace cling {
}
}

if (enableDeserializationListenerCallbacks && Reader) {
// Create a new deserialization listener.
m_DeserializationListener.
reset(new InterpreterDeserializationListener(this));

// Wrap the deserialization listener in an MultiplexConsumer and then
// combine it with the existing Consumer.
// FIXME: Maybe it's better to make MultiplexASTDeserializationListener
// public instead. See also: https://reviews.llvm.org/D37475
std::unique_ptr<DeserializationListenerWrapper> wrapper(
new DeserializationListenerWrapper(m_DeserializationListener.get()));

std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(std::move(wrapper));
Consumers.push_back(m_Interpreter->getCI()->takeASTConsumer());

std::unique_ptr<clang::MultiplexConsumer> multiConsumer(
new clang::MultiplexConsumer(std::move(Consumers)));
m_Interpreter->getCI()->setASTConsumer(std::move(multiConsumer));
}

if (enablePPCallbacks) {
Preprocessor& PP = m_Interpreter->getCI()->getPreprocessor();
m_PPCallbacks = new InterpreterPPCallbacks(this);
Expand All @@ -384,11 +326,6 @@ namespace cling {
return m_ExternalSemaSource;
}

ASTDeserializationListener*
InterpreterCallbacks::getInterpreterDeserializationListener() const {
return m_DeserializationListener.get();
}

bool InterpreterCallbacks::FileNotFound(llvm::StringRef) {
// Default implementation is no op.
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace cling {

public:
MultiplexInterpreterCallbacks(Interpreter* interp)
: InterpreterCallbacks(interp, true, true, true) {}
: InterpreterCallbacks(interp, true, true) {}

void addCallback(std::unique_ptr<InterpreterCallbacks> newCb) {
m_Callbacks.push_back(std::move(newCb));
Expand Down Expand Up @@ -122,18 +122,6 @@ namespace cling {
}
}

void DeclDeserialized(const clang::Decl* D) override {
for (auto&& cb : m_Callbacks) {
cb->DeclDeserialized(D);
}
}

void TypeDeserialized(const clang::Type* Ty) override {
for (auto&& cb : m_Callbacks) {
cb->TypeDeserialized(Ty);
}
}

void LibraryLoaded(const void* Lib, llvm::StringRef Name) override {
for (auto&& cb : m_Callbacks) {
cb->LibraryLoaded(Lib,Name);
Expand Down

0 comments on commit 95674f4

Please sign in to comment.