12 #include "clang/AST/Comment.h"
13 #include "clang/Index/USRGeneration.h"
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/Support/Error.h"
17 using clang::comments::FullComment;
23 TraverseDecl(Context.getTranslationUnitDecl());
26 template <
typename T>
bool MapASTVisitor::mapDecl(
const T *D) {
28 if (D->getASTContext().getSourceManager().isInSystemHeader(D->getLocation()))
32 if (D->getParentFunctionOrMethod())
35 llvm::SmallString<128> USR;
37 if (index::generateUSRForDecl(D, USR))
40 llvm::SmallString<128> File =
41 getFile(D, D->getASTContext(), CDCtx.
SourceRoot, IsFileInRootDir);
43 getLine(D, D->getASTContext()), File,
49 CDCtx.
ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.first->USR)),
52 CDCtx.
ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.second->USR)),
71 if (dyn_cast<CXXMethodDecl>(D))
76 comments::FullComment *
77 MapASTVisitor::getComment(
const NamedDecl *D,
const ASTContext &Context)
const {
78 RawComment *Comment = Context.getRawCommentForDeclNoCache(D);
81 Comment->setAttached();
82 return Comment->parse(Context,
nullptr, D);
87 int MapASTVisitor::getLine(
const NamedDecl *D,
88 const ASTContext &Context)
const {
89 return Context.getSourceManager().getPresumedLoc(D->getBeginLoc()).getLine();
92 llvm::SmallString<128> MapASTVisitor::getFile(
const NamedDecl *D,
93 const ASTContext &Context,
94 llvm::StringRef RootDir,
95 bool &IsFileInRootDir)
const {
96 llvm::SmallString<128> File(Context.getSourceManager()
97 .getPresumedLoc(D->getBeginLoc())
99 IsFileInRootDir =
false;
100 if (RootDir.empty() || !File.startswith(RootDir))
102 IsFileInRootDir =
true;
103 llvm::SmallString<128> Prefix(RootDir);
108 if (!llvm::sys::path::is_separator(Prefix.back()))
109 Prefix += llvm::sys::path::get_separator();
110 llvm::sys::path::replace_path_prefix(File, Prefix,
"");