Add a means to customize which file are ignored in ForwardDeclPrinter.

This will also rootcling to tell cling's ForwardDeclPrinter to consider the file included inside a LinkDef file as
being top level headers (rather than listing the linkdef itself\!).
This commit is contained in:
Philippe Canal 2016-02-18 16:37:09 -06:00 committed by sftnight
parent a754fcc65e
commit c1cb2ca6f2
4 changed files with 20 additions and 7 deletions

View File

@ -45,6 +45,7 @@ namespace clang {
class Sema;
class SourceLocation;
class SourceManager;
class PresumedLoc;
}
namespace cling {
@ -71,6 +72,9 @@ namespace cling {
///
class Interpreter {
public:
// IgnoreFilesFunc_t takes a const reference to avoid having to
// include the actual definition of PresumedLoc.
using IgnoreFilesFunc_t = bool (*)(const clang::PresumedLoc&);
///\brief Pushes a new transaction, which will collect the decls that came
/// within the scope of the RAII object. Calls commit transaction at
@ -659,7 +663,9 @@ namespace cling {
void forwardDeclare(Transaction& T, clang::Sema& S,
llvm::raw_ostream& out,
bool enableMacros = false,
llvm::raw_ostream* logs = 0) const;
llvm::raw_ostream* logs = 0,
IgnoreFilesFunc_t ignoreFiles =
[](const clang::PresumedLoc&) { return false;}) const;
friend class runtime::internal::LifetimeHandler;
};

View File

@ -26,10 +26,11 @@ namespace cling {
Sema& S,
const Transaction& T,
unsigned Indentation,
bool printMacros)
bool printMacros,
IgnoreFilesFunc_t ignoreFiles)
: m_Policy(clang::PrintingPolicy(clang::LangOptions())), m_Log(LogS),
m_Indentation(Indentation), m_SMgr(S.getSourceManager()),
m_Ctx(S.getASTContext()), m_SkipFlag(false) {
m_Ctx(S.getASTContext()), m_SkipFlag(false), m_IgnoreFile(ignoreFiles) {
m_PrintInstantiation = false;
m_Policy.SuppressTagKeyword = true;
@ -173,7 +174,7 @@ namespace cling {
// Walk up the include chain.
PresumedLoc PLoc = m_SMgr.getPresumedLoc(spellingLoc);
llvm::SmallVector<PresumedLoc, 16> PLocs;
while (true) {
while (!m_IgnoreFile(PLoc)) {
if (!m_SMgr.getPresumedLoc(PLoc.getIncludeLoc()).isValid())
break;
PLocs.push_back(PLoc);

View File

@ -90,6 +90,8 @@ namespace cling {
class ForwardDeclPrinter : public clang::DeclVisitor<ForwardDeclPrinter> {
private:
using IgnoreFilesFunc_t = bool (*)(const clang::PresumedLoc&);
clang::PrintingPolicy m_Policy; // intentional copy
llvm::raw_ostream& m_Log;
unsigned m_Indentation;
@ -102,6 +104,7 @@ namespace cling {
llvm::DenseMap<const clang::Decl*, bool> m_Visited; // fwd decl success
std::stack<llvm::raw_ostream*> m_StreamStack;
std::set<const char*> m_BuiltinNames;
IgnoreFilesFunc_t m_IgnoreFile; // Call back to ignore some top level files.
public:
ForwardDeclPrinter(llvm::raw_ostream& OutS,
@ -109,7 +112,9 @@ namespace cling {
clang::Sema& S,
const Transaction& T,
unsigned Indentation = 0,
bool printMacros = false);
bool printMacros = false,
IgnoreFilesFunc_t ignoreFiles =
[](const clang::PresumedLoc&) { return false; } );
// void VisitDeclContext(clang::DeclContext *DC, bool shouldIndent = true);

View File

@ -1335,12 +1335,13 @@ namespace cling {
void Interpreter::forwardDeclare(Transaction& T, Sema& S,
llvm::raw_ostream& out,
bool enableMacros /*=false*/,
llvm::raw_ostream* logs /*=0*/) const {
llvm::raw_ostream* logs /*=0*/,
IgnoreFilesFunc_t ignoreFiles /*= return always false*/) const {
llvm::raw_null_ostream null;
if (!logs)
logs = &null;
ForwardDeclPrinter visitor(out, *logs, S, T);
ForwardDeclPrinter visitor(out, *logs, S, T, 0, false, ignoreFiles);
visitor.printStats();
// Avoid assertion in the ~IncrementalParser.