#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include #include "revng/ADT/CompilationTime.h" #include "revng/ADT/Concepts.h" #include "revng/Model/DynamicFunction.h" #include "revng/Model/Function.h" #include "revng/Model/Identifier.h" #include "revng/Model/Segment.h" namespace model { template concept EntityWithKey = requires(Type &&Value) { { Value.key() } -> std::convertible_to; }; template concept EntityWithCustomName = requires(Type &&Value) { { Value.CustomName() } -> std::convertible_to; }; template concept EntityWithOriginalName = requires(Type &&Value) { { Value.OriginalName() } -> std::convertible_to; }; template concept EntityWithComment = requires(Type &&Value) { { Value.Comment() } -> std::convertible_to; }; template concept EntityWithReturnValueComment = requires(Type &&Value) { { Value.ReturnValueComment() } -> std::convertible_to; }; template LHS ©Metadata(LHS &To, const RHS &From) { if constexpr (EntityWithCustomName && EntityWithCustomName) To.CustomName() = From.CustomName(); if constexpr (EntityWithOriginalName && EntityWithOriginalName) To.OriginalName() = From.OriginalName(); if constexpr (EntityWithComment && EntityWithComment) To.Comment() = From.Comment(); if constexpr (EntityWithReturnValueComment && EntityWithReturnValueComment) { To.ReturnValueComment() = From.ReturnValueComment(); } return To; } template LHS &moveMetadata(LHS &To, RHS &&From) { if constexpr (EntityWithCustomName && EntityWithCustomName) To.CustomName() = std::move(From.CustomName()); if constexpr (EntityWithOriginalName && EntityWithOriginalName) To.OriginalName() = std::move(From.OriginalName()); if constexpr (EntityWithComment && EntityWithComment) To.Comment() = std::move(From.Comment()); if constexpr (EntityWithReturnValueComment && EntityWithReturnValueComment) { To.ReturnValueComment() = std::move(From.ReturnValueComment()); } return To; } template bool hasMetadata(Type &Value) { if constexpr (EntityWithCustomName) if (!Value.CustomName().empty()) return true; if constexpr (EntityWithOriginalName) if (!Value.OriginalName().empty()) return true; if constexpr (EntityWithComment) if (!Value.Comment().empty()) return true; if constexpr (EntityWithReturnValueComment) if (!Value.ReturnValueComment().empty()) return true; return false; } } // namespace model