Skip to content

Avoid shadowing in directory goto-cc/ [blocks: #2310] #3679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions src/goto-cc/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool compilet::doit()
{
goto_model.goto_functions.clear();

add_compiler_specific_defines(config);
add_compiler_specific_defines();

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

if(write_object_file(output_file_executable, goto_model))
if(write_bin_object_file(output_file_executable, goto_model))
return true;

return add_written_cprover_symbols(goto_model.symbol_table);
Expand Down Expand Up @@ -441,7 +441,7 @@ bool compilet::compile()
else
cfn = output_file_object;

if(write_object_file(cfn, goto_model))
if(write_bin_object_file(cfn, goto_model))
return true;

if(add_written_cprover_symbols(goto_model.symbol_table))
Expand Down Expand Up @@ -580,31 +580,21 @@ bool compilet::parse_stdin()
return false;
}

/// writes the goto functions in the function table to a binary format object
/// Writes the goto functions of \p src_goto_model to a binary format object
/// file.
/// \par parameters: file_name, functions table
/// \return true on error, false otherwise
bool compilet::write_object_file(
const std::string &file_name,
const goto_modelt &goto_model)
{
return write_bin_object_file(file_name, goto_model);
}

/// writes the goto functions in the function table to a binary format object
/// file.
/// \par parameters: file_name, functions table
/// \param file_name: Target file to serialize \p src_goto_model to
/// \param src_goto_model: goto model to serialize
/// \return true on error, false otherwise
bool compilet::write_bin_object_file(
const std::string &file_name,
const goto_modelt &goto_model)
const goto_modelt &src_goto_model)
{
statistics() << "Writing binary format object `"
<< file_name << "'" << eom;

// symbols
statistics() << "Symbols in table: " << goto_model.symbol_table.symbols.size()
<< eom;
statistics() << "Symbols in table: "
<< src_goto_model.symbol_table.symbols.size() << eom;

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

Expand All @@ -614,13 +604,14 @@ bool compilet::write_bin_object_file(
return true;
}

if(write_goto_binary(outfile, goto_model))
if(write_goto_binary(outfile, src_goto_model))
return true;

const auto cnt = function_body_count(goto_model.goto_functions);
const auto cnt = function_body_count(src_goto_model.goto_functions);

statistics() << "Functions: " << goto_model.goto_functions.function_map.size()
<< "; " << cnt << " have a body." << eom;
statistics() << "Functions: "
<< src_goto_model.goto_functions.function_map.size() << "; "
<< cnt << " have a body." << eom;

outfile.close();
wrote_object=true;
Expand Down Expand Up @@ -690,7 +681,7 @@ compilet::function_body_count(const goto_functionst &functions) const
return count;
}

void compilet::add_compiler_specific_defines(configt &config) const
void compilet::add_compiler_specific_defines() const
{
config.ansi_c.defines.push_back(
std::string("__GOTO_CC_VERSION__=") + CBMC_VERSION);
Expand Down
4 changes: 1 addition & 3 deletions src/goto-cc/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class compilet : public messaget

bool parse_source(const std::string &);

bool write_object_file(const std::string &, const goto_modelt &);

bool write_bin_object_file(const std::string &, const goto_modelt &);

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

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

void add_compiler_specific_defines(class configt &config) const;
void add_compiler_specific_defines() const;

void convert_symbols(goto_functionst &dest);

Expand Down
26 changes: 13 additions & 13 deletions src/goto-cc/gcc_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,25 @@ bool gcc_cmdlinet::parse(int argc, const char **argv)
assert(argc>0);
add_arg(argv[0]);

argst args;
args.reserve(argc-1);
argst current_args;
current_args.reserve(argc - 1);

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

bool result=parse_arguments(args, false);
bool result = parse_arguments(current_args, false);

parse_specs();

return result;
}

bool gcc_cmdlinet::parse_arguments(
const argst &args,
const argst &args_to_parse,
bool in_spec_file)
{
for(argst::const_iterator it=args.begin();
it!=args.end();
for(argst::const_iterator it = args_to_parse.begin();
it != args_to_parse.end();
++it)
{
const std::string &argv_i=*it;
Expand Down Expand Up @@ -292,7 +292,7 @@ bool gcc_cmdlinet::parse_arguments(
if(argv_i==*o) // separated
{
found=true;
if(next!=args.end())
if(next != args_to_parse.end())
{
set(argv_i, *next);
++it;
Expand Down Expand Up @@ -364,7 +364,7 @@ bool gcc_cmdlinet::parse_arguments(
if(argv_i==*o) // separated
{
found=true;
if(next!=args.end())
if(next != args_to_parse.end())
{
set(argv_i, *next);
if(!in_spec_file)
Expand All @@ -390,7 +390,7 @@ bool gcc_cmdlinet::parse_arguments(
if(argv_i==*o) // separated
{
found=true;
if(next!=args.end())
if(next != args_to_parse.end())
{
set(argv_i, *next);
if(!in_spec_file)
Expand Down Expand Up @@ -438,17 +438,17 @@ void gcc_cmdlinet::parse_specs_line(const std::string &line, bool in_spec_file)
assert(!line.empty());
assert(line[0]!=' ' && line[0]!='\t');

argst args;
argst args_from_specs;

for(std::string::size_type arg_start=0, arg_end=0;
arg_end!=std::string::npos;
arg_start=line.find_first_not_of("\t ", arg_end))
{
arg_end=line.find_first_of("\t ", arg_start);
args.push_back(line.substr(arg_start, arg_end-arg_start));
args_from_specs.push_back(line.substr(arg_start, arg_end - arg_start));
}

parse_arguments(args, in_spec_file);
parse_arguments(args_from_specs, in_spec_file);
}

/// Parse GCC spec files https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html
Expand Down
2 changes: 1 addition & 1 deletion src/goto-cc/gcc_cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class gcc_cmdlinet:public goto_cc_cmdlinet
protected:
typedef std::vector<std::string> argst;

bool parse_arguments(const argst &args, bool in_spec_file);
bool parse_arguments(const argst &args_to_parse, bool in_spec_file);
void parse_specs();
void parse_specs_line(const std::string &line, bool in_spec_file);
};
Expand Down
7 changes: 3 additions & 4 deletions src/goto-cc/gcc_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void gcc_versiont::get(const std::string &executable)
out << "default_cxx_standard __cplusplus\n";
}

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

if(result >= 0)
{
std::ifstream in(cpp_out());
std::string line;
std::ifstream in2(cpp_out());

while(!in.fail() && std::getline(in, line))
while(!in2.fail() && std::getline(in2, line))
{
if(line.empty() || line[0] == '#')
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-cc/linker_script_merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int linker_script_merget::add_linker_script_definitions()
return fail;
}

fail = compiler.write_object_file(goto_binary, original_goto_model);
fail = compiler.write_bin_object_file(goto_binary, original_goto_model);

if(fail!=0)
error() << "Could not write linkerscript-augmented binary" << eom;
Expand Down
50 changes: 24 additions & 26 deletions src/goto-cc/ms_cl_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,46 @@ const char *non_ms_cl_options[]=
nullptr
};

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

if(options[i]=="--verbosity" ||
options[i]=="--function")
if(arguments[i] == "--verbosity" || arguments[i] == "--function")
{
if(i<options.size()-1)
if(i < arguments.size() - 1)
{
set(options[i], options[i+1]);
set(arguments[i], arguments[i + 1]);
i++; // skip ahead
}
}
}
else if(!options[i].empty() && options[i][0]=='@')
else if(!arguments[i].empty() && arguments[i][0] == '@')
{
// potentially recursive
process_response_file(
std::string(options[i], 1, std::string::npos));
process_response_file(std::string(arguments[i], 1, std::string::npos));
}
else if(options[i]=="/link" ||
options[i]=="-link")
else if(arguments[i] == "/link" || arguments[i] == "-link")
{
// anything that follows goes to the linker
i=options.size()-1;
i = arguments.size() - 1;
}
else if(options[i].size()==2 &&
(options[i]=="/D" || options[i]=="-D") &&
i!=options.size()-1)
else if(
arguments[i].size() == 2 &&
(arguments[i] == "/D" || arguments[i] == "-D") &&
i != arguments.size() - 1)
{
// this requires special treatment, as you can do "/D something"
std::string tmp="/D"+options[i+1];
std::string tmp = "/D" + arguments[i + 1];
i++;
process_cl_option(tmp);
}
else
process_cl_option(options[i]);
process_cl_option(arguments[i]);
}

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

std::vector<std::string> options;
std::vector<std::string> arguments;

// skip argv[0]
for(int i=1; i<argc; i++)
options.push_back(argv[i]);
arguments.push_back(argv[i]);

return parse(options);
return parse(arguments);
}

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

std::vector<std::string> options;
std::vector<std::string> arguments;
std::string option;
bool in_quotes=false;
for(std::size_t i=0; i<line.size(); i++)
Expand All @@ -252,7 +250,7 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line)
if(ch==' ' && !in_quotes)
{
if(!option.empty())
options.push_back(option);
arguments.push_back(option);
option.clear();
}
else if(ch=='"')
Expand All @@ -264,9 +262,9 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line)
}

if(!option.empty())
options.push_back(option);
arguments.push_back(option);

parse(options);
parse(arguments);
}

/// \return none
Expand Down
Loading