Skip to content

Commit 56be00d

Browse files
authored
filesettings.h: removed constructors without language (danmar#7493)
1 parent 2d6dc91 commit 56be00d

File tree

11 files changed

+50
-53
lines changed

11 files changed

+50
-53
lines changed

cli/cmdlineparser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
232232
{
233233
if (mSettings.library.markupFile(fs.filename()))
234234
continue;
235+
assert(fs.file.lang() == Standards::Language::None);
235236
bool header = false;
236237
fs.file.setLang(Path::identify(fs.filename(), mSettings.cppHeaderProbe, &header));
237238
// unknown extensions default to C++
@@ -244,6 +245,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
244245
for (auto& fs : fileSettings)
245246
{
246247
if (mSettings.library.markupFile(fs.filename())) {
248+
assert(fs.file.lang() == Standards::Language::None);
247249
fs.file.setLang(Standards::Language::C);
248250
}
249251
}

democlient/democlient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CppcheckExecutor : public ErrorLogger {
6767
{}
6868

6969
void run(const char code[]) {
70-
cppcheck.check(FileWithDetails("test.cpp"), code);
70+
cppcheck.check(FileWithDetails("test.cpp", Standards::Language::CPP, 0), code);
7171
}
7272

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

gui/mainwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "helpdialog.h"
3636
#include "importproject.h"
3737
#include "librarydialog.h"
38+
#include "path.h"
3839
#include "platform.h"
3940
#include "projectfile.h"
4041
#include "projectfiledialog.h"
@@ -702,7 +703,7 @@ void MainWindow::analyzeCode(const QString& code, const QString& filename)
702703
checkLockDownUI();
703704
clearResults();
704705
mUI->mResults->checkingStarted(1);
705-
cppcheck.check(FileWithDetails(filename.toStdString()), code.toStdString());
706+
cppcheck.check(FileWithDetails(filename.toStdString(), Path::identify(filename.toStdString(), false), 0), code.toStdString());
706707
analysisDone();
707708

708709
// Expand results

lib/filesettings.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
class FileWithDetails
3434
{
3535
public:
36-
explicit FileWithDetails(std::string path)
37-
: FileWithDetails(std::move(path), Standards::Language::None, 0)
38-
{}
39-
4036
FileWithDetails(std::string path, Standards::Language lang, std::size_t size)
4137
: mPath(std::move(path))
4238
, mPathSimplified(Path::simplifyPath(mPath))
@@ -80,10 +76,6 @@ class FileWithDetails
8076

8177
/** File settings. Multiple configurations for a file is allowed. */
8278
struct CPPCHECKLIB FileSettings {
83-
explicit FileSettings(std::string path)
84-
: file(std::move(path))
85-
{}
86-
8779
FileSettings(std::string path, Standards::Language lang, std::size_t size)
8880
: file(std::move(path), lang, size)
8981
{}

lib/importproject.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
420420
printError("'" + path + "' from compilation database does not exist");
421421
return false;
422422
}
423-
FileSettings fs{std::move(path)};
423+
FileSettings fs{std::move(path), Standards::Language::None, 0}; // file will be identified later on
424424
fsParseCommand(fs, command); // read settings; -D, -I, -U, -std, -m*, -f*
425425
std::map<std::string, std::string, cppcheck::stricmp> variables;
426426
fsSetIncludePaths(fs, directory, fs.includePaths, variables);
@@ -833,7 +833,7 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
833833
continue;
834834
}
835835

836-
FileSettings fs{cfilename};
836+
FileSettings fs{cfilename, Standards::Language::None, 0}; // file will be identified later on
837837
fs.cfg = p.name;
838838
// TODO: detect actual MSC version
839839
fs.msc = true;
@@ -1195,7 +1195,8 @@ bool ImportProject::importBcb6Prj(const std::string &projectFilename)
11951195
//
11961196
// We can also force C++ compilation for all files using the -P command line switch.
11971197
const bool cppMode = forceCppMode || Path::getFilenameExtensionInLowerCase(c) == ".cpp";
1198-
FileSettings fs{Path::simplifyPath(Path::isAbsolute(c) ? c : projectDir + c)};
1198+
// TODO: needs to set language and ignore later identification and language enforcement
1199+
FileSettings fs{Path::simplifyPath(Path::isAbsolute(c) ? c : projectDir + c), Standards::Language::None, 0}; // file will be identified later on
11991200
fsSetIncludePaths(fs, projectDir, toStringList(includePath), variables);
12001201
fsSetDefines(fs, cppMode ? cppDefines : defines);
12011202
fileSettings.push_back(std::move(fs));
@@ -1483,7 +1484,7 @@ void ImportProject::setRelativePaths(const std::string &filename)
14831484
return;
14841485
const std::vector<std::string> basePaths{Path::fromNativeSeparators(Path::getCurrentPath())};
14851486
for (auto &fs: fileSettings) {
1486-
fs.file = FileWithDetails{Path::getRelativePath(fs.filename(), basePaths)};
1487+
fs.file = FileWithDetails{Path::getRelativePath(fs.filename(), basePaths), Standards::Language::None, 0}; // file will be identified later on
14871488
for (auto &includePath: fs.includePaths)
14881489
includePath = Path::getRelativePath(includePath, basePaths);
14891490
}

oss-fuzz/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static Settings create_settings()
5757
}
5858
static const Settings s_settings = create_settings();
5959
static DummyErrorLogger s_errorLogger;
60-
static const FileWithDetails s_file("test.cpp");
60+
static const FileWithDetails s_file("test.cpp", Standards::Language::CPP, 0);
6161

6262
static void doCheck(const std::string& code)
6363
{

test/testcppcheck.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "filesettings.h"
2323
#include "fixture.h"
2424
#include "helpers.h"
25+
#include "path.h"
2526
#include "settings.h"
2627
#include "suppressions.h"
2728

@@ -116,7 +117,7 @@ class TestCppcheck : public TestFixture {
116117
Suppressions supprs;
117118
ErrorLogger2 errorLogger;
118119
CppCheck cppcheck(s, supprs, errorLogger, false, {});
119-
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(file.path())));
120+
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(file.path(), Path::identify(file.path(), false), 0)));
120121
// TODO: how to properly disable these warnings?
121122
errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
122123
return id == "logChecker";
@@ -138,7 +139,7 @@ class TestCppcheck : public TestFixture {
138139
Suppressions supprs;
139140
ErrorLogger2 errorLogger;
140141
CppCheck cppcheck(s, supprs, errorLogger, false, {});
141-
FileSettings fs{file.path()};
142+
FileSettings fs{file.path(), Path::identify(file.path(), false), 0};
142143
ASSERT_EQUALS(1, cppcheck.check(fs));
143144
// TODO: how to properly disable these warnings?
144145
errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
@@ -162,7 +163,7 @@ class TestCppcheck : public TestFixture {
162163
Suppressions supprs;
163164
ErrorLogger2 errorLogger;
164165
CppCheck cppcheck(s, supprs, errorLogger, false, {});
165-
ASSERT_EQUALS(0, cppcheck.check(FileWithDetails(file.path())));
166+
ASSERT_EQUALS(0, cppcheck.check(FileWithDetails(file.path(), Path::identify(file.path(), false), 0)));
166167
// TODO: how to properly disable these warnings?
167168
errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
168169
return id == "logChecker";
@@ -188,8 +189,8 @@ class TestCppcheck : public TestFixture {
188189
Suppressions supprs;
189190
ErrorLogger2 errorLogger;
190191
CppCheck cppcheck(s, supprs, errorLogger, false, {});
191-
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_a.path())));
192-
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_b.path())));
192+
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_a.path(), Path::identify(test_file_a.path(), false), 0)));
193+
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_b.path(), Path::identify(test_file_b.path(), false), 0)));
193194
// TODO: how to properly disable these warnings?
194195
errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
195196
return msg.id == "logChecker";
@@ -220,7 +221,7 @@ class TestCppcheck : public TestFixture {
220221
Suppressions supprs;
221222
ErrorLogger2 errorLogger;
222223
CppCheck cppcheck(s, supprs, errorLogger, false, {});
223-
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file.path())));
224+
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file.path(), Path::identify(test_file.path(), false), 0)));
224225
// TODO: how to properly disable these warnings?
225226
errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
226227
return msg.id == "logChecker";

test/testexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TestExecutor : public TestFixture {
5858
}
5959

6060
void hasToLogSimple() {
61-
const std::list<FileWithDetails> files{FileWithDetails{"test.c"}};
61+
const std::list<FileWithDetails> files{FileWithDetails{"test.c", Standards::Language::C, 0}};
6262
const std::list<FileSettings> fileSettings;
6363
// this is the "simple" format
6464
const auto settings = dinit(Settings,

test/testfilesettings.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,46 @@ class TestFileSettings : public TestFixture {
3131

3232
void test() const {
3333
{
34-
const FileWithDetails p{"file.cpp"};
35-
ASSERT_EQUALS("file.cpp", p.path());
36-
ASSERT_EQUALS("file.cpp", p.spath());
37-
ASSERT_EQUALS_ENUM(Standards::Language::None, p.lang());
38-
ASSERT_EQUALS(0, p.size());
34+
const FileWithDetails p{"file.c", Standards::Language::C, 456};
35+
ASSERT_EQUALS("file.c", p.path());
36+
ASSERT_EQUALS("file.c", p.spath());
37+
ASSERT_EQUALS_ENUM(Standards::Language::C, p.lang());
38+
ASSERT_EQUALS(456, p.size());
3939
}
4040
{
41-
const FileWithDetails p{"file.cpp", Standards::Language::C, 123};
41+
const FileWithDetails p{"file.cpp", Standards::Language::CPP, 123};
4242
ASSERT_EQUALS("file.cpp", p.path());
4343
ASSERT_EQUALS("file.cpp", p.spath());
44-
ASSERT_EQUALS_ENUM(Standards::Language::C, p.lang());
44+
ASSERT_EQUALS_ENUM(Standards::Language::CPP, p.lang());
4545
ASSERT_EQUALS(123, p.size());
4646
}
4747
{
48-
const FileWithDetails p{"in/file.cpp"};
48+
const FileWithDetails p{"in/file.cpp", Standards::Language::CPP, 123};
4949
ASSERT_EQUALS("in/file.cpp", p.path());
5050
ASSERT_EQUALS("in/file.cpp", p.spath());
51-
ASSERT_EQUALS_ENUM(Standards::Language::None, p.lang());
52-
ASSERT_EQUALS(0, p.size());
51+
ASSERT_EQUALS_ENUM(Standards::Language::CPP, p.lang());
52+
ASSERT_EQUALS(123, p.size());
5353
}
5454
{
55-
const FileWithDetails p{"in\\file.cpp"};
55+
const FileWithDetails p{"in\\file.cpp", Standards::Language::CPP, 123};
5656
ASSERT_EQUALS("in\\file.cpp", p.path());
5757
ASSERT_EQUALS("in/file.cpp", p.spath());
58-
ASSERT_EQUALS_ENUM(Standards::Language::None, p.lang());
59-
ASSERT_EQUALS(0, p.size());
58+
ASSERT_EQUALS_ENUM(Standards::Language::CPP, p.lang());
59+
ASSERT_EQUALS(123, p.size());
6060
}
6161
{
62-
const FileWithDetails p{"in/../file.cpp"};
62+
const FileWithDetails p{"in/../file.cpp", Standards::Language::CPP, 123};
6363
ASSERT_EQUALS("in/../file.cpp", p.path());
6464
ASSERT_EQUALS("file.cpp", p.spath());
65-
ASSERT_EQUALS_ENUM(Standards::Language::None, p.lang());
66-
ASSERT_EQUALS(0, p.size());
65+
ASSERT_EQUALS_ENUM(Standards::Language::CPP, p.lang());
66+
ASSERT_EQUALS(123, p.size());
6767
}
6868
{
69-
const FileWithDetails p{"in\\..\\file.cpp"};
69+
const FileWithDetails p{"in\\..\\file.cpp", Standards::Language::CPP, 123};
7070
ASSERT_EQUALS("in\\..\\file.cpp", p.path());
7171
ASSERT_EQUALS("file.cpp", p.spath());
72-
ASSERT_EQUALS_ENUM(Standards::Language::None, p.lang());
73-
ASSERT_EQUALS(0, p.size());
72+
ASSERT_EQUALS_ENUM(Standards::Language::CPP, p.lang());
73+
ASSERT_EQUALS(123, p.size());
7474
}
7575
}
7676
};

test/testimportproject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TestImportProject : public TestFixture {
7171
}
7272

7373
void setDefines() const {
74-
FileSettings fs{"test.cpp"};
74+
FileSettings fs{"test.cpp", Standards::Language::CPP, 0};
7575

7676
ImportProject::fsSetDefines(fs, "A");
7777
ASSERT_EQUALS("A=1", fs.defines);
@@ -87,7 +87,7 @@ class TestImportProject : public TestFixture {
8787
}
8888

8989
void setIncludePaths1() const {
90-
FileSettings fs{"test.cpp"};
90+
FileSettings fs{"test.cpp", Standards::Language::CPP, 0};
9191
std::list<std::string> in(1, "../include");
9292
std::map<std::string, std::string, cppcheck::stricmp> variables;
9393
ImportProject::fsSetIncludePaths(fs, "abc/def/", in, variables);
@@ -96,7 +96,7 @@ class TestImportProject : public TestFixture {
9696
}
9797

9898
void setIncludePaths2() const {
99-
FileSettings fs{"test.cpp"};
99+
FileSettings fs{"test.cpp", Standards::Language::CPP, 0};
100100
std::list<std::string> in(1, "$(SolutionDir)other");
101101
std::map<std::string, std::string, cppcheck::stricmp> variables;
102102
variables["SolutionDir"] = "c:/abc/";
@@ -106,7 +106,7 @@ class TestImportProject : public TestFixture {
106106
}
107107

108108
void setIncludePaths3() const { // macro names are case insensitive
109-
FileSettings fs{"test.cpp"};
109+
FileSettings fs{"test.cpp", Standards::Language::CPP, 0};
110110
std::list<std::string> in(1, "$(SOLUTIONDIR)other");
111111
std::map<std::string, std::string, cppcheck::stricmp> variables;
112112
variables["SolutionDir"] = "c:/abc/";
@@ -393,8 +393,8 @@ class TestImportProject : public TestFixture {
393393
}
394394

395395
void ignorePaths() const {
396-
FileSettings fs1{"foo/bar"};
397-
FileSettings fs2{"qwe/rty"};
396+
FileSettings fs1{"foo/bar", Standards::Language::CPP, 0};
397+
FileSettings fs2{"qwe/rty", Standards::Language::CPP, 0};
398398
TestImporter project;
399399
project.fileSettings = {std::move(fs1), std::move(fs2)};
400400

0 commit comments

Comments
 (0)