@@ -79,18 +79,18 @@ inline void validate_expr(const transt &value)
79
79
inline const transt &to_trans_expr (const exprt &expr)
80
80
{
81
81
PRECONDITION (expr.id () == ID_trans);
82
- DATA_INVARIANT (
83
- expr. operands (). size () == 3 , " Transition systems must have three operands " );
84
- return static_cast < const transt &>(expr) ;
82
+ const transt &ret = static_cast < const transt &>(expr);
83
+ validate_expr (ret );
84
+ return ret ;
85
85
}
86
86
87
87
// / \copydoc to_trans_expr(const exprt &)
88
88
inline transt &to_trans_expr (exprt &expr)
89
89
{
90
90
PRECONDITION (expr.id () == ID_trans);
91
- DATA_INVARIANT (
92
- expr. operands (). size () == 3 , " Transition systems must have three operands " );
93
- return static_cast <transt &>(expr) ;
91
+ transt &ret = static_cast <transt &>(expr);
92
+ validate_expr (ret );
93
+ return ret ;
94
94
}
95
95
96
96
// / \brief Exponentiation
@@ -128,16 +128,18 @@ inline void validate_expr(const power_exprt &value)
128
128
inline const power_exprt &to_power_expr (const exprt &expr)
129
129
{
130
130
PRECONDITION (expr.id () == ID_power);
131
- DATA_INVARIANT (expr.operands ().size () == 2 , " Power must have two operands" );
132
- return static_cast <const power_exprt &>(expr);
131
+ const power_exprt &ret = static_cast <const power_exprt &>(expr);
132
+ validate_expr (ret);
133
+ return ret;
133
134
}
134
135
135
136
// / \copydoc to_power_expr(const exprt &)
136
137
inline power_exprt &to_power_expr (exprt &expr)
137
138
{
138
139
PRECONDITION (expr.id () == ID_power);
139
- DATA_INVARIANT (expr.operands ().size () == 2 , " Power must have two operands" );
140
- return static_cast <power_exprt &>(expr);
140
+ power_exprt &ret = static_cast <power_exprt &>(expr);
141
+ validate_expr (ret);
142
+ return ret;
141
143
}
142
144
143
145
// / \brief Falling factorial power
@@ -175,18 +177,19 @@ inline void validate_expr(const factorial_power_exprt &value)
175
177
inline const factorial_power_exprt &to_factorial_power_expr (const exprt &expr)
176
178
{
177
179
PRECONDITION (expr.id () == ID_factorial_power);
178
- DATA_INVARIANT (
179
- expr.operands ().size () == 2 , " Factorial power must have two operands" );
180
- return static_cast <const factorial_power_exprt &>(expr);
180
+ const factorial_power_exprt &ret =
181
+ static_cast <const factorial_power_exprt &>(expr);
182
+ validate_expr (ret);
183
+ return ret;
181
184
}
182
185
183
186
// / \copydoc to_factorial_power_expr(const exprt &)
184
187
inline factorial_power_exprt &to_factorial_expr (exprt &expr)
185
188
{
186
189
PRECONDITION (expr.id () == ID_factorial_power);
187
- DATA_INVARIANT (
188
- expr. operands (). size () == 2 , " Factorial power must have two operands " );
189
- return static_cast <factorial_power_exprt &>(expr) ;
190
+ factorial_power_exprt &ret = static_cast <factorial_power_exprt &>(expr);
191
+ validate_expr (ret );
192
+ return ret ;
190
193
}
191
194
192
195
// / \brief Application of (mathematical) function
@@ -246,18 +249,20 @@ inline const function_application_exprt &
246
249
to_function_application_expr (const exprt &expr)
247
250
{
248
251
PRECONDITION (expr.id () == ID_function_application);
249
- DATA_INVARIANT (
250
- expr.operands ().size () == 2 , " Function application must have two operands" );
251
- return static_cast <const function_application_exprt &>(expr);
252
+ const function_application_exprt &ret =
253
+ static_cast <const function_application_exprt &>(expr);
254
+ validate_expr (ret);
255
+ return ret;
252
256
}
253
257
254
258
// / \copydoc to_function_application_expr(const exprt &)
255
259
inline function_application_exprt &to_function_application_expr (exprt &expr)
256
260
{
257
261
PRECONDITION (expr.id () == ID_function_application);
258
- DATA_INVARIANT (
259
- expr.operands ().size () == 2 , " Function application must have two operands" );
260
- return static_cast <function_application_exprt &>(expr);
262
+ function_application_exprt &ret =
263
+ static_cast <function_application_exprt &>(expr);
264
+ validate_expr (ret);
265
+ return ret;
261
266
}
262
267
263
268
// / \brief A base class for quantifier expressions
@@ -302,6 +307,8 @@ inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
302
307
inline void validate_expr (const quantifier_exprt &value)
303
308
{
304
309
validate_operands (value, 2 , " quantifier expressions must have two operands" );
310
+ DATA_INVARIANT (
311
+ value.op0 ().id () == ID_symbol, " quantified variable shall be a symbol" );
305
312
}
306
313
307
314
// / \brief Cast an exprt to a \ref quantifier_exprt
@@ -312,23 +319,19 @@ inline void validate_expr(const quantifier_exprt &value)
312
319
// / \return Object of type \ref quantifier_exprt
313
320
inline const quantifier_exprt &to_quantifier_expr (const exprt &expr)
314
321
{
315
- DATA_INVARIANT (
316
- expr.operands ().size () == 2 ,
317
- " quantifier expressions must have two operands" );
318
- DATA_INVARIANT (
319
- expr.op0 ().id () == ID_symbol, " quantified variable shall be a symbol" );
320
- return static_cast <const quantifier_exprt &>(expr);
322
+ PRECONDITION (can_cast_expr<quantifier_exprt>(expr));
323
+ const quantifier_exprt &ret = static_cast <const quantifier_exprt &>(expr);
324
+ validate_expr (ret);
325
+ return ret;
321
326
}
322
327
323
328
// / \copydoc to_quantifier_expr(const exprt &)
324
329
inline quantifier_exprt &to_quantifier_expr (exprt &expr)
325
330
{
326
- DATA_INVARIANT (
327
- expr.operands ().size () == 2 ,
328
- " quantifier expressions must have two operands" );
329
- DATA_INVARIANT (
330
- expr.op0 ().id () == ID_symbol, " quantified variable shall be a symbol" );
331
- return static_cast <quantifier_exprt &>(expr);
331
+ PRECONDITION (can_cast_expr<quantifier_exprt>(expr));
332
+ quantifier_exprt &ret = static_cast <quantifier_exprt &>(expr);
333
+ validate_expr (ret);
334
+ return ret;
332
335
}
333
336
334
337
// / \brief A forall expression
@@ -344,19 +347,17 @@ class forall_exprt : public quantifier_exprt
344
347
inline const forall_exprt &to_forall_expr (const exprt &expr)
345
348
{
346
349
PRECONDITION (expr.id () == ID_forall);
347
- DATA_INVARIANT (
348
- expr.operands ().size () == 2 ,
349
- " forall expressions have exactly two operands" );
350
- return static_cast <const forall_exprt &>(expr);
350
+ const forall_exprt &ret = static_cast <const forall_exprt &>(expr);
351
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
352
+ return ret;
351
353
}
352
354
353
355
inline forall_exprt &to_forall_expr (exprt &expr)
354
356
{
355
357
PRECONDITION (expr.id () == ID_forall);
356
- DATA_INVARIANT (
357
- expr.operands ().size () == 2 ,
358
- " forall expressions have exactly two operands" );
359
- return static_cast <forall_exprt &>(expr);
358
+ forall_exprt &ret = static_cast <forall_exprt &>(expr);
359
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
360
+ return ret;
360
361
}
361
362
362
363
// / \brief An exists expression
@@ -372,19 +373,17 @@ class exists_exprt : public quantifier_exprt
372
373
inline const exists_exprt &to_exists_expr (const exprt &expr)
373
374
{
374
375
PRECONDITION (expr.id () == ID_exists);
375
- DATA_INVARIANT (
376
- expr.operands ().size () == 2 ,
377
- " exists expressions have exactly two operands" );
378
- return static_cast <const exists_exprt &>(expr);
376
+ const exists_exprt &ret = static_cast <const exists_exprt &>(expr);
377
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
378
+ return ret;
379
379
}
380
380
381
381
inline exists_exprt &to_exists_expr (exprt &expr)
382
382
{
383
383
PRECONDITION (expr.id () == ID_exists);
384
- DATA_INVARIANT (
385
- expr.operands ().size () == 2 ,
386
- " exists expressions have exactly two operands" );
387
- return static_cast <exists_exprt &>(expr);
384
+ exists_exprt &ret = static_cast <exists_exprt &>(expr);
385
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
386
+ return ret;
388
387
}
389
388
390
389
#endif // CPROVER_UTIL_MATHEMATICAL_EXPR_H
0 commit comments