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 
16 std::string source_locationt::as_string(bool print_cwd) const
17 {
18  std::string dest;
19 
20  const irep_idt &file=get_file();
21  const irep_idt &line=get_line();
22  const irep_idt &column=get_column();
23  const irep_idt &function=get_function();
24  const irep_idt &bytecode=get_java_bytecode_index();
25 
26  if(!file.empty())
27  {
28  if(dest!="")
29  dest+=' ';
30  dest+="file ";
31  if(print_cwd)
32  dest+=
34  else
35  dest+=id2string(file);
36  }
37  if(!line.empty())
38  {
39  if(dest!="")
40  dest+=' ';
41  dest+="line "+id2string(line);
42  }
43  if(!column.empty())
44  {
45  if(dest!="")
46  dest+=' ';
47  dest+="column "+id2string(column);
48  }
49  if(!function.empty())
50  {
51  if(dest!="")
52  dest+=' ';
53  dest+="function "+id2string(function);
54  }
55  if(!bytecode.empty())
56  {
57  if(dest!="")
58  dest+=' ';
59  dest+="bytecode-index "+id2string(bytecode);
60  }
61 
62  return dest;
63 }
64 
66 {
68  {
69  if(get(it->first).empty())
70  set(it->first, it->second);
71  }
72 }
73 
74 std::ostream &operator << (
75  std::ostream &out,
76  const source_locationt &source_location)
77 {
78  if(source_location.is_nil())
79  return out;
80  out << source_location.as_string();
81  return out;
82 }
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
Definition: file_util.cpp:134
const irep_idt & get_working_directory() const
bool is_nil() const
Definition: irep.h:172
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
const irep_idt & get_function() 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
std::ostream & operator<<(std::ostream &out, const source_locationt &source_location)
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
named_subt & get_named_sub()
Definition: irep.h:319
const irep_idt & get_file() const
const irep_idt & get_java_bytecode_index() const
bool empty() const
Definition: dstring.h:73
Definition: kdev_t.h:19