CXComment.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===- CXComment.h - Routines for manipulating CXComments -----------------===//
  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 CXComments.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
  13. #define LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
  14. #include "CXTranslationUnit.h"
  15. #include "clang-c/Documentation.h"
  16. #include "clang-c/Index.h"
  17. #include "clang/AST/ASTContext.h"
  18. #include "clang/AST/Comment.h"
  19. #include "clang/Frontend/ASTUnit.h"
  20. namespace clang {
  21. namespace comments {
  22. class CommandTraits;
  23. }
  24. namespace cxcomment {
  25. static inline CXComment createCXComment(const comments::Comment *C,
  26. CXTranslationUnit TU) {
  27. CXComment Result;
  28. Result.ASTNode = C;
  29. Result.TranslationUnit = TU;
  30. return Result;
  31. }
  32. static inline const comments::Comment *getASTNode(CXComment CXC) {
  33. return static_cast<const comments::Comment *>(CXC.ASTNode);
  34. }
  35. template<typename T>
  36. static inline const T *getASTNodeAs(CXComment CXC) {
  37. const comments::Comment *C = getASTNode(CXC);
  38. if (!C)
  39. return nullptr;
  40. return dyn_cast<T>(C);
  41. }
  42. static inline ASTContext &getASTContext(CXComment CXC) {
  43. return cxtu::getASTUnit(CXC.TranslationUnit)->getASTContext();
  44. }
  45. static inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
  46. return getASTContext(CXC).getCommentCommandTraits();
  47. }
  48. } // end namespace cxcomment
  49. } // end namespace clang
  50. #endif