2013-07-02 07:18:19 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2014-02-15 07:45:39 +01:00
|
|
|
* Copyright (C) 2007-2014 Daniel Marjamäki and Cppcheck team.
|
2013-07-02 07:18:19 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-09-04 20:59:49 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2013-07-08 18:26:18 +02:00
|
|
|
#ifndef libraryH
|
|
|
|
#define libraryH
|
2013-09-04 20:59:49 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2013-07-04 13:09:34 +02:00
|
|
|
#include "config.h"
|
2013-10-27 17:10:43 +01:00
|
|
|
#include "path.h"
|
2013-12-23 10:06:45 +01:00
|
|
|
#include "mathlib.h"
|
2014-04-20 14:59:16 +02:00
|
|
|
#include "token.h"
|
2013-10-27 17:10:43 +01:00
|
|
|
|
2013-07-02 07:18:19 +02:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2013-10-20 14:09:10 +02:00
|
|
|
#include <list>
|
|
|
|
|
2013-12-23 10:06:45 +01:00
|
|
|
class TokenList;
|
2013-12-31 12:30:17 +01:00
|
|
|
namespace tinyxml2 {
|
|
|
|
class XMLDocument;
|
|
|
|
}
|
2013-12-23 10:06:45 +01:00
|
|
|
|
2013-07-02 07:18:19 +02:00
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/**
|
2013-07-08 18:26:18 +02:00
|
|
|
* @brief Library definitions handling
|
2013-07-02 07:18:19 +02:00
|
|
|
*/
|
2013-07-08 18:26:18 +02:00
|
|
|
class CPPCHECKLIB Library {
|
2013-07-02 07:18:19 +02:00
|
|
|
public:
|
2013-07-08 18:26:18 +02:00
|
|
|
Library();
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2014-10-19 07:34:40 +02:00
|
|
|
enum ErrorCode { OK, FILE_NOT_FOUND, BAD_XML, BAD_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE, BAD_ATTRIBUTE_VALUE, UNSUPPORTED_FORMAT, DUPLICATE_PLATFORM_TYPE, PLATFORM_TYPE_REDEFINED };
|
2014-05-26 17:00:41 +02:00
|
|
|
|
|
|
|
class Error {
|
|
|
|
public:
|
2014-06-04 18:55:29 +02:00
|
|
|
Error() : errorcode(OK) , reason("") {}
|
2014-05-26 17:00:41 +02:00
|
|
|
explicit Error(ErrorCode e) : errorcode(e) , reason("") {}
|
|
|
|
Error(ErrorCode e, const std::string &r) : errorcode(e), reason(r) {}
|
|
|
|
ErrorCode errorcode;
|
|
|
|
std::string reason;
|
|
|
|
};
|
|
|
|
|
|
|
|
Error load(const char exename [], const char path []);
|
|
|
|
Error load(const tinyxml2::XMLDocument &doc);
|
|
|
|
|
|
|
|
/** this is primarily meant for unit tests. it only returns true/false */
|
2014-01-09 21:58:56 +01:00
|
|
|
bool loadxmldata(const char xmldata[], std::size_t len);
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2014-04-20 14:59:16 +02:00
|
|
|
/** get allocation id for function by name */
|
2014-11-20 14:20:09 +01:00
|
|
|
int alloc(const char name[]) const {
|
2013-07-02 07:18:19 +02:00
|
|
|
return getid(_alloc, name);
|
|
|
|
}
|
|
|
|
|
2014-04-20 14:59:16 +02:00
|
|
|
/** get allocation id for function */
|
2014-11-20 14:20:09 +01:00
|
|
|
int alloc(const Token *tok) const {
|
2014-04-20 14:59:16 +02:00
|
|
|
return tok->function() ? 0 : getid(_alloc, tok->str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** get deallocation id for function */
|
2014-11-20 14:20:09 +01:00
|
|
|
int dealloc(const Token *tok) const {
|
2014-04-20 14:59:16 +02:00
|
|
|
return tok->function() ? 0 : getid(_dealloc, tok->str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** get deallocation id for function by name */
|
2014-11-20 14:20:09 +01:00
|
|
|
int dealloc(const char name[]) const {
|
2013-07-02 07:18:19 +02:00
|
|
|
return getid(_dealloc, name);
|
|
|
|
}
|
|
|
|
|
2013-07-20 17:12:56 +02:00
|
|
|
/** set allocation id for function */
|
2014-11-20 14:20:09 +01:00
|
|
|
void setalloc(const std::string &functionname, int id) {
|
2013-07-20 17:12:56 +02:00
|
|
|
_alloc[functionname] = id;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void setdealloc(const std::string &functionname, int id) {
|
2013-07-20 17:12:56 +02:00
|
|
|
_dealloc[functionname] = id;
|
|
|
|
}
|
|
|
|
|
2013-08-06 11:11:59 +02:00
|
|
|
/** add noreturn function setting */
|
2014-11-20 14:20:09 +01:00
|
|
|
void setnoreturn(const std::string& funcname, bool noreturn) {
|
2013-08-06 11:11:59 +02:00
|
|
|
_noreturn[funcname] = noreturn;
|
|
|
|
}
|
|
|
|
|
2013-07-02 07:18:19 +02:00
|
|
|
/** is allocation type memory? */
|
2014-11-20 14:20:09 +01:00
|
|
|
static bool ismemory(int id) {
|
2013-07-02 07:18:19 +02:00
|
|
|
return ((id > 0) && ((id & 1) == 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** is allocation type resource? */
|
2014-11-20 14:20:09 +01:00
|
|
|
static bool isresource(int id) {
|
2013-07-02 07:18:19 +02:00
|
|
|
return ((id > 0) && ((id & 1) == 1));
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool formatstr_function(const std::string& funcname) const {
|
2014-02-01 07:40:08 +01:00
|
|
|
return _formatstr.find(funcname) != _formatstr.end();
|
2014-01-12 12:44:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool formatstr_scan(const std::string& funcname) const {
|
2014-01-12 12:44:24 +01:00
|
|
|
return _formatstr.at(funcname).first;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool formatstr_secure(const std::string& funcname) const {
|
2014-01-12 12:44:24 +01:00
|
|
|
return _formatstr.at(funcname).second;
|
|
|
|
}
|
|
|
|
|
2013-07-02 07:18:19 +02:00
|
|
|
std::set<std::string> use;
|
2013-07-20 13:12:24 +02:00
|
|
|
std::set<std::string> leakignore;
|
2014-03-14 06:38:45 +01:00
|
|
|
std::set<std::string> functionconst;
|
|
|
|
std::set<std::string> functionpure;
|
2014-09-27 21:31:04 +02:00
|
|
|
std::set<std::string> useretval;
|
2013-07-14 10:10:11 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isnoreturn(const std::string &name) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
std::map<std::string, bool>::const_iterator it = _noreturn.find(name);
|
2013-07-14 10:10:11 +02:00
|
|
|
return (it != _noreturn.end() && it->second);
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isnotnoreturn(const std::string &name) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
std::map<std::string, bool>::const_iterator it = _noreturn.find(name);
|
2013-07-14 10:10:11 +02:00
|
|
|
return (it != _noreturn.end() && !it->second);
|
|
|
|
}
|
|
|
|
|
2014-06-22 19:13:15 +02:00
|
|
|
bool isScopeNoReturn(const Token *end, std::string *unknownFunc) const;
|
|
|
|
|
2013-12-23 10:06:45 +01:00
|
|
|
class ArgumentChecks {
|
|
|
|
public:
|
2014-01-06 08:02:04 +01:00
|
|
|
ArgumentChecks() :
|
|
|
|
notbool(false),
|
|
|
|
notnull(false),
|
|
|
|
notuninit(false),
|
|
|
|
formatstr(false),
|
2014-11-20 14:20:09 +01:00
|
|
|
strz(false) {
|
2013-07-22 20:21:45 +02:00
|
|
|
}
|
|
|
|
|
2013-12-23 10:06:45 +01:00
|
|
|
bool notbool;
|
2013-12-22 19:10:14 +01:00
|
|
|
bool notnull;
|
|
|
|
bool notuninit;
|
|
|
|
bool formatstr;
|
|
|
|
bool strz;
|
|
|
|
std::string valid;
|
2014-07-05 20:31:43 +02:00
|
|
|
|
|
|
|
class MinSize {
|
|
|
|
public:
|
|
|
|
enum Type {NONE,STRLEN,ARGVALUE,SIZEOF,MUL};
|
|
|
|
MinSize(Type t, int a) : type(t), arg(a), arg2(0) {}
|
|
|
|
Type type;
|
|
|
|
int arg;
|
|
|
|
int arg2;
|
|
|
|
};
|
|
|
|
std::list<MinSize> minsizes;
|
2013-07-14 10:10:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// function name, argument nr => argument data
|
2013-07-16 09:40:31 +02:00
|
|
|
std::map<std::string, std::map<int, ArgumentChecks> > argumentChecks;
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isboolargbad(const std::string &functionName, int argnr) const {
|
2013-12-23 10:06:45 +01:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
|
|
|
return arg && arg->notbool;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isnullargbad(const std::string &functionName, int argnr) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
2013-07-15 21:58:29 +02:00
|
|
|
return arg && arg->notnull;
|
|
|
|
}
|
2013-07-15 18:55:40 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isuninitargbad(const std::string &functionName, int argnr) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
2013-07-15 21:58:29 +02:00
|
|
|
return arg && arg->notuninit;
|
|
|
|
}
|
2013-07-15 18:55:40 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isargformatstr(const std::string &functionName, int argnr) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
2013-07-22 20:21:45 +02:00
|
|
|
return arg && arg->formatstr;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isargstrz(const std::string &functionName, int argnr) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
2013-07-22 20:21:45 +02:00
|
|
|
return arg && arg->strz;
|
|
|
|
}
|
|
|
|
|
2013-12-23 10:06:45 +01:00
|
|
|
bool isargvalid(const std::string &functionName, int argnr, const MathLib::bigint argvalue) const;
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string& validarg(const std::string &functionName, int argnr) const {
|
2013-12-23 10:06:45 +01:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
2014-06-26 11:44:19 +02:00
|
|
|
return arg ? arg->valid : emptyString;
|
2013-12-23 10:06:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool hasminsize(const std::string &functionName) const {
|
2014-07-05 20:31:43 +02:00
|
|
|
std::map<std::string, std::map<int, ArgumentChecks> >::const_iterator it1;
|
|
|
|
it1 = argumentChecks.find(functionName);
|
|
|
|
if (it1 == argumentChecks.end())
|
|
|
|
return false;
|
|
|
|
std::map<int,ArgumentChecks>::const_iterator it2;
|
|
|
|
for (it2 = it1->second.begin(); it2 != it1->second.end(); ++it2) {
|
|
|
|
if (!it2->second.minsizes.empty())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::list<ArgumentChecks::MinSize> *argminsizes(const std::string &functionName, int argnr) const {
|
2014-07-05 20:31:43 +02:00
|
|
|
const ArgumentChecks *arg = getarg(functionName, argnr);
|
|
|
|
return arg ? &arg->minsizes : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool markupFile(const std::string &path) const {
|
2013-10-31 19:50:43 +01:00
|
|
|
return _markupExtensions.find(Path::getFilenameExtensionInLowerCase(path)) != _markupExtensions.end();
|
2013-10-31 19:09:01 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool processMarkupAfterCode(const std::string &path) const {
|
2014-01-02 18:18:24 +01:00
|
|
|
const std::map<std::string, bool>::const_iterator it = _processAfterCode.find(Path::getFilenameExtensionInLowerCase(path));
|
|
|
|
return (it == _processAfterCode.end() || it->second);
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::set<std::string> &markupExtensions() const {
|
2013-10-31 19:09:01 +01:00
|
|
|
return _markupExtensions;
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool reportErrors(const std::string &path) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
const std::map<std::string, bool>::const_iterator it = _reporterrors.find(Path::getFilenameExtensionInLowerCase(path));
|
|
|
|
return (it == _reporterrors.end() || it->second);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool ignorefunction(const std::string &function) const {
|
2014-01-02 17:28:24 +01:00
|
|
|
return (_ignorefunction.find(function) != _ignorefunction.end());
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isexecutableblock(const std::string &file, const std::string &token) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
const std::map<std::string, CodeBlock>::const_iterator it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
return (it != _executableblocks.end() && it->second.isBlock(token));
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
int blockstartoffset(const std::string &file) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
int offset = -1;
|
|
|
|
const std::map<std::string, CodeBlock>::const_iterator map_it
|
|
|
|
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
|
|
|
|
if (map_it != _executableblocks.end()) {
|
|
|
|
offset = map_it->second.offset();
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string& blockstart(const std::string &file) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const std::map<std::string, CodeBlock>::const_iterator map_it
|
|
|
|
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
|
|
|
|
if (map_it != _executableblocks.end()) {
|
2014-04-02 13:56:34 +02:00
|
|
|
return map_it->second.start();
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2014-06-26 11:44:19 +02:00
|
|
|
return emptyString;
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string& blockend(const std::string &file) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const std::map<std::string, CodeBlock>::const_iterator map_it
|
|
|
|
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
|
|
|
|
if (map_it != _executableblocks.end()) {
|
2014-04-02 13:56:34 +02:00
|
|
|
return map_it->second.end();
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2014-06-26 11:44:19 +02:00
|
|
|
return emptyString;
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool iskeyword(const std::string &file, const std::string &keyword) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
const std::map<std::string, std::set<std::string> >::const_iterator it =
|
2013-10-20 14:09:10 +02:00
|
|
|
_keywords.find(Path::getFilenameExtensionInLowerCase(file));
|
2013-12-22 17:03:46 +01:00
|
|
|
return (it != _keywords.end() && it->second.count(keyword));
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isexporter(const std::string &prefix) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
return _exporters.find(prefix) != _exporters.end();
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isexportedprefix(const std::string &prefix, const std::string &token) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const std::map<std::string, ExportedFunctions>::const_iterator it = _exporters.find(prefix);
|
2013-12-22 17:03:46 +01:00
|
|
|
return (it != _exporters.end() && it->second.isPrefix(token));
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isexportedsuffix(const std::string &prefix, const std::string &token) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
const std::map<std::string, ExportedFunctions>::const_iterator it = _exporters.find(prefix);
|
2013-12-22 17:03:46 +01:00
|
|
|
return (it != _exporters.end() && it->second.isSuffix(token));
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isimporter(const std::string& file, const std::string &importer) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
const std::map<std::string, std::set<std::string> >::const_iterator it =
|
2013-10-20 14:09:10 +02:00
|
|
|
_importers.find(Path::getFilenameExtensionInLowerCase(file));
|
2013-12-22 17:03:46 +01:00
|
|
|
return (it != _importers.end() && it->second.count(importer) > 0);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isreflection(const std::string &token) const {
|
2014-03-11 15:57:28 +01:00
|
|
|
const std::map<std::string,int>::const_iterator it
|
|
|
|
= _reflection.find(token);
|
|
|
|
return it != _reflection.end();
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
int reflectionArgument(const std::string &token) const {
|
2013-10-20 14:09:10 +02:00
|
|
|
int argIndex = -1;
|
2014-03-11 15:57:28 +01:00
|
|
|
const std::map<std::string,int>::const_iterator it
|
|
|
|
= _reflection.find(token);
|
2013-10-20 14:09:10 +02:00
|
|
|
if (it != _reflection.end()) {
|
2014-03-11 15:57:28 +01:00
|
|
|
argIndex = it->second;
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
return argIndex;
|
|
|
|
}
|
|
|
|
|
2013-07-15 08:44:00 +02:00
|
|
|
std::set<std::string> returnuninitdata;
|
2014-02-06 09:22:07 +01:00
|
|
|
std::vector<std::string> defines; // to provide some library defines
|
2013-07-15 08:44:00 +02:00
|
|
|
|
2014-06-08 12:09:00 +02:00
|
|
|
struct PodType {
|
|
|
|
unsigned int size;
|
|
|
|
char sign;
|
|
|
|
};
|
|
|
|
const struct PodType *podtype(const std::string &name) const {
|
|
|
|
const std::map<std::string, struct PodType>::const_iterator it = podtypes.find(name);
|
|
|
|
return (it != podtypes.end()) ? &(it->second) : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-19 07:34:40 +02:00
|
|
|
struct PlatformType {
|
|
|
|
PlatformType()
|
|
|
|
: _signed(false)
|
|
|
|
, _unsigned(false)
|
|
|
|
, _long(false)
|
|
|
|
, _pointer(false)
|
|
|
|
, _ptr_ptr(false)
|
2014-11-20 14:20:09 +01:00
|
|
|
, _const_ptr(false) {
|
2014-10-19 07:34:40 +02:00
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
bool operator == (const PlatformType & type) const {
|
2014-10-19 07:34:40 +02:00
|
|
|
return (_type == type._type &&
|
|
|
|
_signed == type._signed &&
|
|
|
|
_unsigned == type._unsigned &&
|
|
|
|
_long == type._long &&
|
|
|
|
_pointer == type._pointer &&
|
|
|
|
_ptr_ptr == type._ptr_ptr &&
|
|
|
|
_const_ptr == type._const_ptr);
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
bool operator != (const PlatformType & type) const {
|
2014-10-19 07:34:40 +02:00
|
|
|
return !(*this == type);
|
|
|
|
}
|
|
|
|
std::string _type;
|
|
|
|
bool _signed;
|
|
|
|
bool _unsigned;
|
|
|
|
bool _long;
|
|
|
|
bool _pointer;
|
|
|
|
bool _ptr_ptr;
|
|
|
|
bool _const_ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Platform {
|
2014-11-20 14:20:09 +01:00
|
|
|
const PlatformType *platform_type(const std::string &name) const {
|
2014-10-19 07:34:40 +02:00
|
|
|
const std::map<std::string, struct PlatformType>::const_iterator it = _platform_types.find(name);
|
|
|
|
return (it != _platform_types.end()) ? &(it->second) : nullptr;
|
|
|
|
}
|
|
|
|
std::map<std::string, PlatformType> _platform_types;
|
|
|
|
};
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
const PlatformType *platform_type(const std::string &name, const std::string & platform) const {
|
2014-10-19 07:34:40 +02:00
|
|
|
const std::map<std::string, Platform>::const_iterator it = platforms.find(platform);
|
|
|
|
|
|
|
|
if (it != platforms.end()) {
|
|
|
|
const PlatformType * const type = it->second.platform_type(name);
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::map<std::string, PlatformType>::const_iterator it2 = platform_types.find(name);
|
|
|
|
|
|
|
|
return (it2 != platform_types.end()) ? &(it2->second) : nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-02 07:18:19 +02:00
|
|
|
private:
|
2013-10-20 14:09:10 +02:00
|
|
|
class ExportedFunctions {
|
|
|
|
public:
|
2014-11-20 14:20:09 +01:00
|
|
|
void addPrefix(const std::string& prefix) {
|
2013-12-22 17:03:46 +01:00
|
|
|
_prefixes.insert(prefix);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
void addSuffix(const std::string& suffix) {
|
2013-12-22 17:03:46 +01:00
|
|
|
_suffixes.insert(suffix);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isPrefix(const std::string& prefix) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
return (_prefixes.find(prefix) != _prefixes.end());
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isSuffix(const std::string& suffix) const {
|
2013-12-22 17:03:46 +01:00
|
|
|
return (_suffixes.find(suffix) != _suffixes.end());
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-22 17:03:46 +01:00
|
|
|
std::set<std::string> _prefixes;
|
|
|
|
std::set<std::string> _suffixes;
|
2013-10-20 14:09:10 +02:00
|
|
|
};
|
|
|
|
class CodeBlock {
|
|
|
|
public:
|
2013-10-23 15:03:31 +02:00
|
|
|
CodeBlock() : _offset(0) {}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void setStart(const std::string& s) {
|
2013-10-20 14:09:10 +02:00
|
|
|
_start = s;
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
void setEnd(const std::string& e) {
|
2013-10-20 14:09:10 +02:00
|
|
|
_end = e;
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
void setOffset(const int o) {
|
2013-10-20 14:09:10 +02:00
|
|
|
_offset = o;
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
void addBlock(const std::string& blockName) {
|
2013-10-23 15:03:31 +02:00
|
|
|
_blocks.insert(blockName);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string& start() const {
|
2013-10-20 14:09:10 +02:00
|
|
|
return _start;
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string& end() const {
|
2013-10-20 14:09:10 +02:00
|
|
|
return _end;
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
int offset() const {
|
2013-10-20 14:09:10 +02:00
|
|
|
return _offset;
|
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
bool isBlock(const std::string& blockName) const {
|
2013-10-23 15:03:31 +02:00
|
|
|
return _blocks.find(blockName) != _blocks.end();
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string _start;
|
|
|
|
std::string _end;
|
|
|
|
int _offset;
|
2013-10-23 15:03:31 +02:00
|
|
|
std::set<std::string> _blocks;
|
2013-10-20 14:09:10 +02:00
|
|
|
};
|
2013-07-02 07:18:19 +02:00
|
|
|
int allocid;
|
2014-10-19 07:34:40 +02:00
|
|
|
std::set<std::string> _files;
|
2013-07-02 07:18:19 +02:00
|
|
|
std::map<std::string, int> _alloc; // allocation functions
|
|
|
|
std::map<std::string, int> _dealloc; // deallocation functions
|
2013-07-14 10:10:11 +02:00
|
|
|
std::map<std::string, bool> _noreturn; // is function noreturn?
|
2014-01-02 17:28:24 +01:00
|
|
|
std::set<std::string> _ignorefunction; // ignore functions/macros from a library (gtk, qt etc)
|
2013-10-20 14:09:10 +02:00
|
|
|
std::map<std::string, bool> _reporterrors;
|
2014-01-02 18:18:24 +01:00
|
|
|
std::map<std::string, bool> _processAfterCode;
|
2013-10-31 19:09:01 +01:00
|
|
|
std::set<std::string> _markupExtensions; // file extensions of markup files
|
2013-12-22 17:03:46 +01:00
|
|
|
std::map<std::string, std::set<std::string> > _keywords; // keywords for code in the library
|
2013-10-20 14:09:10 +02:00
|
|
|
std::map<std::string, CodeBlock> _executableblocks; // keywords for blocks of executable code
|
|
|
|
std::map<std::string, ExportedFunctions> _exporters; // keywords that export variables/functions to libraries (meta-code/macros)
|
2013-12-22 17:03:46 +01:00
|
|
|
std::map<std::string, std::set<std::string> > _importers; // keywords that import variables/functions
|
2014-03-11 15:57:28 +01:00
|
|
|
std::map<std::string,int> _reflection; // invocation of reflection
|
2014-01-12 12:44:24 +01:00
|
|
|
std::map<std::string, std::pair<bool, bool> > _formatstr; // Parameters for format string checking
|
2014-06-08 12:09:00 +02:00
|
|
|
std::map<std::string, struct PodType> podtypes; // pod types
|
2014-10-19 07:34:40 +02:00
|
|
|
std::map<std::string, PlatformType> platform_types; // platform independent typedefs
|
|
|
|
std::map<std::string, Platform> platforms; // platform dependent typedefs
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2014-03-06 06:16:14 +01:00
|
|
|
const ArgumentChecks * getarg(const std::string &functionName, int argnr) const;
|
2013-07-15 18:55:40 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
static int getid(const std::map<std::string,int> &data, const std::string &name) {
|
2013-07-02 07:18:19 +02:00
|
|
|
const std::map<std::string,int>::const_iterator it = data.find(name);
|
|
|
|
return (it == data.end()) ? 0 : it->second;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @}
|
2013-09-04 20:59:49 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2013-07-08 18:26:18 +02:00
|
|
|
#endif // libraryH
|