Skip to content

Commit 67697aa

Browse files
committed
Implement style fixes based on feedback
1 parent 2fe55a3 commit 67697aa

File tree

7 files changed

+93
-57
lines changed

7 files changed

+93
-57
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

+26-46
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/prefix.h>
1717
#include <util/arith_tools.h>
1818
#include <util/ieee_float.h>
19+
#include <util/expr_util.h>
1920

2021
#include <linking/zero_initializer.h>
2122

@@ -33,39 +34,7 @@ Author: Daniel Kroening, [email protected]
3334
#include <functional>
3435
#include <unordered_set>
3536
#include <regex>
36-
37-
/*******************************************************************\
38-
39-
Function: traverse_expr_tree
40-
41-
Inputs: `expr`: an expression tree to traverse
42-
`parents`: will hold previously-visited nodes
43-
`func`: will be called on each node, takes the node and the `parents`
44-
stack as arguments
45-
46-
Outputs: None
47-
48-
Purpose: Abstracts the process of calling a function on each node of the
49-
expression tree.
50-
51-
\*******************************************************************/
52-
53-
template <typename Func>
54-
static void traverse_expr_tree(
55-
exprt &expr,
56-
std::vector<exprt*> &parents,
57-
Func func)
58-
{
59-
const auto& parents_ref=parents;
60-
func(expr, parents_ref);
61-
62-
parents.push_back(&expr);
63-
for(auto &op : expr.operands())
64-
{
65-
traverse_expr_tree(op, parents, func);
66-
}
67-
parents.pop_back();
68-
}
37+
#include <iterator>
6938

7039
/*******************************************************************\
7140
@@ -83,21 +52,19 @@ Function: traverse_expr_tree
8352

8453
static void remove_assert_after_generic_nondet(exprt &expr)
8554
{
86-
std::vector<exprt*> parents;
8755
traverse_expr_tree(
8856
expr,
89-
parents,
90-
[] (exprt &expr, const std::vector<exprt*>& parents)
57+
[] (exprt &expr, const std::vector<exprt *> &parents)
9158
{
9259
const std::regex id_regex(
9360
".*org.cprover.CProver.(nondetWithNull|nondetWithoutNull).*");
9461
if(expr.id()==ID_symbol &&
95-
std::regex_match(as_string(to_symbol_expr(expr).get_identifier()),
62+
std::regex_match(id2string(to_symbol_expr(expr).get_identifier()),
9663
id_regex))
9764
{
9865
assert(2<=parents.size());
99-
const auto before_1=*(parents.end()-1);
100-
const auto before_2=*(parents.end()-2);
66+
const auto before_1=*std::prev(parents.end(), 1);
67+
const auto before_2=*std::prev(parents.end(), 2);
10168

10269
for(auto it=before_2->operands().begin(),
10370
end=before_2->operands().end();
@@ -106,11 +73,12 @@ static void remove_assert_after_generic_nondet(exprt &expr)
10673
{
10774
if(&(*it)==before_1)
10875
{
109-
assert(it+1!=end);
110-
if((it+1)->id()==ID_code &&
111-
to_code(*(it+1)).get_statement()=="assert")
76+
const auto next_it=std::next(it);
77+
assert(next_it!=end);
78+
if(next_it->id()==ID_code &&
79+
to_code(*next_it).get_statement()=="assert")
11280
{
113-
*(it+1)=code_skipt();
81+
*next_it=code_skipt();
11482
}
11583
}
11684
}
@@ -929,11 +897,23 @@ void java_bytecode_convert_methodt::check_static_field_stub(
929897
}
930898
}
931899

932-
static unsigned get_bytecode_type_width(const typet &ty)
900+
/*******************************************************************\
901+
902+
Function: get_bytecode_type_width
903+
904+
Inputs: `type`: A bytecode type.
905+
906+
Outputs: The width of the type, in bits.
907+
908+
Purpose: Used to check the size of the item on the top of the stack.
909+
910+
\*******************************************************************/
911+
912+
static unsigned get_bytecode_type_width(const typet &type)
933913
{
934-
if(ty.id()==ID_pointer)
914+
if(type.id()==ID_pointer)
935915
return 32;
936-
return ty.get_unsigned_int(ID_width);
916+
return type.get_unsigned_int(ID_width);
937917
}
938918

939919
/*******************************************************************\

src/java_bytecode/java_bytecode_typecheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class java_bytecode_typecheckt:public typecheckt
4343
{
4444
}
4545

46-
virtual ~java_bytecode_typecheckt() = default;
46+
virtual ~java_bytecode_typecheckt() { }
4747

4848
virtual void typecheck();
4949
virtual void typecheck_expr(exprt &expr);

src/java_bytecode/java_bytecode_typecheck_expr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
5050
typecheck_expr_symbol(to_symbol_expr(expr));
5151
else if(expr.id()==ID_side_effect)
5252
{
53-
auto &side_effect_expr = to_side_effect_expr(expr);
54-
const irep_idt &statement = side_effect_expr.get_statement();
53+
auto &side_effect_expr=to_side_effect_expr(expr);
54+
const irep_idt &statement=side_effect_expr.get_statement();
5555
if(statement==ID_java_new)
5656
{
5757
typecheck_expr_java_new(side_effect_expr);
Binary file not shown.

src/util/expr_util.h

+58-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Author: Daniel Kroening, [email protected]
1717
*/
1818

1919
#include "irep.h"
20+
#include "expr.h"
21+
22+
#include <vector>
2023

21-
class exprt;
2224
class symbol_exprt;
2325
class update_exprt;
2426
class with_exprt;
@@ -51,4 +53,59 @@ bool has_subexpr(const exprt &, const irep_idt &);
5153
/*! lift up an if_exprt one level */
5254
if_exprt lift_if(const exprt &, std::size_t operand_number);
5355

56+
/*******************************************************************\
57+
58+
Function: traverse_expr_tree
59+
60+
Inputs: `expr`: an expression tree to traverse
61+
`parents`: will hold previously-visited nodes
62+
`func`: will be called on each node, takes the node and the `parents`
63+
stack as arguments
64+
65+
Outputs: None
66+
67+
Purpose: Abstracts the process of calling a function on each node of the
68+
expression tree.
69+
70+
\*******************************************************************/
71+
72+
template <typename Func>
73+
inline void traverse_expr_tree(
74+
exprt &expr,
75+
std::vector<exprt *> &parents,
76+
Func func)
77+
{
78+
const auto &parents_ref=parents;
79+
func(expr, parents_ref);
80+
81+
parents.push_back(&expr);
82+
for(auto &op : expr.operands())
83+
{
84+
traverse_expr_tree(op, parents, func);
85+
}
86+
parents.pop_back();
87+
}
88+
89+
/*******************************************************************\
90+
91+
Function: traverse_expr_tree
92+
93+
Inputs: `expr`: an expression tree to traverse
94+
`func`: will be called on each node, takes the node and the `parents`
95+
stack as arguments
96+
97+
Outputs: None
98+
99+
Purpose: Behaves exactly like traverse_expr_tree with three arguments, but
100+
sets up the `parents` vector internally.
101+
102+
\*******************************************************************/
103+
104+
template <typename Func>
105+
inline void traverse_expr_tree(exprt &expr, Func &&func)
106+
{
107+
std::vector<exprt *> parents;
108+
traverse_expr_tree(expr, parents, std::forward<Func>(func));
109+
}
110+
54111
#endif // CPROVER_UTIL_EXPR_UTIL_H

src/util/std_code.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,3 @@ const codet &codet::last_statement() const
177177

178178
return *this;
179179
}
180-

src/util/std_code.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1047,17 +1047,17 @@ class side_effect_expr_nondett:public side_effect_exprt
10471047
static inline const side_effect_expr_nondett &
10481048
to_side_effect_expr_nondet(const exprt &expr)
10491049
{
1050-
const auto &x = to_side_effect_expr(expr);
1051-
assert(x.get_statement() == ID_nondet);
1052-
return static_cast<const side_effect_expr_nondett &>(x);
1050+
const auto &side_effect_expr=to_side_effect_expr(expr);
1051+
assert(side_effect_expr.get_statement() == ID_nondet);
1052+
return static_cast<const side_effect_expr_nondett &>(side_effect_expr);
10531053
}
10541054

10551055
static inline side_effect_expr_nondett &
10561056
to_side_effect_expr_nondet(exprt &expr)
10571057
{
1058-
auto &x = to_side_effect_expr(expr);
1059-
assert(x.get_statement() == ID_nondet);
1060-
return static_cast<side_effect_expr_nondett &>(x);
1058+
auto &side_effect_expr=to_side_effect_expr(expr);
1059+
assert(side_effect_expr.get_statement() == ID_nondet);
1060+
return static_cast<side_effect_expr_nondett &>(side_effect_expr);
10611061
}
10621062

10631063
/*! \brief A function call side effect

0 commit comments

Comments
 (0)