@@ -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
@@ -732,7 +733,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
732
733
// create dumpfile
733
734
std::ofstream fdump;
734
735
std::string dumpFile;
735
- createDumpFile (mSettings , file, fdump, dumpFile);
736
+ createDumpFile (mSettings , file, fileIndex, fdump, dumpFile);
736
737
if (fdump.is_open ()) {
737
738
fdump << getLibraryDumpData ();
738
739
// TODO: use tinyxml2 to create XML
@@ -776,9 +777,9 @@ unsigned int CppCheck::check(const FileWithDetails &file)
776
777
777
778
unsigned int returnValue;
778
779
if (mSettings .clang )
779
- returnValue = checkClang (file);
780
+ returnValue = checkClang (file, 0 );
780
781
else
781
- returnValue = checkFile (file, " " );
782
+ returnValue = checkFile (file, " " , 0 );
782
783
783
784
// TODO: call analyseClangTidy()
784
785
@@ -788,7 +789,7 @@ unsigned int CppCheck::check(const FileWithDetails &file)
788
789
unsigned int CppCheck::check (const FileWithDetails &file, const std::string &content)
789
790
{
790
791
std::istringstream iss (content);
791
- return checkFile (file, " " , &iss);
792
+ return checkFile (file, " " , 0 , &iss);
792
793
}
793
794
794
795
unsigned int CppCheck::check (const FileSettings &fs)
@@ -824,7 +825,7 @@ unsigned int CppCheck::check(const FileSettings &fs)
824
825
}
825
826
// need to pass the externally provided ErrorLogger instead of our internal wrapper
826
827
CppCheck temp (tempSettings, mSuppressions , mErrorLoggerDirect , mUseGlobalSuppressions , mExecuteCommand );
827
- const unsigned int returnValue = temp.checkFile (fs.file , fs.cfg );
828
+ const unsigned int returnValue = temp.checkFile (fs.file , fs.cfg , fs. fileIndex );
828
829
if (mUnusedFunctionsCheck )
829
830
mUnusedFunctionsCheck ->updateFunctionData (*temp.mUnusedFunctionsCheck );
830
831
while (!temp.mFileInfo .empty ()) {
@@ -861,7 +862,7 @@ static std::size_t calculateHash(const Preprocessor& preprocessor, const simplec
861
862
return preprocessor.calculateHash (tokens, toolinfo.str ());
862
863
}
863
864
864
- unsigned int CppCheck::checkFile (const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream)
865
+ unsigned int CppCheck::checkFile (const FileWithDetails& file, const std::string &cfgname, int fileIndex, std::istream* fileStream)
865
866
{
866
867
// TODO: move to constructor when CppCheck no longer owns the settings
867
868
if (mSettings .checks .isEnabled (Checks::unusedFunction) && !mUnusedFunctionsCheck )
@@ -938,7 +939,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
938
939
mLogger ->setAnalyzerInfo (nullptr );
939
940
940
941
std::list<ErrorMessage> errors;
941
- analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors);
942
+ analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, fileIndex, hash, errors);
942
943
analyzerInformation->setFileInfo (" CheckUnusedFunctions" , mUnusedFunctionsCheck ->analyzerInfo (tokenizer));
943
944
analyzerInformation->close ();
944
945
}
@@ -1012,7 +1013,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1012
1013
// Calculate hash so it can be compared with old hash / future hashes
1013
1014
const std::size_t hash = calculateHash (preprocessor, tokens1, mSettings , mSuppressions );
1014
1015
std::list<ErrorMessage> errors;
1015
- if (!analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors)) {
1016
+ if (!analyzerInformation->analyzeFile (mSettings .buildDir , file.spath (), cfgname, fileIndex, hash, errors)) {
1016
1017
while (!errors.empty ()) {
1017
1018
mErrorLogger .reportErr (errors.front ());
1018
1019
errors.pop_front ();
@@ -1075,7 +1076,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1075
1076
// write dump file xml prolog
1076
1077
std::ofstream fdump;
1077
1078
std::string dumpFile;
1078
- createDumpFile (mSettings , file, fdump, dumpFile);
1079
+ createDumpFile (mSettings , file, fileIndex, fdump, dumpFile);
1079
1080
if (fdump.is_open ()) {
1080
1081
fdump << getLibraryDumpData ();
1081
1082
fdump << dumpProlog;
@@ -1170,7 +1171,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1170
1171
#endif
1171
1172
1172
1173
// Simplify tokens into normal form, skip rest of iteration if failed
1173
- if (!tokenizer.simplifyTokens1 (currentConfig))
1174
+ if (!tokenizer.simplifyTokens1 (currentConfig, fileIndex ))
1174
1175
continue ;
1175
1176
1176
1177
// dump xml if --dump
@@ -1812,12 +1813,12 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
1812
1813
1813
1814
std::vector<std::string> ctuInfoFiles;
1814
1815
for (const auto &f: files) {
1815
- const std::string &dumpFileName = getDumpFileName (mSettings , f.path ());
1816
+ const std::string &dumpFileName = getDumpFileName (mSettings , f.path (), 0 );
1816
1817
ctuInfoFiles.push_back (getCtuInfoFileName (dumpFileName));
1817
1818
}
1818
1819
1819
1820
for (const auto &f: fileSettings) {
1820
- const std::string &dumpFileName = getDumpFileName (mSettings , f.filename ());
1821
+ const std::string &dumpFileName = getDumpFileName (mSettings , f.filename (), f. fileIndex );
1821
1822
ctuInfoFiles.push_back (getCtuInfoFileName (dumpFileName));
1822
1823
}
1823
1824
@@ -1944,7 +1945,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
1944
1945
std::string line;
1945
1946
1946
1947
if (!mSettings .buildDir .empty ()) {
1947
- const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , fileSettings.filename (), " " );
1948
+ const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , fileSettings.filename (), " " , fileSettings. fileIndex );
1948
1949
std::ofstream fcmd (analyzerInfoFile + " .clang-tidy-cmd" );
1949
1950
fcmd << istr.str ();
1950
1951
}
@@ -2036,14 +2037,11 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st
2036
2037
std::ifstream fin (filesTxt);
2037
2038
std::string filesTxtLine;
2038
2039
while (std::getline (fin, filesTxtLine)) {
2039
- const std::string::size_type firstColon = filesTxtLine.find (' :' );
2040
- if (firstColon == std::string::npos)
2041
- continue ;
2042
- const std::string::size_type lastColon = filesTxtLine.rfind (' :' );
2043
- if (firstColon == lastColon)
2040
+ AnalyzerInformation::Info filesTxtInfo;
2041
+ if (!filesTxtInfo.parse (filesTxtLine))
2044
2042
continue ;
2045
- const std::string xmlfile = buildDir + ' / ' + filesTxtLine. substr ( 0 ,firstColon);
2046
- // const std::string sourcefile = filesTxtLine.substr(lastColon+1) ;
2043
+
2044
+ const std::string xmlfile = buildDir + ' / ' + filesTxtInfo. afile ;
2047
2045
2048
2046
tinyxml2::XMLDocument doc;
2049
2047
const tinyxml2::XMLError error = doc.LoadFile (xmlfile.c_str ());
@@ -2068,7 +2066,7 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st
2068
2066
for (const Check *check : Check::instances ()) {
2069
2067
if (checkClassAttr == check->name ()) {
2070
2068
Check::FileInfo* fi = check->loadFileInfoFromXml (e);
2071
- fi->file0 = filesTxtLine. substr (firstColon + 2 ) ;
2069
+ fi->file0 = filesTxtInfo. sourceFile ;
2072
2070
fileInfoList.push_back (fi);
2073
2071
}
2074
2072
}
0 commit comments