cprover
Loading...
Searching...
No Matches
source_location.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: 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
16bool 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
24std::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{
75 for(const auto &irep_entry : from.get_named_sub())
76 {
77 if(get(irep_entry.first).empty())
78 set(irep_entry.first, irep_entry.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
95std::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 has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
bool empty() const
Definition dstring.h:90
const irep_idt & get(const irep_idt &name) const
Definition irep.cpp:44
void set(const irep_idt &name, const irep_idt &value)
Definition irep.h:420
bool is_nil() const
Definition irep.h:376
named_subt & get_named_sub()
Definition irep.h:458
void merge(const source_locationt &from)
Set all unset source-location fields in this object to their values in 'from'.
optionalt< std::string > full_path() const
Get a path to the file, including working directory.
bool is_built_in() const
const irep_idt & get_java_bytecode_index() const
const irep_idt & get_column() const
const irep_idt & get_function() const
const irep_idt & get_working_directory() const
const irep_idt & get_file() const
const irep_idt & get_line() const
std::string as_string() const
bool has_prefix(const std::string &s, const std::string &prefix)
Definition converter.cpp:13
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
const std::string & id2string(const irep_idt &d)
Definition irep.h:47
nonstd::optional< T > optionalt
Definition optional.h:35
std::ostream & operator<<(std::ostream &out, const source_locationt &source_location)
Definition kdev_t.h:19