Skip to content

Do not use invalid_source_file_exceptiont without source location #5835

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
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions jbmc/src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void java_bytecode_languaget::initialize_class_loader()

static void throwMainClassLoadingError(const std::string &main_class)
{
throw invalid_source_file_exceptiont(
throw system_exceptiont(
"Error: Could not find or load main class " + main_class);
}

Expand Down Expand Up @@ -392,8 +392,7 @@ bool java_bytecode_languaget::parse(
std::ifstream jar_file(path);
if(!jar_file.good())
{
throw invalid_source_file_exceptiont(
"Error: Unable to access jarfile " + path);
throw system_exceptiont("Error: Unable to access jarfile " + path);
}

// build an object to potentially limit which classes are loaded
Expand Down
4 changes: 2 additions & 2 deletions jbmc/src/java_bytecode/lazy_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ void lazy_goto_modelt::initialize(

if(dynamic_cast<java_bytecode_languaget &>(language).parse())
{
throw invalid_source_file_exceptiont("PARSING ERROR");
throw invalid_input_exceptiont("PARSING ERROR");
}

msg.status() << "Converting" << messaget::eom;

if(language_files.typecheck(symbol_table))
{
throw invalid_source_file_exceptiont("CONVERSION ERROR");
throw invalid_input_exceptiont("CONVERSION ERROR");
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/crangler/ctokenit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ctokenitt match_bracket(ctokenitt t, char open, char close)
while(true)
{
if(!t)
throw invalid_source_file_exceptiont("expected " + std::string(1, close));
throw invalid_input_exceptiont("expected " + std::string(1, close));

const auto &token = *(t++);

Expand Down
6 changes: 3 additions & 3 deletions src/crangler/mini_c_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void mini_c_parsert::parse_brackets(char open, char close, tokenst &dest)
while(true)
{
if(eof())
throw invalid_source_file_exceptiont("expected " + std::string(1, close));
throw invalid_input_exceptiont("expected " + std::string(1, close));

auto &token = consume_token();
dest.push_back(token);
Expand Down Expand Up @@ -297,7 +297,7 @@ mini_c_parsert::tokenst mini_c_parsert::parse_initializer()
while(true)
{
if(eof())
throw invalid_source_file_exceptiont("expected an initializer");
throw invalid_input_exceptiont("expected an initializer");
auto &token = consume_token();
result.push_back(token);
if(token == ';')
Expand All @@ -317,7 +317,7 @@ mini_c_parsert::tokenst mini_c_parsert::parse_initializer()
while(true)
{
if(eof())
throw invalid_source_file_exceptiont("eof in function body");
throw invalid_input_exceptiont("eof in function body");
auto &token = consume_token();
result.push_back(token);
if(token == '{')
Expand Down
2 changes: 1 addition & 1 deletion src/memory-analyzer/analyze_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ exprt gdb_value_extractort::get_pointer_to_function_value(
const auto function_symbol = symbol_table.lookup(function_name);
if(function_symbol == nullptr)
{
throw invalid_source_file_exceptiont{
throw invalid_input_exceptiont{
"input source code does not contain function: " + function_name};
}
CHECK_RETURN(function_symbol->type.id() == ID_code);
Expand Down
4 changes: 2 additions & 2 deletions src/symtab2gb/symtab2gb_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ static void run_symtab2gb(

if(failed(linking(linked_symbol_table, symtab, message_handler)))
{
throw invalid_source_file_exceptiont{"failed to link `" +
symtab_filename + "'"};
throw invalid_input_exceptiont{
"failed to link `" + symtab_filename + "'"};
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/util/exception_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ analysis_exceptiont::analysis_exceptiont(std::string reason)
{
}

invalid_input_exceptiont::invalid_input_exceptiont(std::string reason)
: cprover_exception_baset(std::move(reason))
{
}

invalid_source_file_exceptiont::invalid_source_file_exceptiont(
std::string reason)
: cprover_exception_baset(std::move(reason))
Expand Down
9 changes: 9 additions & 0 deletions src/util/exception_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ class analysis_exceptiont : public cprover_exception_baset
explicit analysis_exceptiont(std::string reason);
};

/// Thrown when user-provided input cannot be processed. Use
/// \ref invalid_source_file_exceptiont when the precise location of erroneous
/// input is known.
class invalid_input_exceptiont : public cprover_exception_baset
{
public:
explicit invalid_input_exceptiont(std::string reason);
};

/// Thrown when we can't handle something in an input source file.
/// For example, if we get C source code that is not syntactically valid
/// or that has type errors.
Expand Down
7 changes: 3 additions & 4 deletions unit/testing-utils/get_goto_model_from_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ goto_modelt get_goto_model_from_c(std::istream &in)
const bool error = language.parse(in, "");

if(error)
throw invalid_source_file_exceptiont("parsing failed");
throw invalid_input_exceptiont("parsing failed");
}

language_file.get_modules();
Expand All @@ -69,16 +69,15 @@ goto_modelt get_goto_model_from_c(std::istream &in)
const bool error = language_files.typecheck(goto_model.symbol_table);

if(error)
throw invalid_source_file_exceptiont("typechecking failed");
throw invalid_input_exceptiont("typechecking failed");
}

{
const bool error =
language_files.generate_support_functions(goto_model.symbol_table);

if(error)
throw invalid_source_file_exceptiont(
"support function generation failed");
throw invalid_input_exceptiont("support function generation failed");
}

goto_convert(
Expand Down