cpp

Coverage Report

Created: 2022-08-03 12:23

/home/andy/git/oilshell/oil/cpp/leaky_core_error.h
Line
Count
Source (jump to first uncovered line)
1
// Replacement for core/error
2
3
#ifndef CORE_ERROR_H
4
#define CORE_ERROR_H
5
6
#include "_build/cpp/syntax_asdl.h"
7
#include "mycpp/mylib_old.h"
8
9
namespace runtime {
10
extern int NO_SPID;
11
}
12
13
namespace error {
14
15
using syntax_asdl::Token;
16
using syntax_asdl::word_part_t;
17
using syntax_asdl::word_t;
18
19
class Usage : public std::exception {
20
 public:
21
0
  Usage(Str* msg, int span_id) : msg(msg), span_id(span_id) {
22
0
  }
23
24
  Str* msg;
25
  int span_id;
26
};
27
28
// This definition is different in Python than C++.  Not worth auto-translating.
29
class _ErrorWithLocation : public std::exception {
30
 public:
31
  _ErrorWithLocation(Str* user_str, int span_id)
32
      : status(1),
33
        user_str_(user_str),
34
        span_id(span_id),
35
        token(nullptr),
36
        part(nullptr),
37
2
        word(nullptr) {
38
2
  }
39
  _ErrorWithLocation(Str* user_str, Token* token)
40
      : status(1),
41
        user_str_(user_str),
42
        span_id(runtime::NO_SPID),
43
        token(token),
44
        part(nullptr),
45
0
        word(nullptr) {
46
0
  }
47
  _ErrorWithLocation(Str* user_str, word_part_t* part)
48
      : status(1),
49
        user_str_(user_str),
50
        span_id(runtime::NO_SPID),
51
        token(nullptr),
52
        part(part),
53
0
        word(nullptr) {
54
0
  }
55
  _ErrorWithLocation(Str* user_str, word_t* word)
56
      : status(1),
57
        user_str_(user_str),
58
        span_id(runtime::NO_SPID),
59
        token(nullptr),
60
        part(nullptr),
61
0
        word(word) {
62
0
  }
63
  _ErrorWithLocation(int status, Str* user_str, int span_id, bool show_code)
64
      : status(status),
65
        user_str_(user_str),
66
        span_id(span_id),
67
        token(nullptr),
68
        part(nullptr),
69
        word(nullptr),
70
0
        show_code(show_code) {
71
0
  }
72
73
0
  Str* UserErrorString() {
74
0
    return user_str_;
75
0
  }
76
77
0
  bool HasLocation() {
78
0
    return false;  // TODO: fix this
79
0
    assert(0);
80
0
  }
81
82
0
  int ExitStatus() {
83
0
    return status;
84
0
  }
85
86
  int status;
87
88
  Str* user_str_;
89
  int span_id;
90
  syntax_asdl::Token* token;
91
  syntax_asdl::word_part_t* part;
92
  syntax_asdl::word_t* word;
93
94
  bool show_code;
95
};
96
97
class Parse : public _ErrorWithLocation {
98
 public:
99
0
  Parse(Str* user_str, int span_id) : _ErrorWithLocation(user_str, span_id) {
100
0
  }
101
0
  Parse(Str* user_str, Token* token) : _ErrorWithLocation(user_str, token) {
102
0
  }
103
0
  Parse(Str* user_str, word_part_t* part) : _ErrorWithLocation(user_str, part) {
104
0
  }
105
0
  Parse(Str* user_str, word_t* word) : _ErrorWithLocation(user_str, word) {
106
0
  }
107
};
108
109
class RedirectEval : public _ErrorWithLocation {
110
 public:
111
  // code only uses this variant
112
  RedirectEval(Str* user_str, word_t* word)
113
0
      : _ErrorWithLocation(user_str, word) {
114
0
  }
115
};
116
117
class FailGlob : public _ErrorWithLocation {
118
 public:
119
  // code only uses this variant
120
0
  FailGlob(Str* user_str, int span_id) : _ErrorWithLocation(user_str, span_id) {
121
0
  }
122
};
123
124
class FatalRuntime : public _ErrorWithLocation {
125
 public:
126
2
  FatalRuntime(Str* user_str) : _ErrorWithLocation(user_str, -1) {
127
2
  }
128
  FatalRuntime(int status, Str* user_str)
129
0
      : _ErrorWithLocation(status, user_str, -1, false) {
130
0
  }
131
};
132
133
class Strict : public FatalRuntime {
134
 public:
135
1
  Strict(Str* user_str) : FatalRuntime(user_str) {
136
1
  }
137
};
138
139
// Stub
140
class ErrExit : public _ErrorWithLocation {
141
 public:
142
  ErrExit(Str* user_str, int span_id, int status)
143
0
      : _ErrorWithLocation(status, user_str, span_id, false) {
144
0
  }
145
  ErrExit(Str* user_str, int span_id, int status, bool show_code)
146
0
      : _ErrorWithLocation(status, user_str, span_id, show_code) {
147
0
  }
148
};
149
150
// Stub: the parts that raise aren't translated
151
class Expr : public _ErrorWithLocation {
152
 public:
153
0
  Expr(Str* user_str, int span_id) : _ErrorWithLocation(user_str, span_id) {
154
0
  }
155
#if 0
156
  Expr(Str* user_str, Token* token)
157
      : _ErrorWithLocation(user_str, token) {
158
  }
159
#endif
160
};
161
162
// Stub
163
class Runtime : public _ErrorWithLocation {
164
 public:
165
0
  Runtime(Str* user_str) : _ErrorWithLocation(user_str, -1) {
166
0
  }
167
};
168
169
}  // namespace error
170
171
#endif  // CORE_ERROR_H