Skip to content

Commit e8c09d3

Browse files
authored
Merge pull request #5616 from tautschnig/messaget-compilet
compilet isn't a messaget
2 parents 0af9689 + 2976b5c commit e8c09d3

File tree

2 files changed

+73
-59
lines changed

2 files changed

+73
-59
lines changed

src/goto-cc/compile.cpp

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,37 @@ bool compilet::doit()
6868
{
6969
if(!find_library(library))
7070
// GCC is going to complain if this doesn't exist
71-
debug() << "Library not found: " << library << " (ignoring)" << eom;
71+
log.debug() << "Library not found: " << library << " (ignoring)"
72+
<< messaget::eom;
7273
}
7374

74-
statistics() << "No. of source files: " << source_files.size() << eom;
75-
statistics() << "No. of object files: " << object_files.size() << eom;
75+
log.statistics() << "No. of source files: " << source_files.size()
76+
<< messaget::eom;
77+
log.statistics() << "No. of object files: " << object_files.size()
78+
<< messaget::eom;
7679

7780
// Work through the given source files
7881

7982
if(source_files.empty() && object_files.empty())
8083
{
81-
error() << "no input files" << eom;
84+
log.error() << "no input files" << messaget::eom;
8285
return true;
8386
}
8487

8588
if(mode==LINK_LIBRARY && !source_files.empty())
8689
{
87-
error() << "cannot link source files" << eom;
90+
log.error() << "cannot link source files" << messaget::eom;
8891
return true;
8992
}
9093

9194
if(mode==PREPROCESS_ONLY && !object_files.empty())
9295
{
93-
error() << "cannot preprocess object files" << eom;
96+
log.error() << "cannot preprocess object files" << messaget::eom;
9497
return true;
9598
}
9699

97-
const unsigned warnings_before=
98-
get_message_handler().get_message_count(messaget::M_WARNING);
100+
const unsigned warnings_before =
101+
log.get_message_handler().get_message_count(messaget::M_WARNING);
99102

100103
auto symbol_table_opt = compile();
101104
if(!symbol_table_opt.has_value())
@@ -109,10 +112,8 @@ bool compilet::doit()
109112
return true;
110113
}
111114

112-
return
113-
warning_is_fatal &&
114-
get_message_handler().get_message_count(messaget::M_WARNING)!=
115-
warnings_before;
115+
return warning_is_fatal && log.get_message_handler().get_message_count(
116+
messaget::M_WARNING) != warnings_before;
116117
}
117118

118119
enum class file_typet
@@ -169,22 +170,23 @@ static file_typet detect_file_type(
169170
/// \return false on success, true on error.
170171
bool compilet::add_input_file(const std::string &file_name)
171172
{
172-
switch(detect_file_type(file_name, get_message_handler()))
173+
switch(detect_file_type(file_name, log.get_message_handler()))
173174
{
174175
case file_typet::FAILED_TO_OPEN_FILE:
175-
warning() << "failed to open file '" << file_name
176-
<< "': " << std::strerror(errno) << eom;
176+
log.warning() << "failed to open file '" << file_name
177+
<< "': " << std::strerror(errno) << messaget::eom;
177178
return warning_is_fatal; // generously ignore unless -Werror
178179

179180
case file_typet::UNKNOWN:
180181
// unknown extension, not a goto binary, will silently ignore
181-
debug() << "unknown file type in '" << file_name << "'" << eom;
182+
log.debug() << "unknown file type in '" << file_name << "'"
183+
<< messaget::eom;
182184
return false;
183185

184186
case file_typet::ELF_OBJECT:
185187
// ELF file without goto-cc section, silently ignore
186-
debug() << "ELF object without goto-cc section: '" << file_name << "'"
187-
<< eom;
188+
log.debug() << "ELF object without goto-cc section: '" << file_name << "'"
189+
<< messaget::eom;
188190
return false;
189191

190192
case file_typet::SOURCE_FILE:
@@ -225,7 +227,7 @@ bool compilet::add_files_from_archive(
225227
run("ar", {"ar", "x", concat_dir_file(working_directory, file_name)});
226228
if(ret != 0)
227229
{
228-
error() << "Failed to extract archive " << file_name << eom;
230+
log.error() << "Failed to extract archive " << file_name << messaget::eom;
229231
return true;
230232
}
231233
}
@@ -240,7 +242,7 @@ bool compilet::add_files_from_archive(
240242
"");
241243
if(ret != 0)
242244
{
243-
error() << "Failed to list archive " << file_name << eom;
245+
log.error() << "Failed to list archive " << file_name << messaget::eom;
244246
return true;
245247
}
246248

@@ -251,10 +253,11 @@ bool compilet::add_files_from_archive(
251253
{
252254
std::string t = concat_dir_file(tstr, line);
253255

254-
if(is_goto_binary(t, get_message_handler()))
256+
if(is_goto_binary(t, log.get_message_handler()))
255257
object_files.push_back(t);
256258
else
257-
debug() << "Object file is not a goto binary: " << line << eom;
259+
log.debug() << "Object file is not a goto binary: " << line
260+
<< messaget::eom;
258261
}
259262

260263
if(!thin_archive)
@@ -282,14 +285,14 @@ bool compilet::find_library(const std::string &name)
282285
{
283286
library_file_name = concat_dir_file(library_path, "lib" + name + ".so");
284287

285-
switch(detect_file_type(library_file_name, get_message_handler()))
288+
switch(detect_file_type(library_file_name, log.get_message_handler()))
286289
{
287290
case file_typet::GOTO_BINARY:
288291
return !add_input_file(library_file_name);
289292

290293
case file_typet::ELF_OBJECT:
291-
warning() << "Warning: Cannot read ELF library " << library_file_name
292-
<< eom;
294+
log.warning() << "Warning: Cannot read ELF library "
295+
<< library_file_name << messaget::eom;
293296
return warning_is_fatal;
294297

295298
case file_typet::THIN_ARCHIVE:
@@ -310,7 +313,7 @@ bool compilet::find_library(const std::string &name)
310313
bool compilet::link(optionalt<symbol_tablet> &&symbol_table)
311314
{
312315
// "compile" hitherto uncompiled functions
313-
statistics() << "Compiling functions" << eom;
316+
log.statistics() << "Compiling functions" << messaget::eom;
314317
goto_modelt goto_model;
315318
if(symbol_table.has_value())
316319
goto_model.symbol_table = std::move(*symbol_table);
@@ -319,7 +322,7 @@ bool compilet::link(optionalt<symbol_tablet> &&symbol_table)
319322
// parse object files
320323
for(const auto &file_name : object_files)
321324
{
322-
if(read_object_and_link(file_name, goto_model, get_message_handler()))
325+
if(read_object_and_link(file_name, goto_model, log.get_message_handler()))
323326
return true;
324327
}
325328

@@ -338,7 +341,7 @@ bool compilet::link(optionalt<symbol_tablet> &&symbol_table)
338341

339342
const bool error = ansi_c_entry_point(
340343
goto_model.symbol_table,
341-
get_message_handler(),
344+
log.get_message_handler(),
342345
c_object_factory_parameterst());
343346

344347
if(error)
@@ -351,7 +354,7 @@ bool compilet::link(optionalt<symbol_tablet> &&symbol_table)
351354
if(keep_file_local)
352355
{
353356
function_name_manglert<file_name_manglert> mangler(
354-
get_message_handler(), goto_model, file_local_mangle_suffix);
357+
log.get_message_handler(), goto_model, file_local_mangle_suffix);
355358
mangler.mangle();
356359
}
357360

@@ -389,7 +392,7 @@ optionalt<symbol_tablet> compilet::compile()
389392
std::ifstream in(file_name, std::ios::binary);
390393
std::ofstream out(debug_outfile, std::ios::binary);
391394
out << in.rdbuf();
392-
warning() << "Failed sources in " << debug_outfile << eom;
395+
log.warning() << "Failed sources in " << debug_outfile << messaget::eom;
393396
}
394397

395398
return {}; // parser/typecheck error
@@ -422,7 +425,7 @@ optionalt<symbol_tablet> compilet::compile()
422425
if(keep_file_local)
423426
{
424427
function_name_manglert<file_name_manglert> mangler(
425-
get_message_handler(), file_goto_model, file_local_mangle_suffix);
428+
log.get_message_handler(), file_goto_model, file_local_mangle_suffix);
426429
mangler.mangle();
427430
}
428431

@@ -434,7 +437,7 @@ optionalt<symbol_tablet> compilet::compile()
434437
}
435438
else
436439
{
437-
if(linking(symbol_table, *file_symbol_table, get_message_handler()))
440+
if(linking(symbol_table, *file_symbol_table, log.get_message_handler()))
438441
{
439442
return {};
440443
}
@@ -467,11 +470,12 @@ bool compilet::parse(
467470

468471
if(languagep==nullptr)
469472
{
470-
error() << "failed to figure out type of file '" << file_name << "'" << eom;
473+
log.error() << "failed to figure out type of file '" << file_name << "'"
474+
<< messaget::eom;
471475
return true;
472476
}
473477

474-
languagep->set_message_handler(get_message_handler());
478+
languagep->set_message_handler(log.get_message_handler());
475479

476480
if(file_name == "-")
477481
return parse_stdin(*languagep);
@@ -484,7 +488,8 @@ bool compilet::parse(
484488

485489
if(!infile)
486490
{
487-
error() << "failed to open input file '" << file_name << "'" << eom;
491+
log.error() << "failed to open input file '" << file_name << "'"
492+
<< messaget::eom;
488493
return true;
489494
}
490495

@@ -493,7 +498,7 @@ bool compilet::parse(
493498

494499
if(mode==PREPROCESS_ONLY)
495500
{
496-
statistics() << "Preprocessing: " << file_name << eom;
501+
log.statistics() << "Preprocessing: " << file_name << messaget::eom;
497502

498503
std::ostream *os = &std::cout;
499504
std::ofstream ofs;
@@ -505,8 +510,8 @@ bool compilet::parse(
505510

506511
if(!ofs.is_open())
507512
{
508-
error() << "failed to open output file '" << cmdline.get_value('o')
509-
<< "'" << eom;
513+
log.error() << "failed to open output file '" << cmdline.get_value('o')
514+
<< "'" << messaget::eom;
510515
return true;
511516
}
512517
}
@@ -515,11 +520,11 @@ bool compilet::parse(
515520
}
516521
else
517522
{
518-
statistics() << "Parsing: " << file_name << eom;
523+
log.statistics() << "Parsing: " << file_name << messaget::eom;
519524

520525
if(lf.language->parse(infile, file_name))
521526
{
522-
error() << "PARSING ERROR" << eom;
527+
log.error() << "PARSING ERROR" << messaget::eom;
523528
return true;
524529
}
525530
}
@@ -533,7 +538,7 @@ bool compilet::parse(
533538
/// \return true on error, false otherwise
534539
bool compilet::parse_stdin(languaget &language)
535540
{
536-
statistics() << "Parsing: (stdin)" << eom;
541+
log.statistics() << "Parsing: (stdin)" << messaget::eom;
537542

538543
if(mode==PREPROCESS_ONLY)
539544
{
@@ -547,8 +552,8 @@ bool compilet::parse_stdin(languaget &language)
547552

548553
if(!ofs.is_open())
549554
{
550-
error() << "failed to open output file '" << cmdline.get_value('o')
551-
<< "'" << eom;
555+
log.error() << "failed to open output file '" << cmdline.get_value('o')
556+
<< "'" << messaget::eom;
552557
return true;
553558
}
554559
}
@@ -559,7 +564,7 @@ bool compilet::parse_stdin(languaget &language)
559564
{
560565
if(language.parse(std::cin, ""))
561566
{
562-
error() << "PARSING ERROR" << eom;
567+
log.error() << "PARSING ERROR" << messaget::eom;
563568
return true;
564569
}
565570
}
@@ -616,7 +621,7 @@ bool compilet::write_bin_object_file(
616621
optionalt<symbol_tablet> compilet::parse_source(const std::string &file_name)
617622
{
618623
language_filest language_files;
619-
language_files.set_message_handler(get_message_handler());
624+
language_files.set_message_handler(log.get_message_handler());
620625

621626
if(parse(file_name, language_files))
622627
return {};
@@ -625,13 +630,13 @@ optionalt<symbol_tablet> compilet::parse_source(const std::string &file_name)
625630
symbol_tablet file_symbol_table;
626631
if(language_files.typecheck(file_symbol_table, keep_file_local))
627632
{
628-
error() << "CONVERSION ERROR" << eom;
633+
log.error() << "CONVERSION ERROR" << messaget::eom;
629634
return {};
630635
}
631636

632637
if(language_files.final(file_symbol_table))
633638
{
634-
error() << "CONVERSION ERROR" << eom;
639+
log.error() << "CONVERSION ERROR" << messaget::eom;
635640
return {};
636641
}
637642

@@ -641,7 +646,7 @@ optionalt<symbol_tablet> compilet::parse_source(const std::string &file_name)
641646
/// constructor
642647
/// \return nothing
643648
compilet::compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
644-
: messaget(mh),
649+
: log(mh),
645650
cmdline(_cmdline),
646651
warning_is_fatal(Werror),
647652
keep_file_local(
@@ -657,9 +662,12 @@ compilet::compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
657662
working_directory=get_current_working_directory();
658663

659664
if(cmdline.isset("export-function-local-symbols"))
660-
warning() << "The `--export-function-local-symbols` flag is deprecated. "
661-
"Please use `--export-file-local-symbols` instead."
662-
<< eom;
665+
{
666+
log.warning()
667+
<< "The `--export-function-local-symbols` flag is deprecated. "
668+
"Please use `--export-file-local-symbols` instead."
669+
<< messaget::eom;
670+
}
663671
}
664672

665673
/// cleans up temporary files
@@ -695,7 +703,7 @@ void compilet::convert_symbols(goto_modelt &goto_model)
695703
symbol_table_buildert::wrap(goto_model.symbol_table);
696704

697705
goto_convert_functionst converter(
698-
symbol_table_builder, get_message_handler());
706+
symbol_table_builder, log.get_message_handler());
699707

700708
// the compilation may add symbols!
701709

@@ -722,7 +730,7 @@ void compilet::convert_symbols(goto_modelt &goto_model)
722730
s_it->second.is_function() && !s_it->second.is_compiled() &&
723731
s_it->second.value.is_not_nil())
724732
{
725-
debug() << "Compiling " << s_it->first << eom;
733+
log.debug() << "Compiling " << s_it->first << messaget::eom;
726734
converter.convert_function(
727735
s_it->first, goto_model.goto_functions.function_map[s_it->first]);
728736
symbol_table_builder.get_writeable_ref(symbol).set_compiled();
@@ -746,10 +754,12 @@ bool compilet::add_written_cprover_symbols(const symbol_tablet &symbol_table)
746754

747755
if(!inserted && old->second.type!=new_type)
748756
{
749-
error() << "Incompatible CPROVER macro symbol types:" << eom
750-
<< old->second.type.pretty() << "(at " << old->second.location
751-
<< ")" << eom << "and" << eom << new_type.pretty()
752-
<< "(at " << pair.second.location << ")" << eom;
757+
log.error() << "Incompatible CPROVER macro symbol types:" << '\n'
758+
<< old->second.type.pretty() << "(at " << old->second.location
759+
<< ")\n"
760+
<< "and\n"
761+
<< new_type.pretty() << "(at " << pair.second.location << ")"
762+
<< messaget::eom;
753763
return true;
754764
}
755765
}

0 commit comments

Comments
 (0)