blob: a937a8034636a6fba127730cd998609d8f6f9f19 [file] [log] [blame]
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +00001//===- CXComment.h - Routines for manipulating CXComments -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines routines for manipulating CXComments.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
15#define LLVM_CLANG_TOOLS_LIBCLANG_CXCOMMENT_H
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000016
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000017#include "CXTranslationUnit.h"
Alp Toker59c6bc52014-04-28 02:39:27 +000018#include "clang-c/Documentation.h"
Chandler Carruth575bc3ba2015-01-14 11:23:58 +000019#include "clang-c/Index.h"
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000020#include "clang/AST/ASTContext.h"
Chandler Carruthcc0694c2012-12-04 09:25:21 +000021#include "clang/AST/Comment.h"
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000022#include "clang/Frontend/ASTUnit.h"
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000023
24namespace clang {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000025namespace comments {
26 class CommandTraits;
27}
28
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000029namespace cxcomment {
30
Dmitri Gribenkoff431602013-11-13 20:19:22 +000031static inline CXComment createCXComment(const comments::Comment *C,
32 CXTranslationUnit TU) {
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000033 CXComment Result;
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000034 Result.ASTNode = C;
35 Result.TranslationUnit = TU;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000036 return Result;
37}
38
Dmitri Gribenkoff431602013-11-13 20:19:22 +000039static inline const comments::Comment *getASTNode(CXComment CXC) {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000040 return static_cast<const comments::Comment *>(CXC.ASTNode);
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000041}
42
43template<typename T>
Dmitri Gribenkoff431602013-11-13 20:19:22 +000044static inline const T *getASTNodeAs(CXComment CXC) {
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000045 const comments::Comment *C = getASTNode(CXC);
46 if (!C)
Craig Topper69186e72014-06-08 08:38:04 +000047 return nullptr;
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000048
49 return dyn_cast<T>(C);
50}
51
Dmitri Gribenkoff431602013-11-13 20:19:22 +000052static inline ASTContext &getASTContext(CXComment CXC) {
Dmitri Gribenkoc22ea1c2013-01-26 18:53:38 +000053 return cxtu::getASTUnit(CXC.TranslationUnit)->getASTContext();
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000054}
55
Dmitri Gribenkoff431602013-11-13 20:19:22 +000056static inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
Dmitri Gribenko7acbf002012-09-10 20:32:42 +000057 return getASTContext(CXC).getCommentCommandTraits();
58}
59
Dmitri Gribenko5e4fe002012-07-20 21:34:34 +000060} // end namespace cxcomment
61} // end namespace clang
62
63#endif
64