clang API Documentation
00001 //===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 /// 00010 /// \file 00011 /// \brief This file defines the structure of a YAML document for serializing 00012 /// replacements. 00013 /// 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H 00017 #define LLVM_CLANG_TOOLING_REPLACEMENTSYAML_H 00018 00019 #include "clang/Tooling/Refactoring.h" 00020 #include "llvm/Support/YAMLTraits.h" 00021 #include <string> 00022 #include <vector> 00023 00024 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement) 00025 00026 namespace llvm { 00027 namespace yaml { 00028 00029 /// \brief Specialized MappingTraits to describe how a Replacement is 00030 /// (de)serialized. 00031 template <> struct MappingTraits<clang::tooling::Replacement> { 00032 /// \brief Helper to (de)serialize a Replacement since we don't have direct 00033 /// access to its data members. 00034 struct NormalizedReplacement { 00035 NormalizedReplacement(const IO &) 00036 : FilePath(""), Offset(0), Length(0), ReplacementText("") {} 00037 00038 NormalizedReplacement(const IO &, const clang::tooling::Replacement &R) 00039 : FilePath(R.getFilePath()), Offset(R.getOffset()), 00040 Length(R.getLength()), ReplacementText(R.getReplacementText()) {} 00041 00042 clang::tooling::Replacement denormalize(const IO &) { 00043 return clang::tooling::Replacement(FilePath, Offset, Length, 00044 ReplacementText); 00045 } 00046 00047 std::string FilePath; 00048 unsigned int Offset; 00049 unsigned int Length; 00050 std::string ReplacementText; 00051 }; 00052 00053 static void mapping(IO &Io, clang::tooling::Replacement &R) { 00054 MappingNormalization<NormalizedReplacement, clang::tooling::Replacement> 00055 Keys(Io, R); 00056 Io.mapRequired("FilePath", Keys->FilePath); 00057 Io.mapRequired("Offset", Keys->Offset); 00058 Io.mapRequired("Length", Keys->Length); 00059 Io.mapRequired("ReplacementText", Keys->ReplacementText); 00060 } 00061 }; 00062 00063 /// \brief Specialized MappingTraits to describe how a 00064 /// TranslationUnitReplacements is (de)serialized. 00065 template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> { 00066 static void mapping(IO &Io, 00067 clang::tooling::TranslationUnitReplacements &Doc) { 00068 Io.mapRequired("MainSourceFile", Doc.MainSourceFile); 00069 Io.mapOptional("Context", Doc.Context, std::string()); 00070 Io.mapRequired("Replacements", Doc.Replacements); 00071 } 00072 }; 00073 } // end namespace yaml 00074 } // end namespace llvm 00075 00076 #endif