@@ -64,6 +64,34 @@ std::string linkingt::type_to_string(
64
64
65
65
/* ******************************************************************\
66
66
67
+ Function: follow_tags_symbols
68
+
69
+ Inputs:
70
+
71
+ Outputs:
72
+
73
+ Purpose:
74
+
75
+ \*******************************************************************/
76
+
77
+ static const typet &follow_tags_symbols (
78
+ const namespacet &ns,
79
+ const typet &type)
80
+ {
81
+ if (type.id ()==ID_symbol)
82
+ return ns.follow (type);
83
+ else if (type.id ()==ID_c_enum_tag)
84
+ return ns.follow_tag (to_c_enum_tag_type (type));
85
+ else if (type.id ()==ID_struct_tag)
86
+ return ns.follow_tag (to_struct_tag_type (type));
87
+ else if (type.id ()==ID_union_tag)
88
+ return ns.follow_tag (to_union_tag_type (type));
89
+ else
90
+ return type;
91
+ }
92
+
93
+ /* ******************************************************************\
94
+
67
95
Function: linkingt::type_to_string_verbose
68
96
69
97
Inputs:
@@ -79,7 +107,7 @@ std::string linkingt::type_to_string_verbose(
79
107
const symbolt &symbol,
80
108
const typet &type) const
81
109
{
82
- const typet &followed=ns. follow ( type);
110
+ const typet &followed=follow_tags_symbols (ns, type);
83
111
84
112
if (followed.id ()==ID_struct || followed.id ()==ID_union)
85
113
{
@@ -149,13 +177,13 @@ void linkingt::detailed_conflict_report_rec(
149
177
{
150
178
#ifdef DEBUG
151
179
str << " <BEGIN DEPTH " << depth << " >" ;
152
- debug ();
180
+ debug_msg ();
153
181
#endif
154
182
155
183
std::string msg;
156
184
157
- const typet &t1=ns. follow ( type1);
158
- const typet &t2=ns. follow ( type2);
185
+ const typet &t1=follow_tags_symbols (ns, type1);
186
+ const typet &t2=follow_tags_symbols (ns, type2);
159
187
160
188
if (t1.id ()!=t2.id ())
161
189
msg=" type classes differ" ;
@@ -231,6 +259,49 @@ void linkingt::detailed_conflict_report_rec(
231
259
}
232
260
}
233
261
}
262
+ else if (t1.id ()==ID_c_enum)
263
+ {
264
+ const c_enum_typet::memberst &members1=
265
+ to_c_enum_type (t1).members ();
266
+
267
+ const c_enum_typet::memberst &members2=
268
+ to_c_enum_type (t2).members ();
269
+
270
+ if (t1.subtype ()!=t2.subtype ())
271
+ {
272
+ msg=" enum value types are different (" ;
273
+ msg+=type_to_string (ns, old_symbol.name , t1.subtype ())+' /' ;
274
+ msg+=type_to_string (ns, new_symbol.name , t2.subtype ())+' )' ;
275
+ }
276
+ else if (members1.size ()!=members2.size ())
277
+ {
278
+ msg=" number of enum members is different (" ;
279
+ msg+=i2string (members1.size ())+' /' ;
280
+ msg+=i2string (members2.size ())+' )' ;
281
+ }
282
+ else
283
+ for (std::size_t i=0 ; i<members1.size (); ++i)
284
+ {
285
+ if (members1[i].get_base_name ()!=members2[i].get_base_name ())
286
+ {
287
+ msg=" names of member " +i2string (i)+" differ (" ;
288
+ msg+=id2string (members1[i].get_base_name ())+' /' ;
289
+ msg+=id2string (members2[i].get_base_name ())+' )' ;
290
+ break ;
291
+ }
292
+ else if (members1[i].get_value ()!=members2[i].get_value ())
293
+ {
294
+ msg=" values of member " +i2string (i)+" differ (" ;
295
+ msg+=id2string (members1[i].get_value ())+' /' ;
296
+ msg+=id2string (members2[i].get_value ())+' )' ;
297
+ break ;
298
+ }
299
+ }
300
+
301
+ msg+=" \n enum declarations at\n " ;
302
+ msg+=t1.source_location ().as_string ()+" and\n " ;
303
+ msg+=t1.source_location ().as_string ();
304
+ }
234
305
else if (t1.id ()==ID_code)
235
306
{
236
307
const code_typet::parameterst ¶meters1=
@@ -309,7 +380,7 @@ void linkingt::detailed_conflict_report_rec(
309
380
310
381
#ifdef DEBUG
311
382
str << " <END DEPTH " << depth << " >" ;
312
- debug ();
383
+ debug_msg ();
313
384
#endif
314
385
}
315
386
@@ -527,8 +598,8 @@ void linkingt::duplicate_code_symbol(
527
598
528
599
while (!conflicts.empty ())
529
600
{
530
- const typet &t1=ns. follow ( conflicts.front ().first );
531
- const typet &t2=ns. follow ( conflicts.front ().second );
601
+ const typet &t1=follow_tags_symbols (ns, conflicts.front ().first );
602
+ const typet &t2=follow_tags_symbols (ns, conflicts.front ().second );
532
603
533
604
// void vs. non-void return type may be acceptable if the
534
605
// return value is never used
@@ -555,7 +626,8 @@ void linkingt::duplicate_code_symbol(
555
626
old_symbol.value .is_nil ()!=new_symbol.value .is_nil ())
556
627
{
557
628
if (warn_msg.empty ())
558
- warn_msg=" different pointer types in function" ;
629
+ warn_msg=" pointer parameter types differ between "
630
+ " declaration and definition" ;
559
631
replace=new_symbol.value .is_not_nil ();
560
632
}
561
633
// transparent union with (or entirely without) implementation is
@@ -736,10 +808,12 @@ void linkingt::duplicate_object_symbol(
736
808
}
737
809
else
738
810
{
739
- // provide additional diagnostic output for struct/union/array
811
+ // provide additional diagnostic output for
812
+ // struct/union/array/enum
740
813
if (old_type.id ()==ID_struct ||
741
814
old_type.id ()==ID_union ||
742
- old_type.id ()==ID_array)
815
+ old_type.id ()==ID_array ||
816
+ old_type.id ()==ID_c_enum)
743
817
detailed_conflict_report (
744
818
old_symbol,
745
819
new_symbol,
@@ -1040,8 +1114,8 @@ void linkingt::do_type_dependencies(id_sett &needs_to_be_renamed)
1040
1114
{
1041
1115
queue.push (*d_it);
1042
1116
#ifdef DEBUG
1043
- str << " LINKING: needs to be renamed (dependency): " << s_it-> first ;
1044
- debug ();
1117
+ str << " LINKING: needs to be renamed (dependency): " << *d_it ;
1118
+ debug_msg ();
1045
1119
#endif
1046
1120
}
1047
1121
}
@@ -1061,20 +1135,28 @@ Function: linkingt::rename_symbols
1061
1135
1062
1136
void linkingt::rename_symbols (const id_sett &needs_to_be_renamed)
1063
1137
{
1138
+ namespacet src_ns (src_symbol_table);
1139
+
1064
1140
for (id_sett::const_iterator
1065
1141
it=needs_to_be_renamed.begin ();
1066
1142
it!=needs_to_be_renamed.end ();
1067
1143
it++)
1068
1144
{
1069
1145
symbolt &new_symbol=src_symbol_table.symbols [*it];
1070
1146
1071
- irep_idt new_identifier=rename (*it);
1147
+ irep_idt new_identifier;
1148
+
1149
+ if (new_symbol.is_type )
1150
+ new_identifier=type_to_name (src_ns, *it, new_symbol.type );
1151
+ else
1152
+ new_identifier=rename (*it);
1153
+
1072
1154
new_symbol.name =new_identifier;
1073
1155
1074
1156
#ifdef DEBUG
1075
1157
str << " LINKING: renaming " << *it << " to "
1076
1158
<< new_identifier;
1077
- debug ();
1159
+ debug_msg ();
1078
1160
#endif
1079
1161
1080
1162
if (new_symbol.is_type )
@@ -1182,7 +1264,7 @@ void linkingt::typecheck()
1182
1264
needs_to_be_renamed.insert (s_it->first );
1183
1265
#ifdef DEBUG
1184
1266
str << " LINKING: needs to be renamed: " << s_it->first ;
1185
- debug ();
1267
+ debug_msg ();
1186
1268
#endif
1187
1269
}
1188
1270
}
0 commit comments