Skip to content

Commit 2c44f49

Browse files
author
Daniel Kroening
committed
codet: introduce codet operand methods
1 parent f1489fd commit 2c44f49

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
@@ -598,12 +631,12 @@ class code_switcht:public codet
598631

599632
const codet &body() const
600633
{
601-
return to_code(op1());
634+
return code_op1();
602635
}
603636

604637
codet &body()
605638
{
606-
return static_cast<codet &>(op1());
639+
return code_op1();
607640
}
608641
};
609642

@@ -660,12 +693,12 @@ class code_whilet:public codet
660693

661694
const codet &body() const
662695
{
663-
return to_code(op1());
696+
return code_op1();
664697
}
665698

666699
codet &body()
667700
{
668-
return static_cast<codet &>(op1());
701+
return code_op1();
669702
}
670703
};
671704

@@ -722,12 +755,12 @@ class code_dowhilet:public codet
722755

723756
const codet &body() const
724757
{
725-
return to_code(op1());
758+
return code_op1();
726759
}
727760

728761
codet &body()
729762
{
730-
return static_cast<codet &>(op1());
763+
return code_op1();
731764
}
732765
};
733766

@@ -799,12 +832,12 @@ class code_fort:public codet
799832

800833
const codet &body() const
801834
{
802-
return to_code(op3());
835+
return code_op3();
803836
}
804837

805838
codet &body()
806839
{
807-
return static_cast<codet &>(op3());
840+
return code_op3();
808841
}
809842
};
810843

@@ -1079,12 +1112,12 @@ class code_labelt:public codet
10791112

10801113
codet &code()
10811114
{
1082-
return static_cast<codet &>(op0());
1115+
return code_op0();
10831116
}
10841117

10851118
const codet &code() const
10861119
{
1087-
return static_cast<const codet &>(op0());
1120+
return code_op0();
10881121
}
10891122
};
10901123

@@ -1126,7 +1159,9 @@ class code_switch_caset:public codet
11261159
code_switch_caset(
11271160
const exprt &_case_op, const codet &_code):codet(ID_switch_case)
11281161
{
1129-
copy_to_operands(_case_op, _code);
1162+
operands().resize(2);
1163+
op0()=_case_op;
1164+
code_op1()=_code;
11301165
}
11311166

11321167
bool is_default() const
@@ -1151,12 +1186,12 @@ class code_switch_caset:public codet
11511186

11521187
codet &code()
11531188
{
1154-
return static_cast<codet &>(op1());
1189+
return code_op1();
11551190
}
11561191

11571192
const codet &code() const
11581193
{
1159-
return static_cast<const codet &>(op1());
1194+
return code_op1();
11601195
}
11611196
};
11621197

@@ -1791,12 +1826,12 @@ class code_try_catcht:public codet
17911826

17921827
codet &try_code()
17931828
{
1794-
return static_cast<codet &>(op0());
1829+
return code_op0();
17951830
}
17961831

17971832
const codet &try_code() const
17981833
{
1799-
return static_cast<const codet &>(op0());
1834+
return code_op0();
18001835
}
18011836

18021837
code_declt &get_catch_decl(unsigned i)

0 commit comments

Comments
 (0)