CBMC
linking_class.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: ANSI-C Linking
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_LINKING_LINKING_CLASS_H
13 #define CPROVER_LINKING_LINKING_CLASS_H
14 
15 #include <util/namespace.h>
16 #include <util/rename_symbol.h>
17 #include <util/replace_symbol.h>
18 #include <util/std_expr.h>
19 #include <util/symbol.h>
20 #include <util/typecheck.h>
21 
23 {
24 private:
25  bool replace_symbol_expr(symbol_exprt &dest) const override;
26 };
27 
28 class linkingt:public typecheckt
29 {
30 public:
32  symbol_table_baset &_main_symbol_table,
33  const symbol_table_baset &_src_symbol_table,
34  message_handlert &_message_handler)
35  : typecheckt(_message_handler),
36  main_symbol_table(_main_symbol_table),
37  src_symbol_table(_src_symbol_table),
38  ns(_main_symbol_table)
39  {
40  }
41 
42  virtual void typecheck();
43 
46 
47 protected:
49  const symbolt &old_symbol,
50  const symbolt &new_symbol);
51 
53  const symbolt &old_symbol,
54  const symbolt &new_symbol);
55 
57  const symbolt &old_symbol,
58  const symbolt &new_symbol)
59  {
60  if(new_symbol.is_type)
61  return needs_renaming_type(old_symbol, new_symbol);
62  else
63  return needs_renaming_non_type(old_symbol, new_symbol);
64  }
65 
66  void do_type_dependencies(std::unordered_set<irep_idt> &);
67 
68  std::unordered_map<irep_idt, irep_idt>
69  rename_symbols(const std::unordered_set<irep_idt> &needs_to_be_renamed);
70  void copy_symbols(const std::unordered_map<irep_idt, irep_idt> &);
71 
73  symbolt &old_symbol,
74  symbolt &new_symbol);
75 
77  symbolt &old_symbol,
78  symbolt &new_symbol);
79 
81  symbolt &old_symbol,
82  symbolt &new_symbol);
83 
84  bool adjust_object_type(
85  const symbolt &old_symbol,
86  const symbolt &new_symbol,
87  bool &set_to_new);
88 
90  {
92  const symbolt &_old_symbol,
93  const symbolt &_new_symbol):
94  old_symbol(_old_symbol),
95  new_symbol(_new_symbol),
96  set_to_new(false)
97  {
98  }
99 
103  std::unordered_set<irep_idt> o_symbols;
104  std::unordered_set<irep_idt> n_symbols;
105  };
106 
108  const typet &type1,
109  const typet &type2,
110  adjust_type_infot &info);
111 
113  symbolt &old_symbol,
114  const symbolt &new_symbol);
115 
116  std::string expr_to_string(
117  const irep_idt &identifier,
118  const exprt &expr) const;
119 
120  std::string type_to_string(
121  const irep_idt &identifier,
122  const typet &type) const;
123 
124  std::string type_to_string_verbose(
125  const symbolt &symbol,
126  const typet &type) const;
127 
129  const symbolt &symbol) const
130  {
131  return type_to_string_verbose(symbol, symbol.type);
132  }
133 
135  const symbolt &old_symbol,
136  const symbolt &new_symbol,
137  const typet &type1,
138  const typet &type2,
139  unsigned depth,
140  exprt &conflict_path);
141 
143  const symbolt &old_symbol,
144  const symbolt &new_symbol,
145  const typet &type1,
146  const typet &type2)
147  {
148  symbol_exprt conflict_path = symbol_exprt::typeless(ID_C_this);
150  old_symbol,
151  new_symbol,
152  type1,
153  type2,
154  10, // somewhat arbitrary limit
155  conflict_path);
156  }
157 
158  void link_error(
159  const symbolt &old_symbol,
160  const symbolt &new_symbol,
161  const std::string &msg);
162 
163  void link_warning(
164  const symbolt &old_symbol,
165  const symbolt &new_symbol,
166  const std::string &msg);
167 
168  void show_struct_diff(
169  const struct_typet &old_type,
170  const struct_typet &new_type);
171 
174 
176 
177  // X -> Y iff Y uses X for new symbol type IDs X and Y
178  typedef std::unordered_map<irep_idt, std::unordered_set<irep_idt>> used_byt;
179 
180  irep_idt rename(const irep_idt &);
181 
182  // the new IDs created by renaming
183  std::unordered_set<irep_idt> renamed_ids;
184 };
185 
186 #endif // CPROVER_LINKING_LINKING_CLASS_H
linkingt::needs_renaming_type
bool needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:1238
linkingt::adjust_object_type
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
Definition: linking.cpp:999
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
casting_replace_symbolt
Definition: linking_class.h:22
linkingt::adjust_type_infot
Definition: linking_class.h:89
linkingt::needs_renaming
bool needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking_class.h:56
linkingt::typecheck
virtual void typecheck()
Definition: linking.cpp:1439
linkingt::adjust_type_infot::new_symbol
const symbolt & new_symbol
Definition: linking_class.h:101
linkingt::object_type_updates
casting_replace_symbolt object_type_updates
Definition: linking_class.h:45
typet
The type of an expression, extends irept.
Definition: type.h:28
linkingt::type_to_string_verbose
std::string type_to_string_verbose(const symbolt &symbol, const typet &type) const
Definition: linking.cpp:77
symbolt::type
typet type
Type of symbol.
Definition: symbol.h:31
symbol_exprt::typeless
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
Definition: std_expr.h:132
replace_symbol.h
linkingt::type_to_string
std::string type_to_string(const irep_idt &identifier, const typet &type) const
Definition: linking.cpp:56
linkingt::needs_renaming_non_type
bool needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:456
exprt
Base class for all expressions.
Definition: expr.h:55
linkingt::rename_symbols
std::unordered_map< irep_idt, irep_idt > rename_symbols(const std::unordered_set< irep_idt > &needs_to_be_renamed)
Definition: linking.cpp:1340
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:112
rename_symbol.h
namespace.h
linkingt::link_warning
void link_warning(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Definition: linking.cpp:414
linkingt::type_to_string_verbose
std::string type_to_string_verbose(const symbolt &symbol) const
Definition: linking_class.h:128
linkingt::duplicate_code_symbol
void duplicate_code_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:470
linkingt::main_symbol_table
symbol_table_baset & main_symbol_table
Definition: linking_class.h:172
linkingt::copy_symbols
void copy_symbols(const std::unordered_map< irep_idt, irep_idt > &)
Definition: linking.cpp:1373
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
linkingt::adjust_object_type_rec
bool adjust_object_type_rec(const typet &type1, const typet &type2, adjust_type_infot &info)
Definition: linking.cpp:807
linkingt::used_byt
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > used_byt
Definition: linking_class.h:178
linkingt::show_struct_diff
void show_struct_diff(const struct_typet &old_type, const struct_typet &new_type)
linkingt::do_type_dependencies
void do_type_dependencies(std::unordered_set< irep_idt > &)
Definition: linking.cpp:1295
typecheck.h
symbol_table_baset
The symbol table base class interface.
Definition: symbol_table_base.h:21
linkingt::src_symbol_table
const symbol_table_baset & src_symbol_table
Definition: linking_class.h:173
casting_replace_symbolt::replace_symbol_expr
bool replace_symbol_expr(symbol_exprt &dest) const override
Definition: linking.cpp:29
linkingt::linkingt
linkingt(symbol_table_baset &_main_symbol_table, const symbol_table_baset &_src_symbol_table, message_handlert &_message_handler)
Definition: linking_class.h:31
linkingt
Definition: linking_class.h:28
linkingt::duplicate_non_type_symbol
void duplicate_non_type_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:1104
symbol.h
Symbol table entry.
message_handlert
Definition: message.h:27
linkingt::detailed_conflict_report_rec
void detailed_conflict_report_rec(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2, unsigned depth, exprt &conflict_path)
Definition: linking.cpp:129
linkingt::duplicate_object_symbol
void duplicate_object_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:1014
linkingt::expr_to_string
std::string expr_to_string(const irep_idt &identifier, const exprt &expr) const
Definition: linking.cpp:49
linkingt::rename_symbol
rename_symbolt rename_symbol
Definition: linking_class.h:44
linkingt::link_error
void link_error(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Definition: linking.cpp:397
struct_typet
Structure type, corresponds to C style structs.
Definition: std_types.h:230
linkingt::adjust_type_infot::set_to_new
bool set_to_new
Definition: linking_class.h:102
linkingt::duplicate_type_symbol
void duplicate_type_symbol(symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:1143
symbolt
Symbol table entry.
Definition: symbol.h:27
symbolt::is_type
bool is_type
Definition: symbol.h:61
rename_symbolt
Definition: rename_symbol.h:25
linkingt::detailed_conflict_report
void detailed_conflict_report(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2)
Definition: linking_class.h:142
linkingt::rename
irep_idt rename(const irep_idt &)
Definition: linking.cpp:432
linkingt::renamed_ids
std::unordered_set< irep_idt > renamed_ids
Definition: linking_class.h:183
linkingt::adjust_type_infot::n_symbols
std::unordered_set< irep_idt > n_symbols
Definition: linking_class.h:104
linkingt::adjust_type_infot::old_symbol
const symbolt & old_symbol
Definition: linking_class.h:100
typecheckt
Definition: typecheck.h:15
linkingt::ns
namespacet ns
Definition: linking_class.h:175
std_expr.h
linkingt::adjust_type_infot::o_symbols
std::unordered_set< irep_idt > o_symbols
Definition: linking_class.h:103
linkingt::adjust_type_infot::adjust_type_infot
adjust_type_infot(const symbolt &_old_symbol, const symbolt &_new_symbol)
Definition: linking_class.h:91
replace_symbolt
Replace a symbol expression by a given expression.
Definition: replace_symbol.h:27