@@ -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,13 +399,22 @@ 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.
407
+ }
408
+ else
409
+ {
410
+ try
411
+ {
412
+ link_goto_model (goto_model, *file_goto_model, get_message_handler ());
413
+ }
414
+ catch (...)
415
+ {
416
+ return true ;
417
+ }
408
418
}
409
419
}
410
420
@@ -579,30 +589,31 @@ bool compilet::write_bin_object_file(
579
589
return false ;
580
590
}
581
591
582
- // / parses a source file
583
- // / \return true on error, false otherwise
584
- bool compilet::parse_source (const std::string &file_name)
592
+ // / Parses and type checks a source file located at \p file_name.
593
+ // / \return A goto model if, and only if, parsing and type checking succeeded.
594
+ optionalt<goto_modelt> compilet::parse_source (const std::string &file_name)
585
595
{
586
596
language_filest language_files;
587
597
language_files.set_message_handler (get_message_handler ());
588
598
589
599
if (parse (file_name, language_files))
590
- return true ;
600
+ return {} ;
591
601
592
602
// we just typecheck one file here
593
- if (language_files.typecheck (goto_model.symbol_table ))
603
+ goto_modelt file_goto_model;
604
+ if (language_files.typecheck (file_goto_model.symbol_table ))
594
605
{
595
606
error () << " CONVERSION ERROR" << eom;
596
- return true ;
607
+ return {} ;
597
608
}
598
609
599
- if (language_files.final (goto_model .symbol_table ))
610
+ if (language_files.final (file_goto_model .symbol_table ))
600
611
{
601
612
error () << " CONVERSION ERROR" << eom;
602
- return true ;
613
+ return {} ;
603
614
}
604
615
605
- return false ;
616
+ return std::move (file_goto_model) ;
606
617
}
607
618
608
619
// / constructor
0 commit comments