cprover
source_location.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "source_location.h"
10 
11 #include <ostream>
12 
13 #include "file_util.h"
14 #include "prefix.h"
15 
16 bool source_locationt::is_built_in(const std::string &s)
17 {
18  std::string built_in1 = "<built-in-"; // "<built-in-additions>";
19  std::string built_in2 = "<builtin-"; // "<builtin-architecture-strings>";
20  return has_prefix(s, built_in1) || has_prefix(s, built_in2);
21 }
22 
24 std::string source_locationt::as_string(bool print_cwd) const
25 {
26  std::string dest;
27 
28  const irep_idt &file=get_file();
29  const irep_idt &line=get_line();
30  const irep_idt &column=get_column();
31  const irep_idt &function=get_function();
32  const irep_idt &bytecode=get_java_bytecode_index();
33 
34  if(!file.empty())
35  {
36  if(!dest.empty())
37  dest+=' ';
38  dest+="file ";
39  if(print_cwd)
40  dest+=
42  else
43  dest+=id2string(file);
44  }
45  if(!line.empty())
46  {
47  if(!dest.empty())
48  dest+=' ';
49  dest+="line "+id2string(line);
50  }
51  if(!column.empty())
52  {
53  if(!dest.empty())
54  dest+=' ';
55  dest+="column "+id2string(column);
56  }
57  if(!function.empty())
58  {
59  if(!dest.empty())
60  dest+=' ';
61  dest+="function "+id2string(function);
62  }
63  if(!bytecode.empty())
64  {
65  if(!dest.empty())
66  dest+=' ';
67  dest+="bytecode-index "+id2string(bytecode);
68  }
69 
70  return dest;
71 }
72 
74 {
76  {
77  if(get(it->first).empty())
78  set(it->first, it->second);
79  }
80 }
81 
86 {
87  const auto file = id2string(get_file());
88 
89  if(file.empty() || is_built_in(file))
90  return {};
91 
93 }
94 
95 std::ostream &operator << (
96  std::ostream &out,
97  const source_locationt &source_location)
98 {
99  if(source_location.is_nil())
100  return out;
101  out << source_location.as_string();
102  return out;
103 }
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
Definition: file_util.cpp:159
const irep_idt & get_working_directory() const
bool is_nil() const
Definition: irep.h:398
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
const irep_idt & get_function() const
bool is_built_in() const
std::string as_string() const
#define forall_named_irep(it, irep)
Definition: irep.h:70
const irep_idt & get_column() const
void merge(const source_locationt &from)
Set all unset source-location fields in this object to their values in &#39;from&#39;.
const irep_idt & get_line() const
nonstd::optional< T > optionalt
Definition: optional.h:35
std::ostream & operator<<(std::ostream &out, const source_locationt &source_location)
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:36
named_subt & get_named_sub()
Definition: irep.h:479
const irep_idt & get_file() const
optionalt< std::string > full_path() const
Get a path to the file, including working directory.
const irep_idt & get_java_bytecode_index() const
bool empty() const
Definition: dstring.h:88
Definition: kdev_t.h:19