Skip to content

Commit 2c7ed8f

Browse files
authored
TokenList: removed determineCppC() / removed language fallbacks / cleaned up asserts (#7515)
1 parent 3fe3fb5 commit 2c7ed8f

File tree

2 files changed

+2
-46
lines changed

2 files changed

+2
-46
lines changed

lib/tokenlist.cpp

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "token.h"
3333

3434
#include <algorithm>
35+
#include <cassert>
3536
#include <cctype>
3637
#include <cstdint>
3738
#include <exception>
@@ -45,15 +46,6 @@
4546

4647
#include <simplecpp.h>
4748

48-
//#define N_ASSERT_LANG
49-
50-
#ifndef N_ASSERT_LANG
51-
#include <cassert>
52-
#define ASSERT_LANG(x) assert(x)
53-
#else
54-
#define ASSERT_LANG(x)
55-
#endif
56-
5749
// How many compileExpression recursions are allowed?
5850
// For practical code this could be endless. But in some special torture test
5951
// there needs to be a limit.
@@ -97,25 +89,9 @@ void TokenList::deallocateTokens()
9789
mFiles.clear();
9890
}
9991

100-
void TokenList::determineCppC()
101-
{
102-
// only try to determine if it wasn't enforced
103-
if (mLang == Standards::Language::None) {
104-
ASSERT_LANG(!getSourceFilePath().empty());
105-
mLang = Path::identify(getSourceFilePath(), mSettings.cppHeaderProbe);
106-
// TODO: cannot enable assert as this might occur for unknown extensions
107-
//ASSERT_LANG(mLang != Standards::Language::None);
108-
if (mLang == Standards::Language::None) {
109-
// TODO: should default to C instead like we do for headers
110-
// default to C++
111-
mLang = Standards::Language::CPP;
112-
}
113-
}
114-
}
115-
11692
int TokenList::appendFileIfNew(std::string fileName)
11793
{
118-
ASSERT_LANG(!fileName.empty());
94+
assert(!fileName.empty());
11995

12096
// Has this file been tokenized already?
12197
auto it = std::find_if(mFiles.cbegin(), mFiles.cend(), [&](const std::string& f) {
@@ -127,10 +103,6 @@ int TokenList::appendFileIfNew(std::string fileName)
127103
// The "mFiles" vector remembers what files have been tokenized..
128104
mFiles.push_back(std::move(fileName));
129105

130-
// Update mIsC and mIsCpp properties
131-
if (mFiles.size() == 1) { // Update only useful if first file added to _files
132-
determineCppC();
133-
}
134106
return mFiles.size() - 1;
135107
}
136108

@@ -378,8 +350,6 @@ void TokenList::createTokens(simplecpp::TokenList&& tokenList)
378350
else
379351
mFiles.clear();
380352

381-
determineCppC();
382-
383353
for (const simplecpp::Token *tok = tokenList.cfront(); tok;) {
384354

385355
// TODO: move from TokenList
@@ -2247,23 +2217,11 @@ bool TokenList::isKeyword(const std::string &str) const
22472217

22482218
bool TokenList::isC() const
22492219
{
2250-
ASSERT_LANG(mLang != Standards::Language::None);
2251-
2252-
// TODO: remove the fallback
2253-
if (mLang == Standards::Language::None)
2254-
return false; // treat as C++ by default
2255-
22562220
return mLang == Standards::Language::C;
22572221
}
22582222

22592223
bool TokenList::isCPP() const
22602224
{
2261-
ASSERT_LANG(mLang != Standards::Language::None);
2262-
2263-
// TODO: remove the fallback
2264-
if (mLang == Standards::Language::None)
2265-
return true; // treat as C++ by default
2266-
22672225
return mLang == Standards::Language::CPP;
22682226
}
22692227

lib/tokenlist.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ class CPPCHECKLIB TokenList {
204204
static const Token * isFunctionHead(const Token *tok, const std::string &endsWith);
205205

206206
private:
207-
void determineCppC();
208-
209207
bool createTokensInternal(std::istream &code, const std::string& file0);
210208

211209
/** Token list */

0 commit comments

Comments
 (0)