32 #include <unordered_map>
33 #include <unordered_set>
54 friend class TestSymbolDatabase;
55 friend class TestSingleExecutorBase;
56 friend class TestThreadExecutorBase;
57 friend class TestProcessExecutorBase;
64 FILE_NOT_FOUND, BAD_XML, UNKNOWN_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE_VALUE,
65 UNSUPPORTED_FORMAT, DUPLICATE_PLATFORM_TYPE, PLATFORM_TYPE_REDEFINED, DUPLICATE_DEFINE
78 Error load(
const char exename[],
const char path[]);
79 Error load(
const tinyxml2::XMLDocument &doc);
102 int getAllocId(
const Token *tok,
int arg)
const;
105 int getDeallocId(
const Token *tok,
int arg)
const;
108 int getReallocId(
const Token *tok,
int arg)
const;
113 return getAllocDealloc(mAlloc, name);
119 return getAllocDealloc(mDealloc, name);
126 const AllocFunc* af = getAllocDealloc(mAlloc, name);
133 const AllocFunc* af = getAllocDealloc(mDealloc, name);
137 static bool isCompliantValidationExpression(
const char* p);
141 return ((
id > 0) && ((
id & 1) == 0));
149 return ((
id > 0) && ((
id & 1) == 1));
155 bool formatstr_function(
const Token* ftok)
const;
156 int formatstr_argno(
const Token* ftok)
const;
157 bool formatstr_scan(
const Token* ftok)
const;
158 bool formatstr_secure(
const Token* ftok)
const;
179 bool isNotLibraryFunction(
const Token *ftok)
const;
180 bool matchArguments(
const Token *ftok,
const std::string &functionName)
const;
183 UseRetValType getUseRetValType(
const Token* ftok)
const;
185 const std::string& returnValue(
const Token *ftok)
const;
186 const std::string& returnValueType(
const Token *ftok)
const;
187 int returnValueContainer(
const Token *ftok)
const;
188 std::vector<MathLib::bigint> unknownReturnValues(
const Token *ftok)
const;
190 bool isnoreturn(
const Token *ftok)
const;
191 bool isnotnoreturn(
const Token *ftok)
const;
193 bool isScopeNoReturn(
const Token *end, std::string *unknownFunc)
const;
234 std::string startPattern, startPattern2,
endPattern, itEndPattern;
236 int type_templateArgNo = -1;
238 int size_templateArgNo = -1;
239 bool arrayLike_indexOp{};
240 bool stdStringLike{};
241 bool stdAssociativeLike{};
242 bool opLessAllowed =
true;
243 bool hasInitializerListConstructor{};
244 bool unstableErase{};
245 bool unstableInsert{};
249 const std::map<std::string, Function>::const_iterator i = functions.find(
function);
250 if (i != functions.end())
251 return i->second.action;
252 return Action::NO_ACTION;
256 const std::map<std::string, Function>::const_iterator i = functions.find(
function);
257 if (i != functions.end())
258 return i->second.yield;
259 return Yield::NO_YIELD;
263 auto i = functions.find(
function);
264 return (i != functions.end()) ? i->second.returnType :
emptyString;
267 static Yield yieldFrom(
const std::string& yieldName);
268 static Action actionFrom(
const std::string& actionName);
273 const Container* detectContainerOrIterator(
const Token* typeStart,
bool*
isIterator =
nullptr,
bool withoutStd =
false)
const;
294 enum class Type { NONE, STRLEN, ARGVALUE, SIZEOF, MUL, VALUE };
322 bool formatstr_scan{};
323 bool formatstr_secure{};
331 bool isUse(
const std::string& functionName)
const;
332 bool isLeakIgnore(
const std::string& functionName)
const;
333 bool isFunctionConst(
const std::string& functionName,
bool pure)
const;
334 bool isFunctionConst(
const Token *ftok)
const;
341 bool isnullargbad(
const Token *ftok,
int argnr)
const;
342 bool isuninitargbad(
const Token *ftok,
int argnr,
int indirect = 0,
bool *hasIndirect=
nullptr)
const;
351 return arg && arg->
strz;
355 bool isFloatArgValid(
const Token *ftok,
int argnr,
double argvalue)
const;
367 bool hasminsize(
const Token *ftok)
const;
369 const std::vector<ArgumentChecks::MinSize> *
argminsizes(
const Token *ftok,
int argnr)
const {
371 return arg ? &arg->
minsizes :
nullptr;
374 ArgumentChecks::Direction getArgDirection(
const Token* ftok,
int argnr)
const;
376 bool markupFile(
const std::string &path)
const;
378 bool processMarkupAfterCode(
const std::string &path)
const;
381 return mMarkupExtensions;
384 bool reportErrors(
const std::string &path)
const;
386 bool ignorefunction(
const std::string &functionName)
const;
388 bool isexecutableblock(
const std::string &file,
const std::string &token)
const;
390 int blockstartoffset(
const std::string &file)
const;
392 const std::string& blockstart(
const std::string &file)
const;
393 const std::string& blockend(
const std::string &file)
const;
395 bool iskeyword(
const std::string &file,
const std::string &keyword)
const;
398 return mExporters.find(prefix) != mExporters.end();
402 const std::map<std::string, ExportedFunctions>::const_iterator it = mExporters.find(prefix);
403 return (it != mExporters.end() && it->second.isPrefix(token));
407 const std::map<std::string, ExportedFunctions>::const_iterator it = mExporters.find(prefix);
408 return (it != mExporters.end() && it->second.isSuffix(token));
411 bool isimporter(
const std::string& file,
const std::string &importer)
const;
413 const Token* getContainerFromYield(
const Token* tok, Container::Yield yield)
const;
414 const Token* getContainerFromAction(
const Token* tok, Container::Action action)
const;
420 return mReflection.find(token) != mReflection.end();
424 const std::map<std::string, int>::const_iterator it = mReflection.find(token);
425 if (it != mReflection.end())
431 return func ==
"main" || mEntrypoints.find(func) != mEntrypoints.end();
442 bool isSmartPointer(
const Token *tok)
const;
443 const SmartPointer* detectSmartPointer(
const Token* tok,
bool withoutStd =
false)
const;
448 enum class Type {
NO, BOOL, CHAR, SHORT, INT, LONG, LONGLONG } stdtype;
451 const std::unordered_map<std::string, PodType>::const_iterator it = mPodTypes.find(name);
452 return (it != mPodTypes.end()) ? &(it->second) :
nullptr;
457 return (mSigned == type.
mSigned &&
459 mLong == type.
mLong &&
463 mType == type.
mType);
466 return !(*
this == type);
479 const std::map<std::string, PlatformType>::const_iterator it = mPlatformTypes.find(name);
480 return (it != mPlatformTypes.end()) ? &(it->second) :
nullptr;
486 const std::map<std::string, Platform>::const_iterator it = mPlatforms.find(platform);
487 if (it != mPlatforms.end()) {
488 const PlatformType *
const type = it->second.platform_type(name);
493 const std::map<std::string, PlatformType>::const_iterator it2 = mPlatformTypes.find(name);
494 return (it2 != mPlatformTypes.end()) ? &(it2->second) :
nullptr;
500 std::string getFunctionName(
const Token *ftok)
const;
508 TypeCheck getTypeCheck(std::string check, std::string typeName)
const;
509 bool hasAnyTypeCheck(
const std::string& typeName)
const;
513 Error
loadFunction(
const tinyxml2::XMLElement *
const node,
const std::string &name, std::set<std::string> &unknown_elements);
518 mPrefixes.insert(std::move(prefix));
521 mSuffixes.insert(std::move(suffix));
524 return (mPrefixes.find(prefix) != mPrefixes.end());
527 return (mSuffixes.find(suffix) != mSuffixes.end());
548 mBlocks.insert(blockName);
553 const std::string&
end()
const {
559 bool isBlock(
const std::string& blockName)
const {
560 return mBlocks.find(blockName) != mBlocks.end();
575 std::unordered_map<std::string, FalseTrueMaybe>
mNoReturn;
597 std::string getFunctionName(
const Token *ftok,
bool &
error)
const;
600 const std::map<std::string, AllocFunc>::const_iterator it = data.find(name);
601 return (it == data.end()) ? nullptr : &it->second;
613 std::unordered_map<nonneg int, const Token*>* lookupVarId =
nullptr);
static bool isIterator(const Variable *var, bool &inconclusiveType)
static bool operator!=(const VariableValue &v, MathLib::bigint i)
void setStart(const char *s)
const std::string & end() const
void setOffset(const int o)
bool isBlock(const std::string &blockName) const
void addBlock(const char *blockName)
const std::string & start() const
std::set< std::string > mBlocks
void setEnd(const char *e)
const std::string & getReturnType(const std::string &function) const
std::vector< RangeItemRecordTypeItem > rangeItemRecordType
std::map< std::string, Function > functions
Action getAction(const std::string &function) const
Yield getYield(const std::string &function) const
Error(ErrorCode e, T &&r)
std::set< std::string > mSuffixes
bool isSuffix(const std::string &suffix) const
std::set< std::string > mPrefixes
void addSuffix(std::string suffix)
bool isPrefix(const std::string &prefix) const
void addPrefix(std::string prefix)
Library definitions handling.
const std::set< std::string > & markupExtensions() const
int allocId(const char name[]) const
get allocation id for function by name (deprecated, use other alloc)
std::map< std::string, AllocFunc > mAlloc
std::set< std::string > mFiles
static bool isresource(const int id)
is allocation type resource?
const AllocFunc * getDeallocFuncInfo(const char name[]) const
get deallocation info for function by name (deprecated, use other alloc)
std::map< std::string, std::vector< MathLib::bigint > > mUnknownReturnValues
const AllocFunc * getAllocFuncInfo(const char name[]) const
get allocation info for function by name (deprecated, use other alloc)
const std::string & validarg(const Token *ftok, int argnr) const
std::map< std::string, std::set< std::string > > mKeywords
bool isexportedsuffix(const std::string &prefix, const std::string &token) const
std::map< std::string, std::set< std::string > > mImporters
std::map< std::pair< std::string, std::string >, TypeCheck > mTypeChecks
static bool ismemory(const int id)
is allocation type memory?
bool isexporter(const std::string &prefix) const
bool isentrypoint(const std::string &func) const
static const AllocFunc * getAllocDealloc(const std::map< std::string, AllocFunc > &data, const std::string &name)
bool isboolargbad(const Token *ftok, int argnr) const
std::map< std::string, ExportedFunctions > mExporters
bool isargformatstr(const Token *ftok, int argnr) const
bool isreflection(const std::string &token) const
static bool isresource(const AllocFunc *const func)
const std::vector< ArgumentChecks::MinSize > * argminsizes(const Token *ftok, int argnr) const
std::unordered_set< std::string > mEntrypoints
std::map< std::string, AllocFunc > mDealloc
static bool ismemory(const AllocFunc *const func)
std::set< std::string > mMarkupExtensions
bool isargstrz(const Token *ftok, int argnr) const
std::set< std::string > defines
TypeCheck
Suppress/check a type.
int deallocId(const char name[]) const
get deallocation id for function by name (deprecated, use other alloc)
std::map< std::string, std::string > mReturnValue
std::map< std::string, int > mReturnValueContainer
const PodType * podtype(const std::string &name) const
std::map< std::string, bool > mProcessAfterCode
std::unordered_map< std::string, CodeBlock > mExecutableBlocks
std::map< std::string, bool > mReportErrors
std::map< std::string, std::string > mReturnValueType
std::map< std::string, PlatformType > mPlatformTypes
const ArgumentChecks::IteratorInfo * getArgIteratorInfo(const Token *ftok, int argnr) const
std::map< std::string, WarnInfo > functionwarn
std::unordered_map< std::string, Container > containers
std::unordered_map< std::string, SmartPointer > smartPointers
std::unordered_map< std::string, PodType > mPodTypes
std::unordered_map< std::string, NonOverlappingData > mNonOverlappingData
std::unordered_map< std::string, FalseTrueMaybe > mNoReturn
std::map< std::string, AllocFunc > mRealloc
bool isexportedprefix(const std::string &prefix, const std::string &token) const
std::unordered_map< std::string, Function > functions
const PlatformType * platform_type(const std::string &name, const std::string &platform) const
std::map< std::string, int > mReflection
int reflectionArgument(const std::string &token) const
std::map< std::string, Platform > mPlatforms
This is just a container for general settings so that we don't need to pass individual values to func...
The token list that the TokenList generates is a linked-list of this class.
Information about a class type.
static const std::string emptyString
static CppcheckLibraryData::Function loadFunction(QXmlStreamReader &xmlReader, const QString &comments)
Severity
enum class for severity.
std::shared_ptr< Token > createTokenFromExpression(const std::string &returnValue, const Settings &settings, bool cpp, std::unordered_map< nonneg int, const Token * > *lookupVarId=nullptr)
CPPCHECKLIB const Library::Container * getLibraryContainer(const Token *tok)
@ error
Programming error.
bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2)
std::vector< MinSize > minsizes
IteratorInfo iteratorInfo
std::map< int, ArgumentChecks > argumentChecks
This is just a container for standards settings.
static const Function * getFunction(const Token *tok)
static Library::Container::Yield getContainerYield(Token *tok, const Settings &settings, Token **parent=nullptr)