@@ -331,16 +331,16 @@ static std::vector<std::string> split(const std::string &str, const std::string
331
331
return ret;
332
332
}
333
333
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 )
335
335
{
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 ;
341
341
342
342
if (!settings.dump && !settings.buildDir .empty ())
343
- return AnalyzerInformation::getAnalyzerInfoFile (settings.buildDir , filename, " " ) + extension;
343
+ return AnalyzerInformation::getAnalyzerInfoFile (settings.buildDir , filename, " " , fileIndex ) + extension;
344
344
return filename + extension;
345
345
}
346
346
@@ -351,12 +351,13 @@ static std::string getCtuInfoFileName(const std::string &dumpFile)
351
351
352
352
static void createDumpFile (const Settings& settings,
353
353
const FileWithDetails& file,
354
+ int fileIndex,
354
355
std::ofstream& fdump,
355
356
std::string& dumpFile)
356
357
{
357
358
if (!settings.dump && settings.addons .empty ())
358
359
return ;
359
- dumpFile = getDumpFileName (settings, file.spath ());
360
+ dumpFile = getDumpFileName (settings, file.spath (), fileIndex );
360
361
361
362
fdump.open (dumpFile);
362
363
if (!fdump.is_open ())
@@ -649,7 +650,7 @@ static std::string getClangFlags(const Settings& setting, Standards::Language la
649
650
}
650
651
651
652
// TODO: clear error list before returning
652
- unsigned int CppCheck::checkClang (const FileWithDetails &file)
653
+ unsigned int CppCheck::checkClang (const FileWithDetails &file, int fileIndex )
653
654
{
654
655
// TODO: clear exitcode
655
656
@@ -662,7 +663,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
662
663
// TODO: get language from FileWithDetails object
663
664
std::string clangStderr;
664
665
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" ;
666
667
667
668
std::string exe = mSettings .clangExecutable ;
668
669
#ifdef _WIN32
@@ -731,7 +732,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
731
732
// create dumpfile
732
733
std::ofstream fdump;
733
734
std::string dumpFile;
734
- createDumpFile (mSettings , file, fdump, dumpFile);
735
+ createDumpFile (mSettings , file, fileIndex, fdump, dumpFile);
735
736
if (fdump.is_open ()) {
736
737
fdump << getLibraryDumpData ();
737
738
// TODO: use tinyxml2 to create XML
@@ -775,9 +776,9 @@ unsigned int CppCheck::check(const FileWithDetails &file)
775
776
776
777
unsigned int returnValue;
777
778
if (mSettings .clang )
778
- returnValue = checkClang (file);
779
+ returnValue = checkClang (file, 0 );
779
780
else
780
- returnValue = checkFile (file, " " );
781
+ returnValue = checkFile (file, " " , 0 );
781
782
782
783
// TODO: call analyseClangTidy()
783
784
@@ -787,7 +788,7 @@ unsigned int CppCheck::check(const FileWithDetails &file)
787
788
unsigned int CppCheck::check (const FileWithDetails &file, const std::string &content)
788
789
{
789
790
std::istringstream iss (content);
790
- return checkFile (file, " " , &iss);
791
+ return checkFile (file, " " , 0 , &iss);
791
792
}
792
793
793
794
unsigned int CppCheck::check (const FileSettings &fs)
@@ -823,7 +824,7 @@ unsigned int CppCheck::check(const FileSettings &fs)
823
824
}
824
825
// need to pass the externally provided ErrorLogger instead of our internal wrapper
825
826
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 );
827
828
if (mUnusedFunctionsCheck )
828
829
mUnusedFunctionsCheck ->updateFunctionData (*temp.mUnusedFunctionsCheck );
829
830
while (!temp.mFileInfo .empty ()) {
@@ -860,7 +861,7 @@ static std::size_t calculateHash(const Preprocessor& preprocessor, const simplec
860
861
return preprocessor.calculateHash (tokens, toolinfo.str ());
861
862
}
862
863
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)
864
865
{
865
866
// TODO: move to constructor when CppCheck no longer owns the settings
866
867
if (mSettings .checks .isEnabled (Checks::unusedFunction) && !mUnusedFunctionsCheck )
@@ -937,7 +938,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
937
938
mLogger ->setAnalyzerInfo (nullptr );
938
939
939
940
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);
941
942
analyzerInformation->setFileInfo (" CheckUnusedFunctions" , mUnusedFunctionsCheck ->analyzerInfo (tokenizer));
942
943
analyzerInformation->close ();
943
944
}
@@ -1011,7 +1012,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1011
1012
// Calculate hash so it can be compared with old hash / future hashes
1012
1013
const std::size_t hash = calculateHash (preprocessor, tokens1, mSettings , mSuppressions );
1013
1014
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)) {
1015
1016
while (!errors.empty ()) {
1016
1017
mErrorLogger .reportErr (errors.front ());
1017
1018
errors.pop_front ();
@@ -1074,7 +1075,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1074
1075
// write dump file xml prolog
1075
1076
std::ofstream fdump;
1076
1077
std::string dumpFile;
1077
- createDumpFile (mSettings , file, fdump, dumpFile);
1078
+ createDumpFile (mSettings , file, fileIndex, fdump, dumpFile);
1078
1079
if (fdump.is_open ()) {
1079
1080
fdump << getLibraryDumpData ();
1080
1081
fdump << dumpProlog;
@@ -1169,7 +1170,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1169
1170
#endif
1170
1171
1171
1172
// Simplify tokens into normal form, skip rest of iteration if failed
1172
- if (!tokenizer.simplifyTokens1 (currentConfig))
1173
+ if (!tokenizer.simplifyTokens1 (currentConfig, fileIndex ))
1173
1174
continue ;
1174
1175
1175
1176
// dump xml if --dump
@@ -1811,12 +1812,12 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
1811
1812
1812
1813
std::vector<std::string> ctuInfoFiles;
1813
1814
for (const auto &f: files) {
1814
- const std::string &dumpFileName = getDumpFileName (mSettings , f.path ());
1815
+ const std::string &dumpFileName = getDumpFileName (mSettings , f.path (), 0 );
1815
1816
ctuInfoFiles.push_back (getCtuInfoFileName (dumpFileName));
1816
1817
}
1817
1818
1818
1819
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 );
1820
1821
ctuInfoFiles.push_back (getCtuInfoFileName (dumpFileName));
1821
1822
}
1822
1823
@@ -1943,7 +1944,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
1943
1944
std::string line;
1944
1945
1945
1946
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 );
1947
1948
std::ofstream fcmd (analyzerInfoFile + " .clang-tidy-cmd" );
1948
1949
fcmd << istr.str ();
1949
1950
}
@@ -2035,14 +2036,11 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st
2035
2036
std::ifstream fin (filesTxt);
2036
2037
std::string filesTxtLine;
2037
2038
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))
2043
2041
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 ;
2046
2044
2047
2045
tinyxml2::XMLDocument doc;
2048
2046
const tinyxml2::XMLError error = doc.LoadFile (xmlfile.c_str ());
@@ -2067,7 +2065,7 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st
2067
2065
for (const Check *check : Check::instances ()) {
2068
2066
if (checkClassAttr == check->name ()) {
2069
2067
Check::FileInfo* fi = check->loadFileInfoFromXml (e);
2070
- fi->file0 = filesTxtLine. substr (firstColon + 2 ) ;
2068
+ fi->file0 = filesTxtInfo. sourceFile ;
2071
2069
fileInfoList.push_back (fi);
2072
2070
}
2073
2071
}
0 commit comments