@@ -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
class tuple_exprt : public multi_ary_exprt
@@ -263,18 +266,20 @@ inline const function_application_exprt &
263
266
to_function_application_expr (const exprt &expr)
264
267
{
265
268
PRECONDITION (expr.id () == ID_function_application);
266
- DATA_INVARIANT (
267
- expr.operands ().size () == 2 , " Function application must have two operands" );
268
- return static_cast <const function_application_exprt &>(expr);
269
+ const function_application_exprt &ret =
270
+ static_cast <const function_application_exprt &>(expr);
271
+ validate_expr (ret);
272
+ return ret;
269
273
}
270
274
271
275
// / \copydoc to_function_application_expr(const exprt &)
272
276
inline function_application_exprt &to_function_application_expr (exprt &expr)
273
277
{
274
278
PRECONDITION (expr.id () == ID_function_application);
275
- DATA_INVARIANT (
276
- expr.operands ().size () == 2 , " Function application must have two operands" );
277
- return static_cast <function_application_exprt &>(expr);
279
+ function_application_exprt &ret =
280
+ static_cast <function_application_exprt &>(expr);
281
+ validate_expr (ret);
282
+ return ret;
278
283
}
279
284
280
285
// / \brief A base class for quantifier expressions
@@ -319,6 +324,8 @@ inline bool can_cast_expr<quantifier_exprt>(const exprt &base)
319
324
inline void validate_expr (const quantifier_exprt &value)
320
325
{
321
326
validate_operands (value, 2 , " quantifier expressions must have two operands" );
327
+ DATA_INVARIANT (
328
+ value.op0 ().id () == ID_symbol, " quantified variable shall be a symbol" );
322
329
}
323
330
324
331
// / \brief Cast an exprt to a \ref quantifier_exprt
@@ -329,23 +336,19 @@ inline void validate_expr(const quantifier_exprt &value)
329
336
// / \return Object of type \ref quantifier_exprt
330
337
inline const quantifier_exprt &to_quantifier_expr (const exprt &expr)
331
338
{
332
- DATA_INVARIANT (
333
- expr.operands ().size () == 2 ,
334
- " quantifier expressions must have two operands" );
335
- DATA_INVARIANT (
336
- expr.op0 ().id () == ID_symbol, " quantified variable shall be a symbol" );
337
- return static_cast <const quantifier_exprt &>(expr);
339
+ PRECONDITION (can_cast_expr<quantifier_exprt>(expr));
340
+ const quantifier_exprt &ret = static_cast <const quantifier_exprt &>(expr);
341
+ validate_expr (ret);
342
+ return ret;
338
343
}
339
344
340
345
// / \copydoc to_quantifier_expr(const exprt &)
341
346
inline quantifier_exprt &to_quantifier_expr (exprt &expr)
342
347
{
343
- DATA_INVARIANT (
344
- expr.operands ().size () == 2 ,
345
- " quantifier expressions must have two operands" );
346
- DATA_INVARIANT (
347
- expr.op0 ().id () == ID_symbol, " quantified variable shall be a symbol" );
348
- return static_cast <quantifier_exprt &>(expr);
348
+ PRECONDITION (can_cast_expr<quantifier_exprt>(expr));
349
+ quantifier_exprt &ret = static_cast <quantifier_exprt &>(expr);
350
+ validate_expr (ret);
351
+ return ret;
349
352
}
350
353
351
354
// / \brief A forall expression
@@ -361,19 +364,17 @@ class forall_exprt : public quantifier_exprt
361
364
inline const forall_exprt &to_forall_expr (const exprt &expr)
362
365
{
363
366
PRECONDITION (expr.id () == ID_forall);
364
- DATA_INVARIANT (
365
- expr.operands ().size () == 2 ,
366
- " forall expressions have exactly two operands" );
367
- return static_cast <const forall_exprt &>(expr);
367
+ const forall_exprt &ret = static_cast <const forall_exprt &>(expr);
368
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
369
+ return ret;
368
370
}
369
371
370
372
inline forall_exprt &to_forall_expr (exprt &expr)
371
373
{
372
374
PRECONDITION (expr.id () == ID_forall);
373
- DATA_INVARIANT (
374
- expr.operands ().size () == 2 ,
375
- " forall expressions have exactly two operands" );
376
- return static_cast <forall_exprt &>(expr);
375
+ forall_exprt &ret = static_cast <forall_exprt &>(expr);
376
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
377
+ return ret;
377
378
}
378
379
379
380
// / \brief An exists expression
@@ -389,19 +390,17 @@ class exists_exprt : public quantifier_exprt
389
390
inline const exists_exprt &to_exists_expr (const exprt &expr)
390
391
{
391
392
PRECONDITION (expr.id () == ID_exists);
392
- DATA_INVARIANT (
393
- expr.operands ().size () == 2 ,
394
- " exists expressions have exactly two operands" );
395
- return static_cast <const exists_exprt &>(expr);
393
+ const exists_exprt &ret = static_cast <const exists_exprt &>(expr);
394
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
395
+ return ret;
396
396
}
397
397
398
398
inline exists_exprt &to_exists_expr (exprt &expr)
399
399
{
400
400
PRECONDITION (expr.id () == ID_exists);
401
- DATA_INVARIANT (
402
- expr.operands ().size () == 2 ,
403
- " exists expressions have exactly two operands" );
404
- return static_cast <exists_exprt &>(expr);
401
+ exists_exprt &ret = static_cast <exists_exprt &>(expr);
402
+ validate_expr (static_cast <const quantifier_exprt &>(ret));
403
+ return ret;
405
404
}
406
405
407
406
#endif // CPROVER_UTIL_MATHEMATICAL_EXPR_H
0 commit comments