Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:12

0001 //===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// This file defines the structure of a YAML document for serializing
0011 /// replacements.
0012 ///
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
0016 #define LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H
0017 
0018 #include "clang/Tooling/Refactoring.h"
0019 #include "llvm/Support/YAMLTraits.h"
0020 #include <string>
0021 
0022 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
0023 
0024 namespace llvm {
0025 namespace yaml {
0026 
0027 /// Specialized MappingTraits to describe how a Replacement is
0028 /// (de)serialized.
0029 template <> struct MappingTraits<clang::tooling::Replacement> {
0030   /// Helper to (de)serialize a Replacement since we don't have direct
0031   /// access to its data members.
0032   struct NormalizedReplacement {
0033     NormalizedReplacement(const IO &) : Offset(0), Length(0) {}
0034 
0035     NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
0036         : FilePath(R.getFilePath()), Offset(R.getOffset()),
0037           Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
0038 
0039     clang::tooling::Replacement denormalize(const IO &) {
0040       return clang::tooling::Replacement(FilePath, Offset, Length,
0041                                          ReplacementText);
0042     }
0043 
0044     std::string FilePath;
0045     unsigned int Offset;
0046     unsigned int Length;
0047     std::string ReplacementText;
0048   };
0049 
0050   static void mapping(IO &Io, clang::tooling::Replacement &R) {
0051     MappingNormalization<NormalizedReplacement, clang::tooling::Replacement>
0052     Keys(Io, R);
0053     Io.mapRequired("FilePath", Keys->FilePath);
0054     Io.mapRequired("Offset", Keys->Offset);
0055     Io.mapRequired("Length", Keys->Length);
0056     Io.mapRequired("ReplacementText", Keys->ReplacementText);
0057   }
0058 };
0059 
0060 /// Specialized MappingTraits to describe how a
0061 /// TranslationUnitReplacements is (de)serialized.
0062 template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
0063   static void mapping(IO &Io,
0064                       clang::tooling::TranslationUnitReplacements &Doc) {
0065     Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
0066     Io.mapRequired("Replacements", Doc.Replacements);
0067   }
0068 };
0069 } // end namespace yaml
0070 } // end namespace llvm
0071 
0072 #endif