Skip to content

Commit 4d80df2

Browse files
committed
Added pointer to Type to Token (similar to Token::Variable() and Token::function()):
- Accessible via Token::type() - Renamed former Token::type() to Token::tokType() - Removed SymbolDatabase::isClassOrStruct()
1 parent aaefdd2 commit 4d80df2

25 files changed

+218
-204
lines changed

lib/astutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ bool isSameExpression(bool cpp, const Token *tok1, const Token *tok2, const std:
238238
if (t1 != end1 || t2 != end2)
239239
return false;
240240
}
241-
if (tok1->type() == Token::eIncDecOp || tok1->isAssignmentOp())
241+
if (tok1->tokType() == Token::eIncDecOp || tok1->isAssignmentOp())
242242
return false;
243243
// bailout when we see ({..})
244244
if (tok1->str() == "{")
@@ -328,7 +328,7 @@ bool isConstExpression(const Token *tok, const std::set<std::string> &constFunct
328328
else if (tok->function() && !tok->function()->isConst())
329329
return false;
330330
}
331-
if (tok->type() == Token::eIncDecOp)
331+
if (tok->tokType() == Token::eIncDecOp)
332332
return false;
333333
// bailout when we see ({..})
334334
if (tok->str() == "{")

lib/checkassert.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void CheckAssert::assertWithSideEffects()
4444
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
4545
checkVariableAssignment(tmp);
4646

47-
if (tmp->type() == Token::eFunction) {
47+
if (tmp->tokType() == Token::eFunction) {
4848
const Function* f = tmp->function();
4949

5050
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
@@ -54,7 +54,7 @@ void CheckAssert::assertWithSideEffects()
5454
if (!scope) continue;
5555

5656
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
57-
if (tok2->type() != Token::eAssignmentOp && tok2->type() != Token::eIncDecOp)
57+
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
5858
continue;
5959

6060
const Variable* var = tok2->previous()->variable();
@@ -113,7 +113,7 @@ void CheckAssert::checkVariableAssignment(const Token* assignTok)
113113
return;
114114

115115
// assignment
116-
if (assignTok->isAssignmentOp() || assignTok->type() == Token::eIncDecOp) {
116+
if (assignTok->isAssignmentOp() || assignTok->tokType() == Token::eIncDecOp) {
117117
if (prevVar->isConst())
118118
return;
119119

lib/checkautovariables.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ void CheckAutoVariables::errorUselessAssignmentPtrArg(const Token *tok)
305305
// return temporary?
306306
bool CheckAutoVariables::returnTemporary(const Token *tok) const
307307
{
308-
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
309-
310308
bool func = false; // Might it be a function call?
311309
bool retref = false; // is there such a function that returns a reference?
312310
bool retvalue = false; // is there such a function that returns a value?
@@ -330,15 +328,15 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
330328
else
331329
retref = true; // Assume that a reference is returned
332330
} else {
333-
if (symbolDatabase->isClassOrStruct(start->str()))
331+
if (start->type())
334332
retvalue = true;
335333
else
336334
retref = true;
337335
}
338336
}
339337
func = true;
340338
}
341-
if (!func && symbolDatabase->isClassOrStruct(tok->str()))
339+
if (!func && tok->type())
342340
return true;
343341

344342
return bool(!retref && retvalue);

lib/checkbool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void CheckBool::checkComparisonOfFuncReturningBool()
227227
for (std::size_t i = 0; i < functionsCount; ++i) {
228228
const Scope * scope = symbolDatabase->functionScopes[i];
229229
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
230-
if (tok->type() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
230+
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
231231
continue;
232232
const Token *firstToken = tok->previous();
233233
if (tok->strAt(-1) == ")") {
@@ -291,7 +291,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
291291
for (std::size_t i = 0; i < functions; ++i) {
292292
const Scope * scope = symbolDatabase->functionScopes[i];
293293
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
294-
if (tok->type() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
294+
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
295295
continue;
296296
bool firstTokenBool = false;
297297

lib/checkbufferoverrun.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
319319
const MathLib::bigint sz = MathLib::toLongNumber(argtok->str());
320320
if ((std::size_t)sz > arraySize)
321321
error = true;
322-
} else if (argtok->type() == Token::eChar && Token::Match(argtok->next(), ",|)") && charSizeToken)
322+
} else if (argtok->tokType() == Token::eChar && Token::Match(argtok->next(), ",|)") && charSizeToken)
323323
*charSizeToken = argtok; //sizeArgumentAsCharError(argtok);
324324
break;
325325
case Library::ArgumentChecks::MinSize::MUL:
@@ -352,7 +352,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
352352
}
353353
break;
354354
case Library::ArgumentChecks::MinSize::SIZEOF:
355-
if (argtok->type() == Token::eString && Token::getStrLength(argtok) >= arraySize)
355+
if (argtok->tokType() == Token::eString && Token::getStrLength(argtok) >= arraySize)
356356
error = true;
357357
break;
358358
case Library::ArgumentChecks::MinSize::NONE:
@@ -1470,13 +1470,13 @@ MathLib::biguint CheckBufferOverrun::countSprintfLength(const std::string &input
14701470
break;
14711471
case 'd':
14721472
i_d_x_f_found = true;
1473-
if (paramIter != parameters.end() && *paramIter && (*paramIter)->type() != Token::eString)
1473+
if (paramIter != parameters.end() && *paramIter && (*paramIter)->tokType() != Token::eString)
14741474
parameterLength = (*paramIter)->str().length();
14751475

14761476
handleNextParameter = true;
14771477
break;
14781478
case 's':
1479-
if (paramIter != parameters.end() && *paramIter && (*paramIter)->type() == Token::eString)
1479+
if (paramIter != parameters.end() && *paramIter && (*paramIter)->tokType() == Token::eString)
14801480
parameterLength = Token::getStrLength(*paramIter);
14811481

14821482
handleNextParameter = true;
@@ -1765,7 +1765,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
17651765
return;
17661766

17671767
// skip comparison
1768-
if (tok->type() == Token::eComparisonOp)
1768+
if (tok->tokType() == Token::eComparisonOp)
17691769
tok = tok->tokAt(2);
17701770

17711771
if (!tok)

lib/checkclass.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,11 +1043,8 @@ void CheckClass::checkMemset()
10431043
if (typeTok && typeTok->str() == "(")
10441044
typeTok = typeTok->next();
10451045

1046-
if (!type) {
1047-
const Type* t = symbolDatabase->findVariableType(scope, typeTok);
1048-
if (t)
1049-
type = t->classScope;
1050-
}
1046+
if (!type && typeTok->type())
1047+
type = typeTok->type()->classScope;
10511048

10521049
if (type) {
10531050
std::list<const Scope *> parsedTypes;
@@ -1693,7 +1690,7 @@ void CheckClass::checkConst()
16931690
} else {
16941691
// don't warn for unknown types..
16951692
// LPVOID, HDC, etc
1696-
if (previous->isUpperCaseName() && previous->str().size() > 2 && !symbolDatabase->isClassOrStruct(previous->str()))
1693+
if (previous->str().size() > 2 && !previous->type() && previous->isUpperCaseName())
16971694
continue;
16981695
}
16991696

@@ -1854,13 +1851,13 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
18541851
const Token* lhs = tok1->tokAt(-1);
18551852
if (lhs->str() == "&") {
18561853
lhs = lhs->previous();
1857-
if (lhs->type() == Token::eAssignmentOp && lhs->previous()->variable()) {
1854+
if (lhs->tokType() == Token::eAssignmentOp && lhs->previous()->variable()) {
18581855
if (lhs->previous()->variable()->typeStartToken()->strAt(-1) != "const" && lhs->previous()->variable()->isPointer())
18591856
return false;
18601857
}
18611858
} else {
18621859
const Variable* v2 = lhs->previous()->variable();
1863-
if (lhs->type() == Token::eAssignmentOp && v2)
1860+
if (lhs->tokType() == Token::eAssignmentOp && v2)
18641861
if (!v2->isConst() && v2->isReference() && lhs == v2->nameToken()->next())
18651862
return false;
18661863
}
@@ -1900,7 +1897,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
19001897
}
19011898

19021899
// Assignment
1903-
else if (end->next()->type() == Token::eAssignmentOp)
1900+
else if (end->next()->tokType() == Token::eAssignmentOp)
19041901
return (false);
19051902

19061903
// Streaming
@@ -1910,7 +1907,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
19101907
return (false);
19111908

19121909
// ++/--
1913-
else if (end->next()->type() == Token::eIncDecOp || tok1->previous()->type() == Token::eIncDecOp)
1910+
else if (end->next()->tokType() == Token::eIncDecOp || tok1->previous()->tokType() == Token::eIncDecOp)
19141911
return (false);
19151912

19161913

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ void CheckCondition::clarifyCondition()
852852
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
853853
if (tok2->str() == "(" || tok2->str() == "[")
854854
tok2 = tok2->link();
855-
else if (tok2->type() == Token::eComparisonOp) {
855+
else if (tok2->tokType() == Token::eComparisonOp) {
856856
// This might be a template
857857
if (!isC && tok2->link())
858858
break;

lib/checkinternal.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void CheckInternal::checkTokenMatchPatterns()
4141

4242
// Get pattern string
4343
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
44-
if (!pattern_tok || pattern_tok->type() != Token::eString)
44+
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
4545
continue;
4646

4747
const std::string pattern = pattern_tok->strValue();
@@ -89,7 +89,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns()
8989

9090
// Get pattern string
9191
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
92-
if (!pattern_tok || pattern_tok->type() != Token::eString)
92+
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
9393
continue;
9494

9595
const std::string pattern = pattern_tok->strValue();
@@ -171,7 +171,7 @@ void CheckInternal::checkMissingPercentCharacter()
171171

172172
// Get pattern string
173173
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
174-
if (!pattern_tok || pattern_tok->type() != Token::eString)
174+
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
175175
continue;
176176

177177
const std::string pattern = pattern_tok->strValue();
@@ -226,7 +226,7 @@ void CheckInternal::checkUnknownPattern()
226226

227227
// Get pattern string
228228
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
229-
if (!pattern_tok || pattern_tok->type() != Token::eString)
229+
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
230230
continue;
231231

232232
const std::string pattern = pattern_tok->strValue();
@@ -286,7 +286,7 @@ void CheckInternal::checkExtraWhitespace()
286286

287287
// Get pattern string
288288
const Token *pattern_tok = tok->tokAt(4)->nextArgument();
289-
if (!pattern_tok || pattern_tok->type() != Token::eString)
289+
if (!pattern_tok || pattern_tok->tokType() != Token::eString)
290290
continue;
291291

292292
const std::string pattern = pattern_tok->strValue();

0 commit comments

Comments
 (0)