]> www.ginac.de Git - ginac.git/blob - ginac/parser/debug.hpp
[BUGFIX] parser.hpp: fix include guard so the header is actually usable.
[ginac.git] / ginac / parser / debug.hpp
1 #ifndef GINAC_PARSER_DEBUG_HPP
2 #define GINAC_PARSER_DEBUG_HPP
3 #include <iosfwd>
4 #include <sstream>
5 #include <stdexcept>
6 #include "compiler.h"
7 #ifndef __GNUC__
8 #if __STDC_VERSION__ < 199901L
9 #define __PRETTY_FUNCTION__ "<unknown>"
10 #else
11 #define __PRETTY_FUNCTION__ __func__
12 #endif
13 #endif
14
15 #define bail_out(exception, message) \
16 do { \
17         std::ostringstream err; \
18         err << __PRETTY_FUNCTION__ << "(" << __FILE__ << ':' << __LINE__ << ": "; \
19         err << message; \
20         throw exception(err.str()); \
21 } while (0)
22
23 #define Parse_error_(message) \
24 do { \
25         std::ostringstream err; \
26         err << "GiNaC: parse error at line " << scanner->line_num << \
27                 ", column " << scanner->column << ": "; \
28         err << message << std::endl; \
29         err << '[' << __PRETTY_FUNCTION__ << "(" << __FILE__ << ':' << __LINE__ << ")]" << std::endl; \
30         throw parse_error(err.str(), scanner->line_num, scanner->column); \
31 } while (0)
32
33 #define Parse_error(message) \
34         Parse_error_(message << ", got: " << scanner->tok2str(token))
35
36 #define bug(message) bail_out(std::logic_error, message)
37
38 #define dout(condition, message) \
39 do { \
40         if (unlikely(condition)) { \
41                 std::cerr << __PRETTY_FUNCTION__ \
42                         << " (" << __FILE__ << ':' << __LINE__ << "): " \
43                         << message << std::endl; \
44         } \
45 } while (0)
46
47 #endif // GINAC_PARSER_DEBUG_HPP
48