GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/parser/parser_exception.h Lines: 17 20 85.0 %
Date: 2021-05-22 Branches: 3 4 75.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Tim King, Morgan Deters, Christopher L. Conway
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Exception class for parse errors.
14
 */
15
16
#include "cvc5parser_public.h"
17
18
#ifndef CVC5__PARSER__PARSER_EXCEPTION_H
19
#define CVC5__PARSER__PARSER_EXCEPTION_H
20
21
#include <iostream>
22
#include <sstream>
23
#include <string>
24
25
#include "base/exception.h"
26
#include "cvc5_export.h"
27
28
namespace cvc5 {
29
namespace parser {
30
31
class CVC5_EXPORT ParserException : public Exception
32
{
33
 public:
34
  // Constructors
35
  ParserException() : d_filename(), d_line(0), d_column(0) {}
36
37
1
  ParserException(const std::string& msg)
38
1
      : Exception(msg), d_filename(), d_line(0), d_column(0)
39
  {
40
1
  }
41
42
  ParserException(const char* msg)
43
      : Exception(msg), d_filename(), d_line(0), d_column(0)
44
  {
45
  }
46
47
121
  ParserException(const std::string& msg,
48
                  const std::string& filename,
49
                  unsigned long line,
50
                  unsigned long column)
51
121
      : Exception(msg), d_filename(filename), d_line(line), d_column(column)
52
  {
53
121
  }
54
55
  // Destructor
56
122
  ~ParserException() override {}
57
58
20
  void toStream(std::ostream& os) const override
59
  {
60
20
    if( d_line > 0 ) {
61
19
      os <<  "Parse Error: " << d_filename << ":" << d_line << "."
62
19
         << d_column << ": " << d_msg;
63
    } else {
64
1
      os << "Parse Error: " << d_msg;
65
    }
66
20
  }
67
68
  std::string getFilename() const { return d_filename; }
69
70
  int getLine() const { return d_line; }
71
72
  int getColumn() const { return d_column; }
73
74
 protected:
75
  std::string d_filename;
76
  unsigned long d_line;
77
  unsigned long d_column;
78
}; /* class ParserException */
79
80
6
class ParserEndOfFileException : public ParserException
81
{
82
 public:
83
  // Constructors same as ParserException's
84
85
  ParserEndOfFileException() : ParserException() {}
86
87
  ParserEndOfFileException(const std::string& msg) : ParserException(msg) {}
88
89
  ParserEndOfFileException(const char* msg) : ParserException(msg) {}
90
91
6
  ParserEndOfFileException(const std::string& msg,
92
                           const std::string& filename,
93
                           unsigned long line,
94
                           unsigned long column)
95
6
      : ParserException(msg, filename, line, column)
96
  {
97
6
  }
98
99
}; /* class ParserEndOfFileException */
100
101
}  // namespace parser
102
}  // namespace cvc5
103
104
#endif /* CVC5__PARSER__PARSER_EXCEPTION_H */