clang  3.9.0
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 #include <vector>
23 
24 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
25 
26 namespace llvm {
27 namespace yaml {
28 
29 /// \brief Specialized MappingTraits to describe how a Replacement is
30 /// (de)serialized.
31 template <> struct MappingTraits<clang::tooling::Replacement> {
32  /// \brief Helper to (de)serialize a Replacement since we don't have direct
33  /// access to its data members.
34  struct NormalizedReplacement {
36  : FilePath(""), Offset(0), Length(0), ReplacementText("") {}
37 
39  : FilePath(R.getFilePath()), Offset(R.getOffset()),
40  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
41 
44  ReplacementText);
45  }
46 
47  std::string FilePath;
48  unsigned int Offset;
49  unsigned int Length;
50  std::string ReplacementText;
51  };
52 
53  static void mapping(IO &Io, clang::tooling::Replacement &R) {
54  MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
55  Keys(Io, R);
56  Io.mapRequired("FilePath", Keys->FilePath);
57  Io.mapRequired("Offset", Keys->Offset);
58  Io.mapRequired("Length", Keys->Length);
59  Io.mapRequired("ReplacementText", Keys->ReplacementText);
60  }
61 };
62 
63 /// \brief Specialized MappingTraits to describe how a
64 /// TranslationUnitReplacements is (de)serialized.
65 template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
66  static void mapping(IO &Io,
68  Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
69  Io.mapOptional("Context", Doc.Context, std::string());
70  Io.mapRequired("Replacements", Doc.Replacements);
71  }
72 };
73 } // end namespace yaml
74 } // end namespace llvm
75 
76 #endif
unsigned Length
const StringRef FilePath
static void mapping(IO &Io, clang::tooling::Replacement &R)
Collection of Replacements generated from a single translation unit.
Definition: Replacement.h:199
uint32_t Offset
Definition: CacheTokens.cpp:44
std::string Context
A freeform chunk of text to describe the context of the replacements.
Definition: Replacement.h:206
A text replacement.
Definition: Replacement.h:77
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Replacement.h:201
static void mapping(IO &Io, clang::tooling::TranslationUnitReplacements &Doc)
std::vector< Replacement > Replacements
Definition: Replacement.h:208
NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
const Expr * Replacement
Definition: AttributeList.h:58