clang-tools  8.0.0
Mapper.h
Go to the documentation of this file.
1 //===-- Mapper.h - ClangDoc Mapper ------------------------------*- C++ -*-===//
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 implements the Mapper piece of the clang-doc tool. It implements
11 // a RecursiveASTVisitor to look at each declaration and populate the info
12 // into the internal representation. Each seen declaration is serialized to
13 // to bitcode and written out to the ExecutionContext as a KV pair where the
14 // key is the declaration's USR and the value is the serialized bitcode.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
19 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
20 
21 #include "Representation.h"
22 #include "clang/AST/RecursiveASTVisitor.h"
23 #include "clang/Tooling/Execution.h"
24 
25 using namespace clang::comments;
26 using namespace clang::tooling;
27 
28 namespace clang {
29 namespace doc {
30 
31 class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>,
32  public ASTConsumer {
33 public:
34  explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx)
35  : CDCtx(CDCtx) {}
36 
37  void HandleTranslationUnit(ASTContext &Context) override;
38  bool VisitNamespaceDecl(const NamespaceDecl *D);
39  bool VisitRecordDecl(const RecordDecl *D);
40  bool VisitEnumDecl(const EnumDecl *D);
41  bool VisitCXXMethodDecl(const CXXMethodDecl *D);
42  bool VisitFunctionDecl(const FunctionDecl *D);
43 
44 private:
45  template <typename T> bool mapDecl(const T *D);
46 
47  int getLine(const NamedDecl *D, const ASTContext &Context) const;
48  StringRef getFile(const NamedDecl *D, const ASTContext &Context) const;
49  comments::FullComment *getComment(const NamedDecl *D,
50  const ASTContext &Context) const;
51 
52  ClangDocContext CDCtx;
53 };
54 
55 } // namespace doc
56 } // namespace clang
57 
58 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
Context Ctx
const Decl * D
Definition: XRefs.cpp:79
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx)
Definition: Mapper.h:34