Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 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 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 17 | #include "CLog.h" |
Dmitri Gribenko | 9c48d16 | 2013-01-26 22:44:19 +0000 | [diff] [blame] | 18 | #include "CXString.h" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 19 | #include "clang-c/Index.h" |
Dmitri Gribenko | 5694feb | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 20 | |
Dmitri Gribenko | e42e578 | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 21 | namespace clang { |
| 22 | class ASTUnit; |
| 23 | class CIndexer; |
Dmitri Gribenko | 86cfda2 | 2013-11-13 22:16:51 +0000 | [diff] [blame] | 24 | namespace index { |
| 25 | class CommentToXMLConverter; |
| 26 | } // namespace index |
Dmitri Gribenko | e42e578 | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 27 | } // namespace clang |
| 28 | |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 29 | struct CXTranslationUnitImpl { |
Dmitri Gribenko | 8c718e7 | 2013-01-26 21:49:50 +0000 | [diff] [blame] | 30 | clang::CIndexer *CIdx; |
Dmitri Gribenko | e42e578 | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 31 | clang::ASTUnit *TheASTUnit; |
Dmitri Gribenko | 9c48d16 | 2013-01-26 22:44:19 +0000 | [diff] [blame] | 32 | clang::cxstring::CXStringPool *StringPool; |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 33 | void *Diagnostics; |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 34 | void *OverridenCursorsPool; |
Dmitri Gribenko | 86cfda2 | 2013-11-13 22:16:51 +0000 | [diff] [blame] | 35 | clang::index::CommentToXMLConverter *CommentToXML; |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 36 | }; |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 37 | |
Argyrios Kyrtzidis | 9049cf6 | 2011-10-12 07:07:33 +0000 | [diff] [blame] | 38 | namespace clang { |
Argyrios Kyrtzidis | 9049cf6 | 2011-10-12 07:07:33 +0000 | [diff] [blame] | 39 | namespace cxtu { |
| 40 | |
Dmitri Gribenko | e42e578 | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 41 | CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *AU); |
Dmitri Gribenko | 5694feb | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 42 | |
| 43 | static inline ASTUnit *getASTUnit(CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 8434722 | 2013-04-09 20:03:03 +0000 | [diff] [blame] | 44 | if (!TU) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 45 | return nullptr; |
Dmitri Gribenko | e42e578 | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 46 | return TU->TheASTUnit; |
Dmitri Gribenko | 5694feb | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 49 | /// \returns true if the ASTUnit has a diagnostic about the AST file being |
| 50 | /// corrupted. |
| 51 | bool isASTReadError(ASTUnit *AU); |
| 52 | |
| 53 | static 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 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 64 | class CXTUOwner { |
| 65 | CXTranslationUnitImpl *TU; |
| 66 | |
| 67 | public: |
| 68 | CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { } |
| 69 | ~CXTUOwner(); |
| 70 | |
| 71 | CXTranslationUnitImpl *getTU() const { return TU; } |
| 72 | |
| 73 | CXTranslationUnitImpl *takeTU() { |
| 74 | CXTranslationUnitImpl *retTU = TU; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 75 | TU = nullptr; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 76 | return retTU; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | |
Argyrios Kyrtzidis | 9049cf6 | 2011-10-12 07:07:33 +0000 | [diff] [blame] | 81 | }} // end namespace clang::cxtu |
| 82 | |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 83 | #endif |