|
20 | 20 | //--------------------------------------------------------------------------- |
21 | 21 | #include "checkunusedfunctions.h" |
22 | 22 |
|
| 23 | +#include "analyzerinfo.h" |
23 | 24 | #include "astutils.h" |
24 | 25 | #include "errorlogger.h" |
25 | 26 | #include "errortypes.h" |
|
34 | 35 | #include <algorithm> |
35 | 36 | #include <cctype> |
36 | 37 | #include <cstring> |
37 | | -#include <fstream> |
| 38 | +#include <functional> |
38 | 39 | #include <map> |
39 | 40 | #include <sstream> |
40 | 41 | #include <tuple> |
@@ -457,55 +458,31 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo |
457 | 458 | std::map<std::string, Location> decls; |
458 | 459 | std::set<std::string> calls; |
459 | 460 |
|
460 | | - const std::string filesTxt(buildDir + "/files.txt"); |
461 | | - std::ifstream fin(filesTxt.c_str()); |
462 | | - std::string filesTxtLine; |
463 | | - while (std::getline(fin, filesTxtLine)) { |
464 | | - const std::string::size_type firstColon = filesTxtLine.find(':'); |
465 | | - if (firstColon == std::string::npos) |
466 | | - continue; |
467 | | - const std::string::size_type secondColon = filesTxtLine.find(':', firstColon+1); |
468 | | - if (secondColon == std::string::npos) |
469 | | - continue; |
470 | | - const std::string xmlfile = buildDir + '/' + filesTxtLine.substr(0,firstColon); |
471 | | - const std::string sourcefile = filesTxtLine.substr(secondColon+1); |
472 | | - |
473 | | - tinyxml2::XMLDocument doc; |
474 | | - const tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str()); |
475 | | - if (error != tinyxml2::XML_SUCCESS) |
476 | | - continue; |
477 | | - |
478 | | - const tinyxml2::XMLElement * const rootNode = doc.FirstChildElement(); |
479 | | - if (rootNode == nullptr) |
480 | | - continue; |
481 | | - |
482 | | - for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { |
483 | | - if (std::strcmp(e->Name(), "FileInfo") != 0) |
| 461 | + const auto handler = [&decls, &calls](const char* checkattr, const tinyxml2::XMLElement* e, const AnalyzerInformation::Info& filesTxtInfo) { |
| 462 | + if (std::strcmp(checkattr,"CheckUnusedFunctions") != 0) |
| 463 | + return; |
| 464 | + for (const tinyxml2::XMLElement *e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { |
| 465 | + const char* functionName = e2->Attribute("functionName"); |
| 466 | + if (functionName == nullptr) |
484 | 467 | continue; |
485 | | - const char *checkattr = e->Attribute("check"); |
486 | | - if (checkattr == nullptr || std::strcmp(checkattr,"CheckUnusedFunctions") != 0) |
| 468 | + const char* name = e2->Name(); |
| 469 | + if (std::strcmp(name,"functioncall") == 0) { |
| 470 | + calls.insert(functionName); |
487 | 471 | continue; |
488 | | - for (const tinyxml2::XMLElement *e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { |
489 | | - const char* functionName = e2->Attribute("functionName"); |
490 | | - if (functionName == nullptr) |
491 | | - continue; |
492 | | - const char* name = e2->Name(); |
493 | | - if (std::strcmp(name,"functioncall") == 0) { |
494 | | - calls.insert(functionName); |
495 | | - continue; |
496 | | - } |
497 | | - if (std::strcmp(name,"functiondecl") == 0) { |
498 | | - const char* lineNumber = e2->Attribute("lineNumber"); |
499 | | - if (lineNumber) { |
500 | | - const char* file = e2->Attribute("file"); |
501 | | - const char* column = default_if_null(e2->Attribute("column"), "0"); |
502 | | - // cppcheck-suppress templateInstantiation - TODO: fix this - see #11631 |
503 | | - decls[functionName] = Location(file ? file : sourcefile, strToInt<int>(lineNumber), strToInt<int>(column)); |
504 | | - } |
| 472 | + } |
| 473 | + if (std::strcmp(name,"functiondecl") == 0) { |
| 474 | + const char* lineNumber = e2->Attribute("lineNumber"); |
| 475 | + if (lineNumber) { |
| 476 | + const char* file = e2->Attribute("file"); |
| 477 | + const char* column = default_if_null(e2->Attribute("column"), "0"); |
| 478 | + // cppcheck-suppress templateInstantiation - TODO: fix this - see #11631 |
| 479 | + decls[functionName] = Location(file ? file : filesTxtInfo.sourceFile, strToInt<int>(lineNumber), strToInt<int>(column)); |
505 | 480 | } |
506 | 481 | } |
507 | 482 | } |
508 | | - } |
| 483 | + }; |
| 484 | + |
| 485 | + AnalyzerInformation::processFilesTxt(buildDir, handler); |
509 | 486 |
|
510 | 487 | for (auto decl = decls.cbegin(); decl != decls.cend(); ++decl) { |
511 | 488 | const std::string &functionName = stripTemplateParameters(decl->first); |
|
0 commit comments