ReplacementsYaml.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// This file defines the structure of a YAML document for serializing
  16. /// replacements.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
  20. #define LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
  21. #include "clang/Tooling/Refactoring.h"
  22. #include "llvm/Support/YAMLTraits.h"
  23. #include <string>
  24. LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
  25. namespace llvm {
  26. namespace yaml {
  27. /// Specialized MappingTraits to describe how a Replacement is
  28. /// (de)serialized.
  29. template <> struct MappingTraits<clang::tooling::Replacement> {
  30. /// Helper to (de)serialize a Replacement since we don't have direct
  31. /// access to its data members.
  32. struct NormalizedReplacement {
  33. NormalizedReplacement(const IO &) : Offset(0), Length(0) {}
  34. NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
  35. : FilePath(R.getFilePath()), Offset(R.getOffset()),
  36. Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
  37. clang::tooling::Replacement denormalize(const IO &) {
  38. return clang::tooling::Replacement(FilePath, Offset, Length,
  39. ReplacementText);
  40. }
  41. std::string FilePath;
  42. unsigned int Offset;
  43. unsigned int Length;
  44. std::string ReplacementText;
  45. };
  46. static void mapping(IO &Io, clang::tooling::Replacement &R) {
  47. MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
  48. Keys(Io, R);
  49. Io.mapRequired("FilePath", Keys->FilePath);
  50. Io.mapRequired("Offset", Keys->Offset);
  51. Io.mapRequired("Length", Keys->Length);
  52. Io.mapRequired("ReplacementText", Keys->ReplacementText);
  53. }
  54. };
  55. /// Specialized MappingTraits to describe how a
  56. /// TranslationUnitReplacements is (de)serialized.
  57. template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
  58. static void mapping(IO &Io,
  59. clang::tooling::TranslationUnitReplacements &Doc) {
  60. Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
  61. Io.mapRequired("Replacements", Doc.Replacements);
  62. }
  63. };
  64. } // end namespace yaml
  65. } // end namespace llvm
  66. #endif
  67. #ifdef __GNUC__
  68. #pragma GCC diagnostic pop
  69. #endif