From 3d4bb2b95423927e0d38266fad28ecdf9658a484 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Mon, 22 Jun 2015 15:18:05 +0200 Subject: [PATCH] Fix fwd-decl detection and loops. --- lib/Interpreter/AutoloadCallback.cpp | 57 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/Interpreter/AutoloadCallback.cpp b/lib/Interpreter/AutoloadCallback.cpp index 0066553b..42597ab6 100644 --- a/lib/Interpreter/AutoloadCallback.cpp +++ b/lib/Interpreter/AutoloadCallback.cpp @@ -255,35 +255,36 @@ namespace cling { if (T.decls_begin()->m_DGR.isNull()) return; - if (const NamedDecl* ND = dyn_cast(*T.decls_begin()->m_DGR.begin())) - if (ND->getIdentifier() && ND->getName().equals("__Cling_Autoloading_Map")) { - AutoloadingVisitor defaultArgsStateCollector; - Preprocessor& PP = m_Interpreter->getCI()->getPreprocessor(); - for (Transaction::const_iterator I = T.decls_begin(), E = T.decls_end(); - I != E; ++I) { - Transaction::DelayCallInfo DCI = *I; - - // if (DCI.m_Call != Transaction::kCCIHandleTopLevelDecl) - // continue; - if (DCI.m_DGR.isNull()) - continue; - - if (const NamedDecl* ND = dyn_cast(*T.decls_begin()->m_DGR.begin())) - if (ND->getIdentifier() - && ND->getName().equals("__Cling_Autoloading_Map")) { - - for (Transaction::const_iterator I = T.decls_begin(), - E = T.decls_end(); I != E; ++I) { - Transaction::DelayCallInfo DCI = *I; - for (DeclGroupRef::iterator J = DCI.m_DGR.begin(), - JE = DCI.m_DGR.end(); J != JE; ++J) { - defaultArgsStateCollector.TrackDefaultArgStateOf(*J, m_Map, PP); - } - } - } - - } + // The first decl must be + // extern int __Cling_Autoloading_Map; + bool HaveAutoloadingMapMarker = false; + for (auto I = T.decls_begin(), E = T.decls_end(); + !HaveAutoloadingMapMarker && I != E; ++I) { + if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl) + return; + for (auto&& D: I->m_DGR) { + if (isa(D)) + continue; + else if (auto VD = dyn_cast(D)) { + HaveAutoloadingMapMarker + = VD->hasExternalStorage() && VD->getIdentifier() + && VD->getName().equals("__Cling_Autoloading_Map"); + if (!HaveAutoloadingMapMarker) + return; + break; + } else + return; } + } + + if (!HaveAutoloadingMapMarker) + return; + + AutoloadingVisitor defaultArgsStateCollector; + Preprocessor& PP = m_Interpreter->getCI()->getPreprocessor(); + for (auto I = T.decls_begin(), E = T.decls_end(); I != E; ++I) + for (auto&& D: I->m_DGR) + defaultArgsStateCollector.TrackDefaultArgStateOf(D, m_Map, PP); } } //end namespace cling