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_CXTRANSLATIONUNIT_H 15 #define LLVM_CLANG_CXTRANSLATIONUNIT_H 16 17 #include "CXString.h" 18 #include "CLog.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 43 static inline ASTUnit *getASTUnit(CXTranslationUnit TU) { 44 if (!TU) 45 return 0; 46 return TU->TheASTUnit; 47 } 48 49 static inline bool isNotUseableTU(CXTranslationUnit TU) { 50 return !TU; 51 } 52 53 #define LOG_BAD_TU(TU) \ 54 do { \ 55 LOG_FUNC_SECTION { \ 56 *Log << "called with a bad TU: " << TU; \ 57 } \ 58 } while(false) 59 60 class CXTUOwner { 61 CXTranslationUnitImpl *TU; 62 63 public: 64 CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { } 65 ~CXTUOwner(); 66 67 CXTranslationUnitImpl *getTU() const { return TU; } 68 69 CXTranslationUnitImpl *takeTU() { 70 CXTranslationUnitImpl *retTU = TU; 71 TU = 0; 72 return retTU; 73 } 74 }; 75 76 77 }} // end namespace clang::cxtu 78 79 #endif 80