TestModuleFileExtension.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //===-- TestModuleFileExtension.h - Module Extension Tester -----*- 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. #ifndef LLVM_CLANG_FRONTEND_TESTMODULEFILEEXTENSION_H
  9. #define LLVM_CLANG_FRONTEND_TESTMODULEFILEEXTENSION_H
  10. #include "clang/Serialization/ModuleFileExtension.h"
  11. #include "clang/Basic/LLVM.h"
  12. #include "llvm/ADT/StringRef.h"
  13. #include "llvm/Bitstream/BitstreamReader.h"
  14. #include <string>
  15. namespace clang {
  16. /// A module file extension used for testing purposes.
  17. class TestModuleFileExtension
  18. : public llvm::RTTIExtends<TestModuleFileExtension, ModuleFileExtension> {
  19. std::string BlockName;
  20. unsigned MajorVersion;
  21. unsigned MinorVersion;
  22. bool Hashed;
  23. std::string UserInfo;
  24. class Writer : public ModuleFileExtensionWriter {
  25. public:
  26. Writer(ModuleFileExtension *Ext) : ModuleFileExtensionWriter(Ext) { }
  27. ~Writer() override;
  28. void writeExtensionContents(Sema &SemaRef,
  29. llvm::BitstreamWriter &Stream) override;
  30. };
  31. class Reader : public ModuleFileExtensionReader {
  32. llvm::BitstreamCursor Stream;
  33. public:
  34. ~Reader() override;
  35. Reader(ModuleFileExtension *Ext, const llvm::BitstreamCursor &InStream);
  36. };
  37. public:
  38. static char ID;
  39. TestModuleFileExtension(StringRef BlockName, unsigned MajorVersion,
  40. unsigned MinorVersion, bool Hashed,
  41. StringRef UserInfo)
  42. : BlockName(BlockName), MajorVersion(MajorVersion),
  43. MinorVersion(MinorVersion), Hashed(Hashed), UserInfo(UserInfo) {}
  44. ~TestModuleFileExtension() override;
  45. ModuleFileExtensionMetadata getExtensionMetadata() const override;
  46. void hashExtension(ExtensionHashBuilder &HBuilder) const override;
  47. std::unique_ptr<ModuleFileExtensionWriter>
  48. createExtensionWriter(ASTWriter &Writer) override;
  49. std::unique_ptr<ModuleFileExtensionReader>
  50. createExtensionReader(const ModuleFileExtensionMetadata &Metadata,
  51. ASTReader &Reader, serialization::ModuleFile &Mod,
  52. const llvm::BitstreamCursor &Stream) override;
  53. std::string str() const;
  54. };
  55. } // end namespace clang
  56. #endif // LLVM_CLANG_FRONTEND_TESTMODULEFILEEXTENSION_H