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 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
source_locationt::get_function
const irep_idt & get_function() const
Definition: source_location.h:56
source_locationt::as_string
std::string as_string() const
Definition: source_location.h:26
file_util.h
operator<<
std::ostream & operator<<(std::ostream &out, const source_locationt &source_location)
Definition: source_location.cpp:95
prefix.h
file
Definition: kdev_t.h:19
source_locationt::get_column
const irep_idt & get_column() const
Definition: source_location.h:51
source_locationt::is_built_in
bool is_built_in() const
Definition: source_location.h:179
source_locationt::get_line
const irep_idt & get_line() const
Definition: source_location.h:46
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
irept::get_named_sub
named_subt & get_named_sub()
Definition: irep.h:479
concat_dir_file
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
Definition: file_util.cpp:159
source_locationt::merge
void merge(const source_locationt &from)
Set all unset source-location fields in this object to their values in 'from'.
Definition: source_location.cpp:73
forall_named_irep
#define forall_named_irep(it, irep)
Definition: irep.h:70
source_location.h
irept::is_nil
bool is_nil() const
Definition: irep.h:398
dstringt::empty
bool empty() const
Definition: dstring.h:88
source_locationt::full_path
optionalt< std::string > full_path() const
Get a path to the file, including working directory.
Definition: source_location.cpp:85
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
source_locationt
Definition: source_location.h:19
source_locationt::get_java_bytecode_index
const irep_idt & get_java_bytecode_index() const
Definition: source_location.h:81
irept::get
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:51
irept::set
void set(const irep_namet &name, const irep_idt &value)
Definition: irep.h:442
source_locationt::get_file
const irep_idt & get_file() const
Definition: source_location.h:36
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
source_locationt::get_working_directory
const irep_idt & get_working_directory() const
Definition: source_location.h:41