Skip to content

Commit 1d7789f

Browse files
committed
Re-use code_*t::check in validate_expr and to_code_*t
Prefer code re-use over duplicated (and possibly inconsistent) implementations.
1 parent 92c140f commit 1d7789f

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

src/util/std_code.h

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ template<> inline bool can_cast_expr<code_assignt>(const exprt &base)
364364

365365
inline void validate_expr(const code_assignt & x)
366366
{
367-
validate_operands(x, 2, "assignment must have two operands");
367+
code_assignt::check(x);
368368
}
369369

370370
inline const code_assignt &to_code_assign(const codet &code)
@@ -432,29 +432,20 @@ template<> inline bool can_cast_expr<code_declt>(const exprt &base)
432432

433433
inline void validate_expr(const code_declt &x)
434434
{
435-
validate_operands(x, 1, "decls must have one or more operands", true);
435+
code_declt::check(x);
436436
}
437437

438438
inline const code_declt &to_code_decl(const codet &code)
439439
{
440440
PRECONDITION(code.get_statement() == ID_decl);
441-
442-
// will be size()==1 in the future
443-
DATA_INVARIANT(
444-
code.operands().size() >= 1, "decls must have one or more operands");
445-
DATA_INVARIANT(
446-
code.op0().id() == ID_symbol, "decls symbols must be a \"symbol\"");
447-
441+
code_declt::check(code);
448442
return static_cast<const code_declt &>(code);
449443
}
450444

451445
inline code_declt &to_code_decl(codet &code)
452446
{
453447
PRECONDITION(code.get_statement() == ID_decl);
454-
455-
// will be size()==1 in the future
456-
DATA_INVARIANT(
457-
code.operands().size() >= 1, "decls must have one or more operands");
448+
code_declt::check(code);
458449
return static_cast<code_declt &>(code);
459450
}
460451

@@ -510,28 +501,20 @@ template<> inline bool can_cast_expr<code_deadt>(const exprt &base)
510501

511502
inline void validate_expr(const code_deadt &x)
512503
{
513-
validate_operands(x, 1, "dead statement must have one operand");
504+
code_deadt::check(x);
514505
}
515506

516507
inline const code_deadt &to_code_dead(const codet &code)
517508
{
518509
PRECONDITION(code.get_statement() == ID_dead);
519-
DATA_INVARIANT(
520-
code.operands().size() == 1, "dead statement must have one operand");
521-
DATA_INVARIANT(
522-
to_unary_expr(code).op().id() == ID_symbol,
523-
"dead statement must take symbol operand");
510+
code_deadt::check(code);
524511
return static_cast<const code_deadt &>(code);
525512
}
526513

527514
inline code_deadt &to_code_dead(codet &code)
528515
{
529516
PRECONDITION(code.get_statement() == ID_dead);
530-
DATA_INVARIANT(
531-
code.operands().size() == 1, "dead statement must have one operand");
532-
DATA_INVARIANT(
533-
to_unary_expr(code).op().id() == ID_symbol,
534-
"dead statement must take symbol operand");
517+
code_deadt::check(code);
535518
return static_cast<code_deadt &>(code);
536519
}
537520

@@ -1242,18 +1225,20 @@ template<> inline bool can_cast_expr<code_function_callt>(const exprt &base)
12421225

12431226
inline void validate_expr(const code_function_callt &x)
12441227
{
1245-
validate_operands(x, 3, "function calls must have three operands");
1228+
code_function_callt::check(x);
12461229
}
12471230

12481231
inline const code_function_callt &to_code_function_call(const codet &code)
12491232
{
12501233
PRECONDITION(code.get_statement() == ID_function_call);
1234+
code_function_callt::check(code);
12511235
return static_cast<const code_function_callt &>(code);
12521236
}
12531237

12541238
inline code_function_callt &to_code_function_call(codet &code)
12551239
{
12561240
PRECONDITION(code.get_statement() == ID_function_call);
1241+
code_function_callt::check(code);
12571242
return static_cast<code_function_callt &>(code);
12581243
}
12591244

@@ -1305,18 +1290,20 @@ template<> inline bool can_cast_expr<code_returnt>(const exprt &base)
13051290

13061291
inline void validate_expr(const code_returnt &x)
13071292
{
1308-
validate_operands(x, 1, "return must have one operand");
1293+
code_returnt::check(x);
13091294
}
13101295

13111296
inline const code_returnt &to_code_return(const codet &code)
13121297
{
13131298
PRECONDITION(code.get_statement() == ID_return);
1299+
code_returnt::check(code);
13141300
return static_cast<const code_returnt &>(code);
13151301
}
13161302

13171303
inline code_returnt &to_code_return(codet &code)
13181304
{
13191305
PRECONDITION(code.get_statement() == ID_return);
1306+
code_returnt::check(code);
13201307
return static_cast<code_returnt &>(code);
13211308
}
13221309

0 commit comments

Comments
 (0)