Skip to content

Commit 6ebf5aa

Browse files
committed
pass language to TokenList constructor [skip ci]
1 parent deac337 commit 6ebf5aa

15 files changed

Lines changed: 34 additions & 77 deletions

lib/cppcheck.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,8 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
903903

904904
if (mUnusedFunctionsCheck && (mSettings.useSingleJob() || analyzerInformation)) {
905905
std::size_t hash = 0;
906+
// markup files are special and do not adhere to the enforced language
906907
TokenList tokenlist{&mSettings, Standards::Language::C};
907-
// enforce the language since markup files are special and do not adhere to the enforced language
908-
tokenlist.setLang(Standards::Language::C, true); // TODO: remove when enforceLang handling has been removed
909908
if (fileStream) {
910909
std::vector<std::string> files;
911910
simplecpp::TokenList tokens(*fileStream, files, file.spath());
@@ -1051,7 +1050,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
10511050
}
10521051
TokenList tokenlist(&mSettings, file.lang());
10531052
std::istringstream istr2(code);
1054-
tokenlist.createTokens(istr2, file.lang()); // TODO: check result?
1053+
tokenlist.createTokens(istr2); // TODO: check result?
10551054
executeRules("define", tokenlist);
10561055
}
10571056
#endif

lib/importproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ namespace {
578578
const Settings s;
579579
TokenList tokenlist(&s, Standards::Language::C);
580580
std::istringstream istr(c);
581-
tokenlist.createTokens(istr, Standards::Language::C); // TODO: check result
581+
tokenlist.createTokens(istr); // TODO: check result
582582
// TODO: put in a helper
583583
// generate links
584584
{

lib/library.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ static std::vector<std::string> getnames(const char *names)
175175
return ret;
176176
}
177177

178-
static void gettokenlistfromvalid(const std::string& valid, bool cpp, TokenList& tokenList)
178+
static void gettokenlistfromvalid(const std::string& valid, TokenList& tokenList)
179179
{
180180
std::istringstream istr(valid + ',');
181-
tokenList.createTokens(istr, cpp ? Standards::Language::CPP : Standards::Language::C); // TODO: check result?
181+
tokenList.createTokens(istr); // TODO: check result?
182182
for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
183183
if (Token::Match(tok,"- %num%")) {
184184
tok->str("-" + tok->strAt(1));
@@ -1063,7 +1063,7 @@ bool Library::isIntArgValid(const Token *ftok, int argnr, const MathLib::bigint
10631063
if (ac->valid.find('.') != std::string::npos)
10641064
return isFloatArgValid(ftok, argnr, static_cast<double>(argvalue));
10651065
TokenList tokenList(nullptr, ftok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
1066-
gettokenlistfromvalid(ac->valid, ftok->isCpp(), tokenList);
1066+
gettokenlistfromvalid(ac->valid, tokenList);
10671067
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
10681068
if (tok->isNumber() && argvalue == MathLib::toBigNumber(tok))
10691069
return true;
@@ -1083,7 +1083,7 @@ bool Library::isFloatArgValid(const Token *ftok, int argnr, double argvalue) con
10831083
if (!ac || ac->valid.empty())
10841084
return true;
10851085
TokenList tokenList(nullptr, ftok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
1086-
gettokenlistfromvalid(ac->valid, ftok->isCpp(), tokenList);
1086+
gettokenlistfromvalid(ac->valid, tokenList);
10871087
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
10881088
if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toDoubleNumber(tok) && argvalue <= MathLib::toDoubleNumber(tok->tokAt(2)))
10891089
return true;

lib/programmemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ static std::shared_ptr<Token> createTokenFromExpression(const std::string& retur
17541754
{
17551755
const std::string code = "return " + returnValue + ";";
17561756
std::istringstream istr(code);
1757-
if (!tokenList->createTokens(istr, cpp ? Standards::Language::CPP : Standards::Language::C))
1757+
if (!tokenList->createTokens(istr))
17581758
return nullptr;
17591759
}
17601760

lib/symboldatabase.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,6 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
18091809
// In template arguments, there might not be AST
18101810
// Determine size by using the "raw tokens"
18111811
TokenList tokenList(&mSettings, dimension.tok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
1812-
tokenList.setLang(dimension.tok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
18131812
tokenList.addtoken(";", 0, 0, 0, false);
18141813
bool fail = false;
18151814
for (const Token *tok = dimension.tok; tok && !Token::Match(tok, "[,>]"); tok = tok->next()) {
@@ -7718,7 +7717,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
77187717
ValueType valuetype;
77197718
TokenList tokenList(&mSettings, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
77207719
std::istringstream istr(typestr+";");
7721-
tokenList.createTokens(istr, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C); // TODO: check result?
7720+
tokenList.createTokens(istr); // TODO: check result?
77227721
tokenList.simplifyStdType();
77237722
if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings)) {
77247723
valuetype.originalTypeName = typestr;
@@ -7808,7 +7807,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
78087807
}
78097808
TokenList tokenList(&mSettings, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C);
78107809
std::istringstream istr(typestr+";");
7811-
if (tokenList.createTokens(istr, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C)) {
7810+
if (tokenList.createTokens(istr)) {
78127811
ValueType vt;
78137812
tokenList.simplifyPlatformTypes();
78147813
tokenList.simplifyStdType();

lib/tokenlist.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,8 @@ TokenList::TokenList(const Settings* settings, Standards::Language lang)
6464
: mTokensFrontBack(new TokensFrontBack)
6565
, mSettings(settings)
6666
{
67-
if (mSettings && (mSettings->enforcedLang != Standards::Language::None)) {
68-
mLang = mSettings->enforcedLang;
69-
}
70-
else {
71-
assert(lang != Standards::Language::None);
72-
mLang = lang;
73-
}
67+
assert(lang != Standards::Language::None);
68+
mLang = lang;
7469
}
7570

7671
TokenList::~TokenList()
@@ -350,16 +345,8 @@ void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
350345

351346
//---------------------------------------------------------------------------
352347

353-
// TODO: remove lang
354-
bool TokenList::createTokens(std::istream &code, Standards::Language lang)
348+
bool TokenList::createTokens(std::istream &code)
355349
{
356-
ASSERT_LANG(lang != Standards::Language::None);
357-
if (mLang == Standards::Language::None) {
358-
mLang = lang;
359-
} else {
360-
ASSERT_LANG(lang == mLang);
361-
}
362-
363350
return createTokensInternal(code, mFiles.empty() ? "" : *mFiles.cbegin());
364351
}
365352

@@ -2293,17 +2280,6 @@ bool TokenList::isCPP() const
22932280
return mLang == Standards::Language::CPP;
22942281
}
22952282

2296-
void TokenList::setLang(Standards::Language lang, bool force)
2297-
{
2298-
ASSERT_LANG(lang != Standards::Language::None);
2299-
if (!force)
2300-
{
2301-
ASSERT_LANG(mLang == Standards::Language::None);
2302-
}
2303-
2304-
mLang = lang;
2305-
}
2306-
23072283
const Token * TokenList::isFunctionHead(const Token *tok, const std::string &endsWith)
23082284
{
23092285
if (!tok)

lib/tokenlist.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ class CPPCHECKLIB TokenList {
6868
/** @return true if the code is C++ */
6969
bool isCPP() const;
7070

71-
// TODO: get rid of this
72-
void setLang(Standards::Language lang, bool force = false);
73-
7471
/**
7572
* Delete all tokens in given token list
7673
* @param tok token list to delete
@@ -103,9 +100,8 @@ class CPPCHECKLIB TokenList {
103100
* - UTF in the code are not handled.
104101
* - comments are not handled.
105102
* @param code input stream for code
106-
* @param lang the language of the code
107103
*/
108-
bool createTokens(std::istream &code, Standards::Language lang);
104+
bool createTokens(std::istream &code);
109105

110106
void createTokens(simplecpp::TokenList&& tokenList);
111107

lib/valueflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ static bool isNotEqual(std::pair<const Token*, const Token*> x, const std::strin
19451945
{
19461946
TokenList tokenList(nullptr, cpp ? Standards::Language::CPP : Standards::Language::C);
19471947
std::istringstream istr(y);
1948-
tokenList.createTokens(istr, cpp ? Standards::Language::CPP : Standards::Language::C); // TODO: check result?
1948+
tokenList.createTokens(istr); // TODO: check result?
19491949
return isNotEqual(x, std::make_pair(tokenList.front(), tokenList.back()));
19501950
}
19511951
static bool isNotEqual(std::pair<const Token*, const Token*> x, const ValueType* y, bool cpp)
@@ -7053,7 +7053,7 @@ static bool getMinMaxValues(const std::string& typestr,
70537053
{
70547054
TokenList typeTokens(&settings, cpp ? Standards::Language::CPP : Standards::Language::C);
70557055
std::istringstream istr(typestr + ";");
7056-
if (!typeTokens.createTokens(istr, cpp ? Standards::Language::CPP : Standards::Language::C))
7056+
if (!typeTokens.createTokens(istr))
70577057
return false;
70587058
typeTokens.simplifyPlatformTypes();
70597059
typeTokens.simplifyStdType();

test/helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SimpleTokenizer : public Tokenizer {
8484
if (list.front())
8585
throw std::runtime_error("token list is not empty");
8686
list.appendFileIfNew(filename);
87-
if (!list.createTokens(istr, Path::identify(filename, false)))
87+
if (!list.createTokens(istr))
8888
return false;
8989

9090
return simplifyTokens1("");
@@ -102,7 +102,7 @@ class SimpleTokenList
102102
: list{&settings, lang}
103103
{
104104
std::istringstream iss(code);
105-
if (!list.createTokens(iss, lang))
105+
if (!list.createTokens(iss))
106106
throw std::runtime_error("creating tokens failed");
107107
}
108108

@@ -259,7 +259,7 @@ struct TokenListHelper
259259
if (tokenlist.front())
260260
throw std::runtime_error("token list is not empty");
261261
tokenlist.appendFileIfNew(file);
262-
return tokenlist.createTokens(istr, Path::identify(file, false));
262+
return tokenlist.createTokens(istr);
263263
}
264264
};
265265

test/testlibrary.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class TestLibrary : public TestFixture {
153153

154154
TokenList tokenList(&settingsDefault, Standards::Language::CPP);
155155
std::istringstream istr("foo();"); // <- too few arguments, not library function
156-
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
156+
ASSERT(tokenList.createTokens(istr));
157157
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
158158
tokenList.createAst();
159159

@@ -177,7 +177,7 @@ class TestLibrary : public TestFixture {
177177
{
178178
TokenList tokenList(&settingsDefault, Standards::Language::CPP);
179179
std::istringstream istr("foo();"); // <- too few arguments, not library function
180-
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
180+
ASSERT(tokenList.createTokens(istr));
181181
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
182182
tokenList.createAst();
183183

@@ -186,7 +186,7 @@ class TestLibrary : public TestFixture {
186186
{
187187
TokenList tokenList(&settingsDefault, Standards::Language::CPP);
188188
std::istringstream istr("foo(a);"); // <- library function
189-
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
189+
ASSERT(tokenList.createTokens(istr));
190190
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
191191
tokenList.createAst();
192192

@@ -197,7 +197,7 @@ class TestLibrary : public TestFixture {
197197
{
198198
TokenList tokenList(&settingsDefault, Standards::Language::CPP);
199199
std::istringstream istr("foo(a, b);"); // <- library function
200-
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
200+
ASSERT(tokenList.createTokens(istr));
201201
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
202202
tokenList.createAst();
203203

@@ -208,7 +208,7 @@ class TestLibrary : public TestFixture {
208208
{
209209
TokenList tokenList(&settingsDefault, Standards::Language::CPP);
210210
std::istringstream istr("foo(a, b, c);"); // <- too much arguments, not library function
211-
ASSERT(tokenList.createTokens(istr, Standards::Language::CPP));
211+
ASSERT(tokenList.createTokens(istr));
212212
Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous());
213213
tokenList.createAst();
214214

0 commit comments

Comments
 (0)