|
25 | 25 | #include "path.h" |
26 | 26 |
|
27 | 27 | #include "checkunusedfunctions.h" |
| 28 | +#include "timer.h" |
| 29 | +#include "version.h" |
28 | 30 |
|
29 | 31 | #include <algorithm> |
30 | 32 | #include <fstream> |
31 | 33 | #include <sstream> |
32 | 34 | #include <stdexcept> |
33 | | -#include "timer.h" |
34 | | -#include "version.h" |
| 35 | +#include <tinyxml2.h> |
35 | 36 |
|
36 | 37 | #ifdef HAVE_RULES |
37 | 38 | #define PCRE_STATIC |
@@ -742,6 +743,50 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<s |
742 | 743 | return; |
743 | 744 | if (_settings.isEnabled("unusedFunction")) |
744 | 745 | CheckUnusedFunctions::analyseWholeProgram(this, buildDir); |
| 746 | + std::list<Check::FileInfo*> fileInfoList; |
| 747 | + |
| 748 | + // Load all analyzer info data.. |
| 749 | + const std::string filesTxt(buildDir + "/files.txt"); |
| 750 | + std::ifstream fin(filesTxt.c_str()); |
| 751 | + std::string filesTxtLine; |
| 752 | + while (std::getline(fin, filesTxtLine)) { |
| 753 | + const std::string::size_type firstColon = filesTxtLine.find(':'); |
| 754 | + if (firstColon == std::string::npos) |
| 755 | + continue; |
| 756 | + const std::string::size_type lastColon = filesTxtLine.rfind(':'); |
| 757 | + if (firstColon == lastColon) |
| 758 | + continue; |
| 759 | + const std::string xmlfile = buildDir + '/' + filesTxtLine.substr(0,firstColon); |
| 760 | + const std::string sourcefile = filesTxtLine.substr(lastColon+1); |
| 761 | + |
| 762 | + tinyxml2::XMLDocument doc; |
| 763 | + tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str()); |
| 764 | + if (error != tinyxml2::XML_SUCCESS) |
| 765 | + continue; |
| 766 | + |
| 767 | + const tinyxml2::XMLElement * const rootNode = doc.FirstChildElement(); |
| 768 | + if (rootNode == nullptr) |
| 769 | + continue; |
| 770 | + |
| 771 | + for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { |
| 772 | + if (std::strcmp(e->Name(), "FileInfo") != 0) |
| 773 | + continue; |
| 774 | + const char *checkClassAttr = e->Attribute("check"); |
| 775 | + if (!checkClassAttr) |
| 776 | + continue; |
| 777 | + for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { |
| 778 | + if (checkClassAttr == (*it)->name()) |
| 779 | + fileInfoList.push_back((*it)->loadFileInfoFromXml(e)); |
| 780 | + } |
| 781 | + } |
| 782 | + } |
| 783 | + |
| 784 | + // Analyse the tokens |
| 785 | + for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) |
| 786 | + (*it)->analyseWholeProgram(fileInfoList, _settings, *this); |
| 787 | + |
| 788 | + for (std::list<Check::FileInfo*>::iterator fi = fileInfoList.begin(); fi != fileInfoList.end(); ++fi) |
| 789 | + delete(*fi); |
745 | 790 | } |
746 | 791 |
|
747 | 792 | bool CppCheck::isUnusedFunctionCheckEnabled() const |
|
0 commit comments