Skip to content

Commit 2b8ef3c

Browse files
committed
Handle ID_cpp_name in expr2cppt
While typechecking is still in progress, tags may still be cpp names. For debugging purposes it's useful to print their underlying names.
1 parent bfc11dc commit 2b8ef3c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/cpp/expr2cpp.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Author: Daniel Kroening, [email protected]
2121
#include <ansi-c/c_qualifiers.h>
2222
#include <ansi-c/expr2c_class.h>
2323

24+
#include "cpp_name.h"
25+
2426
class expr2cppt:public expr2ct
2527
{
2628
public:
@@ -169,6 +171,51 @@ std::string expr2cppt::convert_rec(
169171

170172
return dest;
171173
}
174+
else if(src.id() == ID_struct_tag)
175+
{
176+
const struct_typet &struct_type = ns.follow_tag(to_struct_tag_type(src));
177+
178+
std::string dest = q;
179+
180+
if(src.get_bool(ID_C_class))
181+
dest += "class";
182+
else if(src.get_bool(ID_C_interface))
183+
dest += "__interface"; // MS-specific
184+
else
185+
dest += "struct";
186+
187+
const irept &tag = struct_type.find(ID_tag);
188+
if(!tag.id().empty())
189+
{
190+
if(tag.id() == ID_cpp_name)
191+
dest += " " + to_cpp_name(tag).to_string();
192+
else
193+
dest += id2string(tag.id());
194+
}
195+
196+
dest += d;
197+
198+
return dest;
199+
}
200+
else if(src.id() == ID_union_tag)
201+
{
202+
const union_typet &union_type = ns.follow_tag(to_union_tag_type(src));
203+
204+
std::string dest = q + "union";
205+
206+
const irept &tag = union_type.find(ID_tag);
207+
if(!tag.id().empty())
208+
{
209+
if(tag.id() == ID_cpp_name)
210+
dest += " " + to_cpp_name(tag).to_string();
211+
else
212+
dest += id2string(tag.id());
213+
}
214+
215+
dest += d;
216+
217+
return dest;
218+
}
172219
else if(src.id()==ID_constructor)
173220
{
174221
return "constructor ";

0 commit comments

Comments
 (0)