#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include #include #include #include "llvm/ADT/StringRef.h" #include "revng/ADT/Concepts.h" namespace pipeline { template requires(anyOf()) class Option { public: constexpr Option(const char *Name, T Default) : Default(std::forward(Default)), Name(Name) {} using Type = std::decay_t; T Default; const char *Name; }; template concept HasOptions = requires(T) { { T::Options }; }; namespace detail { template constexpr auto &getOptionInfo() { return std::get(Invokable::Options); } template llvm::StringRef getOptionName() { return getOptionInfo().Name; } template llvm::StringRef typeNameImpl(); template<> inline llvm::StringRef typeNameImpl() { return "string"; } template<> inline llvm::StringRef typeNameImpl() { return "int"; } template<> inline llvm::StringRef typeNameImpl() { return "uint64_t"; } template using ArgTypeImpl = std::decay_t())>; template using OptionTypeImpl = typename ArgTypeImpl::Type; template constexpr bool IsConstCharPtr = std::is_same_v, const char *>; template using OptionType = std::conditional_t, std::string, OptionTypeImpl>; template llvm::StringRef getTypeName() { return typeNameImpl>(); } template OptionType getOptionDefault() { return getOptionInfo().Default; } } // namespace detail } // namespace pipeline