MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / stringifyList

Method stringifyList

lib/token.cpp:1327–1404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1325}
1326
1327std::string Token::stringifyList(const stringifyOptions& options, const std::vector<std::string>* fileNames, const Token* end) const
1328{
1329 if (this == end)
1330 return "";
1331
1332 std::string ret;
1333
1334 unsigned int lineNumber = mImpl->mLineNumber - (options.linenumbers ? 1U : 0U);
1335 // cppcheck-suppress shadowFunction - TODO: fix this
1336 unsigned int fileIndex = options.files ? ~0U : mImpl->mFileIndex;
1337 std::map<int, unsigned int> lineNumbers;
1338 for (const Token *tok = this; tok != end; tok = tok->next()) {
1339 assert(tok && "end precedes token");
1340 if (!tok)
1341 return ret;
1342 bool fileChange = false;
1343 if (tok->mImpl->mFileIndex != fileIndex) {
1344 if (fileIndex != ~0U) {
1345 lineNumbers[fileIndex] = tok->mImpl->mFileIndex;
1346 }
1347
1348 fileIndex = tok->mImpl->mFileIndex;
1349 if (options.files) {
1350 ret += "\n\n##file ";
1351 if (fileNames && fileNames->size() > tok->mImpl->mFileIndex)
1352 ret += fileNames->at(tok->mImpl->mFileIndex);
1353 else
1354 ret += std::to_string(fileIndex);
1355 ret += '\n';
1356 }
1357
1358 lineNumber = lineNumbers[fileIndex];
1359 fileChange = true;
1360 }
1361
1362 if (options.linebreaks && (lineNumber != tok->linenr() || fileChange)) {
1363 if (lineNumber+4 < tok->linenr() && fileIndex == tok->mImpl->mFileIndex) {
1364 ret += '\n';
1365 ret += std::to_string(lineNumber+1);
1366 ret += ":\n|\n";
1367 ret += std::to_string(tok->linenr()-1);
1368 ret += ":\n";
1369 ret += std::to_string(tok->linenr());
1370 ret += ": ";
1371 } else if (this == tok && options.linenumbers) {
1372 ret += std::to_string(tok->linenr());
1373 ret += ": ";
1374 } else if (lineNumber > tok->linenr()) {
1375 lineNumber = tok->linenr();
1376 ret += '\n';
1377 if (options.linenumbers) {
1378 ret += std::to_string(lineNumber);
1379 ret += ':';
1380 ret += ' ';
1381 }
1382 } else {
1383 while (lineNumber < tok->linenr()) {
1384 ++lineNumber;

Callers 15

typeStrMethod · 0.80
checkDuplicateBranchMethod · 0.80
simplifySQLMethod · 0.80
simplifyAsmMethod · 0.80
isUniqueExpressionFunction · 0.80
tok_Method · 0.80
simplifyTypedefMethod · 0.80
simplifyTypedefPMethod · 0.80
simplifyTypedefCMethod · 0.80
tokenize_Method · 0.80
tokenizeHeader_Method · 0.80
tokenizeExpr_Method · 0.80

Calls 5

nextMethod · 0.80
atMethod · 0.80
fileIndexMethod · 0.80
sizeMethod · 0.45
stringifyMethod · 0.45

Tested by 15

tok_Method · 0.64
simplifyTypedefMethod · 0.64
simplifyTypedefPMethod · 0.64
simplifyTypedefCMethod · 0.64
tokenize_Method · 0.64
tokenizeHeader_Method · 0.64
tokenizeExpr_Method · 0.64
tokenizeAndStringify_Method · 0.64
tokenizeDebugListing_Method · 0.64
simplifyExternCMethod · 0.64