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 
21 #include <unordered_set>
22 
23 class message_handlert;
24 
26 {
27 public:
28  bool replace(exprt &dest) const override;
29 
30 private:
31  bool replace_symbol_expr(symbol_exprt &dest) const override;
32 };
33 
34 class linkingt
35 {
36 public:
38  symbol_table_baset &_main_symbol_table,
39  message_handlert &_message_handler)
40  : main_symbol_table(_main_symbol_table),
41  ns(_main_symbol_table),
42  message_handler(_message_handler)
43  {
44  }
45 
49  bool link(const symbol_table_baset &src_symbol_table);
50 
53 
54 protected:
55  enum renamingt
56  {
60  };
61 
62  renamingt
63  needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol);
64 
65  renamingt
66  needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol);
67 
68  renamingt needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
69  {
70  if(new_symbol.is_type)
71  return needs_renaming_type(old_symbol, new_symbol);
72  else
73  return needs_renaming_non_type(old_symbol, new_symbol);
74  }
75 
76  std::unordered_map<irep_idt, irep_idt> rename_symbols(
77  const symbol_table_baset &,
78  const std::unordered_set<irep_idt> &needs_to_be_renamed);
79  void copy_symbols(
80  const symbol_table_baset &,
81  const std::unordered_map<irep_idt, irep_idt> &);
82 
84  symbolt &old_symbol,
85  symbolt &new_symbol);
86 
88  symbolt &old_symbol,
89  symbolt &new_symbol);
90 
92  symbolt &old_symbol,
93  symbolt &new_symbol);
94 
95  bool adjust_object_type(
96  const symbolt &old_symbol,
97  const symbolt &new_symbol,
98  bool &set_to_new);
99 
101  {
103  const symbolt &_old_symbol,
104  const symbolt &_new_symbol):
105  old_symbol(_old_symbol),
106  new_symbol(_new_symbol),
107  set_to_new(false)
108  {
109  }
110 
114  std::unordered_set<irep_idt> o_symbols;
115  std::unordered_set<irep_idt> n_symbols;
116  };
117 
119  const typet &type1,
120  const typet &type2,
121  adjust_type_infot &info);
122 
124  symbolt &old_symbol,
125  const symbolt &new_symbol);
126 
127  std::string expr_to_string(
128  const irep_idt &identifier,
129  const exprt &expr) const;
130 
131  std::string type_to_string(
132  const irep_idt &identifier,
133  const typet &type) const;
134 
135  std::string type_to_string_verbose(
136  const symbolt &symbol,
137  const typet &type) const;
138 
140  const symbolt &symbol) const
141  {
142  return type_to_string_verbose(symbol, symbol.type);
143  }
144 
149  const symbolt &old_symbol,
150  const symbolt &new_symbol,
151  const typet &type1,
152  const typet &type2,
153  unsigned depth,
154  exprt &conflict_path);
155 
157  const symbolt &old_symbol,
158  const symbolt &new_symbol,
159  const typet &type1,
160  const typet &type2)
161  {
162  symbol_exprt conflict_path = symbol_exprt::typeless(ID_C_this);
164  old_symbol,
165  new_symbol,
166  type1,
167  type2,
168  10, // somewhat arbitrary limit
169  conflict_path);
170  }
171 
172  void link_error(
173  const symbolt &old_symbol,
174  const symbolt &new_symbol,
175  const std::string &msg);
176 
177  void link_warning(
178  const symbolt &old_symbol,
179  const symbolt &new_symbol,
180  const std::string &msg);
181 
183  const struct_typet &old_type,
184  const struct_typet &new_type);
185 
189 
190  irep_idt rename(const symbol_table_baset &, const irep_idt &);
191 
192  // the new IDs created by renaming
193  std::unordered_set<irep_idt> renamed_ids;
194 };
195 
196 #endif // CPROVER_LINKING_LINKING_CLASS_H
bool replace_symbol_expr(symbol_exprt &dest) const override
Definition: linking.cpp:94
bool replace(exprt &dest) const override
Definition: linking.cpp:29
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
std::unordered_map< irep_idt, irep_idt > rename_symbols(const symbol_table_baset &, const std::unordered_set< irep_idt > &needs_to_be_renamed)
Definition: linking.cpp:1440
void duplicate_non_type_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:1183
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
Definition: linking.cpp:1076
bool link(const symbol_table_baset &src_symbol_table)
Merges the symbol table src_symbol_table into main_symbol_table, renaming symbols from src_symbol_tab...
Definition: linking.cpp:1541
renamingt needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking_class.h:68
linkingt(symbol_table_baset &_main_symbol_table, message_handlert &_message_handler)
Definition: linking_class.h:37
std::string type_to_string_verbose(const symbolt &symbol) const
namespacet ns
bool adjust_object_type_rec(const typet &type1, const typet &type2, adjust_type_infot &info)
Definition: linking.cpp:884
rename_symbolt rename_main_symbol
Definition: linking_class.h:51
void copy_symbols(const symbol_table_baset &, const std::unordered_map< irep_idt, irep_idt > &)
Definition: linking.cpp:1475
irep_idt rename(const symbol_table_baset &, const irep_idt &)
Definition: linking.cpp:524
renamingt needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:1322
void show_struct_diff(const struct_typet &old_type, const struct_typet &new_type)
symbol_table_baset & main_symbol_table
std::string expr_to_string(const irep_idt &identifier, const exprt &expr) const
Definition: linking.cpp:120
void link_warning(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Definition: linking.cpp:505
renamingt needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:548
void duplicate_object_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:1091
casting_replace_symbolt object_type_updates
Definition: linking_class.h:52
std::string type_to_string(const irep_idt &identifier, const typet &type) const
Definition: linking.cpp:127
std::unordered_set< irep_idt > renamed_ids
bool detailed_conflict_report_rec(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2, unsigned depth, exprt &conflict_path)
Returns true iff the conflict report on a particular branch of the tree of types was a definitive res...
Definition: linking.cpp:200
void duplicate_type_symbol(symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:1227
std::string type_to_string_verbose(const symbolt &symbol, const typet &type) const
Definition: linking.cpp:148
rename_symbolt rename_new_symbol
Definition: linking_class.h:51
void detailed_conflict_report(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2)
void duplicate_code_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:563
message_handlert & message_handler
void link_error(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Definition: linking.cpp:487
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Replace a symbol expression by a given expression.
Structure type, corresponds to C style structs.
Definition: std_types.h:231
Expression to hold a symbol (variable)
Definition: std_expr.h:131
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
Definition: std_expr.h:150
The symbol table base class interface.
Symbol table entry.
Definition: symbol.h:28
bool is_type
Definition: symbol.h:61
typet type
Type of symbol.
Definition: symbol.h:31
The type of an expression, extends irept.
Definition: type.h:29
API to expression classes.
adjust_type_infot(const symbolt &_old_symbol, const symbolt &_new_symbol)
std::unordered_set< irep_idt > o_symbols
std::unordered_set< irep_idt > n_symbols
Symbol table entry.