clang  15.0.0git
ReplacementsYaml.h
Go to the documentation of this file.
1 //===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines the structure of a YAML document for serializing
11 /// replacements.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
16 #define LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
17 
19 #include "llvm/Support/YAMLTraits.h"
20 #include <string>
21 
22 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
23 
24 namespace llvm {
25 namespace yaml {
26 
27 /// Specialized MappingTraits to describe how a Replacement is
28 /// (de)serialized.
29 template <> struct MappingTraits<clang::tooling::Replacement> {
30  /// Helper to (de)serialize a Replacement since we don't have direct
31  /// access to its data members.
32  struct NormalizedReplacement {
33  NormalizedReplacement(const IO &) : Offset(0), Length(0) {}
34 
36  : FilePath(R.getFilePath()), Offset(R.getOffset()),
37  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
38 
40  return clang::tooling::Replacement(FilePath, Offset, Length,
41  ReplacementText);
42  }
43 
45  unsigned int Offset;
46  unsigned int Length;
48  };
49 
50  static void mapping(IO &Io, clang::tooling::Replacement &R) {
51  MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
52  Keys(Io, R);
53  Io.mapRequired("FilePath", Keys->FilePath);
54  Io.mapRequired("Offset", Keys->Offset);
55  Io.mapRequired("Length", Keys->Length);
56  Io.mapRequired("ReplacementText", Keys->ReplacementText);
57  }
58 };
59 
60 /// Specialized MappingTraits to describe how a
61 /// TranslationUnitReplacements is (de)serialized.
62 template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
63  static void mapping(IO &Io,
65  Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
66  Io.mapRequired("Replacements", Doc.Replacements);
67  }
68 };
69 } // end namespace yaml
70 } // end namespace llvm
71 
72 #endif
llvm::yaml::MappingTraits< clang::tooling::TranslationUnitReplacements >::mapping
static void mapping(IO &Io, clang::tooling::TranslationUnitReplacements &Doc)
Definition: ReplacementsYaml.h:63
clang::tooling::TranslationUnitReplacements::Replacements
std::vector< Replacement > Replacements
Definition: Replacement.h:336
clang::tooling::TranslationUnitReplacements::MainSourceFile
std::string MainSourceFile
Name of the main source for the translation unit.
Definition: Replacement.h:334
llvm
YAML serialization mapping.
Definition: Dominators.h:30
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::NormalizedReplacement
NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
Definition: ReplacementsYaml.h:35
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::yaml::MappingTraits< clang::tooling::Replacement >::mapping
static void mapping(IO &Io, clang::tooling::Replacement &R)
Definition: ReplacementsYaml.h:50
Offset
unsigned Offset
Definition: Format.cpp:2553
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::Offset
unsigned int Offset
Definition: ReplacementsYaml.h:45
clang::tooling::TranslationUnitReplacements
Collection of Replacements generated from a single translation unit.
Definition: Replacement.h:332
Refactoring.h
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::NormalizedReplacement
NormalizedReplacement(const IO &)
Definition: ReplacementsYaml.h:33
clang::tooling::Replacement
A text replacement.
Definition: Replacement.h:83
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::FilePath
std::string FilePath
Definition: ReplacementsYaml.h:44
clang
Definition: CalledOnceCheck.h:17
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::denormalize
clang::tooling::Replacement denormalize(const IO &)
Definition: ReplacementsYaml.h:39
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::ReplacementText
std::string ReplacementText
Definition: ReplacementsYaml.h:47
llvm::yaml::MappingTraits< clang::tooling::Replacement >::NormalizedReplacement::Length
unsigned int Length
Definition: ReplacementsYaml.h:46