Cppcheck
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Friends
Scope Class Reference

#include <symboldatabase.h>

List of all members.

Classes

struct  UsingInfo

Public Types

enum  ScopeType {
  eGlobal, eClass, eStruct, eUnion,
  eNamespace, eFunction, eIf, eElse,
  eElseIf, eFor, eWhile, eDo,
  eSwitch, eUnconditional, eTry, eCatch
}

Public Member Functions

 Scope (const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_)
 Scope (const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_)
bool isClassOrStruct () const
bool isExecutable () const
bool isLocal () const
const FunctionfindFunction (const Token *tok) const
 find a function
ScopefindInNestedList (const std::string &name)
 find if name is in nested list
const ScopefindRecordInNestedList (const std::string &name) const
ScopefindRecordInNestedList (const std::string &name)
const TypefindType (const std::string &name) const
TypefindType (const std::string &name)
ScopefindInNestedListRecursive (const std::string &name)
 find if name is in nested list
void addVariable (const Token *token_, const Token *start_, const Token *end_, AccessControl access_, const Type *type_, const Scope *scope_)
void getVariableList ()
 initialize varlist
const FunctiongetDestructor () const
unsigned int getNestedNonFunctions () const
 get the number of nested scopes that are not functions
bool hasDefaultConstructor () const
AccessControl defaultAccess () const
const TokencheckVariable (const Token *tok, AccessControl varaccess)
 check if statement is variable declaration and add it if it is
const VariablegetVariable (const std::string &varname) const
 get variable from name

Public Attributes

const SymbolDatabasecheck
std::string className
const TokenclassDef
const TokenclassStart
const TokenclassEnd
std::list< FunctionfunctionList
std::list< Variablevarlist
const ScopenestedIn
std::list< Scope * > nestedList
unsigned int numConstructors
unsigned int numCopyConstructors
std::list< UsingInfousingList
ScopeType type
TypedefinedType
std::list< Type * > definedTypes
const ScopefunctionOf
Functionfunction

Private Member Functions

bool isVariableDeclaration (const Token *tok, const Token *&vartok, const Token *&typetok) const
 helper function for getVariableList()

Friends

class TestSymbolDatabase

Detailed Description

Definition at line 499 of file symboldatabase.h.


Member Enumeration Documentation

Enumerator:
eGlobal 
eClass 
eStruct 
eUnion 
eNamespace 
eFunction 
eIf 
eElse 
eElseIf 
eFor 
eWhile 
eDo 
eSwitch 
eUnconditional 
eTry 
eCatch 

Definition at line 509 of file symboldatabase.h.


Constructor & Destructor Documentation

Scope::Scope ( const SymbolDatabase check_,
const Token classDef_,
const Scope nestedIn_ 
)
Scope::Scope ( const SymbolDatabase check_,
const Token classDef_,
const Scope nestedIn_,
ScopeType  type_,
const Token start_ 
)

Definition at line 1982 of file symboldatabase.cpp.


Member Function Documentation

void Scope::addVariable ( const Token token_,
const Token start_,
const Token end_,
AccessControl  access_,
const Type type_,
const Scope scope_ 
) [inline]

Definition at line 578 of file symboldatabase.h.

Referenced by checkVariable(), and SymbolDatabase::SymbolDatabase().

const Token * Scope::checkVariable ( const Token tok,
AccessControl  varaccess 
)

check if statement is variable declaration and add it if it is

Parameters:
tokpointer to start of statement
varaccessaccess control of statement
Returns:
pointer to last token

Definition at line 2187 of file symboldatabase.cpp.

References addVariable(), check, SymbolDatabase::debugMessage(), Token::findmatch(), SymbolDatabase::findVariableType(), Token::isBoolean(), isVariableDeclaration(), Token::link(), Token::linkAt(), Token::Match(), nestedIn, Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), Token::tokAt(), usingList, and Token::varId().

Referenced by getVariableList(), and SymbolDatabase::SymbolDatabase().

Definition at line 2049 of file symboldatabase.cpp.

References eClass, eGlobal, eNamespace, eStruct, eUnion, Global, Local, Namespace, Private, Public, and type.

Referenced by getVariableList().

const Function * Scope::findFunction ( const Token tok) const

find a function

Parameters:
toktoken of function call
Returns:
pointer to function if found or NULL if not found
Todo:
This function only counts the number of arguments in the function call.

It does not take into account function constantness. It does not take into account argument types. This can be difficult because of promotion and conversion operators and casts and because the argument can also be a function call.

Todo:
check argument type for match

Definition at line 2385 of file symboldatabase.cpp.

References Function::argCount(), functionList, Function::minArgCount(), Token::nextArgument(), Token::str(), Token::strAt(), and Token::tokAt().

Referenced by SymbolDatabase::findFunction(), and CheckClass::initializeVarList().

Scope * Scope::findInNestedList ( const std::string &  name)

find if name is in nested list

Parameters:
namename of nested scope

Definition at line 2511 of file symboldatabase.cpp.

References nestedList.

Referenced by SymbolDatabase::addClassFunction().

Scope * Scope::findInNestedListRecursive ( const std::string &  name)

find if name is in nested list

Parameters:
namename of nested scope

Definition at line 2550 of file symboldatabase.cpp.

References findInNestedListRecursive(), and nestedList.

Referenced by findInNestedListRecursive(), and SymbolDatabase::SymbolDatabase().

const Scope * Scope::findRecordInNestedList ( const std::string &  name) const
Scope* Scope::findRecordInNestedList ( const std::string &  name) [inline]

Definition at line 563 of file symboldatabase.h.

const Type * Scope::findType ( const std::string &  name) const

Definition at line 2537 of file symboldatabase.cpp.

References definedTypes.

Referenced by SymbolDatabase::findType().

Type* Scope::findType ( const std::string &  name) [inline]

Definition at line 568 of file symboldatabase.h.

const Function * Scope::getDestructor ( ) const

Definition at line 2569 of file symboldatabase.cpp.

References Function::eDestructor, and functionList.

Referenced by CheckClass::virtualDestructor().

unsigned int Scope::getNestedNonFunctions ( ) const

get the number of nested scopes that are not functions

This returns the number of user defined types (class, struct, union) that are defined in this user defined type or namespace.

Definition at line 2581 of file symboldatabase.cpp.

References eFunction, and nestedList.

const Variable * Scope::getVariable ( const std::string &  varname) const

get variable from name

Parameters:
varnamename of variable
Returns:
pointer to variable

Definition at line 2258 of file symboldatabase.cpp.

References varlist.

Referenced by CheckClass::initializerListOrder(), and SymbolDatabase::SymbolDatabase().

Definition at line 2036 of file symboldatabase.cpp.

References Function::eConstructor, functionList, and numConstructors.

bool Scope::isClassOrStruct ( ) const [inline]
bool Scope::isExecutable ( ) const [inline]
bool Scope::isLocal ( ) const [inline]

Definition at line 542 of file symboldatabase.h.

Referenced by isVariableDeclaration().

bool Scope::isVariableDeclaration ( const Token tok,
const Token *&  vartok,
const Token *&  typetok 
) const [private]

helper function for getVariableList()

Parameters:
tokpointer to token to check
vartokpopulated with pointer to the variable token, if found
typetokpopulated with pointer to the type token, if found
Returns:
true if tok points to a variable declaration, false otherwise

Definition at line 2291 of file symboldatabase.cpp.

References SymbolDatabase::_tokenizer, check, eCatch, eFunction, Token::findClosingBracket(), Tokenizer::isCPP(), isLocal(), Token::link(), Token::Match(), Token::next(), Token::simpleMatch(), skipPointers(), skipScopeIdentifiers(), Token::str(), Token::strAt(), Token::tokAt(), and type.

Referenced by checkVariable().


Friends And Related Function Documentation

friend class TestSymbolDatabase [friend]

Definition at line 501 of file symboldatabase.h.


Member Data Documentation

Definition at line 518 of file symboldatabase.h.

Referenced by SymbolDatabase::addNewFunction(), CheckBufferOverrun::arrayIndexThenCheck(), CheckAutoVariables::autoVariables(), CheckLeakAutoVar::check(), CheckMemoryLeakNoVar::check(), CheckOther::checkAssignBoolToPointer(), CheckOther::checkBitwiseOnBoolean(), CheckBoost::checkBoostForeachModification(), CheckBufferOverrun::checkBufferAllocatedWithStrlen(), CheckOther::checkCastIntToCharAndBack(), CheckOther::checkCharVariable(), CheckOther::checkComparisonOfBoolExpressionWithInt(), CheckOther::checkComparisonOfBoolWithBool(), CheckOther::checkComparisonOfBoolWithInt(), CheckOther::checkComparisonOfFuncReturningBool(), CheckClass::checkConstFunc(), CheckIO::checkCoutCerrMisusage(), CheckIO::checkFileUsage(), CheckBufferOverrun::checkFunctionParameter(), CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(), CheckBufferOverrun::checkGlobalAndLocalVariable(), CheckOther::checkIncompleteArrayFill(), CheckOther::checkIncorrectLogicOperator(), CheckOther::checkIncorrectStringCompare(), CheckOther::checkIncrementBoolean(), CheckOther::checkMathFunctions(), CheckOther::checkMemsetZeroBytes(), CheckOther::checkMisusedScopedObject(), CheckOther::checkModuloAlwaysTrueFalse(), CheckOther::checkNegativeBitwiseShift(), CheckOther::checkPipeParameterSize(), CheckMemoryLeakInFunction::checkReallocUsage(), CheckOther::checkRedundantAssignment(), CheckOther::checkSignOfUnsignedVariable(), CheckOther::checkSizeofForArrayParameter(), CheckOther::checkSizeofForNumericParameter(), CheckOther::checkSizeofForPointerSize(), CheckOther::checkSleepTimeInterval(), CheckBufferOverrun::checkStructVariable(), CheckMemoryLeakStructMember::checkStructVariable(), CheckOther::checkSuspiciousStringCompare(), CheckOther::checkUnsignedDivision(), CheckOther::checkVarFuncNullUB(), CheckOther::checkVariableScope(), CheckIO::checkWrongPrintfScanfArguments(), CheckOther::clarifyCalculation(), CheckOther::clarifyCondition(), CheckOther::clarifyStatement(), Tokenizer::createSymbolDatabase(), CheckExceptionSafety::deallocThrow(), CheckExceptionSafety::destructors(), CheckMemoryLeak::functionArgAlloc(), CheckMemoryLeak::functionReturnType(), CheckClass::hasAllocation(), CheckClass::hasAssignSelf(), CheckClass::initializationListUsage(), CheckClass::initializeVarList(), CheckOther::invalidPointerCast(), CheckIO::invalidScanf(), CheckMemoryLeakStructMember::isMalloc(), CheckStl::iterators(), CheckStl::mismatchingContainers(), CheckClass::noMemset(), CheckNullPointer::nullConstantDereference(), CheckNullPointer::nullPointerDefaultArgument(), CheckNullPointer::nullPointerStructByDeRefAndChec(), CheckObsoleteFunctions::obsoleteFunctions(), CheckMemoryLeakInFunction::parse_noreturn(), Check64BitPortability::pointerassignment(), CheckPostfixOperator::postfixOperator(), CheckClass::privateFunctions(), CheckStl::pushback(), CheckAutoVariables::returnPointerToLocalArray(), CheckAutoVariables::returnReference(), CheckStl::size(), CheckStl::stlBoundaries(), CheckOther::strPlusChar(), SymbolDatabase::SymbolDatabase(), CheckStl::uselessCalls(), variableIsUsedInScope(), and CheckBufferOverrun::writeOutsideBufferSize().

std::string Scope::className

Definition at line 517 of file symboldatabase.h.

Referenced by SymbolDatabase::addNewFunction(), CheckBufferOverrun::arrayIndexThenCheck(), CheckAutoVariables::autoVariables(), CheckMemoryLeakInFunction::call_func(), CheckLeakAutoVar::check(), CheckMemoryLeakInFunction::check(), CheckOther::checkAssignBoolToPointer(), CheckOther::checkBitwiseOnBoolean(), CheckBoost::checkBoostForeachModification(), CheckBufferOverrun::checkBufferAllocatedWithStrlen(), CheckOther::checkCastIntToCharAndBack(), CheckOther::checkCharVariable(), CheckOther::checkComparisonOfBoolExpressionWithInt(), CheckOther::checkComparisonOfBoolWithBool(), CheckOther::checkComparisonOfBoolWithInt(), CheckOther::checkComparisonOfFuncReturningBool(), CheckClass::checkConstFunc(), CheckIO::checkCoutCerrMisusage(), CheckIO::checkFileUsage(), CheckBufferOverrun::checkFunctionParameter(), CheckBufferOverrun::checkGlobalAndLocalVariable(), CheckOther::checkIncompleteArrayFill(), CheckOther::checkIncorrectLogicOperator(), CheckOther::checkIncorrectStringCompare(), CheckOther::checkIncrementBoolean(), CheckOther::checkMathFunctions(), CheckOther::checkMemsetZeroBytes(), CheckOther::checkMisusedScopedObject(), CheckOther::checkModuloAlwaysTrueFalse(), CheckOther::checkNegativeBitwiseShift(), CheckOther::checkPipeParameterSize(), CheckMemoryLeakInFunction::checkReallocUsage(), CheckOther::checkSignOfUnsignedVariable(), CheckOther::checkSizeofForArrayParameter(), CheckOther::checkSizeofForNumericParameter(), CheckOther::checkSizeofForPointerSize(), CheckOther::checkSleepTimeInterval(), CheckBufferOverrun::checkStructVariable(), CheckOther::checkSuspiciousStringCompare(), CheckOther::checkUnsignedDivision(), CheckOther::checkVarFuncNullUB(), CheckIO::checkWrongPrintfScanfArguments(), CheckOther::clarifyCalculation(), CheckOther::clarifyCondition(), CheckOther::clarifyStatement(), Tokenizer::createSymbolDatabase(), CheckExceptionSafety::deallocThrow(), CheckExceptionSafety::destructors(), CheckMemoryLeak::functionArgAlloc(), CheckMemoryLeak::functionReturnType(), getVariableList(), CheckClass::hasAllocation(), CheckClass::hasAssignSelf(), CheckClass::initializationListUsage(), CheckOther::invalidPointerCast(), CheckIO::invalidScanf(), CheckStl::mismatchingContainers(), CheckClass::noMemset(), CheckNullPointer::nullConstantDereference(), CheckNullPointer::nullPointerDefaultArgument(), CheckNullPointer::nullPointerLinkedList(), CheckNullPointer::nullPointerStructByDeRefAndChec(), CheckObsoleteFunctions::obsoleteFunctions(), CheckMemoryLeakInFunction::parse_noreturn(), Check64BitPortability::pointerassignment(), CheckPostfixOperator::postfixOperator(), CheckClass::privateFunctions(), CheckStl::pushback(), CheckAutoVariables::returnPointerToLocalArray(), CheckAutoVariables::returnReference(), CheckStl::size(), CheckStl::stlBoundaries(), CheckOther::strPlusChar(), SymbolDatabase::SymbolDatabase(), CheckStl::uselessCalls(), and CheckBufferOverrun::writeOutsideBufferSize().

Definition at line 528 of file symboldatabase.h.

Referenced by findType(), and SymbolDatabase::SymbolDatabase().

std::list<Scope *> Scope::nestedList
unsigned int Scope::numConstructors

Definition at line 524 of file symboldatabase.h.

Referenced by SymbolDatabase::SymbolDatabase().


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