Skip to content

Commit a2b0353

Browse files
committed
renamed FileSettings::fileIndex (and its usage) to fsFileId
to distinct it from `simplecpp::Location::fileIndex` and its usage
1 parent 1964001 commit a2b0353

11 files changed

Lines changed: 49 additions & 49 deletions

gui/checkthread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings
238238

239239
const std::string &buildDir = settings.buildDir;
240240
if (!buildDir.empty()) {
241-
analyzerInfoFile = QString::fromStdString(AnalyzerInformation::getAnalyzerInfoFile(buildDir, fileSettings->filename(), fileSettings->cfg, fileSettings->fileIndex));
241+
analyzerInfoFile = QString::fromStdString(AnalyzerInformation::getAnalyzerInfoFile(buildDir, fileSettings->filename(), fileSettings->cfg, fileSettings->fsFileId));
242242

243243
QStringList args2(args);
244244
args2.insert(0,"-E");

lib/analyzerinfo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::string AnalyzerInformation::getFilesTxt(const std::list<std::string> &sourc
6969

7070
for (const FileSettings &fs : fileSettings) {
7171
const std::string afile = getFilename(fs.filename());
72-
const std::string id = fs.fileIndex > 0 ? std::to_string(fs.fileIndex) : "";
72+
const std::string id = fs.fsFileId > 0 ? std::to_string(fs.fsFileId) : "";
7373
ret << afile << ".a" << (++fileCount[afile]) << sep << fs.cfg << sep << id << sep << Path::simplifyPath(fs.filename()) << std::endl;
7474
}
7575

@@ -128,11 +128,11 @@ std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& f
128128
return "";
129129
}
130130

131-
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex)
131+
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fsFileId)
132132
{
133133
std::ifstream fin(Path::join(buildDir, "files.txt"));
134134
if (fin.is_open()) {
135-
const std::string& ret = getAnalyzerInfoFileFromFilesTxt(fin, sourcefile, cfg, fileIndex);
135+
const std::string& ret = getAnalyzerInfoFileFromFilesTxt(fin, sourcefile, cfg, fsFileId);
136136
if (!ret.empty())
137137
return Path::join(buildDir, ret);
138138
}
@@ -146,13 +146,13 @@ std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir
146146
return Path::join(buildDir, std::move(filename)) + ".analyzerinfo";
147147
}
148148

149-
bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex, std::size_t hash, std::list<ErrorMessage> &errors)
149+
bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fsFileId, std::size_t hash, std::list<ErrorMessage> &errors)
150150
{
151151
if (buildDir.empty() || sourcefile.empty())
152152
return true;
153153
close();
154154

155-
mAnalyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fileIndex);
155+
mAnalyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fsFileId);
156156

157157
tinyxml2::XMLDocument analyzerInfoDoc;
158158
const tinyxml2::XMLError xmlError = analyzerInfoDoc.LoadFile(mAnalyzerInfoFile.c_str());
@@ -194,10 +194,10 @@ bool AnalyzerInformation::Info::parse(const std::string& filesTxtLine) {
194194
return false;
195195

196196
if (sep3 == sep2 + 1)
197-
fileIndex = 0;
197+
fsFileId = 0;
198198
else {
199199
try {
200-
fileIndex = std::stoi(filesTxtLine.substr(sep2+1, sep3-sep2-1));
200+
fsFileId = std::stoi(filesTxtLine.substr(sep2+1, sep3-sep2-1));
201201
} catch (const std::exception&) {
202202
return false;
203203
}

lib/analyzerinfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class CPPCHECKLIB AnalyzerInformation {
6161

6262
/** Close current TU.analyzerinfo file */
6363
void close();
64-
bool analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex, std::size_t hash, std::list<ErrorMessage> &errors);
64+
bool analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fsFileId, std::size_t hash, std::list<ErrorMessage> &errors);
6565
void reportErr(const ErrorMessage &msg);
6666
void setFileInfo(const std::string &check, const std::string &fileInfo);
67-
static std::string getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex);
67+
static std::string getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fsFileId);
6868

6969
static const char sep = ':';
7070

@@ -73,7 +73,7 @@ class CPPCHECKLIB AnalyzerInformation {
7373
bool parse(const std::string& filesTxtLine);
7474
std::string afile;
7575
std::string cfg;
76-
int fileIndex = 0;
76+
int fsFileId = 0;
7777
std::string sourceFile;
7878
};
7979

lib/cppcheck.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,16 @@ static std::vector<std::string> split(const std::string &str, const std::string
332332
return ret;
333333
}
334334

335-
static std::string getDumpFileName(const Settings& settings, const std::string& filename, int fileIndex)
335+
static std::string getDumpFileName(const Settings& settings, const std::string& filename, int fsFileId)
336336
{
337337
std::string extension = ".dump";
338-
if (fileIndex > 0)
339-
extension = "." + std::to_string(fileIndex) + extension;
338+
if (fsFileId > 0)
339+
extension = "." + std::to_string(fsFileId) + extension;
340340
if (!settings.dump && settings.buildDir.empty())
341341
extension = "." + std::to_string(settings.pid) + extension;
342342

343343
if (!settings.dump && !settings.buildDir.empty())
344-
return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, "", fileIndex) + extension;
344+
return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, "", fsFileId) + extension;
345345
return filename + extension;
346346
}
347347

@@ -352,13 +352,13 @@ static std::string getCtuInfoFileName(const std::string &dumpFile)
352352

353353
static void createDumpFile(const Settings& settings,
354354
const FileWithDetails& file,
355-
int fileIndex,
355+
int fsFileId,
356356
std::ofstream& fdump,
357357
std::string& dumpFile)
358358
{
359359
if (!settings.dump && settings.addons.empty())
360360
return;
361-
dumpFile = getDumpFileName(settings, file.spath(), fileIndex);
361+
dumpFile = getDumpFileName(settings, file.spath(), fsFileId);
362362

363363
fdump.open(dumpFile);
364364
if (!fdump.is_open())
@@ -660,7 +660,7 @@ static std::string getClangFlags(const Settings& setting, Standards::Language la
660660
}
661661

662662
// TODO: clear error list before returning
663-
unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
663+
unsigned int CppCheck::checkClang(const FileWithDetails &file, int fsFileId)
664664
{
665665
// TODO: clear exitcode
666666

@@ -673,7 +673,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
673673
// TODO: get language from FileWithDetails object
674674
std::string clangStderr;
675675
if (!mSettings.buildDir.empty())
676-
clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), "", fileIndex) + ".clang-stderr";
676+
clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), "", fsFileId) + ".clang-stderr";
677677

678678
std::string exe = mSettings.clangExecutable;
679679
#ifdef _WIN32
@@ -747,7 +747,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
747747
// create dumpfile
748748
std::ofstream fdump;
749749
std::string dumpFile;
750-
createDumpFile(mSettings, file, fileIndex, fdump, dumpFile);
750+
createDumpFile(mSettings, file, fsFileId, fdump, dumpFile);
751751
if (fdump.is_open()) {
752752
fdump << getLibraryDumpData();
753753
// TODO: use tinyxml2 to create XML
@@ -838,7 +838,7 @@ unsigned int CppCheck::check(const FileSettings &fs)
838838
}
839839
// need to pass the externally provided ErrorLogger instead of our internal wrapper
840840
CppCheck temp(tempSettings, mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand);
841-
const unsigned int returnValue = temp.checkFile(fs.file, fs.cfg, fs.fileIndex);
841+
const unsigned int returnValue = temp.checkFile(fs.file, fs.cfg, fs.fsFileId);
842842
if (mUnusedFunctionsCheck)
843843
mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
844844
while (!temp.mFileInfo.empty()) {
@@ -875,20 +875,20 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std:
875875
return preprocessor.calculateHash(toolinfo.str());
876876
}
877877

878-
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fileIndex, const char* data, std::size_t size)
878+
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fsFileId, const char* data, std::size_t size)
879879
{
880880
const auto f = [&file, data, size](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
881881
return simplecpp::TokenList{{data, size}, files, file.spath(), outputList};
882882
};
883-
return checkInternal(file, cfgname, fileIndex, f);
883+
return checkInternal(file, cfgname, fsFileId, f);
884884
}
885885

886-
unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname, int fileIndex)
886+
unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname, int fsFileId)
887887
{
888888
const auto f = [&file](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
889889
return simplecpp::TokenList{file.spath(), files, outputList};
890890
};
891-
return checkInternal(file, cfgname, fileIndex, f);
891+
return checkInternal(file, cfgname, fsFileId, f);
892892
}
893893

894894
void CppCheck::checkPlistOutput(const FileWithDetails& file, const std::vector<std::string>& files)
@@ -906,7 +906,7 @@ void CppCheck::checkPlistOutput(const FileWithDetails& file, const std::vector<s
906906
}
907907
}
908908

909-
unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokenListFn& createTokenList)
909+
unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::string &cfgname, int fsFileId, const CreateTokenListFn& createTokenList)
910910
{
911911
// TODO: move to constructor when CppCheck no longer owns the settings
912912
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
@@ -974,7 +974,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
974974
mLogger->setAnalyzerInfo(nullptr);
975975

976976
std::list<ErrorMessage> errors;
977-
analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors);
977+
analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fsFileId, hash, errors);
978978
analyzerInformation->setFileInfo("CheckUnusedFunctions", mUnusedFunctionsCheck->analyzerInfo(tokenizer));
979979
analyzerInformation->close();
980980
}
@@ -1020,7 +1020,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10201020
// Calculate hash so it can be compared with old hash / future hashes
10211021
const std::size_t hash = calculateHash(preprocessor, file.spath());
10221022
std::list<ErrorMessage> errors;
1023-
if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors)) {
1023+
if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fsFileId, hash, errors)) {
10241024
while (!errors.empty()) {
10251025
mErrorLogger.reportErr(errors.front());
10261026
errors.pop_front();
@@ -1077,7 +1077,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10771077
// write dump file xml prolog
10781078
std::ofstream fdump;
10791079
std::string dumpFile;
1080-
createDumpFile(mSettings, file, fileIndex, fdump, dumpFile);
1080+
createDumpFile(mSettings, file, fsFileId, fdump, dumpFile);
10811081
if (fdump.is_open()) {
10821082
fdump << getLibraryDumpData();
10831083
fdump << dumpProlog;
@@ -1201,7 +1201,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
12011201
#endif
12021202

12031203
// Simplify tokens into normal form, skip rest of iteration if failed
1204-
if (!tokenizer.simplifyTokens1(currentConfig, fileIndex))
1204+
if (!tokenizer.simplifyTokens1(currentConfig, fsFileId))
12051205
continue;
12061206

12071207
// dump xml if --dump
@@ -1646,7 +1646,7 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
16461646
}
16471647

16481648
for (const auto &f: fileSettings) {
1649-
const std::string &dumpFileName = getDumpFileName(mSettings, f.filename(), f.fileIndex);
1649+
const std::string &dumpFileName = getDumpFileName(mSettings, f.filename(), f.fsFileId);
16501650
ctuInfoFiles.push_back(getCtuInfoFileName(dumpFileName));
16511651
}
16521652

@@ -1758,7 +1758,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
17581758
std::string line;
17591759

17601760
if (!mSettings.buildDir.empty()) {
1761-
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.filename(), "", fileSettings.fileIndex);
1761+
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.filename(), "", fileSettings.fsFileId);
17621762
std::ofstream fcmd(analyzerInfoFile + ".clang-tidy-cmd");
17631763
fcmd << istr.str();
17641764
}

lib/cppcheck.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class CPPCHECKLIB CppCheck {
182182
* @param cfgname cfg name
183183
* @return number of errors found
184184
*/
185-
unsigned int checkFile(const FileWithDetails& file, const std::string &cfgname, int fileIndex);
185+
unsigned int checkFile(const FileWithDetails& file, const std::string &cfgname, int fsFileId);
186186

187187
void checkPlistOutput(const FileWithDetails& file, const std::vector<std::string>& files);
188188

@@ -194,7 +194,7 @@ class CPPCHECKLIB CppCheck {
194194
* @param size the size of the data to be read
195195
* @return number of errors found
196196
*/
197-
unsigned int checkBuffer(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const char* data, std::size_t size);
197+
unsigned int checkBuffer(const FileWithDetails& file, const std::string &cfgname, int fsFileId, const char* data, std::size_t size);
198198

199199
// TODO: should use simplecpp::OutputList
200200
using CreateTokenListFn = std::function<simplecpp::TokenList (std::vector<std::string>&, std::list<simplecpp::Output>*)>;
@@ -206,7 +206,7 @@ class CPPCHECKLIB CppCheck {
206206
* @param createTokenList a function to create the simplecpp::TokenList with
207207
* @return number of errors found
208208
*/
209-
unsigned int checkInternal(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokenListFn& createTokenList);
209+
unsigned int checkInternal(const FileWithDetails& file, const std::string &cfgname, int fsFileId, const CreateTokenListFn& createTokenList);
210210

211211
/**
212212
* @brief Check normal tokens
@@ -235,7 +235,7 @@ class CPPCHECKLIB CppCheck {
235235
void executeRules(const std::string &tokenlist, const TokenList &list);
236236
#endif
237237

238-
unsigned int checkClang(const FileWithDetails &file, int fileIndex);
238+
unsigned int checkClang(const FileWithDetails &file, int fsFileId);
239239

240240
const Settings& mSettings;
241241
Suppressions& mSuppressions;

lib/filesettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct CPPCHECKLIB FileSettings {
8181
: file(std::move(path), lang, size)
8282
{}
8383

84-
int fileIndex = 0;
84+
int fsFileId = 0;
8585
std::string cfg;
8686
FileWithDetails file;
8787
const std::string& filename() const

lib/importproject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
347347
return false;
348348
}
349349

350-
std::map<std::string, int> fileIndex;
350+
std::map<std::string, int> fsFileIds;
351351

352352
for (const picojson::value &fileInfo : compileCommands.get<picojson::array>()) {
353353
picojson::object obj = fileInfo.get<picojson::object>();
@@ -430,7 +430,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
430430
fsSetIncludePaths(fs, directory, fs.includePaths, variables);
431431
// Assign a unique index to each file path. If the file path already exists in the map,
432432
// increment the index to handle duplicate file entries.
433-
fs.fileIndex = fileIndex[path]++;
433+
fs.fsFileId = fsFileIds[path]++;
434434
fileSettings.push_back(std::move(fs));
435435
}
436436

lib/summaries.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636

37-
std::string Summaries::create(const Tokenizer &tokenizer, const std::string &cfg, int fileIndex)
37+
std::string Summaries::create(const Tokenizer &tokenizer, const std::string &cfg, int fsFileId)
3838
{
3939
const SymbolDatabase *symbolDatabase = tokenizer.getSymbolDatabase();
4040
const Settings &settings = tokenizer.getSettings();
@@ -82,7 +82,7 @@ std::string Summaries::create(const Tokenizer &tokenizer, const std::string &cfg
8282
}
8383

8484
if (!settings.buildDir.empty()) {
85-
std::string filename = AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, tokenizer.list.getSourceFilePath(), cfg, fileIndex);
85+
std::string filename = AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, tokenizer.list.getSourceFilePath(), cfg, fsFileId);
8686
const std::string::size_type pos = filename.rfind(".a");
8787
if (pos != std::string::npos) {
8888
filename[pos+1] = 's';

lib/summaries.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
class Tokenizer;
3030

3131
namespace Summaries {
32-
CPPCHECKLIB std::string create(const Tokenizer &tokenizer, const std::string &cfg, int fileIndex);
32+
CPPCHECKLIB std::string create(const Tokenizer &tokenizer, const std::string &cfg, int fsFileId);
3333
CPPCHECKLIB void loadReturn(const std::string &buildDir, std::set<std::string> &summaryReturn);
3434
}
3535

test/testanalyzerinformation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class TestAnalyzerInformation : public TestFixture {
5959
void filesTextDuplicateFile() const {
6060
std::list<FileSettings> fileSettings;
6161
fileSettings.emplace_back("a.c", Standards::Language::C, 10);
62-
fileSettings.back().fileIndex = 0;
62+
fileSettings.back().fsFileId = 0;
6363
fileSettings.emplace_back("a.c", Standards::Language::C, 10);
64-
fileSettings.back().fileIndex = 1;
64+
fileSettings.back().fsFileId = 1;
6565

6666
const char expected[] = "a.a1:::a.c\n"
6767
"a.a2::1:a.c\n";
@@ -90,19 +90,19 @@ class TestAnalyzerInformation : public TestFixture {
9090
ASSERT_EQUALS(true, info.parse("a:b::d"));
9191
ASSERT_EQUALS("a", info.afile);
9292
ASSERT_EQUALS("b", info.cfg);
93-
ASSERT_EQUALS(0, info.fileIndex);
93+
ASSERT_EQUALS(0, info.fsFileId);
9494
ASSERT_EQUALS("d", info.sourceFile);
9595

9696
ASSERT_EQUALS(true, info.parse("e:f:12:g"));
9797
ASSERT_EQUALS("e", info.afile);
9898
ASSERT_EQUALS("f", info.cfg);
99-
ASSERT_EQUALS(12, info.fileIndex);
99+
ASSERT_EQUALS(12, info.fsFileId);
100100
ASSERT_EQUALS("g", info.sourceFile);
101101

102102
ASSERT_EQUALS(true, info.parse("odr1.a1:::C:/dm/cppcheck-fix-13333/test/cli/whole-program/odr1.cpp"));
103103
ASSERT_EQUALS("odr1.a1", info.afile);
104104
ASSERT_EQUALS("", info.cfg);
105-
ASSERT_EQUALS(0, info.fileIndex);
105+
ASSERT_EQUALS(0, info.fsFileId);
106106
ASSERT_EQUALS("C:/dm/cppcheck-fix-13333/test/cli/whole-program/odr1.cpp", info.sourceFile);
107107
}
108108

0 commit comments

Comments
 (0)