Skip to content

Use structured exceptions in initialize_goto_model #3190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions src/goto-programs/initialize_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
#include <langapi/language.h>

#include <goto-programs/rebuild_goto_start_function.h>
#include <util/exception_utils.h>

#include "goto_convert_functions.h"
#include "read_goto_binary.h"
Expand All @@ -36,8 +37,10 @@ goto_modelt initialize_goto_model(
const std::vector<std::string> &files=cmdline.args;
if(files.empty())
{
msg.error() << "Please provide a program" << messaget::eom;
throw 0;
throw invalid_command_line_argument_exceptiont(
"missing program argument",
"filename",
"one or more paths to program files");
}

std::vector<std::string> binaries, sources;
Expand Down Expand Up @@ -69,21 +72,17 @@ goto_modelt initialize_goto_model(

if(!infile)
{
msg.error() << "failed to open input file `" << filename
<< '\'' << messaget::eom;
throw 0;
throw system_exceptiont(
"Failed to open input file `" + filename + '\'');
}

language_filet &lf=language_files.add_file(filename);
lf.language=get_language_from_filename(filename);

if(lf.language==nullptr)
{
source_locationt location;
location.set_file(filename);
msg.error().source_location=location;
msg.error() << "failed to figure out type of file" << messaget::eom;
throw 0;
throw invalid_source_file_exceptiont(
"Failed to figure out type of file `" + filename + '\'');
}

languaget &language=*lf.language;
Expand All @@ -94,8 +93,7 @@ goto_modelt initialize_goto_model(

if(language.parse(infile, filename))
{
msg.error() << "PARSING ERROR" << messaget::eom;
throw 0;
throw invalid_source_file_exceptiont("PARSING ERROR");
}

lf.get_modules();
Expand All @@ -105,8 +103,7 @@ goto_modelt initialize_goto_model(

if(language_files.typecheck(goto_model.symbol_table))
{
msg.error() << "CONVERSION ERROR" << messaget::eom;
throw 0;
throw invalid_source_file_exceptiont("CONVERSION ERROR");
}
}

Expand All @@ -115,7 +112,10 @@ goto_modelt initialize_goto_model(
msg.status() << "Reading GOTO program from file" << messaget::eom;

if(read_object_and_link(file, goto_model, message_handler))
throw 0;
{
throw invalid_source_file_exceptiont(
"failed to read object or link in file `" + file + '\'');
}
}

bool binaries_provided_start=
Expand Down Expand Up @@ -150,14 +150,12 @@ goto_modelt initialize_goto_model(

if(entry_point_generation_failed)
{
msg.error() << "SUPPORT FUNCTION GENERATION ERROR" << messaget::eom;
throw 0;
throw invalid_source_file_exceptiont("SUPPORT FUNCTION GENERATION ERROR");
}

if(language_files.final(goto_model.symbol_table))
{
msg.error() << "FINAL STAGE CONVERSION ERROR" << messaget::eom;
throw 0;
throw invalid_source_file_exceptiont("FINAL STAGE CONVERSION ERROR");
}

msg.status() << "Generating GOTO Program" << messaget::eom;
Expand Down