blob: d86ed2b8d342d593127838c58d22ec0b47822c3f [file] [log] [blame]
Ted Kremenek0a90d322010-11-17 23:24:11 +00001//===- 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 Hines651f13c2014-04-23 16:59:28 -070017#include "CLog.h"
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000018#include "CXString.h"
Stephen Hines651f13c2014-04-23 16:59:28 -070019#include "clang-c/Index.h"
Dmitri Gribenko5694feb2013-01-26 18:53:38 +000020
Dmitri Gribenkoe42e5782013-01-26 21:32:42 +000021namespace clang {
22 class ASTUnit;
23 class CIndexer;
Dmitri Gribenko86cfda22013-11-13 22:16:51 +000024namespace index {
25class CommentToXMLConverter;
26} // namespace index
Dmitri Gribenkoe42e5782013-01-26 21:32:42 +000027} // namespace clang
28
Ted Kremenek0a90d322010-11-17 23:24:11 +000029struct CXTranslationUnitImpl {
Dmitri Gribenko8c718e72013-01-26 21:49:50 +000030 clang::CIndexer *CIdx;
Dmitri Gribenkoe42e5782013-01-26 21:32:42 +000031 clang::ASTUnit *TheASTUnit;
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000032 clang::cxstring::CXStringPool *StringPool;
Ted Kremenek15322172011-11-10 08:43:12 +000033 void *Diagnostics;
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000034 void *OverridenCursorsPool;
Dmitri Gribenko86cfda22013-11-13 22:16:51 +000035 clang::index::CommentToXMLConverter *CommentToXML;
Ted Kremenek0a90d322010-11-17 23:24:11 +000036};
Ted Kremenek0a90d322010-11-17 23:24:11 +000037
Argyrios Kyrtzidis9049cf62011-10-12 07:07:33 +000038namespace clang {
Argyrios Kyrtzidis9049cf62011-10-12 07:07:33 +000039namespace cxtu {
40
Dmitri Gribenkoe42e5782013-01-26 21:32:42 +000041CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *AU);
Dmitri Gribenko5694feb2013-01-26 18:53:38 +000042
43static inline ASTUnit *getASTUnit(CXTranslationUnit TU) {
Argyrios Kyrtzidis84347222013-04-09 20:03:03 +000044 if (!TU)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070045 return nullptr;
Dmitri Gribenkoe42e5782013-01-26 21:32:42 +000046 return TU->TheASTUnit;
Dmitri Gribenko5694feb2013-01-26 18:53:38 +000047}
48
Stephen Hines651f13c2014-04-23 16:59:28 -070049/// \returns true if the ASTUnit has a diagnostic about the AST file being
50/// corrupted.
51bool isASTReadError(ASTUnit *AU);
52
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
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000064class CXTUOwner {
65 CXTranslationUnitImpl *TU;
66
67public:
68 CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { }
69 ~CXTUOwner();
70
71 CXTranslationUnitImpl *getTU() const { return TU; }
72
73 CXTranslationUnitImpl *takeTU() {
74 CXTranslationUnitImpl *retTU = TU;
Stephen Hinesc568f1e2014-07-21 00:47:37 -070075 TU = nullptr;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000076 return retTU;
77 }
78};
79
80
Argyrios Kyrtzidis9049cf62011-10-12 07:07:33 +000081}} // end namespace clang::cxtu
82
Ted Kremenek0a90d322010-11-17 23:24:11 +000083#endif