@@ -121,6 +121,9 @@ bool compilet::doit()
121121 return true ;
122122 }
123123
124+ const unsigned warnings_before=
125+ get_message_handler ().get_message_count (messaget::M_WARNING);
126+
124127 if (source_files.size ()>0 )
125128 if (compile ())
126129 return true ;
@@ -133,7 +136,10 @@ bool compilet::doit()
133136 return true ;
134137 }
135138
136- return false ;
139+ return
140+ warning_is_fatal &&
141+ get_message_handler ().get_message_count (messaget::M_WARNING)!=
142+ warnings_before;
137143}
138144
139145/* ******************************************************************\
@@ -156,8 +162,8 @@ bool compilet::add_input_file(const std::string &file_name)
156162 std::ifstream in (file_name);
157163 if (!in)
158164 {
159- error () << " failed to open file `" << file_name << " '" << eom;
160- return false ; // generously ignore
165+ warning () << " failed to open file `" << file_name << " '" << eom;
166+ return warning_is_fatal ; // generously ignore unless -Werror
161167 }
162168 }
163169
@@ -168,7 +174,7 @@ bool compilet::add_input_file(const std::string &file_name)
168174 // a file without extension; will ignore
169175 warning () << " input file `" << file_name
170176 << " ' has no extension, not considered" << eom;
171- return false ;
177+ return warning_is_fatal ;
172178 }
173179
174180 std::string ext = file_name.substr (r+1 , file_name.length ());
@@ -329,7 +335,7 @@ bool compilet::find_library(const std::string &name)
329335 else if (is_elf_file (libname))
330336 {
331337 warning () << " Warning: Cannot read ELF library " << libname << eom;
332- return false ;
338+ return warning_is_fatal ;
333339 }
334340 }
335341 }
@@ -383,7 +389,7 @@ Function: compilet::link
383389bool compilet::link ()
384390{
385391 // "compile" hitherto uncompiled functions
386- print ( 8 , " Compiling functions" ) ;
392+ statistics () << " Compiling functions" << eom ;
387393 convert_symbols (compiled_functions);
388394
389395 // parse object files
@@ -409,7 +415,7 @@ bool compilet::link()
409415 symbol_table.remove (goto_functionst::entry_point ());
410416 compiled_functions.function_map .erase (goto_functionst::entry_point ());
411417
412- if (ansi_c_entry_point (symbol_table, " main" , ui_message_handler ))
418+ if (ansi_c_entry_point (symbol_table, " main" , get_message_handler () ))
413419 return true ;
414420
415421 // entry_point may (should) add some more functions.
@@ -554,7 +560,7 @@ bool compilet::parse(const std::string &file_name)
554560
555561 if (mode==PREPROCESS_ONLY)
556562 {
557- print ( 8 , " Preprocessing: " + file_name) ;
563+ statistics () << " Preprocessing: " << file_name << eom ;
558564
559565 std::ostream *os = &std::cout;
560566 std::ofstream ofs;
@@ -576,7 +582,7 @@ bool compilet::parse(const std::string &file_name)
576582 }
577583 else
578584 {
579- print ( 8 , " Parsing: " + file_name) ;
585+ statistics () << " Parsing: " << file_name << eom ;
580586
581587 if (language.parse (infile, file_name))
582588 {
@@ -608,7 +614,7 @@ bool compilet::parse_stdin()
608614
609615 language.set_message_handler (get_message_handler ());
610616
611- print ( 8 , " Parsing: (stdin)" ) ;
617+ statistics () << " Parsing: (stdin)" << eom ;
612618
613619 if (mode==PREPROCESS_ONLY)
614620 {
@@ -752,11 +758,11 @@ Function: compilet::compilet
752758
753759\*******************************************************************/
754760
755- compilet::compilet (cmdlinet &_cmdline):
756- language_uit(_cmdline, ui_message_handler),
757- ui_message_handler(_cmdline, " goto-cc " CBMC_VERSION),
761+ compilet::compilet (cmdlinet &_cmdline, ui_message_handlert &mh, bool Werror):
762+ language_uit(_cmdline, mh),
758763 ns(symbol_table),
759- cmdline(_cmdline)
764+ cmdline(_cmdline),
765+ warning_is_fatal(Werror)
760766{
761767 mode=COMPILE_LINK_EXECUTABLE;
762768 echo_file_name=false ;
@@ -842,7 +848,7 @@ Function: compilet::convert_symbols
842848
843849void compilet::convert_symbols (goto_functionst &dest)
844850{
845- goto_convert_functionst converter (symbol_table, dest, ui_message_handler );
851+ goto_convert_functionst converter (symbol_table, dest, get_message_handler () );
846852
847853 // the compilation may add symbols!
848854
@@ -872,7 +878,7 @@ void compilet::convert_symbols(goto_functionst &dest)
872878 s_it->second .value .id ()!=" compiled" &&
873879 s_it->second .value .is_not_nil ())
874880 {
875- print ( 9 , " Compiling " + id2string ( s_it->first )) ;
881+ debug () << " Compiling " << s_it->first << eom ;
876882 converter.convert_function (s_it->first );
877883 s_it->second .value =exprt (" compiled" );
878884 }
0 commit comments