Workaround multiple DeclCollector instances.

This commit is contained in:
CristinaCristescu 2013-11-18 14:44:23 +01:00 committed by sftnight
parent d6e2f85d1c
commit 1d06b2725b
7 changed files with 21 additions and 19 deletions

View File

@ -375,8 +375,8 @@ namespace cling {
///
bool empty() const {
return m_DeclQueue.empty() && m_DeserializedDeclQueue.empty()
&& (!m_NestedTransactions || m_NestedTransactions->empty()
&& m_MacroDirectiveInfoQueue.empty());
&& (!m_NestedTransactions || m_NestedTransactions->empty())
&& m_MacroDirectiveInfoQueue.empty();
}
///\brief Appends a declaration group and source from which consumer

View File

@ -155,7 +155,7 @@ namespace cling {
///\param[in] MD - The MacroDecl containing the IdentifierInfo and
/// MacroDirective to forward.
///
void PreVisitMacro(const Transaction::MacroDirective* MD);
void PreVisitMacro(const clang::MacroDirective* MD);
///\brief Remove the macro from the Preprocessor.
/// @param[in] MD - The MacroDirectiveInfo containing the IdentifierInfo and
@ -695,7 +695,7 @@ namespace cling {
return false;
}
void MacroReverter::PreVisitMacro(const Transaction::MacroDirective* MD) {
void DeclReverter::PreVisitMacro(const clang::MacroDirective* MD) {
const SourceLocation Loc = MD->getLocation();
const SourceManager& SM = m_Sema->getSourceManager();
FileID FID = SM.getFileID(SM.getSpellingLoc(Loc));
@ -705,7 +705,7 @@ namespace cling {
bool DeclReverter::VisitMacro(const Transaction::MacroDirectiveInfo MacroD) {
assert(&MacroD && "The Macro is null");
PreVisitDecl(MacroD.m_MD);
PreVisitMacro(MacroD.m_MD);
Preprocessor& PP = m_Sema->getPreprocessor();
#ifndef NDEBUG

View File

@ -282,7 +282,7 @@ namespace cling {
CI->setASTConsumer(collector);
// Add the callback keeping track of the macro definitions
PP.addPPCallbacks(collector);
PP.addPPCallbacks(static_cast<PPCallbacks*>(collector));
// Set up Sema
CodeCompleteConsumer* CCC = 0;

View File

@ -82,9 +82,9 @@ namespace cling {
m_CurTransaction->append(DCI);
}
void DeclCollector::MacroDefined (const clang::Token &MacroNameTok,
const clang::MacroDirective *MD) {
Transaction::MacroDecl MDE(MacroNameTok.getIdentifierInfo(), MD);
void DeclCollector::MacroDefined(const clang::Token &MacroNameTok,
const clang::MacroDirective *MD) {
Transaction::MacroDirectiveInfo MDE(MacroNameTok.getIdentifierInfo(), MD);
m_CurTransaction->append(MDE);
}

View File

@ -29,7 +29,7 @@ namespace cling {
/// cling::DeclCollector is responsible for appending all the declarations
/// seen by clang.
///
class DeclCollector: public clang::ASTConsumer, public clang::PPCallbacks {
class DeclCollector: public clang::PPCallbacks, public clang::ASTConsumer {
private:
Transaction* m_CurTransaction;
@ -69,8 +69,8 @@ namespace cling {
/// \}
/// Macro support
void MacroDefined (const clang::Token &MacroNameTok,
const clang::MacroDirective *MD);
virtual void MacroDefined (const clang::Token &MacroNameTok,
const clang::MacroDirective *MD);
// dyn_cast/isa support
static bool classof(const clang::ASTConsumer*) { return true; }
};

View File

@ -178,6 +178,8 @@ namespace cling {
bool* fromJIT = 0) const;
llvm::ExecutionEngine* getExecutionEngine() const {
if (!m_engine)
return 0;
return m_engine.get();
}

View File

@ -173,20 +173,20 @@ namespace cling {
forceAppend(DelayCallInfo(DeclGroupRef(D), kCCIHandleTopLevelDecl));
}
void Transaction::append(MacroDecl MDE) {
assert(!MDE.m_II && "Appending null IdentifierInfo?!");
assert(!MDE.m_MD && "Appending null MacroDirective?!");
void Transaction::append(MacroDirectiveInfo MDE) {
assert(MDE.m_II && "Appending null IdentifierInfo?!");
assert(MDE.m_MD && "Appending null MacroDirective?!");
assert(getState() == kCollecting
&& "Cannot append declarations in current state.");
#ifndef NDEBUG
// Check for duplicates
for (size_t i = 0, e = m_MacroDeclQueue.size(); i < e; ++i) {
MacroDecl &oldMacroDecl (m_MacroDeclQueue[i]);
assert(oldMacroDecl != MDE && "Duplicates?!");
for (size_t i = 0, e = m_MacroDirectiveInfoQueue.size(); i < e; ++i) {
MacroDirectiveInfo &oldMacroDirectiveInfo (m_MacroDirectiveInfoQueue[i]);
assert(oldMacroDirectiveInfo != MDE && "Duplicates?!");
}
#endif
m_MacroDeclQueue.push_back(MDE);
m_MacroDirectiveInfoQueue.push_back(MDE);
}
void Transaction::erase(iterator pos) {