From 0c74a310d89480cae5cc7b0e135098a59aa2c247 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Thu, 27 Jun 2013 14:30:07 +0200 Subject: [PATCH] Rebase to master/HEAD; split commitTransaction(); select needed parts in emitAllDecls(). --- lib/Interpreter/IncrementalParser.cpp | 64 ++++++++++----------------- lib/Interpreter/IncrementalParser.h | 20 ++++++++- lib/Interpreter/Interpreter.cpp | 8 +++- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/lib/Interpreter/IncrementalParser.cpp b/lib/Interpreter/IncrementalParser.cpp index 73497155..c905db68 100644 --- a/lib/Interpreter/IncrementalParser.cpp +++ b/lib/Interpreter/IncrementalParser.cpp @@ -235,30 +235,8 @@ namespace cling { commitTransaction(*I); } - bool success = true; - // We are sure it's safe to pipe it through the transformers - for (size_t i = 0; i < m_ASTTransformers.size(); ++i) { - success = m_ASTTransformers[i]->TransformTransaction(*T); - if (!success) { - break; - } - } - - m_CI->getDiagnostics().Reset(); // FIXME: Should be in rollback transaction. - - if (!success) { - // Roll back on error in a transformer - rollbackTransaction(T); + if (!transformTransactionAST(T)) return; - } - - // Pull all template instantiations in that came from the consumers. - Transaction::State oldState = T->getState(); - T->setState(Transaction::kCollecting); - getCI()->getSema().PerformPendingInstantiations(); - T->setState(oldState); - - m_Consumer->HandleTranslationUnit(getCI()->getASTContext()); // Here we expect a template instantiation. We need to open the transaction // that we are currently work with. @@ -301,7 +279,7 @@ namespace cling { } - void IncrementalParser::markWholeTransactionAsUsed(Transaction* T) { + void IncrementalParser::markWholeTransactionAsUsed(Transaction* T) const { for (size_t Idx = 0; Idx < T->size() /*can change in the loop!*/; ++Idx) { Transaction::DelayCallInfo I = (*T)[Idx]; // FIXME: implement for multiple decls in a DGR. @@ -358,35 +336,39 @@ namespace cling { } getCodeGenerator()->HandleTranslationUnit(getCI()->getASTContext()); - - // The static initializers might run anything and can thus cause more - // decls that need to end up in a transaction. But this one is done - // with CodeGen... - T->setState(Transaction::kCommitted); - runStaticInitOnTransaction(T); } - void IncrementalParser::transformTransactionAST(Transaction* T) const { + bool IncrementalParser::transformTransactionAST(Transaction* T) const { + bool success = true; + // We are sure it's safe to pipe it through the transformers + for (size_t i = 0; success && i < m_ASTTransformers.size(); ++i) + success = m_ASTTransformers[i]->TransformTransaction(*T); + + m_CI->getDiagnostics().Reset(); // FIXME: Should be in rollback transaction. + + if (!success) + rollbackTransaction(T); + + return success; } bool IncrementalParser::transformTransactionIR(Transaction* T) const { // Transform IR - for (size_t i = 0; i < m_IRTransformers.size(); ++i) { + bool success = true; + for (size_t i = 0; success && i < m_IRTransformers.size(); ++i) success = m_IRTransformers[i]->TransformTransaction(*T); - if (!success) - return false; - } - return true; + if (!success) + rollbackTransaction(T); + return success; } bool IncrementalParser::runStaticInitOnTransaction(Transaction* T) const { // run the static initializers that came from codegenning - if (m_Interpreter->runStaticInitializersOnce() - >= Interpreter::kExeFirstError) { - // Roll back on error in a transformer + bool success = + m_Interpreter->runStaticInitializersOnce() < Interpreter::kExeFirstError; + if (!success) rollbackTransaction(T); - return; - } + return success; } void IncrementalParser::rollbackTransaction(Transaction* T) const { diff --git a/lib/Interpreter/IncrementalParser.h b/lib/Interpreter/IncrementalParser.h index ced48292..c73c6309 100644 --- a/lib/Interpreter/IncrementalParser.h +++ b/lib/Interpreter/IncrementalParser.h @@ -193,9 +193,27 @@ namespace cling { /// ///\param[in] T - the transaction for which all decls will get a UsedAttr. /// - void markWholeTransactionAsUsed(Transaction* T); + void markWholeTransactionAsUsed(Transaction* T) const; + + ///\brief Runs the static initializers created by codegening a transaction. + /// + ///\param[in] T - the transaction for which to run the initializers. + /// + bool runStaticInitOnTransaction(Transaction* T) const; private: + ///\brief Runs AST transformers on a transaction. + /// + ///\param[in] T - the transaction to be transformed. + /// + bool transformTransactionAST(Transaction* T) const; + + ///\brief Runs IR transformers on a transaction. + /// + ///\param[in] T - the transaction to be transformed. + /// + bool transformTransactionIR(Transaction* T) const; + void CreateSLocOffsetGenerator(); EParseResult ParseInternal(llvm::StringRef input); }; diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 0df8f53d..faae1c18 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -596,8 +596,14 @@ namespace cling { assert(getCodeGenerator() && "No CodeGenerator?"); m_IncrParser->markWholeTransactionAsUsed(T); m_IncrParser->codeGenTransaction(T); - if (T->getState() == Transaction::kCommitted) + + // The static initializers might run anything and can thus cause more + // decls that need to end up in a transaction. But this one is done + // with CodeGen... + T->setState(Transaction::kCommitted); + if (m_IncrParser->runStaticInitOnTransaction(T)) return Interpreter::kSuccess; + return Interpreter::kFailure; }