16#ifndef LIB_ERROR_HELPER_H_
17#define LIB_ERROR_HELPER_H_
21#include <boost/format.hpp>
23#include "lib/error_message.h"
24#include "lib/source_file.h"
25#include "lib/stringify.h"
32static inline ErrorMessage error_helper(boost::format &f, ErrorMessage out) {
33 out.message = boost::str(f);
37template <
class... Args>
38auto error_helper(boost::format &f, ErrorMessage out,
const char *t, Args &&...args) {
39 return error_helper(f % t, out, std::forward<Args>(args)...);
42template <
typename T,
class... Args>
43auto error_helper(boost::format &f, ErrorMessage out,
const T &t,
44 Args &&...args) -> std::enable_if_t<Util::has_toString_v<T>, ErrorMessage>;
46template <
typename T,
class... Args>
47auto error_helper(boost::format &f, ErrorMessage out,
const T &t, Args &&...args)
48 -> std::enable_if_t<!Util::has_toString_v<T> && !std::is_pointer_v<T>, ErrorMessage>;
50template <
typename T,
class... Args>
51auto error_helper(boost::format &f, ErrorMessage out,
const T *t, Args &&...args) {
55 return error_helper(f, out, *t, std::forward<Args>(args)...);
58template <
class... Args>
59ErrorMessage error_helper(boost::format &f, ErrorMessage out,
const Util::SourceInfo &
info,
61 if (
info.isValid()) out.locations.push_back(
info);
62 return error_helper(f %
"", std::move(out), std::forward<Args>(args)...);
66void maybeAddSourceInfo(ErrorMessage &out,
const T &t) {
67 if constexpr (Util::has_SourceInfo_v<T>) {
68 auto info = t.getSourceInfo();
69 if (
info.isValid()) out.locations.push_back(
info);
73template <
typename T,
class... Args>
74auto error_helper(boost::format &f, ErrorMessage out,
const T &t, Args &&...args)
75 -> std::enable_if_t<!Util::has_toString_v<T> && !std::is_pointer_v<T>, ErrorMessage> {
76 maybeAddSourceInfo(out, t);
77 return error_helper(f % t, std::move(out), std::forward<Args>(args)...);
80template <
typename T,
class... Args>
81auto error_helper(boost::format &f, ErrorMessage out,
const T &t,
82 Args &&...args) -> std::enable_if_t<Util::has_toString_v<T>, ErrorMessage> {
83 maybeAddSourceInfo(out, t);
84 return error_helper(f % t.toString(), std::move(out), std::forward<Args>(args)...);
90template <
class... Args>
91ErrorMessage error_helper(boost::format &f, Args &&...args) {
93 return priv::error_helper(f, msg, std::forward<Args>(args)...);
97template <
class... Args>
99 return priv::error_helper(f, std::move(msg), std::forward<Args>(args)...);
103template <
class... Args>
105 const std::string &suffix, Args &&...args) {
106 return priv::error_helper(f,
ErrorMessage(prefix,
info, suffix), std::forward<Args>(args)...);
Definition source_file.h:132
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition lib/error.h:155
Definition error_message.h:38