Skip to content

Commit e186314

Browse files
authored
Merge pull request #8525 from diffblue/cmdline-value_opt
`cmdlinet`: add `value_opt` methods
2 parents 7eef276 + 3c9d699 commit e186314

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/goto-cc/armcc_mode.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,8 @@ int armcc_modet::doit()
105105
}
106106

107107
// armcc's default is .o
108-
if(cmdline.isset("default_extension="))
109-
compiler.object_file_extension=
110-
cmdline.get_value("default_extension=");
111-
else
112-
compiler.object_file_extension="o";
108+
compiler.object_file_extension =
109+
cmdline.value_opt("default_extension=").value_or("o");
113110

114111
// note that ARM's default is "unsigned_chars",
115112
// in contrast to gcc's default!

src/goto-cc/gcc_mode.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,7 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
982982
else
983983
{
984984
// -c is not given
985-
if(cmdline.isset('o'))
986-
output_files.push_back(cmdline.get_value('o'));
987-
else
988-
output_files.push_back("a.out");
985+
output_files.push_back(cmdline.value_opt('o').value_or("a.out"));
989986
}
990987

991988
if(output_files.empty() ||

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ int goto_instrument_parse_optionst::doit()
241241

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

247247
jsont result=goto_unwind.output_log_json();
248248

@@ -1319,8 +1319,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
13191319
}
13201320
else
13211321
{
1322-
std::string filename=cmdline.get_value("log");
1323-
bool have_file=!filename.empty() && filename!="-";
1322+
std::string filename = cmdline.value_opt("log").value_or("-");
1323+
bool have_file = filename != "-";
13241324

13251325
jsont result = goto_function_inline_and_log(
13261326
goto_model, function, ui_message_handler, true, caching);

src/util/cmdline.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ bool cmdlinet::isset(const char *option) const
4646
}
4747

4848
std::string cmdlinet::get_value(char option) const
49+
{
50+
return value_opt(option).value_or("");
51+
}
52+
53+
std::optional<std::string> cmdlinet::value_opt(char option) const
4954
{
5055
auto i=getoptnr(option);
5156

5257
if(i.has_value() && !options[*i].values.empty())
5358
return options[*i].values.front();
5459
else
55-
return "";
60+
return {};
5661
}
5762

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

99104
std::string cmdlinet::get_value(const char *option) const
105+
{
106+
return value_opt(option).value_or("");
107+
}
108+
109+
std::optional<std::string> cmdlinet::value_opt(const char *option) const
100110
{
101111
auto i=getoptnr(option);
102112

103113
if(i.has_value() && !options[*i].values.empty())
104114
return options[*i].values.front();
105115
else
106-
return "";
116+
return {};
107117
}
108118

109119
const std::list<std::string> &cmdlinet::get_values(

src/util/cmdline.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class cmdlinet
7676
std::string get_value(char option) const;
7777
std::string get_value(const char *option) const;
7878

79+
std::optional<std::string> value_opt(char option) const;
80+
std::optional<std::string> value_opt(const char *option) const;
81+
7982
const std::list<std::string> &get_values(const std::string &option) const;
8083
const std::list<std::string> &get_values(char option) const;
8184

0 commit comments

Comments
 (0)