Refactorizations:

- Removed some redundant operator=, copy-ctor and dtor implementations
- use operator[] instead of at() in library loading code
This commit is contained in:
PKEuS 2013-10-27 13:55:13 +01:00
parent f572f3dd81
commit c95b153700
4 changed files with 9 additions and 76 deletions

View File

@ -1978,11 +1978,6 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo()
{ {
} }
CheckBufferOverrun::ArrayInfo::ArrayInfo(const CheckBufferOverrun::ArrayInfo &ai)
{
*this = ai;
}
CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const Tokenizer *tokenizer, const unsigned int forcedeclid) CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const Tokenizer *tokenizer, const unsigned int forcedeclid)
: _varname(var->name()), _declarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid) : _varname(var->name()), _declarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid)
{ {
@ -1996,17 +1991,6 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const Tokenizer *t
_element_size = tokenizer->sizeOfType(var->typeEndToken()); _element_size = tokenizer->sizeOfType(var->typeEndToken());
} }
CheckBufferOverrun::ArrayInfo & CheckBufferOverrun::ArrayInfo::operator=(const CheckBufferOverrun::ArrayInfo &ai)
{
if (&ai != this) {
_element_size = ai._element_size;
_num = ai._num;
_declarationId = ai._declarationId;
_varname = ai._varname;
}
return *this;
}
/** /**
* Create array info with specified data * Create array info with specified data
* The intention is that this is only a temporary solution.. all * The intention is that this is only a temporary solution.. all

View File

@ -130,9 +130,7 @@ public:
public: public:
ArrayInfo(); ArrayInfo();
ArrayInfo(const ArrayInfo &);
ArrayInfo(const Variable *var, const Tokenizer *tokenizer, const unsigned int forcedeclid = 0); ArrayInfo(const Variable *var, const Tokenizer *tokenizer, const unsigned int forcedeclid = 0);
ArrayInfo & operator=(const ArrayInfo &ai);
/** /**
* Create array info with specified data * Create array info with specified data

View File

@ -27,27 +27,6 @@ Library::Library() : allocid(0)
{ {
} }
Library::Library(const Library &lib) :
use(lib.use),
leakignore(lib.leakignore),
argumentChecks(lib.argumentChecks),
returnuninitdata(lib.returnuninitdata),
allocid(lib.allocid),
_alloc(lib._alloc),
_dealloc(lib._dealloc),
_noreturn(lib._noreturn),
_ignorefunction(lib._ignorefunction),
_reporterrors(lib._reporterrors),
_fileextensions(lib._fileextensions),
_keywords(lib._keywords),
_executableblocks(lib._executableblocks),
_importers(lib._importers),
_reflection(lib._reflection)
{
}
Library::~Library() { }
bool Library::load(const char exename[], const char path[]) bool Library::load(const char exename[], const char path[])
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
@ -77,9 +56,7 @@ bool Library::load(const char exename[], const char path[])
if (fp==NULL) { if (fp==NULL) {
// Try to locate the library configuration in the installation folder.. // Try to locate the library configuration in the installation folder..
std::string temp = exename; const std::string installfolder = Path::fromNativeSeparators(Path::getPathFromFilename(exename));
std::replace(temp.begin(), temp.end(), '\\', '/');
const std::string installfolder = Path::getPathFromFilename(temp);
const std::string filename = installfolder + "cfg/" + fullfilename; const std::string filename = installfolder + "cfg/" + fullfilename;
fp = fopen(filename.c_str(), "rb"); fp = fopen(filename.c_str(), "rb");
} }
@ -169,13 +146,9 @@ bool Library::load(const char exename[], const char path[])
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "library") == 0) { if (strcmp(functionnode->Name(), "library") == 0) {
const char * const extension = functionnode->Attribute("extension"); const char * const extension = functionnode->Attribute("extension");
if (_keywords.find(extension) == _keywords.end()) {
std::list<std::string> list;
_keywords[extension] = list;
}
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) { for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
if (strcmp(librarynode->Name(), "keyword") == 0) { if (strcmp(librarynode->Name(), "keyword") == 0) {
_keywords.at(extension).push_back(librarynode->Attribute("name")); _keywords[extension].push_back(librarynode->Attribute("name"));
} else } else
return false; return false;
} }
@ -188,15 +161,7 @@ bool Library::load(const char exename[], const char path[])
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "exporter") == 0) { if (strcmp(functionnode->Name(), "exporter") == 0) {
const char * prefix = (functionnode->Attribute("prefix")); const char * prefix = (functionnode->Attribute("prefix"));
if (prefix) { if (!prefix)
std::map<std::string, ExportedFunctions>::const_iterator
it = _exporters.find(prefix);
if (it == _exporters.end()) {
// add the missing list for later on
ExportedFunctions exporter;
_exporters[prefix] = exporter;
}
} else
return false; return false;
for (const tinyxml2::XMLElement *enode = functionnode->FirstChildElement(); enode; enode = enode->NextSiblingElement()) { for (const tinyxml2::XMLElement *enode = functionnode->FirstChildElement(); enode; enode = enode->NextSiblingElement()) {
@ -216,13 +181,9 @@ bool Library::load(const char exename[], const char path[])
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "library") == 0) { if (strcmp(functionnode->Name(), "library") == 0) {
const char * const extension = functionnode->Attribute("extension"); const char * const extension = functionnode->Attribute("extension");
if (_importers.find(extension) == _importers.end()) {
std::list<std::string> list;
_importers[extension] = list;
}
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) { for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
if (strcmp(librarynode->Name(), "importer") == 0) { if (strcmp(librarynode->Name(), "importer") == 0) {
_importers.at(extension).push_back(librarynode->Attribute("name")); _importers[extension].push_back(librarynode->Attribute("name"));
} else } else
return false; return false;
} }
@ -234,15 +195,11 @@ bool Library::load(const char exename[], const char path[])
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "library") == 0) { if (strcmp(functionnode->Name(), "library") == 0) {
const char * const extension = functionnode->Attribute("extension"); const char * const extension = functionnode->Attribute("extension");
if (_reflection.find(extension) == _reflection.end()) {
std::map<std::string,int> map;
_reflection[extension] = map;
}
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) { for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
if (strcmp(librarynode->Name(), "call") == 0) { if (strcmp(librarynode->Name(), "call") == 0) {
const char * const argString = librarynode->Attribute("arg"); const char * const argString = librarynode->Attribute("arg");
if (argString) { if (argString) {
_reflection.at(extension)[librarynode->Attribute("name")] _reflection[extension][librarynode->Attribute("name")]
= atoi(argString); = atoi(argString);
} }
} else } else
@ -257,23 +214,19 @@ bool Library::load(const char exename[], const char path[])
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(), "library") == 0) { if (strcmp(functionnode->Name(), "library") == 0) {
const char * const extension = functionnode->Attribute("extension"); const char * const extension = functionnode->Attribute("extension");
if (_executableblocks.find(extension) == _executableblocks.end()) {
CodeBlock blockInfo;
_executableblocks[extension] = blockInfo;
}
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) { for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
if (strcmp(librarynode->Name(), "block") == 0) { if (strcmp(librarynode->Name(), "block") == 0) {
_executableblocks.at(extension).addBlock(librarynode->Attribute("name")); _executableblocks[extension].addBlock(librarynode->Attribute("name"));
} else if (strcmp(librarynode->Name(), "structure") == 0) { } else if (strcmp(librarynode->Name(), "structure") == 0) {
const char * start = librarynode->Attribute("start"); const char * start = librarynode->Attribute("start");
if (start) if (start)
_executableblocks.at(extension).setStart(start); _executableblocks[extension].setStart(start);
const char * end = librarynode->Attribute("end"); const char * end = librarynode->Attribute("end");
if (end) if (end)
_executableblocks.at(extension).setEnd(end); _executableblocks[extension].setEnd(end);
const char * offset = librarynode->Attribute("offset"); const char * offset = librarynode->Attribute("offset");
if (offset) if (offset)
_executableblocks.at(extension).setOffset(atoi(offset)); _executableblocks[extension].setOffset(atoi(offset));
} else } else
return false; return false;
} }

View File

@ -39,8 +39,6 @@
class CPPCHECKLIB Library { class CPPCHECKLIB Library {
public: public:
Library(); Library();
Library(const Library &);
~Library();
bool load(const char exename [], const char path []); bool load(const char exename [], const char path []);