blob: 513431709f48a3ac7ccac452eb95ccc40b933911 [file] [log] [blame]
Dmitri Gribenkoae99b752012-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
14#ifndef LLVM_CLANG_CXCOMMENT_H
15#define LLVM_CLANG_CXCOMMENT_H
16
17#include "clang-c/Index.h"
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000018#include "CXTranslationUnit.h"
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000019
20#include "clang/AST/Comment.h"
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000021#include "clang/AST/ASTContext.h"
22#include "clang/Frontend/ASTUnit.h"
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000023
24namespace clang {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000025namespace comments {
26 class CommandTraits;
27}
28
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000029namespace cxcomment {
30
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000031inline CXComment createCXComment(const comments::Comment *C,
32 CXTranslationUnit TU) {
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000033 CXComment Result;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000034 Result.ASTNode = C;
35 Result.TranslationUnit = TU;
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000036 return Result;
37}
38
39inline const comments::Comment *getASTNode(CXComment CXC) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000040 return static_cast<const comments::Comment *>(CXC.ASTNode);
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000041}
42
43template<typename T>
44inline 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
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000052inline ASTContext &getASTContext(CXComment CXC) {
53 return static_cast<ASTUnit *>(CXC.TranslationUnit->TUData)->getASTContext();
54}
55
56inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
57 return getASTContext(CXC).getCommentCommandTraits();
58}
59
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000060} // end namespace cxcomment
61} // end namespace clang
62
63#endif
64