Skip to content

Commit 2c76312

Browse files
Petr BauchPetr Bauch
authored andcommitted
Fix based on review comments
1 parent 6f4cd90 commit 2c76312

9 files changed

+24
-63
lines changed

src/goto-programs/lazy_goto_model.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
9595
const std::vector<std::string> &files=cmdline.args;
9696
if(files.empty())
9797
{
98-
throw invalid_user_input_exceptiont("No program provided", "", "");
98+
throw invalid_user_input_exceptiont(
99+
"no program provided", "cbmc file.c ...");
99100
}
100101

101102
std::vector<std::string> binaries, sources;
@@ -134,10 +135,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
134135
source_locationt location;
135136
location.set_file(filename);
136137
msg.error().source_location=location;
137-
throw deserialization_exceptiont(
138-
"failed to figure out type of file"
139-
"\nsource location: " +
140-
location.as_string());
138+
throw incorrect_goto_program_exceptiont(
139+
"failed to figure out type of file", location);
141140
}
142141

143142
languaget &language=*lf.language;
@@ -148,8 +147,7 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
148147

149148
if(language.parse(infile, filename))
150149
{
151-
// TODO more helpful error message
152-
throw deserialization_exceptiont("PARSING ERROR");
150+
throw deserialization_exceptiont("language parsing failed");
153151
}
154152

155153
lf.get_modules();
@@ -159,8 +157,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
159157

160158
if(language_files.typecheck(symbol_table))
161159
{
162-
// TODO more helpful error message
163-
throw deserialization_exceptiont("CONVERSION ERROR");
160+
throw deserialization_exceptiont(
161+
"type-checking of interface/files/modules failed");
164162
}
165163
}
166164

@@ -170,8 +168,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
170168

171169
if(read_object_and_link(file, *goto_model, message_handler))
172170
{
173-
// TODO more helpful error message
174-
throw deserialization_exceptiont("Failed to read/link goto model");
171+
throw deserialization_exceptiont(
172+
"failed to read object or link in file `" + file + '\'');
175173
}
176174
}
177175

@@ -207,8 +205,7 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
207205

208206
if(entry_point_generation_failed)
209207
{
210-
// TODO more helpful error message
211-
throw deserialization_exceptiont("SUPPORT FUNCTION GENERATION ERROR");
208+
throw deserialization_exceptiont("failed to generate entry point");
212209
}
213210

214211
// stupid hack

src/goto-programs/link_goto_model.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ void link_goto_model(
173173

174174
if(linking.typecheck_main())
175175
{
176-
// TODO more helpful error message
177-
throw deserialization_exceptiont("Typechecking main failed");
176+
throw deserialization_exceptiont(
177+
"failed to rename symbols during typechecking phase of linking");
178178
}
179179
if(link_functions(
180180
dest.symbol_table,
@@ -185,6 +185,6 @@ void link_goto_model(
185185
weak_symbols,
186186
linking.object_type_updates))
187187
{
188-
throw deserialization_exceptiont("Linking failed");
188+
throw deserialization_exceptiont("failed to link functions");
189189
}
190190
}

src/goto-programs/osx_fat_reader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Module: Read Mach-O
1111

1212
#include "osx_fat_reader.h"
1313

14-
#include <cassert>
1514
#include <cstdlib>
1615
#include <util/exception_utils.h>
1716
#include <util/invariant.h>

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static bool read_bin_goto_object_v4(
147147
rev_target_mapt::const_iterator entry=rev_target_map.find(n);
148148
INVARIANT(
149149
entry != rev_target_map.end(),
150-
"Something from the target map should also be in the reverse target "
150+
"something from the target map should also be in the reverse target "
151151
"map");
152152
ins->targets.push_back(entry->second);
153153
}

src/goto-programs/remove_complex.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ static exprt complex_member(const exprt &expr, irep_idt id)
3232
}
3333
else
3434
{
35-
PRECONDITION(expr.type().id() == ID_struct);
3635
const struct_typet &struct_type=
3736
to_struct_type(expr.type());
3837
PRECONDITION(struct_type.components().size() == 2);
@@ -229,13 +228,11 @@ static void remove_complex(exprt &expr)
229228

230229
if(expr.id()==ID_complex_real)
231230
{
232-
static_cast<void>(to_complex_real_expr(expr));
233-
expr=complex_member(expr.op0(), ID_real);
231+
expr = complex_member(to_complex_real_expr(expr).op(), ID_real);
234232
}
235233
else if(expr.id()==ID_complex_imag)
236234
{
237-
static_cast<void>(to_complex_imag_expr(expr));
238-
expr=complex_member(expr.op0(), ID_imag);
235+
expr = complex_member(to_complex_imag_expr(expr).op(), ID_imag);
239236
}
240237

241238
remove_complex(expr.type());

src/goto-programs/remove_unused_functions.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,8 @@ void find_used_functions(
7777
{
7878
const code_function_callt &call = to_code_function_call(it->code);
7979

80-
// check that this is actually a simple call
81-
INVARIANT(
82-
call.function().id() == ID_symbol,
83-
"by this point, all kinds of function calls should have been "
84-
"converted to simple function calls");
85-
80+
// to_symbol_exprt checks that by this point, all kinds of function
81+
// calls have been converted to simple function calls
8682
const irep_idt &identifier =
8783
to_symbol_expr(call.function()).get_identifier();
8884

src/goto-programs/remove_vector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void remove_vector(exprt &expr)
116116
else if(expr.id()==ID_unary_minus || expr.id()==ID_bitnot)
117117
{
118118
DATA_INVARIANT(
119-
expr.operands().size() == 1, "unary operators have one operands");
119+
expr.operands().size() == 1, "unary operators have one operand");
120120
remove_vector(expr.type());
121121
array_typet array_type=to_array_type(expr.type());
122122

src/goto-programs/replace_calls.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void replace_callst::operator()(
108108
const symbol_exprt &se = to_symbol_expr(rhs);
109109
INVARIANT(
110110
!has_suffix(id2string(se.get_identifier()), RETURN_VALUE_SUFFIX),
111-
"this happens before returns are removed");
111+
"returns must not be removed before replacing calls");
112112
}
113113
}
114114

@@ -136,7 +136,7 @@ replace_callst::replacement_mapt replace_callst::parse_replacement_list(
136136
if(!r.second)
137137
{
138138
throw invalid_user_input_exceptiont(
139-
"Conflicting replacement for function " + original, "--replace-calls");
139+
"conflicting replacement for function " + original, "--replace-calls");
140140
}
141141
}
142142

@@ -152,23 +152,23 @@ void replace_callst::check_replacement_map(
152152
{
153153
if(replacement_map.find(p.second) != replacement_map.end())
154154
throw invalid_user_input_exceptiont(
155-
"Function " + id2string(p.second) +
155+
"function " + id2string(p.second) +
156156
" cannot both be replaced and be a replacement",
157157
"--replace-calls");
158158

159159
auto it2 = goto_functions.function_map.find(p.second);
160160

161161
if(it2 == goto_functions.function_map.end())
162162
throw invalid_user_input_exceptiont(
163-
"Replacement function " + id2string(p.second) + " needs to be present",
163+
"replacement function " + id2string(p.second) + " needs to be present",
164164
"--replace-calls");
165165

166166
auto it1 = goto_functions.function_map.find(p.first);
167167
if(it1 != goto_functions.function_map.end())
168168
{
169169
if(!base_type_eq(it1->second.type, it2->second.type, ns))
170170
throw invalid_user_input_exceptiont(
171-
"Functions " + id2string(p.first) + " and " + id2string(p.second) +
171+
"functions " + id2string(p.first) + " and " + id2string(p.second) +
172172
" are not type-compatible",
173173
"--replace-calls");
174174
}

src/util/exception_utils.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,4 @@ class analysis_exceptiont : public cprover_exception_baset
120120
std::string reason;
121121
};
122122

123-
class system_exceptiont
124-
{
125-
private:
126-
std::string reason;
127-
128-
public:
129-
system_exceptiont(const std::string &reason) : reason(reason)
130-
{
131-
}
132-
133-
std::string what() const noexcept
134-
{
135-
std::string res;
136-
res += "System Exception\n";
137-
res += "Reason: " + reason + "\n";
138-
return res;
139-
}
140-
};
141-
142-
class deserialization_exceptiont
143-
{
144-
public:
145-
explicit deserialization_exceptiont(std::string message);
146-
std::string what() const noexcept;
147-
private:
148-
std::string message;
149-
};
150-
151123
#endif // CPROVER_UTIL_EXCEPTION_UTILS_H

0 commit comments

Comments
 (0)