From: Argyrios Kyrtzidis Date: Tue, 5 Mar 2013 20:21:14 +0000 (+0000) Subject: [libclang] When logging a CXTranslationUnit that came from an AST file, print out... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44f65a587ee39c20e715c9df411c864d328c71b5;p=clang [libclang] When logging a CXTranslationUnit that came from an AST file, print out the filename. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176511 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 9a02c0c2b8..108114dd67 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -485,6 +485,9 @@ public: StringRef getMainFileName() const; + /// \brief If this ASTUnit came from an AST file, returns the filename for it. + StringRef getASTFileName() const; + typedef std::vector::iterator top_level_iterator; top_level_iterator top_level_begin() { diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 3dc6e2e607..4a956ff3ab 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1711,6 +1711,15 @@ StringRef ASTUnit::getMainFileName() const { return StringRef(); } +StringRef ASTUnit::getASTFileName() const { + if (!isMainFileAST()) + return StringRef(); + + serialization::ModuleFile & + Mod = Reader->getModuleManager().getPrimaryModule(); + return Mod.FileName; +} + ASTUnit *ASTUnit::create(CompilerInvocation *CI, IntrusiveRefCntPtr Diags, bool CaptureDiagnostics, diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 36224a8cff..2cfaea442b 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -6387,6 +6387,8 @@ Logger &cxindex::Logger::operator<<(CXTranslationUnit TU) { if (TU) { if (ASTUnit *Unit = cxtu::getASTUnit(TU)) { LogOS << '<' << Unit->getMainFileName() << '>'; + if (Unit->isMainFileAST()) + LogOS << " (" << Unit->getASTFileName() << ')'; return *this; } }