Serialize.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===-- Serializer.h - ClangDoc Serializer ----------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the serializing functions fro the clang-doc tool. Given
  10. // a particular declaration, it collects the appropriate information and returns
  11. // a serialized bitcode string for the declaration.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H
  15. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H
  16. #include "Representation.h"
  17. #include "clang/AST/AST.h"
  18. #include "clang/AST/CommentVisitor.h"
  19. #include <string>
  20. #include <vector>
  21. using namespace clang::comments;
  22. namespace clang {
  23. namespace doc {
  24. namespace serialize {
  25. // The first element will contain the relevant information about the declaration
  26. // passed as parameter.
  27. // The second element will contain the relevant information about the
  28. // declaration's parent, it can be a NamespaceInfo or RecordInfo.
  29. // Both elements can be nullptrs if the declaration shouldn't be handled.
  30. // When the declaration is handled, the first element will be a nullptr for
  31. // EnumDecl, FunctionDecl and CXXMethodDecl; they are only returned wrapped in
  32. // its parent scope. For NamespaceDecl and RecordDecl both elements are not
  33. // nullptr.
  34. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  35. emitInfo(const NamespaceDecl *D, const FullComment *FC, int LineNumber,
  36. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  37. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  38. emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber,
  39. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  40. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  41. emitInfo(const EnumDecl *D, const FullComment *FC, int LineNumber,
  42. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  43. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  44. emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  45. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  46. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  47. emitInfo(const CXXMethodDecl *D, const FullComment *FC, int LineNumber,
  48. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  49. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  50. emitInfo(const TypedefDecl *D, const FullComment *FC, int LineNumber,
  51. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  52. std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
  53. emitInfo(const TypeAliasDecl *D, const FullComment *FC, int LineNumber,
  54. StringRef File, bool IsFileInRootDir, bool PublicOnly);
  55. // Function to hash a given USR value for storage.
  56. // As USRs (Unified Symbol Resolution) could be large, especially for functions
  57. // with long type arguments, we use 160-bits SHA1(USR) values to
  58. // guarantee the uniqueness of symbols while using a relatively small amount of
  59. // memory (vs storing USRs directly).
  60. SymbolID hashUSR(llvm::StringRef USR);
  61. std::string serialize(std::unique_ptr<Info> &I);
  62. } // namespace serialize
  63. } // namespace doc
  64. } // namespace clang
  65. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H