7#ifndef LIB_ERROR_HELPER_H_
8#define LIB_ERROR_HELPER_H_
12#include <boost/format.hpp>
14#include "lib/error_message.h"
15#include "lib/source_file.h"
16#include "lib/stringify.h"
23static inline ErrorMessage error_helper(boost::format &f, ErrorMessage out) {
24 out.message = boost::str(f);
28template <
class... Args>
29auto error_helper(boost::format &f, ErrorMessage out,
const char *t, Args &&...args) {
30 return error_helper(f % t, out, std::forward<Args>(args)...);
33template <
typename T,
class... Args>
34auto error_helper(boost::format &f, ErrorMessage out,
const T &t,
35 Args &&...args) -> std::enable_if_t<Util::has_toString_v<T>, ErrorMessage>;
37template <
typename T,
class... Args>
38auto error_helper(boost::format &f, ErrorMessage out,
const T &t, Args &&...args)
39 -> std::enable_if_t<!Util::has_toString_v<T> && !std::is_pointer_v<T>, ErrorMessage>;
41template <
typename T,
class... Args>
42auto error_helper(boost::format &f, ErrorMessage out,
const T *t, Args &&...args) {
46 return error_helper(f, out, *t, std::forward<Args>(args)...);
49template <
class... Args>
50ErrorMessage error_helper(boost::format &f, ErrorMessage out,
const Util::SourceInfo &
info,
52 if (
info.isValid()) out.locations.push_back(
info);
53 return error_helper(f %
"", std::move(out), std::forward<Args>(args)...);
57void maybeAddSourceInfo(ErrorMessage &out,
const T &t) {
58 if constexpr (Util::has_SourceInfo_v<T>) {
59 auto info = t.getSourceInfo();
60 if (
info.isValid()) out.locations.push_back(
info);
64template <
typename T,
class... Args>
65auto error_helper(boost::format &f, ErrorMessage out,
const T &t, Args &&...args)
66 -> std::enable_if_t<!Util::has_toString_v<T> && !std::is_pointer_v<T>, ErrorMessage> {
67 maybeAddSourceInfo(out, t);
68 return error_helper(f % t, std::move(out), std::forward<Args>(args)...);
71template <
typename T,
class... Args>
72auto error_helper(boost::format &f, ErrorMessage out,
const T &t,
73 Args &&...args) -> std::enable_if_t<Util::has_toString_v<T>, ErrorMessage> {
74 maybeAddSourceInfo(out, t);
75 return error_helper(f % t.toString(), std::move(out), std::forward<Args>(args)...);
81template <
class... Args>
82ErrorMessage error_helper(boost::format &f, Args &&...args) {
84 return priv::error_helper(f, msg, std::forward<Args>(args)...);
88template <
class... Args>
90 return priv::error_helper(f, std::move(msg), std::forward<Args>(args)...);
94template <
class... Args>
96 const std::string &suffix, Args &&...args) {
97 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:13
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:167
Definition error_message.h:29