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/std_expr.h>
18 #include <util/symbol.h>
19 
20 #include "casting_replace_symbol.h"
21 
22 #include <unordered_set>
23 
24 class message_handlert;
25 
26 class linkingt
27 {
28 public:
30  symbol_table_baset &_main_symbol_table,
31  message_handlert &_message_handler)
32  : main_symbol_table(_main_symbol_table),
33  ns(_main_symbol_table),
34  message_handler(_message_handler)
35  {
36  }
37 
41  bool link(const symbol_table_baset &src_symbol_table);
42 
45 
46 protected:
47  enum renamingt
48  {
52  };
53 
54  renamingt
55  needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol);
56 
57  renamingt
58  needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol);
59 
60  renamingt needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
61  {
62  if(new_symbol.is_type)
63  return needs_renaming_type(old_symbol, new_symbol);
64  else
65  return needs_renaming_non_type(old_symbol, new_symbol);
66  }
67 
68  std::unordered_map<irep_idt, irep_idt> rename_symbols(
69  const symbol_table_baset &,
70  const std::unordered_set<irep_idt> &needs_to_be_renamed);
71  void copy_symbols(
72  const symbol_table_baset &,
73  const std::unordered_map<irep_idt, irep_idt> &);
74 
76  symbolt &old_symbol,
77  symbolt &new_symbol);
78 
80  symbolt &old_symbol,
81  symbolt &new_symbol);
82 
84  symbolt &old_symbol,
85  symbolt &new_symbol);
86 
87  bool adjust_object_type(
88  const symbolt &old_symbol,
89  const symbolt &new_symbol,
90  bool &set_to_new);
91 
93  {
95  const symbolt &_old_symbol,
96  const symbolt &_new_symbol):
97  old_symbol(_old_symbol),
98  new_symbol(_new_symbol),
99  set_to_new(false)
100  {
101  }
102 
106  std::unordered_set<irep_idt> o_symbols;
107  std::unordered_set<irep_idt> n_symbols;
108  };
109 
111  const typet &type1,
112  const typet &type2,
113  adjust_type_infot &info);
114 
116  symbolt &old_symbol,
117  const symbolt &new_symbol);
118 
122 
123  irep_idt rename(const symbol_table_baset &, const irep_idt &);
124 
125  // the new IDs created by renaming
126  std::unordered_set<irep_idt> renamed_ids;
127 };
128 
129 #endif // CPROVER_LINKING_LINKING_CLASS_H
A variant of replace_symbolt that does not require types to match, but instead inserts type casts as ...
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
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:952
void duplicate_non_type_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:701
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
Definition: linking.cpp:596
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:1053
renamingt needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking_class.h:60
linkingt(symbol_table_baset &_main_symbol_table, message_handlert &_message_handler)
Definition: linking_class.h:29
namespacet ns
bool adjust_object_type_rec(const typet &type1, const typet &type2, adjust_type_infot &info)
Definition: linking.cpp:401
rename_symbolt rename_main_symbol
Definition: linking_class.h:43
void copy_symbols(const symbol_table_baset &, const std::unordered_map< irep_idt, irep_idt > &)
Definition: linking.cpp:987
irep_idt rename(const symbol_table_baset &, const irep_idt &)
Definition: linking.cpp:43
renamingt needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:834
symbol_table_baset & main_symbol_table
renamingt needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:67
void duplicate_object_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:611
casting_replace_symbolt object_type_updates
Definition: linking_class.h:44
std::unordered_set< irep_idt > renamed_ids
void duplicate_type_symbol(symbolt &old_symbol, const symbolt &new_symbol)
Definition: linking.cpp:744
rename_symbolt rename_new_symbol
Definition: linking_class.h:43
void duplicate_code_symbol(symbolt &old_symbol, symbolt &new_symbol)
Definition: linking.cpp:82
message_handlert & message_handler
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The symbol table base class interface.
Symbol table entry.
Definition: symbol.h:28
bool is_type
Definition: symbol.h:61
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)
Definition: linking_class.h:94
std::unordered_set< irep_idt > o_symbols
std::unordered_set< irep_idt > n_symbols
Symbol table entry.