12#include "clang/AST/Comment.h"
13#include "clang/Index/USRGeneration.h"
14#include "llvm/ADT/StringExtras.h"
15#include "llvm/Support/Error.h"
21 TraverseDecl(Context.getTranslationUnitDecl());
24template <
typename T>
bool MapASTVisitor::mapDecl(
const T *D) {
26 if (D->getASTContext().getSourceManager().isInSystemHeader(D->getLocation()))
30 if (D->getParentFunctionOrMethod())
33 llvm::SmallString<128>
USR;
35 if (index::generateUSRForDecl(D,
USR))
38 llvm::SmallString<128> File =
39 getFile(D, D->getASTContext(), CDCtx.
SourceRoot, IsFileInRootDir);
41 getLine(D, D->getASTContext()), File,
47 CDCtx.
ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.first->USR)),
50 CDCtx.
ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.second->USR)),
69 if (isa<CXXMethodDecl>(D))
82comments::FullComment *
83MapASTVisitor::getComment(
const NamedDecl *D,
const ASTContext &Context)
const {
84 RawComment *Comment = Context.getRawCommentForDeclNoCache(D);
87 Comment->setAttached();
88 return Comment->parse(Context,
nullptr, D);
93int MapASTVisitor::getLine(
const NamedDecl *D,
94 const ASTContext &Context)
const {
95 return Context.getSourceManager().getPresumedLoc(D->getBeginLoc()).getLine();
98llvm::SmallString<128> MapASTVisitor::getFile(
const NamedDecl *D,
99 const ASTContext &Context,
100 llvm::StringRef RootDir,
101 bool &IsFileInRootDir)
const {
102 llvm::SmallString<128> File(Context.getSourceManager()
103 .getPresumedLoc(D->getBeginLoc())
105 IsFileInRootDir =
false;
106 if (RootDir.empty() || !File.starts_with(RootDir))
108 IsFileInRootDir =
true;
109 llvm::SmallString<128> Prefix(RootDir);
114 if (!llvm::sys::path::is_separator(Prefix.back()))
115 Prefix += llvm::sys::path::get_separator();
116 llvm::sys::path::replace_path_prefix(File, Prefix,
"");
void HandleTranslationUnit(ASTContext &Context) override
bool VisitEnumDecl(const EnumDecl *D)
bool VisitTypedefDecl(const TypedefDecl *D)
bool VisitCXXMethodDecl(const CXXMethodDecl *D)
bool VisitTypeAliasDecl(const TypeAliasDecl *D)
bool VisitRecordDecl(const RecordDecl *D)
bool VisitFunctionDecl(const FunctionDecl *D)
bool VisitNamespaceDecl(const NamespaceDecl *D)
std::pair< std::unique_ptr< Info >, std::unique_ptr< Info > > emitInfo(const NamespaceDecl *D, const FullComment *FC, int LineNumber, llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly)
static std::string serialize(T &I)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
tooling::ExecutionContext * ECtx