Ted Kremenek | 7df92ae | 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H |
| 15 | #define LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H |
Ted Kremenek | 7df92ae | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 16 | |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 17 | #include "CLog.h" |
Chandler Carruth | 757fcd6 | 2014-03-04 10:05:20 +0000 | [diff] [blame] | 18 | #include "CXString.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 19 | #include "clang-c/Index.h" |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 20 | |
Dmitri Gribenko | d36209e | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 21 | namespace clang { |
| 22 | class ASTUnit; |
| 23 | class CIndexer; |
Dmitri Gribenko | 9e60511 | 2013-11-13 22:16:51 +0000 | [diff] [blame] | 24 | namespace index { |
| 25 | class CommentToXMLConverter; |
| 26 | } // namespace index |
Dmitri Gribenko | d36209e | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 27 | } // namespace clang |
| 28 | |
Ted Kremenek | 7df92ae | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 29 | struct CXTranslationUnitImpl { |
Dmitri Gribenko | 183436e | 2013-01-26 21:49:50 +0000 | [diff] [blame] | 30 | clang::CIndexer *CIdx; |
Dmitri Gribenko | d36209e | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 31 | clang::ASTUnit *TheASTUnit; |
Dmitri Gribenko | b95b3f1 | 2013-01-26 22:44:19 +0000 | [diff] [blame] | 32 | clang::cxstring::CXStringPool *StringPool; |
Ted Kremenek | d010ba4 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 33 | void *Diagnostics; |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 34 | void *OverridenCursorsPool; |
Dmitri Gribenko | 9e60511 | 2013-11-13 22:16:51 +0000 | [diff] [blame] | 35 | clang::index::CommentToXMLConverter *CommentToXML; |
Ted Kremenek | 7df92ae | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 36 | }; |
Ted Kremenek | 7df92ae | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 37 | |
Argyrios Kyrtzidis | 769c7bc | 2011-10-12 07:07:33 +0000 | [diff] [blame] | 38 | namespace clang { |
Argyrios Kyrtzidis | 769c7bc | 2011-10-12 07:07:33 +0000 | [diff] [blame] | 39 | namespace cxtu { |
| 40 | |
Dmitri Gribenko | d36209e | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 41 | CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *AU); |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 42 | |
| 43 | static inline ASTUnit *getASTUnit(CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 2bee666 | 2013-04-09 20:03:03 +0000 | [diff] [blame] | 44 | if (!TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 45 | return nullptr; |
Dmitri Gribenko | d36209e | 2013-01-26 21:32:42 +0000 | [diff] [blame] | 46 | return TU->TheASTUnit; |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Dmitri Gribenko | ea4d1c3 | 2014-02-12 19:12:37 +0000 | [diff] [blame] | 49 | /// \returns true if the ASTUnit has a diagnostic about the AST file being |
| 50 | /// corrupted. |
| 51 | bool isASTReadError(ASTUnit *AU); |
| 52 | |
Dmitri Gribenko | 852d622 | 2014-02-11 15:02:48 +0000 | [diff] [blame] | 53 | static inline bool isNotUsableTU(CXTranslationUnit TU) { |
Dmitri Gribenko | 256454f | 2014-02-11 14:34:14 +0000 | [diff] [blame] | 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 | dc199a3 | 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; |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 75 | TU = nullptr; |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 76 | return retTU; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 81 | }} // end namespace clang::cxtu |
Argyrios Kyrtzidis | 769c7bc | 2011-10-12 07:07:33 +0000 | [diff] [blame] | 82 | |
Ted Kremenek | 7df92ae | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 83 | #endif |