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