@@ -1174,44 +1174,49 @@ void Token::printLines(int lines) const
11741174 std::cout << stringifyList (stringifyOptions::forDebugExprId (), nullptr , end) << std::endl;
11751175}
11761176
1177- void Token::stringify (std::ostream & os, const stringifyOptions& options) const
1177+ void Token::stringify (std::string & os, const stringifyOptions& options) const
11781178{
11791179 if (options.attributes ) {
11801180 if (isUnsigned ())
1181- os << " unsigned " ;
1181+ os += " unsigned " ;
11821182 else if (isSigned ())
1183- os << " signed " ;
1183+ os += " signed " ;
11841184 if (isComplex ())
1185- os << " _Complex " ;
1185+ os += " _Complex " ;
11861186 if (isLong ()) {
11871187 if (!(mTokType == eString || mTokType == eChar))
1188- os << " long " ;
1188+ os += " long " ;
11891189 }
11901190 }
11911191 if (options.macro && isExpandedMacro ())
1192- os << " $ " ;
1192+ os += ' $ ' ;
11931193 if (isName () && mStr .find (' ' ) != std::string::npos) {
11941194 for (char i : mStr ) {
11951195 if (i != ' ' )
1196- os << i;
1196+ os += i;
11971197 }
11981198 } else if (mStr [0 ] != ' \" ' || mStr .find (' \0 ' ) == std::string::npos)
1199- os << mStr ;
1199+ os += mStr ;
12001200 else {
12011201 for (char i : mStr ) {
12021202 if (i == ' \0 ' )
1203- os << " \\ 0" ;
1203+ os += " \\ 0" ;
12041204 else
1205- os << i;
1205+ os += i;
12061206 }
12071207 }
1208- if (options.varid && mImpl ->mVarId != 0 )
1209- os << " @" << (options.idtype ? " var" : " " ) << mImpl ->mVarId ;
1210- else if (options.exprid && mImpl ->mExprId != 0 )
1211- os << " @" << (options.idtype ? " expr" : " " ) << mImpl ->mExprId ;
1208+ if (options.varid && mImpl ->mVarId != 0 ) {
1209+ os += ' @' ;
1210+ os += (options.idtype ? " var" : " " );
1211+ os += std::to_string (mImpl ->mVarId );
1212+ } else if (options.exprid && mImpl ->mExprId != 0 ) {
1213+ os += ' @' ;
1214+ os += (options.idtype ? " expr" : " " );
1215+ os += std::to_string (mImpl ->mExprId );
1216+ }
12121217}
12131218
1214- void Token::stringify (std::ostream & os, bool varid, bool attributes, bool macro) const
1219+ void Token::stringify (std::string & os, bool varid, bool attributes, bool macro) const
12151220{
12161221 stringifyOptions options;
12171222 options.varid = varid;
@@ -1225,7 +1230,7 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
12251230 if (this == end)
12261231 return " " ;
12271232
1228- std::ostringstream ret;
1233+ std::string ret;
12291234
12301235 unsigned int lineNumber = mImpl ->mLineNumber - (options.linenumbers ? 1U : 0U );
12311236 unsigned int fileIndex = options.files ? ~0U : mImpl ->mFileIndex ;
@@ -1239,12 +1244,12 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
12391244
12401245 fileIndex = tok->mImpl ->mFileIndex ;
12411246 if (options.files ) {
1242- ret << " \n\n ##file " ;
1247+ ret += " \n\n ##file " ;
12431248 if (fileNames && fileNames->size () > tok->mImpl ->mFileIndex )
1244- ret << fileNames->at (tok->mImpl ->mFileIndex );
1249+ ret += fileNames->at (tok->mImpl ->mFileIndex );
12451250 else
1246- ret << fileIndex;
1247- ret << ' \n ' ;
1251+ ret += std::to_string ( fileIndex) ;
1252+ ret += ' \n ' ;
12481253 }
12491254
12501255 lineNumber = lineNumbers[fileIndex];
@@ -1253,27 +1258,34 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
12531258
12541259 if (options.linebreaks && (lineNumber != tok->linenr () || fileChange)) {
12551260 if (lineNumber+4 < tok->linenr () && fileIndex == tok->mImpl ->mFileIndex ) {
1256- ret << ' \n ' << lineNumber+1 << " :\n |\n " ;
1257- ret << tok->linenr ()-1 << " :\n " ;
1258- ret << tok->linenr () << " : " ;
1261+ ret += ' \n ' ;
1262+ ret += std::to_string (lineNumber+1 );
1263+ ret += " :\n |\n " ;
1264+ ret += std::to_string (tok->linenr ()-1 );
1265+ ret += " :\n " ;
1266+ ret += std::to_string (tok->linenr ());
1267+ ret += " : " ;
12591268 } else if (this == tok && options.linenumbers ) {
1260- ret << tok->linenr () << " : " ;
1269+ ret += std::to_string (tok->linenr ());
1270+ ret += " : " ;
12611271 } else if (lineNumber > tok->linenr ()) {
12621272 lineNumber = tok->linenr ();
1263- ret << ' \n ' ;
1273+ ret += ' \n ' ;
12641274 if (options.linenumbers ) {
1265- ret << lineNumber << ' :' ;
1275+ ret += std::to_string (lineNumber);
1276+ ret += ' :' ;
12661277 if (lineNumber == tok->linenr ())
1267- ret << ' ' ;
1278+ ret += ' ' ;
12681279 }
12691280 } else {
12701281 while (lineNumber < tok->linenr ()) {
12711282 ++lineNumber;
1272- ret << ' \n ' ;
1283+ ret += ' \n ' ;
12731284 if (options.linenumbers ) {
1274- ret << lineNumber << ' :' ;
1285+ ret += std::to_string (lineNumber);
1286+ ret += ' :' ;
12751287 if (lineNumber == tok->linenr ())
1276- ret << ' ' ;
1288+ ret += ' ' ;
12771289 }
12781290 }
12791291 }
@@ -1282,11 +1294,11 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
12821294
12831295 tok->stringify (ret, options); // print token
12841296 if (tok->next () != end && (!options.linebreaks || (tok->next ()->linenr () == tok->linenr () && tok->next ()->fileIndex () == tok->fileIndex ())))
1285- ret << ' ' ;
1297+ ret += ' ' ;
12861298 }
12871299 if (options.linebreaks && (options.files || options.linenumbers ))
1288- ret << ' \n ' ;
1289- return ret. str () ;
1300+ ret += ' \n ' ;
1301+ return ret;
12901302}
12911303std::string Token::stringifyList (bool varid, bool attributes, bool linenumbers, bool linebreaks, bool files, const std::vector<std::string>* fileNames, const Token* end) const
12921304{
@@ -1472,38 +1484,38 @@ bool Token::isUnaryPreOp() const
14721484
14731485static std::string stringFromTokenRange (const Token* start, const Token* end)
14741486{
1475- std::ostringstream ret;
1487+ std::string ret;
14761488 if (end)
14771489 end = end->next ();
14781490 for (const Token *tok = start; tok && tok != end; tok = tok->next ()) {
14791491 if (tok->isUnsigned ())
1480- ret << " unsigned " ;
1492+ ret += " unsigned " ;
14811493 if (tok->isLong () && !tok->isLiteral ())
1482- ret << " long " ;
1494+ ret += " long " ;
14831495 if (tok->tokType () == Token::eString) {
14841496 for (unsigned char c: tok->str ()) {
14851497 if (c == ' \n ' )
1486- ret << " \\ n" ;
1498+ ret += " \\ n" ;
14871499 else if (c == ' \r ' )
1488- ret << " \\ r" ;
1500+ ret += " \\ r" ;
14891501 else if (c == ' \t ' )
1490- ret << " \\ t" ;
1502+ ret += " \\ t" ;
14911503 else if (c >= ' ' && c <= 126 )
1492- ret << c;
1504+ ret += c;
14931505 else {
14941506 char str[10 ];
14951507 sprintf (str, " \\ x%02x" , c);
1496- ret << str;
1508+ ret += str;
14971509 }
14981510 }
14991511 } else if (tok->originalName ().empty () || tok->isUnsigned () || tok->isLong ()) {
1500- ret << tok->str ();
1512+ ret += tok->str ();
15011513 } else
1502- ret << tok->originalName ();
1514+ ret += tok->originalName ();
15031515 if (Token::Match (tok, " %name%|%num% %name%|%num%" ))
1504- ret << ' ' ;
1516+ ret += ' ' ;
15051517 }
1506- return ret. str () ;
1518+ return ret;
15071519}
15081520
15091521std::string Token::expressionString () const
0 commit comments