Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 1 | //===- CXComment.h - Routines for manipulating CXComments -----------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines routines for manipulating CXComments. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 13 | #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H |
| 14 | #define LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 15 | |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 16 | #include "CXTranslationUnit.h" |
Alp Toker | 59c6bc5 | 2014-04-28 02:39:27 +0000 | [diff] [blame] | 17 | #include "clang-c/Documentation.h" |
Chandler Carruth | 575bc3ba | 2015-01-14 11:23:58 +0000 | [diff] [blame] | 18 | #include "clang-c/Index.h" |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
Chandler Carruth | cc0694c | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 20 | #include "clang/AST/Comment.h" |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/ASTUnit.h" |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 22 | |
| 23 | namespace clang { |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 24 | namespace comments { |
| 25 | class CommandTraits; |
| 26 | } |
| 27 | |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 28 | namespace cxcomment { |
| 29 | |
Dmitri Gribenko | ff43160 | 2013-11-13 20:19:22 +0000 | [diff] [blame] | 30 | static inline CXComment createCXComment(const comments::Comment *C, |
| 31 | CXTranslationUnit TU) { |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 32 | CXComment Result; |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 33 | Result.ASTNode = C; |
| 34 | Result.TranslationUnit = TU; |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 35 | return Result; |
| 36 | } |
| 37 | |
Dmitri Gribenko | ff43160 | 2013-11-13 20:19:22 +0000 | [diff] [blame] | 38 | static inline const comments::Comment *getASTNode(CXComment CXC) { |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 39 | return static_cast<const comments::Comment *>(CXC.ASTNode); |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | template<typename T> |
Dmitri Gribenko | ff43160 | 2013-11-13 20:19:22 +0000 | [diff] [blame] | 43 | static inline const T *getASTNodeAs(CXComment CXC) { |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 44 | const comments::Comment *C = getASTNode(CXC); |
| 45 | if (!C) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 46 | return nullptr; |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 47 | |
| 48 | return dyn_cast<T>(C); |
| 49 | } |
| 50 | |
Dmitri Gribenko | ff43160 | 2013-11-13 20:19:22 +0000 | [diff] [blame] | 51 | static inline ASTContext &getASTContext(CXComment CXC) { |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 52 | return cxtu::getASTUnit(CXC.TranslationUnit)->getASTContext(); |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Dmitri Gribenko | ff43160 | 2013-11-13 20:19:22 +0000 | [diff] [blame] | 55 | static inline comments::CommandTraits &getCommandTraits(CXComment CXC) { |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 56 | return getASTContext(CXC).getCommentCommandTraits(); |
| 57 | } |
| 58 | |
Dmitri Gribenko | 5e4fe00 | 2012-07-20 21:34:34 +0000 | [diff] [blame] | 59 | } // end namespace cxcomment |
| 60 | } // end namespace clang |
| 61 | |
| 62 | #endif |
| 63 | |