CXTranslationUnit.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H
  13. #define LLVM_CLANG_TOOLS_LIBCLANG_CXTRANSLATIONUNIT_H
  14. #include "CLog.h"
  15. #include "CXString.h"
  16. #include "clang-c/Index.h"
  17. namespace clang {
  18. class ASTUnit;
  19. class CIndexer;
  20. namespace index {
  21. class CommentToXMLConverter;
  22. } // namespace index
  23. } // namespace clang
  24. struct CXTranslationUnitImpl {
  25. clang::CIndexer *CIdx;
  26. clang::ASTUnit *TheASTUnit;
  27. clang::cxstring::CXStringPool *StringPool;
  28. void *Diagnostics;
  29. void *OverridenCursorsPool;
  30. clang::index::CommentToXMLConverter *CommentToXML;
  31. unsigned ParsingOptions;
  32. std::vector<std::string> Arguments;
  33. };
  34. struct CXTargetInfoImpl {
  35. CXTranslationUnit TranslationUnit;
  36. };
  37. namespace clang {
  38. namespace cxtu {
  39. CXTranslationUnitImpl *MakeCXTranslationUnit(CIndexer *CIdx,
  40. std::unique_ptr<ASTUnit> AU);
  41. static inline ASTUnit *getASTUnit(CXTranslationUnit TU) {
  42. if (!TU)
  43. return nullptr;
  44. return TU->TheASTUnit;
  45. }
  46. /// \returns true if the ASTUnit has a diagnostic about the AST file being
  47. /// corrupted.
  48. bool isASTReadError(ASTUnit *AU);
  49. static inline bool isNotUsableTU(CXTranslationUnit TU) {
  50. return !TU;
  51. }
  52. #define LOG_BAD_TU(TU) \
  53. do { \
  54. LOG_FUNC_SECTION { \
  55. *Log << "called with a bad TU: " << TU; \
  56. } \
  57. } while(false)
  58. class CXTUOwner {
  59. CXTranslationUnitImpl *TU;
  60. public:
  61. CXTUOwner(CXTranslationUnitImpl *tu) : TU(tu) { }
  62. ~CXTUOwner();
  63. CXTranslationUnitImpl *getTU() const { return TU; }
  64. CXTranslationUnitImpl *takeTU() {
  65. CXTranslationUnitImpl *retTU = TU;
  66. TU = nullptr;
  67. return retTU;
  68. }
  69. };
  70. }} // end namespace clang::cxtu
  71. #endif