90 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file defines routines for manipulating CXTranslationUnits.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H14#define LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H15 16#include "CLog.h"17#include "CXString.h"18#include "clang-c/Index.h"19 20namespace clang {21 class ASTUnit;22 class CIndexer;23namespace index {24class CommentToXMLConverter;25} // namespace index26} // namespace clang27 28struct 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;37};38 39struct CXTargetInfoImpl {40 CXTranslationUnit TranslationUnit;41};42 43namespace clang {44namespace cxtu {45 46CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx,47 std::unique_ptr<ASTUnit> AU);48 49static inline ASTUnit *getASTUnit(CXTranslationUnit TU) {50 if (!TU)51 return nullptr;52 return TU->TheASTUnit;53}54 55/// \returns true if the ASTUnit has a diagnostic about the AST file being56/// corrupted.57bool isASTReadError(ASTUnit *AU);58 59static inline bool isNotUsableTU(CXTranslationUnit TU) {60 return !TU;61}62 63#define LOG_BAD_TU(TU) \64 do { \65 LOG_FUNC_SECTION { \66 *Log << "called with a bad TU: " << TU; \67 } \68 } while(false)69 70class CXTUOwner {71 CXTranslationUnitImpl *TU;72 73public:74 CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { }75 ~CXTUOwner();76 77 CXTranslationUnitImpl *getTU() const { return TU; }78 79 CXTranslationUnitImpl *takeTU() {80 CXTranslationUnitImpl *retTU = TU;81 TU = nullptr;82 return retTU;83 }84};85 86 87}} // end namespace clang::cxtu88 89#endif90