cpp

Coverage Report

Created: 2022-11-10 11:34

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