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_REPLACEMENTSYAML_H
17 #define LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
19 #include "clang/Tooling/Refactoring.h"
20 #include "llvm/Support/YAMLTraits.h"
23 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
28 /// \brief Specialized MappingTraits to describe how a Replacement is
30 template <> struct MappingTraits<clang::tooling::Replacement> {
31 /// \brief Helper to (de)serialize a Replacement since we don't have direct
32 /// access to its data members.
33 struct NormalizedReplacement {
34 NormalizedReplacement(const IO &)
35 : FilePath(""), Offset(0), Length(0), ReplacementText("") {}
37 NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
38 : FilePath(R.getFilePath()), Offset(R.getOffset()),
39 Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
41 clang::tooling::Replacement denormalize(const IO &) {
42 return clang::tooling::Replacement(FilePath, Offset, Length,
49 std::string ReplacementText;
52 static void mapping(IO &Io, clang::tooling::Replacement &R) {
53 MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
55 Io.mapRequired("FilePath", Keys->FilePath);
56 Io.mapRequired("Offset", Keys->Offset);
57 Io.mapRequired("Length", Keys->Length);
58 Io.mapRequired("ReplacementText", Keys->ReplacementText);
62 /// \brief Specialized MappingTraits to describe how a
63 /// TranslationUnitReplacements is (de)serialized.
64 template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
65 static void mapping(IO &Io,
66 clang::tooling::TranslationUnitReplacements &Doc) {
67 Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
68 Io.mapOptional("Context", Doc.Context, std::string());
69 Io.mapRequired("Replacements", Doc.Replacements);
72 } // end namespace yaml
73 } // end namespace llvm