Skip to content

Commit df2274a

Browse files
authored
Merge pull request #400 from diffblue/verilog-throw-0
Verilog: use `errort()` instead of `throw 0`
2 parents e684b79 + bddffde commit df2274a

8 files changed

+50
-80
lines changed

src/verilog/verilog_elaborate.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,8 @@ void verilog_typecheckt::collect_symbols(const verilog_declt &decl)
433433

434434
if(osymbol.type.id() == ID_code)
435435
{
436-
error().source_location = decl.source_location();
437-
error() << "symbol `" << symbol.base_name << "' is already declared"
438-
<< eom;
439-
throw 0;
436+
throw errort().with_location(decl.source_location())
437+
<< "symbol `" << symbol.base_name << "' is already declared";
440438
}
441439

442440
// change of type?
@@ -895,9 +893,7 @@ void verilog_typecheckt::elaborate_symbol_rec(irep_idt identifier)
895893
}
896894
else if(symbol.type.id() == ID_elaborating)
897895
{
898-
error().source_location = symbol.location;
899-
error() << "cyclic dependency when elaborating " << symbol.display_name()
900-
<< eom;
901-
throw 0;
896+
throw errort().with_location(symbol.location)
897+
<< "cyclic dependency when elaborating " << symbol.display_name();
902898
}
903899
}

src/verilog/verilog_generate.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ void verilog_typecheckt::elaborate_generate_if(
135135
if(statement.operands().size()!=3 &&
136136
statement.operands().size()!=2)
137137
{
138-
error().source_location = statement.source_location();
139-
error() << "generate_if expects two or three operands" << eom;
140-
throw 0;
138+
throw errort().with_location(statement.source_location())
139+
<< "generate_if expects two or three operands";
141140
}
142141

143142
mp_integer condition =
@@ -172,9 +171,8 @@ void verilog_typecheckt::elaborate_generate_assign(
172171
{
173172
if(statement.lhs().id() != ID_symbol)
174173
{
175-
error().source_location = statement.lhs().source_location();
176-
error() << "expected symbol on left hand side of assignment" << eom;
177-
throw 0;
174+
throw errort().with_location(statement.lhs().source_location())
175+
<< "expected symbol on left hand side of assignment";
178176
}
179177

180178
const irep_idt &identifier = to_symbol_expr(statement.lhs()).get_identifier();
@@ -183,18 +181,16 @@ void verilog_typecheckt::elaborate_generate_assign(
183181

184182
if(it==genvars.end())
185183
{
186-
error().source_location = statement.lhs().source_location();
187-
error() << "expected genvar on left hand side of assignment" << eom;
188-
throw 0;
184+
throw errort().with_location(statement.lhs().source_location())
185+
<< "expected genvar on left hand side of assignment";
189186
}
190187

191188
mp_integer rhs = convert_integer_constant_expression(statement.rhs());
192189

193190
if(rhs<0)
194191
{
195-
error().source_location = statement.rhs().source_location();
196-
error() << "must not assign negative value to genvar" << eom;
197-
throw 0;
192+
throw errort().with_location(statement.rhs().source_location())
193+
<< "must not assign negative value to genvar";
198194
}
199195

200196
it->second=rhs;
@@ -222,9 +218,8 @@ exprt verilog_typecheckt::generate_for_loop_index(
222218
}
223219
else
224220
{
225-
error().source_location = initialization_statement.source_location();
226-
error() << "failed to determine generate loop index" << eom;
227-
throw 0;
221+
throw errort().with_location(initialization_statement.source_location())
222+
<< "failed to determine generate loop index";
228223
}
229224
}
230225

src/verilog/verilog_interfaces.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ void verilog_typecheckt::check_module_ports(
121121
if(symbol.is_input || symbol.is_output)
122122
if(port_names.find(symbol.base_name)==port_names.end())
123123
{
124-
error().source_location=symbol.location;
125-
error() << "port `" << symbol.base_name
126-
<< "' not in port list" << eom;
127-
throw 0;
124+
throw errort().with_location(symbol.location)
125+
<< "port `" << symbol.base_name << "' not in port list";
128126
}
129127
}
130128
}
@@ -190,11 +188,9 @@ void verilog_typecheckt::interface_inst(
190188

191189
if(symbol_table.add(symbol))
192190
{
193-
error().source_location = op.source_location();
194-
error() << "duplicate definition of identifier `"
195-
<< symbol.base_name << "' in module `"
196-
<< module_symbol.base_name << '\'' << eom;
197-
throw 0;
191+
throw errort().with_location(op.source_location())
192+
<< "duplicate definition of identifier `" << symbol.base_name
193+
<< "' in module `" << module_symbol.base_name << '\'';
198194
}
199195
}
200196

@@ -316,8 +312,8 @@ void verilog_typecheckt::interface_statement(
316312
{
317313
if(statement.operands().size()!=2)
318314
{
319-
error() << "event_guard expected to have two operands" << eom;
320-
throw 0;
315+
throw errort().with_location(statement.source_location())
316+
<< "event_guard expected to have two operands";
321317
}
322318

323319
interface_statement(
@@ -327,8 +323,8 @@ void verilog_typecheckt::interface_statement(
327323
{
328324
if(statement.operands().size()!=2)
329325
{
330-
error() << "delay expected to have two operands" << eom;
331-
throw 0;
326+
throw errort().with_location(statement.source_location())
327+
<< "delay expected to have two operands";
332328
}
333329

334330
interface_statement(
@@ -382,11 +378,9 @@ void verilog_typecheckt::interface_block(
382378

383379
if(symbol_table.add(symbol))
384380
{
385-
error().source_location = statement.source_location();
386-
error() << "duplicate definition of identifier `"
387-
<< symbol.base_name << "' in module `"
388-
<< module_symbol.base_name << '\'' << eom;
389-
throw 0;
381+
throw errort().with_location(statement.source_location())
382+
<< "duplicate definition of identifier `" << symbol.base_name
383+
<< "' in module `" << module_symbol.base_name << '\'';
390384
}
391385

392386
enter_named_block(base_name);

src/verilog/verilog_interpreter.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ void verilog_typecheckt::verilog_interpreter(
3434
exprt rhs = elaborate_constant_expression(assign.rhs());
3535
if(!rhs.is_constant())
3636
{
37-
error().source_location=assign.rhs().source_location();
38-
error() << "right-hand side of assignment is not constant" << eom;
39-
throw 0;
37+
throw errort().with_location(assign.rhs().source_location())
38+
<< "right-hand side of assignment is not constant";
4039
}
4140

4241
if(assign.lhs().id()==ID_symbol)
@@ -76,9 +75,8 @@ void verilog_typecheckt::verilog_interpreter(
7675

7776
if(to_integer_non_constant(cond, cond_i))
7877
{
79-
error().source_location=verilog_for.source_location();
80-
error() << "for condition is not constant: " << cond.pretty() << eom;
81-
throw 0;
78+
throw errort().with_location(verilog_for.source_location())
79+
<< "for condition is not constant: " << cond.pretty();
8280
}
8381

8482
if(cond_i==0) break;
@@ -90,9 +88,7 @@ void verilog_typecheckt::verilog_interpreter(
9088
}
9189
else
9290
{
93-
error().source_location=statement.source_location();
94-
error() << "Don't know how to interpret statement `"
95-
<< statement.id() << '\'' << eom;
96-
throw 0;
91+
throw errort().with_location(statement.source_location())
92+
<< "Don't know how to interpret statement `" << statement.id() << '\'';
9793
}
9894
}

src/verilog/verilog_parameterize_module.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ std::list<exprt> verilog_typecheckt::get_parameter_values(
129129

130130
if(p_it!=parameter_assignment.end())
131131
{
132-
error().source_location = p_it->source_location();
133-
error() << "too many parameter assignments" << eom;
134-
throw 0;
132+
throw errort().with_location(p_it->source_location())
133+
<< "too many parameter assignments";
135134
}
136135
}
137136

@@ -218,12 +217,8 @@ irep_idt verilog_typecheckt::parameterize_module(
218217
symbol_table.symbols.find(module_identifier);
219218

220219
if(it==symbol_table.symbols.end())
221-
{
222-
error().source_location=location;
223-
error() << "module not found" << eom;
224-
throw 0;
225-
}
226-
220+
throw errort().with_location(location) << "module not found";
221+
227222
const symbolt &base_symbol=it->second;
228223

229224
auto parameter_values = get_parameter_values(
@@ -249,10 +244,9 @@ irep_idt verilog_typecheckt::parameterize_module(
249244
mp_integer i;
250245
if(to_integer_non_constant(pv, i))
251246
{
252-
error().source_location = pv.source_location();
253-
error() << "parameter value expected to be constant, but got `"
254-
<< to_string(pv) << "'" << eom;
255-
throw 0;
247+
throw errort().with_location(pv.source_location())
248+
<< "parameter value expected to be constant, but got `"
249+
<< to_string(pv) << "'";
256250
}
257251
else
258252
suffix += integer2string(i);
@@ -288,10 +282,8 @@ irep_idt verilog_typecheckt::parameterize_module(
288282

289283
if(symbol_table.move(symbol, new_symbol))
290284
{
291-
error().source_location=location;
292-
error() << "duplicate definition of parameterized module "
293-
<< symbol.base_name << eom;
294-
throw 0;
285+
throw errort().with_location(location)
286+
<< "duplicate definition of parameterized module " << symbol.base_name;
295287
}
296288

297289
// recursive call

src/verilog/verilog_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ bool verilog_typecheck(
18211821
messaget message(message_handler);
18221822
message.error() << "duplicate definition of module "
18231823
<< symbol.base_name << messaget::eom;
1824-
throw 0;
1824+
return true;
18251825
}
18261826

18271827
verilog_typecheckt verilog_typecheck(*new_symbol, symbol_table, message_handler);

src/verilog/verilog_typecheck_base.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ mp_integer verilog_typecheck_baset::array_size(const array_typet &type)
122122

123123
if(!size_opt.has_value())
124124
{
125-
error() << "failed to get array size of array type" << eom;
126-
throw 0;
125+
throw errort().with_location(type.source_location())
126+
<< "failed to get array size of array type";
127127
}
128128

129129
return size_opt.value();
@@ -148,9 +148,8 @@ mp_integer verilog_typecheck_baset::array_offset(const array_typet &type)
148148
if(to_integer_non_constant(
149149
static_cast<const exprt &>(type.find(ID_offset)), offset))
150150
{
151-
error() << "failed to get array offset of type `"
152-
<< type.id() << '\'' << eom;
153-
throw 0;
151+
throw errort().with_location(type.source_location())
152+
<< "failed to get array offset of type `" << type.id() << '\'';
154153
}
155154

156155
return offset;
@@ -194,9 +193,8 @@ std::size_t verilog_typecheck_baset::get_width(const typet &type)
194193
else if(type.id() == ID_verilog_time)
195194
return 64;
196195

197-
error() << "type `" << type.id() << "' has unknown width"
198-
<< eom;
199-
throw 0;
196+
throw errort().with_location(type.source_location())
197+
<< "type `" << type.id() << "' has unknown width";
200198
}
201199

202200
/*******************************************************************\

src/verilog/verilog_typecheck_type.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
182182
}
183183
else
184184
{
185-
error().source_location = source_location;
186-
error() << "unexpected type: `" << src.id() << "'" << eom;
187-
throw 0;
185+
throw errort().with_location(source_location)
186+
<< "unexpected type: `" << src.id() << "'";
188187
}
189188
}

0 commit comments

Comments
 (0)