CBMC
Loading...
Searching...
No Matches
language_file.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9
10#ifndef CPROVER_LANGAPI_LANGUAGE_FILE_H
11#define CPROVER_LANGAPI_LANGUAGE_FILE_H
12
13#include <iosfwd>
14#include <map>
15#include <memory> // unique_ptr
16#include <set>
17#include <string>
18#include <unordered_set>
19
21
23class language_filet;
24class languaget;
25
27{
28public:
29 std::string name;
32
38};
39
40class language_filet final
41{
42public:
43 typedef std::set<std::string> modulest;
45
46 std::unique_ptr<languaget> language;
47 std::string filename;
48
49 void get_modules();
50
52 const irep_idt &id,
53 symbol_table_baset &symbol_table,
54 message_handlert &message_handler);
55
56 explicit language_filet(const std::string &filename);
58
60};
61
63{
64private:
65 typedef std::map<std::string, language_filet> file_mapt;
67
68 typedef std::map<std::string, language_modulet> module_mapt;
70
71 // Contains pointers into file_map!
72 // This is safe-ish as long as this is std::map.
73 typedef std::map<irep_idt, language_filet *> lazy_method_mapt;
75
76public:
77 language_filet &add_file(const std::string &filename)
78 {
80 return file_map.emplace(filename, std::move(language_file)).first->second;
81 }
82
83 void remove_file(const std::string &filename)
84 {
85 // Clear relevant entries from lazy_method_map
86 language_filet *language_file = &file_map.at(filename);
87 std::unordered_set<irep_idt> files_methods;
88 for(auto const &method : lazy_method_map)
89 {
90 if(method.second == language_file)
91 files_methods.insert(method.first);
92 }
95
96 file_map.erase(filename);
97 }
98
100 {
102 file_map.clear();
103 }
104
105 bool parse(message_handlert &message_handler);
106
107 void show_parse(std::ostream &out, message_handlert &message_handler);
108
110 symbol_table_baset &symbol_table,
111 message_handlert &message_handler);
112
113 bool
114
115 typecheck(
116 symbol_table_baset &symbol_table,
117 const bool keep_file_local,
118 message_handlert &message_handler);
119 bool
120 typecheck(symbol_table_baset &symbol_table, message_handlert &message_handler)
121 {
122 return typecheck(symbol_table, false, message_handler);
123 }
124
125 bool final(symbol_table_baset &symbol_table);
126
127 bool interfaces(
128 symbol_table_baset &symbol_table,
129 message_handlert &message_handler);
130
131 // The method must have been added to the symbol table and registered
132 // in lazy_method_map (currently always in language_filest::typecheck)
133 // for this to be legal.
135 const irep_idt &id,
136 symbol_table_baset &symbol_table,
137 message_handlert &message_handler)
138 {
139 PRECONDITION(symbol_table.has_symbol(id));
140 lazy_method_mapt::iterator it=lazy_method_map.find(id);
141 if(it!=lazy_method_map.end())
142 it->second->convert_lazy_method(id, symbol_table, message_handler);
143 }
144
145 bool can_convert_lazy_method(const irep_idt &id) const
146 {
147 return lazy_method_map.count(id) != 0;
148 }
149
150 void clear()
151 {
152 file_map.clear();
155 }
156
157protected:
158 bool typecheck_module(
159 symbol_table_baset &symbol_table,
161 const bool keep_file_local,
162 message_handlert &message_handler);
163
164 bool typecheck_module(
165 symbol_table_baset &symbol_table,
166 const std::string &module,
167 const bool keep_file_local,
168 message_handlert &message_handler);
169};
170
171#endif // CPROVER_UTIL_LANGUAGE_FILE_H
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
bool interfaces(symbol_table_baset &symbol_table, message_handlert &message_handler)
bool parse(message_handlert &message_handler)
bool typecheck_module(symbol_table_baset &symbol_table, language_modulet &module, const bool keep_file_local, message_handlert &message_handler)
std::map< std::string, language_modulet > module_mapt
void convert_lazy_method(const irep_idt &id, symbol_table_baset &symbol_table, message_handlert &message_handler)
bool typecheck(symbol_table_baset &symbol_table, const bool keep_file_local, message_handlert &message_handler)
file_mapt file_map
std::map< std::string, language_filet > file_mapt
bool generate_support_functions(symbol_table_baset &symbol_table, message_handlert &message_handler)
bool typecheck(symbol_table_baset &symbol_table, message_handlert &message_handler)
lazy_method_mapt lazy_method_map
language_filet & add_file(const std::string &filename)
bool can_convert_lazy_method(const irep_idt &id) const
std::map< irep_idt, language_filet * > lazy_method_mapt
void remove_file(const std::string &filename)
module_mapt module_map
void show_parse(std::ostream &out, message_handlert &message_handler)
std::string filename
~language_filet()
To avoid compiler errors, the complete definition of a pointed-to type must be visible at the point a...
void convert_lazy_method(const irep_idt &id, symbol_table_baset &symbol_table, message_handlert &message_handler)
std::set< std::string > modulest
std::unique_ptr< languaget > language
std::string name
language_filet * file
The symbol table base class interface.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
Author: Diffblue Ltd.