ReplacementsYaml.h revision 276479
138451Smsmith//===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
238451Smsmith//
338451Smsmith//                     The LLVM Compiler Infrastructure
438451Smsmith//
538451Smsmith// This file is distributed under the University of Illinois Open Source
638451Smsmith// License. See LICENSE.TXT for details.
738451Smsmith//
838451Smsmith//===----------------------------------------------------------------------===//
938451Smsmith///
1038451Smsmith/// \file
1138451Smsmith/// \brief This file defines the structure of a YAML document for serializing
1238451Smsmith/// replacements.
1338451Smsmith///
1438451Smsmith//===----------------------------------------------------------------------===//
1538451Smsmith
1638451Smsmith#ifndef LLVM_CLANG_TOOLING_REPLACEMENTS_YAML_H
1738451Smsmith#define LLVM_CLANG_TOOLING_REPLACEMENTS_YAML_H
1838451Smsmith
1938451Smsmith#include "clang/Tooling/Refactoring.h"
2038451Smsmith#include "llvm/Support/YAMLTraits.h"
2138451Smsmith#include <string>
2238451Smsmith#include <vector>
2338451Smsmith
2438451SmsmithLLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
2538451Smsmith
2638451Smsmithnamespace llvm {
2738451Smsmithnamespace yaml {
2838451Smsmith
2938451Smsmith/// \brief Specialized MappingTraits to describe how a Replacement is
3038451Smsmith/// (de)serialized.
3138451Smsmithtemplate <> struct MappingTraits<clang::tooling::Replacement> {
3238451Smsmith  /// \brief Helper to (de)serialize a Replacement since we don't have direct
3338451Smsmith  /// access to its data members.
3438451Smsmith  struct NormalizedReplacement {
3538451Smsmith    NormalizedReplacement(const IO &)
3638451Smsmith        : FilePath(""), Offset(0), Length(0), ReplacementText("") {}
3738451Smsmith
3838451Smsmith    NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
3938451Smsmith        : FilePath(R.getFilePath()), Offset(R.getOffset()),
4038451Smsmith          Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
4138451Smsmith
4238451Smsmith    clang::tooling::Replacement denormalize(const IO &) {
4338451Smsmith      return clang::tooling::Replacement(FilePath, Offset, Length,
4438451Smsmith                                         ReplacementText);
4538451Smsmith    }
4638451Smsmith
4738451Smsmith    std::string FilePath;
4838451Smsmith    unsigned int Offset;
4938451Smsmith    unsigned int Length;
5038451Smsmith    std::string ReplacementText;
5138451Smsmith  };
5238451Smsmith
5338451Smsmith  static void mapping(IO &Io, clang::tooling::Replacement &R) {
5438451Smsmith    MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
5538451Smsmith    Keys(Io, R);
5638451Smsmith    Io.mapRequired("FilePath", Keys->FilePath);
5738451Smsmith    Io.mapRequired("Offset", Keys->Offset);
5838451Smsmith    Io.mapRequired("Length", Keys->Length);
5938451Smsmith    Io.mapRequired("ReplacementText", Keys->ReplacementText);
6038451Smsmith  }
6138451Smsmith};
6238451Smsmith
6338451Smsmith/// \brief Specialized MappingTraits to describe how a
6438451Smsmith/// TranslationUnitReplacements is (de)serialized.
6538451Smsmithtemplate <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
6638451Smsmith  static void mapping(IO &Io,
6738451Smsmith                      clang::tooling::TranslationUnitReplacements &Doc) {
6838451Smsmith    Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
6938451Smsmith    Io.mapOptional("Context", Doc.Context, std::string());
7038451Smsmith    Io.mapRequired("Replacements", Doc.Replacements);
7138451Smsmith  }
7238451Smsmith};
7338451Smsmith} // end namespace yaml
7438451Smsmith} // end namespace llvm
7538451Smsmith
7638451Smsmith#endif // LLVM_CLANG_TOOLING_REPLACEMENTS_YAML_H
7738451Smsmith