Skip to content

Migrate all uses of message_streamt to messaget #166

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 7 commits into from
May 29, 2017
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
9 changes: 9 additions & 0 deletions regression/ansi-c/message_handling1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
int main()
{
goto bla;

for(int i=0; i<5; ++i)
{
bla: i=10;
}
}
7 changes: 7 additions & 0 deletions regression/ansi-c/message_handling1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c
--verbosity 2
^EXIT=0$
^SIGNAL=0$
--
encountered goto `bla' that enters one or more lexical blocks
5 changes: 4 additions & 1 deletion src/ansi-c/ansi_c_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ bool ansi_c_typecheck(
message_handlert &message_handler,
const namespacet &ns)
{
const unsigned errors_before=
message_handler.get_message_count(messaget::M_ERROR);

symbol_tablet symbol_table;
ansi_c_parse_treet ansi_c_parse_tree;

Expand Down Expand Up @@ -99,5 +102,5 @@ bool ansi_c_typecheck(
ansi_c_typecheck.error() << e << messaget::eom;
}

return ansi_c_typecheck.get_error_found();
return message_handler.get_message_count(messaget::M_ERROR)!=errors_before;
}
2 changes: 1 addition & 1 deletion src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ int cbmc_parse_optionst::get_goto_program(

language->set_message_handler(get_message_handler());

status("Parsing", filename);
status() << "Parsing " << filename << eom;

if(language->parse(infile, filename))
{
Expand Down
2 changes: 1 addition & 1 deletion src/clobber/clobber_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ bool clobber_parse_optionst::get_goto_program(

language->set_message_handler(get_message_handler());

status("Parsing", filename);
status() << "Parsing " << filename << eom;

if(language->parse(infile, filename))
{
Expand Down
5 changes: 4 additions & 1 deletion src/cpp/cpp_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ bool cpp_typecheck(
message_handlert &message_handler,
const namespacet &ns)
{
const unsigned errors_before=
message_handler.get_message_count(messaget::M_ERROR);

symbol_tablet symbol_table;
cpp_parse_treet cpp_parse_tree;

Expand All @@ -204,7 +207,7 @@ bool cpp_typecheck(
cpp_typecheck.error() << e << messaget::eom;
}

return cpp_typecheck.get_error_found();
return message_handler.get_message_count(messaget::M_ERROR)!=errors_before;
}

/*******************************************************************\
Expand Down
2 changes: 1 addition & 1 deletion src/goto-cc/armcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int armcc_modet::doit()

unsigned int verbosity=1;

compilet compiler(cmdline);
compilet compiler(cmdline, message_handler, cmdline.isset("diag_error="));

#if 0
bool act_as_ld=
Expand Down
3 changes: 1 addition & 2 deletions src/goto-cc/as_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ int as_modet::doit()
config.set(cmdline);

// determine actions to be undertaken
compilet compiler(cmdline);
compiler.ui_message_handler.set_verbosity(verbosity);
compilet compiler(cmdline, message_handler, cmdline.isset("fatal-warnings"));

if(cmdline.isset('b')) // as86 only
{
Expand Down
38 changes: 22 additions & 16 deletions src/goto-cc/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ bool compilet::doit()
return true;
}

const unsigned warnings_before=
get_message_handler().get_message_count(messaget::M_WARNING);

if(source_files.size()>0)
if(compile())
return true;
Expand All @@ -133,7 +136,10 @@ bool compilet::doit()
return true;
}

return false;
return
warning_is_fatal &&
get_message_handler().get_message_count(messaget::M_WARNING)!=
warnings_before;
}

/*******************************************************************\
Expand All @@ -156,8 +162,8 @@ bool compilet::add_input_file(const std::string &file_name)
std::ifstream in(file_name);
if(!in)
{
error() << "failed to open file `" << file_name << "'" << eom;
return false; // generously ignore
warning() << "failed to open file `" << file_name << "'" << eom;
return warning_is_fatal; // generously ignore unless -Werror
}
}

Expand All @@ -168,7 +174,7 @@ bool compilet::add_input_file(const std::string &file_name)
// a file without extension; will ignore
warning() << "input file `" << file_name
<< "' has no extension, not considered" << eom;
return false;
return warning_is_fatal;
}

std::string ext = file_name.substr(r+1, file_name.length());
Expand Down Expand Up @@ -329,7 +335,7 @@ bool compilet::find_library(const std::string &name)
else if(is_elf_file(libname))
{
warning() << "Warning: Cannot read ELF library " << libname << eom;
return false;
return warning_is_fatal;
}
}
}
Expand Down Expand Up @@ -383,7 +389,7 @@ Function: compilet::link
bool compilet::link()
{
// "compile" hitherto uncompiled functions
print(8, "Compiling functions");
statistics() << "Compiling functions" << eom;
convert_symbols(compiled_functions);

// parse object files
Expand All @@ -409,7 +415,7 @@ bool compilet::link()
symbol_table.remove(goto_functionst::entry_point());
compiled_functions.function_map.erase(goto_functionst::entry_point());

if(ansi_c_entry_point(symbol_table, "main", ui_message_handler))
if(ansi_c_entry_point(symbol_table, "main", get_message_handler()))
return true;

// entry_point may (should) add some more functions.
Expand Down Expand Up @@ -554,7 +560,7 @@ bool compilet::parse(const std::string &file_name)

if(mode==PREPROCESS_ONLY)
{
print(8, "Preprocessing: "+file_name);
statistics() << "Preprocessing: " << file_name << eom;

std::ostream *os = &std::cout;
std::ofstream ofs;
Expand All @@ -576,7 +582,7 @@ bool compilet::parse(const std::string &file_name)
}
else
{
print(8, "Parsing: "+file_name);
statistics() << "Parsing: " << file_name << eom;

if(language.parse(infile, file_name))
{
Expand Down Expand Up @@ -608,7 +614,7 @@ bool compilet::parse_stdin()

language.set_message_handler(get_message_handler());

print(8, "Parsing: (stdin)");
statistics() << "Parsing: (stdin)" << eom;

if(mode==PREPROCESS_ONLY)
{
Expand Down Expand Up @@ -752,11 +758,11 @@ Function: compilet::compilet

\*******************************************************************/

compilet::compilet(cmdlinet &_cmdline):
language_uit(_cmdline, ui_message_handler),
ui_message_handler(_cmdline, "goto-cc " CBMC_VERSION),
compilet::compilet(cmdlinet &_cmdline, ui_message_handlert &mh, bool Werror):
language_uit(_cmdline, mh),
ns(symbol_table),
cmdline(_cmdline)
cmdline(_cmdline),
warning_is_fatal(Werror)
{
mode=COMPILE_LINK_EXECUTABLE;
echo_file_name=false;
Expand Down Expand Up @@ -842,7 +848,7 @@ Function: compilet::convert_symbols

void compilet::convert_symbols(goto_functionst &dest)
{
goto_convert_functionst converter(symbol_table, dest, ui_message_handler);
goto_convert_functionst converter(symbol_table, dest, get_message_handler());

// the compilation may add symbols!

Expand Down Expand Up @@ -872,7 +878,7 @@ void compilet::convert_symbols(goto_functionst &dest)
s_it->second.value.id()!="compiled" &&
s_it->second.value.is_not_nil())
{
print(9, "Compiling "+id2string(s_it->first));
debug() << "Compiling " << s_it->first << eom;
converter.convert_function(s_it->first);
s_it->second.value=exprt("compiled");
}
Expand Down
4 changes: 2 additions & 2 deletions src/goto-cc/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Date: June 2006
class compilet:public language_uit
{
public:
ui_message_handlert ui_message_handler;
namespacet ns;
goto_functionst compiled_functions;
bool echo_file_name;
Expand All @@ -45,7 +44,7 @@ class compilet:public language_uit
std::string object_file_extension;
std::string output_file_object, output_file_executable;

explicit compilet(cmdlinet &_cmdline);
compilet(cmdlinet &_cmdline, ui_message_handlert &mh, bool Werror);

~compilet();

Expand All @@ -72,6 +71,7 @@ class compilet:public language_uit

protected:
cmdlinet &cmdline;
bool warning_is_fatal;

unsigned function_body_count(const goto_functionst &);

Expand Down
2 changes: 1 addition & 1 deletion src/goto-cc/cw_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int cw_modet::doit()

unsigned int verbosity=1;

compilet compiler(cmdline);
compilet compiler(cmdline, message_handler, cmdline.isset("Werror"));

#if 0
bool act_as_ld=
Expand Down
9 changes: 6 additions & 3 deletions src/goto-cc/gcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int gcc_modet::doit()
return EX_OK;
}

if(cmdline.isset("Wall"))
if(cmdline.isset("Wall") || cmdline.isset("Wextra"))
verbosity=2;

if(cmdline.isset("verbosity"))
Expand Down Expand Up @@ -303,8 +303,11 @@ int gcc_modet::doit()
config.ansi_c.double_width=config.ansi_c.single_width;

// determine actions to be undertaken
compilet compiler(cmdline);
compiler.set_message_handler(get_message_handler());
compilet compiler(cmdline,
gcc_message_handler,
cmdline.isset("Werror") &&
cmdline.isset("Wextra") &&
!cmdline.isset("Wno-error"));

if(act_as_ld)
compiler.mode=compilet::LINK_LIBRARY;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-cc/ms_cl_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int ms_cl_modet::doit()

unsigned int verbosity=1;

compilet compiler(cmdline);
compilet compiler(cmdline, message_handler, cmdline.isset("WX"));

#if 0
bool act_as_ld=
Expand Down
9 changes: 6 additions & 3 deletions src/goto-programs/goto_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,6 +2866,9 @@ void goto_convert(
goto_programt &dest,
message_handlert &message_handler)
{
const unsigned errors_before=
message_handler.get_message_count(messaget::M_ERROR);

goto_convertt goto_convert(symbol_table, message_handler);

try
Expand All @@ -2876,20 +2879,20 @@ void goto_convert(
catch(int)
{
goto_convert.error();
throw 0;
}

catch(const char *e)
{
goto_convert.error() << e << messaget::eom;
throw 0;
}

catch(const std::string &e)
{
goto_convert.error() << e << messaget::eom;
throw 0;
}

if(message_handler.get_message_count(messaget::M_ERROR)!=errors_before)
throw 0;
}

/*******************************************************************\
Expand Down
18 changes: 12 additions & 6 deletions src/goto-programs/goto_convert_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ void goto_convert(
goto_functionst &functions,
message_handlert &message_handler)
{
const unsigned errors_before=
message_handler.get_message_count(messaget::M_ERROR);

goto_convert_functionst goto_convert_functions(
symbol_table, functions, message_handler);

Expand All @@ -341,20 +344,20 @@ void goto_convert(
catch(int)
{
goto_convert_functions.error();
throw 0;
}

catch(const char *e)
{
goto_convert_functions.error() << e << messaget::eom;
throw 0;
}

catch(const std::string &e)
{
goto_convert_functions.error() << e << messaget::eom;
throw 0;
}

if(message_handler.get_message_count(messaget::M_ERROR)!=errors_before)
throw 0;
}

/*******************************************************************\
Expand All @@ -375,6 +378,9 @@ void goto_convert(
goto_functionst &functions,
message_handlert &message_handler)
{
const unsigned errors_before=
message_handler.get_message_count(messaget::M_ERROR);

goto_convert_functionst goto_convert_functions(
symbol_table, functions, message_handler);

Expand All @@ -386,18 +392,18 @@ void goto_convert(
catch(int)
{
goto_convert_functions.error();
throw 0;
}

catch(const char *e)
{
goto_convert_functions.error() << e << messaget::eom;
throw 0;
}

catch(const std::string &e)
{
goto_convert_functions.error() << e << messaget::eom;
throw 0;
}

if(message_handler.get_message_count(messaget::M_ERROR)!=errors_before)
throw 0;
}
5 changes: 4 additions & 1 deletion src/goto-programs/initialize_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ bool initialize_goto_model(

if(lf.language==NULL)
{
msg.error("failed to figure out type of file", filename);
source_locationt location;
location.set_file(filename);
msg.error().source_location=location;
msg.error() << "failed to figure out type of file" << messaget::eom;
return true;
}

Expand Down
Loading