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

Method processFilesTxt

lib/analyzerinfo.cpp:242–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242std::string AnalyzerInformation::processFilesTxt(const std::string& buildDir, const std::function<void(const char* checkattr, const tinyxml2::XMLElement* e, const Info& filesTxtInfo)>& handler, bool debug)
243{
244 const std::string filesTxt(buildDir + "/files.txt");
245 std::ifstream fin(filesTxt.c_str());
246 std::string filesTxtLine;
247 while (std::getline(fin, filesTxtLine)) {
248 AnalyzerInformation::Info filesTxtInfo;
249 if (!filesTxtInfo.parse(filesTxtLine))
250 return "failed to parse '" + filesTxtLine + "' from '" + filesTxt + "'";
251
252 if (filesTxtInfo.afile.empty())
253 return "empty afile from '" + filesTxt + "'";
254
255 const std::string xmlfile = buildDir + '/' + filesTxtInfo.afile;
256
257 tinyxml2::XMLDocument doc;
258 const tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str());
259 if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
260 /* FIXME: this can currently not be reported as an error because:
261 * - --clang does not generate any analyzer information - see #14456
262 * - markup files might not generate analyzer information
263 * - files with preprocessor errors might not generate analyzer information
264 */
265 if (debug)
266 std::cout << "'" + xmlfile + "' from '" + filesTxt + "' not found";
267 continue;
268 }
269
270 if (error != tinyxml2::XML_SUCCESS)
271 return "failed to load '" + xmlfile + "' from '" + filesTxt + "'";
272
273 const tinyxml2::XMLElement * const rootNode = doc.FirstChildElement();
274 if (rootNode == nullptr)
275 return "no root node found in '" + xmlfile + "' from '" + filesTxt + "'";
276
277 if (strcmp(rootNode->Name(), "analyzerinfo") != 0)
278 return "unexpected root node in '" + xmlfile + "' from '" + filesTxt + "'";
279
280 for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) {
281 if (std::strcmp(e->Name(), "FileInfo") != 0)
282 continue;
283 const char *checkattr = e->Attribute("check");
284 if (checkattr == nullptr) {
285 if (debug)
286 std::cout << "'check' attribute missing in 'FileInfo' in '" << xmlfile << "' from '" << filesTxt + "'";
287 continue;
288 }
289 handler(checkattr, e, filesTxtInfo);
290 }
291 }
292
293 // TODO: error on empty file?
294 return "";
295}
296
297void AnalyzerInformation::reopen(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId)
298{

Callers

nothing calls this directly

Calls 8

getlineFunction · 0.85
LoadFileMethod · 0.80
FirstChildElementMethod · 0.80
NameMethod · 0.80
NextSiblingElementMethod · 0.80
AttributeMethod · 0.80
parseMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected