blob: 30be06419ccfda7f756fdbd292653c21ce54e041 [file] [log] [blame]
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00001//===- CXComment.h - Routines for manipulating CXComments -----------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Gribenko5e4fe002012-07-20 21:34:34 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file defines routines for manipulating CXComments.
10//
11//===----------------------------------------------------------------------===//
12
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000013#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
14#define LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000015
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000016#include "CXTranslationUnit.h"
Alp Toker59c6bc52014-04-28 02:39:27 +000017#include "clang-c/Documentation.h"
Chandler Carruth575bc3ba2015-01-14 11:23:58 +000018#include "clang-c/Index.h"
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000019#include "clang/AST/ASTContext.h"
Chandler Carruthcc0694c2012-12-04 09:25:21 +000020#include "clang/AST/Comment.h"
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000021#include "clang/Frontend/ASTUnit.h"
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000022
23namespace clang {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000024namespace comments {
25 class CommandTraits;
26}
27
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000028namespace cxcomment {
29
Dmitri Gribenkoff431602013-11-13 20:19:22 +000030static inline CXComment createCXComment(const comments::Comment *C,
31 CXTranslationUnit TU) {
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000032 CXComment Result;
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000033 Result.ASTNode = C;
34 Result.TranslationUnit = TU;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000035 return Result;
36}
37
Dmitri Gribenkoff431602013-11-13 20:19:22 +000038static inline const comments::Comment *getASTNode(CXComment CXC) {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000039 return static_cast<const comments::Comment *>(CXC.ASTNode);
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000040}
41
42template<typename T>
Dmitri Gribenkoff431602013-11-13 20:19:22 +000043static inline const T *getASTNodeAs(CXComment CXC) {
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000044 const comments::Comment *C = getASTNode(CXC);
45 if (!C)
Craig Topper69186e72014-06-08 08:38:04 +000046 return nullptr;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000047
48 return dyn_cast<T>(C);
49}
50
Dmitri Gribenkoff431602013-11-13 20:19:22 +000051static inline ASTContext &getASTContext(CXComment CXC) {
Dmitri Gribenkoc22ea1c2013-01-26 18:53:38 +000052 return cxtu::getASTUnit(CXC.TranslationUnit)->getASTContext();
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000053}
54
Dmitri Gribenkoff431602013-11-13 20:19:22 +000055static inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000056 return getASTContext(CXC).getCommentCommandTraits();
57}
58
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000059} // end namespace cxcomment
60} // end namespace clang
61
62#endif
63