Skip to content

Commit a61b25d

Browse files
committed
smv_typecheckt: use errort()
This replaces instances of "throw 0;" by "throw errort()".
1 parent d40c630 commit a61b25d

File tree

1 file changed

+64
-96
lines changed

1 file changed

+64
-96
lines changed

src/smvlang/smv_typecheck.cpp

Lines changed: 64 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,14 @@ void smv_typecheckt::instantiate(
221221

222222
if(s_it==symbol_table.symbols.end())
223223
{
224-
error().source_location=location;
225-
error() << "submodule `"
226-
<< identifier
227-
<< "' not found" << eom;
228-
throw 0;
224+
throw errort().with_location(location)
225+
<< "submodule `" << identifier << "' not found";
229226
}
230227

231228
if(s_it->second.type.id()!=ID_module)
232229
{
233-
error().source_location=location;
234-
error() << "submodule `"
235-
<< identifier
236-
<< "' not a module" << eom;
237-
throw 0;
230+
throw errort().with_location(location)
231+
<< "submodule `" << identifier << "' not a module";
238232
}
239233

240234
const irept::subt &ports=s_it->second.type.find(ID_ports).get_sub();
@@ -243,10 +237,8 @@ void smv_typecheckt::instantiate(
243237

244238
if(ports.size()!=operands.size())
245239
{
246-
error().source_location=location;
247-
error() << "submodule `" << identifier
248-
<< "' has wrong number of arguments" << eom;
249-
throw 0;
240+
throw errort().with_location(location)
241+
<< "submodule `" << identifier << "' has wrong number of arguments";
250242
}
251243

252244
std::set<irep_idt> port_identifiers;
@@ -275,12 +267,14 @@ void smv_typecheckt::instantiate(
275267

276268
if(s_it2==symbol_table.symbols.end())
277269
{
278-
error() << "symbol `" << v_it->second << "' not found" << eom;
279-
throw 0;
270+
throw errort() << "symbol `" << v_it->second << "' not found";
280271
}
281272

282-
if (port_identifiers.find(s_it2->first) != port_identifiers.end()) {
283-
} else if (s_it2->second.type.id() == ID_module) {
273+
if(port_identifiers.find(s_it2->first) != port_identifiers.end())
274+
{
275+
}
276+
else if(s_it2->second.type.id() == ID_module)
277+
{
284278
}
285279
else
286280
{
@@ -316,8 +310,7 @@ void smv_typecheckt::instantiate(
316310

317311
if(s_it2==nullptr)
318312
{
319-
error() << "symbol `" << v_id << "' not found" << eom;
320-
throw 0;
313+
throw errort() << "symbol `" << v_id << "' not found";
321314
}
322315

323316
symbolt &symbol=*s_it2;
@@ -400,10 +393,9 @@ void smv_typecheckt::instantiate_rename(
400393
}
401394
else
402395
{
403-
error().source_location=expr.find_source_location();
404-
error() << "expected symbol expression here, but got "
405-
<< to_string(it->second) << eom;
406-
throw 0;
396+
throw errort().with_location(expr.find_source_location())
397+
<< "expected symbol expression here, but got "
398+
<< to_string(it->second);
407399
}
408400
}
409401
else
@@ -431,10 +423,8 @@ void smv_typecheckt::typecheck_op(
431423
{
432424
if(expr.operands().size()==0)
433425
{
434-
error().source_location=expr.find_source_location();
435-
error() << "Expected operands for " << expr.id()
436-
<< " operator" << eom;
437-
throw 0;
426+
throw errort().with_location(expr.find_source_location())
427+
<< "Expected operands for " << expr.id() << " operator";
438428
}
439429

440430
for(auto &op : expr.operands())
@@ -497,9 +487,8 @@ smv_ranget smv_typecheckt::convert_type(const typet &src)
497487
}
498488
else
499489
{
500-
error().source_location=src.source_location();
501-
error() << "Unexpected type: `" << to_string(src) << "'" << eom;
502-
throw 0;
490+
throw errort().with_location(src.source_location())
491+
<< "Unexpected type: `" << to_string(src) << "'";
503492
}
504493

505494
return dest;
@@ -589,9 +578,8 @@ void smv_typecheckt::typecheck(
589578

590579
if(s_it==nullptr)
591580
{
592-
error().source_location=expr.find_source_location();
593-
error() << "variable `" << identifier << "' not found" << eom;
594-
throw 0;
581+
throw errort().with_location(expr.find_source_location())
582+
<< "variable `" << identifier << "' not found";
595583
}
596584

597585
symbolt &symbol=*s_it;
@@ -647,9 +635,8 @@ void smv_typecheckt::typecheck(
647635
{
648636
if(expr.operands().size()!=2)
649637
{
650-
error().source_location=expr.find_source_location();
651-
error() << "Expected two operands for -> operator" << eom;
652-
throw 0;
638+
throw errort().with_location(expr.find_source_location())
639+
<< "Expected two operands for -> operator";
653640
}
654641

655642
typecheck_op(expr, bool_typet(), mode);
@@ -663,9 +650,8 @@ void smv_typecheckt::typecheck(
663650

664651
if(expr.operands().size()!=2)
665652
{
666-
error().source_location=expr.find_source_location();
667-
error() << "Expected two operands for " << expr.id() << eom;
668-
throw 0;
653+
throw errort().with_location(expr.find_source_location())
654+
<< "Expected two operands for " << expr.id();
669655
}
670656

671657
expr.type()=bool_typet();
@@ -684,9 +670,8 @@ void smv_typecheckt::typecheck(
684670
{
685671
if(op0.type().id()!=ID_range)
686672
{
687-
error().source_location=expr.find_source_location();
688-
error() << "Expected number type for " << to_string(expr) << eom;
689-
throw 0;
673+
throw errort().with_location(expr.find_source_location())
674+
<< "Expected number type for " << to_string(expr);
690675
}
691676
}
692677
}
@@ -708,9 +693,8 @@ void smv_typecheckt::typecheck(
708693

709694
if(expr.operands().size()!=2)
710695
{
711-
error().source_location=expr.find_source_location();
712-
error() << "Expected two operands for " << expr.id() << eom;
713-
throw 0;
696+
throw errort().with_location(expr.find_source_location())
697+
<< "Expected two operands for " << expr.id();
714698
}
715699

716700
if(type.is_nil())
@@ -742,9 +726,8 @@ void smv_typecheckt::typecheck(
742726
}
743727
else if(type.id()!=ID_range)
744728
{
745-
error().source_location=expr.find_source_location();
746-
error() << "Expected number type for " << to_string(expr) << eom;
747-
throw 0;
729+
throw errort().with_location(expr.find_source_location())
730+
<< "Expected number type for " << to_string(expr);
748731
}
749732
}
750733
else if(expr.id()==ID_constant)
@@ -772,9 +755,8 @@ void smv_typecheckt::typecheck(
772755
expr=true_exprt();
773756
else
774757
{
775-
error().source_location=expr.find_source_location();
776-
error() << "expected 0 or 1 here, but got " << value << eom;
777-
throw 0;
758+
throw errort().with_location(expr.find_source_location())
759+
<< "expected 0 or 1 here, but got " << value;
778760
}
779761
}
780762
else if(type.id()==ID_range)
@@ -783,17 +765,15 @@ void smv_typecheckt::typecheck(
783765

784766
if(int_value<smv_range.from || int_value>smv_range.to)
785767
{
786-
error().source_location=expr.find_source_location();
787-
error() << "expected " << smv_range.from << ".." << smv_range.to
788-
<< " here, but got " << value << eom;
789-
throw 0;
768+
throw errort().with_location(expr.find_source_location())
769+
<< "expected " << smv_range.from << ".." << smv_range.to
770+
<< " here, but got " << value;
790771
}
791772
}
792773
else
793774
{
794-
error().source_location=expr.find_source_location();
795-
error() << "Unexpected constant: " << value << eom;
796-
throw 0;
775+
throw errort().with_location(expr.find_source_location())
776+
<< "Unexpected constant: " << value;
797777
}
798778
}
799779
}
@@ -936,9 +916,8 @@ void smv_typecheckt::typecheck(
936916
}
937917
else
938918
{
939-
error().source_location=expr.find_source_location();
940-
error() << "No type checking for " << expr.id() << eom;
941-
throw 0;
919+
throw errort().with_location(expr.find_source_location())
920+
<< "No type checking for " << expr.id();
942921
}
943922

944923
if(!type.is_nil() && expr.type()!=type)
@@ -969,12 +948,10 @@ void smv_typecheckt::typecheck(
969948
return;
970949
}
971950

972-
error().source_location=expr.find_source_location();
973-
error() << "Expected expression of type `" << to_string(type)
974-
<< "', but got expression `" << to_string(expr)
975-
<< "', which is of type `" << to_string(expr.type())
976-
<< "'" << eom;
977-
throw 0;
951+
throw errort().with_location(expr.find_source_location())
952+
<< "Expected expression of type `" << to_string(type)
953+
<< "', but got expression `" << to_string(expr) << "', which is of type `"
954+
<< to_string(expr.type()) << "'";
978955
}
979956
}
980957

@@ -996,9 +973,8 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
996973
{
997974
if(expr_mode!=NORMAL)
998975
{
999-
error().source_location=expr.find_source_location();
1000-
error() << "next(next(...)) encountered" << eom;
1001-
throw 0;
976+
throw errort().with_location(expr.find_source_location())
977+
<< "next(next(...)) encountered";
1002978
}
1003979

1004980
assert(expr.operands().size()==1);
@@ -1044,9 +1020,8 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
10441020
{
10451021
if(expr.operands().size()==0)
10461022
{
1047-
error().source_location=expr.find_source_location();
1048-
error() << "expected operand here" << eom;
1049-
throw 0;
1023+
throw errort().with_location(expr.find_source_location())
1024+
<< "expected operand here";
10501025
}
10511026

10521027
std::string identifier=
@@ -1061,10 +1036,8 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
10611036
{
10621037
if(expr.operands().size()<1)
10631038
{
1064-
error().source_location=expr.find_source_location();
1065-
error() << "Expected at least one operand for " << expr.id()
1066-
<< " expression" << eom;
1067-
throw 0;
1039+
throw errort().with_location(expr.find_source_location())
1040+
<< "Expected at least one operand for " << expr.id() << " expression";
10681041
}
10691042

10701043
exprt tmp;
@@ -1075,8 +1048,8 @@ void smv_typecheckt::convert(exprt &expr, expr_modet expr_mode)
10751048
{
10761049
if(op.operands().size() != 2)
10771050
{
1078-
error().source_location = op.find_source_location();
1079-
throw "case expected to have two operands";
1051+
throw errort().with_location(op.find_source_location())
1052+
<< "case expected to have two operands";
10801053
}
10811054

10821055
exprt &condition = to_binary_expr(op).op0();
@@ -1254,23 +1227,22 @@ Function: smv_typecheckt::collect_define
12541227
void smv_typecheckt::collect_define(const exprt &expr)
12551228
{
12561229
if(expr.id()!=ID_equal || expr.operands().size()!=2)
1257-
throw "collect_define expects equality";
1230+
throw errort() << "collect_define expects equality";
12581231

12591232
const exprt &op0 = to_equal_expr(expr).op0();
12601233
const exprt &op1 = to_equal_expr(expr).op1();
12611234

12621235
if(op0.id()!=ID_symbol)
1263-
throw "collect_define expects symbol on left hand side";
1236+
throw errort() << "collect_define expects symbol on left hand side";
12641237

1265-
const irep_idt &identifier=op0.get(ID_identifier);
1238+
const irep_idt &identifier = to_symbol_expr(op0).get_identifier();
12661239

12671240
auto it=symbol_table.get_writeable(identifier);
12681241

12691242
if(it==nullptr)
12701243
{
1271-
error() << "collect_define failed to find symbol `"
1272-
<< identifier << "'" << eom;
1273-
throw 0;
1244+
throw errort() << "collect_define failed to find symbol `" << identifier
1245+
<< "'";
12741246
}
12751247

12761248
symbolt &symbol=*it;
@@ -1285,9 +1257,8 @@ void smv_typecheckt::collect_define(const exprt &expr)
12851257

12861258
if(!result.second)
12871259
{
1288-
error().source_location=expr.find_source_location();
1289-
error() << "symbol `" << identifier << "' defined twice" << eom;
1290-
throw 0;
1260+
throw errort().with_location(expr.find_source_location())
1261+
<< "symbol `" << identifier << "' defined twice";
12911262
}
12921263
}
12931264

@@ -1311,17 +1282,15 @@ void smv_typecheckt::convert_define(const irep_idt &identifier)
13111282

13121283
if(d.in_progress)
13131284
{
1314-
error() << "definition of `" << identifier << "' is cyclic" << eom;
1315-
throw 0;
1285+
throw errort() << "definition of `" << identifier << "' is cyclic";
13161286
}
13171287

13181288
auto it=symbol_table.get_writeable(identifier);
13191289

13201290
if(it==nullptr)
13211291
{
1322-
error() << "convert_define failed to find symbol `"
1323-
<< identifier << "'" << eom;
1324-
throw 0;
1292+
throw errort() << "convert_define failed to find symbol `" << identifier
1293+
<< "'";
13251294
}
13261295

13271296
symbolt &symbol=*it;
@@ -1493,8 +1462,7 @@ void smv_typecheckt::typecheck()
14931462

14941463
if(it==smv_parse_tree.modules.end())
14951464
{
1496-
error() << "failed to find module " << module << eom;
1497-
throw 0;
1465+
throw errort() << "failed to find module " << module;
14981466
}
14991467

15001468
convert(it->second);

0 commit comments

Comments
 (0)