@@ -1174,55 +1174,58 @@ void Token::printLines(int lines) const
11741174 std::cout << stringifyList (stringifyOptions::forDebugExprId (), nullptr , end) << std::endl;
11751175}
11761176
1177- void Token::stringify (std::string& os, const stringifyOptions& options) const
1177+ std::string Token::stringify (const stringifyOptions& options) const
11781178{
1179+ std::string ret;
11791180 if (options.attributes ) {
11801181 if (isUnsigned ())
1181- os += " unsigned " ;
1182+ ret += " unsigned " ;
11821183 else if (isSigned ())
1183- os += " signed " ;
1184+ ret += " signed " ;
11841185 if (isComplex ())
1185- os += " _Complex " ;
1186+ ret += " _Complex " ;
11861187 if (isLong ()) {
11871188 if (!(mTokType == eString || mTokType == eChar))
1188- os += " long " ;
1189+ ret += " long " ;
11891190 }
11901191 }
11911192 if (options.macro && isExpandedMacro ())
1192- os += ' $' ;
1193+ ret += ' $' ;
11931194 if (isName () && mStr .find (' ' ) != std::string::npos) {
11941195 for (char i : mStr ) {
11951196 if (i != ' ' )
1196- os += i;
1197+ ret += i;
11971198 }
11981199 } else if (mStr [0 ] != ' \" ' || mStr .find (' \0 ' ) == std::string::npos)
1199- os += mStr ;
1200+ ret += mStr ;
12001201 else {
12011202 for (char i : mStr ) {
12021203 if (i == ' \0 ' )
1203- os += " \\ 0" ;
1204+ ret += " \\ 0" ;
12041205 else
1205- os += i;
1206+ ret += i;
12061207 }
12071208 }
12081209 if (options.varid && mImpl ->mVarId != 0 ) {
1209- os += ' @' ;
1210- os += (options.idtype ? " var" : " " );
1211- os += std::to_string (mImpl ->mVarId );
1210+ ret += ' @' ;
1211+ ret += (options.idtype ? " var" : " " );
1212+ ret += std::to_string (mImpl ->mVarId );
12121213 } else if (options.exprid && mImpl ->mExprId != 0 ) {
1213- os += ' @' ;
1214- os += (options.idtype ? " expr" : " " );
1215- os += std::to_string (mImpl ->mExprId );
1214+ ret += ' @' ;
1215+ ret += (options.idtype ? " expr" : " " );
1216+ ret += std::to_string (mImpl ->mExprId );
12161217 }
1218+
1219+ return ret;
12171220}
12181221
1219- void Token::stringify (std::string& os, bool varid, bool attributes, bool macro) const
1222+ std::string Token::stringify (bool varid, bool attributes, bool macro) const
12201223{
12211224 stringifyOptions options;
12221225 options.varid = varid;
12231226 options.attributes = attributes;
12241227 options.macro = macro;
1225- stringify (os, options);
1228+ return stringify (options);
12261229}
12271230
12281231std::string Token::stringifyList (const stringifyOptions& options, const std::vector<std::string>* fileNames, const Token* end) const
@@ -1292,7 +1295,7 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
12921295 lineNumber = tok->linenr ();
12931296 }
12941297
1295- tok->stringify (ret, options); // print token
1298+ ret += tok->stringify (options); // print token
12961299 if (tok->next () != end && (!options.linebreaks || (tok->next ()->linenr () == tok->linenr () && tok->next ()->fileIndex () == tok->fileIndex ())))
12971300 ret += ' ' ;
12981301 }
0 commit comments