@@ -331,16 +331,16 @@ static std::vector<std::string> split(const std::string &str, const std::string
331331 return ret;
332332}
333333
334- static std::string getDumpFileName (const Settings& settings, const std::string& filename)
334+ static std::string getDumpFileName (const Settings& settings, const std::string& filename, int fileIndex )
335335{
336- std::string extension;
337- if (settings. dump || !settings. buildDir . empty () )
338- extension = " .dump " ;
339- else
340- extension = " ." + std::to_string (settings.pid ) + " .dump " ;
336+ std::string extension = " .dump " ;
337+ if (fileIndex > 0 )
338+ extension = " ." + std::to_string (fileIndex) + extension ;
339+ if (!settings. dump && settings. buildDir . empty ())
340+ extension = " ." + std::to_string (settings.pid ) + extension ;
341341
342342 if (!settings.dump && !settings.buildDir .empty ())
343- return AnalyzerInformation::getAnalyzerInfoFile (settings.buildDir , filename, " " ) + extension;
343+ return AnalyzerInformation::getAnalyzerInfoFile (settings.buildDir , filename, " " , fileIndex ) + extension;
344344 return filename + extension;
345345}
346346
@@ -351,12 +351,13 @@ static std::string getCtuInfoFileName(const std::string &dumpFile)
351351
352352static void createDumpFile (const Settings& settings,
353353 const FileWithDetails& file,
354+ int fileIndex,
354355 std::ofstream& fdump,
355356 std::string& dumpFile)
356357{
357358 if (!settings.dump && settings.addons .empty ())
358359 return ;
359- dumpFile = getDumpFileName (settings, file.spath ());
360+ dumpFile = getDumpFileName (settings, file.spath (), fileIndex );
360361
361362 fdump.open (dumpFile);
362363 if (!fdump.is_open ())
@@ -649,7 +650,7 @@ static std::string getClangFlags(const Settings& setting, Standards::Language la
649650}
650651
651652// TODO: clear error list before returning
652- unsigned int CppCheck::checkClang (const FileWithDetails &file)
653+ unsigned int CppCheck::checkClang (const FileWithDetails &file, int fileIndex )
653654{
654655 // TODO: clear exitcode
655656
@@ -662,7 +663,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
662663 // TODO: get language from FileWithDetails object
663664 std::string clangStderr;
664665 if (!mSettings .buildDir .empty ())
665- clangStderr = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , file.spath (), " " ) + " .clang-stderr" ;
666+ clangStderr = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , file.spath (), " " , fileIndex ) + " .clang-stderr" ;
666667
667668 std::string exe = mSettings .clangExecutable ;
668669#ifdef _WIN32
@@ -731,7 +732,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
731732 // create dumpfile
732733 std::ofstream fdump;
733734 std::string dumpFile;
734- createDumpFile (mSettings , file, fdump, dumpFile);
735+ createDumpFile (mSettings , file, fileIndex, fdump, dumpFile);
735736 if (fdump.is_open ()) {
736737 fdump << getLibraryDumpData ();
737738 // TODO: use tinyxml2 to create XML
@@ -775,9 +776,9 @@ unsigned int CppCheck::check(const FileWithDetails &file)
775776
776777 unsigned int returnValue;
777778 if (mSettings .clang )
778- returnValue = checkClang (file);
779+ returnValue = checkClang (file, 0 );
779780 else
780- returnValue = checkFile (file, " " );
781+ returnValue = checkFile (file, " " , 0 );
781782
782783 // TODO: call analyseClangTidy()
783784
@@ -787,7 +788,7 @@ unsigned int CppCheck::check(const FileWithDetails &file)
787788unsigned int CppCheck::check (const FileWithDetails &file, const std::string &content)
788789{
789790 std::istringstream iss (content);
790- return checkFile (file, " " , &iss);
791+ return checkFile (file, " " , 0 , &iss);
791792}
792793
793794unsigned int CppCheck::check (const FileSettings &fs)
@@ -823,7 +824,7 @@ unsigned int CppCheck::check(const FileSettings &fs)
823824 }
824825 // need to pass the externally provided ErrorLogger instead of our internal wrapper
825826 CppCheck temp (tempSettings, mSuppressions , mErrorLoggerDirect , mUseGlobalSuppressions , mExecuteCommand );
826- const unsigned int returnValue = temp.checkFile (fs.file , fs.cfg );
827+ const unsigned int returnValue = temp.checkFile (fs.file , fs.cfg , fs. fileIndex );
827828 if (mUnusedFunctionsCheck )
828829 mUnusedFunctionsCheck ->updateFunctionData (*temp.mUnusedFunctionsCheck );
829830 while (!temp.mFileInfo .empty ()) {
@@ -860,7 +861,7 @@ static std::size_t calculateHash(const Preprocessor& preprocessor, const simplec
860861 return preprocessor.calculateHash (tokens, toolinfo.str ());
861862}
862863
863- unsigned int CppCheck::checkFile (const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream)
864+ unsigned int CppCheck::checkFile (const FileWithDetails& file, const std::string &cfgname, int fileIndex, std::istream* fileStream)
864865{
865866 // TODO: move to constructor when CppCheck no longer owns the settings
866867 if (mSettings .checks .isEnabled (Checks::unusedFunction) && !mUnusedFunctionsCheck )
@@ -937,7 +938,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
937938 mLogger ->setAnalyzerInfo (nullptr );
938939
939940 std::list<ErrorMessage> errors;
940- analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors);
941+ analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, fileIndex, hash, errors);
941942 analyzerInformation->setFileInfo (" CheckUnusedFunctions" , mUnusedFunctionsCheck ->analyzerInfo (tokenizer));
942943 analyzerInformation->close ();
943944 }
@@ -1011,7 +1012,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
10111012 // Calculate hash so it can be compared with old hash / future hashes
10121013 const std::size_t hash = calculateHash (preprocessor, tokens1, mSettings , mSuppressions );
10131014 std::list<ErrorMessage> errors;
1014- if (!analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors)) {
1015+ if (!analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, fileIndex, hash, errors)) {
10151016 while (!errors.empty ()) {
10161017 mErrorLogger .reportErr (errors.front ());
10171018 errors.pop_front ();
@@ -1074,7 +1075,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
10741075 // write dump file xml prolog
10751076 std::ofstream fdump;
10761077 std::string dumpFile;
1077- createDumpFile (mSettings , file, fdump, dumpFile);
1078+ createDumpFile (mSettings , file, fileIndex, fdump, dumpFile);
10781079 if (fdump.is_open ()) {
10791080 fdump << getLibraryDumpData ();
10801081 fdump << dumpProlog;
@@ -1169,7 +1170,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
11691170#endif
11701171
11711172 // Simplify tokens into normal form, skip rest of iteration if failed
1172- if (!tokenizer.simplifyTokens1 (currentConfig))
1173+ if (!tokenizer.simplifyTokens1 (currentConfig, fileIndex ))
11731174 continue ;
11741175
11751176 // dump xml if --dump
@@ -1811,12 +1812,12 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
18111812
18121813 std::vector<std::string> ctuInfoFiles;
18131814 for (const auto &f: files) {
1814- const std::string &dumpFileName = getDumpFileName (mSettings , f.path ());
1815+ const std::string &dumpFileName = getDumpFileName (mSettings , f.path (), 0 );
18151816 ctuInfoFiles.push_back (getCtuInfoFileName (dumpFileName));
18161817 }
18171818
18181819 for (const auto &f: fileSettings) {
1819- const std::string &dumpFileName = getDumpFileName (mSettings , f.filename ());
1820+ const std::string &dumpFileName = getDumpFileName (mSettings , f.filename (), f. fileIndex );
18201821 ctuInfoFiles.push_back (getCtuInfoFileName (dumpFileName));
18211822 }
18221823
@@ -1943,7 +1944,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
19431944 std::string line;
19441945
19451946 if (!mSettings .buildDir .empty ()) {
1946- const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , fileSettings.filename (), " " );
1947+ const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , fileSettings.filename (), " " , fileSettings. fileIndex );
19471948 std::ofstream fcmd (analyzerInfoFile + " .clang-tidy-cmd" );
19481949 fcmd << istr.str ();
19491950 }
@@ -2035,14 +2036,11 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st
20352036 std::ifstream fin (filesTxt);
20362037 std::string filesTxtLine;
20372038 while (std::getline (fin, filesTxtLine)) {
2038- const std::string::size_type firstColon = filesTxtLine.find (' :' );
2039- if (firstColon == std::string::npos)
2040- continue ;
2041- const std::string::size_type lastColon = filesTxtLine.rfind (' :' );
2042- if (firstColon == lastColon)
2039+ AnalyzerInformation::Info filesTxtInfo;
2040+ if (!filesTxtInfo.parse (filesTxtLine))
20432041 continue ;
2044- const std::string xmlfile = buildDir + ' / ' + filesTxtLine. substr ( 0 ,firstColon);
2045- // const std::string sourcefile = filesTxtLine.substr(lastColon+1) ;
2042+
2043+ const std::string xmlfile = buildDir + ' / ' + filesTxtInfo. afile ;
20462044
20472045 tinyxml2::XMLDocument doc;
20482046 const tinyxml2::XMLError error = doc.LoadFile (xmlfile.c_str ());
@@ -2067,7 +2065,7 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st
20672065 for (const Check *check : Check::instances ()) {
20682066 if (checkClassAttr == check->name ()) {
20692067 Check::FileInfo* fi = check->loadFileInfoFromXml (e);
2070- fi->file0 = filesTxtLine. substr (firstColon + 2 ) ;
2068+ fi->file0 = filesTxtInfo. sourceFile ;
20712069 fileInfoList.push_back (fi);
20722070 }
20732071 }
0 commit comments