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