@@ -62,140 +62,3 @@ bool languaget::type_to_name(
62
62
name=type.pretty ();
63
63
return false ;
64
64
}
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 ¶meter)
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 ¶meters=function_type.parameters ();
190
- for (std::size_t i=0 ; i<parameters.size (); ++i)
191
- {
192
- code_typet::parametert ¶m=parameters[i];
193
- const parameter_symbolt ¶m_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
- }
0 commit comments