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