Skip to content

Commit 559e78f

Browse files
Petr BauchPetr Bauch
authored andcommitted
Fix based on comments
1 parent bbeb694 commit 559e78f

File tree

8 files changed

+28
-141
lines changed

8 files changed

+28
-141
lines changed

src/goto-programs/goto_function.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ class goto_functiont
119119
void validate(const namespacet &ns, const validation_modet vm) const
120120
{
121121
body.validate(ns, vm);
122-
source_locationt nil_location;
123-
nil_location.make_nil();
124-
forall_subtypes(it, type)
122+
123+
find_symbols_sett typetags;
124+
find_type_symbols(type, typetags);
125+
const symbolt *symbol;
126+
for(const auto &identifier : typetags)
125127
{
126-
find_typetag_in_namespace(*it, nil_location, ns, vm);
128+
DATA_CHECK(
129+
vm,
130+
!ns.lookup(identifier, symbol),
131+
id2string(identifier) + " not found");
127132
}
128133

129134
validate_full_type(type, ns, vm);

src/goto-programs/goto_program.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "goto_program.h"
1313

14-
#include <ostream>
14+
#include <algorithm>
1515
#include <iomanip>
16+
#include <ostream>
1617

18+
#include <util/expr_iterator.h>
1719
#include <util/find_symbols.h>
1820
#include <util/std_expr.h>
1921
#include <util/validate.h>
@@ -685,11 +687,18 @@ void goto_programt::instructiont::validate(
685687
source_location);
686688

687689
auto expr_symbol_finder = [&](const exprt &e) {
688-
forall_subtypes(it, e.type())
690+
find_symbols_sett typetags;
691+
find_type_symbols(e.type(), typetags);
692+
find_symbols(e, typetags);
693+
const symbolt *symbol;
694+
for(const auto &identifier : typetags)
689695
{
690-
find_typetag_in_namespace(*it, source_location, ns, vm);
696+
DATA_CHECK_WITH_DIAGNOSTICS(
697+
vm,
698+
!ns.lookup(identifier, symbol),
699+
id2string(identifier) + " not found",
700+
source_location);
691701
}
692-
find_symbol_in_namespace(e, source_location, ns, vm);
693702
};
694703

695704
auto &current_source_location = source_location;
@@ -742,8 +751,8 @@ void goto_programt::instructiont::validate(
742751
"assert instruction should not have a target",
743752
source_location);
744753

745-
guard.visit(expr_symbol_finder);
746-
guard.visit(type_finder);
754+
std::for_each(guard.depth_begin(), guard.depth_end(), expr_symbol_finder);
755+
std::for_each(guard.depth_begin(), guard.depth_end(), type_finder);
747756
break;
748757
case OTHER:
749758
break;
@@ -809,8 +818,8 @@ void goto_programt::instructiont::validate(
809818
"function call instruction should contain a call statement",
810819
source_location);
811820

812-
code.visit(expr_symbol_finder);
813-
code.visit(type_finder);
821+
std::for_each(code.depth_begin(), code.depth_end(), expr_symbol_finder);
822+
std::for_each(code.depth_begin(), code.depth_end(), type_finder);
814823
break;
815824
case THROW:
816825
break;

src/util/expr.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,6 @@ void exprt::visit(const_expr_visitort &visitor) const
279279
}
280280
}
281281

282-
void exprt::visit(const std::function<void(const exprt &)> &f) const
283-
{
284-
std::stack<const exprt *> stack;
285-
stack.push(this);
286-
while(!stack.empty())
287-
{
288-
const exprt &expr = *stack.top();
289-
stack.pop();
290-
f(expr);
291-
forall_operands(it, expr)
292-
stack.push(&(*it));
293-
}
294-
}
295-
296282
depth_iteratort exprt::depth_begin()
297283
{ return depth_iteratort(*this); }
298284
depth_iteratort exprt::depth_end()

src/util/expr.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,6 @@ class exprt:public irept
305305
void visit(class expr_visitort &visitor);
306306
void visit(class const_expr_visitort &visitor) const;
307307

308-
/// Recursively traverse the expression tree (via operands) and call \p f on
309-
/// every subexpressions, including `this`. The input function has
310-
/// side-effects and does not modify the expression.
311-
/// \param f: The function to be call on subexpressions
312-
void visit(const std::function<void(const exprt &)> &f) const;
313-
314308
depth_iteratort depth_begin();
315309
depth_iteratort depth_end();
316310
const_depth_iteratort depth_begin() const;

src/util/find_symbols.cpp

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -210,55 +210,3 @@ void find_type_and_expr_symbols(const typet &src, find_symbols_sett &dest)
210210
{
211211
find_symbols(kindt::F_BOTH, src, dest);
212212
}
213-
214-
void find_typetag_in_namespace(
215-
const typet &src,
216-
const source_locationt &location,
217-
const namespacet &ns,
218-
const validation_modet vm)
219-
{
220-
irep_idt identifier = ID_nil;
221-
if(src.id() == ID_symbol_type)
222-
{
223-
identifier = to_symbol_type(src).get_identifier();
224-
}
225-
else if(
226-
src.id() == ID_c_enum_tag || src.id() == ID_struct_tag ||
227-
src.id() == ID_union_tag)
228-
{
229-
identifier = to_tag_type(src).get_identifier();
230-
}
231-
if(identifier != ID_nil)
232-
{
233-
const symbolt *symbol;
234-
if(location.is_nil())
235-
DATA_CHECK(
236-
vm,
237-
!ns.lookup(identifier, symbol),
238-
id2string(identifier) + " not found");
239-
else
240-
DATA_CHECK_WITH_DIAGNOSTICS(
241-
vm,
242-
!ns.lookup(identifier, symbol),
243-
id2string(identifier) + " not found",
244-
location);
245-
}
246-
}
247-
248-
void find_symbol_in_namespace(
249-
const exprt &src,
250-
const source_locationt &location,
251-
const namespacet &ns,
252-
const validation_modet vm)
253-
{
254-
if(src.id() == ID_symbol)
255-
{
256-
const symbolt *symbol;
257-
auto identifier = to_symbol_expr(src).get_identifier();
258-
DATA_CHECK_WITH_DIAGNOSTICS(
259-
vm,
260-
!ns.lookup(identifier, symbol),
261-
id2string(identifier) + " not found",
262-
location);
263-
}
264-
}

src/util/find_symbols.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Author: Daniel Kroening, [email protected]
1818
#include "validate.h"
1919

2020
class exprt;
21+
class source_locationt;
2122
class symbol_exprt;
22-
class typet;
2323
class symbolt;
24-
class source_locationt;
24+
class typet;
2525

2626
typedef std::unordered_set<irep_idt> find_symbols_sett;
2727

@@ -71,16 +71,4 @@ void find_type_and_expr_symbols(
7171
const exprt &src,
7272
find_symbols_sett &dest);
7373

74-
void find_typetag_in_namespace(
75-
const typet &src,
76-
const source_locationt &location,
77-
const namespacet &ns,
78-
const validation_modet vm);
79-
80-
void find_symbol_in_namespace(
81-
const exprt &src,
82-
const source_locationt &location,
83-
const namespacet &ns,
84-
const validation_modet vm);
85-
8674
#endif // CPROVER_UTIL_FIND_SYMBOLS_H

unit/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ SRC += analyses/ai/ai.cpp \
6464
util/string_utils/strip_string.cpp \
6565
util/symbol_table.cpp \
6666
util/unicode.cpp \
67-
util/visit.cpp \
6867
# Empty last line
6968

7069
INCLUDES= -I ../src/ -I.

unit/util/visit.cpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)