1
+ #include < utility>
2
+
1
3
/* ******************************************************************\
2
4
3
5
Module: Get a Goto Program
21
23
#include < langapi/language.h>
22
24
23
25
#include < goto-programs/rebuild_goto_start_function.h>
26
+ #include < util/exception_utils.h>
24
27
25
28
#include " goto_convert_functions.h"
26
29
#include " read_goto_binary.h"
@@ -33,8 +36,9 @@ goto_modelt initialize_goto_model(
33
36
const std::vector<std::string> &files=cmdline.args ;
34
37
if (files.empty ())
35
38
{
36
- msg.error () << " Please provide a program" << messaget::eom;
37
- throw 0 ;
39
+ throw invalid_user_input_exceptiont (" missing program argument" ,
40
+ " " ,
41
+ " one or more paths to program files" );
38
42
}
39
43
40
44
std::vector<std::string> binaries, sources;
@@ -66,21 +70,18 @@ goto_modelt initialize_goto_model(
66
70
67
71
if (!infile)
68
72
{
69
- msg.error () << " failed to open input file `" << filename
70
- << ' \' ' << messaget::eom;
71
- throw 0 ;
73
+ throw io_exceptiont (" Failed to open input file `" + filename + ' \' ' );
72
74
}
73
75
74
76
language_filet &lf=language_files.add_file (filename);
75
77
lf.language =get_language_from_filename (filename);
76
78
77
79
if (lf.language ==nullptr )
78
80
{
81
+
79
82
source_locationt location;
80
83
location.set_file (filename);
81
- msg.error ().source_location =location;
82
- msg.error () << " failed to figure out type of file" << messaget::eom;
83
- throw 0 ;
84
+ throw goto_model_initialization_errort (" Failed to figure out type of file" , location);
84
85
}
85
86
86
87
languaget &language=*lf.language ;
@@ -91,8 +92,8 @@ goto_modelt initialize_goto_model(
91
92
92
93
if (language.parse (infile, filename))
93
94
{
94
- msg. error () << " PARSING ERROR " << messaget::eom;
95
- throw 0 ;
95
+ // FIXME not a super helpful message
96
+ throw goto_model_initialization_errort ( " PARSING ERROR " ) ;
96
97
}
97
98
98
99
lf.get_modules ();
@@ -102,17 +103,17 @@ goto_modelt initialize_goto_model(
102
103
103
104
if (language_files.typecheck (goto_model.symbol_table ))
104
105
{
105
- msg.error () << " CONVERSION ERROR" << messaget::eom;
106
- throw 0 ;
106
+ throw goto_model_initialization_errort (" CONVERSION ERROR" );
107
107
}
108
108
}
109
109
110
110
for (const auto &file : binaries)
111
111
{
112
112
msg.status () << " Reading GOTO program from file" << messaget::eom;
113
113
114
- if (read_object_and_link (file, goto_model, message_handler))
115
- throw 0 ;
114
+ if (read_object_and_link (file, goto_model, message_handler)) {
115
+ throw goto_model_initialization_errort (" failed to read object or link in file `" + file + ' \' ' );
116
+ }
116
117
}
117
118
118
119
bool binaries_provided_start=
@@ -149,14 +150,13 @@ goto_modelt initialize_goto_model(
149
150
150
151
if (entry_point_generation_failed)
151
152
{
152
- msg. error () << " SUPPORT FUNCTION GENERATION ERROR " << messaget::eom;
153
- throw 0 ;
153
+ // FIXME more helpful error message?
154
+ throw goto_model_initialization_errort ( " SUPPORT FUNCTION GENERATION ERROR " ) ;
154
155
}
155
156
156
157
if (language_files.final (goto_model.symbol_table ))
157
158
{
158
- msg.error () << " FINAL STAGE CONVERSION ERROR" << messaget::eom;
159
- throw 0 ;
159
+ throw goto_model_initialization_errort (" FINAL STAGE CONVERSION ERROR" );
160
160
}
161
161
162
162
msg.status () << " Generating GOTO Program" << messaget::eom;
@@ -172,3 +172,22 @@ goto_modelt initialize_goto_model(
172
172
173
173
return goto_model;
174
174
}
175
+
176
+ goto_model_initialization_errort::goto_model_initialization_errort (std::string message)
177
+ : goto_model_initialization_errort(std::move(message), source_locationt())
178
+ {}
179
+
180
+ std::string goto_model_initialization_errort::what () const noexcept {
181
+ std::string what_msg = message;
182
+ if (source_location.is_not_nil ())
183
+ {
184
+ what_msg += " \n source location: " + source_location.as_string ();
185
+ }
186
+ return what_msg;
187
+ }
188
+
189
+ goto_model_initialization_errort::goto_model_initialization_errort (std::string message, source_locationt source_location)
190
+ : message(std::move(message)), source_location(std::move(source_location))
191
+ {
192
+
193
+ }
0 commit comments