Skip to content

Commit 7a20ab6

Browse files
committed
Refactor type2identifier, splitting into 2 functions
In order to make the conversion from type name to type identifier unit testable in isolation.
1 parent 5a3e001 commit 7a20ab6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ansi-c/type2name.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,10 @@ std::string type2name(const typet &type, const namespacet &ns)
277277
/// If we want utilities like dump_c to work properly identifiers
278278
/// should ideally always be valid C identifiers
279279
/// This replaces some invalid characters that can appear in type2name output.
280-
std::string type2identifier(const typet &type, const namespacet &ns)
280+
std::string type_name2type_identifier(const std::string &name)
281281
{
282-
auto type2name_res = type2name(type, ns);
283282
std::string result{};
284-
for(char c : type2name_res)
283+
for(char c : name)
285284
{
286285
switch(c)
287286
{
@@ -301,3 +300,8 @@ std::string type2identifier(const typet &type, const namespacet &ns)
301300
}
302301
return result;
303302
}
303+
304+
std::string type2identifier(const typet &type, const namespacet &ns)
305+
{
306+
return type_name2type_identifier(type2name(type, ns));
307+
}

0 commit comments

Comments
 (0)