blob: 126227f8d767561db94e266c983759e6e2f09347 [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
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000017#include "CXTranslationUnit.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000018#include "clang-c/Index.h"
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000019#include "clang/AST/ASTContext.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000020#include "clang/AST/Comment.h"
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000021#include "clang/Frontend/ASTUnit.h"
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000022
23namespace clang {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000024namespace comments {
25 class CommandTraits;
26}
27
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000028namespace cxcomment {
29
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000030inline CXComment createCXComment(const comments::Comment *C,
31 CXTranslationUnit TU) {
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000032 CXComment Result;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000033 Result.ASTNode = C;
34 Result.TranslationUnit = TU;
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000035 return Result;
36}
37
38inline const comments::Comment *getASTNode(CXComment CXC) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000039 return static_cast<const comments::Comment *>(CXC.ASTNode);
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000040}
41
42template<typename T>
43inline const T *getASTNodeAs(CXComment CXC) {
44 const comments::Comment *C = getASTNode(CXC);
45 if (!C)
46 return NULL;
47
48 return dyn_cast<T>(C);
49}
50
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000051inline ASTContext &getASTContext(CXComment CXC) {
52 return static_cast<ASTUnit *>(CXC.TranslationUnit->TUData)->getASTContext();
53}
54
55inline comments::CommandTraits &getCommandTraits(CXComment CXC) {
56 return getASTContext(CXC).getCommentCommandTraits();
57}
58
Dmitri Gribenkoae99b752012-07-20 21:34:34 +000059} // end namespace cxcomment
60} // end namespace clang
61
62#endif
63