8000 small `simplecpp::TokenList` usage cleanup (#7438) · firewave/cppcheck@9ae8547 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ae8547

Browse files
authored
small simplecpp::TokenList usage cleanup (danmar#7438)
1 parent 4792249 commit 9ae8547

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

lib/cppcheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,16 +907,16 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
907907
// enforce the language since markup files are special and do not adhere to the enforced language
908908
tokenizer.list.setLang(Standards::Language::C, true);
909909
if (fileStream) {
910-
std::vector<std::string> files{file.spath()};
911-
simplecpp::TokenList tokens(*fileStream, files);
910+
std::vector<std::string> files;
911+
simplecpp::TokenList tokens(*fileStream, files, file.spath());
912912
if (analyzerInformation) {
913913
const Preprocessor preprocessor(mSettings, mErrorLogger);
914914
hash = calculateHash(preprocessor, tokens, mSettings, mSuppressions);
915915
}
916916
tokenizer.list.createTokens(std::move(tokens));
917917
}
918918
else {
919-
std::vector<std::string> files{file.spath()};
919+
std::vector<std::string> files;
920920
simplecpp::TokenList tokens(file.spath(), files);
921921
if (analyzerInformation) {
922922
const Preprocessor preprocessor(mSettings, mErrorLogger);

test/testpreprocessor.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ class TestPreprocessor : public TestFixture {
6161
return tokens2.stringify();
6262
}
6363

64-
static void preprocess(const char code[], std::vector<std::string> &files, TokenList& tokenlist, const simplecpp::DUI& dui)
64+
static void preprocess(const char code[], std::vector<std::string> &files, const std::string& file0, TokenList& tokenlist, const simplecpp::DUI& dui)
6565
{
66+
if (!files.empty())
67+
throw std::runtime_error("file list not empty");
68+
6669
if (tokenlist.front())
6770
throw std::runtime_error("token list not empty");
6871

6972
std::istringstream istr(code);
70-
const simplecpp::TokenList tokens1(istr, files, files[0]);
73+
const simplecpp::TokenList tokens1(istr, files, file0);
7174

7275
// Preprocess..
7376
simplecpp::TokenList tokens2(files);
@@ -81,9 +84,9 @@ class TestPreprocessor : public TestFixture {
8184

8285
static std::vector<RemarkComment> getRemarkComments(const char code[], ErrorLogger& errorLogger)
8386
{
84-
std::vector<std::string> files{"test.cpp"};
87+
std::vector<std::string> files;
8588
std::istringstream istr(code);
86-
const simplecpp::TokenList tokens1(istr, files, files[0]);
89+
const simplecpp::TokenList tokens1(istr, files, "test.cpp");
8790

8891
const Settings settings;
8992

@@ -2570,44 +2573,48 @@ class TestPreprocessor : public TestFixture {
25702573
}
25712574

25722575
void standard() const {
2573-
std::vector<std::string> files = {"test.cpp"};
25742576

25752577
const char code[] = "int a;";
25762578
// TODO: this bypasses the standard determined from the settings - the parameter should not be exposed
25772579
simplecpp::DUI dui;
25782580

25792581
{
25802582
dui.std = "c89";
2583+
std::vector<std::string> files;
25812584
TokenList tokenlist{&settingsDefault};
2582-
preprocess(code, files, tokenlist, dui);
2585+
preprocess(code, files, "test.cpp", tokenlist, dui);
25832586
ASSERT(tokenlist.front());
25842587
}
25852588

25862589
{
25872590
dui.std = "gnu23";
2591+
std::vector<std::string> files;
25882592
TokenList tokenlist{&settingsDefault};
2589-
preprocess(code, files, tokenlist, dui);
2593+
preprocess(code, files, "test.cpp", tokenlist, dui);
25902594
ASSERT(tokenlist.front());
25912595
}
25922596

25932597
{
25942598
dui.std = "c++98";
2599+
std::vector<std::string> files;
25952600
TokenList tokenlist{&settingsDefault};
2596-
preprocess(code, files, tokenlist, dui);
2601+
preprocess(code, files, "test.cpp", tokenlist, dui);
25972602
ASSERT(tokenlist.front());
25982603
}
25992604

26002605
{
26012606
dui.std = "gnu++26";
2607+
std::vector<std::string> files;
26022608
TokenList tokenlist{&settingsDefault};
2603-
preprocess(code, files, tokenlist, dui);
2609+
preprocess(code, files, "test.cpp", tokenlist, dui);
26042610
ASSERT(tokenlist.front());
26052611
}
26062612

26072613
{
26082614
dui.std = "gnu77";
2615+
std::vector<std::string> files;
26092616
TokenList tokenlist{&settingsDefault};
2610-
preprocess(code, files, tokenlist, dui);
2617+
preprocess(code, files, "test.cpp", tokenlist, dui);
26112618
ASSERT(!tokenlist.front()); // nothing is tokenized when an unknown standard is provided
26122619
}
26132620
}

test/testtokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class TestTokenizer : public TestFixture {
553553
Preprocessor preprocessor(settings, *this);
554554
std::istringstream istr(filedata);
555555
simplecpp::OutputList outputList;
556-
std::vector<std::string> files{filename};
556+
std::vector<std::string> files;
557557
const simplecpp::TokenList tokens1(istr, files, filename, &outputList);
558558
std::list<Directive> directives = preprocessor.createDirectives(tokens1);
559559

0 commit comments

Comments
 (0)
0