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

Line Exec Source
1
/*********************                                                        */
2
/*! \file parser_exception.h
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Tim King, Morgan Deters, Christopher L. Conway
6
 ** This file is part of the CVC4 project.
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.\endverbatim
11
 **
12
 ** \brief Exception class for parse errors.
13
 **
14
 ** Exception class for parse errors.
15
 **/
16
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 "base/exception.h"
27
#include "cvc4_export.h"
28
29
namespace CVC4 {
30
namespace parser {
31
32
class CVC4_EXPORT ParserException : public Exception
33
{
34
 public:
35
  // Constructors
36
  ParserException() : d_filename(), d_line(0), d_column(0) {}
37
38
1
  ParserException(const std::string& msg)
39
1
      : Exception(msg), d_filename(), d_line(0), d_column(0)
40
  {
41
1
  }
42
43
  ParserException(const char* msg)
44
      : Exception(msg), d_filename(), d_line(0), d_column(0)
45
  {
46
  }
47
48
122
  ParserException(const std::string& msg,
49
                  const std::string& filename,
50
                  unsigned long line,
51
                  unsigned long column)
52
122
      : Exception(msg), d_filename(filename), d_line(line), d_column(column)
53
  {
54
122
  }
55
56
  // Destructor
57
123
  ~ParserException() override {}
58
59
21
  void toStream(std::ostream& os) const override
60
  {
61
21
    if( d_line > 0 ) {
62
20
      os <<  "Parse Error: " << d_filename << ":" << d_line << "."
63
20
         << d_column << ": " << d_msg;
64
    } else {
65
1
      os << "Parse Error: " << d_msg;
66
    }
67
21
  }
68
69
  std::string getFilename() const { return d_filename; }
70
71
  int getLine() const { return d_line; }
72
73
  int getColumn() const { return d_column; }
74
75
 protected:
76
  std::string d_filename;
77
  unsigned long d_line;
78
  unsigned long d_column;
79
}; /* class ParserException */
80
81
6
class ParserEndOfFileException : public ParserException
82
{
83
 public:
84
  // Constructors same as ParserException's
85
86
  ParserEndOfFileException() : ParserException() {}
87
88
  ParserEndOfFileException(const std::string& msg) : ParserException(msg) {}
89
90
  ParserEndOfFileException(const char* msg) : ParserException(msg) {}
91
92
6
  ParserEndOfFileException(const std::string& msg,
93
                           const std::string& filename,
94
                           unsigned long line,
95
                           unsigned long column)
96
6
      : ParserException(msg, filename, line, column)
97
  {
98
6
  }
99
100
}; /* class ParserEndOfFileException */
101
102
}/* CVC4::parser namespace */
103
}/* CVC4 namespace */
104
105
#endif /* CVC4__PARSER__PARSER_EXCEPTION_H */