Skip to content

Commit 627a5e7

Browse files
committed
Token::stringify; refactor in/out parameter to return value
1 parent e783df6 commit 627a5e7

4 files changed

Lines changed: 27 additions & 32 deletions

File tree

lib/checkio.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,9 +1938,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
19381938
os << type->str() << "::";
19391939
type = type->tokAt(2);
19401940
}
1941-
std::string s;
1942-
type->stringify(s, false, true, false);
1943-
os << s;
1941+
os << type->stringify(false, true, false);
19441942
if (type->strAt(1) == "*" && !argInfo->element)
19451943
os << " *";
19461944
else if (argInfo->variableInfo && !argInfo->element && argInfo->variableInfo->isArray())
@@ -1957,10 +1955,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
19571955
os << type->originalName();
19581956
if (type->strAt(1) == "*" || argInfo->address)
19591957
os << " *";
1960-
os << " {aka ";
1961-
std::string s;
1962-
type->stringify(s, false, true, false);
1963-
os << s;
1958+
os << " {aka " << type->stringify(false, true, false);
19641959
if (type->strAt(1) == "*" || argInfo->address)
19651960
os << " *";
19661961
os << "}";

lib/symboldatabase.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,9 +3488,7 @@ void SymbolDatabase::printOut(const char *title) const
34883488
if (scope->type == Scope::eEnum) {
34893489
std::cout << " enumType: ";
34903490
if (scope->enumType) {
3491-
std::string s;
3492-
scope->enumType->stringify(s, false, true, false);
3493-
std::cout << s;
3491+
std::cout << scope->enumType->stringify(false, true, false);
34943492
} else
34953493
std::cout << "int";
34963494
std::cout << std::endl;

lib/token.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

12281231
std::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
}

lib/token.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,16 +887,15 @@ class CPPCHECKLIB Token {
887887
}
888888
};
889889

890-
void stringify(std::string& os, const stringifyOptions& options) const;
890+
std::string stringify(const stringifyOptions& options) const;
891891

892892
/**
893893
* Stringify a token
894-
* @param os The result is shifted into that output stream
895894
* @param varid Print varids. (Style: "varname\@id")
896895
* @param attributes Print attributes of tokens like "unsigned" in front of it.
897896
* @param macro Prints $ in front of the token if it was expanded from a macro.
898897
*/
899-
void stringify(std::string& os, bool varid, bool attributes, bool macro) const;
898+
std::string stringify(bool varid, bool attributes, bool macro) const;
900899

901900
std::string stringifyList(const stringifyOptions& options, const std::vector<std::string>* fileNames = nullptr, const Token* end = nullptr) const;
902901
std::string stringifyList(const Token* end, bool attributes = true) const;

0 commit comments

Comments
 (0)