]> www.ginac.de Git - ginac.git/blob - ginac/parser/debug.h
Allow underscores in identifiers.
[ginac.git] / ginac / parser / debug.h
1 /** @file debug.h
2  *
3  *  Debugging facilities for parser. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef GINAC_PARSER_DEBUG_H
24 #define GINAC_PARSER_DEBUG_H
25
26 #include "compiler.h"
27
28 #include <iosfwd>
29 #include <sstream>
30 #include <stdexcept>
31
32 #ifndef __GNUC__
33 #if __STDC_VERSION__ < 199901L
34 #define __PRETTY_FUNCTION__ "<unknown>"
35 #else
36 #define __PRETTY_FUNCTION__ __func__
37 #endif
38 #endif
39
40 #define bail_out(exception, message) \
41 do { \
42         std::ostringstream err; \
43         err << __PRETTY_FUNCTION__ << "(" << __FILE__ << ':' << __LINE__ << ": "; \
44         err << message; \
45         throw exception(err.str()); \
46 } while (0)
47
48 #define Parse_error_(message) \
49 do { \
50         std::ostringstream err; \
51         err << "GiNaC: parse error at line " << scanner->line_num << \
52                 ", column " << scanner->column << ": "; \
53         err << message << std::endl; \
54         err << '[' << __PRETTY_FUNCTION__ << "(" << __FILE__ << ':' << __LINE__ << ")]" << std::endl; \
55         throw parse_error(err.str(), scanner->line_num, scanner->column); \
56 } while (0)
57
58 #define Parse_error(message) \
59         Parse_error_(message << ", got: " << scanner->tok2str(token))
60
61 #define bug(message) bail_out(std::logic_error, message)
62
63 #define dout(condition, message) \
64 do { \
65         if (unlikely(condition)) { \
66                 std::cerr << __PRETTY_FUNCTION__ \
67                         << " (" << __FILE__ << ':' << __LINE__ << "): " \
68                         << message << std::endl; \
69         } \
70 } while (0)
71
72 #endif // GINAC_PARSER_DEBUG_H