Skip to content

Commit 92c140f

Browse files
committed
Replace misleading comments about validate_expr
Adds one implementation of validate_expr, and moves the other existing ones to replace the comment that claims there is no implementation.
1 parent 3c85341 commit 92c140f

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

src/util/std_code.h

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,10 @@ template<> inline bool can_cast_expr<code_assumet>(const exprt &base)
571571
return detail::can_cast_code_impl(base, ID_assume);
572572
}
573573

574-
// to_code_assume only checks the code statement, so no validate_expr is
575-
// provided for code_assumet
574+
inline void validate_expr(const code_assumet &x)
575+
{
576+
validate_operands(x, 1, "assume must have one operand");
577+
}
576578

577579
inline const code_assumet &to_code_assume(const codet &code)
578580
{
@@ -586,11 +588,6 @@ inline code_assumet &to_code_assume(codet &code)
586588
return static_cast<code_assumet &>(code);
587589
}
588590

589-
inline void validate_expr(const code_assumet &x)
590-
{
591-
validate_operands(x, 1, "assume must have one operand");
592-
}
593-
594591
/// A non-fatal assertion, which checks a condition then permits execution to
595592
/// continue.
596593
class code_assertt:public codet
@@ -628,8 +625,10 @@ template<> inline bool can_cast_expr<code_assertt>(const exprt &base)
628625
return detail::can_cast_code_impl(base, ID_assert);
629626
}
630627

631-
// to_code_assert only checks the code statement, so no validate_expr is
632-
// provided for code_assertt
628+
inline void validate_expr(const code_assertt &x)
629+
{
630+
validate_operands(x, 1, "assert must have one operand");
631+
}
633632

634633
inline const code_assertt &to_code_assert(const codet &code)
635634
{
@@ -643,11 +642,6 @@ inline code_assertt &to_code_assert(codet &code)
643642
return static_cast<code_assertt &>(code);
644643
}
645644

646-
inline void validate_expr(const code_assertt &x)
647-
{
648-
validate_operands(x, 1, "assert must have one operand");
649-
}
650-
651645
/// Create a fatal assertion, which checks a condition and then halts if it does
652646
/// not hold. Equivalent to `ASSERT(condition); ASSUME(condition)`.
653647
///
@@ -1246,8 +1240,10 @@ template<> inline bool can_cast_expr<code_function_callt>(const exprt &base)
12461240
return detail::can_cast_code_impl(base, ID_function_call);
12471241
}
12481242

1249-
// to_code_function_call only checks the code statement, so no validate_expr is
1250-
// provided for code_function_callt
1243+
inline void validate_expr(const code_function_callt &x)
1244+
{
1245+
validate_operands(x, 3, "function calls must have three operands");
1246+
}
12511247

12521248
inline const code_function_callt &to_code_function_call(const codet &code)
12531249
{
@@ -1261,11 +1257,6 @@ inline code_function_callt &to_code_function_call(codet &code)
12611257
return static_cast<code_function_callt &>(code);
12621258
}
12631259

1264-
inline void validate_expr(const code_function_callt &x)
1265-
{
1266-
validate_operands(x, 3, "function calls must have three operands");
1267-
}
1268-
12691260
/// \ref codet representation of a "return from a function" statement.
12701261
class code_returnt:public codet
12711262
{
@@ -1312,8 +1303,10 @@ template<> inline bool can_cast_expr<code_returnt>(const exprt &base)
13121303
return detail::can_cast_code_impl(base, ID_return);
13131304
}
13141305

1315-
// to_code_return only checks the code statement, so no validate_expr is
1316-
// provided for code_returnt
1306+
inline void validate_expr(const code_returnt &x)
1307+
{
1308+
validate_operands(x, 1, "return must have one operand");
1309+
}
13171310

13181311
inline const code_returnt &to_code_return(const codet &code)
13191312
{
@@ -1327,11 +1320,6 @@ inline code_returnt &to_code_return(codet &code)
13271320
return static_cast<code_returnt &>(code);
13281321
}
13291322

1330-
inline void validate_expr(const code_returnt &x)
1331-
{
1332-
validate_operands(x, 1, "return must have one operand");
1333-
}
1334-
13351323
/// \ref codet representation of a label for branch targets.
13361324
class code_labelt:public codet
13371325
{
@@ -1760,8 +1748,10 @@ inline bool can_cast_expr<code_asm_gcct>(const exprt &base)
17601748
return detail::can_cast_code_impl(base, ID_asm);
17611749
}
17621750

1763-
// to_code_asm_gcc only checks the code statement, so no validate_expr is
1764-
// provided for code_asmt
1751+
inline void validate_expr(const code_asm_gcct &x)
1752+
{
1753+
validate_operands(x, 5, "code_asm_gcc must have five operands");
1754+
}
17651755

17661756
inline code_asm_gcct &to_code_asm_gcc(codet &code)
17671757
{

0 commit comments

Comments
 (0)