Skip to content

Commit 5e870d9

Browse files
authored
Merge pull request #4889 from diffblue/non-symbol-function-applications
applying functions that aren't symbols
2 parents 784be6f + 7a44403 commit 5e870d9

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

src/solvers/smt2/smt2_solver.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,39 @@ void smt2_solvert::expand_function_applications(exprt &expr)
8181
{
8282
auto &app=to_function_application_expr(expr);
8383

84-
// look it up
85-
irep_idt identifier=app.function().get_identifier();
86-
auto f_it=id_map.find(identifier);
87-
88-
if(f_it!=id_map.end())
84+
if(app.function().id() == ID_symbol)
8985
{
90-
const auto &f=f_it->second;
86+
// look up the symbol
87+
auto identifier = to_symbol_expr(app.function()).get_identifier();
88+
auto f_it = id_map.find(identifier);
9189

92-
DATA_INVARIANT(f.type.id()==ID_mathematical_function,
93-
"type of function symbol must be mathematical_function_type");
90+
if(f_it != id_map.end())
91+
{
92+
const auto &f = f_it->second;
9493

95-
const auto f_type=
96-
to_mathematical_function_type(f.type);
94+
DATA_INVARIANT(
95+
f.type.id() == ID_mathematical_function,
96+
"type of function symbol must be mathematical_function_type");
9797

98-
const auto &domain = f_type.domain();
98+
const auto &domain = to_mathematical_function_type(f.type).domain();
9999

100-
DATA_INVARIANT(
101-
domain.size() == app.arguments().size(),
102-
"number of function parameters");
100+
DATA_INVARIANT(
101+
domain.size() == app.arguments().size(),
102+
"number of parameters must match number of arguments");
103103

104-
replace_symbolt replace_symbol;
104+
replace_symbolt replace_symbol;
105105

106-
std::map<irep_idt, exprt> parameter_map;
107-
for(std::size_t i = 0; i < domain.size(); i++)
108-
{
109-
const symbol_exprt s(f.parameters[i], domain[i]);
110-
replace_symbol.insert(s, app.arguments()[i]);
111-
}
106+
for(std::size_t i = 0; i < domain.size(); i++)
107+
{
108+
replace_symbol.insert(
109+
symbol_exprt(f.parameters[i], domain[i]), app.arguments()[i]);
110+
}
112111

113-
exprt body=f.definition;
114-
replace_symbol(body);
115-
expand_function_applications(body);
116-
expr=body;
112+
exprt body = f.definition;
113+
replace_symbol(body);
114+
expand_function_applications(body);
115+
expr = body;
116+
}
117117
}
118118
}
119119
}

src/solvers/strings/string_builtin_function.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ class string_builtin_function_with_no_evalt : public string_builtin_functiont
484484

485485
std::string name() const override
486486
{
487-
return id2string(function_application.function().get_identifier());
487+
PRECONDITION(function_application.function().id() == ID_symbol);
488+
return id2string(
489+
to_symbol_expr(function_application.function()).get_identifier());
488490
}
489491
std::vector<array_string_exprt> string_arguments() const override
490492
{

src/util/mathematical_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#include "mathematical_types.h"
1111

1212
function_application_exprt::function_application_exprt(
13-
const symbol_exprt &_function,
13+
const exprt &_function,
1414
argumentst _arguments)
1515
: binary_exprt(
1616
_function,

src/util/mathematical_expr.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,16 @@ class function_application_exprt : public binary_exprt
211211
{
212212
}
213213

214-
function_application_exprt(
215-
const symbol_exprt &_function,
216-
argumentst _arguments);
214+
function_application_exprt(const exprt &_function, argumentst _arguments);
217215

218-
symbol_exprt &function()
216+
exprt &function()
219217
{
220-
return static_cast<symbol_exprt &>(op0());
218+
return op0();
221219
}
222220

223-
const symbol_exprt &function() const
221+
const exprt &function() const
224222
{
225-
return static_cast<const symbol_exprt &>(op0());
223+
return op0();
226224
}
227225

228226
argumentst &arguments()

0 commit comments

Comments
 (0)