Skip to content

Commit faa3144

Browse files
authored
Merge pull request #7938 from diffblue/widen-if-needed
introduce widen_if_needed
2 parents f33b96a + f06ff71 commit faa3144

File tree

14 files changed

+102
-201
lines changed

14 files changed

+102
-201
lines changed

src/ansi-c/c_preprocess.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/run.h>
1616
#include <util/suffix.h>
1717
#include <util/tempfile.h>
18-
19-
#ifdef _MSC_VER
20-
# include <util/unicode.h>
21-
#endif
18+
#include <util/unicode.h>
2219

2320
#include <fstream>
2421

@@ -720,11 +717,7 @@ bool c_preprocess_none(
720717
std::ostream &outstream,
721718
message_handlert &message_handler)
722719
{
723-
#ifdef _MSC_VER
724-
std::ifstream infile(widen(file));
725-
#else
726-
std::ifstream infile(file);
727-
#endif
720+
std::ifstream infile(widen_if_needed(file));
728721

729722
if(!infile)
730723
{

src/cbmc/cbmc_parse_options.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/help_formatter.h>
1717
#include <util/invariant.h>
1818
#include <util/make_unique.h>
19+
#include <util/unicode.h>
1920
#include <util/version.h>
2021

21-
#include <cstdlib> // exit()
22-
#include <fstream> // IWYU pragma: keep
23-
#include <iostream>
24-
#include <memory>
25-
26-
#ifdef _MSC_VER
27-
# include <util/unicode.h>
28-
#endif
29-
3022
#include <goto-programs/initialize_goto_model.h>
3123
#include <goto-programs/link_to_library.h>
3224
#include <goto-programs/loop_ids.h>
@@ -69,6 +61,11 @@ Author: Daniel Kroening, [email protected]
6961

7062
#include "c_test_input_generator.h"
7163

64+
#include <cstdlib> // exit()
65+
#include <fstream> // IWYU pragma: keep
66+
#include <iostream>
67+
#include <memory>
68+
7269
cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv)
7370
: parse_options_baset(
7471
CBMC_OPTIONS,
@@ -507,11 +504,7 @@ int cbmc_parse_optionst::doit()
507504

508505
std::string filename=cmdline.args[0];
509506

510-
#ifdef _MSC_VER
511-
std::ifstream infile(widen(filename));
512-
#else
513-
std::ifstream infile(filename);
514-
#endif
507+
std::ifstream infile(widen_if_needed(filename));
515508

516509
if(!infile)
517510
{

src/cprover/cprover_parse_options.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ Author: Daniel Kroening, [email protected]
1919
#include <util/parse_options.h>
2020
#include <util/signal_catcher.h>
2121
#include <util/ui_message.h>
22+
#include <util/unicode.h>
2223
#include <util/version.h>
2324

24-
#ifdef _WIN32
25-
# include <util/unicode.h>
26-
#endif
27-
2825
#include <goto-programs/adjust_float_expressions.h>
2926
#include <goto-programs/goto_inline.h>
3027
#include <goto-programs/initialize_goto_model.h>
@@ -236,11 +233,8 @@ int cprover_parse_optionst::main()
236233
if(cmdline.isset("outfile"))
237234
{
238235
auto file_name = cmdline.get_value("outfile");
239-
#ifdef _WIN32
240-
std::ofstream out(widen(file_name));
241-
#else
242-
std::ofstream out(file_name);
243-
#endif
236+
std::ofstream out(widen_if_needed(file_name));
237+
244238
if(!out)
245239
{
246240
std::cerr << "failed to open " << file_name << '\n';

src/goto-analyzer/show_on_source.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#include "show_on_source.h"
1010

1111
#include <util/message.h>
12-
13-
#ifdef _MSC_VER
14-
# include <util/unicode.h>
15-
#endif
12+
#include <util/unicode.h>
1613

1714
#include <analyses/ai.h>
1815

@@ -74,11 +71,7 @@ void show_on_source(
7471
const ai_baset &ai,
7572
message_handlert &message_handler)
7673
{
77-
#ifdef _MSC_VER
78-
std::ifstream in(widen(source_file));
79-
#else
80-
std::ifstream in(source_file);
81-
#endif
74+
std::ifstream in(widen_if_needed(source_file));
8275

8376
messaget message(message_handler);
8477

src/goto-cc/cl_message_handler.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ Author: Michael Tautschnig
88

99
#include "cl_message_handler.h"
1010

11-
#ifdef _MSC_VER
12-
# include <util/unicode.h>
13-
#endif
11+
#include <util/unicode.h>
1412

1513
#include <fstream>
1614

@@ -42,11 +40,8 @@ void cl_message_handlert::print(
4240

4341
if(full_path.has_value() && !line.empty())
4442
{
45-
#ifdef _MSC_VER
46-
std::ifstream in(widen(full_path.value()));
47-
#else
48-
std::ifstream in(full_path.value());
49-
#endif
43+
std::ifstream in(widen_if_needed(full_path.value()));
44+
5045
if(in)
5146
{
5247
const auto line_number = std::stoull(line);

src/goto-cc/compile.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ Date: June 2006
1313

1414
#include "compile.h"
1515

16-
#include <cstring>
17-
#include <fstream>
18-
#include <iostream>
19-
2016
#include <util/cmdline.h>
2117
#include <util/config.h>
2218
#include <util/file_util.h>
@@ -26,27 +22,26 @@ Date: June 2006
2622
#include <util/symbol_table_builder.h>
2723
#include <util/tempdir.h>
2824
#include <util/tempfile.h>
25+
#include <util/unicode.h>
2926
#include <util/version.h>
3027

31-
#ifdef _MSC_VER
32-
# include <util/unicode.h>
33-
#endif
34-
35-
#include <ansi-c/ansi_c_entry_point.h>
36-
#include <ansi-c/c_object_factory_parameters.h>
37-
3828
#include <goto-programs/goto_convert_functions.h>
3929
#include <goto-programs/name_mangler.h>
4030
#include <goto-programs/read_goto_binary.h>
4131
#include <goto-programs/write_goto_binary.h>
4232

33+
#include <ansi-c/ansi_c_entry_point.h>
34+
#include <ansi-c/c_object_factory_parameters.h>
4335
#include <langapi/language.h>
4436
#include <langapi/language_file.h>
4537
#include <langapi/mode.h>
46-
4738
#include <linking/linking.h>
4839
#include <linking/static_lifetime_init.h>
4940

41+
#include <cstring>
42+
#include <fstream>
43+
#include <iostream>
44+
5045
#define DOTGRAPHSETTINGS "color=black;" \
5146
"orientation=portrait;" \
5247
"fontsize=20;"\
@@ -479,11 +474,7 @@ bool compilet::parse(
479474
if(file_name == "-")
480475
return parse_stdin(*languagep);
481476

482-
#ifdef _MSC_VER
483-
std::ifstream infile(widen(file_name));
484-
#else
485-
std::ifstream infile(file_name);
486-
#endif
477+
std::ifstream infile(widen_if_needed(file_name));
487478

488479
if(!infile)
489480
{

src/goto-cc/gcc_message_handler.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "gcc_message_handler.h"
1010

11-
#ifdef _MSC_VER
12-
# include <util/unicode.h>
13-
#endif
11+
#include <util/unicode.h>
1412

1513
#include <fstream> // IWYU pragma: keep
1614
#include <iostream>
@@ -68,11 +66,8 @@ void gcc_message_handlert::print(
6866
const auto file_name = location.full_path();
6967
if(file_name.has_value() && !line.empty())
7068
{
71-
#ifdef _MSC_VER
72-
std::ifstream in(widen(file_name.value()));
73-
#else
74-
std::ifstream in(file_name.value());
75-
#endif
69+
std::ifstream in(widen_if_needed(file_name.value()));
70+
7671
if(in)
7772
{
7873
const auto line_number = std::stoull(id2string(line));

src/goto-checker/solver_factory.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@ Author: Daniel Kroening, Peter Schrammel
1717
#include <util/make_unique.h>
1818
#include <util/message.h>
1919
#include <util/options.h>
20-
#include <util/version.h>
21-
22-
#include <iostream>
23-
24-
#ifdef _MSC_VER
2520
#include <util/unicode.h>
26-
#endif
27-
28-
#include <solvers/stack_decision_procedure.h>
21+
#include <util/version.h>
2922

23+
#include <goto-symex/solver_hardness.h>
3024
#include <solvers/flattening/bv_dimacs.h>
3125
#include <solvers/prop/prop.h>
3226
#include <solvers/prop/solver_resource_limits.h>
@@ -36,9 +30,10 @@ Author: Daniel Kroening, Peter Schrammel
3630
#include <solvers/sat/satcheck.h>
3731
#include <solvers/smt2_incremental/smt2_incremental_decision_procedure.h>
3832
#include <solvers/smt2_incremental/smt_solver_process.h>
33+
#include <solvers/stack_decision_procedure.h>
3934
#include <solvers/strings/string_refinement.h>
4035

41-
#include <goto-symex/solver_hardness.h>
36+
#include <iostream>
4237

4338
solver_factoryt::solver_factoryt(
4439
const optionst &_options,
@@ -450,11 +445,7 @@ std::unique_ptr<std::ofstream> open_outfile_and_check(
450445
if(filename.empty())
451446
return nullptr;
452447

453-
#ifdef _MSC_VER
454-
auto out = util_make_unique<std::ofstream>(widen(filename));
455-
#else
456-
auto out = util_make_unique<std::ofstream>(filename);
457-
#endif
448+
auto out = util_make_unique<std::ofstream>(widen_if_needed(filename));
458449

459450
if(!*out)
460451
{

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,9 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/options.h>
1919
#include <util/string2int.h>
2020
#include <util/string_utils.h>
21+
#include <util/unicode.h>
2122
#include <util/version.h>
2223

23-
#include <fstream> // IWYU pragma: keep
24-
#include <iostream>
25-
#include <memory>
26-
27-
#ifdef _MSC_VER
28-
# include <util/unicode.h>
29-
#endif
30-
3124
#include <goto-programs/class_hierarchy.h>
3225
#include <goto-programs/ensure_one_backedge_per_target.h>
3326
#include <goto-programs/goto_check.h>
@@ -109,6 +102,10 @@ Author: Daniel Kroening, [email protected]
109102
#include "unwind.h"
110103
#include "value_set_fi_fp_removal.h"
111104

105+
#include <fstream> // IWYU pragma: keep
106+
#include <iostream>
107+
#include <memory>
108+
112109
#include "accelerate/accelerate.h"
113110

114111
/// invoke main modules
@@ -248,11 +245,8 @@ int goto_instrument_parse_optionst::doit()
248245

249246
if(have_file)
250247
{
251-
#ifdef _MSC_VER
252-
std::ofstream of(widen(filename));
253-
#else
254-
std::ofstream of(filename);
255-
#endif
248+
std::ofstream of(widen_if_needed(filename));
249+
256250
if(!of)
257251
throw "failed to open file "+filename;
258252

@@ -745,11 +739,8 @@ int goto_instrument_parse_optionst::doit()
745739

746740
if(cmdline.args.size()==2)
747741
{
748-
#ifdef _MSC_VER
749-
std::ofstream out(widen(cmdline.args[1]));
750-
#else
751-
std::ofstream out(cmdline.args[1]);
752-
#endif
742+
std::ofstream out(widen_if_needed(cmdline.args[1]));
743+
753744
if(!out)
754745
{
755746
log.error() << "failed to write to '" << cmdline.args[1] << "'";
@@ -844,11 +835,8 @@ int goto_instrument_parse_optionst::doit()
844835

845836
if(cmdline.args.size()==2)
846837
{
847-
#ifdef _MSC_VER
848-
std::ofstream out(widen(cmdline.args[1]));
849-
#else
850-
std::ofstream out(cmdline.args[1]);
851-
#endif
838+
std::ofstream out(widen_if_needed(cmdline.args[1]));
839+
852840
if(!out)
853841
{
854842
log.error() << "failed to write to " << cmdline.args[1] << "'";
@@ -891,11 +879,7 @@ int goto_instrument_parse_optionst::doit()
891879

892880
if(cmdline.args.size()==2)
893881
{
894-
#ifdef _MSC_VER
895-
std::ofstream out(widen(cmdline.args[1]));
896-
#else
897-
std::ofstream out(cmdline.args[1]);
898-
#endif
882+
std::ofstream out(widen_if_needed(cmdline.args[1]));
899883

900884
if(!out)
901885
{
@@ -1338,11 +1322,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
13381322

13391323
if(have_file)
13401324
{
1341-
#ifdef _MSC_VER
1342-
std::ofstream of(widen(filename));
1343-
#else
1344-
std::ofstream of(filename);
1345-
#endif
1325+
std::ofstream of(widen_if_needed(filename));
1326+
13461327
if(!of)
13471328
throw "failed to open file "+filename;
13481329

src/goto-instrument/unwindset.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/string2int.h>
1414
#include <util/string_utils.h>
1515
#include <util/symbol_table.h>
16-
17-
#ifdef _MSC_VER
18-
# include <util/unicode.h>
19-
#endif
16+
#include <util/unicode.h>
2017

2118
#include <goto-programs/abstract_goto_model.h>
2219

@@ -234,11 +231,7 @@ void unwindsett::parse_unwindset_file(
234231
const std::string &file_name,
235232
message_handlert &message_handler)
236233
{
237-
#ifdef _MSC_VER
238-
std::ifstream file(widen(file_name));
239-
#else
240-
std::ifstream file(file_name);
241-
#endif
234+
std::ifstream file(widen_if_needed(file_name));
242235

243236
if(!file)
244237
throw "cannot open file "+file_name;

0 commit comments

Comments
 (0)