Skip to content

Use cmdlinet::get_comma_separated_values where possible #6996

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
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
5 changes: 4 additions & 1 deletion jbmc/src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ void jbmc_parse_optionst::get_command_line_options(optionst &options)
options.set_option("depth", cmdline.get_value("depth"));

if(cmdline.isset("unwindset"))
options.set_option("unwindset", cmdline.get_value("unwindset"));
{
options.set_option(
"unwindset", cmdline.get_comma_separated_values("unwindset"));
}

// constant propagation
if(cmdline.isset("no-propagation"))
Expand Down
2 changes: 1 addition & 1 deletion regression/goto-instrument/unwind-unwindset4/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE
main.c
--unwindset main.0:10,f.0:10,g.0:10,g.1:10 --unwinding-assertions
--unwindset main.0:10,f.0:10 --unwindset g.0:10,g.1:10 --unwinding-assertions
Copy link

@chris-ryder chris-ryder Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting here, but more a comment for the PR and/or commit descriptions... But I was having a slightly hard time groking the intent of this PR until I saw this example here in the test case 👍 - So perhaps a clearer description might be something like:

Allow command line options that take values consisting of comma separated list to be
repeated and accumulated into a single list. For instance, making `--foo A,B,C,D` be
semantically equivalent to `--foo A,B --foo C,D`

Or words to that affect... not sure if its clearer or not to other people... but at least having the example in the description would be a big help :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I shamelessly copied this into the commit message!

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
Expand Down
2 changes: 1 addition & 1 deletion regression/memory-analyzer/pointer_05/test.desc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CORE
main.gb
--breakpoint checkpoint --symbols p1,x,p2
--breakpoint checkpoint --symbols p1,x --symbols p2
^EXIT=0$
^SIGNAL=0$
5 changes: 4 additions & 1 deletion src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
}

if(cmdline.isset("unwindset"))
options.set_option("unwindset", cmdline.get_values("unwindset"));
{
options.set_option(
"unwindset", cmdline.get_comma_separated_values("unwindset"));
}

// constant propagation
if(cmdline.isset("no-propagation"))
Expand Down
3 changes: 2 additions & 1 deletion src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ int goto_instrument_parse_optionst::doit()
if(unwindset_given)
{
unwindset.parse_unwindset(
cmdline.get_values("unwindset"), ui_message_handler);
cmdline.get_comma_separated_values("unwindset"),
ui_message_handler);
}

bool unwinding_assertions=cmdline.isset("unwinding-assertions");
Expand Down
8 changes: 1 addition & 7 deletions src/goto-instrument/unwindset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,7 @@ void unwindsett::parse_unwindset(
message_handlert &message_handler)
{
for(auto &element : unwindset)
{
std::vector<std::string> unwindset_elements =
split_string(element, ',', true, true);

for(auto &element : unwindset_elements)
parse_unwindset_one_loop(element, message_handler);
}
parse_unwindset_one_loop(element, message_handler);
}

optionalt<unsigned>
Expand Down
3 changes: 2 additions & 1 deletion src/memory-analyzer/analyze_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ mp_integer gdb_value_extractort::get_type_size(const typet &type) const
return *maybe_size / CHAR_BIT;
}

void gdb_value_extractort::analyze_symbols(const std::vector<irep_idt> &symbols)
void gdb_value_extractort::analyze_symbols(
const std::list<std::string> &symbols)
{
// record addresses of given symbols
for(const auto &id : symbols)
Expand Down
2 changes: 1 addition & 1 deletion src/memory-analyzer/analyze_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class gdb_value_extractort
/// \ref symbol_exprt (via the `values` map) and then call
/// \ref analyze_symbol on it.
/// \param symbols: names of symbols to be analysed
void analyze_symbols(const std::vector<irep_idt> &symbols);
void analyze_symbols(const std::list<std::string> &symbols);

/// Get memory snapshot as C code
/// \return converted block of code with the collected assignments
Expand Down
12 changes: 2 additions & 10 deletions src/memory-analyzer/memory_analyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Author: Malte Mues <[email protected]>
#include <util/config.h>
#include <util/exit_codes.h>
#include <util/message.h>
#include <util/string_utils.h>
#include <util/version.h>

#include <goto-programs/goto_model.h>
Expand Down Expand Up @@ -103,9 +102,6 @@ int memory_analyzer_parse_optionst::doit()

std::string binary = cmdline.args.front();

const std::string symbol_list(cmdline.get_value("symbols"));
std::vector<std::string> result = split_string(symbol_list, ',', true, true);

auto opt = read_goto_binary(binary, ui_message_handler);

if(!opt.has_value())
Expand All @@ -131,12 +127,8 @@ int memory_analyzer_parse_optionst::doit()
gdb_value_extractor.run_gdb_to_breakpoint(breakpoint);
}

std::vector<irep_idt> result_ids(result.size());
std::transform(
result.begin(), result.end(), result_ids.begin(), [](std::string &name) {
return irep_idt{name};
});
gdb_value_extractor.analyze_symbols(result_ids);
gdb_value_extractor.analyze_symbols(
cmdline.get_comma_separated_values("symbols"));

std::ofstream file;

Expand Down