@@ -549,13 +549,17 @@ inline void validate_expr(const code_assumet &x)
549
549
inline const code_assumet &to_code_assume (const codet &code)
550
550
{
551
551
PRECONDITION (code.get_statement () == ID_assume);
552
- return static_cast <const code_assumet &>(code);
552
+ const code_assumet &ret = static_cast <const code_assumet &>(code);
553
+ validate_expr (ret);
554
+ return ret;
553
555
}
554
556
555
557
inline code_assumet &to_code_assume (codet &code)
556
558
{
557
559
PRECONDITION (code.get_statement () == ID_assume);
558
- return static_cast <code_assumet &>(code);
560
+ code_assumet &ret = static_cast <code_assumet &>(code);
561
+ validate_expr (ret);
562
+ return ret;
559
563
}
560
564
561
565
// / A non-fatal assertion, which checks a condition then permits execution to
@@ -603,13 +607,17 @@ inline void validate_expr(const code_assertt &x)
603
607
inline const code_assertt &to_code_assert (const codet &code)
604
608
{
605
609
PRECONDITION (code.get_statement () == ID_assert);
606
- return static_cast <const code_assertt &>(code);
610
+ const code_assertt &ret = static_cast <const code_assertt &>(code);
611
+ validate_expr (ret);
612
+ return ret;
607
613
}
608
614
609
615
inline code_assertt &to_code_assert (codet &code)
610
616
{
611
617
PRECONDITION (code.get_statement () == ID_assert);
612
- return static_cast <code_assertt &>(code);
618
+ code_assertt &ret = static_cast <code_assertt &>(code);
619
+ validate_expr (ret);
620
+ return ret;
613
621
}
614
622
615
623
// / Create a fatal assertion, which checks a condition and then halts if it does
@@ -709,17 +717,17 @@ inline void validate_expr(const code_ifthenelset &x)
709
717
inline const code_ifthenelset &to_code_ifthenelse (const codet &code)
710
718
{
711
719
PRECONDITION (code.get_statement () == ID_ifthenelse);
712
- DATA_INVARIANT (
713
- code. operands (). size () == 3 , " if-then-else must have three operands " );
714
- return static_cast < const code_ifthenelset &>(code) ;
720
+ const code_ifthenelset &ret = static_cast < const code_ifthenelset &>(code);
721
+ validate_expr (code );
722
+ return ret ;
715
723
}
716
724
717
725
inline code_ifthenelset &to_code_ifthenelse (codet &code)
718
726
{
719
727
PRECONDITION (code.get_statement () == ID_ifthenelse);
720
- DATA_INVARIANT (
721
- code. operands (). size () == 3 , " if-then-else must have three operands " );
722
- return static_cast <code_ifthenelset &>(code) ;
728
+ code_ifthenelset &ret = static_cast <code_ifthenelset &>(code);
729
+ validate_expr (code );
730
+ return ret ;
723
731
}
724
732
725
733
// / \ref codet representing a `switch` statement.
@@ -777,15 +785,17 @@ inline void validate_expr(const code_switcht &x)
777
785
inline const code_switcht &to_code_switch (const codet &code)
778
786
{
779
787
PRECONDITION (code.get_statement () == ID_switch);
780
- DATA_INVARIANT (code.operands ().size () == 2 , " switch must have two operands" );
781
- return static_cast <const code_switcht &>(code);
788
+ const code_switcht &ret = static_cast <const code_switcht &>(code);
789
+ validate_expr (code);
790
+ return ret;
782
791
}
783
792
784
793
inline code_switcht &to_code_switch (codet &code)
785
794
{
786
795
PRECONDITION (code.get_statement () == ID_switch);
787
- DATA_INVARIANT (code.operands ().size () == 2 , " switch must have two operands" );
788
- return static_cast <code_switcht &>(code);
796
+ code_switcht &ret = static_cast <code_switcht &>(code);
797
+ validate_expr (code);
798
+ return ret;
789
799
}
790
800
791
801
// / \ref codet representing a `while` statement.
@@ -843,15 +853,17 @@ inline void validate_expr(const code_whilet &x)
843
853
inline const code_whilet &to_code_while (const codet &code)
844
854
{
845
855
PRECONDITION (code.get_statement () == ID_while);
846
- DATA_INVARIANT (code.operands ().size () == 2 , " while must have two operands" );
847
- return static_cast <const code_whilet &>(code);
856
+ const code_whilet &ret = static_cast <const code_whilet &>(code);
857
+ validate_expr (code);
858
+ return ret;
848
859
}
849
860
850
861
inline code_whilet &to_code_while (codet &code)
851
862
{
852
863
PRECONDITION (code.get_statement () == ID_while);
853
- DATA_INVARIANT (code.operands ().size () == 2 , " while must have two operands" );
854
- return static_cast <code_whilet &>(code);
864
+ code_whilet &ret = static_cast <code_whilet &>(code);
865
+ validate_expr (code);
866
+ return ret;
855
867
}
856
868
857
869
// / \ref codet representation of a `do while` statement.
@@ -909,17 +921,17 @@ inline void validate_expr(const code_dowhilet &x)
909
921
inline const code_dowhilet &to_code_dowhile (const codet &code)
910
922
{
911
923
PRECONDITION (code.get_statement () == ID_dowhile);
912
- DATA_INVARIANT (
913
- code. operands (). size () == 2 , " do-while must have two operands " );
914
- return static_cast < const code_dowhilet &>(code) ;
924
+ const code_dowhilet &ret = static_cast < const code_dowhilet &>(code);
925
+ validate_expr (code );
926
+ return ret ;
915
927
}
916
928
917
929
inline code_dowhilet &to_code_dowhile (codet &code)
918
930
{
919
931
PRECONDITION (code.get_statement () == ID_dowhile);
920
- DATA_INVARIANT (
921
- code. operands (). size () == 2 , " do-while must have two operands " );
922
- return static_cast <code_dowhilet &>(code) ;
932
+ code_dowhilet &ret = static_cast <code_dowhilet &>(code);
933
+ validate_expr (code );
934
+ return ret ;
923
935
}
924
936
925
937
// / \ref codet representation of a `for` statement.
@@ -1004,15 +1016,17 @@ inline void validate_expr(const code_fort &x)
1004
1016
inline const code_fort &to_code_for (const codet &code)
1005
1017
{
1006
1018
PRECONDITION (code.get_statement () == ID_for);
1007
- DATA_INVARIANT (code.operands ().size () == 4 , " for must have four operands" );
1008
- return static_cast <const code_fort &>(code);
1019
+ const code_fort &ret = static_cast <const code_fort &>(code);
1020
+ validate_expr (code);
1021
+ return ret;
1009
1022
}
1010
1023
1011
1024
inline code_fort &to_code_for (codet &code)
1012
1025
{
1013
1026
PRECONDITION (code.get_statement () == ID_for);
1014
- DATA_INVARIANT (code.operands ().size () == 4 , " for must have four operands" );
1015
- return static_cast <code_fort &>(code);
1027
+ code_fort &ret = static_cast <code_fort &>(code);
1028
+ validate_expr (code);
1029
+ return ret;
1016
1030
}
1017
1031
1018
1032
// / \ref codet representation of a `goto` statement.
@@ -1059,15 +1073,17 @@ inline void validate_expr(const code_gotot &x)
1059
1073
inline const code_gotot &to_code_goto (const codet &code)
1060
1074
{
1061
1075
PRECONDITION (code.get_statement () == ID_goto);
1062
- DATA_INVARIANT (code.operands ().empty (), " goto must not have operands" );
1063
- return static_cast <const code_gotot &>(code);
1076
+ const code_gotot &ret = static_cast <const code_gotot &>(code);
1077
+ validate_expr (code);
1078
+ return ret;
1064
1079
}
1065
1080
1066
1081
inline code_gotot &to_code_goto (codet &code)
1067
1082
{
1068
1083
PRECONDITION (code.get_statement () == ID_goto);
1069
- DATA_INVARIANT (code.operands ().empty (), " goto must not have operands" );
1070
- return static_cast <code_gotot &>(code);
1084
+ code_gotot &ret = static_cast <code_gotot &>(code);
1085
+ validate_expr (code);
1086
+ return ret;
1071
1087
}
1072
1088
1073
1089
// / \ref codet representation of a function call statement.
@@ -1357,15 +1373,17 @@ inline void validate_expr(const code_labelt &x)
1357
1373
inline const code_labelt &to_code_label (const codet &code)
1358
1374
{
1359
1375
PRECONDITION (code.get_statement () == ID_label);
1360
- DATA_INVARIANT (code.operands ().size () == 1 , " label must have one operand" );
1361
- return static_cast <const code_labelt &>(code);
1376
+ const code_labelt &ret = static_cast <const code_labelt &>(code);
1377
+ validate_expr (code);
1378
+ return ret;
1362
1379
}
1363
1380
1364
1381
inline code_labelt &to_code_label (codet &code)
1365
1382
{
1366
1383
PRECONDITION (code.get_statement () == ID_label);
1367
- DATA_INVARIANT (code.operands ().size () == 1 , " label must have one operand" );
1368
- return static_cast <code_labelt &>(code);
1384
+ code_labelt &ret = static_cast <code_labelt &>(code);
1385
+ validate_expr (code);
1386
+ return ret;
1369
1387
}
1370
1388
1371
1389
// / \ref codet representation of a switch-case, i.e.\ a `case` statement within
@@ -1434,17 +1452,17 @@ inline void validate_expr(const code_switch_caset &x)
1434
1452
inline const code_switch_caset &to_code_switch_case (const codet &code)
1435
1453
{
1436
1454
PRECONDITION (code.get_statement () == ID_switch_case);
1437
- DATA_INVARIANT (
1438
- code. operands (). size () == 2 , " switch-case must have two operands " );
1439
- return static_cast < const code_switch_caset &>(code) ;
1455
+ const code_switch_caset &ret = static_cast < const code_switch_caset &>(code);
1456
+ validate_expr (code );
1457
+ return ret ;
1440
1458
}
1441
1459
1442
1460
inline code_switch_caset &to_code_switch_case (codet &code)
1443
1461
{
1444
1462
PRECONDITION (code.get_statement () == ID_switch_case);
1445
- DATA_INVARIANT (
1446
- code. operands (). size () == 2 , " switch-case must have two operands " );
1447
- return static_cast <code_switch_caset &>(code) ;
1463
+ code_switch_caset &ret = static_cast <code_switch_caset &>(code);
1464
+ validate_expr (code );
1465
+ return ret ;
1448
1466
}
1449
1467
1450
1468
// / \ref codet representation of a switch-case, i.e.\ a `case` statement
@@ -1518,19 +1536,19 @@ inline const code_gcc_switch_case_ranget &
1518
1536
to_code_gcc_switch_case_range (const codet &code)
1519
1537
{
1520
1538
PRECONDITION (code.get_statement () == ID_gcc_switch_case_range);
1521
- DATA_INVARIANT (
1522
- code. operands (). size () == 3 ,
1523
- " gcc-switch-case-range must have three operands " );
1524
- return static_cast < const code_gcc_switch_case_ranget &>(code) ;
1539
+ const code_gcc_switch_case_ranget &ret =
1540
+ static_cast < const code_gcc_switch_case_ranget &>(code);
1541
+ validate_expr (code );
1542
+ return ret ;
1525
1543
}
1526
1544
1527
1545
inline code_gcc_switch_case_ranget &to_code_gcc_switch_case_range (codet &code)
1528
1546
{
1529
1547
PRECONDITION (code.get_statement () == ID_gcc_switch_case_range);
1530
- DATA_INVARIANT (
1531
- code. operands (). size () == 3 ,
1532
- " gcc-switch-case-range must have three operands " );
1533
- return static_cast <code_gcc_switch_case_ranget &>(code) ;
1548
+ code_gcc_switch_case_ranget &ret =
1549
+ static_cast <code_gcc_switch_case_ranget &>(code);
1550
+ validate_expr (code );
1551
+ return ret ;
1534
1552
}
1535
1553
1536
1554
// / \ref codet representation of a `break` statement (within a `for` or `while`
@@ -1731,18 +1749,18 @@ inline code_asm_gcct &to_code_asm_gcc(codet &code)
1731
1749
{
1732
1750
PRECONDITION (code.get_statement () == ID_asm);
1733
1751
PRECONDITION (to_code_asm (code).get_flavor () == ID_gcc);
1734
- DATA_INVARIANT (
1735
- code. operands (). size () == 5 , " code_asm_gcc must have give operands " );
1736
- return static_cast <code_asm_gcct &>(code) ;
1752
+ code_asm_gcct &ret = static_cast <code_asm_gcct &>(code);
1753
+ validate_expr (code );
1754
+ return ret ;
1737
1755
}
1738
1756
1739
1757
inline const code_asm_gcct &to_code_asm_gcc (const codet &code)
1740
1758
{
1741
1759
PRECONDITION (code.get_statement () == ID_asm);
1742
1760
PRECONDITION (to_code_asm (code).get_flavor () == ID_gcc);
1743
- DATA_INVARIANT (
1744
- code. operands (). size () == 5 , " code_asm_gcc must have give operands " );
1745
- return static_cast < const code_asm_gcct &>(code) ;
1761
+ const code_asm_gcct &ret = static_cast < const code_asm_gcct &>(code);
1762
+ validate_expr (code );
1763
+ return ret ;
1746
1764
}
1747
1765
1748
1766
// / \ref codet representation of an expression statement.
@@ -1790,17 +1808,17 @@ inline void validate_expr(const code_expressiont &x)
1790
1808
inline code_expressiont &to_code_expression (codet &code)
1791
1809
{
1792
1810
PRECONDITION (code.get_statement () == ID_expression);
1793
- DATA_INVARIANT (
1794
- code. operands (). size () == 1 , " expression statement must have one operand " );
1795
- return static_cast <code_expressiont &>(code) ;
1811
+ code_expressiont &ret = static_cast <code_expressiont &>(code);
1812
+ validate_expr (code );
1813
+ return ret ;
1796
1814
}
1797
1815
1798
1816
inline const code_expressiont &to_code_expression (const codet &code)
1799
1817
{
1800
1818
PRECONDITION (code.get_statement () == ID_expression);
1801
- DATA_INVARIANT (
1802
- code. operands (). size () == 1 , " expression statement must have one operand " );
1803
- return static_cast < const code_expressiont &>(code) ;
1819
+ const code_expressiont &ret = static_cast < const code_expressiont &>(code);
1820
+ validate_expr (code );
1821
+ return ret ;
1804
1822
}
1805
1823
1806
1824
// / An expression containing a side effect.
@@ -2443,17 +2461,17 @@ inline void validate_expr(const code_try_catcht &x)
2443
2461
inline const code_try_catcht &to_code_try_catch (const codet &code)
2444
2462
{
2445
2463
PRECONDITION (code.get_statement () == ID_try_catch);
2446
- DATA_INVARIANT (
2447
- code. operands (). size () >= 3 , " try-catch must have three or more operands " );
2448
- return static_cast < const code_try_catcht &>(code) ;
2464
+ const code_try_catcht &ret = static_cast < const code_try_catcht &>(code);
2465
+ validate_expr (code );
2466
+ return ret ;
2449
2467
}
2450
2468
2451
2469
inline code_try_catcht &to_code_try_catch (codet &code)
2452
2470
{
2453
2471
PRECONDITION (code.get_statement () == ID_try_catch);
2454
- DATA_INVARIANT (
2455
- code. operands (). size () >= 3 , " try-catch must have three or more operands " );
2456
- return static_cast <code_try_catcht &>(code) ;
2472
+ code_try_catcht &ret = static_cast <code_try_catcht &>(code);
2473
+ validate_expr (code );
2474
+ return ret ;
2457
2475
}
2458
2476
2459
2477
#endif // CPROVER_UTIL_STD_CODE_H
0 commit comments