| 1 | //===- YAMLSourceEditFormat.cpp -------------------------------------------===// |
|---|---|
| 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 | #include "clang/ScalableStaticAnalysis/SourceTransformation/YAMLSourceEditFormat.h" |
| 10 | #include "clang/Tooling/ReplacementsYaml.h" |
| 11 | #include "llvm/Support/Error.h" |
| 12 | #include "llvm/Support/FileSystem.h" |
| 13 | #include "llvm/Support/YAMLTraits.h" |
| 14 | #include "llvm/Support/raw_ostream.h" |
| 15 | |
| 16 | using namespace clang; |
| 17 | using namespace ssaf; |
| 18 | |
| 19 | llvm::Error ssaf::writeYAMLSourceEdits( |
| 20 | const clang::tooling::TranslationUnitReplacements &Doc, |
| 21 | llvm::StringRef Path) { |
| 22 | std::error_code EC; |
| 23 | llvm::raw_fd_ostream OS(Path, EC, llvm::sys::fs::OF_None); |
| 24 | if (EC) |
| 25 | return llvm::createStringError(EC, S: "failed to open '"+ Path + "'"); |
| 26 | |
| 27 | // llvm::yaml::Output's stream operator binds to a non-const reference. |
| 28 | clang::tooling::TranslationUnitReplacements Mutable = Doc; |
| 29 | llvm::yaml::Output YAMLOut(OS); |
| 30 | YAMLOut << Mutable; |
| 31 | |
| 32 | return llvm::Error::success(); |
| 33 | } |
| 34 |