Skip to content

Commit 55c2229

Browse files
author
Daniel Kroening
committed
codet: introduce codet operand methods
1 parent 0a63cb2 commit 55c2229

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
@@ -576,12 +609,12 @@ class code_switcht:public codet
576609

577610
const codet &body() const
578611
{
579-
return to_code(op1());
612+
return code_op1();
580613
}
581614

582615
codet &body()
583616
{
584-
return static_cast<codet &>(op1());
617+
return code_op1();
585618
}
586619
};
587620

@@ -638,12 +671,12 @@ class code_whilet:public codet
638671

639672
const codet &body() const
640673
{
641-
return to_code(op1());
674+
return code_op1();
642675
}
643676

644677
codet &body()
645678
{
646-
return static_cast<codet &>(op1());
679+
return code_op1();
647680
}
648681
};
649682

@@ -700,12 +733,12 @@ class code_dowhilet:public codet
700733

701734
const codet &body() const
702735
{
703-
return to_code(op1());
736+
return code_op1();
704737
}
705738

706739
codet &body()
707740
{
708-
return static_cast<codet &>(op1());
741+
return code_op1();
709742
}
710743
};
711744

@@ -775,12 +808,12 @@ class code_fort:public codet
775808

776809
const codet &body() const
777810
{
778-
return to_code(op3());
811+
return code_op3();
779812
}
780813

781814
codet &body()
782815
{
783-
return static_cast<codet &>(op3());
816+
return code_op3();
784817
}
785818
};
786819

@@ -1014,12 +1047,12 @@ class code_labelt:public codet
10141047

10151048
codet &code()
10161049
{
1017-
return static_cast<codet &>(op0());
1050+
return code_op0();
10181051
}
10191052

10201053
const codet &code() const
10211054
{
1022-
return static_cast<const codet &>(op0());
1055+
return code_op0();
10231056
}
10241057
};
10251058

@@ -1059,7 +1092,9 @@ class code_switch_caset:public codet
10591092
code_switch_caset(
10601093
const exprt &_case_op, const codet &_code):codet(ID_switch_case)
10611094
{
1062-
copy_to_operands(_case_op, _code);
1095+
operands().resize(2);
1096+
op0()=_case_op;
1097+
code_op1()=_code;
10631098
}
10641099

10651100
bool is_default() const
@@ -1084,12 +1119,12 @@ class code_switch_caset:public codet
10841119

10851120
codet &code()
10861121
{
1087-
return static_cast<codet &>(op1());
1122+
return code_op1();
10881123
}
10891124

10901125
const codet &code() const
10911126
{
1092-
return static_cast<const codet &>(op1());
1127+
return code_op1();
10931128
}
10941129
};
10951130

@@ -1718,12 +1753,12 @@ class code_try_catcht:public codet
17181753

17191754
codet &try_code()
17201755
{
1721-
return static_cast<codet &>(op0());
1756+
return code_op0();
17221757
}
17231758

17241759
const codet &try_code() const
17251760
{
1726-
return static_cast<const codet &>(op0());
1761+
return code_op0();
17271762
}
17281763

17291764
code_declt &get_catch_decl(unsigned i)

0 commit comments

Comments
 (0)