Skip to content

Commit 5752f19

Browse files
author
Daniel Kroening
authored
Merge pull request #3679 from tautschnig/vs-shadow-goto-cc
Avoid shadowing in directory goto-cc/ [blocks: #2310]
2 parents eb4f9c2 + 2b27328 commit 5752f19

8 files changed

+75
-89
lines changed

src/goto-cc/compile.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool compilet::doit()
7979
{
8080
goto_model.goto_functions.clear();
8181

82-
add_compiler_specific_defines(config);
82+
add_compiler_specific_defines();
8383

8484
// Parse command line for source and object file names
8585
for(const auto &arg : cmdline.args)
@@ -381,7 +381,7 @@ bool compilet::link()
381381
convert_symbols(goto_model.goto_functions);
382382
}
383383

384-
if(write_object_file(output_file_executable, goto_model))
384+
if(write_bin_object_file(output_file_executable, goto_model))
385385
return true;
386386

387387
return add_written_cprover_symbols(goto_model.symbol_table);
@@ -441,7 +441,7 @@ bool compilet::compile()
441441
else
442442
cfn = output_file_object;
443443

444-
if(write_object_file(cfn, goto_model))
444+
if(write_bin_object_file(cfn, goto_model))
445445
return true;
446446

447447
if(add_written_cprover_symbols(goto_model.symbol_table))
@@ -580,31 +580,21 @@ bool compilet::parse_stdin()
580580
return false;
581581
}
582582

583-
/// writes the goto functions in the function table to a binary format object
583+
/// Writes the goto functions of \p src_goto_model to a binary format object
584584
/// file.
585-
/// \par parameters: file_name, functions table
586-
/// \return true on error, false otherwise
587-
bool compilet::write_object_file(
588-
const std::string &file_name,
589-
const goto_modelt &goto_model)
590-
{
591-
return write_bin_object_file(file_name, goto_model);
592-
}
593-
594-
/// writes the goto functions in the function table to a binary format object
595-
/// file.
596-
/// \par parameters: file_name, functions table
585+
/// \param file_name: Target file to serialize \p src_goto_model to
586+
/// \param src_goto_model: goto model to serialize
597587
/// \return true on error, false otherwise
598588
bool compilet::write_bin_object_file(
599589
const std::string &file_name,
600-
const goto_modelt &goto_model)
590+
const goto_modelt &src_goto_model)
601591
{
602592
statistics() << "Writing binary format object `"
603593
<< file_name << "'" << eom;
604594

605595
// symbols
606-
statistics() << "Symbols in table: " << goto_model.symbol_table.symbols.size()
607-
<< eom;
596+
statistics() << "Symbols in table: "
597+
<< src_goto_model.symbol_table.symbols.size() << eom;
608598

609599
std::ofstream outfile(file_name, std::ios::binary);
610600

@@ -614,13 +604,14 @@ bool compilet::write_bin_object_file(
614604
return true;
615605
}
616606

617-
if(write_goto_binary(outfile, goto_model))
607+
if(write_goto_binary(outfile, src_goto_model))
618608
return true;
619609

620-
const auto cnt = function_body_count(goto_model.goto_functions);
610+
const auto cnt = function_body_count(src_goto_model.goto_functions);
621611

622-
statistics() << "Functions: " << goto_model.goto_functions.function_map.size()
623-
<< "; " << cnt << " have a body." << eom;
612+
statistics() << "Functions: "
613+
<< src_goto_model.goto_functions.function_map.size() << "; "
614+
<< cnt << " have a body." << eom;
624615

625616
outfile.close();
626617
wrote_object=true;
@@ -690,7 +681,7 @@ compilet::function_body_count(const goto_functionst &functions) const
690681
return count;
691682
}
692683

693-
void compilet::add_compiler_specific_defines(configt &config) const
684+
void compilet::add_compiler_specific_defines() const
694685
{
695686
config.ansi_c.defines.push_back(
696687
std::string("__GOTO_CC_VERSION__=") + CBMC_VERSION);

src/goto-cc/compile.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ class compilet : public messaget
7171

7272
bool parse_source(const std::string &);
7373

74-
bool write_object_file(const std::string &, const goto_modelt &);
75-
7674
bool write_bin_object_file(const std::string &, const goto_modelt &);
7775

7876
/// \brief Has this compiler written any object files?
@@ -98,7 +96,7 @@ class compilet : public messaget
9896

9997
std::size_t function_body_count(const goto_functionst &) const;
10098

101-
void add_compiler_specific_defines(class configt &config) const;
99+
void add_compiler_specific_defines() const;
102100

103101
void convert_symbols(goto_functionst &dest);
104102

src/goto-cc/gcc_cmdline.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,25 +221,25 @@ bool gcc_cmdlinet::parse(int argc, const char **argv)
221221
assert(argc>0);
222222
add_arg(argv[0]);
223223

224-
argst args;
225-
args.reserve(argc-1);
224+
argst current_args;
225+
current_args.reserve(argc - 1);
226226

227227
for(int i=1; i<argc; i++)
228-
args.push_back(argv[i]);
228+
current_args.push_back(argv[i]);
229229

230-
bool result=parse_arguments(args, false);
230+
bool result = parse_arguments(current_args, false);
231231

232232
parse_specs();
233233

234234
return result;
235235
}
236236

237237
bool gcc_cmdlinet::parse_arguments(
238-
const argst &args,
238+
const argst &args_to_parse,
239239
bool in_spec_file)
240240
{
241-
for(argst::const_iterator it=args.begin();
242-
it!=args.end();
241+
for(argst::const_iterator it = args_to_parse.begin();
242+
it != args_to_parse.end();
243243
++it)
244244
{
245245
const std::string &argv_i=*it;
@@ -292,7 +292,7 @@ bool gcc_cmdlinet::parse_arguments(
292292
if(argv_i==*o) // separated
293293
{
294294
found=true;
295-
if(next!=args.end())
295+
if(next != args_to_parse.end())
296296
{
297297
set(argv_i, *next);
298298
++it;
@@ -364,7 +364,7 @@ bool gcc_cmdlinet::parse_arguments(
364364
if(argv_i==*o) // separated
365365
{
366366
found=true;
367-
if(next!=args.end())
367+
if(next != args_to_parse.end())
368368
{
369369
set(argv_i, *next);
370370
if(!in_spec_file)
@@ -390,7 +390,7 @@ bool gcc_cmdlinet::parse_arguments(
390390
if(argv_i==*o) // separated
391391
{
392392
found=true;
393-
if(next!=args.end())
393+
if(next != args_to_parse.end())
394394
{
395395
set(argv_i, *next);
396396
if(!in_spec_file)
@@ -438,17 +438,17 @@ void gcc_cmdlinet::parse_specs_line(const std::string &line, bool in_spec_file)
438438
assert(!line.empty());
439439
assert(line[0]!=' ' && line[0]!='\t');
440440

441-
argst args;
441+
argst args_from_specs;
442442

443443
for(std::string::size_type arg_start=0, arg_end=0;
444444
arg_end!=std::string::npos;
445445
arg_start=line.find_first_not_of("\t ", arg_end))
446446
{
447447
arg_end=line.find_first_of("\t ", arg_start);
448-
args.push_back(line.substr(arg_start, arg_end-arg_start));
448+
args_from_specs.push_back(line.substr(arg_start, arg_end - arg_start));
449449
}
450450

451-
parse_arguments(args, in_spec_file);
451+
parse_arguments(args_from_specs, in_spec_file);
452452
}
453453

454454
/// Parse GCC spec files https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html

src/goto-cc/gcc_cmdline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class gcc_cmdlinet:public goto_cc_cmdlinet
2929
protected:
3030
typedef std::vector<std::string> argst;
3131

32-
bool parse_arguments(const argst &args, bool in_spec_file);
32+
bool parse_arguments(const argst &args_to_parse, bool in_spec_file);
3333
void parse_specs();
3434
void parse_specs_line(const std::string &line, bool in_spec_file);
3535
};

src/goto-cc/gcc_version.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void gcc_versiont::get(const std::string &executable)
9595
out << "default_cxx_standard __cplusplus\n";
9696
}
9797

98-
int result = run(
98+
result = run(
9999
executable,
100100
{executable, "-E", "-x", "c++", "-", "-o", "-"},
101101
cpp_in(),
@@ -104,10 +104,9 @@ void gcc_versiont::get(const std::string &executable)
104104

105105
if(result >= 0)
106106
{
107-
std::ifstream in(cpp_out());
108-
std::string line;
107+
std::ifstream in2(cpp_out());
109108

110-
while(!in.fail() && std::getline(in, line))
109+
while(!in2.fail() && std::getline(in2, line))
111110
{
112111
if(line.empty() || line[0] == '#')
113112
continue;

src/goto-cc/linker_script_merge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int linker_script_merget::add_linker_script_definitions()
105105
return fail;
106106
}
107107

108-
fail = compiler.write_object_file(goto_binary, original_goto_model);
108+
fail = compiler.write_bin_object_file(goto_binary, original_goto_model);
109109

110110
if(fail!=0)
111111
error() << "Could not write linkerscript-augmented binary" << eom;

src/goto-cc/ms_cl_cmdline.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,46 @@ const char *non_ms_cl_options[]=
4747
nullptr
4848
};
4949

50-
bool ms_cl_cmdlinet::parse(const std::vector<std::string> &options)
50+
bool ms_cl_cmdlinet::parse(const std::vector<std::string> &arguments)
5151
{
52-
for(std::size_t i=0; i<options.size(); i++)
52+
for(std::size_t i = 0; i < arguments.size(); i++)
5353
{
5454
// is it a non-cl option?
55-
if(std::string(options[i], 0, 2)=="--")
55+
if(std::string(arguments[i], 0, 2) == "--")
5656
{
57-
process_non_cl_option(options[i]);
57+
process_non_cl_option(arguments[i]);
5858

59-
if(options[i]=="--verbosity" ||
60-
options[i]=="--function")
59+
if(arguments[i] == "--verbosity" || arguments[i] == "--function")
6160
{
62-
if(i<options.size()-1)
61+
if(i < arguments.size() - 1)
6362
{
64-
set(options[i], options[i+1]);
63+
set(arguments[i], arguments[i + 1]);
6564
i++; // skip ahead
6665
}
6766
}
6867
}
69-
else if(!options[i].empty() && options[i][0]=='@')
68+
else if(!arguments[i].empty() && arguments[i][0] == '@')
7069
{
7170
// potentially recursive
72-
process_response_file(
73-
std::string(options[i], 1, std::string::npos));
71+
process_response_file(std::string(arguments[i], 1, std::string::npos));
7472
}
75-
else if(options[i]=="/link" ||
76-
options[i]=="-link")
73+
else if(arguments[i] == "/link" || arguments[i] == "-link")
7774
{
7875
// anything that follows goes to the linker
79-
i=options.size()-1;
76+
i = arguments.size() - 1;
8077
}
81-
else if(options[i].size()==2 &&
82-
(options[i]=="/D" || options[i]=="-D") &&
83-
i!=options.size()-1)
78+
else if(
79+
arguments[i].size() == 2 &&
80+
(arguments[i] == "/D" || arguments[i] == "-D") &&
81+
i != arguments.size() - 1)
8482
{
8583
// this requires special treatment, as you can do "/D something"
86-
std::string tmp="/D"+options[i+1];
84+
std::string tmp = "/D" + arguments[i + 1];
8785
i++;
8886
process_cl_option(tmp);
8987
}
9088
else
91-
process_cl_option(options[i]);
89+
process_cl_option(arguments[i]);
9290
}
9391

9492
return false;
@@ -123,13 +121,13 @@ bool ms_cl_cmdlinet::parse(int argc, const char **argv)
123121
{
124122
// should really use "wide" argv from wmain()
125123

126-
std::vector<std::string> options;
124+
std::vector<std::string> arguments;
127125

128126
// skip argv[0]
129127
for(int i=1; i<argc; i++)
130-
options.push_back(argv[i]);
128+
arguments.push_back(argv[i]);
131129

132-
return parse(options);
130+
return parse(arguments);
133131
}
134132

135133
static std::istream &my_wgetline(std::istream &in, std::wstring &dest)
@@ -242,7 +240,7 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line)
242240
if(line[0]=='#')
243241
return; // comment
244242

245-
std::vector<std::string> options;
243+
std::vector<std::string> arguments;
246244
std::string option;
247245
bool in_quotes=false;
248246
for(std::size_t i=0; i<line.size(); i++)
@@ -252,7 +250,7 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line)
252250
if(ch==' ' && !in_quotes)
253251
{
254252
if(!option.empty())
255-
options.push_back(option);
253+
arguments.push_back(option);
256254
option.clear();
257255
}
258256
else if(ch=='"')
@@ -264,9 +262,9 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line)
264262
}
265263

266264
if(!option.empty())
267-
options.push_back(option);
265+
arguments.push_back(option);
268266

269-
parse(options);
267+
parse(arguments);
270268
}
271269

272270
/// \return none

0 commit comments

Comments
 (0)