2013-07-02 07:18:19 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2018-03-31 20:59:09 +02:00
|
|
|
* Copyright (C) 2007-2018 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-07-08 18:26:18 +02:00
|
|
|
#include "library.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
|
|
|
|
#include "astutils.h"
|
|
|
|
#include "mathlib.h"
|
2013-07-20 17:12:56 +02:00
|
|
|
#include "path.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
#include "symboldatabase.h"
|
2013-07-07 11:33:25 +02:00
|
|
|
#include "tinyxml2.h"
|
2013-12-23 10:06:45 +01:00
|
|
|
#include "token.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
#include "tokenlist.h"
|
2017-04-01 18:14:18 +02:00
|
|
|
#include "utils.h"
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2017-05-27 04:33:47 +02:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <list>
|
2013-07-20 17:12:56 +02:00
|
|
|
|
2015-11-15 15:24:10 +01:00
|
|
|
static std::vector<std::string> getnames(const char *names)
|
|
|
|
{
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
while (const char *p = std::strchr(names,',')) {
|
2018-04-11 09:44:35 +02:00
|
|
|
ret.emplace_back(names, p-names);
|
2015-11-15 15:24:10 +01:00
|
|
|
names = p + 1;
|
|
|
|
}
|
|
|
|
ret.push_back(names);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-08 18:26:18 +02:00
|
|
|
Library::Library() : allocid(0)
|
2013-07-02 07:18:19 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-26 17:00:41 +02:00
|
|
|
Library::Error Library::load(const char exename[], const char path[])
|
2013-07-02 07:18:19 +02:00
|
|
|
{
|
2014-02-15 08:41:17 +01:00
|
|
|
if (std::strchr(path,',') != nullptr) {
|
2013-07-20 10:21:05 +02:00
|
|
|
std::string p(path);
|
2015-08-27 10:19:51 +02:00
|
|
|
for (;;) {
|
|
|
|
const std::string::size_type pos = p.find(',');
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
break;
|
2014-05-26 17:00:41 +02:00
|
|
|
const Error &e = load(exename, p.substr(0,pos).c_str());
|
2014-06-04 19:18:27 +02:00
|
|
|
if (e.errorcode != OK)
|
2014-05-26 17:00:41 +02:00
|
|
|
return e;
|
2013-07-20 10:21:05 +02:00
|
|
|
p = p.substr(pos+1);
|
|
|
|
}
|
|
|
|
if (!p.empty())
|
2014-05-26 17:00:41 +02:00
|
|
|
return load(exename, p.c_str());
|
|
|
|
return Error();
|
2013-07-20 10:21:05 +02:00
|
|
|
}
|
|
|
|
|
2014-10-19 07:34:40 +02:00
|
|
|
std::string absolute_path;
|
2013-07-20 17:12:56 +02:00
|
|
|
// open file..
|
2013-10-27 17:32:38 +01:00
|
|
|
tinyxml2::XMLDocument doc;
|
2014-03-01 14:09:03 +01:00
|
|
|
tinyxml2::XMLError error = doc.LoadFile(path);
|
2013-10-27 17:32:38 +01:00
|
|
|
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
|
2013-07-20 17:12:56 +02:00
|
|
|
// failed to open file.. is there no extension?
|
|
|
|
std::string fullfilename(path);
|
2017-06-02 20:38:00 +02:00
|
|
|
if (Path::getFilenameExtension(fullfilename).empty()) {
|
2013-07-20 17:12:56 +02:00
|
|
|
fullfilename += ".cfg";
|
2014-03-01 14:09:03 +01:00
|
|
|
error = doc.LoadFile(fullfilename.c_str());
|
2014-10-19 07:34:40 +02:00
|
|
|
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
|
2015-12-03 14:19:17 +01:00
|
|
|
absolute_path = Path::getAbsoluteFilePath(fullfilename);
|
2013-07-20 10:21:05 +02:00
|
|
|
}
|
2013-07-20 17:12:56 +02:00
|
|
|
|
2016-08-01 12:58:33 +02:00
|
|
|
std::list<std::string> cfgfolders;
|
2013-12-26 18:41:51 +01:00
|
|
|
#ifdef CFGDIR
|
2016-08-01 12:58:33 +02:00
|
|
|
cfgfolders.push_back(CFGDIR);
|
2013-12-26 18:41:51 +01:00
|
|
|
#endif
|
2016-08-01 12:58:33 +02:00
|
|
|
if (exename) {
|
|
|
|
const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(exename)));
|
|
|
|
cfgfolders.push_back(exepath + "cfg");
|
|
|
|
cfgfolders.push_back(exepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty()) {
|
|
|
|
const std::string cfgfolder(cfgfolders.front());
|
|
|
|
cfgfolders.pop_front();
|
2017-04-01 18:14:18 +02:00
|
|
|
const char *sep = (!cfgfolder.empty() && endsWith(cfgfolder,'/') ? "" : "/");
|
2013-12-26 18:41:51 +01:00
|
|
|
const std::string filename(cfgfolder + sep + fullfilename);
|
2014-03-01 14:09:03 +01:00
|
|
|
error = doc.LoadFile(filename.c_str());
|
2014-10-19 07:34:40 +02:00
|
|
|
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
|
2015-12-03 14:19:17 +01:00
|
|
|
absolute_path = Path::getAbsoluteFilePath(filename);
|
2013-07-20 17:12:56 +02:00
|
|
|
}
|
2014-10-19 07:34:40 +02:00
|
|
|
} else
|
|
|
|
absolute_path = Path::getAbsoluteFilePath(path);
|
|
|
|
|
2016-07-09 11:56:07 +02:00
|
|
|
if (error == tinyxml2::XML_SUCCESS) {
|
2014-10-19 07:34:40 +02:00
|
|
|
if (_files.find(absolute_path) == _files.end()) {
|
|
|
|
Error err = load(doc);
|
|
|
|
if (err.errorcode == OK)
|
|
|
|
_files.insert(absolute_path);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error(OK); // ignore duplicates
|
2013-07-20 10:21:05 +02:00
|
|
|
}
|
|
|
|
|
2014-10-19 07:34:40 +02:00
|
|
|
return Error(error == tinyxml2::XML_ERROR_FILE_NOT_FOUND ? FILE_NOT_FOUND : BAD_XML);
|
2013-10-27 17:10:43 +01:00
|
|
|
}
|
|
|
|
|
2014-01-09 21:58:56 +01:00
|
|
|
bool Library::loadxmldata(const char xmldata[], std::size_t len)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
2016-07-09 11:56:07 +02:00
|
|
|
return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (load(doc).errorcode == OK);
|
2014-01-09 21:58:56 +01:00
|
|
|
}
|
|
|
|
|
2014-05-26 17:00:41 +02:00
|
|
|
Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
2013-10-27 17:10:43 +01:00
|
|
|
{
|
2013-07-02 07:18:19 +02:00
|
|
|
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
|
2013-10-31 19:49:36 +01:00
|
|
|
|
2014-02-15 08:41:17 +01:00
|
|
|
if (rootnode == nullptr)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(BAD_XML);
|
2013-10-31 19:49:36 +01:00
|
|
|
|
|
|
|
if (strcmp(rootnode->Name(),"def") != 0)
|
2015-01-10 22:18:57 +01:00
|
|
|
return Error(UNSUPPORTED_FORMAT, rootnode->Name());
|
2013-07-02 07:18:19 +02:00
|
|
|
|
2014-09-29 16:25:35 +02:00
|
|
|
const char* format_string = rootnode->Attribute("format");
|
2015-08-11 13:56:32 +02:00
|
|
|
int format = 1; // Assume format version 1 if nothing else is specified (very old .cfg files had no 'format' attribute)
|
2014-09-29 16:25:35 +02:00
|
|
|
if (format_string)
|
|
|
|
format = atoi(format_string);
|
|
|
|
|
2015-08-11 13:56:32 +02:00
|
|
|
if (format > 2 || format <= 0)
|
2014-09-29 16:25:35 +02:00
|
|
|
return Error(UNSUPPORTED_FORMAT);
|
|
|
|
|
2015-01-10 22:18:57 +01:00
|
|
|
std::set<std::string> unknown_elements;
|
|
|
|
|
2013-07-02 07:18:19 +02:00
|
|
|
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
|
2014-12-12 22:16:20 +01:00
|
|
|
const std::string nodename = node->Name();
|
2014-09-10 17:03:31 +02:00
|
|
|
if (nodename == "memory" || nodename == "resource") {
|
2014-04-19 13:15:06 +02:00
|
|
|
// get allocationId to use..
|
|
|
|
int allocationId = 0;
|
|
|
|
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
|
|
|
|
if (strcmp(memorynode->Name(),"dealloc")==0) {
|
2016-05-22 17:18:50 +02:00
|
|
|
const std::map<std::string, AllocFunc>::const_iterator it = _dealloc.find(memorynode->GetText());
|
2014-04-19 13:15:06 +02:00
|
|
|
if (it != _dealloc.end()) {
|
2016-05-22 17:18:50 +02:00
|
|
|
allocationId = it->second.groupId;
|
2014-04-19 13:15:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allocationId == 0) {
|
2014-12-12 22:16:20 +01:00
|
|
|
if (nodename == "memory")
|
2014-04-19 13:15:06 +02:00
|
|
|
while (!ismemory(++allocid));
|
|
|
|
else
|
|
|
|
while (!isresource(++allocid));
|
|
|
|
allocationId = allocid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add alloc/dealloc/use functions..
|
2013-07-02 07:18:19 +02:00
|
|
|
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
|
2014-12-12 22:16:20 +01:00
|
|
|
const std::string memorynodename = memorynode->Name();
|
|
|
|
if (memorynodename == "alloc") {
|
2016-05-22 17:18:50 +02:00
|
|
|
AllocFunc temp;
|
|
|
|
temp.groupId = allocationId;
|
|
|
|
|
2016-07-09 11:56:07 +02:00
|
|
|
if (memorynode->Attribute("init", "false"))
|
2013-07-15 08:44:00 +02:00
|
|
|
returnuninitdata.insert(memorynode->GetText());
|
2016-07-09 11:56:07 +02:00
|
|
|
|
2016-05-22 17:18:50 +02:00
|
|
|
const char *arg = memorynode->Attribute("arg");
|
|
|
|
if (arg)
|
|
|
|
temp.arg = atoi(arg);
|
|
|
|
else
|
|
|
|
temp.arg = -1;
|
|
|
|
_alloc[memorynode->GetText()] = temp;
|
|
|
|
} else if (memorynodename == "dealloc") {
|
|
|
|
AllocFunc temp;
|
|
|
|
temp.groupId = allocationId;
|
|
|
|
const char *arg = memorynode->Attribute("arg");
|
|
|
|
if (arg)
|
|
|
|
temp.arg = atoi(arg);
|
|
|
|
else
|
|
|
|
temp.arg = 1;
|
|
|
|
_dealloc[memorynode->GetText()] = temp;
|
|
|
|
} else if (memorynodename == "use")
|
2016-12-06 12:31:16 +01:00
|
|
|
functions[memorynode->GetText()].use = true;
|
2013-07-02 07:18:19 +02:00
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(memorynodename);
|
2013-07-02 07:18:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (nodename == "define") {
|
2014-02-06 09:22:07 +01:00
|
|
|
const char *name = node->Attribute("name");
|
2014-02-15 08:41:17 +01:00
|
|
|
if (name == nullptr)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(MISSING_ATTRIBUTE, "name");
|
2014-02-06 09:22:07 +01:00
|
|
|
const char *value = node->Attribute("value");
|
2014-02-15 08:41:17 +01:00
|
|
|
if (value == nullptr)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(MISSING_ATTRIBUTE, "value");
|
2014-02-06 09:22:07 +01:00
|
|
|
defines.push_back(std::string("#define ") +
|
|
|
|
name +
|
|
|
|
" " +
|
|
|
|
value +
|
|
|
|
"\n");
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (nodename == "function") {
|
2015-11-15 15:24:10 +01:00
|
|
|
const char *name = node->Attribute("name");
|
|
|
|
if (name == nullptr)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(MISSING_ATTRIBUTE, "name");
|
2015-11-15 15:24:10 +01:00
|
|
|
const std::vector<std::string> names(getnames(name));
|
|
|
|
for (unsigned int i = 0U; i < names.size(); ++i) {
|
|
|
|
const Error &err = loadFunction(node, names[i], unknown_elements);
|
2015-08-09 21:27:57 +02:00
|
|
|
if (err.errorcode != ErrorCode::OK)
|
|
|
|
return err;
|
2013-07-14 10:10:11 +02:00
|
|
|
}
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (nodename == "reflection") {
|
2014-03-11 15:57:28 +01:00
|
|
|
for (const tinyxml2::XMLElement *reflectionnode = node->FirstChildElement(); reflectionnode; reflectionnode = reflectionnode->NextSiblingElement()) {
|
2015-01-10 22:18:57 +01:00
|
|
|
if (strcmp(reflectionnode->Name(), "call") != 0) {
|
|
|
|
unknown_elements.insert(reflectionnode->Name());
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-11 15:57:28 +01:00
|
|
|
|
|
|
|
const char * const argString = reflectionnode->Attribute("arg");
|
|
|
|
if (!argString)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(MISSING_ATTRIBUTE, "arg");
|
2014-03-11 15:57:28 +01:00
|
|
|
|
|
|
|
_reflection[reflectionnode->GetText()] = atoi(argString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (nodename == "markup") {
|
2013-12-22 18:44:31 +01:00
|
|
|
const char * const extension = node->Attribute("ext");
|
|
|
|
if (!extension)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(MISSING_ATTRIBUTE, "ext");
|
2013-12-22 18:44:31 +01:00
|
|
|
_markupExtensions.insert(extension);
|
2013-10-20 14:09:10 +02:00
|
|
|
|
2016-07-09 11:56:07 +02:00
|
|
|
_reporterrors[extension] = (node->Attribute("reporterrors", "true") != nullptr);
|
|
|
|
_processAfterCode[extension] = (node->Attribute("aftercode", "true") != nullptr);
|
2013-12-22 18:44:31 +01:00
|
|
|
|
|
|
|
for (const tinyxml2::XMLElement *markupnode = node->FirstChildElement(); markupnode; markupnode = markupnode->NextSiblingElement()) {
|
2014-12-12 22:16:20 +01:00
|
|
|
const std::string markupnodename = markupnode->Name();
|
2014-09-10 17:03:31 +02:00
|
|
|
if (markupnodename == "keywords") {
|
2013-12-22 18:44:31 +01:00
|
|
|
for (const tinyxml2::XMLElement *librarynode = markupnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
|
2014-08-12 09:14:28 +02:00
|
|
|
if (strcmp(librarynode->Name(), "keyword") == 0) {
|
|
|
|
const char* nodeName = librarynode->Attribute("name");
|
|
|
|
if (nodeName == nullptr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "name");
|
|
|
|
_keywords[extension].insert(nodeName);
|
|
|
|
} else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(librarynode->Name());
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2013-12-22 18:44:31 +01:00
|
|
|
}
|
2013-10-20 14:09:10 +02:00
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (markupnodename == "exported") {
|
2014-01-02 18:18:24 +01:00
|
|
|
for (const tinyxml2::XMLElement *exporter = markupnode->FirstChildElement(); exporter; exporter = exporter->NextSiblingElement()) {
|
2015-01-10 22:18:57 +01:00
|
|
|
if (strcmp(exporter->Name(), "exporter") != 0) {
|
|
|
|
unknown_elements.insert(exporter->Name());
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-22 18:44:31 +01:00
|
|
|
|
|
|
|
const char * const prefix = exporter->Attribute("prefix");
|
|
|
|
if (!prefix)
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(MISSING_ATTRIBUTE, "prefix");
|
2013-12-22 18:44:31 +01:00
|
|
|
|
|
|
|
for (const tinyxml2::XMLElement *e = exporter->FirstChildElement(); e; e = e->NextSiblingElement()) {
|
2014-12-12 22:16:20 +01:00
|
|
|
const std::string ename = e->Name();
|
|
|
|
if (ename == "prefix")
|
2013-12-22 18:44:31 +01:00
|
|
|
_exporters[prefix].addPrefix(e->GetText());
|
2014-12-12 22:16:20 +01:00
|
|
|
else if (ename == "suffix")
|
2013-12-22 18:44:31 +01:00
|
|
|
_exporters[prefix].addSuffix(e->GetText());
|
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(ename);
|
2013-12-22 18:44:31 +01:00
|
|
|
}
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2013-12-22 18:44:31 +01:00
|
|
|
}
|
2013-10-20 14:09:10 +02:00
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (markupnodename == "imported") {
|
2013-12-22 18:44:31 +01:00
|
|
|
for (const tinyxml2::XMLElement *librarynode = markupnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
|
|
|
|
if (strcmp(librarynode->Name(), "importer") == 0)
|
|
|
|
_importers[extension].insert(librarynode->GetText());
|
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(librarynode->Name());
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (markupnodename == "codeblocks") {
|
2013-12-23 12:27:00 +01:00
|
|
|
for (const tinyxml2::XMLElement *blocknode = markupnode->FirstChildElement(); blocknode; blocknode = blocknode->NextSiblingElement()) {
|
2014-12-12 22:16:20 +01:00
|
|
|
const std::string blocknodename = blocknode->Name();
|
|
|
|
if (blocknodename == "block") {
|
2014-08-04 08:00:53 +02:00
|
|
|
const char * blockName = blocknode->Attribute("name");
|
|
|
|
if (blockName)
|
|
|
|
_executableblocks[extension].addBlock(blockName);
|
2014-12-12 22:16:20 +01:00
|
|
|
} else if (blocknodename == "structure") {
|
2013-12-22 18:44:31 +01:00
|
|
|
const char * start = blocknode->Attribute("start");
|
2013-10-20 14:09:10 +02:00
|
|
|
if (start)
|
2013-10-27 13:55:13 +01:00
|
|
|
_executableblocks[extension].setStart(start);
|
2013-12-22 18:44:31 +01:00
|
|
|
const char * end = blocknode->Attribute("end");
|
2013-10-20 14:09:10 +02:00
|
|
|
if (end)
|
2013-10-27 13:55:13 +01:00
|
|
|
_executableblocks[extension].setEnd(end);
|
2013-12-22 18:44:31 +01:00
|
|
|
const char * offset = blocknode->Attribute("offset");
|
2013-10-20 14:09:10 +02:00
|
|
|
if (offset)
|
2013-10-27 13:55:13 +01:00
|
|
|
_executableblocks[extension].setOffset(atoi(offset));
|
2013-12-22 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(blocknodename);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-22 18:44:31 +01:00
|
|
|
|
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(markupnodename);
|
2013-10-20 14:09:10 +02:00
|
|
|
}
|
2013-12-22 18:44:31 +01:00
|
|
|
}
|
2013-10-20 14:09:10 +02:00
|
|
|
|
2015-01-03 20:35:33 +01:00
|
|
|
else if (nodename == "container") {
|
|
|
|
const char* const id = node->Attribute("id");
|
|
|
|
if (!id)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "id");
|
|
|
|
|
|
|
|
Container& container = containers[id];
|
|
|
|
|
|
|
|
const char* const inherits = node->Attribute("inherits");
|
|
|
|
if (inherits) {
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Container>::const_iterator i = containers.find(inherits);
|
2015-01-10 20:51:14 +01:00
|
|
|
if (i != containers.end())
|
2015-01-03 20:35:33 +01:00
|
|
|
container = i->second; // Take values from parent and overwrite them if necessary
|
|
|
|
else
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, inherits);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* const startPattern = node->Attribute("startPattern");
|
|
|
|
if (startPattern)
|
|
|
|
container.startPattern = startPattern;
|
|
|
|
const char* const endPattern = node->Attribute("endPattern");
|
|
|
|
if (endPattern)
|
|
|
|
container.endPattern = endPattern;
|
2015-11-20 12:46:59 +01:00
|
|
|
const char* const itEndPattern = node->Attribute("itEndPattern");
|
|
|
|
if (itEndPattern)
|
|
|
|
container.itEndPattern = itEndPattern;
|
2016-07-09 12:42:46 +02:00
|
|
|
const char* const opLessAllowed = node->Attribute("opLessAllowed");
|
|
|
|
if (opLessAllowed)
|
|
|
|
container.opLessAllowed = std::string(opLessAllowed) == "true";
|
2015-01-03 20:35:33 +01:00
|
|
|
|
|
|
|
for (const tinyxml2::XMLElement *containerNode = node->FirstChildElement(); containerNode; containerNode = containerNode->NextSiblingElement()) {
|
|
|
|
const std::string containerNodeName = containerNode->Name();
|
|
|
|
if (containerNodeName == "size" || containerNodeName == "access" || containerNodeName == "other") {
|
|
|
|
for (const tinyxml2::XMLElement *functionNode = containerNode->FirstChildElement(); functionNode; functionNode = functionNode->NextSiblingElement()) {
|
2015-01-10 22:18:57 +01:00
|
|
|
if (std::string(functionNode->Name()) != "function") {
|
|
|
|
unknown_elements.insert(functionNode->Name());
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-03 20:35:33 +01:00
|
|
|
|
|
|
|
const char* const functionName = functionNode->Attribute("name");
|
|
|
|
if (!functionName)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "name");
|
|
|
|
|
|
|
|
const char* const action_ptr = functionNode->Attribute("action");
|
|
|
|
Container::Action action = Container::NO_ACTION;
|
|
|
|
if (action_ptr) {
|
|
|
|
std::string actionName = action_ptr;
|
|
|
|
if (actionName == "resize")
|
|
|
|
action = Container::RESIZE;
|
|
|
|
else if (actionName == "clear")
|
|
|
|
action = Container::CLEAR;
|
|
|
|
else if (actionName == "push")
|
|
|
|
action = Container::PUSH;
|
|
|
|
else if (actionName == "pop")
|
|
|
|
action = Container::POP;
|
2015-01-04 12:43:31 +01:00
|
|
|
else if (actionName == "find")
|
|
|
|
action = Container::FIND;
|
2015-11-20 18:22:15 +01:00
|
|
|
else if (actionName == "insert")
|
|
|
|
action = Container::INSERT;
|
|
|
|
else if (actionName == "erase")
|
|
|
|
action = Container::ERASE;
|
|
|
|
else if (actionName == "change-content")
|
|
|
|
action = Container::CHANGE_CONTENT;
|
|
|
|
else if (actionName == "change-internal")
|
|
|
|
action = Container::CHANGE_INTERNAL;
|
|
|
|
else if (actionName == "change")
|
|
|
|
action = Container::CHANGE;
|
2015-01-03 20:35:33 +01:00
|
|
|
else
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, actionName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* const yield_ptr = functionNode->Attribute("yields");
|
|
|
|
Container::Yield yield = Container::NO_YIELD;
|
|
|
|
if (yield_ptr) {
|
|
|
|
std::string yieldName = yield_ptr;
|
|
|
|
if (yieldName == "at_index")
|
|
|
|
yield = Container::AT_INDEX;
|
|
|
|
else if (yieldName == "item")
|
|
|
|
yield = Container::ITEM;
|
|
|
|
else if (yieldName == "buffer")
|
|
|
|
yield = Container::BUFFER;
|
|
|
|
else if (yieldName == "buffer-nt")
|
|
|
|
yield = Container::BUFFER_NT;
|
|
|
|
else if (yieldName == "start-iterator")
|
|
|
|
yield = Container::START_ITERATOR;
|
|
|
|
else if (yieldName == "end-iterator")
|
|
|
|
yield = Container::END_ITERATOR;
|
2015-11-20 18:22:15 +01:00
|
|
|
else if (yieldName == "iterator")
|
|
|
|
yield = Container::ITERATOR;
|
2015-01-03 20:35:33 +01:00
|
|
|
else if (yieldName == "size")
|
|
|
|
yield = Container::SIZE;
|
|
|
|
else if (yieldName == "empty")
|
|
|
|
yield = Container::EMPTY;
|
|
|
|
else
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, yieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
container.functions[functionName].action = action;
|
|
|
|
container.functions[functionName].yield = yield;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (containerNodeName == "size") {
|
|
|
|
const char* const templateArg = containerNode->Attribute("templateParameter");
|
|
|
|
if (templateArg)
|
|
|
|
container.size_templateArgNo = atoi(templateArg);
|
|
|
|
} else if (containerNodeName == "access") {
|
2016-07-09 12:42:46 +02:00
|
|
|
const char* const indexArg = containerNode->Attribute("indexOperator");
|
|
|
|
if (indexArg)
|
|
|
|
container.arrayLike_indexOp = std::string(indexArg) == "array-like";
|
2015-01-03 20:35:33 +01:00
|
|
|
}
|
|
|
|
} else if (containerNodeName == "type") {
|
|
|
|
const char* const templateArg = containerNode->Attribute("templateParameter");
|
|
|
|
if (templateArg)
|
|
|
|
container.type_templateArgNo = atoi(templateArg);
|
|
|
|
|
2016-07-09 12:42:46 +02:00
|
|
|
const char* const string = containerNode->Attribute("string");
|
|
|
|
if (string)
|
|
|
|
container.stdStringLike = std::string(string) == "std-like";
|
2015-01-03 20:35:33 +01:00
|
|
|
} else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(containerNodeName);
|
2015-01-03 20:35:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:03:31 +02:00
|
|
|
else if (nodename == "podtype") {
|
2014-06-08 12:09:00 +02:00
|
|
|
const char * const name = node->Attribute("name");
|
|
|
|
if (!name)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "name");
|
2014-06-13 15:46:43 +02:00
|
|
|
PodType podType = {0};
|
2015-01-30 20:27:48 +01:00
|
|
|
const char * const size = node->Attribute("size");
|
2014-06-08 12:09:00 +02:00
|
|
|
if (size)
|
|
|
|
podType.size = atoi(size);
|
|
|
|
const char * const sign = node->Attribute("sign");
|
|
|
|
if (sign)
|
|
|
|
podType.sign = *sign;
|
2015-11-15 15:24:10 +01:00
|
|
|
const std::vector<std::string> names(getnames(name));
|
|
|
|
for (unsigned int i = 0U; i < names.size(); ++i)
|
|
|
|
podtypes[names[i]] = podType;
|
2014-06-08 12:09:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-19 07:34:40 +02:00
|
|
|
else if (nodename == "platformtype") {
|
|
|
|
const char * const type_name = node->Attribute("name");
|
|
|
|
if (type_name == nullptr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "name");
|
|
|
|
const char *value = node->Attribute("value");
|
|
|
|
if (value == nullptr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "value");
|
|
|
|
PlatformType type;
|
|
|
|
type._type = value;
|
|
|
|
std::set<std::string> platform;
|
|
|
|
for (const tinyxml2::XMLElement *typenode = node->FirstChildElement(); typenode; typenode = typenode->NextSiblingElement()) {
|
2014-12-12 22:16:20 +01:00
|
|
|
const std::string typenodename = typenode->Name();
|
|
|
|
if (typenodename == "platform") {
|
2014-10-19 07:34:40 +02:00
|
|
|
const char * const type_attribute = typenode->Attribute("type");
|
|
|
|
if (type_attribute == nullptr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "type");
|
|
|
|
platform.insert(type_attribute);
|
2014-12-12 22:16:20 +01:00
|
|
|
} else if (typenodename == "signed")
|
2014-10-19 07:34:40 +02:00
|
|
|
type._signed = true;
|
2014-12-12 22:16:20 +01:00
|
|
|
else if (typenodename == "unsigned")
|
2014-10-19 07:34:40 +02:00
|
|
|
type._unsigned = true;
|
2014-12-12 22:16:20 +01:00
|
|
|
else if (typenodename == "long")
|
2014-10-19 07:34:40 +02:00
|
|
|
type._long = true;
|
2014-12-12 22:16:20 +01:00
|
|
|
else if (typenodename == "pointer")
|
2014-10-19 07:34:40 +02:00
|
|
|
type._pointer= true;
|
2014-12-12 22:16:20 +01:00
|
|
|
else if (typenodename == "ptr_ptr")
|
2014-10-19 07:34:40 +02:00
|
|
|
type._ptr_ptr = true;
|
2014-12-12 22:16:20 +01:00
|
|
|
else if (typenodename == "const_ptr")
|
2014-10-19 07:34:40 +02:00
|
|
|
type._const_ptr = true;
|
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(typenodename);
|
2014-10-19 07:34:40 +02:00
|
|
|
}
|
|
|
|
if (platform.empty()) {
|
2017-03-01 10:50:50 +01:00
|
|
|
const PlatformType * const type_ptr = platform_type(type_name, emptyString);
|
2014-10-19 07:34:40 +02:00
|
|
|
if (type_ptr) {
|
|
|
|
if (*type_ptr == type)
|
|
|
|
return Error(DUPLICATE_PLATFORM_TYPE, type_name);
|
|
|
|
return Error(PLATFORM_TYPE_REDEFINED, type_name);
|
|
|
|
}
|
|
|
|
platform_types[type_name] = type;
|
|
|
|
} else {
|
|
|
|
std::set<std::string>::const_iterator it;
|
|
|
|
for (it = platform.begin(); it != platform.end(); ++it) {
|
|
|
|
const PlatformType * const type_ptr = platform_type(type_name, *it);
|
|
|
|
if (type_ptr) {
|
|
|
|
if (*type_ptr == type)
|
|
|
|
return Error(DUPLICATE_PLATFORM_TYPE, type_name);
|
|
|
|
return Error(PLATFORM_TYPE_REDEFINED, type_name);
|
|
|
|
}
|
|
|
|
platforms[*it]._platform_types[type_name] = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-22 18:44:31 +01:00
|
|
|
else
|
2015-01-10 22:18:57 +01:00
|
|
|
unknown_elements.insert(nodename);
|
|
|
|
}
|
|
|
|
if (!unknown_elements.empty()) {
|
|
|
|
std::string str;
|
|
|
|
for (std::set<std::string>::const_iterator i = unknown_elements.begin(); i != unknown_elements.end();) {
|
|
|
|
str += *i;
|
|
|
|
if (++i != unknown_elements.end())
|
|
|
|
str += ", ";
|
|
|
|
}
|
|
|
|
return Error(UNKNOWN_ELEMENT, str);
|
2013-07-02 07:18:19 +02:00
|
|
|
}
|
2014-06-04 19:18:27 +02:00
|
|
|
return Error(OK);
|
2013-07-02 07:18:19 +02:00
|
|
|
}
|
2013-12-23 10:06:45 +01:00
|
|
|
|
2015-08-09 21:27:57 +02:00
|
|
|
Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, const std::string &name, std::set<std::string> &unknown_elements)
|
|
|
|
{
|
|
|
|
if (name.empty())
|
|
|
|
return Error(OK);
|
|
|
|
|
2016-12-06 14:47:45 +01:00
|
|
|
Function& func = functions[name];
|
2016-09-04 14:14:21 +02:00
|
|
|
|
2015-08-09 21:27:57 +02:00
|
|
|
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
|
|
|
|
const std::string functionnodename = functionnode->Name();
|
|
|
|
if (functionnodename == "noreturn")
|
|
|
|
_noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
|
|
|
|
else if (functionnodename == "pure")
|
2016-12-06 14:47:45 +01:00
|
|
|
func.ispure = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (functionnodename == "const") {
|
2016-12-06 14:47:45 +01:00
|
|
|
func.ispure = true;
|
|
|
|
func.isconst = true; // a constant function is pure
|
2015-08-09 21:27:57 +02:00
|
|
|
} else if (functionnodename == "leak-ignore")
|
2016-12-06 14:47:45 +01:00
|
|
|
func.leakignore = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (functionnodename == "use-retval")
|
2016-12-06 14:47:45 +01:00
|
|
|
func.useretval = true;
|
2016-10-23 23:20:36 +02:00
|
|
|
else if (functionnodename == "returnValue") {
|
|
|
|
if (const char *expr = functionnode->GetText())
|
|
|
|
_returnValue[name] = expr;
|
|
|
|
if (const char *type = functionnode->Attribute("type"))
|
2016-10-23 23:04:15 +02:00
|
|
|
_returnValueType[name] = type;
|
2016-11-01 14:08:42 +01:00
|
|
|
if (const char *container = functionnode->Attribute("container"))
|
|
|
|
_returnValueContainer[name] = std::atoi(container);
|
2016-10-23 23:04:15 +02:00
|
|
|
} else if (functionnodename == "arg") {
|
2016-07-09 12:42:46 +02:00
|
|
|
const char* argNrString = functionnode->Attribute("nr");
|
|
|
|
if (!argNrString)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "nr");
|
2017-03-14 17:41:34 +01:00
|
|
|
const bool bAnyArg = strcmp(argNrString, "any") == 0;
|
|
|
|
const bool bVariadicArg = strcmp(argNrString, "variadic") == 0;
|
|
|
|
const int nr = (bAnyArg || bVariadicArg) ? -1 : std::atoi(argNrString);
|
2016-12-06 14:47:45 +01:00
|
|
|
ArgumentChecks &ac = func.argumentChecks[nr];
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.optional = functionnode->Attribute("default") != nullptr;
|
2017-03-14 17:41:34 +01:00
|
|
|
ac.variadic = bVariadicArg;
|
2015-08-09 21:27:57 +02:00
|
|
|
for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
|
|
|
|
const std::string argnodename = argnode->Name();
|
|
|
|
if (argnodename == "not-bool")
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.notbool = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (argnodename == "not-null")
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.notnull = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (argnodename == "not-uninit")
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.notuninit = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (argnodename == "formatstr")
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.formatstr = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (argnodename == "strz")
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.strz = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
else if (argnodename == "valid") {
|
|
|
|
// Validate the validation expression
|
|
|
|
const char *p = argnode->GetText();
|
|
|
|
bool error = false;
|
|
|
|
bool range = false;
|
|
|
|
for (; *p; p++) {
|
|
|
|
if (std::isdigit(*p))
|
|
|
|
error |= (*(p+1) == '-');
|
|
|
|
else if (*p == ':')
|
|
|
|
error |= range;
|
|
|
|
else if (*p == '-')
|
|
|
|
error |= (!std::isdigit(*(p+1)));
|
|
|
|
else if (*p == ',')
|
|
|
|
range = false;
|
|
|
|
else
|
|
|
|
error = true;
|
|
|
|
|
|
|
|
range |= (*p == ':');
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, argnode->GetText());
|
|
|
|
|
|
|
|
// Set validation expression
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.valid = argnode->GetText();
|
2015-08-09 21:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (argnodename == "minsize") {
|
|
|
|
const char *typeattr = argnode->Attribute("type");
|
|
|
|
if (!typeattr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "type");
|
|
|
|
|
|
|
|
ArgumentChecks::MinSize::Type type;
|
|
|
|
if (strcmp(typeattr,"strlen")==0)
|
|
|
|
type = ArgumentChecks::MinSize::STRLEN;
|
|
|
|
else if (strcmp(typeattr,"argvalue")==0)
|
|
|
|
type = ArgumentChecks::MinSize::ARGVALUE;
|
|
|
|
else if (strcmp(typeattr,"sizeof")==0)
|
|
|
|
type = ArgumentChecks::MinSize::SIZEOF;
|
|
|
|
else if (strcmp(typeattr,"mul")==0)
|
|
|
|
type = ArgumentChecks::MinSize::MUL;
|
|
|
|
else
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, typeattr);
|
|
|
|
|
|
|
|
const char *argattr = argnode->Attribute("arg");
|
|
|
|
if (!argattr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "arg");
|
|
|
|
if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9')
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, argattr);
|
|
|
|
|
2017-03-27 17:33:26 +02:00
|
|
|
ac.minsizes.reserve(type == ArgumentChecks::MinSize::MUL ? 2 : 1);
|
2018-04-11 09:44:35 +02:00
|
|
|
ac.minsizes.emplace_back(type,argattr[0]-'0');
|
2015-08-09 21:27:57 +02:00
|
|
|
if (type == ArgumentChecks::MinSize::MUL) {
|
2017-03-27 17:33:26 +02:00
|
|
|
const char *arg2attr = argnode->Attribute("arg2");
|
2015-08-09 21:27:57 +02:00
|
|
|
if (!arg2attr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "arg2");
|
|
|
|
if (strlen(arg2attr) != 1 || arg2attr[0]<'0' || arg2attr[0]>'9')
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, arg2attr);
|
2016-10-25 23:07:18 +02:00
|
|
|
ac.minsizes.back().arg2 = arg2attr[0] - '0';
|
2015-08-09 21:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-25 23:07:18 +02:00
|
|
|
else if (argnodename == "iterator") {
|
2016-12-06 12:31:16 +01:00
|
|
|
ac.iteratorInfo.it = true;
|
|
|
|
const char* str = argnode->Attribute("type");
|
|
|
|
ac.iteratorInfo.first = str ? (std::strcmp(str, "first") == 0) : false;
|
|
|
|
ac.iteratorInfo.last = str ? (std::strcmp(str, "last") == 0) : false;
|
|
|
|
str = argnode->Attribute("container");
|
|
|
|
ac.iteratorInfo.container = str ? std::atoi(str) : 0;
|
2016-10-25 23:07:18 +02:00
|
|
|
}
|
|
|
|
|
2015-08-09 21:27:57 +02:00
|
|
|
else
|
|
|
|
unknown_elements.insert(argnodename);
|
|
|
|
}
|
|
|
|
} else if (functionnodename == "ignorefunction") {
|
2016-12-06 14:47:45 +01:00
|
|
|
func.ignore = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
} else if (functionnodename == "formatstr") {
|
2016-12-06 14:47:45 +01:00
|
|
|
func.formatstr = true;
|
2015-08-09 21:27:57 +02:00
|
|
|
const tinyxml2::XMLAttribute* scan = functionnode->FindAttribute("scan");
|
|
|
|
const tinyxml2::XMLAttribute* secure = functionnode->FindAttribute("secure");
|
2016-12-06 14:47:45 +01:00
|
|
|
func.formatstr_scan = scan && scan->BoolValue();
|
|
|
|
func.formatstr_secure = secure && secure->BoolValue();
|
2015-11-21 20:24:30 +01:00
|
|
|
} else if (functionnodename == "warn") {
|
|
|
|
WarnInfo wi;
|
|
|
|
const char* const severity = functionnode->Attribute("severity");
|
|
|
|
if (severity == nullptr)
|
|
|
|
return Error(MISSING_ATTRIBUTE, "severity");
|
|
|
|
wi.severity = Severity::fromString(severity);
|
|
|
|
|
|
|
|
const char* const cstd = functionnode->Attribute("cstd");
|
|
|
|
if (cstd) {
|
|
|
|
if (!wi.standards.setC(cstd))
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, cstd);
|
|
|
|
} else
|
|
|
|
wi.standards.c = Standards::C89;
|
|
|
|
|
|
|
|
const char* const cppstd = functionnode->Attribute("cppstd");
|
|
|
|
if (cppstd) {
|
|
|
|
if (!wi.standards.setCPP(cppstd))
|
|
|
|
return Error(BAD_ATTRIBUTE_VALUE, cppstd);
|
|
|
|
} else
|
|
|
|
wi.standards.cpp = Standards::CPP03;
|
|
|
|
|
|
|
|
const char* const reason = functionnode->Attribute("reason");
|
|
|
|
const char* const alternatives = functionnode->Attribute("alternatives");
|
|
|
|
if (reason && alternatives) {
|
|
|
|
// Construct message
|
|
|
|
wi.message = std::string(reason) + " function '" + name + "' called. It is recommended to use ";
|
|
|
|
std::vector<std::string> alt = getnames(alternatives);
|
|
|
|
for (std::size_t i = 0; i < alt.size(); ++i) {
|
|
|
|
wi.message += "'" + alt[i] + "'";
|
|
|
|
if (i == alt.size() - 1)
|
|
|
|
wi.message += " instead.";
|
|
|
|
else if (i == alt.size() - 2)
|
|
|
|
wi.message += " or ";
|
|
|
|
else
|
|
|
|
wi.message += ", ";
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
wi.message = functionnode->GetText();
|
|
|
|
|
|
|
|
functionwarn[name] = wi;
|
2015-08-09 21:27:57 +02:00
|
|
|
} else
|
|
|
|
unknown_elements.insert(functionnodename);
|
|
|
|
}
|
|
|
|
return Error(OK);
|
|
|
|
}
|
|
|
|
|
2015-01-08 19:31:41 +01:00
|
|
|
bool Library::isargvalid(const Token *ftok, int argnr, const MathLib::bigint argvalue) const
|
2013-12-23 10:06:45 +01:00
|
|
|
{
|
2015-01-08 19:31:41 +01:00
|
|
|
const ArgumentChecks *ac = getarg(ftok, argnr);
|
2013-12-23 10:06:45 +01:00
|
|
|
if (!ac || ac->valid.empty())
|
|
|
|
return true;
|
2017-08-09 20:00:26 +02:00
|
|
|
TokenList tokenList(nullptr);
|
2013-12-23 10:06:45 +01:00
|
|
|
std::istringstream istr(ac->valid + ',');
|
2014-10-03 10:02:46 +02:00
|
|
|
tokenList.createTokens(istr);
|
2014-06-08 18:12:11 +02:00
|
|
|
for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
|
|
|
|
if (Token::Match(tok,"- %num%")) {
|
|
|
|
tok->str("-" + tok->strAt(1));
|
|
|
|
tok->deleteNext();
|
|
|
|
}
|
2014-06-07 16:28:29 +02:00
|
|
|
}
|
2013-12-23 10:06:45 +01:00
|
|
|
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
|
|
|
|
if (tok->isNumber() && argvalue == MathLib::toLongNumber(tok->str()))
|
|
|
|
return true;
|
2014-06-08 18:12:11 +02:00
|
|
|
if (Token::Match(tok, "%num% : %num%") && argvalue >= MathLib::toLongNumber(tok->str()) && argvalue <= MathLib::toLongNumber(tok->strAt(2)))
|
2013-12-23 10:06:45 +01:00
|
|
|
return true;
|
2014-06-08 18:12:11 +02:00
|
|
|
if (Token::Match(tok, "%num% : ,") && argvalue >= MathLib::toLongNumber(tok->str()))
|
2013-12-23 10:06:45 +01:00
|
|
|
return true;
|
2014-06-08 18:12:11 +02:00
|
|
|
if ((!tok->previous() || tok->previous()->str() == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toLongNumber(tok->strAt(1)))
|
2013-12-23 10:06:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-06 06:16:14 +01:00
|
|
|
|
2016-09-04 14:14:21 +02:00
|
|
|
std::string Library::getFunctionName(const Token *ftok, bool *error) const
|
2015-08-10 09:41:06 +02:00
|
|
|
{
|
|
|
|
if (!ftok) {
|
|
|
|
*error = true;
|
|
|
|
return "";
|
|
|
|
}
|
2016-09-04 14:14:21 +02:00
|
|
|
if (ftok->isName()) {
|
|
|
|
for (const Scope *scope = ftok->scope(); scope; scope = scope->nestedIn) {
|
|
|
|
if (!scope->isClassOrStruct())
|
|
|
|
continue;
|
2017-08-28 17:19:03 +02:00
|
|
|
const std::vector<Type::BaseInfo> &derivedFrom = scope->definedType->derivedFrom;
|
|
|
|
for (unsigned int i = 0; i < derivedFrom.size(); ++i) {
|
|
|
|
const Type::BaseInfo &baseInfo = derivedFrom[i];
|
2016-09-04 14:14:21 +02:00
|
|
|
const std::string name(baseInfo.name + "::" + ftok->str());
|
2016-12-06 14:47:45 +01:00
|
|
|
if (functions.find(name) != functions.end() && matchArguments(ftok, name))
|
2016-09-04 14:14:21 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
2015-08-10 09:41:06 +02:00
|
|
|
return ftok->str();
|
2016-09-04 14:14:21 +02:00
|
|
|
}
|
2015-08-10 09:41:06 +02:00
|
|
|
if (ftok->str() == "::") {
|
|
|
|
if (!ftok->astOperand2())
|
2016-09-04 14:14:21 +02:00
|
|
|
return getFunctionName(ftok->astOperand1(), error);
|
|
|
|
return getFunctionName(ftok->astOperand1(),error) + "::" + getFunctionName(ftok->astOperand2(),error);
|
2015-08-10 09:41:06 +02:00
|
|
|
}
|
|
|
|
if (ftok->str() == "." && ftok->astOperand1()) {
|
|
|
|
const std::string type = astCanonicalType(ftok->astOperand1());
|
|
|
|
if (type.empty()) {
|
|
|
|
*error = true;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-09-04 14:14:21 +02:00
|
|
|
return type + "::" + getFunctionName(ftok->astOperand2(),error);
|
2015-08-10 09:41:06 +02:00
|
|
|
}
|
|
|
|
*error = true;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-09-04 14:14:21 +02:00
|
|
|
std::string Library::getFunctionName(const Token *ftok) const
|
2015-08-09 19:55:33 +02:00
|
|
|
{
|
2015-08-10 09:41:06 +02:00
|
|
|
if (!Token::Match(ftok, "%name% ("))
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// Lookup function name using AST..
|
|
|
|
if (ftok->astParent()) {
|
|
|
|
bool error = false;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::string ret = getFunctionName(ftok->next()->astOperand1(), &error);
|
2015-08-10 09:41:06 +02:00
|
|
|
return error ? std::string() : ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup function name without using AST..
|
2015-08-09 19:55:33 +02:00
|
|
|
if (Token::simpleMatch(ftok->previous(), "."))
|
|
|
|
return "";
|
|
|
|
if (!Token::Match(ftok->tokAt(-2), "%name% ::"))
|
|
|
|
return ftok->str();
|
|
|
|
std::string ret(ftok->str());
|
|
|
|
ftok = ftok->tokAt(-2);
|
|
|
|
while (Token::Match(ftok, "%name% ::")) {
|
|
|
|
ret = ftok->str() + "::" + ret;
|
|
|
|
ftok = ftok->tokAt(-2);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:51:45 +02:00
|
|
|
bool Library::isnullargbad(const Token *ftok, int argnr) const
|
|
|
|
{
|
|
|
|
const ArgumentChecks *arg = getarg(ftok, argnr);
|
|
|
|
if (!arg) {
|
|
|
|
// scan format string argument should not be null
|
2016-09-04 14:14:21 +02:00
|
|
|
const std::string funcname = getFunctionName(ftok);
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(funcname);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend() && it->second.formatstr && it->second.formatstr_scan)
|
2015-10-03 20:51:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return arg && arg->notnull;
|
|
|
|
}
|
|
|
|
|
2015-10-03 18:35:16 +02:00
|
|
|
bool Library::isuninitargbad(const Token *ftok, int argnr) const
|
|
|
|
{
|
|
|
|
const ArgumentChecks *arg = getarg(ftok, argnr);
|
|
|
|
if (!arg) {
|
|
|
|
// non-scan format string argument should not be uninitialized
|
2016-09-04 14:14:21 +02:00
|
|
|
const std::string funcname = getFunctionName(ftok);
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(funcname);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend() && it->second.formatstr && !it->second.formatstr_scan)
|
2015-10-03 18:35:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return arg && arg->notuninit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-22 17:18:50 +02:00
|
|
|
/** get allocation info for function */
|
|
|
|
const Library::AllocFunc* Library::alloc(const Token *tok) const
|
2015-08-10 18:36:09 +02:00
|
|
|
{
|
2016-09-04 14:14:21 +02:00
|
|
|
const std::string funcname = getFunctionName(tok);
|
2017-08-09 20:00:26 +02:00
|
|
|
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(_alloc, funcname);
|
2015-08-10 18:36:09 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 17:18:50 +02:00
|
|
|
/** get deallocation info for function */
|
|
|
|
const Library::AllocFunc* Library::dealloc(const Token *tok) const
|
2015-08-10 18:36:09 +02:00
|
|
|
{
|
2016-09-04 14:14:21 +02:00
|
|
|
const std::string funcname = getFunctionName(tok);
|
2017-08-09 20:00:26 +02:00
|
|
|
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(_dealloc, funcname);
|
2016-05-22 17:18:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** get allocation id for function */
|
|
|
|
int Library::alloc(const Token *tok, int arg) const
|
|
|
|
{
|
|
|
|
const Library::AllocFunc* af = alloc(tok);
|
|
|
|
return (af && af->arg == arg) ? af->groupId : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** get deallocation id for function */
|
|
|
|
int Library::dealloc(const Token *tok, int arg) const
|
|
|
|
{
|
|
|
|
const Library::AllocFunc* af = dealloc(tok);
|
|
|
|
return (af && af->arg == arg) ? af->groupId : 0;
|
2015-08-10 18:36:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-08 19:31:41 +01:00
|
|
|
const Library::ArgumentChecks * Library::getarg(const Token *ftok, int argnr) const
|
2014-03-06 06:16:14 +01:00
|
|
|
{
|
2015-01-08 19:31:41 +01:00
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return nullptr;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it1 = functions.find(getFunctionName(ftok));
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it1 == functions.cend())
|
2014-03-06 06:16:14 +01:00
|
|
|
return nullptr;
|
2016-12-06 12:31:16 +01:00
|
|
|
const std::map<int,ArgumentChecks>::const_iterator it2 = it1->second.argumentChecks.find(argnr);
|
|
|
|
if (it2 != it1->second.argumentChecks.cend())
|
2014-03-06 06:16:14 +01:00
|
|
|
return &it2->second;
|
2016-12-06 12:31:16 +01:00
|
|
|
const std::map<int,ArgumentChecks>::const_iterator it3 = it1->second.argumentChecks.find(-1);
|
|
|
|
if (it3 != it1->second.argumentChecks.cend())
|
2014-03-06 06:16:14 +01:00
|
|
|
return &it3->second;
|
2014-03-06 06:27:01 +01:00
|
|
|
return nullptr;
|
2014-03-06 06:16:14 +01:00
|
|
|
}
|
2014-06-22 19:13:15 +02:00
|
|
|
|
|
|
|
bool Library::isScopeNoReturn(const Token *end, std::string *unknownFunc) const
|
|
|
|
{
|
|
|
|
if (unknownFunc)
|
|
|
|
unknownFunc->clear();
|
|
|
|
|
|
|
|
if (!Token::simpleMatch(end->tokAt(-2), ") ; }"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const Token *funcname = end->linkAt(-2)->previous();
|
|
|
|
const Token *start = funcname;
|
2015-02-01 15:21:09 +01:00
|
|
|
if (Token::Match(funcname->tokAt(-3),"( * %name% )")) {
|
2014-06-22 19:13:15 +02:00
|
|
|
funcname = funcname->previous();
|
|
|
|
start = funcname->tokAt(-3);
|
|
|
|
} else if (funcname->isName()) {
|
2015-01-31 10:50:39 +01:00
|
|
|
while (Token::Match(start, "%name%|.|::"))
|
2014-06-22 19:13:15 +02:00
|
|
|
start = start->previous();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-31 10:50:39 +01:00
|
|
|
if (Token::Match(start,"[;{}]") && Token::Match(funcname, "%name% )| (")) {
|
2014-06-22 19:13:15 +02:00
|
|
|
if (funcname->str() == "exit")
|
|
|
|
return true;
|
2015-01-08 19:31:41 +01:00
|
|
|
if (!isnotnoreturn(funcname)) {
|
|
|
|
if (unknownFunc && !isnoreturn(funcname))
|
2014-06-22 19:13:15 +02:00
|
|
|
*unknownFunc = funcname->str();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-20 12:46:59 +01:00
|
|
|
const Library::Container* Library::detectContainer(const Token* typeStart, bool iterator) const
|
2015-01-03 20:35:33 +01:00
|
|
|
{
|
|
|
|
for (std::map<std::string, Container>::const_iterator i = containers.begin(); i != containers.end(); ++i) {
|
|
|
|
const Container& container = i->second;
|
|
|
|
if (container.startPattern.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Token::Match(typeStart, container.startPattern.c_str())) {
|
2015-11-20 12:46:59 +01:00
|
|
|
if (!iterator && container.endPattern.empty()) // If endPattern is undefined, it will always match, but itEndPattern has to be defined.
|
2015-01-03 20:35:33 +01:00
|
|
|
return &container;
|
|
|
|
|
|
|
|
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
|
|
|
|
if (tok->link()) {
|
2015-11-20 12:46:59 +01:00
|
|
|
const std::string& endPattern = iterator ? container.itEndPattern : container.endPattern;
|
|
|
|
if (Token::Match(tok->link(), endPattern.c_str()))
|
2015-01-03 20:35:33 +01:00
|
|
|
return &container;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-08-09 19:55:33 +02:00
|
|
|
|
2018-03-24 07:58:37 +01:00
|
|
|
bool Library::isContainerYield(const Token * const cond, Library::Container::Yield y, const std::string& fallback)
|
|
|
|
{
|
2018-03-24 12:30:11 +01:00
|
|
|
if (!cond)
|
2018-03-24 07:58:37 +01:00
|
|
|
return false;
|
|
|
|
if (cond->str() == "(") {
|
|
|
|
const Token* tok = cond->astOperand1();
|
2018-03-24 12:30:11 +01:00
|
|
|
if (tok && tok->str() == ".") {
|
|
|
|
if (tok->astOperand1() && tok->astOperand1()->valueType()) {
|
|
|
|
if (const Library::Container *container = tok->astOperand1()->valueType()->container) {
|
2018-03-24 07:58:37 +01:00
|
|
|
return tok->astOperand2() && y == container->getYield(tok->astOperand2()->str());
|
|
|
|
}
|
2018-03-24 12:30:11 +01:00
|
|
|
} else if (!fallback.empty()) {
|
2018-03-24 07:58:37 +01:00
|
|
|
return Token::simpleMatch(cond, "( )") && cond->previous()->str() == fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-27 17:55:18 +01:00
|
|
|
// returns true if ftok is not a library function
|
|
|
|
bool Library::isNotLibraryFunction(const Token *ftok) const
|
|
|
|
{
|
2015-03-08 16:13:32 +01:00
|
|
|
if (ftok->function() && ftok->function()->nestedIn && ftok->function()->nestedIn->type != Scope::eGlobal)
|
|
|
|
return true;
|
2017-10-11 17:15:28 +02:00
|
|
|
|
2015-03-01 11:46:43 +01:00
|
|
|
// variables are not library functions.
|
|
|
|
if (ftok->varId())
|
|
|
|
return true;
|
|
|
|
|
2016-09-04 14:14:21 +02:00
|
|
|
return !matchArguments(ftok, getFunctionName(ftok));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::matchArguments(const Token *ftok, const std::string &functionName) const
|
|
|
|
{
|
2018-04-04 21:51:31 +02:00
|
|
|
const int callargs = numberOfArguments(ftok);
|
2016-12-06 12:31:16 +01:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(functionName);
|
|
|
|
if (it == functions.cend())
|
2016-09-04 14:14:21 +02:00
|
|
|
return (callargs == 0);
|
2015-01-27 17:55:18 +01:00
|
|
|
int args = 0;
|
2016-07-09 12:42:46 +02:00
|
|
|
int firstOptionalArg = -1;
|
2016-12-06 12:31:16 +01:00
|
|
|
for (std::map<int, ArgumentChecks>::const_iterator it2 = it->second.argumentChecks.cbegin(); it2 != it->second.argumentChecks.cend(); ++it2) {
|
2015-01-27 17:55:18 +01:00
|
|
|
if (it2->first > args)
|
|
|
|
args = it2->first;
|
2016-07-09 12:42:46 +02:00
|
|
|
if (it2->second.optional && (firstOptionalArg == -1 || firstOptionalArg > it2->first))
|
|
|
|
firstOptionalArg = it2->first;
|
|
|
|
|
2017-03-14 17:41:34 +01:00
|
|
|
if (it2->second.formatstr || it2->second.variadic)
|
2016-09-04 14:14:21 +02:00
|
|
|
return args <= callargs;
|
2015-01-27 17:55:18 +01:00
|
|
|
}
|
2016-09-04 14:14:21 +02:00
|
|
|
return (firstOptionalArg < 0) ? args == callargs : (callargs >= firstOptionalArg-1 && callargs <= args);
|
2015-01-27 17:55:18 +01:00
|
|
|
}
|
2015-03-11 20:52:54 +01:00
|
|
|
|
2015-11-21 20:24:30 +01:00
|
|
|
const Library::WarnInfo* Library::getWarnInfo(const Token* ftok) const
|
|
|
|
{
|
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return nullptr;
|
2016-09-04 14:14:21 +02:00
|
|
|
std::map<std::string, WarnInfo>::const_iterator i = functionwarn.find(getFunctionName(ftok));
|
2015-11-21 20:24:30 +01:00
|
|
|
if (i == functionwarn.cend())
|
|
|
|
return nullptr;
|
|
|
|
return &i->second;
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:36:27 +02:00
|
|
|
bool Library::formatstr_function(const Token* ftok) const
|
|
|
|
{
|
2016-12-06 12:31:16 +01:00
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return false;
|
|
|
|
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok));
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend())
|
|
|
|
return it->second.formatstr;
|
|
|
|
return false;
|
2016-08-19 17:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Library::formatstr_argno(const Token* ftok) const
|
|
|
|
{
|
2016-12-06 12:31:16 +01:00
|
|
|
const std::map<int, Library::ArgumentChecks>& argumentChecksFunc = functions.at(getFunctionName(ftok)).argumentChecks;
|
2016-08-19 17:36:27 +02:00
|
|
|
for (std::map<int, Library::ArgumentChecks>::const_iterator i = argumentChecksFunc.cbegin(); i != argumentChecksFunc.cend(); ++i) {
|
|
|
|
if (i->second.formatstr) {
|
|
|
|
return i->first - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::formatstr_scan(const Token* ftok) const
|
|
|
|
{
|
2016-12-06 12:31:16 +01:00
|
|
|
return functions.at(getFunctionName(ftok)).formatstr_scan;
|
2016-08-19 17:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::formatstr_secure(const Token* ftok) const
|
|
|
|
{
|
2016-12-06 12:31:16 +01:00
|
|
|
return functions.at(getFunctionName(ftok)).formatstr_secure;
|
2016-08-19 17:36:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-15 12:19:14 +02:00
|
|
|
bool Library::isUseRetVal(const Token* ftok) const
|
|
|
|
{
|
2016-12-06 12:31:16 +01:00
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return false;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok));
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend())
|
|
|
|
return it->second.useretval;
|
|
|
|
return false;
|
2015-08-15 12:19:14 +02:00
|
|
|
}
|
|
|
|
|
2016-12-05 17:30:06 +01:00
|
|
|
const std::string& Library::returnValue(const Token *ftok) const
|
2016-10-17 13:05:19 +02:00
|
|
|
{
|
|
|
|
if (isNotLibraryFunction(ftok))
|
2016-12-05 17:30:06 +01:00
|
|
|
return emptyString;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, std::string>::const_iterator it = _returnValue.find(getFunctionName(ftok));
|
2016-12-05 17:30:06 +01:00
|
|
|
return it != _returnValue.end() ? it->second : emptyString;
|
2016-10-17 13:05:19 +02:00
|
|
|
}
|
|
|
|
|
2016-12-05 17:30:06 +01:00
|
|
|
const std::string& Library::returnValueType(const Token *ftok) const
|
2016-10-23 23:04:15 +02:00
|
|
|
{
|
|
|
|
if (isNotLibraryFunction(ftok))
|
2016-12-05 17:30:06 +01:00
|
|
|
return emptyString;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, std::string>::const_iterator it = _returnValueType.find(getFunctionName(ftok));
|
2016-12-05 17:30:06 +01:00
|
|
|
return it != _returnValueType.end() ? it->second : emptyString;
|
2016-10-23 23:04:15 +02:00
|
|
|
}
|
|
|
|
|
2016-11-01 14:08:42 +01:00
|
|
|
int Library::returnValueContainer(const Token *ftok) const
|
|
|
|
{
|
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return -1;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, int>::const_iterator it = _returnValueContainer.find(getFunctionName(ftok));
|
2016-11-01 14:08:42 +01:00
|
|
|
return it != _returnValueContainer.end() ? it->second : -1;
|
|
|
|
}
|
|
|
|
|
2016-12-06 12:31:16 +01:00
|
|
|
bool Library::hasminsize(const std::string &functionName) const
|
|
|
|
{
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it1 = functions.find(functionName);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it1 == functions.cend())
|
|
|
|
return false;
|
|
|
|
for (std::map<int, ArgumentChecks>::const_iterator it2 = it1->second.argumentChecks.cbegin(); it2 != it1->second.argumentChecks.cend(); ++it2) {
|
|
|
|
if (!it2->second.minsizes.empty())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::ignorefunction(const std::string& functionName) const
|
|
|
|
{
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(functionName);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend())
|
|
|
|
return it->second.ignore;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool Library::isUse(const std::string& functionName) const
|
|
|
|
{
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(functionName);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend())
|
|
|
|
return it->second.use;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool Library::isLeakIgnore(const std::string& functionName) const
|
|
|
|
{
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(functionName);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend())
|
|
|
|
return it->second.leakignore;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool Library::isFunctionConst(const std::string& functionName, bool pure) const
|
|
|
|
{
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(functionName);
|
2016-12-06 12:31:16 +01:00
|
|
|
if (it != functions.cend())
|
|
|
|
return pure ? it->second.ispure : it->second.isconst;
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-08 18:08:32 +02:00
|
|
|
bool Library::isFunctionConst(const Token *ftok) const
|
|
|
|
{
|
|
|
|
if (ftok->function() && ftok->function()->isAttributeConst())
|
|
|
|
return true;
|
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return false;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok));
|
2017-09-08 18:08:32 +02:00
|
|
|
return (it != functions.end() && it->second.isconst);
|
|
|
|
}
|
2015-03-11 20:52:54 +01:00
|
|
|
bool Library::isnoreturn(const Token *ftok) const
|
|
|
|
{
|
|
|
|
if (ftok->function() && ftok->function()->isAttributeNoreturn())
|
|
|
|
return true;
|
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return false;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, bool>::const_iterator it = _noreturn.find(getFunctionName(ftok));
|
2015-03-11 20:52:54 +01:00
|
|
|
return (it != _noreturn.end() && it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::isnotnoreturn(const Token *ftok) const
|
|
|
|
{
|
|
|
|
if (ftok->function() && ftok->function()->isAttributeNoreturn())
|
|
|
|
return false;
|
|
|
|
if (isNotLibraryFunction(ftok))
|
|
|
|
return false;
|
2018-04-04 21:51:31 +02:00
|
|
|
const std::map<std::string, bool>::const_iterator it = _noreturn.find(getFunctionName(ftok));
|
2015-03-11 20:52:54 +01:00
|
|
|
return (it != _noreturn.end() && !it->second);
|
|
|
|
}
|
2015-03-11 22:12:17 +01:00
|
|
|
|
|
|
|
bool Library::markupFile(const std::string &path) const
|
|
|
|
{
|
|
|
|
return _markupExtensions.find(Path::getFilenameExtensionInLowerCase(path)) != _markupExtensions.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::processMarkupAfterCode(const std::string &path) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, bool>::const_iterator it = _processAfterCode.find(Path::getFilenameExtensionInLowerCase(path));
|
|
|
|
return (it == _processAfterCode.end() || it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::reportErrors(const std::string &path) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, bool>::const_iterator it = _reporterrors.find(Path::getFilenameExtensionInLowerCase(path));
|
|
|
|
return (it == _reporterrors.end() || it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::isexecutableblock(const std::string &file, const std::string &token) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, CodeBlock>::const_iterator it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
return (it != _executableblocks.end() && it->second.isBlock(token));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Library::blockstartoffset(const std::string &file) const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Library::blockstart(const std::string &file) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, CodeBlock>::const_iterator map_it
|
|
|
|
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
|
|
|
|
if (map_it != _executableblocks.end()) {
|
|
|
|
return map_it->second.start();
|
|
|
|
}
|
|
|
|
return emptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Library::blockend(const std::string &file) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, CodeBlock>::const_iterator map_it
|
|
|
|
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
|
|
|
|
if (map_it != _executableblocks.end()) {
|
|
|
|
return map_it->second.end();
|
|
|
|
}
|
|
|
|
return emptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::iskeyword(const std::string &file, const std::string &keyword) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, std::set<std::string> >::const_iterator it =
|
|
|
|
_keywords.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
return (it != _keywords.end() && it->second.count(keyword));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Library::isimporter(const std::string& file, const std::string &importer) const
|
|
|
|
{
|
|
|
|
const std::map<std::string, std::set<std::string> >::const_iterator it =
|
|
|
|
_importers.find(Path::getFilenameExtensionInLowerCase(file));
|
|
|
|
return (it != _importers.end() && it->second.count(importer) > 0);
|
|
|
|
}
|