1f4a2713aSLionel Sambuc //===- CXTranslationUnit.h - Routines for manipulating CXTranslationUnits -===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This file defines routines for manipulating CXTranslationUnits. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H 15*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H 16f4a2713aSLionel Sambuc 17*0a6a1f1dSLionel Sambuc #include "CLog.h" 18f4a2713aSLionel Sambuc #include "CXString.h" 19*0a6a1f1dSLionel Sambuc #include "clang-c/Index.h" 20f4a2713aSLionel Sambuc 21f4a2713aSLionel Sambuc namespace clang { 22f4a2713aSLionel Sambuc class ASTUnit; 23f4a2713aSLionel Sambuc class CIndexer; 24f4a2713aSLionel Sambuc namespace index { 25f4a2713aSLionel Sambuc class CommentToXMLConverter; 26f4a2713aSLionel Sambuc } // namespace index 27f4a2713aSLionel Sambuc } // namespace clang 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambuc struct CXTranslationUnitImpl { 30f4a2713aSLionel Sambuc clang::CIndexer *CIdx; 31f4a2713aSLionel Sambuc clang::ASTUnit *TheASTUnit; 32f4a2713aSLionel Sambuc clang::cxstring::CXStringPool *StringPool; 33f4a2713aSLionel Sambuc void *Diagnostics; 34f4a2713aSLionel Sambuc void *OverridenCursorsPool; 35f4a2713aSLionel Sambuc clang::index::CommentToXMLConverter *CommentToXML; 36f4a2713aSLionel Sambuc }; 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc namespace clang { 39f4a2713aSLionel Sambuc namespace cxtu { 40f4a2713aSLionel Sambuc 41f4a2713aSLionel Sambuc CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *AU); 42f4a2713aSLionel Sambuc getASTUnit(CXTranslationUnit TU)43f4a2713aSLionel Sambucstatic inline ASTUnit *getASTUnit(CXTranslationUnit TU) { 44f4a2713aSLionel Sambuc if (!TU) 45*0a6a1f1dSLionel Sambuc return nullptr; 46f4a2713aSLionel Sambuc return TU->TheASTUnit; 47f4a2713aSLionel Sambuc } 48f4a2713aSLionel Sambuc 49*0a6a1f1dSLionel Sambuc /// \returns true if the ASTUnit has a diagnostic about the AST file being 50*0a6a1f1dSLionel Sambuc /// corrupted. 51*0a6a1f1dSLionel Sambuc bool isASTReadError(ASTUnit *AU); 52*0a6a1f1dSLionel Sambuc isNotUsableTU(CXTranslationUnit TU)53*0a6a1f1dSLionel Sambucstatic inline bool isNotUsableTU(CXTranslationUnit TU) { 54*0a6a1f1dSLionel Sambuc return !TU; 55*0a6a1f1dSLionel Sambuc } 56*0a6a1f1dSLionel Sambuc 57*0a6a1f1dSLionel Sambuc #define LOG_BAD_TU(TU) \ 58*0a6a1f1dSLionel Sambuc do { \ 59*0a6a1f1dSLionel Sambuc LOG_FUNC_SECTION { \ 60*0a6a1f1dSLionel Sambuc *Log << "called with a bad TU: " << TU; \ 61*0a6a1f1dSLionel Sambuc } \ 62*0a6a1f1dSLionel Sambuc } while(false) 63*0a6a1f1dSLionel Sambuc 64f4a2713aSLionel Sambuc class CXTUOwner { 65f4a2713aSLionel Sambuc CXTranslationUnitImpl *TU; 66f4a2713aSLionel Sambuc 67f4a2713aSLionel Sambuc public: CXTUOwner(CXTranslationUnitImpl * tu)68f4a2713aSLionel Sambuc CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { } 69f4a2713aSLionel Sambuc ~CXTUOwner(); 70f4a2713aSLionel Sambuc getTU()71f4a2713aSLionel Sambuc CXTranslationUnitImpl *getTU() const { return TU; } 72f4a2713aSLionel Sambuc takeTU()73f4a2713aSLionel Sambuc CXTranslationUnitImpl *takeTU() { 74f4a2713aSLionel Sambuc CXTranslationUnitImpl *retTU = TU; 75*0a6a1f1dSLionel Sambuc TU = nullptr; 76f4a2713aSLionel Sambuc return retTU; 77f4a2713aSLionel Sambuc } 78f4a2713aSLionel Sambuc }; 79f4a2713aSLionel Sambuc 80f4a2713aSLionel Sambuc 81f4a2713aSLionel Sambuc }} // end namespace clang::cxtu 82f4a2713aSLionel Sambuc 83f4a2713aSLionel Sambuc #endif 84