Skip to content

Commit 3d88188

Browse files
author
Daniel Kroening
committed
applying functions that aren't symbols
SMT-LIB 3 will bring function applications for terms that aren't symbols (e.g., lamba, choice). This commit removes the restriction that the function in a function application has to be a symbol. The expression is still required to have function type.
1 parent 78570d9 commit 3d88188

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

src/solvers/smt2/smt2_solver.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,42 @@ 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 f_type = to_mathematical_function_type(f.type);
9999

100-
DATA_INVARIANT(
101-
domain.size() == app.arguments().size(),
102-
"number of function parameters");
100+
const auto &domain = f_type.domain();
103101

104-
replace_symbolt replace_symbol;
102+
DATA_INVARIANT(
103+
domain.size() == app.arguments().size(),
104+
"number of function parameters");
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+
replace_symbolt replace_symbol;
112107

113-
exprt body=f.definition;
114-
replace_symbol(body);
115-
expand_function_applications(body);
116-
expr=body;
108+
std::map<irep_idt, exprt> parameter_map;
109+
for(std::size_t i = 0; i < domain.size(); i++)
110+
{
111+
const symbol_exprt s(f.parameters[i], domain[i]);
112+
replace_symbol.insert(s, app.arguments()[i]);
113+
}
114+
115+
exprt body = f.definition;
116+
replace_symbol(body);
117+
expand_function_applications(body);
118+
expr = body;
119+
}
117120
}
118121
}
119122
}

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)