@@ -121,6 +121,9 @@ bool compilet::doit()
121
121
return true ;
122
122
}
123
123
124
+ const unsigned warnings_before=
125
+ get_message_handler ().get_message_count (messaget::M_WARNING);
126
+
124
127
if (source_files.size ()>0 )
125
128
if (compile ())
126
129
return true ;
@@ -133,7 +136,10 @@ bool compilet::doit()
133
136
return true ;
134
137
}
135
138
136
- return false ;
139
+ return
140
+ warning_is_fatal &&
141
+ get_message_handler ().get_message_count (messaget::M_WARNING)!=
142
+ warnings_before;
137
143
}
138
144
139
145
/* ******************************************************************\
@@ -156,8 +162,8 @@ bool compilet::add_input_file(const std::string &file_name)
156
162
std::ifstream in (file_name);
157
163
if (!in)
158
164
{
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
161
167
}
162
168
}
163
169
@@ -168,7 +174,7 @@ bool compilet::add_input_file(const std::string &file_name)
168
174
// a file without extension; will ignore
169
175
warning () << " input file `" << file_name
170
176
<< " ' has no extension, not considered" << eom;
171
- return false ;
177
+ return warning_is_fatal ;
172
178
}
173
179
174
180
std::string ext = file_name.substr (r+1 , file_name.length ());
@@ -329,7 +335,7 @@ bool compilet::find_library(const std::string &name)
329
335
else if (is_elf_file (libname))
330
336
{
331
337
warning () << " Warning: Cannot read ELF library " << libname << eom;
332
- return false ;
338
+ return warning_is_fatal ;
333
339
}
334
340
}
335
341
}
@@ -383,7 +389,7 @@ Function: compilet::link
383
389
bool compilet::link ()
384
390
{
385
391
// "compile" hitherto uncompiled functions
386
- print ( 8 , " Compiling functions" ) ;
392
+ statistics () << " Compiling functions" << eom ;
387
393
convert_symbols (compiled_functions);
388
394
389
395
// parse object files
@@ -409,7 +415,7 @@ bool compilet::link()
409
415
symbol_table.remove (goto_functionst::entry_point ());
410
416
compiled_functions.function_map .erase (goto_functionst::entry_point ());
411
417
412
- if (ansi_c_entry_point (symbol_table, " main" , ui_message_handler ))
418
+ if (ansi_c_entry_point (symbol_table, " main" , get_message_handler () ))
413
419
return true ;
414
420
415
421
// entry_point may (should) add some more functions.
@@ -554,7 +560,7 @@ bool compilet::parse(const std::string &file_name)
554
560
555
561
if (mode==PREPROCESS_ONLY)
556
562
{
557
- print ( 8 , " Preprocessing: " + file_name) ;
563
+ statistics () << " Preprocessing: " << file_name << eom ;
558
564
559
565
std::ostream *os = &std::cout;
560
566
std::ofstream ofs;
@@ -576,7 +582,7 @@ bool compilet::parse(const std::string &file_name)
576
582
}
577
583
else
578
584
{
579
- print ( 8 , " Parsing: " + file_name) ;
585
+ statistics () << " Parsing: " << file_name << eom ;
580
586
581
587
if (language.parse (infile, file_name))
582
588
{
@@ -608,7 +614,7 @@ bool compilet::parse_stdin()
608
614
609
615
language.set_message_handler (get_message_handler ());
610
616
611
- print ( 8 , " Parsing: (stdin)" ) ;
617
+ statistics () << " Parsing: (stdin)" << eom ;
612
618
613
619
if (mode==PREPROCESS_ONLY)
614
620
{
@@ -752,11 +758,11 @@ Function: compilet::compilet
752
758
753
759
\*******************************************************************/
754
760
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),
758
763
ns(symbol_table),
759
- cmdline(_cmdline)
764
+ cmdline(_cmdline),
765
+ warning_is_fatal(Werror)
760
766
{
761
767
mode=COMPILE_LINK_EXECUTABLE;
762
768
echo_file_name=false ;
@@ -842,7 +848,7 @@ Function: compilet::convert_symbols
842
848
843
849
void compilet::convert_symbols (goto_functionst &dest)
844
850
{
845
- goto_convert_functionst converter (symbol_table, dest, ui_message_handler );
851
+ goto_convert_functionst converter (symbol_table, dest, get_message_handler () );
846
852
847
853
// the compilation may add symbols!
848
854
@@ -872,7 +878,7 @@ void compilet::convert_symbols(goto_functionst &dest)
872
878
s_it->second .value .id ()!=" compiled" &&
873
879
s_it->second .value .is_not_nil ())
874
880
{
875
- print ( 9 , " Compiling " + id2string ( s_it->first )) ;
881
+ debug () << " Compiling " << s_it->first << eom ;
876
882
converter.convert_function (s_it->first );
877
883
s_it->second .value =exprt (" compiled" );
878
884
}
0 commit comments