Skip to content

Commit e3d8334

Browse files
committed
remove lambda_exprt::application
lambda_exprt uses a binding_exprt, which means that the application of a function given as lambda expression is a special case of an instantiation.
1 parent de97a80 commit e3d8334

File tree

2 files changed

+4
-66
lines changed

2 files changed

+4
-66
lines changed

src/util/mathematical_expr.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -51,68 +51,3 @@ lambda_exprt::lambda_exprt(const variablest &_variables, const exprt &_where)
5151
lambda_type(_variables, _where))
5252
{
5353
}
54-
55-
static optionalt<exprt> substitute_symbols_rec(
56-
const std::map<irep_idt, exprt> &substitutions,
57-
exprt src)
58-
{
59-
if(src.id() == ID_symbol)
60-
{
61-
auto s_it = substitutions.find(to_symbol_expr(src).get_identifier());
62-
if(s_it == substitutions.end())
63-
return {};
64-
else
65-
return s_it->second;
66-
}
67-
68-
if(!src.has_operands())
69-
return {};
70-
71-
bool op_changed = false;
72-
73-
for(auto &op : src.operands())
74-
{
75-
auto op_result = substitute_symbols_rec(substitutions, op);
76-
77-
if(op_result.has_value())
78-
{
79-
op = op_result.value();
80-
op_changed = true;
81-
}
82-
}
83-
84-
if(op_changed)
85-
return src;
86-
else
87-
return {};
88-
}
89-
90-
exprt lambda_exprt::application(const operandst &arguments) const
91-
{
92-
// number of arguments must match function signature
93-
auto &variables = this->variables();
94-
PRECONDITION(variables.size() == arguments.size());
95-
96-
std::map<symbol_exprt, exprt> value_map;
97-
98-
for(std::size_t i = 0; i < variables.size(); i++)
99-
{
100-
// types must match
101-
PRECONDITION(variables[i].type() == arguments[i].type());
102-
value_map[variables[i]] = arguments[i];
103-
}
104-
105-
// build a subsitution map
106-
std::map<irep_idt, exprt> substitutions;
107-
108-
for(std::size_t i = 0; i < variables.size(); i++)
109-
substitutions[variables[i].get_identifier()] = arguments[i];
110-
111-
// now recurse downwards and substitute in 'where'
112-
auto substitute_result = substitute_symbols_rec(substitutions, where());
113-
114-
if(substitute_result.has_value())
115-
return substitute_result.value();
116-
else
117-
return where(); // trivial case, variables not used
118-
}

src/util/mathematical_expr.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ class lambda_exprt : public binding_exprt
398398
}
399399

400400
// apply the function to the given arguments
401-
exprt application(const operandst &) const;
401+
exprt application(const operandst &arguments) const
402+
{
403+
return instantiate(arguments);
404+
}
402405
};
403406

404407
template <>

0 commit comments

Comments
 (0)