12#include "clang/AST/Comment.h"
13#include "clang/Index/USRGeneration.h"
14#include "llvm/ADT/StringExtras.h"
15#include "llvm/ADT/StringSet.h"
16#include "llvm/Support/Mutex.h"
25 if (
const auto *
C = dyn_cast<CXXRecordDecl>(D)) {
26 return C->getTypedefNameForAnonDecl();
32 TraverseDecl(Context.getTranslationUnitDecl());
36bool MapASTVisitor::mapDecl(
const T *D,
bool IsDefinition) {
38 if (D->getASTContext().getSourceManager().isInSystemHeader(D->getLocation()))
42 if (D->getParentFunctionOrMethod())
45 llvm::SmallString<128>
USR;
47 if (index::generateUSRForDecl(D,
USR))
52 StringRef Visited =
USR.str();
53 if (
USRVisited.count(Visited) && !isTypedefAnonRecord<T>(D))
60 llvm::SmallString<128> File =
61 getFile(D, D->getASTContext(), CDCtx.
SourceRoot, IsFileInRootDir);
63 getLine(D, D->getASTContext()), File,
69 CDCtx.
ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.first->USR)),
72 CDCtx.
ECtx->reportResult(llvm::toHex(llvm::toStringRef(I.second->USR)),
78 return mapDecl(D,
true);
82 return mapDecl(D, D->isThisDeclarationADefinition());
86 return mapDecl(D, D->isThisDeclarationADefinition());
90 return mapDecl(D, D->isThisDeclarationADefinition());
95 if (isa<CXXMethodDecl>(D))
97 return mapDecl(D, D->isThisDeclarationADefinition());
101 return mapDecl(D,
true);
105 return mapDecl(D,
true);
108comments::FullComment *
109MapASTVisitor::getComment(
const NamedDecl *D,
const ASTContext &Context)
const {
110 RawComment *Comment = Context.getRawCommentForDeclNoCache(D);
113 Comment->setAttached();
114 return Comment->parse(Context,
nullptr, D);
119int MapASTVisitor::getLine(
const NamedDecl *D,
120 const ASTContext &Context)
const {
121 return Context.getSourceManager().getPresumedLoc(D->getBeginLoc()).getLine();
124llvm::SmallString<128> MapASTVisitor::getFile(
const NamedDecl *D,
125 const ASTContext &Context,
126 llvm::StringRef RootDir,
127 bool &IsFileInRootDir)
const {
128 llvm::SmallString<128> File(Context.getSourceManager()
129 .getPresumedLoc(D->getBeginLoc())
131 IsFileInRootDir =
false;
132 if (RootDir.empty() || !File.starts_with(RootDir))
134 IsFileInRootDir =
true;
135 llvm::SmallString<128> Prefix(RootDir);
140 if (!llvm::sys::path::is_separator(Prefix.back()))
141 Prefix += llvm::sys::path::get_separator();
142 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)
static llvm::sys::Mutex USRVisitedGuard
bool isTypedefAnonRecord(const T *D)
static llvm::StringSet USRVisited
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
tooling::ExecutionContext * ECtx