* Implement interpreter callbacks, which the Interpreter owns.

* Implement new callback functions - on transaction committed and transaction unloaded.
* Publish the Transaction class so that it can be visible by TCintWithCling.
* Publish the CompilationOptions needed by Transaction.
* Fix the references of Transaction and CompilationOptions.
* Forward declare where possible.
* Add missing keywords.
* Improve include style.


git-svn-id: http://root.cern.ch/svn/root/trunk@46264 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
Vassil Vassilev 2012-10-02 10:30:25 +00:00
parent 3a2e68400b
commit e087402f78
15 changed files with 61 additions and 23 deletions

View File

@ -99,6 +99,10 @@ namespace cling {
///
bool m_DynamicLookupEnabled;
///\brief Interpreter callbacks.
///
llvm::OwningPtr<InterpreterCallbacks> m_Callbacks;
///\breif Helper that manages when the destructor of an object to be called.
///
/// The object is registered first as an CXAAtExitElement and then cling
@ -376,9 +380,12 @@ namespace cling {
Value Evaluate(const char* expr, clang::DeclContext* DC,
bool ValuePrinterReq = false);
///\brief Sets callbacks needed for the dynamic lookup.
///\brief Interpreter callbacks accessors.
/// Note that this class takes ownership of any callback object given to it.
///
void setCallbacks(InterpreterCallbacks* C);
const InterpreterCallbacks* getCallbacks() const {return m_Callbacks.get();}
InterpreterCallbacks* getCallbacks() { return m_Callbacks.get(); }
///\brief Gets the address of an existing global and whether it was JITted.
///

View File

@ -14,6 +14,7 @@ namespace clang {
namespace cling {
class Interpreter;
class Transaction;
/// \brief This interface provides a way to observe the actions of the
/// interpreter as it does its thing. Clients can define their hooks here to
@ -43,8 +44,30 @@ namespace cling {
/// \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
virtual bool LookupObject(clang::LookupResult& R, clang::Scope* S) = 0;
/// delayed evaluation from the interpreter's dynamic lookup extension.
///
/// \param[out] R - Lookup result
/// \param[in] S - Scope
///
/// \returns true if lookup result is found and should be used.
///
virtual bool LookupObject(clang::LookupResult&, clang::Scope*) {
return false;
}
///\brief This callback is invoked whenever interpreter has committed new
/// portion of declarations.
///
///\param[out] - The transaction that was committed.
///
virtual void TransactionCommitted(const Transaction&) {}
///\brief This callback is invoked whenever interpreter has reverted a
/// portion of declarations.
///
///\param[out] - The transaction that was reverted.
///
virtual void TransactionUnloaded(const Transaction&) {};
};
} // end namespace cling

View File

@ -7,7 +7,7 @@
#ifndef CLING_TRANSACTION_H
#define CLING_TRANSACTION_H
#include "CompilationOptions.h"
#include "cling/Interpreter/CompilationOptions.h"
#include "clang/AST/DeclGroup.h"

View File

@ -5,7 +5,7 @@
//------------------------------------------------------------------------------
#include "ASTDumper.h"
#include "Transaction.h"
#include "cling/Interpreter/Transaction.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"

View File

@ -5,7 +5,7 @@
//------------------------------------------------------------------------------
#include "ASTNodeEraser.h"
#include "Transaction.h"
#include "cling/Interpreter/Transaction.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"

View File

@ -6,7 +6,7 @@
#include "DeclCollector.h"
#include "Transaction.h"
#include "cling/Interpreter/Transaction.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclGroup.h"

View File

@ -5,7 +5,7 @@
//------------------------------------------------------------------------------
#include "DeclExtractor.h"
#include "Transaction.h"
#include "cling/Interpreter/Transaction.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclGroup.h"

View File

@ -5,9 +5,9 @@
//------------------------------------------------------------------------------
#include "DynamicLookup.h"
#include "Transaction.h"
#include "cling/Interpreter/InterpreterCallbacks.h"
#include "cling/Interpreter/Transaction.h"
#include "cling/Utils/AST.h"
#include "clang/AST/ASTContext.h"
@ -26,9 +26,7 @@ namespace cling {
{}
// pin the vtable to this file
DynamicIDHandler::~DynamicIDHandler(){
delete Callbacks;
Callbacks = 0;
DynamicIDHandler::~DynamicIDHandler() {
}
bool DynamicIDHandler::LookupUnqualified(LookupResult& R, Scope* S) {

View File

@ -13,6 +13,7 @@
#include "ValuePrinterSynthesizer.h"
#include "cling/Interpreter/CIFactory.h"
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/InterpreterCallbacks.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
@ -170,6 +171,9 @@ namespace cling {
}
CurT->setState(Transaction::kCommitted);
InterpreterCallbacks* callbacks = m_Interpreter->getCallbacks();
if (callbacks && callbacks->isEnabled())
callbacks->TransactionCommitted(*CurT);
}
void IncrementalParser::rollbackTransaction(Transaction* T) const {
@ -345,6 +349,10 @@ namespace cling {
ASTNodeEraser NodeEraser(&getCI()->getSema());
NodeEraser.RevertTransaction(T);
InterpreterCallbacks* callbacks = m_Interpreter->getCallbacks();
if (callbacks && callbacks->isEnabled())
callbacks->TransactionUnloaded(*T);
}
} // namespace cling

View File

@ -8,8 +8,6 @@
#define CLING_INCREMENTAL_PARSER_H
#include "DeclCollector.h"
#include "CompilationOptions.h"
#include "Transaction.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclGroup.h"
@ -39,10 +37,12 @@ namespace clang {
namespace cling {
class CompilationOptions;
class CIFactory;
class DeclCollector;
class ExecutionContext;
class Interpreter;
class Transaction;
class TransactionTransformer;
///\brief Responsible for the incremental parsing and compilation of input.

View File

@ -6,17 +6,16 @@
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/LookupHelper.h"
#include "cling/Utils/AST.h"
#include "CompilationOptions.h"
#include "DynamicLookup.h"
#include "ExecutionContext.h"
#include "IncrementalParser.h"
#include "cling/Interpreter/CIFactory.h"
#include "cling/Interpreter/CompilationOptions.h"
#include "cling/Interpreter/InterpreterCallbacks.h"
#include "cling/Interpreter/LookupHelper.h"
#include "cling/Interpreter/Value.h"
#include "cling/Utils/AST.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Mangle.h"
@ -652,9 +651,12 @@ namespace cling {
}
void Interpreter::setCallbacks(InterpreterCallbacks* C) {
m_Callbacks.reset(C);
// FIXME: Terrible hack breaking the encapsulation.
Sema& S = getCI()->getSema();
assert(S.ExternalSource && "No ExternalSource set!");
static_cast<DynamicIDHandler*>(S.ExternalSource)->Callbacks = C;
if (S.ExternalSource)
static_cast<DynamicIDHandler*>(S.ExternalSource)->Callbacks = C;
}
void Interpreter::enableDynamicLookup(bool value /*=true*/) {

View File

@ -4,7 +4,7 @@
// author: Vassil Vassilev <vvasielv@cern.ch>
//------------------------------------------------------------------------------
#include "Transaction.h"
#include "cling/Interpreter/Transaction.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclBase.h"

View File

@ -1,6 +1,6 @@
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// version: $Id: Transaction.h 45164 2012-07-23 15:22:40Z vvassilev $
// version: $Id$
// author: Vassil Vassilev <vvasilev@cern.ch>
//------------------------------------------------------------------------------

View File

@ -6,8 +6,8 @@
#include "ValuePrinterSynthesizer.h"
#include "Transaction.h"
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/Transaction.h"
#include "cling/Utils/AST.h"
#include "clang/AST/ASTContext.h"