library: Refactor to use enum class (#3026)
This commit is contained in:
parent
13b8ee8871
commit
bedf3118ef
|
@ -1126,35 +1126,35 @@ bool CppCheckExecutor::tryLoadLibrary(Library& destination, const char* basepath
|
||||||
{
|
{
|
||||||
const Library::Error err = destination.load(basepath, filename);
|
const Library::Error err = destination.load(basepath, filename);
|
||||||
|
|
||||||
if (err.errorcode == Library::UNKNOWN_ELEMENT)
|
if (err.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT)
|
||||||
std::cout << "cppcheck: Found unknown elements in configuration file '" << filename << "': " << err.reason << std::endl;
|
std::cout << "cppcheck: Found unknown elements in configuration file '" << filename << "': " << err.reason << std::endl;
|
||||||
else if (err.errorcode != Library::OK) {
|
else if (err.errorcode != Library::ErrorCode::OK) {
|
||||||
std::cout << "cppcheck: Failed to load library configuration file '" << filename << "'. ";
|
std::cout << "cppcheck: Failed to load library configuration file '" << filename << "'. ";
|
||||||
switch (err.errorcode) {
|
switch (err.errorcode) {
|
||||||
case Library::OK:
|
case Library::ErrorCode::OK:
|
||||||
break;
|
break;
|
||||||
case Library::FILE_NOT_FOUND:
|
case Library::ErrorCode::FILE_NOT_FOUND:
|
||||||
std::cout << "File not found";
|
std::cout << "File not found";
|
||||||
break;
|
break;
|
||||||
case Library::BAD_XML:
|
case Library::ErrorCode::BAD_XML:
|
||||||
std::cout << "Bad XML";
|
std::cout << "Bad XML";
|
||||||
break;
|
break;
|
||||||
case Library::UNKNOWN_ELEMENT:
|
case Library::ErrorCode::UNKNOWN_ELEMENT:
|
||||||
std::cout << "Unexpected element";
|
std::cout << "Unexpected element";
|
||||||
break;
|
break;
|
||||||
case Library::MISSING_ATTRIBUTE:
|
case Library::ErrorCode::MISSING_ATTRIBUTE:
|
||||||
std::cout << "Missing attribute";
|
std::cout << "Missing attribute";
|
||||||
break;
|
break;
|
||||||
case Library::BAD_ATTRIBUTE_VALUE:
|
case Library::ErrorCode::BAD_ATTRIBUTE_VALUE:
|
||||||
std::cout << "Bad attribute value";
|
std::cout << "Bad attribute value";
|
||||||
break;
|
break;
|
||||||
case Library::UNSUPPORTED_FORMAT:
|
case Library::ErrorCode::UNSUPPORTED_FORMAT:
|
||||||
std::cout << "File is of unsupported format version";
|
std::cout << "File is of unsupported format version";
|
||||||
break;
|
break;
|
||||||
case Library::DUPLICATE_PLATFORM_TYPE:
|
case Library::ErrorCode::DUPLICATE_PLATFORM_TYPE:
|
||||||
std::cout << "Duplicate platform type";
|
std::cout << "Duplicate platform type";
|
||||||
break;
|
break;
|
||||||
case Library::PLATFORM_TYPE_REDEFINED:
|
case Library::ErrorCode::PLATFORM_TYPE_REDEFINED:
|
||||||
std::cout << "Platform type redefined";
|
std::cout << "Platform type redefined";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -798,7 +798,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
|
||||||
{
|
{
|
||||||
const Library::Error error = loadLibrary(library, filename);
|
const Library::Error error = loadLibrary(library, filename);
|
||||||
if (error.errorcode != Library::ErrorCode::OK) {
|
if (error.errorcode != Library::ErrorCode::OK) {
|
||||||
if (error.errorcode == Library::UNKNOWN_ELEMENT) {
|
if (error.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT) {
|
||||||
QMessageBox::information(this, tr("Information"), tr("The library '%1' contains unknown elements:\n%2").arg(filename).arg(error.reason.c_str()));
|
QMessageBox::information(this, tr("Information"), tr("The library '%1' contains unknown elements:\n%2").arg(filename).arg(error.reason.c_str()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
|
||||||
Library lib;
|
Library lib;
|
||||||
const QString fullfilename = sp + "/" + library;
|
const QString fullfilename = sp + "/" + library;
|
||||||
const Library::Error err = lib.load(nullptr, fullfilename.toLatin1());
|
const Library::Error err = lib.load(nullptr, fullfilename.toLatin1());
|
||||||
if (err.errorcode != Library::OK)
|
if (err.errorcode != Library::ErrorCode::OK)
|
||||||
continue;
|
continue;
|
||||||
// Working std.cfg found
|
// Working std.cfg found
|
||||||
stdLibraryFilename = fullfilename;
|
stdLibraryFilename = fullfilename;
|
||||||
|
@ -135,12 +135,12 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
|
||||||
Library lib;
|
Library lib;
|
||||||
const QString fullfilename = sp + "/" + library;
|
const QString fullfilename = sp + "/" + library;
|
||||||
Library::Error err = lib.load(nullptr, fullfilename.toLatin1());
|
Library::Error err = lib.load(nullptr, fullfilename.toLatin1());
|
||||||
if (err.errorcode != Library::OK) {
|
if (err.errorcode != Library::ErrorCode::OK) {
|
||||||
// Some libraries depend on std.cfg so load it first and test again
|
// Some libraries depend on std.cfg so load it first and test again
|
||||||
lib.load(nullptr, stdLibraryFilename.toLatin1());
|
lib.load(nullptr, stdLibraryFilename.toLatin1());
|
||||||
err = lib.load(nullptr, fullfilename.toLatin1());
|
err = lib.load(nullptr, fullfilename.toLatin1());
|
||||||
}
|
}
|
||||||
if (err.errorcode != Library::OK)
|
if (err.errorcode != Library::ErrorCode::OK)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
library.chop(4);
|
library.chop(4);
|
||||||
|
|
|
@ -130,7 +130,7 @@ static void bufferOverflow(const Token *tok, const ExprEngine::Value &value, Exp
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Library::ArgumentChecks::MinSize &minsize: checks.minsizes) {
|
for (const Library::ArgumentChecks::MinSize &minsize: checks.minsizes) {
|
||||||
if (minsize.type == Library::ArgumentChecks::MinSize::ARGVALUE && minsize.arg > 0 && minsize.arg <= arguments.size()) {
|
if (minsize.type == Library::ArgumentChecks::MinSize::Type::ARGVALUE && minsize.arg > 0 && minsize.arg <= arguments.size()) {
|
||||||
ExprEngine::ValuePtr otherValue = functionCallArguments->argValues[minsize.arg - 1];
|
ExprEngine::ValuePtr otherValue = functionCallArguments->argValues[minsize.arg - 1];
|
||||||
if (!otherValue || otherValue->type == ExprEngine::ValueType::BailoutValue) {
|
if (!otherValue || otherValue->type == ExprEngine::ValueType::BailoutValue) {
|
||||||
overflowArgument = argnr;
|
overflowArgument = argnr;
|
||||||
|
@ -141,7 +141,7 @@ static void bufferOverflow(const Token *tok, const ExprEngine::Value &value, Exp
|
||||||
overflowArgument = argnr;
|
overflowArgument = argnr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (minsize.type == Library::ArgumentChecks::MinSize::STRLEN && minsize.arg > 0 && minsize.arg <= arguments.size()) {
|
} else if (minsize.type == Library::ArgumentChecks::MinSize::Type::STRLEN && minsize.arg > 0 && minsize.arg <= arguments.size()) {
|
||||||
if (func->formatstr) {
|
if (func->formatstr) {
|
||||||
// TODO: implement this properly. check if minsize refers to a format string and check max length of that..
|
// TODO: implement this properly. check if minsize refers to a format string and check max length of that..
|
||||||
overflowArgument = argnr;
|
overflowArgument = argnr;
|
||||||
|
@ -583,32 +583,32 @@ static void checkFunctionCall(const Token *tok, const ExprEngine::Value &value,
|
||||||
bool err = false;
|
bool err = false;
|
||||||
std::string bad;
|
std::string bad;
|
||||||
switch (invalidArgValue.type) {
|
switch (invalidArgValue.type) {
|
||||||
case Library::InvalidArgValue::eq:
|
case Library::InvalidArgValue::Type::eq:
|
||||||
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() == MathLib::toLongNumber(invalidArgValue.op1))
|
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() == MathLib::toLongNumber(invalidArgValue.op1))
|
||||||
err = value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
err = value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
||||||
bad = "equals " + invalidArgValue.op1;
|
bad = "equals " + invalidArgValue.op1;
|
||||||
break;
|
break;
|
||||||
case Library::InvalidArgValue::le:
|
case Library::InvalidArgValue::Type::le:
|
||||||
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() <= MathLib::toLongNumber(invalidArgValue.op1))
|
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() <= MathLib::toLongNumber(invalidArgValue.op1))
|
||||||
err = value.isLessThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1) + 1);
|
err = value.isLessThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1) + 1);
|
||||||
bad = "less equal " + invalidArgValue.op1;
|
bad = "less equal " + invalidArgValue.op1;
|
||||||
break;
|
break;
|
||||||
case Library::InvalidArgValue::lt:
|
case Library::InvalidArgValue::Type::lt:
|
||||||
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() < MathLib::toLongNumber(invalidArgValue.op1))
|
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() < MathLib::toLongNumber(invalidArgValue.op1))
|
||||||
err = value.isLessThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
err = value.isLessThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
||||||
bad = "less than " + invalidArgValue.op1;
|
bad = "less than " + invalidArgValue.op1;
|
||||||
break;
|
break;
|
||||||
case Library::InvalidArgValue::ge:
|
case Library::InvalidArgValue::Type::ge:
|
||||||
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() >= MathLib::toLongNumber(invalidArgValue.op1))
|
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() >= MathLib::toLongNumber(invalidArgValue.op1))
|
||||||
err = value.isGreaterThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1) - 1);
|
err = value.isGreaterThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1) - 1);
|
||||||
bad = "greater equal " + invalidArgValue.op1;
|
bad = "greater equal " + invalidArgValue.op1;
|
||||||
break;
|
break;
|
||||||
case Library::InvalidArgValue::gt:
|
case Library::InvalidArgValue::Type::gt:
|
||||||
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() > MathLib::toLongNumber(invalidArgValue.op1))
|
if (!tok->hasKnownIntValue() || tok->getKnownIntValue() > MathLib::toLongNumber(invalidArgValue.op1))
|
||||||
err = value.isGreaterThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
err = value.isGreaterThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
||||||
bad = "greater than " + invalidArgValue.op1;
|
bad = "greater than " + invalidArgValue.op1;
|
||||||
break;
|
break;
|
||||||
case Library::InvalidArgValue::range:
|
case Library::InvalidArgValue::Type::range:
|
||||||
// TODO
|
// TODO
|
||||||
err = value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
err = value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op1));
|
||||||
err |= value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op2));
|
err |= value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op2));
|
||||||
|
|
136
lib/library.cpp
136
lib/library.cpp
|
@ -69,7 +69,7 @@ Library::Error Library::load(const char exename[], const char path[])
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
break;
|
break;
|
||||||
const Error &e = load(exename, p.substr(0,pos).c_str());
|
const Error &e = load(exename, p.substr(0,pos).c_str());
|
||||||
if (e.errorcode != OK)
|
if (e.errorcode != ErrorCode::OK)
|
||||||
return e;
|
return e;
|
||||||
p = p.substr(pos+1);
|
p = p.substr(pos+1);
|
||||||
}
|
}
|
||||||
|
@ -120,26 +120,26 @@ Library::Error Library::load(const char exename[], const char path[])
|
||||||
if (error == tinyxml2::XML_SUCCESS) {
|
if (error == tinyxml2::XML_SUCCESS) {
|
||||||
if (mFiles.find(absolute_path) == mFiles.end()) {
|
if (mFiles.find(absolute_path) == mFiles.end()) {
|
||||||
Error err = load(doc);
|
Error err = load(doc);
|
||||||
if (err.errorcode == OK)
|
if (err.errorcode == ErrorCode::OK)
|
||||||
mFiles.insert(absolute_path);
|
mFiles.insert(absolute_path);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error(OK); // ignore duplicates
|
return Error(ErrorCode::OK); // ignore duplicates
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
|
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
|
||||||
return Error(FILE_NOT_FOUND);
|
return Error(ErrorCode::FILE_NOT_FOUND);
|
||||||
else {
|
else {
|
||||||
doc.PrintError();
|
doc.PrintError();
|
||||||
return Error(BAD_XML);
|
return Error(ErrorCode::BAD_XML);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Library::loadxmldata(const char xmldata[], std::size_t len)
|
bool Library::loadxmldata(const char xmldata[], std::size_t len)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (load(doc).errorcode == OK);
|
return (tinyxml2::XML_SUCCESS == doc.Parse(xmldata, len)) && (load(doc).errorcode == ErrorCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
|
@ -148,11 +148,11 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
|
|
||||||
if (rootnode == nullptr) {
|
if (rootnode == nullptr) {
|
||||||
doc.PrintError();
|
doc.PrintError();
|
||||||
return Error(BAD_XML);
|
return Error(ErrorCode::BAD_XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(rootnode->Name(),"def") != 0)
|
if (strcmp(rootnode->Name(),"def") != 0)
|
||||||
return Error(UNSUPPORTED_FORMAT, rootnode->Name());
|
return Error(ErrorCode::UNSUPPORTED_FORMAT, rootnode->Name());
|
||||||
|
|
||||||
const char* format_string = rootnode->Attribute("format");
|
const char* format_string = rootnode->Attribute("format");
|
||||||
int format = 1; // Assume format version 1 if nothing else is specified (very old .cfg files had no 'format' attribute)
|
int format = 1; // Assume format version 1 if nothing else is specified (very old .cfg files had no 'format' attribute)
|
||||||
|
@ -160,7 +160,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
format = atoi(format_string);
|
format = atoi(format_string);
|
||||||
|
|
||||||
if (format > 2 || format <= 0)
|
if (format > 2 || format <= 0)
|
||||||
return Error(UNSUPPORTED_FORMAT);
|
return Error(ErrorCode::UNSUPPORTED_FORMAT);
|
||||||
|
|
||||||
std::set<std::string> unknown_elements;
|
std::set<std::string> unknown_elements;
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (std::strncmp(bufferSize, "strdup", 6) == 0)
|
else if (std::strncmp(bufferSize, "strdup", 6) == 0)
|
||||||
temp.bufferSize = AllocFunc::BufferSize::strdup;
|
temp.bufferSize = AllocFunc::BufferSize::strdup;
|
||||||
else
|
else
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, bufferSize);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, bufferSize);
|
||||||
temp.bufferSizeArg1 = 1;
|
temp.bufferSizeArg1 = 1;
|
||||||
temp.bufferSizeArg2 = 2;
|
temp.bufferSizeArg2 = 2;
|
||||||
if (bufferSize[6] == 0) {
|
if (bufferSize[6] == 0) {
|
||||||
|
@ -225,7 +225,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
if (bufferSize[8] == ',' && bufferSize[9] >= '1' && bufferSize[9] <= '5')
|
if (bufferSize[8] == ',' && bufferSize[9] >= '1' && bufferSize[9] <= '5')
|
||||||
temp.bufferSizeArg2 = bufferSize[9] - '0';
|
temp.bufferSizeArg2 = bufferSize[9] - '0';
|
||||||
} else
|
} else
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, bufferSize);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memorynodename == "realloc") {
|
if (memorynodename == "realloc") {
|
||||||
|
@ -259,10 +259,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (nodename == "define") {
|
else if (nodename == "define") {
|
||||||
const char *name = node->Attribute("name");
|
const char *name = node->Attribute("name");
|
||||||
if (name == nullptr)
|
if (name == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "name");
|
||||||
const char *value = node->Attribute("value");
|
const char *value = node->Attribute("value");
|
||||||
if (value == nullptr)
|
if (value == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "value");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "value");
|
||||||
defines.push_back(std::string(name) +
|
defines.push_back(std::string(name) +
|
||||||
" " +
|
" " +
|
||||||
value);
|
value);
|
||||||
|
@ -271,7 +271,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (nodename == "function") {
|
else if (nodename == "function") {
|
||||||
const char *name = node->Attribute("name");
|
const char *name = node->Attribute("name");
|
||||||
if (name == nullptr)
|
if (name == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "name");
|
||||||
for (const std::string &s : getnames(name)) {
|
for (const std::string &s : getnames(name)) {
|
||||||
const Error &err = loadFunction(node, s, unknown_elements);
|
const Error &err = loadFunction(node, s, unknown_elements);
|
||||||
if (err.errorcode != ErrorCode::OK)
|
if (err.errorcode != ErrorCode::OK)
|
||||||
|
@ -288,7 +288,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
|
|
||||||
const char * const argString = reflectionnode->Attribute("arg");
|
const char * const argString = reflectionnode->Attribute("arg");
|
||||||
if (!argString)
|
if (!argString)
|
||||||
return Error(MISSING_ATTRIBUTE, "arg");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "arg");
|
||||||
|
|
||||||
mReflection[reflectionnode->GetText()] = atoi(argString);
|
mReflection[reflectionnode->GetText()] = atoi(argString);
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (nodename == "markup") {
|
else if (nodename == "markup") {
|
||||||
const char * const extension = node->Attribute("ext");
|
const char * const extension = node->Attribute("ext");
|
||||||
if (!extension)
|
if (!extension)
|
||||||
return Error(MISSING_ATTRIBUTE, "ext");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "ext");
|
||||||
mMarkupExtensions.insert(extension);
|
mMarkupExtensions.insert(extension);
|
||||||
|
|
||||||
mReportErrors[extension] = (node->Attribute("reporterrors", "true") != nullptr);
|
mReportErrors[extension] = (node->Attribute("reporterrors", "true") != nullptr);
|
||||||
|
@ -310,7 +310,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
if (strcmp(librarynode->Name(), "keyword") == 0) {
|
if (strcmp(librarynode->Name(), "keyword") == 0) {
|
||||||
const char* nodeName = librarynode->Attribute("name");
|
const char* nodeName = librarynode->Attribute("name");
|
||||||
if (nodeName == nullptr)
|
if (nodeName == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "name");
|
||||||
mKeywords[extension].insert(nodeName);
|
mKeywords[extension].insert(nodeName);
|
||||||
} else
|
} else
|
||||||
unknown_elements.insert(librarynode->Name());
|
unknown_elements.insert(librarynode->Name());
|
||||||
|
@ -326,7 +326,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
|
|
||||||
const char * const prefix = exporter->Attribute("prefix");
|
const char * const prefix = exporter->Attribute("prefix");
|
||||||
if (!prefix)
|
if (!prefix)
|
||||||
return Error(MISSING_ATTRIBUTE, "prefix");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "prefix");
|
||||||
|
|
||||||
for (const tinyxml2::XMLElement *e = exporter->FirstChildElement(); e; e = e->NextSiblingElement()) {
|
for (const tinyxml2::XMLElement *e = exporter->FirstChildElement(); e; e = e->NextSiblingElement()) {
|
||||||
const std::string ename = e->Name();
|
const std::string ename = e->Name();
|
||||||
|
@ -381,7 +381,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (nodename == "container") {
|
else if (nodename == "container") {
|
||||||
const char* const id = node->Attribute("id");
|
const char* const id = node->Attribute("id");
|
||||||
if (!id)
|
if (!id)
|
||||||
return Error(MISSING_ATTRIBUTE, "id");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "id");
|
||||||
|
|
||||||
Container& container = containers[id];
|
Container& container = containers[id];
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
if (i != containers.end())
|
if (i != containers.end())
|
||||||
container = i->second; // Take values from parent and overwrite them if necessary
|
container = i->second; // Take values from parent and overwrite them if necessary
|
||||||
else
|
else
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, inherits);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, inherits);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const startPattern = node->Attribute("startPattern");
|
const char* const startPattern = node->Attribute("startPattern");
|
||||||
|
@ -423,7 +423,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
|
|
||||||
const char* const functionName = functionNode->Attribute("name");
|
const char* const functionName = functionNode->Attribute("name");
|
||||||
if (!functionName)
|
if (!functionName)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "name");
|
||||||
|
|
||||||
const char* const action_ptr = functionNode->Attribute("action");
|
const char* const action_ptr = functionNode->Attribute("action");
|
||||||
Container::Action action = Container::Action::NO_ACTION;
|
Container::Action action = Container::Action::NO_ACTION;
|
||||||
|
@ -450,7 +450,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (actionName == "change")
|
else if (actionName == "change")
|
||||||
action = Container::Action::CHANGE;
|
action = Container::Action::CHANGE;
|
||||||
else
|
else
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, actionName);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, actionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const yield_ptr = functionNode->Attribute("yields");
|
const char* const yield_ptr = functionNode->Attribute("yields");
|
||||||
|
@ -476,7 +476,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (yieldName == "empty")
|
else if (yieldName == "empty")
|
||||||
yield = Container::Yield::EMPTY;
|
yield = Container::Yield::EMPTY;
|
||||||
else
|
else
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, yieldName);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, yieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
container.functions[functionName].action = action;
|
container.functions[functionName].action = action;
|
||||||
|
@ -541,23 +541,23 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (nodename == "podtype") {
|
else if (nodename == "podtype") {
|
||||||
const char * const name = node->Attribute("name");
|
const char * const name = node->Attribute("name");
|
||||||
if (!name)
|
if (!name)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "name");
|
||||||
PodType podType = {0};
|
PodType podType = {0};
|
||||||
podType.stdtype = PodType::NO;
|
podType.stdtype = PodType::Type::NO;
|
||||||
const char * const stdtype = node->Attribute("stdtype");
|
const char * const stdtype = node->Attribute("stdtype");
|
||||||
if (stdtype) {
|
if (stdtype) {
|
||||||
if (std::strcmp(stdtype, "bool") == 0)
|
if (std::strcmp(stdtype, "bool") == 0)
|
||||||
podType.stdtype = PodType::BOOL;
|
podType.stdtype = PodType::Type::BOOL;
|
||||||
else if (std::strcmp(stdtype, "char") == 0)
|
else if (std::strcmp(stdtype, "char") == 0)
|
||||||
podType.stdtype = PodType::CHAR;
|
podType.stdtype = PodType::Type::CHAR;
|
||||||
else if (std::strcmp(stdtype, "short") == 0)
|
else if (std::strcmp(stdtype, "short") == 0)
|
||||||
podType.stdtype = PodType::SHORT;
|
podType.stdtype = PodType::Type::SHORT;
|
||||||
else if (std::strcmp(stdtype, "int") == 0)
|
else if (std::strcmp(stdtype, "int") == 0)
|
||||||
podType.stdtype = PodType::INT;
|
podType.stdtype = PodType::Type::INT;
|
||||||
else if (std::strcmp(stdtype, "long") == 0)
|
else if (std::strcmp(stdtype, "long") == 0)
|
||||||
podType.stdtype = PodType::LONG;
|
podType.stdtype = PodType::Type::LONG;
|
||||||
else if (std::strcmp(stdtype, "long long") == 0)
|
else if (std::strcmp(stdtype, "long long") == 0)
|
||||||
podType.stdtype = PodType::LONGLONG;
|
podType.stdtype = PodType::Type::LONGLONG;
|
||||||
}
|
}
|
||||||
const char * const size = node->Attribute("size");
|
const char * const size = node->Attribute("size");
|
||||||
if (size)
|
if (size)
|
||||||
|
@ -572,10 +572,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
else if (nodename == "platformtype") {
|
else if (nodename == "platformtype") {
|
||||||
const char * const type_name = node->Attribute("name");
|
const char * const type_name = node->Attribute("name");
|
||||||
if (type_name == nullptr)
|
if (type_name == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "name");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "name");
|
||||||
const char *value = node->Attribute("value");
|
const char *value = node->Attribute("value");
|
||||||
if (value == nullptr)
|
if (value == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "value");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "value");
|
||||||
PlatformType type;
|
PlatformType type;
|
||||||
type.mType = value;
|
type.mType = value;
|
||||||
std::set<std::string> platform;
|
std::set<std::string> platform;
|
||||||
|
@ -584,7 +584,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
if (typenodename == "platform") {
|
if (typenodename == "platform") {
|
||||||
const char * const type_attribute = typenode->Attribute("type");
|
const char * const type_attribute = typenode->Attribute("type");
|
||||||
if (type_attribute == nullptr)
|
if (type_attribute == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "type");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "type");
|
||||||
platform.insert(type_attribute);
|
platform.insert(type_attribute);
|
||||||
} else if (typenodename == "signed")
|
} else if (typenodename == "signed")
|
||||||
type.mSigned = true;
|
type.mSigned = true;
|
||||||
|
@ -605,8 +605,8 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
const PlatformType * const type_ptr = platform_type(type_name, emptyString);
|
const PlatformType * const type_ptr = platform_type(type_name, emptyString);
|
||||||
if (type_ptr) {
|
if (type_ptr) {
|
||||||
if (*type_ptr == type)
|
if (*type_ptr == type)
|
||||||
return Error(DUPLICATE_PLATFORM_TYPE, type_name);
|
return Error(ErrorCode::DUPLICATE_PLATFORM_TYPE, type_name);
|
||||||
return Error(PLATFORM_TYPE_REDEFINED, type_name);
|
return Error(ErrorCode::PLATFORM_TYPE_REDEFINED, type_name);
|
||||||
}
|
}
|
||||||
mPlatformTypes[type_name] = type;
|
mPlatformTypes[type_name] = type;
|
||||||
} else {
|
} else {
|
||||||
|
@ -614,8 +614,8 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
const PlatformType * const type_ptr = platform_type(type_name, p);
|
const PlatformType * const type_ptr = platform_type(type_name, p);
|
||||||
if (type_ptr) {
|
if (type_ptr) {
|
||||||
if (*type_ptr == type)
|
if (*type_ptr == type)
|
||||||
return Error(DUPLICATE_PLATFORM_TYPE, type_name);
|
return Error(ErrorCode::DUPLICATE_PLATFORM_TYPE, type_name);
|
||||||
return Error(PLATFORM_TYPE_REDEFINED, type_name);
|
return Error(ErrorCode::PLATFORM_TYPE_REDEFINED, type_name);
|
||||||
}
|
}
|
||||||
mPlatforms[p].mPlatformTypes[type_name] = type;
|
mPlatforms[p].mPlatformTypes[type_name] = type;
|
||||||
}
|
}
|
||||||
|
@ -632,15 +632,15 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
if (++i != unknown_elements.end())
|
if (++i != unknown_elements.end())
|
||||||
str += ", ";
|
str += ", ";
|
||||||
}
|
}
|
||||||
return Error(UNKNOWN_ELEMENT, str);
|
return Error(ErrorCode::UNKNOWN_ELEMENT, str);
|
||||||
}
|
}
|
||||||
return Error(OK);
|
return Error(ErrorCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, const std::string &name, std::set<std::string> &unknown_elements)
|
Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, const std::string &name, std::set<std::string> &unknown_elements)
|
||||||
{
|
{
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return Error(OK);
|
return Error(ErrorCode::OK);
|
||||||
|
|
||||||
Function& func = functions[name];
|
Function& func = functions[name];
|
||||||
|
|
||||||
|
@ -681,7 +681,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
} else if (functionnodename == "arg") {
|
} else if (functionnodename == "arg") {
|
||||||
const char* argNrString = functionnode->Attribute("nr");
|
const char* argNrString = functionnode->Attribute("nr");
|
||||||
if (!argNrString)
|
if (!argNrString)
|
||||||
return Error(MISSING_ATTRIBUTE, "nr");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "nr");
|
||||||
const bool bAnyArg = strcmp(argNrString, "any") == 0;
|
const bool bAnyArg = strcmp(argNrString, "any") == 0;
|
||||||
const bool bVariadicArg = strcmp(argNrString, "variadic") == 0;
|
const bool bVariadicArg = strcmp(argNrString, "variadic") == 0;
|
||||||
const int nr = (bAnyArg || bVariadicArg) ? -1 : std::atoi(argNrString);
|
const int nr = (bAnyArg || bVariadicArg) ? -1 : std::atoi(argNrString);
|
||||||
|
@ -719,13 +719,13 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
// Validate the validation expression
|
// Validate the validation expression
|
||||||
const char *p = argnode->GetText();
|
const char *p = argnode->GetText();
|
||||||
if (!isCompliantValidationExpression(p))
|
if (!isCompliantValidationExpression(p))
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, (!p ? "\"\"" : argnode->GetText()));
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, (!p ? "\"\"" : argnode->GetText()));
|
||||||
// Set validation expression
|
// Set validation expression
|
||||||
ac.valid = argnode->GetText();
|
ac.valid = argnode->GetText();
|
||||||
} else if (argnodename == "minsize") {
|
} else if (argnodename == "minsize") {
|
||||||
const char *typeattr = argnode->Attribute("type");
|
const char *typeattr = argnode->Attribute("type");
|
||||||
if (!typeattr)
|
if (!typeattr)
|
||||||
return Error(MISSING_ATTRIBUTE, "type");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "type");
|
||||||
|
|
||||||
ArgumentChecks::MinSize::Type type;
|
ArgumentChecks::MinSize::Type type;
|
||||||
if (strcmp(typeattr,"strlen")==0)
|
if (strcmp(typeattr,"strlen")==0)
|
||||||
|
@ -739,37 +739,37 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
else if (strcmp(typeattr,"value")==0)
|
else if (strcmp(typeattr,"value")==0)
|
||||||
type = ArgumentChecks::MinSize::Type::VALUE;
|
type = ArgumentChecks::MinSize::Type::VALUE;
|
||||||
else
|
else
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, typeattr);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, typeattr);
|
||||||
|
|
||||||
if (type == ArgumentChecks::MinSize::Type::VALUE) {
|
if (type == ArgumentChecks::MinSize::Type::VALUE) {
|
||||||
const char *valueattr = argnode->Attribute("value");
|
const char *valueattr = argnode->Attribute("value");
|
||||||
if (!valueattr)
|
if (!valueattr)
|
||||||
return Error(MISSING_ATTRIBUTE, "value");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "value");
|
||||||
long long minsizevalue = 0;
|
long long minsizevalue = 0;
|
||||||
try {
|
try {
|
||||||
minsizevalue = MathLib::toLongNumber(valueattr);
|
minsizevalue = MathLib::toLongNumber(valueattr);
|
||||||
} catch (const InternalError&) {
|
} catch (const InternalError&) {
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, valueattr);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, valueattr);
|
||||||
}
|
}
|
||||||
if (minsizevalue <= 0)
|
if (minsizevalue <= 0)
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, valueattr);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, valueattr);
|
||||||
ac.minsizes.emplace_back(type, 0);
|
ac.minsizes.emplace_back(type, 0);
|
||||||
ac.minsizes.back().value = minsizevalue;
|
ac.minsizes.back().value = minsizevalue;
|
||||||
} else {
|
} else {
|
||||||
const char *argattr = argnode->Attribute("arg");
|
const char *argattr = argnode->Attribute("arg");
|
||||||
if (!argattr)
|
if (!argattr)
|
||||||
return Error(MISSING_ATTRIBUTE, "arg");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "arg");
|
||||||
if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9')
|
if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9')
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, argattr);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, argattr);
|
||||||
|
|
||||||
ac.minsizes.reserve(type == ArgumentChecks::MinSize::Type::MUL ? 2 : 1);
|
ac.minsizes.reserve(type == ArgumentChecks::MinSize::Type::MUL ? 2 : 1);
|
||||||
ac.minsizes.emplace_back(type, argattr[0] - '0');
|
ac.minsizes.emplace_back(type, argattr[0] - '0');
|
||||||
if (type == ArgumentChecks::MinSize::Type::MUL) {
|
if (type == ArgumentChecks::MinSize::Type::MUL) {
|
||||||
const char *arg2attr = argnode->Attribute("arg2");
|
const char *arg2attr = argnode->Attribute("arg2");
|
||||||
if (!arg2attr)
|
if (!arg2attr)
|
||||||
return Error(MISSING_ATTRIBUTE, "arg2");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "arg2");
|
||||||
if (strlen(arg2attr) != 1 || arg2attr[0]<'0' || arg2attr[0]>'9')
|
if (strlen(arg2attr) != 1 || arg2attr[0]<'0' || arg2attr[0]>'9')
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, arg2attr);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, arg2attr);
|
||||||
ac.minsizes.back().arg2 = arg2attr[0] - '0';
|
ac.minsizes.back().arg2 = arg2attr[0] - '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -801,20 +801,20 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
WarnInfo wi;
|
WarnInfo wi;
|
||||||
const char* const severity = functionnode->Attribute("severity");
|
const char* const severity = functionnode->Attribute("severity");
|
||||||
if (severity == nullptr)
|
if (severity == nullptr)
|
||||||
return Error(MISSING_ATTRIBUTE, "severity");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "severity");
|
||||||
wi.severity = Severity::fromString(severity);
|
wi.severity = Severity::fromString(severity);
|
||||||
|
|
||||||
const char* const cstd = functionnode->Attribute("cstd");
|
const char* const cstd = functionnode->Attribute("cstd");
|
||||||
if (cstd) {
|
if (cstd) {
|
||||||
if (!wi.standards.setC(cstd))
|
if (!wi.standards.setC(cstd))
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, cstd);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, cstd);
|
||||||
} else
|
} else
|
||||||
wi.standards.c = Standards::C89;
|
wi.standards.c = Standards::C89;
|
||||||
|
|
||||||
const char* const cppstd = functionnode->Attribute("cppstd");
|
const char* const cppstd = functionnode->Attribute("cppstd");
|
||||||
if (cppstd) {
|
if (cppstd) {
|
||||||
if (!wi.standards.setCPP(cppstd))
|
if (!wi.standards.setCPP(cppstd))
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, cppstd);
|
return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, cppstd);
|
||||||
} else
|
} else
|
||||||
wi.standards.cpp = Standards::CPP03;
|
wi.standards.cpp = Standards::CPP03;
|
||||||
|
|
||||||
|
@ -836,7 +836,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
} else {
|
} else {
|
||||||
const char * const message = functionnode->GetText();
|
const char * const message = functionnode->GetText();
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return Error(MISSING_ATTRIBUTE, "\"reason\" and \"alternatives\" or some text.");
|
return Error(ErrorCode::MISSING_ATTRIBUTE, "\"reason\" and \"alternatives\" or some text.");
|
||||||
} else
|
} else
|
||||||
wi.message = message;
|
wi.message = message;
|
||||||
}
|
}
|
||||||
|
@ -845,7 +845,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
} else
|
} else
|
||||||
unknown_elements.insert(functionnodename);
|
unknown_elements.insert(functionnodename);
|
||||||
}
|
}
|
||||||
return Error(OK);
|
return Error(ErrorCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Library::InvalidArgValue> Library::getInvalidArgValues(const std::string &validExpr)
|
std::vector<Library::InvalidArgValue> Library::getInvalidArgValues(const std::string &validExpr)
|
||||||
|
@ -857,16 +857,16 @@ std::vector<Library::InvalidArgValue> Library::getInvalidArgValues(const std::st
|
||||||
if (tok->str() == ",")
|
if (tok->str() == ",")
|
||||||
continue;
|
continue;
|
||||||
if (Token::Match(tok, ": %num%")) {
|
if (Token::Match(tok, ": %num%")) {
|
||||||
valid.push_back(InvalidArgValue{InvalidArgValue::le, tok->next()->str(), std::string()});
|
valid.push_back(InvalidArgValue{InvalidArgValue::Type::le, tok->next()->str(), std::string()});
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
} else if (Token::Match(tok, "%num% : %num%")) {
|
} else if (Token::Match(tok, "%num% : %num%")) {
|
||||||
valid.push_back(InvalidArgValue{InvalidArgValue::range, tok->str(), tok->strAt(2)});
|
valid.push_back(InvalidArgValue{InvalidArgValue::Type::range, tok->str(), tok->strAt(2)});
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
} else if (Token::Match(tok, "%num% :")) {
|
} else if (Token::Match(tok, "%num% :")) {
|
||||||
valid.push_back(InvalidArgValue{InvalidArgValue::ge, tok->str(), std::string()});
|
valid.push_back(InvalidArgValue{InvalidArgValue::Type::ge, tok->str(), std::string()});
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
} else if (Token::Match(tok, "%num%")) {
|
} else if (Token::Match(tok, "%num%")) {
|
||||||
valid.push_back(InvalidArgValue{InvalidArgValue::eq, tok->str(), std::string()});
|
valid.push_back(InvalidArgValue{InvalidArgValue::Type::eq, tok->str(), std::string()});
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -875,21 +875,21 @@ std::vector<Library::InvalidArgValue> Library::getInvalidArgValues(const std::st
|
||||||
if (valid.empty())
|
if (valid.empty())
|
||||||
return invalid;
|
return invalid;
|
||||||
|
|
||||||
if (valid[0].type == InvalidArgValue::ge || valid[0].type == InvalidArgValue::eq)
|
if (valid[0].type == InvalidArgValue::Type::ge || valid[0].type == InvalidArgValue::Type::eq)
|
||||||
invalid.push_back(InvalidArgValue{InvalidArgValue::lt, valid[0].op1, std::string()});
|
invalid.push_back(InvalidArgValue{InvalidArgValue::Type::lt, valid[0].op1, std::string()});
|
||||||
if (valid.back().type == InvalidArgValue::le || valid.back().type == InvalidArgValue::eq)
|
if (valid.back().type == InvalidArgValue::Type::le || valid.back().type == InvalidArgValue::Type::eq)
|
||||||
invalid.push_back(InvalidArgValue{InvalidArgValue::gt, valid[0].op1, std::string()});
|
invalid.push_back(InvalidArgValue{InvalidArgValue::Type::gt, valid[0].op1, std::string()});
|
||||||
for (int i = 0; i + 1 < valid.size(); i++) {
|
for (int i = 0; i + 1 < valid.size(); i++) {
|
||||||
const InvalidArgValue &v1 = valid[i];
|
const InvalidArgValue &v1 = valid[i];
|
||||||
const InvalidArgValue &v2 = valid[i + 1];
|
const InvalidArgValue &v2 = valid[i + 1];
|
||||||
if (v1.type == InvalidArgValue::le && v2.type == InvalidArgValue::ge) {
|
if (v1.type == InvalidArgValue::Type::le && v2.type == InvalidArgValue::Type::ge) {
|
||||||
if (v1.isInt()) {
|
if (v1.isInt()) {
|
||||||
MathLib::bigint op1 = MathLib::toLongNumber(v1.op1);
|
MathLib::bigint op1 = MathLib::toLongNumber(v1.op1);
|
||||||
MathLib::bigint op2 = MathLib::toLongNumber(v2.op1);
|
MathLib::bigint op2 = MathLib::toLongNumber(v2.op1);
|
||||||
if (op1 + 1 == op2 - 1)
|
if (op1 + 1 == op2 - 1)
|
||||||
invalid.push_back(InvalidArgValue{InvalidArgValue::eq, MathLib::toString(op1 + 1), std::string()});
|
invalid.push_back(InvalidArgValue{InvalidArgValue::Type::eq, MathLib::toString(op1 + 1), std::string()});
|
||||||
else
|
else
|
||||||
invalid.push_back(InvalidArgValue{InvalidArgValue::range, MathLib::toString(op1 + 1), MathLib::toString(op2 - 1)});
|
invalid.push_back(InvalidArgValue{InvalidArgValue::Type::range, MathLib::toString(op1 + 1), MathLib::toString(op2 - 1)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,11 @@ class CPPCHECKLIB Library {
|
||||||
public:
|
public:
|
||||||
Library();
|
Library();
|
||||||
|
|
||||||
enum ErrorCode { OK, FILE_NOT_FOUND, BAD_XML, UNKNOWN_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE_VALUE, UNSUPPORTED_FORMAT, DUPLICATE_PLATFORM_TYPE, PLATFORM_TYPE_REDEFINED };
|
enum class ErrorCode { OK, FILE_NOT_FOUND, BAD_XML, UNKNOWN_ELEMENT, MISSING_ATTRIBUTE, BAD_ATTRIBUTE_VALUE, UNSUPPORTED_FORMAT, DUPLICATE_PLATFORM_TYPE, PLATFORM_TYPE_REDEFINED };
|
||||||
|
|
||||||
class Error {
|
class Error {
|
||||||
public:
|
public:
|
||||||
Error() : errorcode(OK) {}
|
Error() : errorcode(ErrorCode::OK) {}
|
||||||
explicit Error(ErrorCode e) : errorcode(e) {}
|
explicit Error(ErrorCode e) : errorcode(e) {}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Error(ErrorCode e, T&& r) : errorcode(e), reason(r) {}
|
Error(ErrorCode e, T&& r) : errorcode(e), reason(r) {}
|
||||||
|
@ -283,7 +283,7 @@ public:
|
||||||
|
|
||||||
class MinSize {
|
class MinSize {
|
||||||
public:
|
public:
|
||||||
enum Type { NONE, STRLEN, ARGVALUE, SIZEOF, MUL, VALUE };
|
enum class Type { NONE, STRLEN, ARGVALUE, SIZEOF, MUL, VALUE };
|
||||||
MinSize(Type t, int a) : type(t), arg(a), arg2(0), value(0) {}
|
MinSize(Type t, int a) : type(t), arg(a), arg2(0), value(0) {}
|
||||||
Type type;
|
Type type;
|
||||||
int arg;
|
int arg;
|
||||||
|
@ -349,7 +349,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InvalidArgValue {
|
struct InvalidArgValue {
|
||||||
enum Type {le, lt, eq, ge, gt, range} type;
|
enum class Type {le, lt, eq, ge, gt, range} type;
|
||||||
std::string op1;
|
std::string op1;
|
||||||
std::string op2;
|
std::string op2;
|
||||||
bool isInt() const {
|
bool isInt() const {
|
||||||
|
@ -428,7 +428,7 @@ public:
|
||||||
struct PodType {
|
struct PodType {
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
char sign;
|
char sign;
|
||||||
enum { NO, BOOL, CHAR, SHORT, INT, LONG, LONGLONG } stdtype;
|
enum class Type { NO, BOOL, CHAR, SHORT, INT, LONG, LONGLONG } stdtype;
|
||||||
};
|
};
|
||||||
const struct PodType *podtype(const std::string &name) const {
|
const struct PodType *podtype(const std::string &name) const {
|
||||||
const std::map<std::string, struct PodType>::const_iterator it = mPodTypes.find(name);
|
const std::map<std::string, struct PodType>::const_iterator it = mPodTypes.find(name);
|
||||||
|
|
|
@ -6419,17 +6419,17 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett
|
||||||
type = ValueType::Type::LONG;
|
type = ValueType::Type::LONG;
|
||||||
else if (podtype->size == settings->sizeof_long_long)
|
else if (podtype->size == settings->sizeof_long_long)
|
||||||
type = ValueType::Type::LONGLONG;
|
type = ValueType::Type::LONGLONG;
|
||||||
else if (podtype->stdtype == Library::PodType::BOOL)
|
else if (podtype->stdtype == Library::PodType::Type::BOOL)
|
||||||
type = ValueType::Type::BOOL;
|
type = ValueType::Type::BOOL;
|
||||||
else if (podtype->stdtype == Library::PodType::CHAR)
|
else if (podtype->stdtype == Library::PodType::Type::CHAR)
|
||||||
type = ValueType::Type::CHAR;
|
type = ValueType::Type::CHAR;
|
||||||
else if (podtype->stdtype == Library::PodType::SHORT)
|
else if (podtype->stdtype == Library::PodType::Type::SHORT)
|
||||||
type = ValueType::Type::SHORT;
|
type = ValueType::Type::SHORT;
|
||||||
else if (podtype->stdtype == Library::PodType::INT)
|
else if (podtype->stdtype == Library::PodType::Type::INT)
|
||||||
type = ValueType::Type::INT;
|
type = ValueType::Type::INT;
|
||||||
else if (podtype->stdtype == Library::PodType::LONG)
|
else if (podtype->stdtype == Library::PodType::Type::LONG)
|
||||||
type = ValueType::Type::LONG;
|
type = ValueType::Type::LONG;
|
||||||
else if (podtype->stdtype == Library::PodType::LONGLONG)
|
else if (podtype->stdtype == Library::PodType::Type::LONGLONG)
|
||||||
type = ValueType::Type::LONGLONG;
|
type = ValueType::Type::LONGLONG;
|
||||||
else
|
else
|
||||||
type = ValueType::Type::UNKNOWN_INT;
|
type = ValueType::Type::UNKNOWN_INT;
|
||||||
|
|
|
@ -96,7 +96,7 @@ private:
|
||||||
// Reading an empty library file is considered to be OK
|
// Reading an empty library file is considered to be OK
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ private:
|
||||||
tokenList.front()->next()->astOperand1(tokenList.front());
|
tokenList.front()->next()->astOperand1(tokenList.front());
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT_EQUALS(library.functions.size(), 1U);
|
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||||
ASSERT(library.functions.at("foo").argumentChecks.empty());
|
ASSERT(library.functions.at("foo").argumentChecks.empty());
|
||||||
ASSERT(library.isnotnoreturn(tokenList.front()));
|
ASSERT(library.isnotnoreturn(tokenList.front()));
|
||||||
|
@ -129,7 +129,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
{
|
{
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function
|
std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function
|
||||||
|
@ -161,7 +161,7 @@ private:
|
||||||
tokenList.createAst();
|
tokenList.createAst();
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT(library.isNotLibraryFunction(tokenList.front()));
|
ASSERT(library.isNotLibraryFunction(tokenList.front()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
{
|
{
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
|
@ -230,7 +230,7 @@ private:
|
||||||
tokenList.front()->next()->varId(1);
|
tokenList.front()->next()->varId(1);
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT(library.isNotLibraryFunction(tokenList.front()->next()));
|
ASSERT(library.isNotLibraryFunction(tokenList.front()->next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[1].notuninit);
|
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[1].notuninit);
|
||||||
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[2].notnull);
|
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[2].notnull);
|
||||||
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[3].formatstr);
|
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[3].formatstr);
|
||||||
|
@ -266,7 +266,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
|
@ -306,7 +306,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("foo(a,b,c,d);");
|
std::istringstream istr("foo(a,b,c,d);");
|
||||||
|
@ -337,7 +337,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j);");
|
std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j);");
|
||||||
|
@ -473,7 +473,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("foo(a,b,c,d);");
|
std::istringstream istr("foo(a,b,c,d);");
|
||||||
|
@ -486,7 +486,7 @@ private:
|
||||||
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
||||||
if (minsizes && minsizes->size() == 1U) {
|
if (minsizes && minsizes->size() == 1U) {
|
||||||
const Library::ArgumentChecks::MinSize &m = minsizes->front();
|
const Library::ArgumentChecks::MinSize &m = minsizes->front();
|
||||||
ASSERT_EQUALS(Library::ArgumentChecks::MinSize::STRLEN, m.type);
|
ASSERT_EQUALS(true, Library::ArgumentChecks::MinSize::Type::STRLEN == m.type);
|
||||||
ASSERT_EQUALS(2, m.arg);
|
ASSERT_EQUALS(2, m.arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ private:
|
||||||
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
||||||
if (minsizes && minsizes->size() == 1U) {
|
if (minsizes && minsizes->size() == 1U) {
|
||||||
const Library::ArgumentChecks::MinSize &m = minsizes->front();
|
const Library::ArgumentChecks::MinSize &m = minsizes->front();
|
||||||
ASSERT_EQUALS(Library::ArgumentChecks::MinSize::ARGVALUE, m.type);
|
ASSERT_EQUALS(true, Library::ArgumentChecks::MinSize::Type::ARGVALUE == m.type);
|
||||||
ASSERT_EQUALS(3, m.arg);
|
ASSERT_EQUALS(3, m.arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +506,7 @@ private:
|
||||||
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
||||||
if (minsizes && minsizes->size() == 1U) {
|
if (minsizes && minsizes->size() == 1U) {
|
||||||
const Library::ArgumentChecks::MinSize &m = minsizes->front();
|
const Library::ArgumentChecks::MinSize &m = minsizes->front();
|
||||||
ASSERT_EQUALS(Library::ArgumentChecks::MinSize::VALUE, m.type);
|
ASSERT(Library::ArgumentChecks::MinSize::Type::VALUE == m.type);
|
||||||
ASSERT_EQUALS(500, m.value);
|
ASSERT_EQUALS(500, m.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,7 +520,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT_EQUALS(library.functions.size(), 2U);
|
ASSERT_EQUALS(library.functions.size(), 2U);
|
||||||
ASSERT(library.functions.at("Foo::foo").argumentChecks.empty());
|
ASSERT(library.functions.at("Foo::foo").argumentChecks.empty());
|
||||||
ASSERT(library.functions.at("bar").argumentChecks.empty());
|
ASSERT(library.functions.at("bar").argumentChecks.empty());
|
||||||
|
@ -549,7 +549,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT_EQUALS(library.functions.size(), 1U);
|
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -576,7 +576,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(&settings, nullptr);
|
Tokenizer tokenizer(&settings, nullptr);
|
||||||
|
@ -605,7 +605,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("a(); b();");
|
std::istringstream istr("a(); b();");
|
||||||
|
@ -639,7 +639,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
|
|
||||||
ASSERT(Library::ismemory(library.getAllocFuncInfo("CreateX")));
|
ASSERT(Library::ismemory(library.getAllocFuncInfo("CreateX")));
|
||||||
|
@ -682,7 +682,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
|
|
||||||
const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX");
|
const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX");
|
||||||
|
@ -701,7 +701,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
|
|
||||||
ASSERT(Library::isresource(library.allocId("CreateX")));
|
ASSERT(Library::isresource(library.allocId("CreateX")));
|
||||||
|
@ -718,7 +718,7 @@ private:
|
||||||
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
|
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
// s8
|
// s8
|
||||||
{
|
{
|
||||||
const struct Library::PodType * const type = library.podtype("s8");
|
const struct Library::PodType * const type = library.podtype("s8");
|
||||||
|
@ -796,7 +796,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
||||||
|
|
||||||
Library::Container& A = library.containers["A"];
|
Library::Container& A = library.containers["A"];
|
||||||
Library::Container& B = library.containers["B"];
|
Library::Container& B = library.containers["B"];
|
||||||
|
@ -848,7 +848,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
const Library::Error err = readLibrary(library, xmldata);
|
const Library::Error err = readLibrary(library, xmldata);
|
||||||
ASSERT_EQUALS(err.errorcode, Library::OK);
|
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const char xmldata [] = "<?xml version=\"1.0\"?>\n"
|
const char xmldata [] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -856,7 +856,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
const Library::Error err = readLibrary(library, xmldata);
|
const Library::Error err = readLibrary(library, xmldata);
|
||||||
ASSERT_EQUALS(err.errorcode, Library::OK);
|
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const char xmldata [] = "<?xml version=\"1.0\"?>\n"
|
const char xmldata [] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -864,13 +864,13 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
const Library::Error err = readLibrary(library, xmldata);
|
const Library::Error err = readLibrary(library, xmldata);
|
||||||
ASSERT_EQUALS(err.errorcode, Library::UNSUPPORTED_FORMAT);
|
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::UNSUPPORTED_FORMAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadLibError(const char xmldata [], Library::ErrorCode errorcode, const char* file, unsigned line) const {
|
void loadLibError(const char xmldata [], Library::ErrorCode errorcode, const char* file, unsigned line) const {
|
||||||
Library library;
|
Library library;
|
||||||
assertEquals(file, line, errorcode, readLibrary(library, xmldata).errorcode);
|
assertEquals(file, line, true, errorcode == readLibrary(library, xmldata).errorcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOADLIBERROR(xmldata, errorcode) loadLibError(xmldata, errorcode, __FILE__, __LINE__)
|
#define LOADLIBERROR(xmldata, errorcode) loadLibError(xmldata, errorcode, __FILE__, __LINE__)
|
||||||
|
@ -882,7 +882,7 @@ private:
|
||||||
"</arg>\n" \
|
"</arg>\n" \
|
||||||
"</function>\n" \
|
"</function>\n" \
|
||||||
"</def>", \
|
"</def>", \
|
||||||
Library::BAD_ATTRIBUTE_VALUE)
|
Library::ErrorCode::BAD_ATTRIBUTE_VALUE)
|
||||||
|
|
||||||
void loadLibErrors() const {
|
void loadLibErrors() const {
|
||||||
|
|
||||||
|
@ -890,32 +890,32 @@ private:
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
" <X name=\"uint8_t,std::uint8_t\" size=\"1\"/>\n"
|
" <X name=\"uint8_t,std::uint8_t\" size=\"1\"/>\n"
|
||||||
"</def>",
|
"</def>",
|
||||||
Library::UNKNOWN_ELEMENT);
|
Library::ErrorCode::UNKNOWN_ELEMENT);
|
||||||
|
|
||||||
// #define without attributes
|
// #define without attributes
|
||||||
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
" <define />\n" // no attributes provided at all
|
" <define />\n" // no attributes provided at all
|
||||||
"</def>",
|
"</def>",
|
||||||
Library::MISSING_ATTRIBUTE);
|
Library::ErrorCode::MISSING_ATTRIBUTE);
|
||||||
|
|
||||||
// #define with name but without value
|
// #define with name but without value
|
||||||
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
" <define name=\"foo\" />\n" // no value provided
|
" <define name=\"foo\" />\n" // no value provided
|
||||||
"</def>",
|
"</def>",
|
||||||
Library::MISSING_ATTRIBUTE);
|
Library::ErrorCode::MISSING_ATTRIBUTE);
|
||||||
|
|
||||||
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
" <define value=\"1\" />\n" // no name provided
|
" <define value=\"1\" />\n" // no name provided
|
||||||
"</def>",
|
"</def>",
|
||||||
Library::MISSING_ATTRIBUTE);
|
Library::ErrorCode::MISSING_ATTRIBUTE);
|
||||||
|
|
||||||
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
LOADLIBERROR("<?xml version=\"1.0\"?>\n"
|
||||||
"<X>\n"
|
"<X>\n"
|
||||||
"</X>",
|
"</X>",
|
||||||
Library::UNSUPPORTED_FORMAT);
|
Library::ErrorCode::UNSUPPORTED_FORMAT);
|
||||||
|
|
||||||
// empty range
|
// empty range
|
||||||
LOADLIB_ERROR_INVALID_RANGE("");
|
LOADLIB_ERROR_INVALID_RANGE("");
|
||||||
|
|
|
@ -114,9 +114,9 @@ extern std::ostringstream output;
|
||||||
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; }
|
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; }
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define LOAD_LIB_2( LIB, NAME ) do { { if (((LIB).load("./testrunner", "../cfg/" NAME).errorcode != Library::OK) && ((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::OK)) { complainMissingLib(NAME); return; } } } while(false)
|
#define LOAD_LIB_2( LIB, NAME ) do { { if (((LIB).load("./testrunner", "../cfg/" NAME).errorcode != Library::ErrorCode::OK) && ((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::ErrorCode::OK)) { complainMissingLib(NAME); return; } } } while(false)
|
||||||
#else
|
#else
|
||||||
#define LOAD_LIB_2( LIB, NAME ) do { { if (((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::OK) && ((LIB).load("./bin/testrunner", "bin/cfg/" NAME).errorcode != Library::OK)) { complainMissingLib(NAME); return; } } } while(false)
|
#define LOAD_LIB_2( LIB, NAME ) do { { if (((LIB).load("./testrunner", "cfg/" NAME).errorcode != Library::ErrorCode::OK) && ((LIB).load("./bin/testrunner", "bin/cfg/" NAME).errorcode != Library::ErrorCode::OK)) { complainMissingLib(NAME); return; } } } while(false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7009,7 +7009,7 @@ private:
|
||||||
Settings settingsWin64;
|
Settings settingsWin64;
|
||||||
settingsWin64.platformType = Settings::Win64;
|
settingsWin64.platformType = Settings::Win64;
|
||||||
const Library::PodType u32 = { 4, 'u' };
|
const Library::PodType u32 = { 4, 'u' };
|
||||||
const Library::PodType podtype2 = { 0, 'u', Library::PodType::INT };
|
const Library::PodType podtype2 = { 0, 'u', Library::PodType::Type::INT };
|
||||||
settingsWin64.library.mPodTypes["u32"] = u32;
|
settingsWin64.library.mPodTypes["u32"] = u32;
|
||||||
settingsWin64.library.mPodTypes["xyz::x"] = u32;
|
settingsWin64.library.mPodTypes["xyz::x"] = u32;
|
||||||
settingsWin64.library.mPodTypes["podtype2"] = podtype2;
|
settingsWin64.library.mPodTypes["podtype2"] = podtype2;
|
||||||
|
|
Loading…
Reference in New Issue