Add more handy interface that takes a number of transactions to be rolled back.

This commit is contained in:
Vassil Vassilev 2013-10-28 23:18:40 -05:00 committed by sftnight
parent a4c14b87e5
commit 91c54bda2e
4 changed files with 33 additions and 7 deletions

View File

@ -249,9 +249,6 @@ namespace cling {
void ignoreFakeDiagnostics() const;
public:
void unload();
Interpreter(int argc, const char* const *argv, const char* llvmdir = 0);
virtual ~Interpreter();
@ -481,6 +478,13 @@ namespace cling {
CompilationResult loadFile(const std::string& filename,
bool allowSharedLib = true);
///\brief Unloads (forgets) given number of transactions.
///
///\param[in] numberOfTransactions - how many transactions to revert
/// starting from the last.
///
void unload(unsigned numberOfTransactions);
bool isPrintingAST() const { return m_PrintAST; }
void enablePrintAST(bool print = true) { m_PrintAST = print; }

View File

@ -615,6 +615,17 @@ namespace cling {
return IncrementalParser::kSuccess;
}
void IncrementalParser::unloadLastNTransactions(unsigned N) {
assert(N <= m_Transactions.size() && "Unloading more than ever seen.");
while(true) {
unloadTransaction(m_Transactions.back());
m_Transactions.pop_back();
if (!N--)
break;
}
}
void IncrementalParser::unloadTransaction(Transaction* T) {
if (!T)
T = getLastTransaction();

View File

@ -191,7 +191,18 @@ namespace cling {
///
Transaction* Parse(llvm::StringRef input, const CompilationOptions& Opts);
///\brief Unloads last N transactions.
///
///\param[in] N - how many starting from the last seen.
///
void unloadLastNTransactions(unsigned N);
///\brief Unloads a given transaction.
///
///\param[in] T - The transaction to unload.
///
void unloadTransaction(Transaction* T);
void printTransactionStructure() const;
///\brief Adds a UsedAttr to all decls in the transaction.

View File

@ -148,10 +148,6 @@ namespace cling {
return m_IncrParser->getCodeGenerator();
}
void Interpreter::unload() {
m_IncrParser->unloadTransaction(0);
}
Interpreter::Interpreter(int argc, const char* const *argv,
const char* llvmdir /*= 0*/) :
m_UniqueCounter(0), m_PrintAST(false), m_PrintIR(false),
@ -772,6 +768,10 @@ namespace cling {
return res;
}
void Interpreter::unload(unsigned numberOfTransactions) {
m_IncrParser->unloadLastNTransactions(numberOfTransactions);
}
void Interpreter::installLazyFunctionCreator(void* (*fp)(const std::string&)) {
m_ExecutionContext->installLazyFunctionCreator(fp);
}