clang  6.0.0svn
ReplacementsYaml.h
Go to the documentation of this file.
1 //===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file defines the structure of a YAML document for serializing
12 /// replacements.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
17 #define LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
18 
20 #include "llvm/Support/YAMLTraits.h"
21 #include <string>
22 
23 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
24 
25 namespace llvm {
26 namespace yaml {
27 
28 /// \brief Specialized MappingTraits to describe how a Replacement is
29 /// (de)serialized.
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 {
35  : FilePath(""), Offset(0), Length(0), ReplacementText("") {}
36 
38  : FilePath(R.getFilePath()), Offset(R.getOffset()),
39  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
40 
42  return clang::tooling::Replacement(FilePath, Offset, Length,
43  ReplacementText);
44  }
45 
46  std::string FilePath;
47  unsigned int Offset;
48  unsigned int Length;
49  std::string ReplacementText;
50  };
51 
52  static void mapping(IO &Io, clang::tooling::Replacement &R) {
53  MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
54  Keys(Io, R);
55  Io.mapRequired("FilePath", Keys->FilePath);
56  Io.mapRequired("Offset", Keys->Offset);
57  Io.mapRequired("Length", Keys->Length);
58  Io.mapRequired("ReplacementText", Keys->ReplacementText);
59  }
60 };
61 
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,
67  Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
68  Io.mapRequired("Replacements", Doc.Replacements);
69  }
70 };
71 } // end namespace yaml
72 } // end namespace llvm
73 
74 #endif
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
static void mapping(IO &Io, clang::tooling::Replacement &R)
Collection of Replacements generated from a single translation unit.
Definition: Replacement.h:329
uint32_t Offset
Definition: CacheTokens.cpp:43
A text replacement.
Definition: Replacement.h:81
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Replacement.h:331
static void mapping(IO &Io, clang::tooling::TranslationUnitReplacements &Doc)
Dataflow Directional Tag Classes.
std::vector< Replacement > Replacements
Definition: Replacement.h:332
NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
const Expr * Replacement
Definition: AttributeList.h:59