cprover
source_location.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_SOURCE_LOCATION_H
11 #define CPROVER_UTIL_SOURCE_LOCATION_H
12 
13 #include "invariant.h"
14 #include "irep.h"
15 #include "optional.h"
16 
17 #include <string>
18 
19 class source_locationt:public irept
20 {
21 public:
23  {
24  }
25 
26  std::string as_string() const
27  {
28  return as_string(false);
29  }
30 
31  std::string as_string_with_cwd() const
32  {
33  return as_string(true);
34  }
35 
36  const irep_idt &get_file() const
37  {
38  return get(ID_file);
39  }
40 
42  {
43  return get(ID_working_directory);
44  }
45 
46  const irep_idt &get_line() const
47  {
48  return get(ID_line);
49  }
50 
51  const irep_idt &get_column() const
52  {
53  return get(ID_column);
54  }
55 
56  const irep_idt &get_function() const
57  {
58  return get(ID_function);
59  }
60 
61  const irep_idt &get_property_id() const
62  {
63  return get(ID_property_id);
64  }
65 
67  {
68  return get(ID_property_class);
69  }
70 
71  const irep_idt &get_comment() const
72  {
73  return get(ID_comment);
74  }
75 
76  const irep_idt &get_case_number() const
77  {
78  return get(ID_switch_case_number);
79  }
80 
82  {
83  return get(ID_java_bytecode_index);
84  }
85 
87  {
88  return get(ID_basic_block_covered_lines);
89  }
90 
92  {
93  return get(ID_basic_block_source_lines);
94  }
95 
96  void set_file(const irep_idt &file)
97  {
98  set(ID_file, file);
99  }
100 
102  {
103  set(ID_working_directory, cwd);
104  }
105 
106  void set_line(const irep_idt &line)
107  {
108  set(ID_line, line);
109  }
110 
111  void set_line(unsigned line)
112  {
113  set(ID_line, line);
114  }
115 
116  void set_column(const irep_idt &column)
117  {
118  set(ID_column, column);
119  }
120 
121  void set_column(unsigned column)
122  {
123  set(ID_column, column);
124  }
125 
126  void set_function(const irep_idt &function)
127  {
128  set(ID_function, function);
129  }
130 
131  void set_property_id(const irep_idt &property_id)
132  {
133  set(ID_property_id, property_id);
134  }
135 
136  void set_property_class(const irep_idt &property_class)
137  {
138  set(ID_property_class, property_class);
139  }
140 
142  {
143  set(ID_comment, comment);
144  }
145 
146  // for switch case number
147  void set_case_number(const irep_idt &number)
148  {
149  set(ID_switch_case_number, number);
150  }
151 
153  {
154  set(ID_java_bytecode_index, index);
155  }
156 
157  void set_basic_block_covered_lines(const irep_idt &covered_lines)
158  {
159  return set(ID_basic_block_covered_lines, covered_lines);
160  }
161 
162  void set_basic_block_source_lines(const irep_idt &source_lines)
163  {
164  return set(ID_basic_block_source_lines, source_lines);
165  }
166 
167  void set_hide()
168  {
169  set(ID_hide, true);
170  }
171 
172  bool get_hide() const
173  {
174  return get_bool(ID_hide);
175  }
176 
177  static bool is_built_in(const std::string &s);
178 
179  bool is_built_in() const
180  {
181  return is_built_in(id2string(get_file()));
182  }
183 
186  void merge(const source_locationt &from);
187 
188  static const source_locationt &nil()
189  {
190  return static_cast<const source_locationt &>(get_nil_irep());
191  }
192 
194 
195  void add_pragma(const irep_idt &pragma)
196  {
197  add(ID_pragma).add(pragma);
198  }
199 
201  {
202  return find(ID_pragma).get_named_sub();
203  }
204 
205 protected:
206  std::string as_string(bool print_cwd) const;
207 };
208 
209 std::ostream &operator <<(std::ostream &, const source_locationt &);
210 
211 template <>
213 {
214  static std::string
215  diagnostics_as_string(const source_locationt &source_location)
216  {
217  return "source location: " + source_location.as_string();
218  }
219 };
220 
221 #endif // CPROVER_UTIL_SOURCE_LOCATION_H
const irept & get_nil_irep()
Definition: irep.cpp:26
const irep_idt & get_working_directory() const
void set_function(const irep_idt &function)
void set_case_number(const irep_idt &number)
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
void set_java_bytecode_index(const irep_idt &index)
void set_property_class(const irep_idt &property_class)
static const source_locationt & nil()
void set_comment(const irep_idt &comment)
void set_basic_block_source_lines(const irep_idt &source_lines)
const irep_idt & get_function() const
bool is_built_in() const
std::string as_string() const
const irept::named_subt & get_pragmas() const
const irep_idt & get_basic_block_source_lines() const
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:64
void add_pragma(const irep_idt &pragma)
void set_line(unsigned line)
const irep_idt & get_column() const
void set_property_id(const irep_idt &property_id)
void set_working_directory(const irep_idt &cwd)
const irep_idt & get_case_number() 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
Helper to give us some diagnostic in a usable form on assertion failure.
Definition: invariant.h:299
void set_file(const irep_idt &file)
nonstd::optional< T > optionalt
Definition: optional.h:35
void set_line(const irep_idt &line)
const irep_idt & get_basic_block_covered_lines() const
void set_column(const irep_idt &column)
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:381
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:36
bool get_hide() const
static std::string diagnostics_as_string(const source_locationt &source_location)
named_subt & get_named_sub()
Definition: irep.h:479
const irep_idt & get_file() const
std::string as_string_with_cwd() const
void set_column(unsigned column)
optionalt< std::string > full_path() const
Get a path to the file, including working directory.
irept & add(const irep_namet &name)
Definition: irep.cpp:113
const irep_idt & get_java_bytecode_index() const
const irep_idt & get_comment() const
const irep_idt & get_property_id() const
const irep_idt & get_property_class() const
std::ostream & operator<<(std::ostream &, const source_locationt &)
const irept & find(const irep_namet &name) const
Definition: irep.cpp:103
void set_basic_block_covered_lines(const irep_idt &covered_lines)
static std::string comment(const rw_set_baset::entryt &entry, bool write)
Definition: race_check.cpp:109
Definition: kdev_t.h:19