1 //===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file defines the structure of a YAML document for serializing
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_TOOLING_REPLACEMENTS_YAML_H
17 #define LLVM_CLANG_TOOLING_REPLACEMENTS_YAML_H
19 #include "clang/Tooling/Refactoring.h"
20 #include "llvm/Support/YAMLTraits.h"
24 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
29 /// \brief ScalarTraits to read/write std::string objects.
30 template <> struct ScalarTraits<std::string> {
31 static void output(const std::string &Val, void *, llvm::raw_ostream &Out) {
35 static StringRef input(StringRef Scalar, void *, std::string &Val) {
41 /// \brief Specialized MappingTraits to describe how a Replacement is
43 template <> struct MappingTraits<clang::tooling::Replacement> {
44 /// \brief Helper to (de)serialize a Replacement since we don't have direct
45 /// access to its data members.
46 struct NormalizedReplacement {
47 NormalizedReplacement(const IO &)
48 : FilePath(""), Offset(0), Length(0), ReplacementText("") {}
50 NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
51 : FilePath(R.getFilePath()), Offset(R.getOffset()),
52 Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
54 clang::tooling::Replacement denormalize(const IO &) {
55 return clang::tooling::Replacement(FilePath, Offset, Length,
62 std::string ReplacementText;
65 static void mapping(IO &Io, clang::tooling::Replacement &R) {
66 MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
68 Io.mapRequired("FilePath", Keys->FilePath);
69 Io.mapRequired("Offset", Keys->Offset);
70 Io.mapRequired("Length", Keys->Length);
71 Io.mapRequired("ReplacementText", Keys->ReplacementText);
75 /// \brief Specialized MappingTraits to describe how a
76 /// TranslationUnitReplacements is (de)serialized.
77 template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
78 static void mapping(IO &Io,
79 clang::tooling::TranslationUnitReplacements &Doc) {
80 Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
81 Io.mapOptional("Context", Doc.Context, std::string());
82 Io.mapRequired("Replacements", Doc.Replacements);
85 } // end namespace yaml
86 } // end namespace llvm
88 #endif // LLVM_CLANG_TOOLING_REPLACEMENTS_YAML_H