@@ -34,6 +34,7 @@ Date: June 2006
34
34
35
35
#include < goto-programs/goto_convert.h>
36
36
#include < goto-programs/goto_convert_functions.h>
37
+ #include < goto-programs/link_goto_model.h>
37
38
#include < goto-programs/read_goto_binary.h>
38
39
#include < goto-programs/write_goto_binary.h>
39
40
@@ -359,9 +360,9 @@ bool compilet::compile()
359
360
if (echo_file_name)
360
361
std::cout << get_base_name (file_name, false ) << ' \n ' << std::flush;
361
362
362
- bool r= parse_source (file_name); // don't break the program!
363
+ auto file_goto_model = parse_source (file_name);
363
364
364
- if (r )
365
+ if (!file_goto_model. has_value () )
365
366
{
366
367
const std::string &debug_outfile=
367
368
cmdline.get_value (" print-rejected-preprocessed-source" );
@@ -381,7 +382,7 @@ bool compilet::compile()
381
382
// output an object file for every source file
382
383
383
384
// "compile" functions
384
- convert_symbols (goto_model. goto_functions );
385
+ convert_symbols (file_goto_model-> goto_functions );
385
386
386
387
std::string cfn;
387
388
@@ -398,14 +399,14 @@ bool compilet::compile()
398
399
else
399
400
cfn = output_file_object;
400
401
401
- if (write_bin_object_file (cfn, goto_model ))
402
+ if (write_bin_object_file (cfn, *file_goto_model ))
402
403
return true ;
403
404
404
- if (add_written_cprover_symbols (goto_model. symbol_table ))
405
+ if (add_written_cprover_symbols (file_goto_model-> symbol_table ))
405
406
return true ;
406
-
407
- goto_model.clear (); // clean symbol table for next source file.
408
407
}
408
+ else
409
+ link_goto_model (goto_model, *file_goto_model, get_message_handler ());
409
410
}
410
411
411
412
return false ;
@@ -579,30 +580,31 @@ bool compilet::write_bin_object_file(
579
580
return false ;
580
581
}
581
582
582
- // / parses a source file
583
- // / \return true on error, false otherwise
584
- bool compilet::parse_source (const std::string &file_name)
583
+ // / Parses and type checks a source file located at \p file_name.
584
+ // / \return A goto model if, and only if, parsing and type checking succeeded.
585
+ optionalt<goto_modelt> compilet::parse_source (const std::string &file_name)
585
586
{
586
587
language_filest language_files;
587
588
language_files.set_message_handler (get_message_handler ());
588
589
589
590
if (parse (file_name, language_files))
590
- return true ;
591
+ return {} ;
591
592
592
593
// we just typecheck one file here
593
- if (language_files.typecheck (goto_model.symbol_table ))
594
+ goto_modelt file_goto_model;
595
+ if (language_files.typecheck (file_goto_model.symbol_table ))
594
596
{
595
597
error () << " CONVERSION ERROR" << eom;
596
- return true ;
598
+ return {} ;
597
599
}
598
600
599
- if (language_files.final (goto_model .symbol_table ))
601
+ if (language_files.final (file_goto_model .symbol_table ))
600
602
{
601
603
error () << " CONVERSION ERROR" << eom;
602
- return true ;
604
+ return {} ;
603
605
}
604
606
605
- return false ;
607
+ return std::move (file_goto_model) ;
606
608
}
607
609
608
610
// / constructor
0 commit comments