CXTranslationUnit.h revision 651f13cea278ec967336033dd032faef0e9fc2ec
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 "CLog.h"
18#include "CXString.h"
19#include "clang-c/Index.h"
20
21namespace clang {
22  class ASTUnit;
23  class CIndexer;
24namespace index {
25class CommentToXMLConverter;
26} // namespace index
27} // namespace clang
28
29struct 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
38namespace clang {
39namespace cxtu {
40
41CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx, ASTUnit *AU);
42
43static inline ASTUnit *getASTUnit(CXTranslationUnit TU) {
44  if (!TU)
45    return 0;
46  return TU->TheASTUnit;
47}
48
49/// \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
64class 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;
75    TU = 0;
76    return retTU;
77  }
78};
79
80
81}} // end namespace clang::cxtu
82
83#endif
84