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