[clang][NFC] Generalize getSpecificAttr for const attributes (#116606)
[llvm-project.git] / clang / tools / libclang / CXTranslationUnit.h
blob3424bf2997feb2f4cb032fe4c121a73d8456fe4f
1 //===- CXTranslationUnit.h - Routines for manipulating CXTranslationUnits -===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines routines for manipulating CXTranslationUnits.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H
14 #define LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H
16 #include "CLog.h"
17 #include "CXString.h"
18 #include "clang-c/Index.h"
20 namespace clang {
21 class ASTUnit;
22 class CIndexer;
23 namespace index {
24 class CommentToXMLConverter;
25 } // namespace index
26 } // namespace clang
28 struct CXTranslationUnitImpl {
29 clang::CIndexer *CIdx;
30 clang::ASTUnit *TheASTUnit;
31 clang::cxstring::CXStringPool *StringPool;
32 void *Diagnostics;
33 void *OverridenCursorsPool;
34 clang::index::CommentToXMLConverter *CommentToXML;
35 unsigned ParsingOptions;
36 std::vector<std::string> Arguments;
39 struct CXTargetInfoImpl {
40 CXTranslationUnit TranslationUnit;
43 namespace clang {
44 namespace cxtu {
46 CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx,
47 std::unique_ptr<ASTUnit> AU);
49 static inline ASTUnit *getASTUnit(CXTranslationUnit TU) {
50 if (!TU)
51 return nullptr;
52 return TU->TheASTUnit;
55 /// \returns true if the ASTUnit has a diagnostic about the AST file being
56 /// corrupted.
57 bool isASTReadError(ASTUnit *AU);
59 static inline bool isNotUsableTU(CXTranslationUnit TU) {
60 return !TU;
63 #define LOG_BAD_TU(TU) \
64 do { \
65 LOG_FUNC_SECTION { \
66 *Log << "called with a bad TU: " << TU; \
67 } \
68 } while(false)
70 class CXTUOwner {
71 CXTranslationUnitImpl *TU;
73 public:
74 CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { }
75 ~CXTUOwner();
77 CXTranslationUnitImpl *getTU() const { return TU; }
79 CXTranslationUnitImpl *takeTU() {
80 CXTranslationUnitImpl *retTU = TU;
81 TU = nullptr;
82 return retTU;
87 }} // end namespace clang::cxtu
89 #endif