Move the multiplexing callbacks in lib. Simplify.

This commit is contained in:
Vassil Vassilev 2014-08-21 12:23:43 +02:00 committed by sftnight
parent f4c946a68d
commit 0246d5f0b0
3 changed files with 129 additions and 116 deletions

View File

@ -1,97 +0,0 @@
#ifndef CLING_MULTIPLEX_INTERPRETER_CALLBACKS_H
#define CLING_MULTIPLEX_INTERPRETER_CALLBACKS_H
#include "InterpreterCallbacks.h"
namespace cling {
class MultiplexInterpreterCallbacks : public InterpreterCallbacks {
public:
MultiplexInterpreterCallbacks(cling::Interpreter* interp)
:InterpreterCallbacks(interp){}
void addCallback(InterpreterCallbacks* newCb) {
m_Callbacks.push_back(newCb);
}
void InclusionDirective(clang::SourceLocation HashLoc,
const clang::Token& IncludeTok,
llvm::StringRef FileName,
bool IsAngled,
clang::CharSourceRange FilenameRange,
const clang::FileEntry* File,
llvm::StringRef SearchPath,
llvm::StringRef RelativePath,
const clang::Module* Imported) {
for(InterpreterCallbacks* cb : m_Callbacks)
cb->InclusionDirective(HashLoc, IncludeTok,
FileName, IsAngled,
FilenameRange, File,
SearchPath, RelativePath, Imported);
}
bool FileNotFound(llvm::StringRef FileName,
llvm::SmallVectorImpl<char>& RecoveryPath) {
bool result = false;
for(InterpreterCallbacks* cb : m_Callbacks)
result = cb->FileNotFound(FileName, RecoveryPath) || result;
return result;
}
bool LookupObject(clang::LookupResult& LR, clang::Scope* S) {
bool result = false;
for(InterpreterCallbacks* cb : m_Callbacks)
result = cb->LookupObject(LR, S) || result;
return result;
}
bool LookupObject(const clang::DeclContext* DC, clang::DeclarationName DN) {
bool result = false;
for(InterpreterCallbacks* cb : m_Callbacks)
result = cb->LookupObject(DC, DN) || result;
return result;
}
bool LookupObject(clang::TagDecl* T) {
bool result = false;
for(InterpreterCallbacks* cb : m_Callbacks)
result = cb->LookupObject(T) || result;
return result;
}
void TransactionCommitted(const Transaction& T) {
for(InterpreterCallbacks* cb : m_Callbacks) {
cb->TransactionCommitted(T);
}
}
void TransactionUnloaded(const Transaction& T) {
for(InterpreterCallbacks* cb : m_Callbacks) {
cb->TransactionUnloaded(T);
}
}
void DeclDeserialized(const clang::Decl* D) {
for(InterpreterCallbacks* cb : m_Callbacks) {
cb->DeclDeserialized(D);
}
}
void TypeDeserialized(const clang::Type* Ty) {
for(InterpreterCallbacks* cb : m_Callbacks) {
cb->TypeDeserialized(Ty);
}
}
void LibraryLoaded(const void* Lib, llvm::StringRef Name) {
for(InterpreterCallbacks* cb : m_Callbacks) {
cb->LibraryLoaded(Lib,Name);
}
}
void LibraryUnloaded(const void* Lib, llvm::StringRef Name) {
for(InterpreterCallbacks* cb : m_Callbacks) {
cb->LibraryUnloaded(Lib,Name);
}
}
private:
std::vector<InterpreterCallbacks*> m_Callbacks;
};
} // end namespace cling
#endif

View File

@ -11,15 +11,15 @@
#include "cling-compiledata.h"
#include "DynamicLookup.h"
#include "ForwardDeclPrinter.h"
#include "IncrementalExecutor.h"
#include "IncrementalParser.h"
#include "ForwardDeclPrinter.h"
#include "MultiplexInterpreterCallbacks.h"
#include "cling/Interpreter/CIFactory.h"
#include "cling/Interpreter/ClangInternalState.h"
#include "cling/Interpreter/CompilationOptions.h"
#include "cling/Interpreter/DynamicLibraryManager.h"
#include "cling/Interpreter/InterpreterCallbacks.h"
#include "cling/Interpreter/LookupHelper.h"
#include "cling/Interpreter/Transaction.h"
#include "cling/Interpreter/Value.h"
@ -223,7 +223,7 @@ namespace cling {
I != E; ++I)
m_IncrParser->commitTransaction(*I);
setCallbacks(new AutoloadCallback(this));
//setCallbacks(new AutoloadCallback(this));
}
Interpreter::~Interpreter() {
@ -1105,25 +1105,24 @@ namespace cling {
}
void Interpreter::setCallbacks(InterpreterCallbacks* C) {
if (m_Callbacks.get() == C)
return;
// We need it to enable LookupObject callback.
if (!m_Callbacks)
m_Callbacks.reset(C);
else
m_Callbacks->setNext(C);
if (!m_Callbacks) {
m_Callbacks.reset(new MultiplexInterpreterCallbacks(this));
// FIXME: Move to the InterpreterCallbacks.cpp;
if (DynamicLibraryManager* DLM = getDynamicLibraryManager())
DLM->setCallbacks(m_Callbacks.get());
}
static_cast<MultiplexInterpreterCallbacks*>(m_Callbacks.get())->addCallback(C);
// FIXME: We should add a multiplexer in the ASTContext, too.
llvm::IntrusiveRefCntPtr<ExternalASTSource>
astContextExternalSource(getSema().getExternalSource());
clang::ASTContext& Ctx = getSema().getASTContext();
// FIXME: This is a gross hack. We must make multiplexer in the astcontext,
// or a derived class that extends what we need.
Ctx.ExternalSource.resetWithoutRelease(); // FIXME: make sure we delete it.
Ctx.setExternalSource(astContextExternalSource);
if (DynamicLibraryManager* DLM = getDynamicLibraryManager())
DLM->setCallbacks(C);
// llvm::IntrusiveRefCntPtr<ExternalASTSource>
// astContextExternalSource(getSema().getExternalSource());
// clang::ASTContext& Ctx = getSema().getASTContext();
// // FIXME: This is a gross hack. We must make multiplexer in the astcontext,
// // or a derived class that extends what we need.
// Ctx.ExternalSource.resetWithoutRelease(); // FIXME: make sure we delete it.
// Ctx.setExternalSource(astContextExternalSource);
}
const Transaction* Interpreter::getFirstTransaction() const {

View File

@ -0,0 +1,111 @@
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Manasij Mukherjee <manasij7479@gmail.com>
// author: Vassil Vassilev <vvasilev@cern.ch>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
#ifndef CLING_MULTIPLEX_INTERPRETER_CALLBACKS_H
#define CLING_MULTIPLEX_INTERPRETER_CALLBACKS_H
#include "cling/Interpreter/InterpreterCallbacks.h"
namespace cling {
class MultiplexInterpreterCallbacks : public InterpreterCallbacks {
private:
std::vector<InterpreterCallbacks*> m_Callbacks;
public:
MultiplexInterpreterCallbacks(Interpreter* interp)
: InterpreterCallbacks(interp, true, true, true) {}
void addCallback(InterpreterCallbacks* newCb) {
m_Callbacks.push_back(newCb);
}
void InclusionDirective(clang::SourceLocation HashLoc,
const clang::Token& IncludeTok,
llvm::StringRef FileName, bool IsAngled,
clang::CharSourceRange FilenameRange,
const clang::FileEntry* File,
llvm::StringRef SearchPath,
llvm::StringRef RelativePath,
const clang::Module* Imported) {
for (InterpreterCallbacks* cb : m_Callbacks)
cb->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange, File, SearchPath, RelativePath,
Imported);
}
bool FileNotFound(llvm::StringRef FileName,
llvm::SmallVectorImpl<char>& RecoveryPath) {
bool result = false;
for (InterpreterCallbacks* cb : m_Callbacks)
result = cb->FileNotFound(FileName, RecoveryPath) || result;
return result;
}
bool LookupObject(clang::LookupResult& LR, clang::Scope* S) {
bool result = false;
for (InterpreterCallbacks* cb : m_Callbacks)
result = cb->LookupObject(LR, S) || result;
return result;
}
bool LookupObject(const clang::DeclContext* DC, clang::DeclarationName DN) {
bool result = false;
for (InterpreterCallbacks* cb : m_Callbacks)
result = cb->LookupObject(DC, DN) || result;
return result;
}
bool LookupObject(clang::TagDecl* T) {
bool result = false;
for (InterpreterCallbacks* cb : m_Callbacks)
result = cb->LookupObject(T) || result;
return result;
}
void TransactionCommitted(const Transaction& T) {
for (InterpreterCallbacks* cb : m_Callbacks) {
cb->TransactionCommitted(T);
}
}
void TransactionUnloaded(const Transaction& T) {
for (InterpreterCallbacks* cb : m_Callbacks) {
cb->TransactionUnloaded(T);
}
}
void DeclDeserialized(const clang::Decl* D) {
for (InterpreterCallbacks* cb : m_Callbacks) {
cb->DeclDeserialized(D);
}
}
void TypeDeserialized(const clang::Type* Ty) {
for (InterpreterCallbacks* cb : m_Callbacks) {
cb->TypeDeserialized(Ty);
}
}
void LibraryLoaded(const void* Lib, llvm::StringRef Name) {
for (InterpreterCallbacks* cb : m_Callbacks) {
cb->LibraryLoaded(Lib,Name);
}
}
void LibraryUnloaded(const void* Lib, llvm::StringRef Name) {
for (InterpreterCallbacks* cb : m_Callbacks) {
cb->LibraryUnloaded(Lib,Name);
}
}
};
} // end namespace cling
#endif // CLING_MULTIPLEX_INTERPRETER_CALLBACKS_H