Skip to content

Commit aba0fc9

Browse files
Use diagnostics in arrayst
instead of throw 0.
1 parent 882bfff commit aba0fc9

File tree

1 file changed

+28
-48
lines changed

1 file changed

+28
-48
lines changed

src/solvers/flattening/arrays.cpp

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@ literalt arrayst::record_array_equality(
4848
const exprt &op0=equality.op0();
4949
const exprt &op1=equality.op1();
5050

51-
// check types
52-
if(op0.type() != op1.type())
53-
{
54-
log.error() << equality.pretty() << messaget::eom;
55-
DATA_INVARIANT(
56-
false,
57-
"record_array_equality got equality without matching types");
58-
}
51+
DATA_INVARIANT_WITH_DIAGNOSTICS(
52+
op0.type() == op1.type(),
53+
"record_array_equality got equality without matching types",
54+
irep_pretty_diagnosticst{equality});
5955

6056
DATA_INVARIANT(
6157
op0.type().id() == ID_array,
@@ -116,12 +112,10 @@ void arrayst::collect_arrays(const exprt &a)
116112
{
117113
const with_exprt &with_expr=to_with_expr(a);
118114

119-
// check types
120-
if(array_type != with_expr.old().type())
121-
{
122-
log.error() << a.pretty() << messaget::eom;
123-
DATA_INVARIANT(false, "collect_arrays got 'with' without matching types");
124-
}
115+
DATA_INVARIANT_WITH_DIAGNOSTICS(
116+
array_type == with_expr.old().type(),
117+
"collect_arrays got 'with' without matching types",
118+
irep_pretty_diagnosticst{a});
125119

126120
arrays.make_union(a, with_expr.old());
127121
collect_arrays(with_expr.old());
@@ -137,14 +131,10 @@ void arrayst::collect_arrays(const exprt &a)
137131
{
138132
const update_exprt &update_expr=to_update_expr(a);
139133

140-
// check types
141-
if(array_type != update_expr.old().type())
142-
{
143-
log.error() << a.pretty() << messaget::eom;
144-
DATA_INVARIANT(
145-
false,
146-
"collect_arrays got 'update' without matching types");
147-
}
134+
DATA_INVARIANT_WITH_DIAGNOSTICS(
135+
array_type == update_expr.old().type(),
136+
"collect_arrays got 'update' without matching types",
137+
irep_pretty_diagnosticst{a});
148138

149139
arrays.make_union(a, update_expr.old());
150140
collect_arrays(update_expr.old());
@@ -159,19 +149,15 @@ void arrayst::collect_arrays(const exprt &a)
159149
{
160150
const if_exprt &if_expr=to_if_expr(a);
161151

162-
// check types
163-
if(array_type != if_expr.true_case().type())
164-
{
165-
log.error() << a.pretty() << messaget::eom;
166-
DATA_INVARIANT(false, "collect_arrays got if without matching types");
167-
}
152+
DATA_INVARIANT_WITH_DIAGNOSTICS(
153+
array_type == if_expr.true_case().type(),
154+
"collect_arrays got if without matching types",
155+
irep_pretty_diagnosticst{a});
168156

169-
// check types
170-
if(array_type != if_expr.false_case().type())
171-
{
172-
log.error() << a.pretty() << messaget::eom;
173-
DATA_INVARIANT(false, "collect_arrays got if without matching types");
174-
}
157+
DATA_INVARIANT_WITH_DIAGNOSTICS(
158+
array_type == if_expr.false_case().type(),
159+
"collect_arrays got if without matching types",
160+
irep_pretty_diagnosticst{a});
175161

176162
arrays.make_union(a, if_expr.true_case());
177163
arrays.make_union(a, if_expr.false_case());
@@ -521,13 +507,10 @@ void arrayst::add_array_constraints_with(
521507

522508
index_exprt index_expr(expr, index, expr.type().subtype());
523509

524-
if(index_expr.type()!=value.type())
525-
{
526-
log.error() << expr.pretty() << messaget::eom;
527-
DATA_INVARIANT(
528-
false,
529-
"with-expression operand should match array element type");
530-
}
510+
DATA_INVARIANT_WITH_DIAGNOSTICS(
511+
index_expr.type() == value.type(),
512+
"with-expression operand should match array element type",
513+
irep_pretty_diagnosticst{expr});
531514

532515
lazy_constraintt lazy(
533516
lazy_typet::ARRAY_WITH, equal_exprt(index_expr, value));
@@ -597,13 +580,10 @@ void arrayst::add_array_constraints_update(
597580
{
598581
index_exprt index_expr(expr, index, expr.type().subtype());
599582

600-
if(index_expr.type()!=value.type())
601-
{
602-
prop.message.log.error() << expr.pretty() << messaget::eom;
603-
DATA_INVARIANT(
604-
false,
605-
"update operand should match array element type");
606-
}
583+
DATA_INVARIANT_WITH_DIAGNOSTICS(
584+
index_expr.type()==value.type(),
585+
"update operand should match array element type",
586+
irep_pretty_diagnosticst{expr});
607587

608588
set_to_true(equal_exprt(index_expr, value));
609589
}

0 commit comments

Comments
 (0)