#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "llvm/Support/YAMLTraits.h" #include "revng/ADT/UpcastablePointer.h" #include "revng/TupleTree/TupleLikeTraits.h" template void initializeOwningPointer(llvm::StringRef Kind, llvm::yaml::IO &TheIO, O &Obj) { using concrete_types = concrete_types_traits_t; if constexpr (I < std::tuple_size_v) { using type = typename std::tuple_element_t; if (llvm::StringRef(TupleLikeTraits::Name) == Kind) { Obj.reset(new type); } else { initializeOwningPointer(Kind, TheIO, Obj); } } else { revng_abort(); } } template void dispatchMappingTraits(llvm::yaml::IO &TheIO, O &Obj) { using concrete_types = concrete_types_traits_t; if constexpr (I < std::tuple_size_v) { using type = typename std::tuple_element_t; auto Pointer = Obj.get(); if (llvm::isa(Pointer)) { llvm::yaml::MappingTraits::mapping(TheIO, *llvm::cast(Pointer)); } else { dispatchMappingTraits(TheIO, Obj); } } else { revng_abort(); } } template struct PolymorphicMappingTraits { static void mapping(llvm::yaml::IO &TheIO, T &Obj) { if (!TheIO.outputting()) { std::string Kind; TheIO.mapRequired("Kind", Kind); initializeOwningPointer(Kind, TheIO, Obj); } dispatchMappingTraits(TheIO, Obj); } };