Skip to content

Commit df358f6

Browse files
author
Daniel Kroening
committed
codet: introduce codet operand methods
1 parent 9d69f68 commit df358f6

File tree

1 file changed

+50
-15
lines changed

1 file changed

+50
-15
lines changed

src/util/std_code.h

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ class codet:public exprt
5959
codet &last_statement();
6060
const codet &last_statement() const;
6161
class code_blockt &make_block();
62+
63+
protected:
64+
typedef std::vector<codet> code_operandst;
65+
66+
code_operandst &code_operands()
67+
{ return (code_operandst &)get_sub(); }
68+
69+
const code_operandst &code_operands() const
70+
{ return (const code_operandst &)get_sub(); }
71+
72+
codet &code_op0()
73+
{ return code_operands().front(); }
74+
75+
codet &code_op1()
76+
{ return code_operands()[1]; }
77+
78+
codet &code_op2()
79+
{ return code_operands()[2]; }
80+
81+
codet &code_op3()
82+
{ return code_operands()[3]; }
83+
84+
const codet &code_op0() const
85+
{ return code_operands().front(); }
86+
87+
const codet &code_op1() const
88+
{ return code_operands()[1]; }
89+
90+
const codet &code_op2() const
91+
{ return code_operands()[2]; }
92+
93+
const codet &code_op3() const
94+
{ return code_operands()[3]; }
6295
};
6396

6497
namespace detail // NOLINT
@@ -595,12 +628,12 @@ class code_switcht:public codet
595628

596629
const codet &body() const
597630
{
598-
return to_code(op1());
631+
return code_op1();
599632
}
600633

601634
codet &body()
602635
{
603-
return static_cast<codet &>(op1());
636+
return code_op1();
604637
}
605638
};
606639

@@ -657,12 +690,12 @@ class code_whilet:public codet
657690

658691
const codet &body() const
659692
{
660-
return to_code(op1());
693+
return code_op1();
661694
}
662695

663696
codet &body()
664697
{
665-
return static_cast<codet &>(op1());
698+
return code_op1();
666699
}
667700
};
668701

@@ -719,12 +752,12 @@ class code_dowhilet:public codet
719752

720753
const codet &body() const
721754
{
722-
return to_code(op1());
755+
return code_op1();
723756
}
724757

725758
codet &body()
726759
{
727-
return static_cast<codet &>(op1());
760+
return code_op1();
728761
}
729762
};
730763

@@ -796,12 +829,12 @@ class code_fort:public codet
796829

797830
const codet &body() const
798831
{
799-
return to_code(op3());
832+
return code_op3();
800833
}
801834

802835
codet &body()
803836
{
804-
return static_cast<codet &>(op3());
837+
return code_op3();
805838
}
806839
};
807840

@@ -1076,12 +1109,12 @@ class code_labelt:public codet
10761109

10771110
codet &code()
10781111
{
1079-
return static_cast<codet &>(op0());
1112+
return code_op0();
10801113
}
10811114

10821115
const codet &code() const
10831116
{
1084-
return static_cast<const codet &>(op0());
1117+
return code_op0();
10851118
}
10861119
};
10871120

@@ -1123,7 +1156,9 @@ class code_switch_caset:public codet
11231156
code_switch_caset(
11241157
const exprt &_case_op, const codet &_code):codet(ID_switch_case)
11251158
{
1126-
add_to_operands(_case_op, _code);
1159+
operands().resize(2);
1160+
op0()=_case_op;
1161+
code_op1()=_code;
11271162
}
11281163

11291164
bool is_default() const
@@ -1148,12 +1183,12 @@ class code_switch_caset:public codet
11481183

11491184
codet &code()
11501185
{
1151-
return static_cast<codet &>(op1());
1186+
return code_op1();
11521187
}
11531188

11541189
const codet &code() const
11551190
{
1156-
return static_cast<const codet &>(op1());
1191+
return code_op1();
11571192
}
11581193
};
11591194

@@ -1788,12 +1823,12 @@ class code_try_catcht:public codet
17881823

17891824
codet &try_code()
17901825
{
1791-
return static_cast<codet &>(op0());
1826+
return code_op0();
17921827
}
17931828

17941829
const codet &try_code() const
17951830
{
1796-
return static_cast<const codet &>(op0());
1831+
return code_op0();
17971832
}
17981833

17991834
code_declt &get_catch_decl(unsigned i)

0 commit comments

Comments
 (0)