Cppcheck
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Tokenizer Class Reference

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

#include <tokenize.h>

List of all members.

Public Member Functions

 Tokenizer ()
 Tokenizer (const Settings *settings, ErrorLogger *errorLogger)
 ~Tokenizer ()
void setTimerResults (TimerResults *tr)
const std::string & getSourceFilePath () const
 Returns the source file path.
bool isC () const
 Is the code C.
bool isCPP () const
 Is the code CPP.
bool tokenize (std::istream &code, const char FileName[], const std::string &configuration="")
 Tokenize code.
bool tokenizeCondition (const std::string &code)
 tokenize condition and run simple simplifications on it
void setVarId ()
 Set variable id.
bool simplifyTokenList ()
 Simplify tokenlist.
void simplifyMulAndParens ()
 Simplify '* & ( var% ) =' or any combination of '* &' and '()' parentheses around 'var' to 'var% ='.
unsigned int sizeOfType (const Token *type) const
 Calculates sizeof value for given type.
bool isFunctionParameterPassedByValue (const Token *fpar) const
 Try to determine if function parameter is passed by value by looking at the function declaration.
void simplifyAssignmentInFunctionCall ()
 Simplify assignment in function call "f(x=g());" => "x=g();f(x);".
void simplifyAssignmentBlock ()
 Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}".
bool simplifyCalculations ()
 Simplify constant calculations such as "1+2" => "3".
void arraySize ()
 Insert array size where it isn't given.
bool simplifyLabelsCaseDefault ()
 Simplify labels and 'case|default' syntaxes.
void removeMacrosInGlobalScope ()
 Remove macros in global scope.
void removeMacroInVarDecl ()
 Remove unknown macro in variable declarations: PROGMEM char x;.
void removeRedundantAssignment ()
 Remove redundant assignment.
void simplifyRealloc ()
 Simplifies some realloc usage like 'x = realloc (0, n);' => 'x = malloc(n);' 'x = realloc (y, 0);' => 'x = 0; free(y);'.
bool simplifySizeof ()
 Replace sizeof() to appropriate size.
void simplifyVarDecl (bool only_k_r_fpar)
 Simplify variable declarations (split up)
void simplifyInitVar ()
 Simplify variable initialization '; int *p(0);' => '; int *p = 0;'.
TokeninitVar (Token *tok)
void simplifyPlatformTypes ()
 Convert platform dependent types to standard types.
void simplifyStdType ()
 Collapse compound standard types into a single token.
bool simplifyConstTernaryOp ()
 Simplify easy constant '?:' operation Example: 0 ? (2/0) : 0 => 0.
void simplifyCompoundAssignment ()
 Simplify compound assignments Example: ";a+=b;" => ";a=a+b;".
void simplifyIfAssign ()
 simplify if-assignments Example: "if(a=b);" => "a=b;if(a);"
void simplifyVariableMultipleAssign ()
 Simplify multiple assignments.
void simplifyIfNot ()
 simplify if-not Example: "if(0==x);" => "if(!x);"
void simplifyIfNotNull ()
 simplify if-not NULL Example: "if(0!=x);" => "if(x);" Special case: 'x = (0 != x);' is removed.
void simplifyIfSameInnerCondition ()
 simplify if (a) { if (a)
bool simplifyLogicalOperators ()
 Simplify the "not" and "and" keywords to "!" and "&&" accordingly.
void simplifyComma ()
 Simplify comma into a semicolon when possible:
bool simplifyAddBraces ()
 Add braces to an if-block, for-block, etc.
TokensimplifyAddBracesToCommand (Token *tok)
 Add braces to an if-block, for-block, etc.
TokensimplifyAddBracesPair (Token *tok, bool commandWithCondition)
 Add pair of braces to an single if-block, else-block, for-block, etc.
void simplifyTypedef ()
 typedef A mytype; mytype c;
void simplifyCasts ()
 Simplify casts.
void simplifyUndefinedSizeArray ()
 Change (multiple) arrays to (multiple) pointers.
bool simplifyKnownVariables ()
 A simplify function that replaces a variable with its value in cases when the value is known.
bool simplifyKnownVariablesSimplify (Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token *const valueToken, int indentlevel) const
 utility function for simplifyKnownVariables.
void simplifyGoto ()
 Replace a "goto" with the statements.
void simplifyEmptyNamespaces ()
 Simplify useless C++ empty namespaces, like: 'namespace var% { }'.
void simplifyFlowControl ()
 Simplify redundant code placed after control flow statements : 'return', 'throw', 'goto', 'break' and 'continue'.
void simplifyNestedStrcat ()
 Expand nested strcat() calls.
void elseif ()
 Simplify "if else".
void simplifyConditionOperator ()
 Simplify the operator "?:".
bool simplifyConditions ()
 Simplify conditions.
bool removeRedundantConditions ()
 Remove redundant code, e.g.
void removeRedundantFor ()
 Remove redundant for: "for (x=0;x<1;x++) { }" => "{ x = 1; }".
void removeRedundantSemicolons ()
 Reduces "; ;" to ";", except in "( ; ; )".
bool simplifyFunctionReturn ()
 Simplify function calls - constant return value.
void simplifyStructInit ()
 Struct initialization.
void simplifyStructDecl ()
 Struct simplification "struct S { } s;" => "struct S { }; S s;".
bool simplifyRedundantParentheses ()
 Remove redundant parentheses:
void simplifyCharAt ()
void simplifyReference ()
 Simplify references.
bool simplifyFunctionParameters ()
 Simplify functions like "void f(x) int x; {" into "void f(int x) {".
void simplifyTemplates ()
 Simplify templates.
void simplifyDoublePlusAndDoubleMinus ()
void simplifyRedundantConsecutiveBraces ()
void simplifyArrayAccessSyntax ()
void simplifyParameterVoid ()
void fillTypeSizes ()
void combineOperators ()
void combineStrings ()
void concatenateDoubleSharp ()
void simplifyFileAndLineMacro ()
void simplifyNull ()
void concatenateNegativeNumberAndAnyPositive ()
void simplifyExternC ()
void simplifyRoundCurlyParentheses ()
void simplifyDebugNew ()
void simplifySQL ()
bool hasEnumsWithTypedef ()
void simplifyDefaultAndDeleteInsideClass ()
bool hasComplicatedSyntaxErrorsInTemplates ()
void simplifyMathFunctions ()
 Simplify e.g.
void simplifyMathExpressions ()
 Simplify e.g.
void simplifyComparisonOrder ()
 Use "<" comparison instead of ">" Use "<=" comparison instead of ">=".
void simplifyConst ()
 Change "int const x;" into "const int x;".
void simplifyWhile0 ()
 simplify "while (0)"
void simplifyErrNoInWhile ()
 Simplify while(func() && errno==EINTR)
void simplifyFuncInWhile ()
 Simplify while(func(f))
void simplifyEnum ()
 Replace enum with constant value.
void simplifyStd ()
 Remove "std::" before some function names.
void simplifyPointerToStandardType ()
 Simplify pointer to standard type (C only)
void simplifyFunctionPointers ()
 Simplify function pointers.
void removeExceptionSpecifications ()
 Remove exception specifications.
void cppcheckError (const Token *tok) const
 Send error message to error logger about internal bug.
bool createLinks ()
 Setup links for tokens so that one can call Token::link().
void createLinks2 ()
 Setup links between < and >.
void syntaxError (const Token *tok) const
 Syntax error.
void syntaxError (const Token *tok, char c) const
 Syntax error.
void unhandled_macro_class_x_y (const Token *tok)
 Report that there is an unhandled "class x y {" code.
bool validate () const
 assert that tokens are ok - used during debugging for example to catch problems in simplifyTokenList.
void simplifyDeclspec ()
 Remove __declspec()
void simplifyCallingConvention ()
 Remove calling convention.
void simplifyAttribute ()
 Remove __attribute__ ((?))
void simplifyKeyword ()
 Remove keywords "volatile", "inline", "register", and "restrict".
void simplifyAsm ()
 Remove __asm.
void simplifyBitfields ()
 Simplify bitfields - the field width is removed as we don't use it.
void simplifyBuiltinExpect ()
 Remove __builtin_expect(...), likely(...), and unlikely(...)
void removeUnnecessaryQualification ()
 Remove unnecessary member qualification.
void unnecessaryQualificationError (const Token *tok, const std::string &qualification) const
 unnecessary member qualification error
void simplifyNamespaceStd ()
 Add std:: in front of std classes, when using namespace std; was given.
void simplifyMicrosoftMFC ()
 Remove Microsoft MFC 'DECLARE_MESSAGE_MAP()'.
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)
void simplifyMicrosoftStringFunctions ()
 Convert Microsoft string functions _tcscpy -> strcpy.
void simplifyBorland ()
 Remove Borland code.
void simplifyQtSignalsSlots ()
 Remove Qt signals and slots.
void simplifyOperatorName ()
 Collapse operator name tokens into single token operator = => operator=.
bool duplicateDefinition (Token **tokPtr, const Token *name) const
 check for duplicate enum definition
void reportError (const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, bool inconclusive=false) const
 report error message
void reportError (const std::list< const Token * > &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, bool inconclusive=false) const
void duplicateEnumError (const Token *tok1, const Token *tok2, const std::string &type) const
 duplicate enum definition error
bool duplicateTypedef (Token **tokPtr, const Token *name, const Token *typeDef, bool undefinedStruct) const
void duplicateTypedefError (const Token *tok1, const Token *tok2, const std::string &type) const
void duplicateDeclarationError (const Token *tok1, const Token *tok2, const std::string &type) const
 Report error - duplicate declarations.
void unsupportedTypedef (const Token *tok) const
bool codeWithTemplates () const
 Was there templates in the code?
void setSettings (const Settings *settings)
const SymbolDatabasegetSymbolDatabase () const
void createSymbolDatabase ()
void deleteSymbolDatabase ()
TokendeleteInvalidTypedef (Token *typeDef)
unsigned int varIdCount () const
 Get variable count.
void simplifyReturnStrncat ()
 Simplify e.g.
void printUnknownTypes ()
 Output list of unknown types.
const Tokentokens () const

Static Public Member Functions

static bool IsScopeNoReturn (const Token *endScopeToken, bool *unknown=0)
 Check if inner scope ends with a call to a noreturn function.
static void eraseDeadCode (Token *begin, const Token *end)
 Deletes dead code between 'begin' and 'end'.
static void getErrorMessages (ErrorLogger *errorLogger, const Settings *settings)
 get error messages that the tokenizer generate
static bool simplifyKnownVariablesGetData (unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar)
 Utility function for simplifyKnownVariables.
static std::string simplifyString (const std::string &source)
 Modify strings in the token list by replacing hex and oct values.
static TokencopyTokens (Token *dest, const Token *first, const Token *last, bool one_line=true)
 Copy tokens.

Public Attributes

TokenList list
 Token list: stores all tokens.

Private Member Functions

 Tokenizer (const Tokenizer &)
 Disable copy constructor, no implementation.
Tokenizeroperator= (const Tokenizer &)
 Disable assignment operator, no implementation.

Private Attributes

const Settings_settings
 settings
ErrorLogger *const _errorLogger
 errorlogger
SymbolDatabase_symbolDatabase
 Symbol database that all checks etc can use.
std::string _configuration
 E.g.
std::map< std::string,
unsigned int > 
_typeSize
 sizeof information for known types
unsigned int _varId
 variable count
bool _codeWithTemplates
 was there any templates? templates that are "unused" are removed from the token list
TimerResultsm_timerResults
 TimerResults.

Detailed Description

The main purpose is to tokenize the source code.

It also has functions that simplify the token list

Definition at line 41 of file tokenize.h.


Constructor & Destructor Documentation

Definition at line 38 of file tokenize.cpp.

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

Definition at line 49 of file tokenize.cpp.

References _settings.

Definition at line 62 of file tokenize.cpp.

References _symbolDatabase.

Tokenizer::Tokenizer ( const Tokenizer ) [private]

Disable copy constructor, no implementation.


Member Function Documentation

Insert array size where it isn't given.

Specify array size if it hasn't been given.

Definition at line 2372 of file tokenize.cpp.

References Token::deleteNext(), TokenList::front(), Token::link(), Token::linkAt(), list, MathLib::longToString(), Token::Match(), Token::next(), and Token::tokAt().

Referenced by tokenize().

bool Tokenizer::codeWithTemplates ( ) const [inline]

Was there templates in the code?

Definition at line 686 of file tokenize.h.

Referenced by CheckOther::checkSignOfUnsignedVariable().

Definition at line 2090 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

Definition at line 2136 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

Definition at line 2168 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

Token * Tokenizer::copyTokens ( Token dest,
const Token first,
const Token last,
bool  one_line = true 
) [static]

Copy tokens.

Parameters:
destdestination token where copied tokens will be inserted after
firstfirst token to copy
lastlast token to copy
one_linetrue=>copy all tokens to the same line as dest. false=>copy all tokens to dest while keeping the 'line breaks'
Returns:
new location of last token copied

Definition at line 95 of file tokenize.cpp.

References Token::fileIndex(), Token::insertToken(), Token::isLong(), Token::isPointerCompare(), Token::isSigned(), Token::isUnsigned(), Token::isUnused(), Token::linenr(), Token::link(), Token::next(), Token::setExpandedMacro(), Token::str(), Token::type(), and Token::varId().

Referenced by EnumValue::simplify(), simplifyEnum(), simplifyReturnStrncat(), and simplifyTypedef().

void Tokenizer::cppcheckError ( const Token tok) const

Send error message to error logger about internal bug.

Parameters:
tokthe token that this bug concerns.

Definition at line 7870 of file tokenize.cpp.

References Severity::error, and reportError().

Referenced by getErrorMessages(), tokenize(), tokenizeCondition(), and validate().

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

Returns:
false if there was a mismatch with tokens, this should mean that source code was not valid.

Definition at line 2980 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

Setup links between < and >.

Definition at line 3025 of file tokenize.cpp.

References Token::createMutualLinks(), TokenList::front(), isC(), list, Token::Match(), Token::next(), and Token::str().

Referenced by tokenize().

Definition at line 9178 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

void Tokenizer::duplicateDeclarationError ( const Token tok1,
const Token tok2,
const std::string &  type 
) const

Report error - duplicate declarations.

Definition at line 151 of file tokenize.cpp.

References _settings, Settings::isEnabled(), reportError(), Token::str(), and Severity::style.

Referenced by duplicateTypedef(), and getErrorMessages().

bool Tokenizer::duplicateDefinition ( Token **  tokPtr,
const Token name 
) const

check for duplicate enum definition

Definition at line 6992 of file tokenize.cpp.

References duplicateEnumError(), Token::isName(), Token::link(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::tokAt().

Referenced by simplifyEnum().

void Tokenizer::duplicateEnumError ( const Token tok1,
const Token tok2,
const std::string &  type 
) const

duplicate enum definition error

Definition at line 6975 of file tokenize.cpp.

References _settings, Settings::isEnabled(), reportError(), Token::str(), and Severity::style.

Referenced by duplicateDefinition(), and getErrorMessages().

bool Tokenizer::duplicateTypedef ( Token **  tokPtr,
const Token name,
const Token typeDef,
bool  undefinedStruct 
) const
void Tokenizer::duplicateTypedefError ( const Token tok1,
const Token tok2,
const std::string &  type 
) const

Simplify "if else".

Definition at line 6537 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

void Tokenizer::eraseDeadCode ( Token begin,
const Token end 
) [static]

Deletes dead code between 'begin' and 'end'.

In general not everything can be erased, such as:

  • code after labels;
  • code outside the scope where the function is called;
  • code after a change of scope caused by 'switch(...);' instructions, like 'case any%;' or 'default;' Also, if the dead code contains a 'switch' block and inside it there's a label, the function removes all the 'switch(..)' tokens and every occurrence of 'case any%; | default;' expression, such as the 'switch' block is reduced to a simple block.
Parameters:
beginTokens after this have a possibility to be erased.
endTokens before this have a possibility to be erased.

Definition at line 7661 of file tokenize.cpp.

References Token::deleteNext(), Token::eraseTokens(), Token::findsimplematch(), Token::link(), Token::linkAt(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::tokAt().

Referenced by removeRedundantConditions(), simplifyFlowControl(), and simplifyWhile0().

void Tokenizer::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
) [static]

get error messages that the tokenizer generate

Definition at line 8246 of file tokenize.cpp.

References cppcheckError(), duplicateDeclarationError(), duplicateEnumError(), duplicateTypedefError(), syntaxError(), and unnecessaryQualificationError().

const std::string & Tokenizer::getSourceFilePath ( ) const

Returns the source file path.

e.g. "file.cpp"

Definition at line 9477 of file tokenize.cpp.

References TokenList::getFiles(), and list.

Referenced by CppCheck::checkFile(), CheckBufferOverrun::checkGlobalAndLocalVariable(), isC(), isCPP(), and CheckUnusedFunctions::parseTokens().

const SymbolDatabase* Tokenizer::getSymbolDatabase ( ) const [inline]

Definition at line 695 of file tokenize.h.

Referenced by CheckBufferOverrun::arrayIndexInForLoop(), CheckBufferOverrun::arrayIndexThenCheck(), CheckAutoVariables::autoVariables(), CheckUninitVar::check(), CheckLeakAutoVar::check(), CheckMemoryLeakInClass::check(), CheckMemoryLeakStructMember::check(), CheckMemoryLeakNoVar::check(), CheckOther::checkAssignBoolToPointer(), CheckOther::checkBitwiseOnBoolean(), CheckBoost::checkBoostForeachModification(), CheckBufferOverrun::checkBufferAllocatedWithStrlen(), CheckOther::checkCastIntToCharAndBack(), CheckExceptionSafety::checkCatchExceptionByValue(), CheckOther::checkCharVariable(), CheckOther::checkComparisonOfBoolExpressionWithInt(), CheckOther::checkComparisonOfBoolWithBool(), CheckOther::checkComparisonOfBoolWithInt(), CheckOther::checkComparisonOfFuncReturningBool(), CheckOther::checkConstantFunctionParameter(), CheckIO::checkCoutCerrMisusage(), CheckOther::checkDuplicateBranch(), CheckOther::checkDuplicateExpression(), CheckOther::checkDuplicateIf(), CheckIO::checkFileUsage(), CheckUnusedVar::checkFunctionVariableUsage(), CheckBufferOverrun::checkGlobalAndLocalVariable(), CheckOther::checkIncompleteArrayFill(), CheckOther::checkIncorrectLogicOperator(), CheckOther::checkIncorrectStringCompare(), CheckOther::checkIncrementBoolean(), CheckBufferOverrun::checkInsecureCmdLineArgs(), CheckOther::checkMathFunctions(), CheckMemoryLeakInFunction::CheckMemoryLeakInFunction(), CheckOther::checkMemsetZeroBytes(), CheckOther::checkMisusedScopedObject(), CheckOther::checkModuloAlwaysTrueFalse(), CheckOther::checkNegativeBitwiseShift(), CheckOther::checkPipeParameterSize(), CheckMemoryLeakInClass::checkPublicFunctions(), CheckOther::checkRedundantAssignment(), CheckOther::checkRedundantAssignmentInSwitch(), CheckOther::checkRedundantCopy(), CheckExceptionSafety::checkRethrowCopy(), CheckUninitVar::checkScope(), CheckBufferOverrun::checkScopeForBody(), CheckOther::checkSignOfUnsignedVariable(), CheckOther::checkSizeofForArrayParameter(), CheckOther::checkSizeofForNumericParameter(), CheckOther::checkSizeofForPointerSize(), CheckOther::checkSleepTimeInterval(), CheckBufferOverrun::checkStructVariable(), CheckOther::checkSuspiciousCaseInSwitch(), CheckOther::checkSuspiciousSemicolon(), CheckOther::checkSuspiciousStringCompare(), CheckOther::checkSwitchCaseFallThrough(), CheckOther::checkUnsignedDivision(), CheckOther::checkVarFuncNullUB(), CheckOther::checkVariableScope(), CheckIO::checkWrongPrintfScanfArguments(), CheckOther::clarifyCalculation(), CheckOther::clarifyCondition(), CheckOther::clarifyStatement(), CheckExceptionSafety::deallocThrow(), CheckExceptionSafety::destructors(), CheckStl::erase(), CheckUninitVar::executionPaths(), CheckBufferOverrun::executionPaths(), CheckNullPointer::executionPaths(), CheckMemoryLeak::functionReturnType(), CheckStl::if_find(), CheckOther::invalidPointerCast(), CheckIO::invalidScanf(), CheckMemoryLeak::isclass(), CheckStl::iterators(), CheckStl::mismatchingContainers(), CheckStl::missingComparison(), CheckAssignIf::multiCondition(), CheckNullPointer::nullConstantDereference(), CheckNullPointer::nullPointerByCheckAndDeRef(), CheckNullPointer::nullPointerByDeRefAndChec(), CheckNullPointer::nullPointerDefaultArgument(), CheckNullPointer::nullPointerLinkedList(), CheckNullPointer::nullPointerStructByDeRefAndChec(), CheckObsoleteFunctions::obsoleteFunctions(), CheckOther::oppositeInnerCondition(), Check64BitPortability::pointerassignment(), CheckPostfixOperator::postfixOperator(), CheckStl::pushback(), CheckLeakAutoVar::ret(), CheckAutoVariables::returnPointerToLocalArray(), CheckAutoVariables::returnReference(), CheckAutoVariables::returnTemporary(), CheckStl::size(), CheckStl::stlBoundaries(), CheckStl::stlOutOfBounds(), CheckStl::string_c_str(), CheckOther::strPlusChar(), CheckStl::uselessCalls(), and CheckBufferOverrun::writeOutsideBufferSize().

Definition at line 2048 of file tokenize.cpp.

References TokenList::front(), list, and syntaxError().

Referenced by tokenize().

bool Tokenizer::isC ( ) const
bool Tokenizer::isCPP ( ) const
bool Tokenizer::isFunctionParameterPassedByValue ( const Token fpar) const

Try to determine if function parameter is passed by value by looking at the function declaration.

Parameters:
fpartoken for function parameter in the function call
Returns:
true if the parameter is passed by value. if unsure, false is returned

Definition at line 7588 of file tokenize.cpp.

References Token::isStandardType(), Token::Match(), Token::next(), Token::previous(), Token::str(), Token::tokAt(), and tokens().

Referenced by simplifyKnownVariablesSimplify().

bool Tokenizer::IsScopeNoReturn ( const Token endScopeToken,
bool *  unknown = 0 
) [static]

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 7552 of file tokenize.cpp.

References Token::isName(), Token::linkAt(), Token::Match(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::tokAt().

Referenced by CheckOther::checkDoubleFree(), CheckOther::checkRedundantAssignment(), CheckLeakAutoVar::checkScope(), CheckUninitVar::checkScopeForVariable(), and CheckNullPointer::nullPointerByCheckAndDeRef().

Tokenizer& Tokenizer::operator= ( const Tokenizer ) [private]

Disable assignment operator, no implementation.

Remove exception specifications.

Definition at line 8029 of file tokenize.cpp.

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

Referenced by tokenize().

Remove unknown macro in variable declarations: PROGMEM char x;.

Definition at line 3578 of file tokenize.cpp.

References Token::eraseTokens(), TokenList::front(), Token::isStandardType(), Token::isUpperCaseName(), list, Token::Match(), Token::next(), and Token::str().

Referenced by tokenize().

Remove macros in global scope.

Definition at line 3523 of file tokenize.cpp.

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

Referenced by tokenize().

Remove redundant assignment.

Definition at line 3607 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

Remove redundant code, e.g.

if( false ) { int a; } should be removed, because it is never executed.

Returns:
true if something is modified false if nothing is done.

Definition at line 3811 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

Remove redundant for: "for (x=0;x<1;x++) { }" => "{ x = 1; }".

Definition at line 3880 of file tokenize.cpp.

References TokenList::front(), Token::insertToken(), Token::link(), Token::linkAt(), list, MathLib::longToString(), Token::Match(), Token::next(), Token::str(), Token::tokAt(), MathLib::toLongNumber(), and Token::varId().

Referenced by simplifyTokenList().

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

Definition at line 3950 of file tokenize.cpp.

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

Referenced by simplifyTokenList(), and tokenize().

Remove unnecessary member qualification.

Todo:
this should be made more generic to handle more levels

Definition at line 9248 of file tokenize.cpp.

References _settings, Space::classEnd, Space::className, TokenList::front(), isC(), Settings::isEnabled(), Space::isNamespace, Token::link(), list, Token::Match(), Token::next(), Token::str(), Token::tokAt(), and unnecessaryQualificationError().

Referenced by tokenize().

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

Definition at line 9502 of file tokenize.cpp.

References _errorLogger, list, ErrorLogger::reportErr(), and reportError().

void Tokenizer::setSettings ( const Settings settings) [inline]

Definition at line 690 of file tokenize.h.

Referenced by PreprocessorMacro::PreprocessorMacro().

void Tokenizer::setTimerResults ( TimerResults tr) [inline]

Definition at line 47 of file tokenize.h.

Referenced by CppCheck::checkFile().

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

Returns:
true if no syntax errors

Definition at line 3969 of file tokenize.cpp.

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

Referenced by tokenize().

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

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 4029 of file tokenize.cpp.

References Token::createMutualLinks(), Token::eBracket, Token::eExtendedOp, Token::insertToken(), Token::link(), Token::Match(), Token::next(), Token::previous(), simplifyAddBracesToCommand(), Token::str(), syntaxError(), and Token::type().

Referenced by simplifyAddBracesToCommand().

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 3979 of file tokenize.cpp.

References Token::link(), Token::next(), Token::previous(), simplifyAddBracesPair(), Token::str(), and syntaxError().

Referenced by simplifyAddBraces(), and simplifyAddBracesPair().

Definition at line 2289 of file tokenize.cpp.

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

Referenced by tokenize().

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

Definition at line 8617 of file tokenize.cpp.

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

Referenced by tokenize().

Simplify assignment in function call "f(x=g());" => "x=g();f(x);".

Definition at line 8578 of file tokenize.cpp.

References Token::createMutualLinks(), Token::eraseTokens(), TokenList::front(), Token::link(), list, Token::Match(), Token::next(), Token::simpleMatch(), and Token::tokAt().

Referenced by tokenize().

Remove __attribute__ ((?))

Definition at line 8521 of file tokenize.cpp.

References Token::eraseTokens(), TokenList::front(), list, Token::Match(), Token::next(), and Token::simpleMatch().

Referenced by tokenize().

Remove Borland code.

Definition at line 9021 of file tokenize.cpp.

References Token::eraseTokens(), TokenList::front(), Token::link(), list, Token::Match(), and Token::next().

Referenced by tokenize().

Remove __builtin_expect(...), likely(...), and unlikely(...)

Definition at line 8759 of file tokenize.cpp.

References TokenList::front(), Token::link(), Token::linkAt(), list, Token::Match(), Token::next(), Token::simpleMatch(), and Token::tokAt().

Referenced by tokenize().

Simplify constant calculations such as "1+2" => "3".

Returns:
true if modifications to token-list are done. false if no modifications are done.

Definition at line 6737 of file tokenize.cpp.

References TokenList::front(), and list.

Referenced by Preprocessor::simplifyCondition(), and simplifyTokenList().

Remove calling convention.

Definition at line 8502 of file tokenize.cpp.

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

Referenced by tokenize().

Simplify comma into a semicolon when possible:

  • "delete a, delete b" => "delete a; delete b;"
  • "a = 0, b = 0;" => "a = 0; b = 0;"
  • "return a(), b;" => "a(); return b;"

Definition at line 7907 of file tokenize.cpp.

References Token::deleteNext(), Token::findClosingBracket(), TokenList::front(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), and Token::str().

Referenced by simplifyTokenList().

Use "<" comparison instead of ">" Use "<=" comparison instead of ">=".

Definition at line 8199 of file tokenize.cpp.

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

Referenced by simplifyTokenList(), and tokenize().

Simplify compound assignments Example: ";a+=b;" => ";a=a+b;".

Definition at line 4101 of file tokenize.cpp.

References Token::createMutualLinks(), Token::deleteNext(), Token::eIncDecOp, TokenList::front(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), and Token::simpleMatch().

Referenced by tokenize().

Simplify conditions.

Returns:
true if something is modified false if nothing is done.

Definition at line 4310 of file tokenize.cpp.

References Token::eraseTokens(), TokenList::front(), MathLib::isInt(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), MathLib::toDoubleNumber(), and MathLib::toLongNumber().

Referenced by simplifyTokenList().

Change "int const x;" into "const int x;".

Definition at line 8226 of file tokenize.cpp.

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

Referenced by tokenize().

Simplify easy constant '?:' operation Example: 0 ? (2/0) : 0 => 0.

Returns:
true if something is modified false if nothing is done.

Definition at line 4458 of file tokenize.cpp.

References Token::eraseTokens(), TokenList::front(), list, Token::Match(), Token::next(), Token::previous(), skipTernaryOp(), Token::str(), TemplateSimplifier::templateParameters(), and Token::tokAt().

Referenced by simplifyTokenList().

Definition at line 2280 of file tokenize.cpp.

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

Referenced by tokenize().

Remove __declspec()

Definition at line 8511 of file tokenize.cpp.

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

Referenced by tokenize().

Definition at line 2324 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

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

Definition at line 3704 of file tokenize.cpp.

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

Referenced by simplifyTokenList(), and tokenize().

Simplify while(func() && errno==EINTR)

Definition at line 8305 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

Definition at line 2224 of file tokenize.cpp.

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

Referenced by tokenize().

Definition at line 2178 of file tokenize.cpp.

References TokenList::file(), TokenList::front(), list, MathLib::longToString(), and Token::next().

Referenced by tokenize().

Simplify redundant code placed after control flow statements : 'return', 'throw', 'goto', 'break' and 'continue'.

Definition at line 3737 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

Simplify functions like "void f(x) int x; {" into "void f(int x) {".

Returns:
false only if there's a syntax error

Definition at line 4648 of file tokenize.cpp.

References Token::deleteNext(), TokenList::front(), Token::isName(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), Token::replace(), Token::simpleMatch(), Token::str(), syntaxError(), and Token::tokAt().

Referenced by tokenize().

Simplify function calls - constant return value.

Returns:
true if something is modified false if nothing is done.

Definition at line 4903 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

simplify if-assignments Example: "if(a=b);" => "a=b;if(a);"

Definition at line 5455 of file tokenize.cpp.

References Token::createMutualLinks(), Token::fileIndex(), TokenList::front(), Token::insertToken(), Token::linenr(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), Token::str(), and Token::varId().

Referenced by simplifyTokenList().

simplify if-not Example: "if(0==x);" => "if(!x);"

Definition at line 5584 of file tokenize.cpp.

References Token::createMutualLinks(), TokenList::front(), Token::link(), list, Token::Match(), and Token::next().

Referenced by simplifyTokenList(), and tokenize().

simplify if-not NULL Example: "if(0!=x);" => "if(x);" Special case: 'x = (0 != x);' is removed.

Definition at line 5645 of file tokenize.cpp.

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

Referenced by simplifyTokenList(), and tokenize().

simplify if (a) { if (a)

Definition at line 5701 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

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

Definition at line 5779 of file tokenize.cpp.

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

Referenced by simplifyTokenList(), and tokenize().

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

Definition at line 8547 of file tokenize.cpp.

References _settings, Standards::c, Standards::C99, Standards::cpp, Standards::CPP11, TokenList::front(), list, Token::Match(), Token::next(), and Settings::standards.

Referenced by tokenize(), and tokenizeCondition().

A simplify function that replaces a variable with its value in cases when the value is known.

e.g. "x=10; if(x)" => "x=10;if(10)"

Returns:
true if modifications to token-list are done. false if no modifications are done.

Definition at line 5859 of file tokenize.cpp.

References _settings, Token::deleteNext(), Token::deleteThis(), TokenList::front(), Token::isName(), list, Token::Match(), Token::next(), Token::previous(), Token::replace(), simplifyKnownVariablesGetData(), simplifyKnownVariablesSimplify(), Token::str(), Token::strAt(), Settings::terminated(), Token::tokAt(), and Token::varId().

Referenced by simplifyTokenList().

bool Tokenizer::simplifyKnownVariablesGetData ( unsigned int  varid,
Token **  _tok2,
Token **  _tok3,
std::string &  value,
unsigned int &  valueVarId,
bool &  valueIsPointer,
bool  floatvar 
) [static]

Utility function for simplifyKnownVariables.

Get data about an assigned variable.

Definition at line 6062 of file tokenize.cpp.

References Token::isBoolean(), Token::isNumber(), Token::link(), Token::linkAt(), MathLib::longToString(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::strAt(), Token::tokAt(), MathLib::toLongNumber(), and Token::varId().

Referenced by simplifyKnownVariables().

bool Tokenizer::simplifyKnownVariablesSimplify ( Token **  tok2,
Token tok3,
unsigned int  varid,
const std::string &  structname,
std::string &  value,
unsigned int  valueVarId,
bool  valueIsPointer,
const Token *const  valueToken,
int  indentlevel 
) const

Simplify labels and 'case|default' syntaxes.

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

Returns:
true if found nothing or the syntax is correct. false if syntax is found to be wrong.

Definition at line 2444 of file tokenize.cpp.

References TokenList::front(), list, Token::Match(), Token::next(), skipTernaryOp(), and syntaxError().

Referenced by tokenize().

Simplify the "not" and "and" keywords to "!" and "&&" accordingly.

Examples:

  • "if (not p)" => "if (!p)"
  • "if (p and q)" => "if (p && q)"

Definition at line 5727 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

Simplify e.g.

'atol("0")' into '0'

Definition at line 7877 of file tokenize.cpp.

References TokenList::front(), MathLib::isInt(), list, MathLib::longToString(), Token::Match(), Token::next(), Token::simpleMatch(), and MathLib::toLongNumber().

Referenced by tokenize(), and tokenizeCondition().

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)

Definition at line 8873 of file tokenize.cpp.

References _settings, TokenList::front(), Token::insertToken(), Token::link(), list, Token::Match(), Token::move(), Token::next(), Token::nextArgument(), Settings::platformType, Token::previous(), Token::simpleMatch(), Token::tokAt(), Settings::Win32A, Settings::Win32W, and Settings::Win64.

Referenced by tokenize().

Remove Microsoft MFC 'DECLARE_MESSAGE_MAP()'.

Definition at line 8856 of file tokenize.cpp.

References _settings, TokenList::front(), list, Token::Match(), Token::next(), Settings::platformType, Token::simpleMatch(), Settings::Win32A, Settings::Win32W, and Settings::Win64.

Referenced by tokenize().

Convert Microsoft string functions _tcscpy -> strcpy.

Definition at line 8925 of file tokenize.cpp.

References _settings, TokenList::front(), list, Token::Match(), Token::next(), Settings::platformType, Token::simpleMatch(), Settings::Win32A, Settings::Win32W, and Settings::Win64.

Referenced by tokenize().

Simplify '* & ( var% ) =' or any combination of '* &' and '()' parentheses around 'var' to 'var% ='.

Definition at line 1494 of file tokenize.cpp.

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

Referenced by tokenize().

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

Definition at line 8789 of file tokenize.cpp.

References _settings, Standards::cpp, Standards::CPP11, Token::eraseTokens(), Token::findsimplematch(), TokenList::front(), isCPP(), list, Token::Match(), Token::next(), Token::simpleMatch(), and Settings::standards.

Referenced by tokenize().

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

Definition at line 9191 of file tokenize.cpp.

References Token::eraseTokens(), TokenList::front(), isC(), Token::isName(), Token::link(), list, Token::Match(), Token::next(), Token::simpleMatch(), Token::str(), and Token::tokAt().

Referenced by tokenize().

Definition at line 2301 of file tokenize.cpp.

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

Referenced by tokenize().

Convert platform dependent types to standard types.

32 bits: size_t -> unsigned long 64 bits: size_t -> unsigned long long

Todo:
This assumes a flat address space. Not true for segmented address space (FAR *).

Definition at line 5200 of file tokenize.cpp.

References _settings, TokenList::front(), list, Token::Match(), Token::next(), Settings::platformType, Settings::sizeof_long, Settings::sizeof_size_t, Settings::Win32A, Settings::Win32W, and Settings::Win64.

Referenced by tokenize(), and tokenizeCondition().

Simplify pointer to standard type (C only)

Definition at line 4820 of file tokenize.cpp.

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

Referenced by tokenize().

Remove Qt signals and slots.

Definition at line 9070 of file tokenize.cpp.

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

Referenced by tokenize().

Simplifies some realloc usage like 'x = realloc (0, n);' => 'x = malloc(n);' 'x = realloc (y, 0);' => 'x = 0; free(y);'.

Definition at line 3659 of file tokenize.cpp.

References Token::deleteNext(), TokenList::front(), Token::insertToken(), Token::link(), list, Token::Match(), Token::move(), Token::next(), Token::previous(), Token::simpleMatch(), and Token::tokAt().

Referenced by simplifyTokenList().

Definition at line 2309 of file tokenize.cpp.

References TokenList::front(), list, and Token::simpleMatch().

Referenced by simplifyTokenList(), and tokenize().

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 6563 of file tokenize.cpp.

References Token::deleteNext(), Token::deleteThis(), Token::findsimplematch(), TokenList::front(), Token::isArithmeticalOp(), isCPP(), Token::link(), list, Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), and Token::tokAt().

Referenced by Preprocessor::simplifyCondition(), simplifyTokenList(), tokenize(), and tokenizeCondition().

Simplify references.

Definition at line 6703 of file tokenize.cpp.

References TokenList::front(), isC(), Token::link(), list, Token::Match(), Token::next(), and Token::tokAt().

Referenced by simplifyTokenList().

Simplify e.g.

'return(strncat(temp,"a",1));' into strncat(temp,"a",1); return temp;

Definition at line 9323 of file tokenize.cpp.

References copyTokens(), Token::deleteThis(), TokenList::front(), Token::insertToken(), Token::link(), Token::linkAt(), list, Token::next(), Token::nextArgument(), Token::simpleMatch(), and Token::tokAt().

Referenced by simplifyTokenList().

Definition at line 2238 of file tokenize.cpp.

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

Referenced by tokenize().

Remove "std::" before some function names.

Definition at line 7520 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

Collapse compound standard types into a single token.

unsigned long long int => long _isUnsigned=true,_isLong=true

Definition at line 5399 of file tokenize.cpp.

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

Referenced by tokenize(), and tokenizeCondition().

std::string Tokenizer::simplifyString ( const std::string &  source) [static]

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"

Definition at line 8112 of file tokenize.cpp.

References MathLib::isOctalDigit().

Referenced by combineStrings().

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

Definition at line 8373 of file tokenize.cpp.

References Token::deleteThis(), TokenList::front(), Token::insertToken(), Token::link(), list, MathLib::longToString(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), Token::tokAt(), and Token::varId().

Referenced by tokenize().

Simplify tokenlist.

Returns:
false if there is an error that requires aborting the checking of this file.

Definition at line 3299 of file tokenize.cpp.

References _settings, _symbolDatabase, Settings::_verbose, Token::assignProgressValues(), Token::createMutualLinks(), createSymbolDatabase(), Settings::debug, Settings::debugwarnings, deleteSymbolDatabase(), Token::deleteThis(), elseif(), TokenList::front(), TokenList::getFiles(), Token::getStrLength(), Token::link(), list, Token::Match(), Token::next(), Token::printOut(), SymbolDatabase::printOut(), printUnknownTypes(), removeRedundantAssignment(), removeRedundantConditions(), removeRedundantFor(), removeRedundantSemicolons(), Token::simpleMatch(), simplifyCalculations(), simplifyCasts(), simplifyCharAt(), simplifyComma(), simplifyComparisonOrder(), simplifyConditionOperator(), simplifyConditions(), simplifyConstTernaryOp(), simplifyEmptyNamespaces(), simplifyErrNoInWhile(), simplifyFlowControl(), simplifyFuncInWhile(), simplifyFunctionReturn(), simplifyGoto(), simplifyIfAssign(), simplifyIfNot(), simplifyIfNotNull(), simplifyIfSameInnerCondition(), simplifyInitVar(), simplifyKnownVariables(), simplifyNestedStrcat(), simplifyRealloc(), simplifyRedundantConsecutiveBraces(), simplifyRedundantParentheses(), simplifyReference(), simplifyReturnStrncat(), simplifySizeof(), simplifyStd(), simplifyUndefinedSizeArray(), simplifyVarDecl(), simplifyWhile0(), Settings::terminated(), Token::tokAt(), and validate().

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

Change (multiple) arrays to (multiple) pointers.

Definition at line 4530 of file tokenize.cpp.

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

Referenced by simplifyTokenList().

void Tokenizer::simplifyVarDecl ( bool  only_k_r_fpar)

Simplify multiple assignments.

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

Definition at line 5553 of file tokenize.cpp.

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

Referenced by tokenize().

unsigned int Tokenizer::sizeOfType ( const Token type) const
void Tokenizer::syntaxError ( const Token tok) const
void Tokenizer::syntaxError ( const Token tok,
char  c 
) const

Syntax error.

Example: invalid number of ')'

Definition at line 7851 of file tokenize.cpp.

References _configuration, Severity::error, and reportError().

bool Tokenizer::tokenize ( std::istream &  code,
const char  FileName[],
const std::string &  configuration = "" 
)

Tokenize code.

Parameters:
codeinput stream for code, e.g.
 #file "p.h"
 class Foo
 {
 private:
 void Bar();
 };

 #endfile
 void Foo::Bar()
 {
 }
FileNameThe filename
configurationE.g. "A" for code where "#ifdef A" is true
Returns:
false if source code contains syntax errors

Definition at line 1555 of file tokenize.cpp.

References Settings::_basePaths, _configuration, _settings, Settings::_showtime, arraySize(), Token::assignProgressValues(), TemplateSimplifier::cleanupAfterSimplify(), combineOperators(), combineStrings(), concatenateDoubleSharp(), concatenateNegativeNumberAndAnyPositive(), cppcheckError(), createLinks(), createLinks2(), createSymbolDatabase(), TokenList::createTokens(), TokenList::deallocateTokens(), fillTypeSizes(), TokenList::front(), Path::getRelativePath(), hasComplicatedSyntaxErrorsInTemplates(), hasEnumsWithTypedef(), isCPP(), Settings::isEnabled(), list, m_timerResults, Token::Match(), Token::next(), removeExceptionSpecifications(), removeMacroInVarDecl(), removeMacrosInGlobalScope(), removeRedundantSemicolons(), removeUnnecessaryQualification(), setVarId(), Token::simpleMatch(), simplifyAddBraces(), simplifyArrayAccessSyntax(), simplifyAsm(), simplifyAssignmentBlock(), simplifyAssignmentInFunctionCall(), simplifyAttribute(), simplifyBitfields(), simplifyBorland(), simplifyBuiltinExpect(), simplifyCallingConvention(), simplifyComparisonOrder(), simplifyCompoundAssignment(), simplifyConditionOperator(), simplifyConst(), simplifyDebugNew(), simplifyDeclspec(), simplifyDoublePlusAndDoubleMinus(), simplifyEmptyNamespaces(), simplifyEnum(), simplifyExternC(), simplifyFileAndLineMacro(), simplifyFunctionParameters(), simplifyFunctionPointers(), simplifyIfNot(), simplifyIfNotNull(), simplifyInitVar(), simplifyKeyword(), simplifyLabelsCaseDefault(), simplifyLogicalOperators(), simplifyMathExpressions(), simplifyMathFunctions(), simplifyMicrosoftMemoryFunctions(), simplifyMicrosoftMFC(), simplifyMicrosoftStringFunctions(), simplifyMulAndParens(), simplifyNamespaceStd(), simplifyNull(), TemplateSimplifier::simplifyNumericCalculations(), simplifyOperatorName(), simplifyParameterVoid(), Path::simplifyPath(), simplifyPlatformTypes(), simplifyPointerToStandardType(), simplifyQtSignalsSlots(), simplifyRedundantConsecutiveBraces(), simplifyRedundantParentheses(), simplifyRoundCurlyParentheses(), simplifySQL(), simplifyStdType(), simplifyStructDecl(), simplifyStructInit(), simplifyTemplates(), simplifyTypedef(), simplifyVarDecl(), simplifyVariableMultipleAssign(), syntaxError(), unhandled_macro_class_x_y(), and validate().

Referenced by CppCheck::analyseFile(), CppCheck::checkFile(), and Preprocessor::getcode().

bool Tokenizer::tokenizeCondition ( const std::string &  code)
const Token* Tokenizer::tokens ( ) const [inline]

Definition at line 728 of file tokenize.h.

Referenced by CppCheck::analyseFile(), CheckAssignIf::assignIf(), CheckMemoryLeakNoVar::check(), CheckOther::checkAlwaysTrueOrFalseStringCompare(), CheckOther::checkAssignmentInAssert(), CheckStl::checkAutoPointer(), CheckOther::checkCCTypeFunctions(), CheckOther::checkDoubleFree(), CppCheck::checkFile(), CheckBufferOverrun::checkGlobalAndLocalVariable(), CheckOther::checkIncompleteStatement(), CheckOther::checkInvalidFree(), CheckInternal::checkMissingPercentCharacter(), CheckInternal::checkRedundantNextPrevious(), CheckOther::checkSelfAssignment(), CheckUnusedVar::checkStructMemberUsage(), CheckOther::checkSuspiciousEqualityComparison(), CheckOther::checkSwitchCaseFallThrough(), CheckInternal::checkTokenMatchPatterns(), CheckInternal::checkTokenSimpleMatchPatterns(), CheckInternal::checkUnknownPattern(), CheckOther::checkUnreachableCode(), CheckOther::checkZeroDivision(), CheckAssignIf::comparison(), CheckStl::erase(), CheckUninitVar::executionPaths(), CheckMemoryLeak::getAllocationType(), Preprocessor::getcfgs(), Preprocessor::getcode(), CheckMemoryLeakInFunction::getcode(), Scope::getVariableList(), CheckOther::invalidFunctionUsage(), isFunctionParameterPassedByValue(), CheckBufferOverrun::negativeIndex(), CheckNonReentrantFunctions::nonReentrantFunctions(), CheckUnusedFunctions::parseTokens(), CheckStl::redundantCondition(), CheckOther::redundantGetAndSetUserId(), Preprocessor::simplifyCondition(), simplifyFunctionReturn(), CheckOther::sizeofCalculation(), CheckOther::sizeofsizeof(), CheckStl::string_c_str(), CheckOther::suspiciousSizeofCalculation(), SymbolDatabase::SymbolDatabase(), CheckClass::thisSubtraction(), PreprocessorMacro::tokens(), validate(), CheckClass::virtualDestructor(), and CheckOther::warningOldStylePointerCast().

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

Definition at line 7858 of file tokenize.cpp.

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

Referenced by tokenize().

void Tokenizer::unnecessaryQualificationError ( const Token tok,
const std::string &  qualification 
) const

unnecessary member qualification error

Definition at line 9317 of file tokenize.cpp.

References Severity::portability, and reportError().

Referenced by getErrorMessages(), and removeUnnecessaryQualification().

void Tokenizer::unsupportedTypedef ( const Token tok) const
bool Tokenizer::validate ( ) const

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

Returns:
always true.

Definition at line 8053 of file tokenize.cpp.

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

Referenced by simplifyTokenList(), and tokenize().

unsigned int Tokenizer::varIdCount ( ) const [inline]

Get variable count.

Returns:
number of variables

Definition at line 707 of file tokenize.h.

Referenced by CheckBufferOverrun::checkGlobalAndLocalVariable(), CheckBufferOverrun::executionPaths(), and SymbolDatabase::SymbolDatabase().


Member Data Documentation

was there any templates? templates that are "unused" are removed from the token list

Definition at line 772 of file tokenize.h.

Referenced by simplifyTemplates().

std::string Tokenizer::_configuration [private]

E.g.

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

Definition at line 760 of file tokenize.h.

Referenced by syntaxError(), and tokenize().

const Settings* Tokenizer::_settings [private]

Symbol database that all checks etc can use.

Definition at line 756 of file tokenize.h.

Referenced by createSymbolDatabase(), deleteSymbolDatabase(), printUnknownTypes(), simplifyTokenList(), and ~Tokenizer().

std::map<std::string, unsigned int> Tokenizer::_typeSize [private]

sizeof information for known types

Definition at line 763 of file tokenize.h.

Referenced by fillTypeSizes(), simplifyCasts(), and sizeOfType().

unsigned int Tokenizer::_varId [private]

variable count

Definition at line 766 of file tokenize.h.

Referenced by printUnknownTypes(), setVarId(), and simplifyFuncInWhile().

Token list: stores all tokens.

Definition at line 726 of file tokenize.h.

Referenced by arraySize(), CppCheck::checkFile(), combineOperators(), combineStrings(), concatenateDoubleSharp(), concatenateNegativeNumberAndAnyPositive(), createLinks(), createLinks2(), createSymbolDatabase(), SymbolDatabase::debugMessage(), deleteInvalidTypedef(), deleteSymbolDatabase(), elseif(), getSourceFilePath(), hasComplicatedSyntaxErrorsInTemplates(), hasEnumsWithTypedef(), PreprocessorMacro::PreprocessorMacro(), SymbolDatabase::printOut(), SymbolDatabase::printVariable(), removeExceptionSpecifications(), removeMacroInVarDecl(), removeMacrosInGlobalScope(), removeRedundantAssignment(), removeRedundantConditions(), removeRedundantFor(), removeRedundantSemicolons(), removeUnnecessaryQualification(), CheckMemoryLeak::reportErr(), reportError(), setVarId(), simplifyAddBraces(), simplifyArrayAccessSyntax(), simplifyAsm(), simplifyAssignmentBlock(), simplifyAssignmentInFunctionCall(), simplifyAttribute(), simplifyBitfields(), simplifyBorland(), simplifyBuiltinExpect(), simplifyCalculations(), simplifyCallingConvention(), simplifyCasts(), simplifyCharAt(), simplifyComma(), simplifyComparisonOrder(), simplifyCompoundAssignment(), simplifyConditionOperator(), simplifyConditions(), simplifyConst(), simplifyConstTernaryOp(), simplifyDebugNew(), simplifyDeclspec(), simplifyDoublePlusAndDoubleMinus(), simplifyEmptyNamespaces(), simplifyEnum(), simplifyErrNoInWhile(), simplifyExternC(), simplifyFileAndLineMacro(), simplifyFlowControl(), simplifyFuncInWhile(), simplifyFunctionParameters(), simplifyFunctionPointers(), simplifyFunctionReturn(), simplifyGoto(), simplifyIfAssign(), simplifyIfNot(), simplifyIfNotNull(), simplifyIfSameInnerCondition(), simplifyInitVar(), simplifyKeyword(), simplifyKnownVariables(), simplifyKnownVariablesSimplify(), simplifyLabelsCaseDefault(), simplifyLogicalOperators(), simplifyMathExpressions(), simplifyMathFunctions(), simplifyMicrosoftMemoryFunctions(), simplifyMicrosoftMFC(), simplifyMicrosoftStringFunctions(), simplifyMulAndParens(), simplifyNamespaceStd(), simplifyNestedStrcat(), simplifyNull(), simplifyOperatorName(), simplifyParameterVoid(), simplifyPlatformTypes(), simplifyPointerToStandardType(), simplifyQtSignalsSlots(), simplifyRealloc(), simplifyRedundantConsecutiveBraces(), simplifyRedundantParentheses(), simplifyReference(), simplifyReturnStrncat(), simplifyRoundCurlyParentheses(), simplifySizeof(), simplifySQL(), simplifyStd(), simplifyStdType(), simplifyStructDecl(), simplifyStructInit(), simplifyTemplates(), simplifyTokenList(), simplifyTypedef(), simplifyUndefinedSizeArray(), simplifyVarDecl(), simplifyVariableMultipleAssign(), simplifyWhile0(), tokenize(), tokenizeCondition(), and validate().

TimerResults.

Definition at line 777 of file tokenize.h.

Referenced by tokenize().


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