Skip to content

Commit 06889a3

Browse files
authored
more FileWithDetails usage (#6500)
1 parent d33d29c commit 06889a3

15 files changed

+109
-48
lines changed

Makefile

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

cli/processexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ unsigned int ProcessExecutor::check()
286286
fileChecker.analyseClangTidy(*iFileSettings);
287287
} else {
288288
// Read file from a file
289-
resultOfCheck = fileChecker.check(iFile->path());
289+
resultOfCheck = fileChecker.check(*iFile);
290290
// TODO: call analyseClangTidy()?
291291
}
292292

cli/singleexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ unsigned int SingleExecutor::check()
5050
unsigned int c = 0;
5151

5252
for (std::list<FileWithDetails>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
53-
result += mCppcheck.check(i->path());
53+
result += mCppcheck.check(*i);
5454
processedsize += i->size();
5555
++c;
5656
if (!mSettings.quiet)

cli/threadexecutor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ class ThreadData
9494
});
9595
}
9696

97-
bool next(const std::string *&file, const FileSettings *&fs, std::size_t &fileSize) {
97+
bool next(const FileWithDetails *&file, const FileSettings *&fs, std::size_t &fileSize) {
9898
std::lock_guard<std::mutex> l(mFileSync);
9999
if (mItNextFile != mFiles.end()) {
100-
file = &mItNextFile->path();
100+
file = &(*mItNextFile);
101101
fs = nullptr;
102102
fileSize = mItNextFile->size();
103103
++mItNextFile;
@@ -114,7 +114,7 @@ class ThreadData
114114
return false;
115115
}
116116

117-
unsigned int check(ErrorLogger &errorLogger, const std::string *file, const FileSettings *fs) const {
117+
unsigned int check(ErrorLogger &errorLogger, const FileWithDetails *file, const FileSettings *fs) const {
118118
CppCheck fileChecker(errorLogger, false, mExecuteCommand);
119119
fileChecker.settings() = mSettings; // this is a copy
120120

@@ -163,7 +163,7 @@ static unsigned int STDCALL threadProc(ThreadData *data)
163163
{
164164
unsigned int result = 0;
165165

166-
const std::string *file;
166+
const FileWithDetails *file;
167167
const FileSettings *fs;
168168
std::size_t fileSize;
169169

democlient/democlient.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <iostream>
2424

2525
#include "cppcheck.h"
26+
#include "filesettings.h"
2627
#include "version.h"
2728

2829
static void unencode(const char *src, char *dest)
@@ -59,7 +60,7 @@ class CppcheckExecutor : public ErrorLogger {
5960
}
6061

6162
void run(const char code[]) {
62-
cppcheck.check("test.cpp", code);
63+
cppcheck.check(FileWithDetails("test.cpp"), code);
6364
}
6465

6566
void reportOut(const std::string & /*outmsg*/, Color /*c*/) override {}

gui/checkthread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void CheckThread::run()
124124
QString file = mResult.getNextFile();
125125
while (!file.isEmpty() && mState == Running) {
126126
qDebug() << "Checking file" << file;
127-
mCppcheck.check(file.toStdString());
127+
mCppcheck.check(FileWithDetails(file.toStdString()));
128128
runAddonsAndTools(nullptr, file);
129129
emit fileChecked(file);
130130

gui/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void MainWindow::analyzeCode(const QString& code, const QString& filename)
662662
checkLockDownUI();
663663
clearResults();
664664
mUI->mResults->checkingStarted(1);
665-
cppcheck.check(filename.toStdString(), code.toStdString());
665+
cppcheck.check(FileWithDetails(filename.toStdString()), code.toStdString());
666666
analysisDone();
667667

668668
// Expand results

lib/cppcheck.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,18 @@ unsigned int CppCheck::checkClang(const std::string &path)
539539
return mExitCode;
540540
}
541541

542-
unsigned int CppCheck::check(const std::string &path)
542+
unsigned int CppCheck::check(const FileWithDetails &file)
543543
{
544544
if (mSettings.clang)
545-
return checkClang(Path::simplifyPath(path));
545+
return checkClang(file.spath());
546546

547-
return checkFile(Path::simplifyPath(path), emptyString);
547+
return checkFile(file.spath(), emptyString);
548548
}
549549

550-
unsigned int CppCheck::check(const std::string &path, const std::string &content)
550+
unsigned int CppCheck::check(const FileWithDetails &file, const std::string &content)
551551
{
552552
std::istringstream iss(content);
553-
return checkFile(Path::simplifyPath(path), emptyString, &iss);
553+
return checkFile(file.spath(), emptyString, &iss);
554554
}
555555

556556
unsigned int CppCheck::check(const FileSettings &fs)
@@ -578,12 +578,12 @@ unsigned int CppCheck::check(const FileSettings &fs)
578578
if (mSettings.clang) {
579579
temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
580580
// TODO: propagate back suppressions
581-
const unsigned int returnValue = temp.check(Path::simplifyPath(fs.filename()));
581+
const unsigned int returnValue = temp.check(fs.file);
582582
if (mUnusedFunctionsCheck)
583583
mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
584584
return returnValue;
585585
}
586-
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename()), fs.cfg);
586+
const unsigned int returnValue = temp.checkFile(fs.sfilename(), fs.cfg);
587587
mSettings.supprs.nomsg.addSuppressions(temp.mSettings.supprs.nomsg.getSuppressions());
588588
if (mUnusedFunctionsCheck)
589589
mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
@@ -612,8 +612,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
612612
const Timer fileTotalTimer(mSettings.showtime == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL, filename);
613613

614614
if (!mSettings.quiet) {
615-
std::string fixedpath = Path::simplifyPath(filename);
616-
fixedpath = Path::toNativeSeparators(std::move(fixedpath));
615+
std::string fixedpath = Path::toNativeSeparators(filename);
617616
mErrorLogger.reportOut(std::string("Checking ") + fixedpath + ' ' + cfgname + std::string("..."), Color::FgGreen);
618617

619618
if (mSettings.verbose) {
@@ -867,8 +866,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
867866

868867
// If only errors are printed, print filename after the check
869868
if (!mSettings.quiet && (!mCurrentConfig.empty() || checkCount > 1)) {
870-
std::string fixedpath = Path::simplifyPath(filename);
871-
fixedpath = Path::toNativeSeparators(std::move(fixedpath));
869+
std::string fixedpath = Path::toNativeSeparators(filename);
872870
mErrorLogger.reportOut("Checking " + fixedpath + ": " + mCurrentConfig + "...", Color::FgGreen);
873871
}
874872

@@ -973,7 +971,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
973971
fdump.close();
974972
}
975973

976-
executeAddons(dumpFile, Path::simplifyPath(filename));
974+
executeAddons(dumpFile, filename);
977975

978976
} catch (const TerminateException &) {
979977
// Analysis is terminated

lib/cppcheck.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,26 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
8383
/**
8484
* @brief Check the file.
8585
* This function checks one given file for errors.
86-
* @param path Path to the file to check.
86+
* @param file The file to check.
8787
* @return amount of errors found or 0 if none were found.
8888
* @note You must set settings before calling this function (by calling
8989
* settings()).
9090
*/
91-
unsigned int check(const std::string &path);
91+
unsigned int check(const FileWithDetails &file);
9292
unsigned int check(const FileSettings &fs);
9393

9494
/**
9595
* @brief Check the file.
9696
* This function checks one "virtual" file. The file is not read from
9797
* the disk but the content is given in @p content. In errors the @p path
9898
* is used as a filename.
99-
* @param path Path to the file to check.
99+
* @param file The file to check.
100100
* @param content File content as a string.
101101
* @return amount of errors found or 0 if none were found.
102102
* @note You must set settings before calling this function (by calling
103103
* settings()).
104104
*/
105-
unsigned int check(const std::string &path, const std::string &content);
105+
unsigned int check(const FileWithDetails &file, const std::string &content);
106106

107107
/**
108108
* @brief Get reference to current settings.

lib/filesettings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define fileSettingsH
2121

2222
#include "config.h"
23+
#include "path.h"
2324
#include "platform.h"
2425

2526
#include <list>
@@ -44,6 +45,11 @@ class FileWithDetails
4445
return mPath;
4546
}
4647

48+
std::string spath() const
49+
{
50+
return Path::simplifyPath(mPath);
51+
}
52+
4753
std::size_t size() const
4854
{
4955
return mSize;
@@ -69,6 +75,10 @@ struct CPPCHECKLIB FileSettings {
6975
{
7076
return file.path();
7177
}
78+
std::string sfilename() const
79+
{
80+
return file.spath();
81+
}
7282
std::string defines;
7383
// TODO: handle differently
7484
std::string cppcheckDefines() const {

0 commit comments

Comments
 (0)