@@ -71,86 +71,27 @@ static const slicet normalize_to_slice(const exprt &expr, const namespacet &ns)
71
71
UNREACHABLE;
72
72
}
73
73
74
- // / Result type for guarded assigns target pattern matching
75
- using if_match_resultt = optionalt<std::pair<exprt, exprt>>;
76
-
77
- // / \brief Matches an expression with ID_NULL or ID_constant "0".
78
- // / \param expr The candidate expression.
79
- // / \returns True iff the match is successful.
80
- bool match_NULL_or_zero (const exprt &expr)
81
- {
82
- const auto &clean_expr = skip_typecast (expr);
83
- // FIXME clean up once #6532 lands.
84
- return clean_expr.id () == ID_NULL ||
85
- (clean_expr.id () == ID_constant &&
86
- id2string (to_constant_expr (clean_expr).get_value ()) == " 0" );
87
- }
88
-
89
- // / \brief Matches an expression of the form `guard ? target : (NULL|0)`
90
- // / \param expr The candidate expression.
91
- // / \returns A pair `(guard,target)` iff the match is successful.
92
- if_match_resultt match_if (const exprt &expr)
93
- {
94
- const auto &clean_expr = skip_typecast (expr);
95
- if (clean_expr.id () == ID_if)
96
- {
97
- const auto &if_expr = to_if_expr (clean_expr);
98
- if (!match_NULL_or_zero (if_expr.false_case ()))
99
- return {};
100
-
101
- return {{if_expr.cond (), if_expr.true_case ()}};
102
- }
103
- else
104
- return {};
105
- }
106
-
107
- // / Pattern match the given expression for a guarded pattern
108
- // / and builds guarded_slice expression as follows:
74
+ // / Normalises a assigns target expression to a guarded slice struct.
109
75
// /
110
76
// / ```
111
77
// / case expr of
112
- // / | guard ? target : NULL ->
113
- // / {guard,
78
+ // / | guard ? target ->
79
+ // / {guard
114
80
// / target,
115
- // / address_of{target},
116
- // / size_of_expr{target}}
117
- // / | __CPROVER_POINTER_OBJECT(guard ? target : NULL) ->
118
- // / {guard,
119
- // / __CPROVER_POINTER_OBJECT(target),
120
- // / address_of{target-offset(target)},
121
- // / object_size{target}}
122
- // / | other ->
81
+ // / normalize_to_slice(target)}
82
+ // / | target ->
123
83
// / {true,
124
- // / expr,
125
- // / address_of{expr},
126
- // / object_size{expr}}
84
+ // / target,
85
+ // / normalize_to_slice(target)}
127
86
// / ```
128
87
static const guarded_slicet
129
88
normalize_to_guarded_slice (const exprt &expr, const namespacet &ns)
130
89
{
131
- if (expr.id () == ID_pointer_object)
132
- {
133
- if_match_resultt match_opt = match_if (expr.operands ().at (0 ));
134
- if (match_opt.has_value ())
135
- {
136
- const auto &match = match_opt.value ();
137
- const auto &new_expr = pointer_object (match.second );
138
- const auto slice = normalize_to_slice (new_expr, ns);
139
- return {match.first , new_expr, slice.first , slice.second };
140
- }
141
- else
142
- {
143
- const auto slice = normalize_to_slice (expr, ns);
144
- return {true_exprt{}, expr, slice.first , slice.second };
145
- }
146
- }
147
-
148
- if_match_resultt match_opt = match_if (expr);
149
- if (match_opt.has_value ())
90
+ if (expr.id () == ID_conditional_assigns_target)
150
91
{
151
- const auto &match = match_opt. value ( );
152
- const auto slice = normalize_to_slice (match. second , ns);
153
- return {match. first , match. second , slice.first , slice.second };
92
+ const auto &new_expr = expr. operands (). at ( 1 );
93
+ const auto slice = normalize_to_slice (new_expr , ns);
94
+ return {expr. operands (). at ( 0 ), new_expr , slice.first , slice.second };
154
95
}
155
96
else
156
97
{
0 commit comments