Move the PPCallbacks in InterpreterCallbacks too.

This commit is contained in:
Vassil Vassilev 2013-08-22 13:45:06 +02:00 committed by sftnight
parent 2445d8b5fe
commit 36b6e36b1a
2 changed files with 56 additions and 5 deletions

View File

@ -29,6 +29,7 @@ namespace cling {
class InterpreterCallbacks;
class InterpreterDeserializationListener;
class InterpreterExternalSemaSource;
class InterpreterPPCallbacks;
class Transaction;
/// \brief This interface provides a way to observe the actions of the
@ -52,6 +53,11 @@ namespace cling {
llvm::
OwningPtr<InterpreterDeserializationListener> m_DeserializationListener;
///\brief Our custom PPCallbacks, translating interesting
/// events into interpreter callbacks.
///
llvm::OwningPtr<InterpreterPPCallbacks> m_PPCallbacks;
///\brief DynamicScopes only! Set to true only when evaluating dynamic expr.
///
bool m_IsRuntime;
@ -65,24 +71,28 @@ namespace cling {
///\param[in] interp - an interpreter.
///\param[in] IESS - an InterpreterExternalSemaSource (takes the ownership)
///\param[in] IDL - an InterpreterDeserializationListener (owned)
///\param[in] IPPC - an InterpreterPPCallbacks (owned)
///
InterpreterCallbacks(Interpreter* interp,
InterpreterExternalSemaSource* IESS,
InterpreterDeserializationListener* IDL);
InterpreterDeserializationListener* IDL,
InterpreterPPCallbacks* IPPC);
///\brief Constructs the callbacks with default callback adaptors.
///
///\param[in] interp - an interpreter.
///\param[in] enableExternalSemaSourceCallbacks - creates a default
/// InterpreterExternalSemaSource and attaches it to Sema.
///
///\param[in] enableInterpreterDeserializationListener - 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 enableDeserializationListenerCallbacks = false,
bool enablePPCallbacks = false);
virtual ~InterpreterCallbacks();
@ -91,6 +101,9 @@ namespace cling {
clang::ASTDeserializationListener*
getInterpreterDeserializationListener() const;
virtual bool FileNotFound(llvm::StringRef FileName,
llvm::SmallVectorImpl<char>& RecoveryPath);
/// \brief This callback is invoked whenever the interpreter needs to
/// resolve the type and the adress of an object, which has been marked for
/// delayed evaluation from the interpreter's dynamic lookup extension.

View File

@ -9,6 +9,7 @@
#include "cling/Interpreter/Interpreter.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/ASTDeserializationListener.h"
@ -18,6 +19,25 @@ using namespace clang;
namespace cling {
///\brief Translates 'interesting' for the interpreter
/// ASTDeserializationListener events into interpreter callback.
///
class InterpreterPPCallbacks : public PPCallbacks {
private:
cling::InterpreterCallbacks* m_Callbacks;
public:
InterpreterPPCallbacks(InterpreterCallbacks* C) : m_Callbacks(C) { }
~InterpreterPPCallbacks() { }
virtual bool FileNotFound(llvm::StringRef FileName,
llvm::SmallVectorImpl<char>& RecoveryPath) {
if (m_Callbacks)
return m_Callbacks->FileNotFound(FileName, RecoveryPath);
// Returning true would mean that the preprocessor should try to recover.
return false;
}
};
///\brief Translates 'interesting' for the interpreter
/// ASTDeserializationListener events into interpreter callback.
///
@ -91,7 +111,8 @@ namespace cling {
InterpreterCallbacks::InterpreterCallbacks(Interpreter* interp,
InterpreterExternalSemaSource* IESS,
InterpreterDeserializationListener* IDL)
InterpreterDeserializationListener* IDL,
InterpreterPPCallbacks* IPPC)
: m_Interpreter(interp), m_ExternalSemaSource(IESS), m_IsRuntime(false),
m_DeserializationListener(IDL) {
if (IESS)
@ -99,11 +120,14 @@ namespace cling {
ASTReader* Reader = m_Interpreter->getCI()->getModuleManager();
if (IDL && Reader)
Reader->setDeserializationListener(IDL);
if (IPPC)
m_Interpreter->getCI()->getPreprocessor().addPPCallbacks(IPPC);
}
InterpreterCallbacks::InterpreterCallbacks(Interpreter* interp,
bool enableExternalSemaSourceCallbacks/* = false*/,
bool enableDeserializationListenerCallbacks/* = false*/)
bool enableDeserializationListenerCallbacks/* = false*/,
bool enablePPCallbacks/* = false*/)
: m_Interpreter(interp), m_IsRuntime(false) {
if (enableExternalSemaSourceCallbacks) {
@ -119,6 +143,12 @@ namespace cling {
reset(new InterpreterDeserializationListener(this));
Reader->setDeserializationListener(m_DeserializationListener.get());
}
if (enablePPCallbacks) {
m_PPCallbacks.reset(new InterpreterPPCallbacks(this));
Preprocessor& PP = m_Interpreter->getCI()->getPreprocessor();
PP.addPPCallbacks(m_PPCallbacks.get());
}
}
// pin the vtable here
@ -138,11 +168,19 @@ namespace cling {
return m_DeserializationListener.get();
}
bool InterpreterCallbacks::FileNotFound(llvm::StringRef FileName,
llvm::SmallVectorImpl<char>& RecoveryPath) {
// Default implementation is no op.
return false;
}
bool InterpreterCallbacks::LookupObject(LookupResult&, Scope*) {
// Default implementation is no op.
return false;
}
bool InterpreterCallbacks::LookupObject(const DeclContext*, DeclarationName) {
// Default implementation is no op.
return false;
}