Skip to content

Commit d695563

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
irep2name: return std::string by value
This simplifies the contract and code, and should be at least as efficient in C++11.
1 parent e2b42b8 commit d695563

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/cpp/cpp_type2name.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ static std::string do_prefix(const std::string &s)
2626
return s;
2727
}
2828

29-
static void irep2name(const irept &irep, std::string &result)
29+
static std::string irep2name(const irept &irep)
3030
{
31-
result="";
31+
std::string result;
3232

3333
if(is_reference(static_cast<const typet&>(irep)))
3434
result+="reference";
@@ -48,7 +48,7 @@ static void irep2name(const irept &irep, std::string &result)
4848
result+=do_prefix(irep.id_string());
4949

5050
if(irep.get_named_sub().empty() && irep.get_sub().empty())
51-
return;
51+
return result;
5252

5353
result+='(';
5454
bool first=true;
@@ -64,9 +64,7 @@ static void irep2name(const irept &irep, std::string &result)
6464
result += do_prefix(name2string(it->first));
6565

6666
result += '=';
67-
std::string tmp;
68-
irep2name(it->second, tmp);
69-
result += tmp;
67+
result += irep2name(it->second);
7068
}
7169

7270
forall_named_irep(it, irep.get_named_sub())
@@ -80,9 +78,7 @@ static void irep2name(const irept &irep, std::string &result)
8078
result+=',';
8179
result+=do_prefix(name2string(it->first));
8280
result+='=';
83-
std::string tmp;
84-
irep2name(it->second, tmp);
85-
result+=tmp;
81+
result += irep2name(it->second);
8682
}
8783

8884
forall_irep(it, irep.get_sub())
@@ -91,12 +87,12 @@ static void irep2name(const irept &irep, std::string &result)
9187
first=false;
9288
else
9389
result+=',';
94-
std::string tmp;
95-
irep2name(*it, tmp);
96-
result+=tmp;
90+
result += irep2name(*it);
9791
}
9892

9993
result+=')';
94+
95+
return result;
10096
}
10197

10298
std::string cpp_type2name(const typet &type)
@@ -175,17 +171,13 @@ std::string cpp_type2name(const typet &type)
175171
else
176172
{
177173
// give up
178-
std::string tmp;
179-
irep2name(type, tmp);
180-
return tmp;
174+
return irep2name(type);
181175
}
182176

183177
return result;
184178
}
185179

186180
std::string cpp_expr2name(const exprt &expr)
187181
{
188-
std::string tmp;
189-
irep2name(expr, tmp);
190-
return tmp;
182+
return irep2name(expr);
191183
}

0 commit comments

Comments
 (0)