cprover
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  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  void rename_symbols(const std::unordered_set<irep_idt> &needs_to_be_renamed);
69  void copy_symbols();
70 
72  symbolt &old_symbol,
73  symbolt &new_symbol);
74 
76  symbolt &old_symbol,
77  symbolt &new_symbol);
78 
80  symbolt &old_symbol,
81  symbolt &new_symbol);
82 
83  bool adjust_object_type(
84  const symbolt &old_symbol,
85  const symbolt &new_symbol,
86  bool &set_to_new);
87 
89  {
91  const symbolt &_old_symbol,
92  const symbolt &_new_symbol):
93  old_symbol(_old_symbol),
94  new_symbol(_new_symbol),
95  set_to_new(false)
96  {
97  }
98 
102  std::unordered_set<irep_idt> o_symbols;
103  std::unordered_set<irep_idt> n_symbols;
104  };
105 
107  const typet &type1,
108  const typet &type2,
109  adjust_type_infot &info);
110 
112  symbolt &old_symbol,
113  const symbolt &new_symbol);
114 
115  std::string expr_to_string(
116  const irep_idt &identifier,
117  const exprt &expr) const;
118 
119  std::string type_to_string(
120  const irep_idt &identifier,
121  const typet &type) const;
122 
123  std::string type_to_string_verbose(
124  const symbolt &symbol,
125  const typet &type) const;
126 
128  const symbolt &symbol) const
129  {
130  return type_to_string_verbose(symbol, symbol.type);
131  }
132 
134  const symbolt &old_symbol,
135  const symbolt &new_symbol,
136  const typet &type1,
137  const typet &type2,
138  unsigned depth,
139  exprt &conflict_path);
140 
142  const symbolt &old_symbol,
143  const symbolt &new_symbol,
144  const typet &type1,
145  const typet &type2)
146  {
147  symbol_exprt conflict_path = symbol_exprt::typeless(ID_C_this);
149  old_symbol,
150  new_symbol,
151  type1,
152  type2,
153  10, // somewhat arbitrary limit
154  conflict_path);
155  }
156 
157  void link_error(
158  const symbolt &old_symbol,
159  const symbolt &new_symbol,
160  const std::string &msg);
161 
162  void link_warning(
163  const symbolt &old_symbol,
164  const symbolt &new_symbol,
165  const std::string &msg);
166 
168  const struct_typet &old_type,
169  const struct_typet &new_type);
170 
173 
175 
176  // X -> Y iff Y uses X for new symbol type IDs X and Y
177  typedef std::unordered_map<irep_idt, std::unordered_set<irep_idt>> used_byt;
178 
180 
181  // the new IDs created by renaming
182  std::unordered_set<irep_idt> renamed_ids;
183 };
184 
185 #endif // CPROVER_LINKING_LINKING_CLASS_H
bool replace_symbol_expr(symbol_exprt &dest) const override
Definition: linking.cpp:30
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
Base class for all expressions.
Definition: expr.h:54
void duplicate_non_type_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:1087
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
Definition: linking.cpp:982
bool needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:1215
symbol_table_baset & src_symbol_table
rename_symbolt rename_symbol
Definition: linking_class.h:44
std::string type_to_string_verbose(const symbolt &symbol) const
namespacet ns
linkingt(symbol_table_baset &_main_symbol_table, symbol_table_baset &_src_symbol_table, message_handlert &_message_handler)
Definition: linking_class.h:31
bool adjust_object_type_rec(const typet &type1, const typet &type2, adjust_type_infot &info)
Definition: linking.cpp:803
bool needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:448
virtual void typecheck()
Definition: linking.cpp:1408
void show_struct_diff(const struct_typet &old_type, const struct_typet &new_type)
void copy_symbols()
Definition: linking.cpp:1346
symbol_table_baset & main_symbol_table
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > used_byt
std::string expr_to_string(const irep_idt &identifier, const exprt &expr) const
Definition: linking.cpp:50
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:128
void do_type_dependencies(std::unordered_set< irep_idt > &)
Definition: linking.cpp:1271
void link_warning(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Definition: linking.cpp:406
void duplicate_object_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:997
void rename_symbols(const std::unordered_set< irep_idt > &needs_to_be_renamed)
Definition: linking.cpp:1316
casting_replace_symbolt object_type_updates
Definition: linking_class.h:45
std::string type_to_string(const irep_idt &identifier, const typet &type) const
Definition: linking.cpp:57
std::unordered_set< irep_idt > renamed_ids
void duplicate_type_symbol(symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:1121
std::string type_to_string_verbose(const symbolt &symbol, const typet &type) const
Definition: linking.cpp:78
void detailed_conflict_report(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2)
bool needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking_class.h:56
void duplicate_code_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:462
void link_error(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Definition: linking.cpp:389
irep_idt rename(irep_idt)
Definition: linking.cpp:424
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:91
Replace expression or type symbols by an expression or type, respectively.
Structure type, corresponds to C style structs.
Definition: std_types.h:231
Expression to hold a symbol (variable)
Definition: std_expr.h:80
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
Definition: std_expr.h:99
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:28
API to expression classes.
const symbolt & old_symbol
Definition: linking_class.h:99
adjust_type_infot(const symbolt &_old_symbol, const symbolt &_new_symbol)
Definition: linking_class.h:90
std::unordered_set< irep_idt > o_symbols
std::unordered_set< irep_idt > n_symbols
Symbol table entry.