xref: /openbsd-src/gnu/llvm/clang/tools/libclang/CXComment.h (revision e5dd70708596ae51455a0ffa086a00c5b29f8583)
1*e5dd7070Spatrick //===- CXComment.h - Routines for manipulating CXComments -----------------===//
2*e5dd7070Spatrick //
3*e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5*e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e5dd7070Spatrick //
7*e5dd7070Spatrick //===----------------------------------------------------------------------===//
8*e5dd7070Spatrick //
9*e5dd7070Spatrick // This file defines routines for manipulating CXComments.
10*e5dd7070Spatrick //
11*e5dd7070Spatrick //===----------------------------------------------------------------------===//
12*e5dd7070Spatrick 
13*e5dd7070Spatrick #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
14*e5dd7070Spatrick #define LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
15*e5dd7070Spatrick 
16*e5dd7070Spatrick #include "CXTranslationUnit.h"
17*e5dd7070Spatrick #include "clang-c/Documentation.h"
18*e5dd7070Spatrick #include "clang-c/Index.h"
19*e5dd7070Spatrick #include "clang/AST/ASTContext.h"
20*e5dd7070Spatrick #include "clang/AST/Comment.h"
21*e5dd7070Spatrick #include "clang/Frontend/ASTUnit.h"
22*e5dd7070Spatrick 
23*e5dd7070Spatrick namespace clang {
24*e5dd7070Spatrick namespace comments {
25*e5dd7070Spatrick   class CommandTraits;
26*e5dd7070Spatrick }
27*e5dd7070Spatrick 
28*e5dd7070Spatrick namespace cxcomment {
29*e5dd7070Spatrick 
createCXComment(const comments::Comment * C,CXTranslationUnit TU)30*e5dd7070Spatrick static inline CXComment createCXComment(const comments::Comment *C,
31*e5dd7070Spatrick                                         CXTranslationUnit TU) {
32*e5dd7070Spatrick   CXComment Result;
33*e5dd7070Spatrick   Result.ASTNode = C;
34*e5dd7070Spatrick   Result.TranslationUnit = TU;
35*e5dd7070Spatrick   return Result;
36*e5dd7070Spatrick }
37*e5dd7070Spatrick 
getASTNode(CXComment CXC)38*e5dd7070Spatrick static inline const comments::Comment *getASTNode(CXComment CXC) {
39*e5dd7070Spatrick   return static_cast<const comments::Comment *>(CXC.ASTNode);
40*e5dd7070Spatrick }
41*e5dd7070Spatrick 
42*e5dd7070Spatrick template<typename T>
getASTNodeAs(CXComment CXC)43*e5dd7070Spatrick static inline const T *getASTNodeAs(CXComment CXC) {
44*e5dd7070Spatrick   const comments::Comment *C = getASTNode(CXC);
45*e5dd7070Spatrick   if (!C)
46*e5dd7070Spatrick     return nullptr;
47*e5dd7070Spatrick 
48*e5dd7070Spatrick   return dyn_cast<T>(C);
49*e5dd7070Spatrick }
50*e5dd7070Spatrick 
getASTContext(CXComment CXC)51*e5dd7070Spatrick static inline ASTContext &getASTContext(CXComment CXC) {
52*e5dd7070Spatrick   return cxtu::getASTUnit(CXC.TranslationUnit)->getASTContext();
53*e5dd7070Spatrick }
54*e5dd7070Spatrick 
getCommandTraits(CXComment CXC)55*e5dd7070Spatrick static inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
56*e5dd7070Spatrick   return getASTContext(CXC).getCommentCommandTraits();
57*e5dd7070Spatrick }
58*e5dd7070Spatrick 
59*e5dd7070Spatrick } // end namespace cxcomment
60*e5dd7070Spatrick } // end namespace clang
61*e5dd7070Spatrick 
62*e5dd7070Spatrick #endif
63*e5dd7070Spatrick 
64