33#ifndef _PERROR_HANDLER_HPP_
34#define _PERROR_HANDLER_HPP_
58 template <
typename Iterator>
84 template <
typename Message,
typename What>
86 Message
const& message,
88 Iterator err_pos)
const
91 Iterator line_start =
get_pos(err_pos, line);
92 const char *homeStr = getenv(
"HOME");
94 snprintf(fln,
sizeof(fln),
"%s/.musrfit/mupp/mupp_err.log", homeStr);
95 std::ofstream fout(fln, std::ofstream::app);
96 if (err_pos !=
last) {
97 fout << message << what <<
':' << std::endl;
98 fout <<
get_line(line_start) << std::endl;
99 for (; line_start != err_pos; ++line_start)
101 fout <<
"^~~" << std::endl;
103 fout <<
"**ERROR** Unexpected end of file. ";
104 fout << message << what <<
" line " << line << std::endl;
118 Iterator
get_pos(Iterator err_pos,
int& line)
const
122 Iterator line_start =
first;
123 while (i != err_pos) {
125 if (i != err_pos && *i ==
'\r') {
129 if (i != err_pos && *i ==
'\n') {
151 Iterator i = err_pos;
153 while (i !=
last && (*i !=
'\r' && *i !=
'\n'))
155 return std::string(err_pos, i);
Iterator get_pos(Iterator err_pos, int &line) const
Finds the start of the line containing an error and computes line number.
PErrorHandler(Iterator first, Iterator last)
Constructor that stores the source code range.
std::vector< Iterator > iters
Vector mapping AST node IDs to source positions (used by PAnnotation)
void operator()(Message const &message, What const &what, Iterator err_pos) const
Function call operator that logs an error to file.
Iterator last
Iterator to the end of the source code.
std::string get_line(Iterator err_pos) const
Extracts the complete line containing an error.
Iterator first
Iterator to the beginning of the source code.