Skip to content

Commit 81b02e5

Browse files
committed
use typet::with_source_location
This replaces use of add_source_location() on types by typet::with_source_location.
1 parent 6341566 commit 81b02e5

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

src/verilog/verilog_typecheck_type.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,72 +28,64 @@ Function: verilog_typecheck_exprt::convert_type
2828

2929
typet verilog_typecheck_exprt::convert_type(const typet &src)
3030
{
31-
auto source_location = src.source_location();
31+
const auto &source_location = src.source_location();
3232

3333
if(src.is_nil() || src.id()==ID_reg)
3434
{
3535
// it's just a bit
36-
return bool_typet();
36+
return bool_typet().with_source_location(source_location);
3737
}
3838
else if(src.id() == ID_integer)
3939
{
40-
typet result = integer_typet();
41-
result.add_source_location() = std::move(source_location);
42-
return result;
40+
return integer_typet().with_source_location(source_location);
4341
}
4442
else if(src.id() == ID_verilog_byte)
4543
{
46-
return signedbv_typet{8};
44+
return signedbv_typet{8}.with_source_location(source_location);
4745
}
4846
else if(src.id() == ID_verilog_shortint)
4947
{
50-
return signedbv_typet{16};
48+
return signedbv_typet{16}.with_source_location(source_location);
5149
}
5250
else if(src.id() == ID_verilog_int)
5351
{
54-
return signedbv_typet{32};
52+
return signedbv_typet{32}.with_source_location(source_location);
5553
}
5654
else if(src.id() == ID_verilog_longint)
5755
{
58-
return signedbv_typet{64};
56+
return signedbv_typet{64}.with_source_location(source_location);
5957
}
6058
else if(src.id() == ID_verilog_integer)
6159
{
62-
return signedbv_typet{32};
60+
return signedbv_typet{32}.with_source_location(source_location);
6361
}
6462
else if(src.id() == ID_verilog_time)
6563
{
66-
return unsignedbv_typet{64};
64+
return unsignedbv_typet{64}.with_source_location(source_location);
6765
}
6866
else if(src.id() == ID_verilog_bit)
6967
{
70-
return unsignedbv_typet{1};
68+
return unsignedbv_typet{1}.with_source_location(source_location);
7169
}
7270
else if(src.id() == ID_verilog_logic)
7371
{
74-
return unsignedbv_typet{1};
72+
return unsignedbv_typet{1}.with_source_location(source_location);
7573
}
7674
else if(src.id() == ID_verilog_reg)
7775
{
78-
return unsignedbv_typet{1};
76+
return unsignedbv_typet{1}.with_source_location(source_location);
7977
}
8078
else if(src.id() == ID_verilog_shortreal)
8179
{
82-
typet result = verilog_shortreal_typet();
83-
result.add_source_location() = std::move(source_location);
84-
return result;
80+
return verilog_shortreal_typet().with_source_location(source_location);
8581
}
8682
else if(src.id() == ID_verilog_real)
8783
{
88-
typet result = verilog_real_typet();
89-
result.add_source_location() = std::move(source_location);
90-
return result;
84+
return verilog_real_typet().with_source_location(source_location);
9185
}
9286
else if(src.id() == ID_verilog_realtime)
9387
{
94-
typet result = verilog_realtime_typet();
95-
result.add_source_location() = std::move(source_location);
96-
return result;
88+
return verilog_realtime_typet().with_source_location(source_location);
9789
}
9890
else if(src.id() == ID_typedef_type)
9991
{
@@ -108,15 +100,17 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
108100

109101
DATA_INVARIANT(symbol_ptr->is_type, "typedef symbols must be types");
110102

111-
return symbol_ptr->type;
103+
auto result = symbol_ptr->type; // copy
104+
return result.with_source_location(source_location);
112105
}
113106
else if(src.id() == ID_verilog_enum)
114107
{
115108
// Replace by base type.
116109
// The default base type is 'int'.
117110
auto &enum_type = to_verilog_enum_type(src);
118-
return enum_type.has_base_type() ? enum_type.base_type()
119-
: signedbv_typet(32);
111+
auto result =
112+
enum_type.has_base_type() ? enum_type.base_type() : signedbv_typet(32);
113+
return result.with_source_location(source_location);
120114
}
121115
else if(src.id() == ID_array)
122116
{
@@ -149,7 +143,7 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
149143
dest.set(ID_C_little_endian, little_endian);
150144
dest.set(ID_C_offset, integer2string(offset));
151145

152-
return std::move(dest);
146+
return std::move(dest).with_source_location(source_location);
153147
}
154148
else
155149
{
@@ -161,7 +155,7 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
161155
result.add_source_location() = source_location;
162156
result.set(ID_offset, from_integer(offset, integer_typet()));
163157

164-
return std::move(result);
158+
return std::move(result).with_source_location(source_location);
165159
}
166160
}
167161
else if(src.id() == ID_verilog_type_reference)
@@ -172,7 +166,7 @@ typet verilog_typecheck_exprt::convert_type(const typet &src)
172166
// the expression is not evaluated
173167
auto expr = type_reference.expression_op();
174168
convert_expr(expr);
175-
return expr.type();
169+
return expr.type().with_source_location(source_location);
176170
}
177171
else
178172
return convert_type(type_reference.type_op());

0 commit comments

Comments
 (0)