Generators.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===-- Generators.h - ClangDoc Generator ----------------------*- 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. // Generator classes for converting declaration information into documentation
  9. // in a specified format.
  10. //===----------------------------------------------------------------------===//
  11. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
  12. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
  13. #include "Representation.h"
  14. #include "llvm/Support/Error.h"
  15. #include "llvm/Support/Registry.h"
  16. namespace clang {
  17. namespace doc {
  18. // Abstract base class for generators.
  19. // This is expected to be implemented and exposed via the GeneratorRegistry.
  20. class Generator {
  21. public:
  22. virtual ~Generator() = default;
  23. // Write out the decl info for the objects in the given map in the specified
  24. // format.
  25. virtual llvm::Error
  26. generateDocs(StringRef RootDir,
  27. llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
  28. const ClangDocContext &CDCtx) = 0;
  29. // This function writes a file with the index previously constructed.
  30. // It can be overwritten by any of the inherited generators.
  31. // If the override method wants to run this it should call
  32. // Generator::createResources(CDCtx);
  33. virtual llvm::Error createResources(ClangDocContext &CDCtx);
  34. // Write out one specific decl info to the destination stream.
  35. virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
  36. const ClangDocContext &CDCtx) = 0;
  37. static void addInfoToIndex(Index &Idx, const doc::Info *Info);
  38. };
  39. typedef llvm::Registry<Generator> GeneratorRegistry;
  40. llvm::Expected<std::unique_ptr<Generator>>
  41. findGeneratorByName(llvm::StringRef Format);
  42. std::string getTagType(TagTypeKind AS);
  43. } // namespace doc
  44. } // namespace clang
  45. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H