Cppcheck
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
Function Class Reference

#include <symboldatabase.h>

Public Types

enum  Type {
  eConstructor , eCopyConstructor , eMoveConstructor , eOperatorEqual ,
  eDestructor , eFunction , eLambda
}
 

Public Member Functions

 Function (const Token *tok, const Scope *scope, const Token *tokDef, const Token *tokArgDef)
 
 Function (const Token *tokenDef, const std::string &clangType)
 
const std::string & name () const
 
std::string fullName () const
 
nonneg int argCount () const
 
nonneg int minArgCount () const
 
const VariablegetArgumentVar (nonneg int num) const
 
nonneg int initializedArgCount () const
 
void addArguments (const SymbolDatabase *symbolDatabase, const Scope *scope)
 
bool isImplicitlyVirtual (bool defaultVal=false) const
 check if this function is virtual in the base classes More...
 
std::vector< const Function * > getOverloadedFunctions () const
 
const FunctiongetOverriddenFunction (bool *foundAllBaseClasses=nullptr) const
 get function in base class that is overridden More...
 
bool isLambda () const
 
bool isConstructor () const
 
bool isDestructor () const
 
bool isAttributeConstructor () const
 
bool isAttributeDestructor () const
 
bool isAttributePure () const
 
bool isAttributeConst () const
 
bool isAttributeNoreturn () const
 
bool isAttributeNothrow () const
 
bool isAttributeNodiscard () const
 
bool hasBody () const
 
bool isInline () const
 
bool isConst () const
 
bool hasVirtualSpecifier () const
 
bool isPure () const
 
bool isStatic () const
 
bool isStaticLocal () const
 
bool isExtern () const
 
bool isFriend () const
 
bool isExplicit () const
 
bool isDefault () const
 
bool isDelete () const
 
bool isNoExcept () const
 
bool isThrow () const
 
bool hasOverrideSpecifier () const
 
bool hasFinalSpecifier () const
 
bool isOperator () const
 
bool hasLvalRefQualifier () const
 
bool hasRvalRefQualifier () const
 
bool isVariadic () const
 
bool isVolatile () const
 
bool hasTrailingReturnType () const
 
void hasBody (bool state)
 
bool isInlineKeyword () const
 
bool isEscapeFunction () const
 
void isEscapeFunction (bool state)
 
bool isConstexpr () const
 
void isConstexpr (bool state)
 
bool isSafe (const Settings &settings) const
 
bool argsMatch (const Scope *scope, const Token *first, const Token *second, const std::string &path, nonneg int path_length) const
 
const TokenreturnDefEnd () const
 
const TokenconstructorMemberInitialization () const
 

Static Public Member Functions

static bool returnsConst (const Function *function, bool unknown=false)
 
static bool returnsPointer (const Function *function, bool unknown=false)
 
static bool returnsReference (const Function *function, bool unknown=false, bool includeRValueRef=false)
 
static bool returnsStandardType (const Function *function, bool unknown=false)
 
static bool returnsVoid (const Function *function, bool unknown=false)
 
static std::vector< const Token * > findReturns (const Function *f)
 

Public Attributes

const TokentokenDef {}
 function name token in class definition More...
 
const TokenargDef {}
 function argument start '(' in class definition More...
 
const Tokentoken {}
 function name token in implementation More...
 
const Tokenarg {}
 function argument start '(' More...
 
const TokenretDef {}
 function return type token More...
 
const ::TyperetType {}
 function return type More...
 
const ScopefunctionScope {}
 scope of function body More...
 
const ScopenestedIn {}
 Scope the function is declared in. More...
 
std::list< VariableargumentList
 argument list, must remain list due to clangimport usage! More...
 
nonneg int initArgCount {}
 number of args with default values More...
 
Type type = eFunction
 constructor, destructor, ... More...
 
const TokennoexceptArg {}
 noexcept token More...
 
const TokenthrowArg {}
 throw token More...
 
const TokentemplateDef {}
 points to 'template <' before function More...
 
const TokenfunctionPointerUsage {}
 function pointer usage More...
 
AccessControl access {}
 public/protected/private More...
 

Private Types

enum  {
  fHasBody = (1 << 0) , fIsInline = (1 << 1) , fIsConst = (1 << 2) , fHasVirtualSpecifier = (1 << 3) ,
  fIsPure = (1 << 4) , fIsStatic = (1 << 5) , fIsStaticLocal = (1 << 6) , fIsExtern = (1 << 7) ,
  fIsFriend = (1 << 8) , fIsExplicit = (1 << 9) , fIsDefault = (1 << 10) , fIsDelete = (1 << 11) ,
  fHasOverrideSpecifier = (1 << 12) , fHasFinalSpecifier = (1 << 13) , fIsNoExcept = (1 << 14) , fIsThrow = (1 << 15) ,
  fIsOperator = (1 << 16) , fHasLvalRefQual = (1 << 17) , fHasRvalRefQual = (1 << 18) , fIsVariadic = (1 << 19) ,
  fIsVolatile = (1 << 20) , fHasTrailingReturnType = (1 << 21) , fIsEscapeFunction = (1 << 22) , fIsInlineKeyword = (1 << 23) ,
  fIsConstexpr = (1 << 24)
}
 flags mask used to access specific bit. More...
 

Private Member Functions

bool getFlag (unsigned int flag) const
 Get specified flag state. More...
 
void setFlag (unsigned int flag, bool state)
 Set specified flag state. More...
 
const FunctiongetOverriddenFunctionRecursive (const ::Type *baseType, bool *foundAllBaseClasses) const
 Recursively determine if this function overrides a virtual function in a base class. More...
 
void isInline (bool state)
 
void isConst (bool state)
 
void hasVirtualSpecifier (bool state)
 
void isPure (bool state)
 
void isStatic (bool state)
 
void isStaticLocal (bool state)
 
void isExtern (bool state)
 
void isFriend (bool state)
 
void isExplicit (bool state)
 
void isDefault (bool state)
 
void isDelete (bool state)
 
void isNoExcept (bool state)
 
void isThrow (bool state)
 
void isOperator (bool state)
 
void hasLvalRefQualifier (bool state)
 
void hasRvalRefQualifier (bool state)
 
void isVariadic (bool state)
 
void isVolatile (bool state)
 
void hasTrailingReturnType (bool state)
 
void isInlineKeyword (bool state)
 
const TokensetFlags (const Token *tok1, const Scope *scope)
 

Private Attributes

unsigned int mFlags {}
 

Friends

class SymbolDatabase
 

Detailed Description

Definition at line 698 of file symboldatabase.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

flags mask used to access specific bit.

Enumerator
fHasBody 

has implementation

fIsInline 

implementation in class definition

fIsConst 

is const

fHasVirtualSpecifier 

does declaration contain 'virtual' specifier

fIsPure 

is pure virtual

fIsStatic 

is static

fIsStaticLocal 

is static local

fIsExtern 

is extern

fIsFriend 

is friend

fIsExplicit 

is explicit

fIsDefault 

is default

fIsDelete 

is delete

fHasOverrideSpecifier 

does declaration contain 'override' specifier?

fHasFinalSpecifier 

does declaration contain 'final' specifier?

fIsNoExcept 

is noexcept

fIsThrow 

is throw

fIsOperator 

is operator

fHasLvalRefQual 

has & lvalue ref-qualifier

fHasRvalRefQual 

has && rvalue ref-qualifier

fIsVariadic 

is variadic

fIsVolatile 

is volatile

fHasTrailingReturnType 

has trailing return type

fIsEscapeFunction 

Function throws or exits.

fIsInlineKeyword 

Function has "inline" keyword.

fIsConstexpr 

is constexpr

Definition at line 703 of file symboldatabase.h.

◆ Type

Enumerator
eConstructor 
eCopyConstructor 
eMoveConstructor 
eOperatorEqual 
eDestructor 
eFunction 
eLambda 

Definition at line 750 of file symboldatabase.h.

Constructor & Destructor Documentation

◆ Function() [1/2]

Function::Function ( const Token tok,
const Scope scope,
const Token tokDef,
const Token tokArgDef 
)

◆ Function() [2/2]

Function::Function ( const Token tokenDef,
const std::string &  clangType 
)

Member Function Documentation

◆ addArguments()

void Function::addArguments ( const SymbolDatabase symbolDatabase,
const Scope scope 
)

◆ argCount()

nonneg int Function::argCount ( ) const
inline

◆ argsMatch()

bool Function::argsMatch ( const Scope scope,
const Token first,
const Token second,
const std::string &  path,
nonneg int  path_length 
) const

◆ constructorMemberInitialization()

const Token * Function::constructorMemberInitialization ( ) const
Returns
token to ":" if the function is a constructor and it contains member initialization otherwise a nullptr is returned

Definition at line 3173 of file symboldatabase.cpp.

References arg, isConstructor(), Token::link(), and Token::simpleMatch().

Referenced by CheckOther::checkAccessOfMovedVariable(), CheckClass::checkUnsafeClassRefMember(), CheckClass::constructors(), CheckClass::initializationListUsage(), valueFlowAfterMove(), and valueFlowLifetimeUserConstructor().

◆ findReturns()

std::vector< const Token * > Function::findReturns ( const Function f)
static

◆ fullName()

std::string Function::fullName ( ) const

Definition at line 2678 of file symboldatabase.cpp.

References argumentList, name(), nestedIn, and Scope::nestedIn.

◆ getArgumentVar()

const Variable * Function::getArgumentVar ( nonneg int  num) const

◆ getFlag()

bool Function::getFlag ( unsigned int  flag) const
inlineprivate

Get specified flag state.

Parameters
flagflag to get state of
Returns
true if flag set or false in flag not set

Definition at line 736 of file symboldatabase.h.

◆ getOverloadedFunctions()

std::vector< const Function * > Function::getOverloadedFunctions ( ) const

◆ getOverriddenFunction()

const Function * Function::getOverriddenFunction ( bool *  foundAllBaseClasses = nullptr) const

◆ getOverriddenFunctionRecursive()

const Function * Function::getOverriddenFunctionRecursive ( const ::Type baseType,
bool *  foundAllBaseClasses 
) const
private

◆ hasBody() [1/2]

bool Function::hasBody ( ) const
inline

◆ hasBody() [2/2]

void Function::hasBody ( bool  state)
inline

Definition at line 882 of file symboldatabase.h.

◆ hasFinalSpecifier()

bool Function::hasFinalSpecifier ( ) const
inline

◆ hasLvalRefQualifier() [1/2]

bool Function::hasLvalRefQualifier ( ) const
inline

Definition at line 867 of file symboldatabase.h.

Referenced by Function(), and getOverriddenFunctionRecursive().

◆ hasLvalRefQualifier() [2/2]

void Function::hasLvalRefQualifier ( bool  state)
inlineprivate

Definition at line 993 of file symboldatabase.h.

◆ hasOverrideSpecifier()

bool Function::hasOverrideSpecifier ( ) const
inline

◆ hasRvalRefQualifier() [1/2]

bool Function::hasRvalRefQualifier ( ) const
inline

Definition at line 870 of file symboldatabase.h.

Referenced by Function(), and getOverriddenFunctionRecursive().

◆ hasRvalRefQualifier() [2/2]

void Function::hasRvalRefQualifier ( bool  state)
inlineprivate

Definition at line 996 of file symboldatabase.h.

◆ hasTrailingReturnType() [1/2]

bool Function::hasTrailingReturnType ( ) const
inline

Definition at line 879 of file symboldatabase.h.

Referenced by Function().

◆ hasTrailingReturnType() [2/2]

void Function::hasTrailingReturnType ( bool  state)
inlineprivate

Definition at line 1005 of file symboldatabase.h.

◆ hasVirtualSpecifier() [1/2]

bool Function::hasVirtualSpecifier ( ) const
inline

◆ hasVirtualSpecifier() [2/2]

void Function::hasVirtualSpecifier ( bool  state)
inlineprivate

Definition at line 957 of file symboldatabase.h.

◆ initializedArgCount()

nonneg int Function::initializedArgCount ( ) const
inline

◆ isAttributeConst()

bool Function::isAttributeConst ( ) const
inline

Definition at line 803 of file symboldatabase.h.

◆ isAttributeConstructor()

bool Function::isAttributeConstructor ( ) const
inline

Definition at line 794 of file symboldatabase.h.

Referenced by CheckUnusedFunctions::parseTokens().

◆ isAttributeDestructor()

bool Function::isAttributeDestructor ( ) const
inline

Definition at line 797 of file symboldatabase.h.

Referenced by CheckUnusedFunctions::parseTokens().

◆ isAttributeNodiscard()

bool Function::isAttributeNodiscard ( ) const
inline

Definition at line 812 of file symboldatabase.h.

◆ isAttributeNoreturn()

bool Function::isAttributeNoreturn ( ) const
inline

Definition at line 806 of file symboldatabase.h.

◆ isAttributeNothrow()

bool Function::isAttributeNothrow ( ) const
inline

Definition at line 809 of file symboldatabase.h.

Referenced by CheckMemoryLeakNoVar::checkForUnsafeArgAlloc().

◆ isAttributePure()

bool Function::isAttributePure ( ) const
inline

Definition at line 800 of file symboldatabase.h.

◆ isConst() [1/2]

bool Function::isConst ( ) const
inline

◆ isConst() [2/2]

void Function::isConst ( bool  state)
inlineprivate

Definition at line 954 of file symboldatabase.h.

◆ isConstexpr() [1/2]

bool Function::isConstexpr ( ) const
inline

Definition at line 896 of file symboldatabase.h.

Referenced by setFlags().

◆ isConstexpr() [2/2]

void Function::isConstexpr ( bool  state)
inline

Definition at line 899 of file symboldatabase.h.

◆ isConstructor()

bool Function::isConstructor ( ) const
inline

◆ isDefault() [1/2]

bool Function::isDefault ( ) const
inline

◆ isDefault() [2/2]

void Function::isDefault ( bool  state)
inlineprivate

Definition at line 978 of file symboldatabase.h.

◆ isDelete() [1/2]

bool Function::isDelete ( ) const
inline

◆ isDelete() [2/2]

void Function::isDelete ( bool  state)
inlineprivate

Definition at line 981 of file symboldatabase.h.

◆ isDestructor()

bool Function::isDestructor ( ) const
inline

◆ isEscapeFunction() [1/2]

bool Function::isEscapeFunction ( ) const
inline

◆ isEscapeFunction() [2/2]

void Function::isEscapeFunction ( bool  state)
inline

Definition at line 892 of file symboldatabase.h.

◆ isExplicit() [1/2]

bool Function::isExplicit ( ) const
inline

Definition at line 843 of file symboldatabase.h.

Referenced by CheckClass::checkExplicitConstructors(), and Function().

◆ isExplicit() [2/2]

void Function::isExplicit ( bool  state)
inlineprivate

Definition at line 975 of file symboldatabase.h.

◆ isExtern() [1/2]

bool Function::isExtern ( ) const
inline

Definition at line 837 of file symboldatabase.h.

Referenced by CheckUnusedFunctions::parseTokens(), and setFlags().

◆ isExtern() [2/2]

void Function::isExtern ( bool  state)
inlineprivate

Definition at line 969 of file symboldatabase.h.

◆ isFriend() [1/2]

bool Function::isFriend ( ) const
inline

Definition at line 840 of file symboldatabase.h.

Referenced by CheckClass::checkConst(), and setFlags().

◆ isFriend() [2/2]

void Function::isFriend ( bool  state)
inlineprivate

Definition at line 972 of file symboldatabase.h.

◆ isImplicitlyVirtual()

bool Function::isImplicitlyVirtual ( bool  defaultVal = false) const

◆ isInline() [1/2]

bool Function::isInline ( ) const
inline

Definition at line 819 of file symboldatabase.h.

Referenced by CheckClass::checkConst(), and Function().

◆ isInline() [2/2]

void Function::isInline ( bool  state)
inlineprivate

Definition at line 951 of file symboldatabase.h.

◆ isInlineKeyword() [1/2]

bool Function::isInlineKeyword ( ) const
inline

Definition at line 885 of file symboldatabase.h.

Referenced by setFlags().

◆ isInlineKeyword() [2/2]

void Function::isInlineKeyword ( bool  state)
inlineprivate

Definition at line 1008 of file symboldatabase.h.

◆ isLambda()

bool Function::isLambda ( ) const
inline

Definition at line 781 of file symboldatabase.h.

Referenced by Token::function(), and Function().

◆ isNoExcept() [1/2]

bool Function::isNoExcept ( ) const
inline

Definition at line 852 of file symboldatabase.h.

Referenced by Function(), and functionThrowsRecursive().

◆ isNoExcept() [2/2]

void Function::isNoExcept ( bool  state)
inlineprivate

Definition at line 984 of file symboldatabase.h.

◆ isOperator() [1/2]

bool Function::isOperator ( ) const
inline

◆ isOperator() [2/2]

void Function::isOperator ( bool  state)
inlineprivate

Definition at line 990 of file symboldatabase.h.

◆ isPure() [1/2]

bool Function::isPure ( ) const
inline

◆ isPure() [2/2]

void Function::isPure ( bool  state)
inlineprivate

Definition at line 960 of file symboldatabase.h.

◆ isSafe()

bool Function::isSafe ( const Settings settings) const

◆ isStatic() [1/2]

bool Function::isStatic ( ) const
inline

◆ isStatic() [2/2]

void Function::isStatic ( bool  state)
inlineprivate

Definition at line 963 of file symboldatabase.h.

◆ isStaticLocal() [1/2]

bool Function::isStaticLocal ( ) const
inline

Definition at line 834 of file symboldatabase.h.

Referenced by setFlags().

◆ isStaticLocal() [2/2]

void Function::isStaticLocal ( bool  state)
inlineprivate

Definition at line 966 of file symboldatabase.h.

◆ isThrow() [1/2]

bool Function::isThrow ( ) const
inline

◆ isThrow() [2/2]

void Function::isThrow ( bool  state)
inlineprivate

Definition at line 987 of file symboldatabase.h.

◆ isVariadic() [1/2]

bool Function::isVariadic ( ) const
inline

◆ isVariadic() [2/2]

void Function::isVariadic ( bool  state)
inlineprivate

Definition at line 999 of file symboldatabase.h.

◆ isVolatile() [1/2]

bool Function::isVolatile ( ) const
inline

◆ isVolatile() [2/2]

void Function::isVolatile ( bool  state)
inlineprivate

Definition at line 1002 of file symboldatabase.h.

◆ minArgCount()

nonneg int Function::minArgCount ( ) const
inline

◆ name()

const std::string& Function::name ( ) const
inline

◆ returnDefEnd()

const Token* Function::returnDefEnd ( ) const
inline

Definition at line 933 of file symboldatabase.h.

References Token::findmatch().

◆ returnsConst()

bool Function::returnsConst ( const Function function,
bool  unknown = false 
)
static

◆ returnsPointer()

bool Function::returnsPointer ( const Function function,
bool  unknown = false 
)
static

◆ returnsReference()

bool Function::returnsReference ( const Function function,
bool  unknown = false,
bool  includeRValueRef = false 
)
static

◆ returnsStandardType()

bool Function::returnsStandardType ( const Function function,
bool  unknown = false 
)
static

◆ returnsVoid()

bool Function::returnsVoid ( const Function function,
bool  unknown = false 
)
static

◆ setFlag()

void Function::setFlag ( unsigned int  flag,
bool  state 
)
inlineprivate

Set specified flag state.

Parameters
flagflag to set state
statenew state of flag

Definition at line 745 of file symboldatabase.h.

Referenced by Function().

◆ setFlags()

const Token * Function::setFlags ( const Token tok1,
const Scope scope 
)
private

Friends And Related Function Documentation

◆ SymbolDatabase

friend class SymbolDatabase
friend

Definition at line 700 of file symboldatabase.h.

Member Data Documentation

◆ access

AccessControl Function::access {}

◆ arg

const Token* Function::arg {}

◆ argDef

const Token* Function::argDef {}

◆ argumentList

std::list<Variable> Function::argumentList

◆ functionPointerUsage

const Token* Function::functionPointerUsage {}

function pointer usage

Definition at line 918 of file symboldatabase.h.

Referenced by CheckOther::passedByValueError().

◆ functionScope

const Scope* Function::functionScope {}

◆ initArgCount

nonneg int Function::initArgCount {}

number of args with default values

Definition at line 913 of file symboldatabase.h.

Referenced by addArguments().

◆ mFlags

unsigned int Function::mFlags {}
private

Definition at line 949 of file symboldatabase.h.

◆ nestedIn

const Scope* Function::nestedIn {}

◆ noexceptArg

const Token* Function::noexceptArg {}

noexcept token

Definition at line 915 of file symboldatabase.h.

Referenced by functionThrowsRecursive().

◆ retDef

const Token* Function::retDef {}

◆ retType

const ::Type* Function::retType {}

function return type

Definition at line 909 of file symboldatabase.h.

Referenced by CheckClass::checkConstFunc(), isUniqueExpression(), and Token::typeOf().

◆ templateDef

const Token* Function::templateDef {}

points to 'template <' before function

Definition at line 917 of file symboldatabase.h.

Referenced by CheckClass::checkExplicitConstructors(), ValueType::matchParameter(), and setFlags().

◆ throwArg

const Token* Function::throwArg {}

◆ token

const Token* Function::token {}

◆ tokenDef

const Token* Function::tokenDef {}

◆ type

Type Function::type = eFunction

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