Skip to content

Commit

Permalink
Merge pull request #8525 from diffblue/cmdline-value_opt
Browse files Browse the repository at this point in the history
`cmdlinet`: add `value_opt` methods
  • Loading branch information
tautschnig authored Dec 10, 2024
2 parents 7eef276 + 3c9d699 commit e186314
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/goto-cc/armcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ int armcc_modet::doit()
}

// armcc's default is .o
if(cmdline.isset("default_extension="))
compiler.object_file_extension=
cmdline.get_value("default_extension=");
else
compiler.object_file_extension="o";
compiler.object_file_extension =
cmdline.value_opt("default_extension=").value_or("o");

// note that ARM's default is "unsigned_chars",
// in contrast to gcc's default!
Expand Down
5 changes: 1 addition & 4 deletions src/goto-cc/gcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,10 +982,7 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
else
{
// -c is not given
if(cmdline.isset('o'))
output_files.push_back(cmdline.get_value('o'));
else
output_files.push_back("a.out");
output_files.push_back(cmdline.value_opt('o').value_or("a.out"));
}

if(output_files.empty() ||
Expand Down
8 changes: 4 additions & 4 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ int goto_instrument_parse_optionst::doit()

if(cmdline.isset("log"))
{
std::string filename=cmdline.get_value("log");
bool have_file=!filename.empty() && filename!="-";
std::string filename = cmdline.value_opt("log").value_or("-");
bool have_file = filename != "-";

jsont result=goto_unwind.output_log_json();

Expand Down Expand Up @@ -1319,8 +1319,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
}
else
{
std::string filename=cmdline.get_value("log");
bool have_file=!filename.empty() && filename!="-";
std::string filename = cmdline.value_opt("log").value_or("-");
bool have_file = filename != "-";

jsont result = goto_function_inline_and_log(
goto_model, function, ui_message_handler, true, caching);
Expand Down
14 changes: 12 additions & 2 deletions src/util/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ bool cmdlinet::isset(const char *option) const
}

std::string cmdlinet::get_value(char option) const
{
return value_opt(option).value_or("");
}

std::optional<std::string> cmdlinet::value_opt(char option) const
{
auto i=getoptnr(option);

if(i.has_value() && !options[*i].values.empty())
return options[*i].values.front();
else
return "";
return {};
}

void cmdlinet::set(const std::string &option, bool value)
Expand Down Expand Up @@ -97,13 +102,18 @@ const std::list<std::string> &cmdlinet::get_values(char option) const
}

std::string cmdlinet::get_value(const char *option) const
{
return value_opt(option).value_or("");
}

std::optional<std::string> cmdlinet::value_opt(const char *option) const
{
auto i=getoptnr(option);

if(i.has_value() && !options[*i].values.empty())
return options[*i].values.front();
else
return "";
return {};
}

const std::list<std::string> &cmdlinet::get_values(
Expand Down
3 changes: 3 additions & 0 deletions src/util/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class cmdlinet
std::string get_value(char option) const;
std::string get_value(const char *option) const;

std::optional<std::string> value_opt(char option) const;
std::optional<std::string> value_opt(const char *option) const;

const std::list<std::string> &get_values(const std::string &option) const;
const std::list<std::string> &get_values(char option) const;

Expand Down

0 comments on commit e186314

Please sign in to comment.