cprover
Loading...
Searching...
No Matches
source_lines.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Source Lines
4
5Author: Mark R. Tuttle
6
7\*******************************************************************/
8
11
12#include "source_lines.h"
13
15#include <util/range.h>
17#include <util/string2int.h>
18#include <util/string_utils.h>
19
20#include <sstream>
21
23{
24 if(loc.get_file().empty() || loc.is_built_in())
25 return;
26 const std::string &file = id2string(loc.get_file());
27
28 // the function of a source location can fail to be set
29 const std::string &func = id2string(loc.get_function());
30
31 if(loc.get_line().empty())
32 return;
33 std::size_t line = safe_string2size_t(id2string(loc.get_line()));
34
35 block_lines[file + ":" + func].insert(line);
36}
37
38std::string source_linest::to_string() const
39{
40 std::stringstream ss;
41 const auto map =
42 make_range(block_lines).map([&](const block_linest::value_type &pair) {
43 std::vector<unsigned> line_numbers(
44 pair.second.begin(), pair.second.end());
45 return pair.first + ':' + format_number_range(line_numbers);
46 });
47 join_strings(ss, map.begin(), map.end(), "; ");
48 return ss.str();
49}
bool empty() const
Definition dstring.h:88
void insert(const source_locationt &loc)
Insert a line (a source location) into the set of lines.
block_linest block_lines
std::string to_string() const
Construct a string representing the set of lines.
const irep_idt & get_function() const
const irep_idt & get_file() const
const irep_idt & get_line() const
static bool is_built_in(const std::string &s)
std::string format_number_range(const std::vector< unsigned > &input_numbers)
create shorter representation for output
Format vector of numbers into a compressed range.
const std::string & id2string(const irep_idt &d)
Definition irep.h:47
Ranges: pair of begin and end iterators, which can be initialized from containers,...
ranget< iteratort > make_range(iteratort begin, iteratort end)
Definition range.h:524
Set of source code lines contributing to a basic block.
std::size_t safe_string2size_t(const std::string &str, int base)
Stream & join_strings(Stream &&os, const It b, const It e, const Delimiter &delimiter, TransformFunc &&transform_func)
Prints items to an stream, separated by a constant delimiter.
Definition kdev_t.h:19