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