Skip to content

Commit 2725a05

Browse files
Clean out unused stub generation code
Fixes #3519
1 parent 8a6e9d2 commit 2725a05

File tree

8 files changed

+1
-208
lines changed

8 files changed

+1
-208
lines changed

src/ansi-c/ansi_c_language.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ bool ansi_c_languaget::typecheck(
129129
bool ansi_c_languaget::generate_support_functions(
130130
symbol_tablet &symbol_table)
131131
{
132-
// Note this can happen here because C doesn't currently
133-
// support lazy loading at the symbol-table level, and therefore
134-
// function bodies have already been populated and external stub
135-
// symbols created during the typecheck() phase. If it gains lazy
136-
// loading support then stubs will need to be created during
137-
// function body parsing, or else generate-stubs moved to the
138-
// final phase.
139-
generate_opaque_method_stubs(symbol_table);
140-
141132
// This creates __CPROVER_start and __CPROVER_initialize:
142133
return ansi_c_entry_point(
143134
symbol_table, get_message_handler(), object_factory_params);

src/goto-programs/initialize_goto_model.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ goto_modelt initialize_goto_model(
133133
}
134134
else if(!binaries_provided_start)
135135
{
136-
// Unsure of the rationale for only generating stubs when there are no
137-
// GOTO binaries in play; simply mirroring old code in language_uit here.
138-
if(binaries.empty())
139-
{
140-
// Enable/disable stub generation for opaque methods
141-
bool stubs_enabled = options.is_set("generate-opaque-stubs");
142-
language_files.set_should_generate_opaque_method_stubs(stubs_enabled);
143-
}
144-
145136
// Allow all language front-ends to try to provide the user-specified
146137
// (--function) entry-point, or some language-specific default:
147138
entry_point_generation_failed=

src/goto-programs/lazy_goto_model.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,6 @@ void lazy_goto_modelt::initialize(
209209
}
210210
else if(!binaries_provided_start)
211211
{
212-
// Unsure of the rationale for only generating stubs when there are no
213-
// GOTO binaries in play; simply mirroring old code in language_uit here.
214-
if(binaries.empty())
215-
{
216-
// Enable/disable stub generation for opaque methods
217-
bool stubs_enabled = options.is_set("generate-opaque-stubs");
218-
language_files.set_should_generate_opaque_method_stubs(stubs_enabled);
219-
}
220-
221212
// Allow all language front-ends to try to provide the user-specified
222213
// (--function) entry-point, or some language-specific default:
223214
entry_point_generation_failed=

src/langapi/language.cpp

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -62,140 +62,3 @@ bool languaget::type_to_name(
6262
name=type.pretty();
6363
return false;
6464
}
65-
66-
/// Turn on or off stub generation.
67-
/// \param should_generate_stubs: Should stub generation be enabled
68-
void languaget::set_should_generate_opaque_method_stubs(
69-
bool should_generate_stubs)
70-
{
71-
generate_opaque_stubs=should_generate_stubs;
72-
}
73-
74-
/// When there are opaque methods (e.g. ones where we don't have a body), we
75-
/// create a stub function in the goto program and mark it as opaque so the
76-
/// interpreter fills in appropriate values for it. This will only happen if
77-
/// generate_opaque_stubs is enabled.
78-
/// \param symbol_table: the symbol table for the program
79-
void languaget::generate_opaque_method_stubs(symbol_tablet &symbol_table)
80-
{
81-
if(generate_opaque_stubs)
82-
{
83-
system_symbols=system_library_symbolst();
84-
85-
for(auto &symbol_entry : symbol_table.symbols)
86-
{
87-
if(is_symbol_opaque_function(symbol_entry.second))
88-
{
89-
symbolt &symbol=
90-
*symbol_table.get_writeable(symbol_entry.second.name);
91-
92-
generate_opaque_parameter_symbols(symbol, symbol_table);
93-
94-
irep_idt return_symbol_id=generate_opaque_stub_body(
95-
symbol,
96-
symbol_table);
97-
98-
if(return_symbol_id!=ID_nil)
99-
{
100-
symbol.type.set("opaque_method_capture_symbol", return_symbol_id);
101-
}
102-
}
103-
}
104-
}
105-
}
106-
107-
/// To generate the stub function for the opaque function in question. The
108-
/// identifier is used in the flag to the interpreter that the function is
109-
/// opaque. This function should be implemented in the languages.
110-
/// \param symbol: the function symbol which is opaque
111-
/// \param symbol_table: the symbol table
112-
/// \return The identifier of the return variable. ID_nil if the function
113-
/// doesn't return anything.
114-
irep_idt languaget::generate_opaque_stub_body(
115-
symbolt &symbol,
116-
symbol_tablet &symbol_table)
117-
{
118-
// unused parameters
119-
(void)symbol;
120-
(void)symbol_table;
121-
return ID_nil;
122-
}
123-
124-
/// To build the parameter symbol and choose its name. This should be
125-
/// implemented in each language.
126-
/// \param function_symbol: the symbol of an opaque function
127-
/// \param parameter_index: the index of the parameter within the the parameter
128-
/// list
129-
/// \param parameter: the parameter description, including its type and name
130-
/// \return A named symbol to be added to the symbol table representing one of
131-
/// the parameters in this opaque function.
132-
parameter_symbolt languaget::build_stub_parameter_symbol(
133-
const symbolt &function_symbol,
134-
size_t parameter_index,
135-
const code_typet::parametert &parameter)
136-
{
137-
// unused parameters
138-
(void)function_symbol;
139-
(void)parameter_index;
140-
(void)parameter;
141-
error() << "language " << id()
142-
<< " doesn't implement build_stub_parameter_symbol. "
143-
<< "This means cannot use opaque functions." << eom;
144-
145-
return parameter_symbolt();
146-
}
147-
148-
/// To get the name of the symbol to be used for the return value of the
149-
/// function. Generates a name like to_return_function_name
150-
/// \param function_id: the function that has a return value
151-
/// \return the identifier to use for the symbol that will store the return
152-
/// value of this function.
153-
irep_idt languaget::get_stub_return_symbol_name(const irep_idt &function_id)
154-
{
155-
std::ostringstream return_symbol_name_builder;
156-
return_symbol_name_builder << "to_return_" << function_id;
157-
return return_symbol_name_builder.str();
158-
}
159-
160-
161-
/// To identify if a given symbol is an opaque function and hence needs to be
162-
/// stubbed. We explicitly exclude CPROVER functions, if they have no body it is
163-
/// because we haven't generated it yet.
164-
/// \param symbol: the symbol to be checked
165-
/// \return True if the symbol is an opaque (e.g. non-bodied) function
166-
bool languaget::is_symbol_opaque_function(const symbolt &symbol)
167-
{
168-
std::set<std::string> headers;
169-
// Don't create stubs for symbols like:
170-
// __CPROVER_blah (which aren't real external functions)
171-
// and strstr (which we will model for ourselves later)
172-
bool is_internal=system_symbols.is_symbol_internal_symbol(symbol, headers);
173-
174-
return !symbol.is_type &&
175-
symbol.value.id()==ID_nil &&
176-
symbol.type.id()==ID_code &&
177-
!is_internal;
178-
}
179-
180-
/// To create stub parameter symbols for each parameter the function has and
181-
/// assign their IDs into the parameters identifier.
182-
/// \param function_symbol: the symbol of an opaque function
183-
/// \param symbol_table: the symbol table to add the new parameter symbols into
184-
void languaget::generate_opaque_parameter_symbols(
185-
symbolt &function_symbol,
186-
symbol_tablet &symbol_table)
187-
{
188-
code_typet &function_type = to_code_type(function_symbol.type);
189-
code_typet::parameterst &parameters=function_type.parameters();
190-
for(std::size_t i=0; i<parameters.size(); ++i)
191-
{
192-
code_typet::parametert &param=parameters[i];
193-
const parameter_symbolt &param_symbol=
194-
build_stub_parameter_symbol(function_symbol, i, param);
195-
196-
param.set_base_name(param_symbol.base_name);
197-
param.set_identifier(param_symbol.name);
198-
199-
symbol_table.add(param_symbol);
200-
}
201-
}

src/langapi/language.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -181,35 +181,14 @@ class languaget:public messaget
181181

182182
virtual std::unique_ptr<languaget> new_language()=0;
183183

184-
void set_should_generate_opaque_method_stubs(bool should_generate_stubs);
185-
186184
// constructor / destructor
187185

188186
languaget() { }
189187
virtual ~languaget() { }
190188

191189
protected:
192-
void generate_opaque_method_stubs(symbol_tablet &symbol_table);
193-
virtual irep_idt generate_opaque_stub_body(
194-
symbolt &symbol,
195-
symbol_tablet &symbol_table);
196-
197-
virtual parameter_symbolt build_stub_parameter_symbol(
198-
const symbolt &function_symbol,
199-
size_t parameter_index,
200-
const code_typet::parametert &parameter);
201-
202-
static irep_idt get_stub_return_symbol_name(const irep_idt &function_id);
203-
204-
bool generate_opaque_stubs=false;
205190
bool language_options_initialized=false;
206-
207-
private:
208-
bool is_symbol_opaque_function(const symbolt &symbol);
209-
void generate_opaque_parameter_symbols(
210-
symbolt &function_symbol,
211-
symbol_tablet &symbol_table);
212-
213191
system_library_symbolst system_symbols;
214192
};
193+
215194
#endif // CPROVER_UTIL_LANGUAGE_H

src/langapi/language_file.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ void language_filest::show_parse(std::ostream &out)
5050
file.second.language->show_parse(out);
5151
}
5252

53-
/// Turn on or off stub generation for all the languages
54-
/// \param stubs_enabled: Should stub generation be enabled
55-
void language_filest::set_should_generate_opaque_method_stubs(
56-
bool stubs_enabled)
57-
{
58-
for(file_mapt::value_type &language_file_entry : file_map)
59-
{
60-
auto &language=*language_file_entry.second.language;
61-
language.set_should_generate_opaque_method_stubs(stubs_enabled);
62-
}
63-
}
64-
6553
bool language_filest::parse()
6654
{
6755
for(auto &file : file_map)

src/langapi/language_file.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ class language_filest:public messaget
101101
file_map.clear();
102102
}
103103

104-
void set_should_generate_opaque_method_stubs(bool stubs_enabled);
105-
106104
bool parse();
107105

108106
void show_parse(std::ostream &out);

src/langapi/language_ui.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ bool language_uit::final()
113113
{
114114
language_files.set_message_handler(*message_handler);
115115

116-
// TODO: This should be moved elsewhere because it is not used in
117-
// this repository.
118-
// Enable/disable stub generation for opaque methods
119-
bool stubs_enabled = false;
120-
if(options != nullptr)
121-
stubs_enabled = options->is_set("generate-opaque-stubs");
122-
language_files.set_should_generate_opaque_method_stubs(stubs_enabled);
123-
124116
if(language_files.final(symbol_table))
125117
{
126118
error() << "CONVERSION ERROR" << eom;

0 commit comments

Comments
 (0)