cvc4-1.4
parser_exception.h
Go to the documentation of this file.
1 /********************* */
17 #include "cvc4parser_public.h"
18 
19 #ifndef __CVC4__PARSER__PARSER_EXCEPTION_H
20 #define __CVC4__PARSER__PARSER_EXCEPTION_H
21 
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 
26 #include "util/exception.h"
27 
28 namespace CVC4 {
29 namespace parser {
30 
32 public:
33  // Constructors
34  ParserException() throw() :
35  d_filename(),
36  d_line(0),
37  d_column(0) {
38  }
39 
40  ParserException(const std::string& msg) throw() :
41  Exception(msg),
42  d_filename(),
43  d_line(0),
44  d_column(0) {
45  }
46 
47  ParserException(const char* msg) throw() :
48  Exception(msg),
49  d_filename(),
50  d_line(0),
51  d_column(0) {
52  }
53 
54  ParserException(const std::string& msg, const std::string& filename,
55  unsigned long line, unsigned long column) throw() :
56  Exception(msg),
57  d_filename(filename),
58  d_line(line),
59  d_column(column) {
60  }
61 
62  // Destructor
63  virtual ~ParserException() throw() {}
64 
65  virtual void toStream(std::ostream& os) const throw() {
66  if( d_line > 0 ) {
67  os << "Parse Error: " << d_filename << ":" << d_line << "."
68  << d_column << ": " << d_msg;
69  } else {
70  os << "Parse Error: " << d_msg;
71  }
72  }
73 
74  std::string getFilename() const throw() {
75  return d_filename;
76  }
77 
78  int getLine() const throw() {
79  return d_line;
80  }
81 
82  int getColumn() const throw() {
83  return d_column;
84  }
85 
86 protected:
87  std::string d_filename;
88  unsigned long d_line;
89  unsigned long d_column;
90 };/* class ParserException */
91 
93 public:
94 
95  // Constructors same as ParserException's
96 
98  ParserException() {
99  }
100 
101  ParserEndOfFileException(const std::string& msg) throw() :
102  ParserException(msg) {
103  }
104 
105  ParserEndOfFileException(const char* msg) throw() :
106  ParserException(msg) {
107  }
108 
109  ParserEndOfFileException(const std::string& msg, const std::string& filename,
110  unsigned long line, unsigned long column) throw() :
111  ParserException(msg, filename, line, column) {
112  }
113 
114 };/* class ParserEndOfFileException */
115 
116 }/* CVC4::parser namespace */
117 }/* CVC4 namespace */
118 
119 #endif /* __CVC4__PARSER__PARSER_EXCEPTION_H */
ParserEndOfFileException(const std::string &msg)
Definition: expr.h:106
CVC4's exception base class and some associated utilities.
ParserException(const std::string &msg)
#define CVC4_PUBLIC
Definition: cvc4_public.h:30
ParserException(const std::string &msg, const std::string &filename, unsigned long line, unsigned long column)
virtual void toStream(std::ostream &os) const
Printing: feel free to redefine toStream().
ParserEndOfFileException(const std::string &msg, const std::string &filename, unsigned long line, unsigned long column)
Macros that should be defined everywhere during the building of the libraries and driver binary...
std::string getFilename() const