Cppcheck
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Tokenizer Class Reference

The main purpose is to tokenize the source code. More...

#include <tokenize.h>

Classes

struct  TypedefInfo
 

Public Member Functions

 Tokenizer (const Settings &settings, ErrorLogger &errorLogger)
 
 ~Tokenizer ()
 
void setTimerResults (TimerResults *tr)
 
bool isC () const
 Is the code C. More...
 
bool isCPP () const
 Is the code CPP. More...
 
bool isScopeNoReturn (const Token *endScopeToken, bool *unknown=nullptr) const
 Check if inner scope ends with a call to a noreturn function. More...
 
bool simplifyTokens1 (const std::string &configuration)
 
nonneg int sizeOfType (const Token *type) const
 Calculates sizeof value for given type. More...
 
nonneg int sizeOfType (const std::string &type) const
 
bool hasIfdef (const Token *start, const Token *end) const
 
bool isPacked (const Token *bodyStart) const
 
NORETURN void syntaxError (const Token *tok, const std::string &code=emptyString) const
 Syntax error. More...
 
NORETURN void unmatchedToken (const Token *tok) const
 Syntax error. More...
 
NORETURN void syntaxErrorC (const Token *tok, const std::string &what) const
 Syntax error. More...
 
NORETURN void unknownMacroError (const Token *tok1) const
 Warn about unknown macro(s), configuration is recommended. More...
 
void unhandledCharLiteral (const Token *tok, const std::string &msg) const
 
const SymbolDatabasegetSymbolDatabase () const
 
void createSymbolDatabase ()
 
void printDebugOutput (int simplification) const
 print –debug output if debug flags match the simplification: 0=unknown/both simplifications 1=1st simplifications 2=2nd simplifications More...
 
void dump (std::ostream &out) const
 
TokendeleteInvalidTypedef (Token *typeDef)
 
nonneg int varIdCount () const
 Get variable count. More...
 
const Tokentokens () const
 
Tokentokens ()
 
const SettingsgetSettings () const
 
void calculateScopes ()
 
 Tokenizer (const Tokenizer &)=delete
 Disable copy constructor. More...
 
Tokenizeroperator= (const Tokenizer &)=delete
 Disable assignment operator. More...
 
void setDirectives (std::list< Directive > directives)
 

Static Public Member Functions

static const TokenisFunctionHead (const Token *tok, const std::string &endsWith)
 is token pointing at function head? More...
 
static bool isOneNumber (const std::string &s)
 Helper function to check whether number is one (1 or 0.1E+1 or 1E+0) or not? More...
 
static const TokenstartOfExecutableScope (const Token *tok)
 Helper function to check for start of function execution scope. More...
 

Public Attributes

TokenList list
 Token list: stores all tokens. More...
 

Private Member Functions

void setVarId ()
 Set variable id. More...
 
void setVarIdPass1 ()
 
void setVarIdPass2 ()
 
bool simplifyTokenList1 (const char FileName[])
 Basic simplification of tokenlist. More...
 
void simplifyHeadersAndUnusedTemplates ()
 If –check-headers=no has been given; then remove unneeded code in headers. More...
 
void removeExtraTemplateKeywords ()
 Remove extra "template" keywords that are not used by Cppcheck. More...
 
void splitTemplateRightAngleBrackets (bool check)
 Split up template right angle brackets. More...
 
void simplifyDebug ()
 
void simplifyAssignmentBlock ()
 Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}". More...
 
void arraySize ()
 Insert array size where it isn't given. More...
 
void arraySizeAfterValueFlow ()
 
void simplifyLabelsCaseDefault ()
 Simplify labels and 'case|default' syntaxes. More...
 
void simplifyCaseRange ()
 simplify case ranges (gcc extension) More...
 
void removeMacrosInGlobalScope ()
 Remove macros in global scope. More...
 
void addSemicolonAfterUnknownMacro ()
 
void removePragma ()
 
void removeMacroInClassDef ()
 Remove undefined macro in class definition: class DLLEXPORT Fred { }; class Fred FINAL : Base { };. More...
 
void sizeofAddParentheses ()
 Add parentheses for sizeof: sizeof x => sizeof(x) More...
 
void simplifyVarDecl (const bool only_k_r_fpar)
 Simplify variable declarations (split up) More...
 
void simplifyVarDecl (Token *tokBegin, const Token *const tokEnd, const bool only_k_r_fpar)
 
void simplifyInitVar ()
 Simplify variable initialization '; int *p(0);' => '; int *p = 0;'. More...
 
void simplifyStaticConst ()
 Simplify the location of "static" and "const" qualifiers in a variable declaration or definition. More...
 
void simplifyVariableMultipleAssign ()
 Simplify multiple assignments. More...
 
bool simplifyCAlternativeTokens ()
 Simplify the 'C Alternative Tokens' Examples: "if(s and t)" => "if(s && t)" "while((r bitand s) and not t)" => while((r & s) && !t)" "a and_eq b;" => "a &= b;". More...
 
bool simplifyAddBraces ()
 Add braces to an if-block, for-block, etc. More...
 
TokensimplifyAddBracesToCommand (Token *tok)
 Add braces to an if-block, for-block, etc. More...
 
TokensimplifyAddBracesPair (Token *tok, bool commandWithCondition)
 Add pair of braces to an single if-block, else-block, for-block, etc. More...
 
void simplifyUsingToTypedef ()
 
void simplifyTypedef ()
 typedef A mytype; mytype c; More...
 
void simplifyTypedefCpp ()
 
void simplifyTypedefLHS ()
 Move typedef token to the left og the expression. More...
 
bool simplifyUsing ()
 
void simplifyUsingError (const Token *usingStart, const Token *usingEnd)
 
void simplifyEmptyNamespaces ()
 Simplify useless C++ empty namespaces, like: 'namespace name% { }'. More...
 
void elseif ()
 Simplify "if else". More...
 
void simplifyIfSwitchForInit ()
 Simplify C++17/C++20 if/switch/for initialization expression. More...
 
void removeRedundantSemicolons ()
 Reduces "; ;" to ";", except in "( ; ; )". More...
 
void simplifyStructDecl ()
 Struct simplification "struct S { } s;" => "struct S { }; S s;". More...
 
bool simplifyRedundantParentheses ()
 Remove redundant parentheses: More...
 
void simplifyFunctionParameters ()
 Simplify functions like "void f(x) int x; {" into "void f(int x) {". More...
 
void simplifyFunctionTryCatch ()
 Simplify function level try blocks: Convert "void f() try {} catch (int) {}" to "void f() { try {} catch (int) {} }". More...
 
void simplifyTemplates ()
 Simplify templates. More...
 
void simplifyDoublePlusAndDoubleMinus ()
 
void simplifyRedundantConsecutiveBraces ()
 
void simplifyArrayAccessSyntax ()
 
void simplifyParameterVoid ()
 
void fillTypeSizes ()
 
void combineOperators ()
 
void combineStringAndCharLiterals ()
 
void concatenateNegativeNumberAndAnyPositive ()
 
void simplifyExternC ()
 
void simplifyRoundCurlyParentheses ()
 
void simplifyTypeIntrinsics ()
 
void simplifySQL ()
 
void checkForEnumsWithTypedef ()
 
void findComplicatedSyntaxErrorsInTemplates ()
 
void simplifyPointerToStandardType ()
 Simplify pointer to standard type (C only) More...
 
void simplifyFunctionPointers ()
 Simplify function pointers. More...
 
NORETURN void cppcheckError (const Token *tok) const
 Send error message to error logger about internal bug. More...
 
void createLinks ()
 Setup links for tokens so that one can call Token::link(). More...
 
void createLinks2 ()
 Setup links between < and >. More...
 
void markCppCasts ()
 Set isCast() for C++ casts. More...
 
void unhandled_macro_class_x_y (const Token *tok) const
 Report that there is an unhandled "class x y {" code. More...
 
void checkConfiguration () const
 Check configuration (unknown macros etc) More...
 
void macroWithSemicolonError (const Token *tok, const std::string &macroName) const
 
void validateC () const
 Is there C++ code in C file? More...
 
void validate () const
 assert that tokens are ok - used during debugging for example to catch problems in simplifyTokenList1/2. More...
 
void reportUnknownMacros () const
 Detect unknown macros and throw unknownMacro. More...
 
void findGarbageCode () const
 Detect garbage code and call syntaxError() if found. More...
 
void simplifyDeclspec ()
 Remove __declspec() More...
 
void simplifyCallingConvention ()
 Remove calling convention. More...
 
void simplifyAttribute ()
 Remove __attribute__ ((?)) More...
 
TokengetAttributeFuncTok (Token *tok, bool gccattr) const
 Get function token for a attribute. More...
 
void simplifyCppcheckAttribute ()
 Remove __cppcheck__ ((?)) More...
 
void simplifySpaceshipOperator ()
 Simplify c++20 spaceship operator. More...
 
void simplifyKeyword ()
 Remove keywords "volatile", "inline", "register", and "restrict". More...
 
void simplifyAsm ()
 Remove __asm. More...
 
void simplifyAsm2 ()
 asm heuristics, Put ^{} statements in asm() More...
 
void simplifyAt ()
 Simplify @… (compiler extension) More...
 
void simplifyBitfields ()
 Simplify bitfields - the field width is removed as we don't use it. More...
 
void removeUnnecessaryQualification ()
 Remove unnecessary member qualification. More...
 
void simplifyNamespaceStd ()
 Add std:: in front of std classes, when using namespace std; was given. More...
 
void simplifyMicrosoftMemoryFunctions ()
 Convert Microsoft memory functions CopyMemory(dst, src, len) -> memcpy(dst, src, len) FillMemory(dst, len, val) -> memset(dst, val, len) MoveMemory(dst, src, len) -> memmove(dst, src, len) ZeroMemory(dst, len) -> memset(dst, 0, len) More...
 
void simplifyMicrosoftStringFunctions ()
 Convert Microsoft string functions _tcscpy -> strcpy. More...
 
void simplifyBorland ()
 Remove Borland code. More...
 
void simplifyOperatorName ()
 Collapse operator name tokens into single token operator = => operator=. More...
 
void simplifyOverloadedOperators ()
 simplify overloaded operators: 'obj(123)' => 'obj . More...
 
void simplifyCPPAttribute ()
 Remove [[attribute]] (C++11 and later) from TokenList. More...
 
void simplifyNamespaceAliases ()
 Convert namespace aliases. More...
 
void simplifyNestedNamespace ()
 Convert C++17 style nested namespace to older style. More...
 
void simplifyCoroutines ()
 Simplify coroutines - just put parentheses around arguments for co_* keywords so they can be handled like function calls in data flow. More...
 
void prepareTernaryOpForAST ()
 Prepare ternary operators with parentheses so that the AST can be created. More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg, bool inconclusive=false) const
 report error message More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg, bool inconclusive=false) const
 
bool duplicateTypedef (Token *&tokPtr, const Token *name, const Token *typeDef) const
 
void unsupportedTypedef (const Token *tok) const
 
void printUnknownTypes () const
 Output list of unknown types. More...
 
const TokenprocessFunc (const Token *tok2, bool inOperator) const
 
TokenprocessFunc (Token *tok2, bool inOperator)
 
nonneg int newVarId ()
 Get new variable id. More...
 
void setPodTypes ()
 Set pod types. More...
 

Static Private Member Functions

static TokeninitVar (Token *tok)
 
static bool isMemberFunction (const Token *openParen)
 
static std::string simplifyString (const std::string &source)
 Modify strings in the token list by replacing hex and oct values. More...
 
static bool isGarbageExpr (const Token *start, const Token *end, bool allowSemicolon)
 Detect garbage expression. More...
 
static void setVarIdClassFunction (const std::string &classname, Token *const startToken, const Token *const endToken, const std::map< std::string, nonneg int > &varlist, std::map< nonneg int, std::map< std::string, nonneg int >> &structMembers, nonneg int &varId_)
 
static const TokenfindSQLBlockEnd (const Token *tokSQLStart)
 Find end of SQL (or PL/SQL) block. More...
 
static bool operatorEnd (const Token *tok)
 

Private Attributes

const SettingsmSettings
 settings More...
 
ErrorLoggermErrorLogger
 errorlogger More...
 
SymbolDatabasemSymbolDatabase {}
 Symbol database that all checks etc can use. More...
 
TemplateSimplifier *const mTemplateSimplifier
 
std::string mConfiguration
 E.g. More...
 
std::map< std::string, int > mTypeSize
 sizeof information for known types More...
 
std::vector< TypedefInfomTypedefInfo
 
std::list< DirectivemDirectives
 
nonneg int mVarId {}
 variable count More...
 
nonneg int mUnnamedCount {}
 unnamed count "Unnamed0", "Unnamed1", "Unnamed2", ... More...
 
TimerResultsmTimerResults {}
 TimerResults. More...
 

Friends

class SymbolDatabase
 
class TemplateSimplifier
 
class TestSimplifyTemplate
 
class TestSimplifyTypedef
 
class TestTokenizer
 

Detailed Description

The main purpose is to tokenize the source code.

It also has functions that simplify the token list

Definition at line 46 of file tokenize.h.

Constructor & Destructor Documentation

◆ Tokenizer() [1/2]

Tokenizer::Tokenizer ( const Settings settings,
ErrorLogger errorLogger 
)
explicit

Definition at line 155 of file tokenize.cpp.

◆ ~Tokenizer()

Tokenizer::~Tokenizer ( )

Definition at line 162 of file tokenize.cpp.

References mSymbolDatabase, and mTemplateSimplifier.

◆ Tokenizer() [2/2]

Tokenizer::Tokenizer ( const Tokenizer )
delete

Disable copy constructor.

Member Function Documentation

◆ addSemicolonAfterUnknownMacro()

void Tokenizer::addSemicolonAfterUnknownMacro ( )
private

◆ arraySize()

void Tokenizer::arraySize ( )
private

◆ arraySizeAfterValueFlow()

void Tokenizer::arraySizeAfterValueFlow ( )
private

◆ calculateScopes()

void Tokenizer::calculateScopes ( )

◆ checkConfiguration()

void Tokenizer::checkConfiguration ( ) const
private

◆ checkForEnumsWithTypedef()

void Tokenizer::checkForEnumsWithTypedef ( )
private

◆ combineOperators()

void Tokenizer::combineOperators ( )
private

◆ combineStringAndCharLiterals()

void Tokenizer::combineStringAndCharLiterals ( )
private

◆ concatenateNegativeNumberAndAnyPositive()

void Tokenizer::concatenateNegativeNumberAndAnyPositive ( )
private

◆ cppcheckError()

void Tokenizer::cppcheckError ( const Token tok) const
private

Send error message to error logger about internal bug.

Parameters
tokthe token that this bug concerns.

Definition at line 8083 of file tokenize.cpp.

References InternalError::INTERNAL, and printDebugOutput().

Referenced by setVarIdPass1(), and validate().

◆ createLinks()

void Tokenizer::createLinks ( )
private

Setup links for tokens so that one can call Token::link().

Definition at line 5267 of file tokenize.cpp.

References TokenList::front(), linkBrackets(), list, Token::next(), and unmatchedToken().

Referenced by simplifyTokenList1().

◆ createLinks2()

void Tokenizer::createLinks2 ( )
private

◆ createSymbolDatabase()

void Tokenizer::createSymbolDatabase ( )

◆ deleteInvalidTypedef()

Token * Tokenizer::deleteInvalidTypedef ( Token typeDef)

◆ dump()

void Tokenizer::dump ( std::ostream &  out) const

Definition at line 5918 of file tokenize.cpp.

References Token::astOperand1(), Token::astOperand2(), Token::astParent(), Settings::basePaths, bool_to_string(), Token::column(), ValueType::container, ValueType::dump(), TemplateSimplifier::dump(), Token::eChar, Token::eLogicalOp, Token::eString, Token::exprId(), TokenList::file(), TokenList::front(), Token::function(), Token::getMacroName(), Path::getRelativePath(), Token::getStrLength(), id_string(), Token::isArithmeticalOp(), Token::isAssignmentOp(), Token::isAtomic(), Token::isAttributeExport(), Token::isAttributeMaybeUnused(), Token::isAttributeUnused(), Token::isBoolean(), Token::isCast(), Token::isComparisonOp(), Token::isComplex(), Token::isExpandedMacro(), Token::isExternC(), MathLib::isFloat(), Token::isImplicitInt(), MathLib::isInt(), Token::isName(), Library::isnoreturn(), Token::isNumber(), Token::isOp(), Token::isRemovedVoidParameter(), Token::isRestrict(), Token::isSigned(), Token::isSplittedVarDeclComma(), Token::isSplittedVarDeclEq(), Token::isTemplateArg(), Token::isUnsigned(), Settings::library, Token::linenr(), Token::link(), list, Token::Match(), mDirectives, mSettings, mSymbolDatabase, mTemplateSimplifier, mTypedefInfo, Token::next(), Token::originalName(), Token::printValueFlow(), SymbolDatabase::printXml(), Token::scope(), Token::str(), Token::tokType(), ErrorLogger::toxml(), Token::type(), Token::values(), Token::valueType(), Token::variable(), and Token::varId().

Referenced by CppCheck::checkClang(), and CppCheck::checkFile().

◆ duplicateTypedef()

bool Tokenizer::duplicateTypedef ( Token *&  tokPtr,
const Token name,
const Token typeDef 
) const
private

◆ elseif()

void Tokenizer::elseif ( )
private

◆ fillTypeSizes()

void Tokenizer::fillTypeSizes ( )
private

◆ findComplicatedSyntaxErrorsInTemplates()

void Tokenizer::findComplicatedSyntaxErrorsInTemplates ( )
private

◆ findGarbageCode()

void Tokenizer::findGarbageCode ( ) const
private

Detect garbage code and call syntaxError() if found.

Referenced by simplifyTokenList1().

◆ findSQLBlockEnd()

static const Token* Tokenizer::findSQLBlockEnd ( const Token tokSQLStart)
staticprivate

Find end of SQL (or PL/SQL) block.

Referenced by simplifySQL().

◆ getAttributeFuncTok()

Token* Tokenizer::getAttributeFuncTok ( Token tok,
bool  gccattr 
) const
private

Get function token for a attribute.

◆ getSettings()

const Settings& Tokenizer::getSettings ( ) const
inline

◆ getSymbolDatabase()

const SymbolDatabase* Tokenizer::getSymbolDatabase ( ) const
inline

Definition at line 563 of file tokenize.h.

Referenced by CheckCondition::alwaysTrueFalse(), CheckBufferOverrun::argumentSize(), CheckNullPointer::arithmetic(), CheckBufferOverrun::arrayIndexThenCheck(), CheckAutoVariables::assignFunctionArg(), CheckAutoVariables::autoVariables(), CheckBufferOverrun::bufferOverflow(), CheckLeakAutoVar::check(), CheckMemoryLeakInClass::check(), CheckMemoryLeakStructMember::check(), CheckMemoryLeakNoVar::check(), CheckUninitVar::check(), CheckOther::checkAccessOfMovedVariable(), CheckBool::checkAssignBoolToFloat(), CheckBool::checkAssignBoolToPointer(), CheckCondition::checkAssignmentInCondition(), CheckBool::checkBitwiseOnBoolean(), CheckBoost::checkBoostForeachModification(), CheckOther::checkCastIntToCharAndBack(), CheckExceptionSafety::checkCatchExceptionByValue(), CheckOther::checkCharVariable(), CppCheck::checkClang(), CheckOther::checkComparePointers(), CheckCondition::checkCompareValueOutOfTypeRange(), CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse(), CheckBool::checkComparisonOfBoolExpressionWithInt(), CheckBool::checkComparisonOfBoolWithBool(), CheckBool::checkComparisonOfBoolWithInt(), CheckBool::checkComparisonOfFuncReturningBool(), CheckOther::checkConstVariable(), CheckIO::checkCoutCerrMisusage(), CheckStl::checkDereferenceInvalidIterator(), CheckOther::checkDuplicateBranch(), CheckCondition::checkDuplicateConditionalAssign(), CheckOther::checkDuplicateExpression(), CheckOther::checkEvaluationOrder(), CheckIO::checkFileUsage(), CheckStl::checkFindInsert(), CheckOther::checkFuncArgNamesDifferent(), CheckUnusedVar::checkFunctionVariableUsage(), CheckFunctions::checkIgnoredReturnValue(), CheckOther::checkIncompleteArrayFill(), CheckCondition::checkIncorrectLogicOperator(), CheckString::checkIncorrectStringCompare(), CheckBool::checkIncrementBoolean(), CheckOther::checkInvalidFree(), CheckOther::checkKnownArgument(), CheckOther::checkKnownPointerToBool(), CheckType::checkLongCast(), CheckFunctions::checkMathFunctions(), CheckFunctions::checkMissingReturn(), CheckOther::checkMisusedScopedObject(), CheckCondition::checkModuloAlwaysTrueFalse(), CheckStl::checkMutexes(), CheckOther::checkOverlappingWrite(), CheckOther::checkPassByReference(), CheckCondition::checkPointerAdditionResultNotNull(), CheckFunctions::checkProhibitedFunctions(), CheckMemoryLeakInFunction::checkReallocUsage(), CheckOther::checkRedundantAssignment(), CheckOther::checkRedundantCopy(), CheckExceptionSafety::checkRethrowCopy(), CheckOther::checkShadowVariables(), CheckOther::checkSignOfUnsignedVariable(), CheckSizeof::checkSizeofForArrayParameter(), CheckSizeof::checkSizeofForNumericParameter(), CheckSizeof::checkSizeofForPointerSize(), CheckUninitVar::checkStruct(), CheckUnusedVar::checkStructMemberUsage(), CheckOther::checkSuspiciousCaseInSwitch(), CheckOther::checkSuspiciousSemicolon(), CheckString::checkSuspiciousStringCompare(), CheckOther::checkUnreachableCode(), CheckOther::checkUnusedLabel(), CheckOther::checkVarFuncNullUB(), CheckOther::checkVariableScope(), CheckAutoVariables::checkVarLifetime(), CheckIO::checkWrongPrintfScanfArguments(), CheckOther::clarifyCalculation(), CheckCondition::clarifyCondition(), CheckOther::clarifyStatement(), Summaries::create(), CheckExceptionSafety::deallocThrow(), CheckExceptionSafety::destructors(), CheckCondition::duplicateCondition(), CheckStl::erase(), CheckStl::eraseIteratorOutOfBounds(), CTU::getFileInfo(), CheckClass::getFileInfo(), CTU::getUnsafeUsage(), CheckStl::if_find(), CheckStl::invalidContainer(), CheckFunctions::invalidFunctionUsage(), CheckOther::invalidPointerCast(), CheckIO::invalidScanf(), CheckStl::iterators(), CheckStl::knownEmptyContainer(), CheckFunctions::memsetInvalid2ndParam(), CheckFunctions::memsetZeroBytes(), CheckStl::mismatchingContainerIterator(), CheckStl::mismatchingContainers(), CheckStl::missingComparison(), CheckCondition::multiCondition(), CheckCondition::multiCondition2(), CheckBufferOverrun::negativeArraySize(), CheckStl::negativeIndex(), CheckExceptionSafety::nothrowThrows(), CheckNullPointer::nullConstantDereference(), CheckBufferOverrun::objectIndex(), CheckStl::outOfBounds(), CheckStl::outOfBoundsIndexExpression(), CheckString::overlappingStrcmp(), clangimport::parseClangAstDump(), CheckUnusedFunctions::parseTokens(), CheckBool::pointerArithBool(), Check64BitPortability::pointerassignment(), CheckPostfixOperator::postfixOperator(), CheckOther::redundantBitwiseOperationInSwitchError(), CheckStl::redundantCondition(), CheckLeakAutoVar::ret(), CheckExceptionSafety::rethrowNoCurrentException(), CheckFunctions::returnLocalStdMove(), CheckBool::returnValueOfFunctionReturningBool(), CheckStl::size(), CheckString::sprintfOverlappingData(), CheckStl::stlBoundaries(), CheckStl::stlOutOfBounds(), CheckStl::string_c_str(), CheckString::stringLiteralWrite(), CheckBufferOverrun::stringNotZeroTerminated(), CheckString::strPlusChar(), CheckExceptionSafety::unhandledExceptionSpecification(), CheckStl::uselessCalls(), CheckFunctions::useStandardLibrary(), CheckStl::useStlAlgorithm(), CheckVaarg::va_list_usage(), CheckVaarg::va_start_argument(), CheckUninitVar::valueFlowUninit(), and CheckOther::warningOldStylePointerCast().

◆ hasIfdef()

bool Tokenizer::hasIfdef ( const Token start,
const Token end 
) const

◆ initVar()

Token * Tokenizer::initVar ( Token tok)
staticprivate

◆ isC()

bool Tokenizer::isC ( ) const
inline

◆ isCPP()

bool Tokenizer::isCPP ( ) const
inline

◆ isFunctionHead()

const Token * Tokenizer::isFunctionHead ( const Token tok,
const std::string &  endsWith 
)
static

◆ isGarbageExpr()

static bool Tokenizer::isGarbageExpr ( const Token start,
const Token end,
bool  allowSemicolon 
)
staticprivate

Detect garbage expression.

◆ isMemberFunction()

bool Tokenizer::isMemberFunction ( const Token openParen)
staticprivate

Definition at line 2805 of file tokenize.cpp.

References isFunctionHead(), Token::Match(), and Token::tokAt().

Referenced by simplifyUsing().

◆ isOneNumber()

bool Tokenizer::isOneNumber ( const std::string &  s)
static

Helper function to check whether number is one (1 or 0.1E+1 or 1E+0) or not?

Parameters
sthe string to check
Returns
true in case is is one and false otherwise.

Definition at line 8128 of file tokenize.cpp.

References isNumberOneOf(), and MathLib::isPositive().

Referenced by CheckFunctions::checkMathFunctions().

◆ isPacked()

bool Tokenizer::isPacked ( const Token bodyStart) const

◆ isScopeNoReturn()

bool Tokenizer::isScopeNoReturn ( const Token endScopeToken,
bool *  unknown = nullptr 
) const

Check if inner scope ends with a call to a noreturn function.

Parameters
endScopeTokenThe '}' token
unknownset to true if it's unknown if the scope is noreturn
Returns
true if scope ends with a function call that might be 'noreturn'

Definition at line 8008 of file tokenize.cpp.

References Settings::checkLibrary, Token::function(), information, Library::isScopeNoReturn(), Settings::library, Token::linkAt(), mSettings, Token::previous(), reportError(), Token::simpleMatch(), Settings::summaryReturn, Token::tokAt(), Token::type(), and Token::variable().

Referenced by CheckMemoryLeakInFunction::checkReallocUsage(), CheckLeakAutoVar::checkScope(), and CheckUninitVar::checkScopeForVariable().

◆ macroWithSemicolonError()

void Tokenizer::macroWithSemicolonError ( const Token tok,
const std::string &  macroName 
) const
private

Definition at line 8075 of file tokenize.cpp.

References information, and reportError().

Referenced by checkConfiguration().

◆ markCppCasts()

void Tokenizer::markCppCasts ( )
private

Set isCast() for C++ casts.

Definition at line 5419 of file tokenize.cpp.

References TokenList::front(), isC(), Token::isCast(), Token::linkAt(), list, Token::Match(), Token::next(), Token::simpleMatch(), and syntaxError().

Referenced by simplifyTokenList1().

◆ newVarId()

nonneg int Tokenizer::newVarId ( )
inlineprivate

Get new variable id.

Returns
new variable id

Definition at line 637 of file tokenize.h.

Referenced by SymbolDatabase::fixVarId().

◆ operator=()

Tokenizer& Tokenizer::operator= ( const Tokenizer )
delete

Disable assignment operator.

◆ operatorEnd()

static bool Tokenizer::operatorEnd ( const Token tok)
staticprivate

◆ prepareTernaryOpForAST()

void Tokenizer::prepareTernaryOpForAST ( )
private

Prepare ternary operators with parentheses so that the AST can be created.

Referenced by simplifyTokenList1().

◆ printDebugOutput()

void Tokenizer::printDebugOutput ( int  simplification) const

◆ printUnknownTypes()

void Tokenizer::printUnknownTypes ( ) const
private

Output list of unknown types.

Referenced by printDebugOutput().

◆ processFunc() [1/2]

const Token * Tokenizer::processFunc ( const Token tok2,
bool  inOperator 
) const
private

◆ processFunc() [2/2]

Token * Tokenizer::processFunc ( Token tok2,
bool  inOperator 
)
private

Definition at line 535 of file tokenize.cpp.

References processFunc().

◆ removeExtraTemplateKeywords()

void Tokenizer::removeExtraTemplateKeywords ( )
private

Remove extra "template" keywords that are not used by Cppcheck.

Definition at line 6293 of file tokenize.cpp.

References Token::deleteNext(), TokenList::front(), isCPP(), Token::isTemplate(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), Token::str(), syntaxError(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ removeMacroInClassDef()

void Tokenizer::removeMacroInClassDef ( )
private

Remove undefined macro in class definition: class DLLEXPORT Fred { }; class Fred FINAL : Base { };.

Definition at line 6474 of file tokenize.cpp.

References Token::deleteNext(), TokenList::front(), Token::isUpperCaseName(), list, Token::Match(), Token::next(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ removeMacrosInGlobalScope()

void Tokenizer::removeMacrosInGlobalScope ( )
private

◆ removePragma()

void Tokenizer::removePragma ( )
private

◆ removeRedundantSemicolons()

void Tokenizer::removeRedundantSemicolons ( )
private

Reduces "; ;" to ";", except in "( ; ; )".

Definition at line 6548 of file tokenize.cpp.

References Token::deleteNext(), TokenList::front(), Token::link(), list, Token::next(), Token::simpleMatch(), and Token::str().

Referenced by simplifyTokenList1().

◆ removeUnnecessaryQualification()

void Tokenizer::removeUnnecessaryQualification ( )
private

Remove unnecessary member qualification.

Referenced by simplifyTokenList1().

◆ reportError() [1/2]

void Tokenizer::reportError ( const std::list< const Token * > &  callstack,
Severity  severity,
const std::string &  id,
const std::string &  msg,
bool  inconclusive = false 
) const
private

◆ reportError() [2/2]

void Tokenizer::reportError ( const Token tok,
const Severity  severity,
const std::string &  id,
const std::string &  msg,
bool  inconclusive = false 
) const
private

◆ reportUnknownMacros()

void Tokenizer::reportUnknownMacros ( ) const
private

◆ setDirectives()

void Tokenizer::setDirectives ( std::list< Directive directives)

Referenced by CppCheck::checkFile().

◆ setPodTypes()

void Tokenizer::setPodTypes ( )
private

Set pod types.

Referenced by setVarId().

◆ setTimerResults()

void Tokenizer::setTimerResults ( TimerResults tr)
inline

Definition at line 59 of file tokenize.h.

Referenced by CppCheck::checkFile().

◆ setVarId()

void Tokenizer::setVarId ( )
private

◆ setVarIdClassFunction()

void Tokenizer::setVarIdClassFunction ( const std::string &  classname,
Token *const  startToken,
const Token *const  endToken,
const std::map< std::string, nonneg int > &  varlist,
std::map< nonneg int, std::map< std::string, nonneg int >> &  structMembers,
nonneg int &  varId_ 
)
staticprivate

◆ setVarIdPass1()

void Tokenizer::setVarIdPass1 ( )
private

◆ setVarIdPass2()

void Tokenizer::setVarIdPass2 ( )
private

◆ simplifyAddBraces()

bool Tokenizer::simplifyAddBraces ( )
private

Add braces to an if-block, for-block, etc.

Returns
true if no syntax errors

Definition at line 6568 of file tokenize.cpp.

References TokenList::front(), list, Token::next(), and simplifyAddBracesToCommand().

Referenced by simplifyTokenList1().

◆ simplifyAddBracesPair()

Token * Tokenizer::simplifyAddBracesPair ( Token tok,
bool  commandWithCondition 
)
private

Add pair of braces to an single if-block, else-block, for-block, etc.

for command starting at token

Returns
last token of command or input token in case of an error where no braces are added or NULL when syntaxError is called

Definition at line 6622 of file tokenize.cpp.

References Token::createMutualLinks(), Token::eBracket, Token::insertToken(), Token::isUpperCaseName(), Token::link(), Token::linkAt(), Token::Match(), Token::move(), Token::next(), Token::previous(), Token::simpleMatch(), simplifyAddBracesToCommand(), skipCaseLabel(), Token::str(), Token::strAt(), syntaxError(), Token::tokAt(), Token::tokType(), and unknownMacroError().

Referenced by simplifyAddBracesToCommand().

◆ simplifyAddBracesToCommand()

Token * Tokenizer::simplifyAddBracesToCommand ( Token tok)
private

Add braces to an if-block, for-block, etc.

for command starting at token including else-block

Returns
last token of command or input token in case of an error where no braces are added or NULL when syntaxError is called

Definition at line 6578 of file tokenize.cpp.

References Token::link(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), simplifyAddBracesPair(), Token::str(), Token::strAt(), syntaxError(), and Token::tokAt().

Referenced by simplifyAddBraces(), and simplifyAddBracesPair().

◆ simplifyArrayAccessSyntax()

void Tokenizer::simplifyArrayAccessSyntax ( )
private

◆ simplifyAsm()

void Tokenizer::simplifyAsm ( )
private

Remove __asm.

Referenced by simplifyTokenList1().

◆ simplifyAsm2()

void Tokenizer::simplifyAsm2 ( )
private

asm heuristics, Put ^{} statements in asm()

Referenced by simplifyTokenList1().

◆ simplifyAssignmentBlock()

void Tokenizer::simplifyAssignmentBlock ( )
private

Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}".

Referenced by simplifyTokenList1().

◆ simplifyAt()

void Tokenizer::simplifyAt ( )
private

Simplify @… (compiler extension)

Referenced by simplifyTokenList1().

◆ simplifyAttribute()

void Tokenizer::simplifyAttribute ( )
private

Remove __attribute__ ((?))

Referenced by simplifyTokenList1().

◆ simplifyBitfields()

void Tokenizer::simplifyBitfields ( )
private

Simplify bitfields - the field width is removed as we don't use it.

Referenced by simplifyTokenList1().

◆ simplifyBorland()

void Tokenizer::simplifyBorland ( )
private

Remove Borland code.

Referenced by simplifyTokenList1().

◆ simplifyCallingConvention()

void Tokenizer::simplifyCallingConvention ( )
private

Remove calling convention.

Referenced by simplifyTokenList1().

◆ simplifyCAlternativeTokens()

bool Tokenizer::simplifyCAlternativeTokens ( )
private

Simplify the 'C Alternative Tokens' Examples: "if(s and t)" => "if(s && t)" "while((r bitand s) and not t)" => while((r & s) && !t)" "a and_eq b;" => "a &= b;".

Definition at line 7524 of file tokenize.cpp.

References cAlternativeTokens, TokenList::front(), isC(), isFunctionHead(), Token::isName(), list, Token::Match(), Token::next(), Token::previous(), Token::str(), and Token::strAt().

Referenced by simplifyTokenList1().

◆ simplifyCaseRange()

void Tokenizer::simplifyCaseRange ( )
private

simplify case ranges (gcc extension)

Definition at line 3987 of file tokenize.cpp.

References TokenList::front(), Token::insertToken(), list, Token::Match(), Token::next(), Token::str(), Token::strAt(), MathLib::toBigNumber(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ simplifyCoroutines()

void Tokenizer::simplifyCoroutines ( )
private

Simplify coroutines - just put parentheses around arguments for co_* keywords so they can be handled like function calls in data flow.

Referenced by simplifyTokenList1().

◆ simplifyCPPAttribute()

void Tokenizer::simplifyCPPAttribute ( )
private

Remove [[attribute]] (C++11 and later) from TokenList.

Referenced by simplifyTokenList1().

◆ simplifyCppcheckAttribute()

void Tokenizer::simplifyCppcheckAttribute ( )
private

Remove __cppcheck__ ((?))

Referenced by simplifyTokenList1().

◆ simplifyDebug()

void Tokenizer::simplifyDebug ( )
private

Referenced by simplifyTokenList1().

◆ simplifyDeclspec()

void Tokenizer::simplifyDeclspec ( )
private

Remove __declspec()

Referenced by simplifyTokenList1().

◆ simplifyDoublePlusAndDoubleMinus()

void Tokenizer::simplifyDoublePlusAndDoubleMinus ( )
private

◆ simplifyEmptyNamespaces()

void Tokenizer::simplifyEmptyNamespaces ( )
private

Simplify useless C++ empty namespaces, like: 'namespace name% { }'.

Definition at line 6509 of file tokenize.cpp.

References Token::deleteNext(), Token::deleteThis(), TokenList::front(), isC(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), Token::str(), Token::strAt(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ simplifyExternC()

void Tokenizer::simplifyExternC ( )
private

◆ simplifyFunctionParameters()

void Tokenizer::simplifyFunctionParameters ( )
private

◆ simplifyFunctionPointers()

void Tokenizer::simplifyFunctionPointers ( )
private

◆ simplifyFunctionTryCatch()

void Tokenizer::simplifyFunctionTryCatch ( )
private

Simplify function level try blocks: Convert "void f() try {} catch (int) {}" to "void f() { try {} catch (int) {} }".

Referenced by simplifyTokenList1().

◆ simplifyHeadersAndUnusedTemplates()

void Tokenizer::simplifyHeadersAndUnusedTemplates ( )
private

◆ simplifyIfSwitchForInit()

void Tokenizer::simplifyIfSwitchForInit ( )
private

◆ simplifyInitVar()

void Tokenizer::simplifyInitVar ( )
private

Simplify variable initialization '; int *p(0);' => '; int *p = 0;'.

Definition at line 7612 of file tokenize.cpp.

References TokenList::front(), initVar(), TokenList::insertTokens(), isC(), Token::isName(), Token::link(), Token::linkAt(), list, Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ simplifyKeyword()

void Tokenizer::simplifyKeyword ( )
private

Remove keywords "volatile", "inline", "register", and "restrict".

Referenced by simplifyTokenList1().

◆ simplifyLabelsCaseDefault()

void Tokenizer::simplifyLabelsCaseDefault ( )
private

Simplify labels and 'case|default' syntaxes.

simplify labels and case|default in the code: add a ";" if not already in.

Definition at line 3937 of file tokenize.cpp.

References TokenList::front(), Token::insertToken(), isCPP(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), skipCaseLabel(), startOfExecutableScope(), Token::str(), Token::strAt(), syntaxError(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ simplifyMicrosoftMemoryFunctions()

void Tokenizer::simplifyMicrosoftMemoryFunctions ( )
private

Convert Microsoft memory functions CopyMemory(dst, src, len) -> memcpy(dst, src, len) FillMemory(dst, len, val) -> memset(dst, val, len) MoveMemory(dst, src, len) -> memmove(dst, src, len) ZeroMemory(dst, len) -> memset(dst, 0, len)

Referenced by simplifyTokenList1().

◆ simplifyMicrosoftStringFunctions()

void Tokenizer::simplifyMicrosoftStringFunctions ( )
private

Convert Microsoft string functions _tcscpy -> strcpy.

Referenced by simplifyTokenList1().

◆ simplifyNamespaceAliases()

void Tokenizer::simplifyNamespaceAliases ( )
private

Convert namespace aliases.

Referenced by simplifyTokenList1().

◆ simplifyNamespaceStd()

void Tokenizer::simplifyNamespaceStd ( )
private

Add std:: in front of std classes, when using namespace std; was given.

Referenced by simplifyTokenList1().

◆ simplifyNestedNamespace()

void Tokenizer::simplifyNestedNamespace ( )
private

Convert C++17 style nested namespace to older style.

Referenced by simplifyTokenList1().

◆ simplifyOperatorName()

void Tokenizer::simplifyOperatorName ( )
private

Collapse operator name tokens into single token operator = => operator=.

Referenced by simplifyTokenList1().

◆ simplifyOverloadedOperators()

void Tokenizer::simplifyOverloadedOperators ( )
private

simplify overloaded operators: 'obj(123)' => 'obj .

operator() ( 123 )'

Referenced by simplifyTokenList1().

◆ simplifyParameterVoid()

void Tokenizer::simplifyParameterVoid ( )
private

◆ simplifyPointerToStandardType()

void Tokenizer::simplifyPointerToStandardType ( )
private

Simplify pointer to standard type (C only)

Definition at line 6893 of file tokenize.cpp.

References Token::deleteNext(), Token::eraseTokens(), TokenList::front(), isC(), list, Token::Match(), Token::next(), Token::previous(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ simplifyRedundantConsecutiveBraces()

void Tokenizer::simplifyRedundantConsecutiveBraces ( )
private

◆ simplifyRedundantParentheses()

bool Tokenizer::simplifyRedundantParentheses ( )
private

Remove redundant parentheses:

  • "((x))" => "(x)"
  • "(function())" => "function()"
  • "(delete x)" => "delete x"
  • "(delete [] x)" => "delete [] x"
    Returns
    true if modifications to token-list are done. false if no modifications are done.

Definition at line 7783 of file tokenize.cpp.

References Token::deleteNext(), Token::deleteThis(), Token::findsimplematch(), TokenList::front(), Token::isCpp(), isCPP(), Token::isKeyword(), Token::isStandardType(), Token::link(), Token::linkAt(), list, Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), and Token::varId().

Referenced by simplifyTokenList1().

◆ simplifyRoundCurlyParentheses()

void Tokenizer::simplifyRoundCurlyParentheses ( )
private

◆ simplifySpaceshipOperator()

void Tokenizer::simplifySpaceshipOperator ( )
private

Simplify c++20 spaceship operator.

Referenced by simplifyTokenList1().

◆ simplifySQL()

void Tokenizer::simplifySQL ( )
private

◆ simplifyStaticConst()

void Tokenizer::simplifyStaticConst ( )
private

Simplify the location of "static" and "const" qualifiers in a variable declaration or definition.

Example: "int static const a;" => "static const a;" Example: "long long const static b;" => "static const long long b;"

Definition at line 7400 of file tokenize.cpp.

References Token::deleteNext(), Token::findOpeningBracket(), TokenList::front(), Token::insertToken(), Token::insertTokenBefore(), isCPP(), list, Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::swapWithNext().

Referenced by simplifyTokenList1().

◆ simplifyString()

static std::string Tokenizer::simplifyString ( const std::string &  source)
staticprivate

Modify strings in the token list by replacing hex and oct values.

E.g. "\x61" -> "a" and "\000" -> "\0"

Parameters
sourceThe string to be modified, e.g. "\x61"
Returns
Modified string, e.g. "a"

Referenced by combineStringAndCharLiterals().

◆ simplifyStructDecl()

void Tokenizer::simplifyStructDecl ( )
private

Struct simplification "struct S { } s;" => "struct S { }; S s;".

Referenced by simplifyTokenList1().

◆ simplifyTemplates()

void Tokenizer::simplifyTemplates ( )
private

Simplify templates.

Definition at line 4099 of file tokenize.cpp.

References isC(), mSettings, mTemplateSimplifier, TemplateSimplifier::simplifyTemplates(), and Settings::templateMaxTime.

Referenced by simplifyTokenList1().

◆ simplifyTokenList1()

bool Tokenizer::simplifyTokenList1 ( const char  FileName[])
private

Basic simplification of tokenlist.

Parameters
FileNameThe filename to run; used to do markup checks.
Returns
false if there is an error that requires aborting the checking of this file.

Definition at line 5458 of file tokenize.cpp.

References addSemicolonAfterUnknownMacro(), arraySize(), Token::assignIndexes(), Token::assignProgressValues(), checkConfiguration(), checkForEnumsWithTypedef(), combineOperators(), combineStringAndCharLiterals(), concatenateNegativeNumberAndAnyPositive(), createLinks(), createLinks2(), Settings::daca, Token::deleteNext(), elseif(), findComplicatedSyntaxErrorsInTemplates(), findGarbageCode(), TokenList::front(), information, isC(), Token::isConstexpr(), isCPP(), SimpleEnableGroup< T >::isEnabled(), Token::isNumber(), Token::isUpperCaseName(), Settings::library, Token::link(), Token::linkAt(), list, markCppCasts(), Library::markupFile(), Token::Match(), mSettings, mTimerResults, Token::next(), prepareTernaryOpForAST(), removeExtraTemplateKeywords(), removeMacroInClassDef(), removeMacrosInGlobalScope(), removePragma(), removeRedundantSemicolons(), removeUnnecessaryQualification(), reportUnknownMacros(), setVarId(), Settings::severity, Settings::showtime, Token::simpleMatch(), simplifyAddBraces(), simplifyArrayAccessSyntax(), simplifyAsm(), simplifyAsm2(), simplifyAssignmentBlock(), simplifyAt(), simplifyAttribute(), simplifyBitfields(), simplifyBorland(), simplifyCallingConvention(), simplifyCAlternativeTokens(), simplifyCaseRange(), simplifyCoroutines(), simplifyCPPAttribute(), simplifyCppcheckAttribute(), simplifyDebug(), simplifyDeclspec(), simplifyDoublePlusAndDoubleMinus(), simplifyEmptyNamespaces(), simplifyExternC(), simplifyFunctionParameters(), simplifyFunctionPointers(), simplifyFunctionTryCatch(), simplifyHeadersAndUnusedTemplates(), simplifyIfSwitchForInit(), simplifyInitVar(), simplifyKeyword(), simplifyLabelsCaseDefault(), simplifyMicrosoftMemoryFunctions(), simplifyMicrosoftStringFunctions(), simplifyNamespaceAliases(), simplifyNamespaceStd(), simplifyNestedNamespace(), TemplateSimplifier::simplifyNumericCalculations(), simplifyOperatorName(), simplifyOverloadedOperators(), simplifyParameterVoid(), TokenList::simplifyPlatformTypes(), simplifyPointerToStandardType(), simplifyRedundantConsecutiveBraces(), simplifyRedundantParentheses(), simplifyRoundCurlyParentheses(), simplifySpaceshipOperator(), simplifySQL(), simplifyStaticConst(), TokenList::simplifyStdType(), simplifyStructDecl(), simplifyTemplates(), simplifyTypedef(), simplifyTypedefLHS(), simplifyTypeIntrinsics(), simplifyUsing(), simplifyVarDecl(), simplifyVariableMultipleAssign(), sizeofAddParentheses(), splitTemplateRightAngleBrackets(), Token::str(), Token::strAt(), syntaxError(), Settings::terminated(), unhandled_macro_class_x_y(), validate(), and validateC().

Referenced by simplifyTokens1().

◆ simplifyTokens1()

bool Tokenizer::simplifyTokens1 ( const std::string &  configuration)

◆ simplifyTypedef()

void Tokenizer::simplifyTypedef ( )
private

◆ simplifyTypedefCpp()

void Tokenizer::simplifyTypedefCpp ( )
private

◆ simplifyTypedefLHS()

void Tokenizer::simplifyTypedefLHS ( )
private

Move typedef token to the left og the expression.

Definition at line 563 of file tokenize.cpp.

References Token::deleteThis(), TokenList::front(), Token::insertTokenBefore(), Token::linkAt(), list, Token::Match(), Token::next(), Token::previous(), and Token::simpleMatch().

Referenced by simplifyTokenList1().

◆ simplifyTypeIntrinsics()

void Tokenizer::simplifyTypeIntrinsics ( )
private

◆ simplifyUsing()

bool Tokenizer::simplifyUsing ( )
private

◆ simplifyUsingError()

void Tokenizer::simplifyUsingError ( const Token usingStart,
const Token usingEnd 
)
private

◆ simplifyUsingToTypedef()

void Tokenizer::simplifyUsingToTypedef ( )
private

◆ simplifyVarDecl() [1/2]

void Tokenizer::simplifyVarDecl ( const bool  only_k_r_fpar)
private

Simplify variable declarations (split up)

Parameters
only_k_r_fparOnly simplify K&R function parameters

Definition at line 7036 of file tokenize.cpp.

References TokenList::front(), and list.

Referenced by simplifyTokenList1(), and simplifyVarDecl().

◆ simplifyVarDecl() [2/2]

void Tokenizer::simplifyVarDecl ( Token tokBegin,
const Token *const  tokEnd,
const bool  only_k_r_fpar 
)
private

◆ simplifyVariableMultipleAssign()

void Tokenizer::simplifyVariableMultipleAssign ( )
private

Simplify multiple assignments.

Example: "a = b = c = 0;" => "a = 0; b = 0; c = 0;"

Definition at line 7469 of file tokenize.cpp.

References TokenList::front(), Token::insertToken(), list, Token::Match(), Token::next(), Token::previous(), Token::str(), and Token::tokAt().

Referenced by simplifyTokenList1().

◆ sizeofAddParentheses()

void Tokenizer::sizeofAddParentheses ( )
private

Add parentheses for sizeof: sizeof x => sizeof(x)

Definition at line 5434 of file tokenize.cpp.

References Token::createMutualLinks(), TokenList::front(), Token::insertToken(), Token::isLiteral(), Token::linkAt(), list, Token::Match(), Token::next(), and Token::simpleMatch().

Referenced by simplifyTokenList1().

◆ sizeOfType() [1/2]

nonneg int Tokenizer::sizeOfType ( const std::string &  type) const

◆ sizeOfType() [2/2]

nonneg int Tokenizer::sizeOfType ( const Token type) const

Calculates sizeof value for given type.

Parameters
typeToken which will contain e.g. "int", "*", or string.
Returns
sizeof for given type, or 0 if it can't be calculated.

Definition at line 186 of file tokenize.cpp.

References Token::eString, Token::getStrLength(), Token::isLong(), Settings::library, mSettings, mTypeSize, Settings::platform, Library::podtype(), Library::PodType::size, Platform::sizeof_long_double, Platform::sizeof_long_long, Token::str(), and Token::tokType().

Referenced by checkBufferSize(), CheckOther::checkIncompleteArrayFill(), TemplateSimplifier::simplifyTemplateArgs(), and SymbolDatabase::sizeOfType().

◆ splitTemplateRightAngleBrackets()

void Tokenizer::splitTemplateRightAngleBrackets ( bool  check)
private

◆ startOfExecutableScope()

const Token * Tokenizer::startOfExecutableScope ( const Token tok)
static

Helper function to check for start of function execution scope.

Do not use this in checks. Use the symbol database.

Parameters
tokpointer to end parentheses of parameter list
Returns
pointer to start brace of function scope or nullptr if not start.

Definition at line 3919 of file tokenize.cpp.

References isFunctionHead(), Token::linkAt(), Token::Match(), Token::next(), and Token::str().

Referenced by TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates(), and simplifyLabelsCaseDefault().

◆ syntaxError()

void Tokenizer::syntaxError ( const Token tok,
const std::string &  code = emptyString 
) const

◆ syntaxErrorC()

void Tokenizer::syntaxErrorC ( const Token tok,
const std::string &  what 
) const

Syntax error.

C++ code in C file.

Definition at line 8051 of file tokenize.cpp.

References printDebugOutput(), and InternalError::SYNTAX.

Referenced by setVarIdPass1(), and validateC().

◆ tokens() [1/2]

Token* Tokenizer::tokens ( )
inline

Definition at line 596 of file tokenize.h.

References TokenList::front().

◆ tokens() [2/2]

const Token* Tokenizer::tokens ( ) const
inline

Definition at line 592 of file tokenize.h.

References TokenList::front().

Referenced by CheckBufferOverrun::arrayIndex(), CheckCondition::assignIf(), CheckUninitVar::check(), CheckString::checkAlwaysTrueOrFalseStringCompare(), CheckCondition::checkBadBitmaskCheck(), CheckOther::checkCommaSeparatedReturn(), checkConfiguration(), CheckOther::checkConstPointer(), CheckStl::checkDereferenceInvalidIterator2(), CppCheck::checkFile(), CheckType::checkFloatToIntegerOverflow(), CheckOther::checkIncompleteStatement(), CheckType::checkIntegerOverflow(), CheckOther::checkInterlockedDecrement(), CheckCondition::checkInvalidTestForOverflow(), CheckFunctions::checkLibraryMatchFunctions(), CheckType::checkLongCast(), CheckOther::checkModuloOfOne(), CheckOther::checkNanInArithmeticExpression(), CheckOther::checkNegativeBitwiseShift(), CheckOther::checkRedundantPointerOp(), CheckType::checkSignConversion(), CheckUnusedVar::checkStructMemberUsage(), CheckType::checkTooBigBitwiseShift(), CheckOther::checkZeroDivision(), CheckCondition::comparison(), SymbolDatabase::createSymbolDatabaseFindAllScopes(), Scope::getVariableList(), CheckCondition::isAliased(), SuppressionList::markUnmatchedInlineSuppressionsAsChecked(), CheckNullPointer::nullPointerByDeRefAndChec(), CheckUnusedFunctions::parseTokens(), CheckBufferOverrun::pointerArithmetic(), reportUnknownMacros(), setValues(), simplifyTokens1(), CheckSizeof::sizeofCalculation(), CheckSizeof::sizeofFunction(), CheckSizeof::sizeofsizeof(), CheckSizeof::sizeofVoid(), CheckSizeof::suspiciousSizeofCalculation(), SymbolDatabase::SymbolDatabase(), CheckClass::thisSubtraction(), validate(), validateC(), and CheckClass::virtualDestructor().

◆ unhandled_macro_class_x_y()

void Tokenizer::unhandled_macro_class_x_y ( const Token tok) const
private

Report that there is an unhandled "class x y {" code.

Definition at line 8063 of file tokenize.cpp.

References information, reportError(), Token::str(), and Token::strAt().

Referenced by simplifyTokenList1().

◆ unhandledCharLiteral()

void Tokenizer::unhandledCharLiteral ( const Token tok,
const std::string &  msg 
) const

Definition at line 8089 of file tokenize.cpp.

References portability, reportError(), and Token::str().

Referenced by simplifyTokens1().

◆ unknownMacroError()

void Tokenizer::unknownMacroError ( const Token tok1) const

Warn about unknown macro(s), configuration is recommended.

Definition at line 8057 of file tokenize.cpp.

References printDebugOutput(), Token::str(), and InternalError::UNKNOWN_MACRO.

Referenced by elseif(), removeMacrosInGlobalScope(), reportUnknownMacros(), and simplifyAddBracesPair().

◆ unmatchedToken()

void Tokenizer::unmatchedToken ( const Token tok) const

Syntax error.

Unmatched character.

Definition at line 8043 of file tokenize.cpp.

References mConfiguration, printDebugOutput(), Token::str(), and InternalError::SYNTAX.

Referenced by SymbolDatabase::addNewFunction(), createLinks(), and linkBrackets().

◆ unsupportedTypedef()

void Tokenizer::unsupportedTypedef ( const Token tok) const
private

Definition at line 332 of file tokenize.cpp.

References debug, Settings::debugwarnings, mSettings, Token::next(), reportError(), and Token::str().

Referenced by simplifyTypedefCpp().

◆ validate()

void Tokenizer::validate ( ) const
private

assert that tokens are ok - used during debugging for example to catch problems in simplifyTokenList1/2.

Definition at line 8184 of file tokenize.cpp.

References TokenList::back(), cppcheckError(), Token::link(), list, Token::Match(), Token::next(), Token::str(), and tokens().

Referenced by findComplicatedSyntaxErrorsInTemplates(), and simplifyTokenList1().

◆ validateC()

void Tokenizer::validateC ( ) const
private

◆ varIdCount()

nonneg int Tokenizer::varIdCount ( ) const
inline

Get variable count.

Returns
number of variables

Definition at line 583 of file tokenize.h.

Referenced by SymbolDatabase::createSymbolDatabaseVariableSymbolTable().

Friends And Related Function Documentation

◆ SymbolDatabase

friend class SymbolDatabase
friend

Definition at line 48 of file tokenize.h.

◆ TemplateSimplifier

friend class TemplateSimplifier
friend

Definition at line 49 of file tokenize.h.

◆ TestSimplifyTemplate

friend class TestSimplifyTemplate
friend

Definition at line 51 of file tokenize.h.

◆ TestSimplifyTypedef

friend class TestSimplifyTypedef
friend

Definition at line 52 of file tokenize.h.

◆ TestTokenizer

friend class TestTokenizer
friend

Definition at line 53 of file tokenize.h.

Member Data Documentation

◆ list

TokenList Tokenizer::list

Token list: stores all tokens.

Definition at line 590 of file tokenize.h.

Referenced by addSemicolonAfterUnknownMacro(), arraySize(), CheckAssert::assertWithSideEffects(), calculateScopes(), CppCheck::checkClang(), CppCheck::checkFile(), checkForEnumsWithTypedef(), CppCheck::checkNormalTokens(), combineOperators(), combineStringAndCharLiterals(), concatenateNegativeNumberAndAnyPositive(), Summaries::create(), createLinks(), createLinks2(), SymbolDatabase::createSymbolDatabaseEnums(), SymbolDatabase::createSymbolDatabaseExprIds(), SymbolDatabase::createSymbolDatabaseFindAllScopes(), SymbolDatabase::createSymbolDatabaseIncompleteVars(), SymbolDatabase::createSymbolDatabaseSetFunctionPointers(), SymbolDatabase::createSymbolDatabaseSetScopePointers(), SymbolDatabase::createSymbolDatabaseSetTypePointers(), SymbolDatabase::createSymbolDatabaseSetVariablePointers(), SymbolDatabase::debugMessage(), SymbolDatabase::debugSymbolDatabase(), deleteInvalidTypedef(), dump(), elseif(), CTU::getFileInfo(), CheckClass::getFileInfo(), CTU::getFunctionId(), markCppCasts(), SuppressionList::markUnmatchedInlineSuppressionsAsChecked(), clangimport::parseClangAstDump(), CheckUnusedFunctions::parseTokens(), printDebugOutput(), SymbolDatabase::printOut(), SymbolDatabase::printVariable(), removeExtraTemplateKeywords(), removeMacroInClassDef(), removeMacrosInGlobalScope(), removePragma(), removeRedundantSemicolons(), CheckMemoryLeak::reportErr(), Check::reportError(), SymbolDatabase::returnImplicitIntError(), scopeToString(), SymbolDatabase::setValueTypeInTokenList(), setVarId(), setVarIdPass1(), setVarIdPass2(), simplifyAddBraces(), simplifyArrayAccessSyntax(), simplifyCAlternativeTokens(), simplifyCaseRange(), simplifyDoublePlusAndDoubleMinus(), simplifyEmptyNamespaces(), simplifyExternC(), simplifyFunctionParameters(), simplifyFunctionPointers(), simplifyHeadersAndUnusedTemplates(), simplifyIfSwitchForInit(), simplifyInitVar(), simplifyLabelsCaseDefault(), simplifyParameterVoid(), simplifyPointerToStandardType(), simplifyRedundantConsecutiveBraces(), simplifyRedundantParentheses(), simplifyRoundCurlyParentheses(), simplifySQL(), simplifyStaticConst(), TemplateSimplifier::simplifyTemplateInstantiations(), TemplateSimplifier::simplifyTemplates(), simplifyTokenList1(), simplifyTokens1(), simplifyTypedef(), simplifyTypedefCpp(), simplifyTypedefLHS(), simplifyTypeIntrinsics(), simplifyUsing(), simplifyUsingError(), simplifyUsingToTypedef(), simplifyVarDecl(), simplifyVariableMultipleAssign(), sizeofAddParentheses(), splitTemplateRightAngleBrackets(), tokenToString(), TemplateSimplifier::useDefaultArgumentValues(), validate(), SymbolDatabase::validateExecutableScopes(), and SymbolDatabase::~SymbolDatabase().

◆ mConfiguration

std::string Tokenizer::mConfiguration
private

E.g.

"A" for code where "#ifdef A" is true. This is used to print additional information in error situations.

Definition at line 657 of file tokenize.h.

Referenced by simplifyTokens1(), and unmatchedToken().

◆ mDirectives

std::list<Directive> Tokenizer::mDirectives
private

Definition at line 671 of file tokenize.h.

Referenced by dump().

◆ mErrorLogger

ErrorLogger& Tokenizer::mErrorLogger
private

errorlogger

Definition at line 648 of file tokenize.h.

Referenced by simplifyTokens1(), simplifyTypedefCpp(), simplifyUsing(), and simplifyUsingError().

◆ mSettings

const Settings& Tokenizer::mSettings
private

◆ mSymbolDatabase

SymbolDatabase* Tokenizer::mSymbolDatabase {}
private

Symbol database that all checks etc can use.

Definition at line 651 of file tokenize.h.

Referenced by arraySizeAfterValueFlow(), dump(), printDebugOutput(), simplifyTokens1(), and ~Tokenizer().

◆ mTemplateSimplifier

TemplateSimplifier* const Tokenizer::mTemplateSimplifier
private

◆ mTimerResults

TimerResults* Tokenizer::mTimerResults {}
private

TimerResults.

Definition at line 682 of file tokenize.h.

Referenced by simplifyTokenList1(), and simplifyTokens1().

◆ mTypedefInfo

std::vector<TypedefInfo> Tokenizer::mTypedefInfo
private

Definition at line 669 of file tokenize.h.

Referenced by dump(), simplifyTypedef(), and simplifyTypedefCpp().

◆ mTypeSize

std::map<std::string, int> Tokenizer::mTypeSize
private

sizeof information for known types

Definition at line 660 of file tokenize.h.

Referenced by fillTypeSizes(), and sizeOfType().

◆ mUnnamedCount

nonneg int Tokenizer::mUnnamedCount {}
private

unnamed count "Unnamed0", "Unnamed1", "Unnamed2", ...

Definition at line 677 of file tokenize.h.

Referenced by simplifyTypedefCpp(), and simplifyUsing().

◆ mVarId

nonneg int Tokenizer::mVarId {}
private

variable count

Definition at line 674 of file tokenize.h.

Referenced by setVarIdPass1(), and setVarIdPass2().


The documentation for this class was generated from the following files: