diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index e34feb90b..8dc433b80 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -1126,35 +1126,35 @@ bool CppCheckExecutor::tryLoadLibrary(Library& destination, const char* basepath { 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; - else if (err.errorcode != Library::OK) { + else if (err.errorcode != Library::ErrorCode::OK) { std::cout << "cppcheck: Failed to load library configuration file '" << filename << "'. "; switch (err.errorcode) { - case Library::OK: + case Library::ErrorCode::OK: break; - case Library::FILE_NOT_FOUND: + case Library::ErrorCode::FILE_NOT_FOUND: std::cout << "File not found"; break; - case Library::BAD_XML: + case Library::ErrorCode::BAD_XML: std::cout << "Bad XML"; break; - case Library::UNKNOWN_ELEMENT: + case Library::ErrorCode::UNKNOWN_ELEMENT: std::cout << "Unexpected element"; break; - case Library::MISSING_ATTRIBUTE: + case Library::ErrorCode::MISSING_ATTRIBUTE: std::cout << "Missing attribute"; break; - case Library::BAD_ATTRIBUTE_VALUE: + case Library::ErrorCode::BAD_ATTRIBUTE_VALUE: std::cout << "Bad attribute value"; break; - case Library::UNSUPPORTED_FORMAT: + case Library::ErrorCode::UNSUPPORTED_FORMAT: std::cout << "File is of unsupported format version"; break; - case Library::DUPLICATE_PLATFORM_TYPE: + case Library::ErrorCode::DUPLICATE_PLATFORM_TYPE: std::cout << "Duplicate platform type"; break; - case Library::PLATFORM_TYPE_REDEFINED: + case Library::ErrorCode::PLATFORM_TYPE_REDEFINED: std::cout << "Platform type redefined"; break; } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 9a8e38ed6..e5f234ad6 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -798,7 +798,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename) { const Library::Error error = loadLibrary(library, filename); 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())); return true; } diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index ac0e7b277..016b9999e 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -114,7 +114,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent) Library lib; const QString fullfilename = sp + "/" + library; const Library::Error err = lib.load(nullptr, fullfilename.toLatin1()); - if (err.errorcode != Library::OK) + if (err.errorcode != Library::ErrorCode::OK) continue; // Working std.cfg found stdLibraryFilename = fullfilename; @@ -135,12 +135,12 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent) Library lib; const QString fullfilename = sp + "/" + library; 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 lib.load(nullptr, stdLibraryFilename.toLatin1()); err = lib.load(nullptr, fullfilename.toLatin1()); } - if (err.errorcode != Library::OK) + if (err.errorcode != Library::ErrorCode::OK) continue; } library.chop(4); diff --git a/lib/bughuntingchecks.cpp b/lib/bughuntingchecks.cpp index 7c2028580..5ca7a4733 100644 --- a/lib/bughuntingchecks.cpp +++ b/lib/bughuntingchecks.cpp @@ -130,7 +130,7 @@ static void bufferOverflow(const Token *tok, const ExprEngine::Value &value, Exp } 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]; if (!otherValue || otherValue->type == ExprEngine::ValueType::BailoutValue) { overflowArgument = argnr; @@ -141,7 +141,7 @@ static void bufferOverflow(const Token *tok, const ExprEngine::Value &value, Exp overflowArgument = argnr; 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) { // TODO: implement this properly. check if minsize refers to a format string and check max length of that.. overflowArgument = argnr; @@ -583,32 +583,32 @@ static void checkFunctionCall(const Token *tok, const ExprEngine::Value &value, bool err = false; std::string bad; switch (invalidArgValue.type) { - case Library::InvalidArgValue::eq: + case Library::InvalidArgValue::Type::eq: if (!tok->hasKnownIntValue() || tok->getKnownIntValue() == MathLib::toLongNumber(invalidArgValue.op1)) err = value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op1)); bad = "equals " + invalidArgValue.op1; break; - case Library::InvalidArgValue::le: + case Library::InvalidArgValue::Type::le: if (!tok->hasKnownIntValue() || tok->getKnownIntValue() <= MathLib::toLongNumber(invalidArgValue.op1)) err = value.isLessThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1) + 1); bad = "less equal " + invalidArgValue.op1; break; - case Library::InvalidArgValue::lt: + case Library::InvalidArgValue::Type::lt: if (!tok->hasKnownIntValue() || tok->getKnownIntValue() < MathLib::toLongNumber(invalidArgValue.op1)) err = value.isLessThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1)); bad = "less than " + invalidArgValue.op1; break; - case Library::InvalidArgValue::ge: + case Library::InvalidArgValue::Type::ge: if (!tok->hasKnownIntValue() || tok->getKnownIntValue() >= MathLib::toLongNumber(invalidArgValue.op1)) err = value.isGreaterThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1) - 1); bad = "greater equal " + invalidArgValue.op1; break; - case Library::InvalidArgValue::gt: + case Library::InvalidArgValue::Type::gt: if (!tok->hasKnownIntValue() || tok->getKnownIntValue() > MathLib::toLongNumber(invalidArgValue.op1)) err = value.isGreaterThan(dataBase, MathLib::toLongNumber(invalidArgValue.op1)); bad = "greater than " + invalidArgValue.op1; break; - case Library::InvalidArgValue::range: + case Library::InvalidArgValue::Type::range: // TODO err = value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op1)); err |= value.isEqual(dataBase, MathLib::toLongNumber(invalidArgValue.op2)); diff --git a/lib/library.cpp b/lib/library.cpp index f6187d2f2..50ad74780 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -69,7 +69,7 @@ Library::Error Library::load(const char exename[], const char path[]) if (pos == std::string::npos) break; const Error &e = load(exename, p.substr(0,pos).c_str()); - if (e.errorcode != OK) + if (e.errorcode != ErrorCode::OK) return e; 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 (mFiles.find(absolute_path) == mFiles.end()) { Error err = load(doc); - if (err.errorcode == OK) + if (err.errorcode == ErrorCode::OK) mFiles.insert(absolute_path); return err; } - return Error(OK); // ignore duplicates + return Error(ErrorCode::OK); // ignore duplicates } if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) - return Error(FILE_NOT_FOUND); + return Error(ErrorCode::FILE_NOT_FOUND); else { doc.PrintError(); - return Error(BAD_XML); + return Error(ErrorCode::BAD_XML); } } bool Library::loadxmldata(const char xmldata[], std::size_t len) { 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) @@ -148,11 +148,11 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) if (rootnode == nullptr) { doc.PrintError(); - return Error(BAD_XML); + return Error(ErrorCode::BAD_XML); } 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"); 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); if (format > 2 || format <= 0) - return Error(UNSUPPORTED_FORMAT); + return Error(ErrorCode::UNSUPPORTED_FORMAT); std::set unknown_elements; @@ -215,7 +215,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (std::strncmp(bufferSize, "strdup", 6) == 0) temp.bufferSize = AllocFunc::BufferSize::strdup; else - return Error(BAD_ATTRIBUTE_VALUE, bufferSize); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, bufferSize); temp.bufferSizeArg1 = 1; temp.bufferSizeArg2 = 2; 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') temp.bufferSizeArg2 = bufferSize[9] - '0'; } else - return Error(BAD_ATTRIBUTE_VALUE, bufferSize); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, bufferSize); } if (memorynodename == "realloc") { @@ -259,10 +259,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (nodename == "define") { const char *name = node->Attribute("name"); if (name == nullptr) - return Error(MISSING_ATTRIBUTE, "name"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "name"); const char *value = node->Attribute("value"); if (value == nullptr) - return Error(MISSING_ATTRIBUTE, "value"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "value"); defines.push_back(std::string(name) + " " + value); @@ -271,7 +271,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (nodename == "function") { const char *name = node->Attribute("name"); if (name == nullptr) - return Error(MISSING_ATTRIBUTE, "name"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "name"); for (const std::string &s : getnames(name)) { const Error &err = loadFunction(node, s, unknown_elements); if (err.errorcode != ErrorCode::OK) @@ -288,7 +288,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) const char * const argString = reflectionnode->Attribute("arg"); if (!argString) - return Error(MISSING_ATTRIBUTE, "arg"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "arg"); mReflection[reflectionnode->GetText()] = atoi(argString); } @@ -297,7 +297,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (nodename == "markup") { const char * const extension = node->Attribute("ext"); if (!extension) - return Error(MISSING_ATTRIBUTE, "ext"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "ext"); mMarkupExtensions.insert(extension); 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) { const char* nodeName = librarynode->Attribute("name"); if (nodeName == nullptr) - return Error(MISSING_ATTRIBUTE, "name"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "name"); mKeywords[extension].insert(nodeName); } else unknown_elements.insert(librarynode->Name()); @@ -326,7 +326,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) const char * const prefix = exporter->Attribute("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()) { const std::string ename = e->Name(); @@ -381,7 +381,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (nodename == "container") { const char* const id = node->Attribute("id"); if (!id) - return Error(MISSING_ATTRIBUTE, "id"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "id"); Container& container = containers[id]; @@ -391,7 +391,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) if (i != containers.end()) container = i->second; // Take values from parent and overwrite them if necessary else - return Error(BAD_ATTRIBUTE_VALUE, inherits); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, inherits); } 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"); if (!functionName) - return Error(MISSING_ATTRIBUTE, "name"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "name"); const char* const action_ptr = functionNode->Attribute("action"); Container::Action action = Container::Action::NO_ACTION; @@ -450,7 +450,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (actionName == "change") action = Container::Action::CHANGE; else - return Error(BAD_ATTRIBUTE_VALUE, actionName); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, actionName); } const char* const yield_ptr = functionNode->Attribute("yields"); @@ -476,7 +476,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (yieldName == "empty") yield = Container::Yield::EMPTY; else - return Error(BAD_ATTRIBUTE_VALUE, yieldName); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, yieldName); } container.functions[functionName].action = action; @@ -541,23 +541,23 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (nodename == "podtype") { const char * const name = node->Attribute("name"); if (!name) - return Error(MISSING_ATTRIBUTE, "name"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "name"); PodType podType = {0}; - podType.stdtype = PodType::NO; + podType.stdtype = PodType::Type::NO; const char * const stdtype = node->Attribute("stdtype"); if (stdtype) { if (std::strcmp(stdtype, "bool") == 0) - podType.stdtype = PodType::BOOL; + podType.stdtype = PodType::Type::BOOL; else if (std::strcmp(stdtype, "char") == 0) - podType.stdtype = PodType::CHAR; + podType.stdtype = PodType::Type::CHAR; else if (std::strcmp(stdtype, "short") == 0) - podType.stdtype = PodType::SHORT; + podType.stdtype = PodType::Type::SHORT; else if (std::strcmp(stdtype, "int") == 0) - podType.stdtype = PodType::INT; + podType.stdtype = PodType::Type::INT; else if (std::strcmp(stdtype, "long") == 0) - podType.stdtype = PodType::LONG; + podType.stdtype = PodType::Type::LONG; else if (std::strcmp(stdtype, "long long") == 0) - podType.stdtype = PodType::LONGLONG; + podType.stdtype = PodType::Type::LONGLONG; } const char * const size = node->Attribute("size"); if (size) @@ -572,10 +572,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (nodename == "platformtype") { const char * const type_name = node->Attribute("name"); if (type_name == nullptr) - return Error(MISSING_ATTRIBUTE, "name"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "name"); const char *value = node->Attribute("value"); if (value == nullptr) - return Error(MISSING_ATTRIBUTE, "value"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "value"); PlatformType type; type.mType = value; std::set platform; @@ -584,7 +584,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) if (typenodename == "platform") { const char * const type_attribute = typenode->Attribute("type"); if (type_attribute == nullptr) - return Error(MISSING_ATTRIBUTE, "type"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "type"); platform.insert(type_attribute); } else if (typenodename == "signed") 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); if (type_ptr) { if (*type_ptr == type) - return Error(DUPLICATE_PLATFORM_TYPE, type_name); - return Error(PLATFORM_TYPE_REDEFINED, type_name); + return Error(ErrorCode::DUPLICATE_PLATFORM_TYPE, type_name); + return Error(ErrorCode::PLATFORM_TYPE_REDEFINED, type_name); } mPlatformTypes[type_name] = type; } else { @@ -614,8 +614,8 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) const PlatformType * const type_ptr = platform_type(type_name, p); if (type_ptr) { if (*type_ptr == type) - return Error(DUPLICATE_PLATFORM_TYPE, type_name); - return Error(PLATFORM_TYPE_REDEFINED, type_name); + return Error(ErrorCode::DUPLICATE_PLATFORM_TYPE, type_name); + return Error(ErrorCode::PLATFORM_TYPE_REDEFINED, type_name); } mPlatforms[p].mPlatformTypes[type_name] = type; } @@ -632,15 +632,15 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) if (++i != unknown_elements.end()) 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 &unknown_elements) { if (name.empty()) - return Error(OK); + return Error(ErrorCode::OK); Function& func = functions[name]; @@ -681,7 +681,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co } else if (functionnodename == "arg") { const char* argNrString = functionnode->Attribute("nr"); if (!argNrString) - return Error(MISSING_ATTRIBUTE, "nr"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "nr"); const bool bAnyArg = strcmp(argNrString, "any") == 0; const bool bVariadicArg = strcmp(argNrString, "variadic") == 0; 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 const char *p = argnode->GetText(); if (!isCompliantValidationExpression(p)) - return Error(BAD_ATTRIBUTE_VALUE, (!p ? "\"\"" : argnode->GetText())); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, (!p ? "\"\"" : argnode->GetText())); // Set validation expression ac.valid = argnode->GetText(); } else if (argnodename == "minsize") { const char *typeattr = argnode->Attribute("type"); if (!typeattr) - return Error(MISSING_ATTRIBUTE, "type"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "type"); ArgumentChecks::MinSize::Type type; 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) type = ArgumentChecks::MinSize::Type::VALUE; else - return Error(BAD_ATTRIBUTE_VALUE, typeattr); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, typeattr); if (type == ArgumentChecks::MinSize::Type::VALUE) { const char *valueattr = argnode->Attribute("value"); if (!valueattr) - return Error(MISSING_ATTRIBUTE, "value"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "value"); long long minsizevalue = 0; try { minsizevalue = MathLib::toLongNumber(valueattr); } catch (const InternalError&) { - return Error(BAD_ATTRIBUTE_VALUE, valueattr); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, valueattr); } if (minsizevalue <= 0) - return Error(BAD_ATTRIBUTE_VALUE, valueattr); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, valueattr); ac.minsizes.emplace_back(type, 0); ac.minsizes.back().value = minsizevalue; } else { const char *argattr = argnode->Attribute("arg"); if (!argattr) - return Error(MISSING_ATTRIBUTE, "arg"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "arg"); 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.emplace_back(type, argattr[0] - '0'); if (type == ArgumentChecks::MinSize::Type::MUL) { const char *arg2attr = argnode->Attribute("arg2"); if (!arg2attr) - return Error(MISSING_ATTRIBUTE, "arg2"); + return Error(ErrorCode::MISSING_ATTRIBUTE, "arg2"); 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'; } } @@ -801,20 +801,20 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co WarnInfo wi; const char* const severity = functionnode->Attribute("severity"); if (severity == nullptr) - return Error(MISSING_ATTRIBUTE, "severity"); + return Error(ErrorCode::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); + return Error(ErrorCode::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); + return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, cppstd); } else wi.standards.cpp = Standards::CPP03; @@ -836,7 +836,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co } else { const char * const message = functionnode->GetText(); if (!message) { - return Error(MISSING_ATTRIBUTE, "\"reason\" and \"alternatives\" or some text."); + return Error(ErrorCode::MISSING_ATTRIBUTE, "\"reason\" and \"alternatives\" or some text."); } else wi.message = message; } @@ -845,7 +845,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co } else unknown_elements.insert(functionnodename); } - return Error(OK); + return Error(ErrorCode::OK); } std::vector Library::getInvalidArgValues(const std::string &validExpr) @@ -857,16 +857,16 @@ std::vector Library::getInvalidArgValues(const std::st if (tok->str() == ",") continue; 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); } 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); } 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); } 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(); } } @@ -875,21 +875,21 @@ std::vector Library::getInvalidArgValues(const std::st if (valid.empty()) return invalid; - if (valid[0].type == InvalidArgValue::ge || valid[0].type == InvalidArgValue::eq) - invalid.push_back(InvalidArgValue{InvalidArgValue::lt, valid[0].op1, std::string()}); - if (valid.back().type == InvalidArgValue::le || valid.back().type == InvalidArgValue::eq) - invalid.push_back(InvalidArgValue{InvalidArgValue::gt, valid[0].op1, std::string()}); + if (valid[0].type == InvalidArgValue::Type::ge || valid[0].type == InvalidArgValue::Type::eq) + invalid.push_back(InvalidArgValue{InvalidArgValue::Type::lt, valid[0].op1, std::string()}); + if (valid.back().type == InvalidArgValue::Type::le || valid.back().type == InvalidArgValue::Type::eq) + invalid.push_back(InvalidArgValue{InvalidArgValue::Type::gt, valid[0].op1, std::string()}); for (int i = 0; i + 1 < valid.size(); i++) { const InvalidArgValue &v1 = valid[i]; 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()) { MathLib::bigint op1 = MathLib::toLongNumber(v1.op1); MathLib::bigint op2 = MathLib::toLongNumber(v2.op1); 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 - 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)}); } } } diff --git a/lib/library.h b/lib/library.h index 2a41eaa2b..77a7f0d26 100644 --- a/lib/library.h +++ b/lib/library.h @@ -52,11 +52,11 @@ class CPPCHECKLIB Library { public: 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 { public: - Error() : errorcode(OK) {} + Error() : errorcode(ErrorCode::OK) {} explicit Error(ErrorCode e) : errorcode(e) {} template Error(ErrorCode e, T&& r) : errorcode(e), reason(r) {} @@ -283,7 +283,7 @@ public: class MinSize { 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) {} Type type; int arg; @@ -349,7 +349,7 @@ public: } 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 op2; bool isInt() const { @@ -428,7 +428,7 @@ public: struct PodType { unsigned int size; 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 std::map::const_iterator it = mPodTypes.find(name); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 3e4404b35..d2792281e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6419,17 +6419,17 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings *sett type = ValueType::Type::LONG; else if (podtype->size == settings->sizeof_long_long) type = ValueType::Type::LONGLONG; - else if (podtype->stdtype == Library::PodType::BOOL) + else if (podtype->stdtype == Library::PodType::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; - else if (podtype->stdtype == Library::PodType::SHORT) + else if (podtype->stdtype == Library::PodType::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; - else if (podtype->stdtype == Library::PodType::LONG) + else if (podtype->stdtype == Library::PodType::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; else type = ValueType::Type::UNKNOWN_INT; diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index d34d4d88f..d4c97a5f9 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -96,7 +96,7 @@ private: // Reading an empty library file is considered to be OK const char xmldata[] = "\n"; 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()); } @@ -114,7 +114,7 @@ private: tokenList.front()->next()->astOperand1(tokenList.front()); 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(library.functions.at("foo").argumentChecks.empty()); ASSERT(library.isnotnoreturn(tokenList.front())); @@ -129,7 +129,7 @@ private: ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); { TokenList tokenList(nullptr); std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function @@ -161,7 +161,7 @@ private: tokenList.createAst(); 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())); } @@ -175,7 +175,7 @@ private: ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); { TokenList tokenList(nullptr); @@ -230,7 +230,7 @@ private: tokenList.front()->next()->varId(1); 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())); } @@ -247,7 +247,7 @@ private: ""; 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(true, library.functions["foo"].argumentChecks[2].notnull); ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[3].formatstr); @@ -266,7 +266,7 @@ private: ""; 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); } @@ -280,7 +280,7 @@ private: ""; 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); TokenList tokenList(nullptr); @@ -306,7 +306,7 @@ private: ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); TokenList tokenList(nullptr); std::istringstream istr("foo(a,b,c,d);"); @@ -337,7 +337,7 @@ private: ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); TokenList tokenList(nullptr); std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j);"); @@ -473,7 +473,7 @@ private: ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); TokenList tokenList(nullptr); std::istringstream istr("foo(a,b,c,d);"); @@ -486,7 +486,7 @@ private: ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U); if (minsizes && minsizes->size() == 1U) { 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); } @@ -496,7 +496,7 @@ private: ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U); if (minsizes && minsizes->size() == 1U) { 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); } @@ -506,7 +506,7 @@ private: ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U); if (minsizes && minsizes->size() == 1U) { 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); } } @@ -520,7 +520,7 @@ private: ""; 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(library.functions.at("Foo::foo").argumentChecks.empty()); ASSERT(library.functions.at("bar").argumentChecks.empty()); @@ -549,7 +549,7 @@ private: ""; 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); { @@ -576,7 +576,7 @@ private: ""; 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); @@ -605,7 +605,7 @@ private: ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); TokenList tokenList(nullptr); std::istringstream istr("a(); b();"); @@ -639,7 +639,7 @@ private: ""; 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::ismemory(library.getAllocFuncInfo("CreateX"))); @@ -682,7 +682,7 @@ private: ""; 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()); const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX"); @@ -701,7 +701,7 @@ private: ""; 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::isresource(library.allocId("CreateX"))); @@ -718,7 +718,7 @@ private: " \n" ""; Library library; - ASSERT_EQUALS(true, Library::OK == (readLibrary(library, xmldata)).errorcode); + ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode); // s8 { const struct Library::PodType * const type = library.podtype("s8"); @@ -796,7 +796,7 @@ private: ""; 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& B = library.containers["B"]; @@ -848,7 +848,7 @@ private: ""; Library library; const Library::Error err = readLibrary(library, xmldata); - ASSERT_EQUALS(err.errorcode, Library::OK); + ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK); } { const char xmldata [] = "\n" @@ -856,7 +856,7 @@ private: ""; Library library; const Library::Error err = readLibrary(library, xmldata); - ASSERT_EQUALS(err.errorcode, Library::OK); + ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK); } { const char xmldata [] = "\n" @@ -864,13 +864,13 @@ private: ""; Library library; 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 { 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__) @@ -882,7 +882,7 @@ private: "\n" \ "\n" \ "", \ - Library::BAD_ATTRIBUTE_VALUE) + Library::ErrorCode::BAD_ATTRIBUTE_VALUE) void loadLibErrors() const { @@ -890,32 +890,32 @@ private: "\n" " \n" "", - Library::UNKNOWN_ELEMENT); + Library::ErrorCode::UNKNOWN_ELEMENT); // #define without attributes LOADLIBERROR("\n" "\n" " \n" // no attributes provided at all "", - Library::MISSING_ATTRIBUTE); + Library::ErrorCode::MISSING_ATTRIBUTE); // #define with name but without value LOADLIBERROR("\n" "\n" " \n" // no value provided "", - Library::MISSING_ATTRIBUTE); + Library::ErrorCode::MISSING_ATTRIBUTE); LOADLIBERROR("\n" "\n" " \n" // no name provided "", - Library::MISSING_ATTRIBUTE); + Library::ErrorCode::MISSING_ATTRIBUTE); LOADLIBERROR("\n" "\n" "", - Library::UNSUPPORTED_FORMAT); + Library::ErrorCode::UNSUPPORTED_FORMAT); // empty range LOADLIB_ERROR_INVALID_RANGE(""); diff --git a/test/testsuite.h b/test/testsuite.h index 3db7c6117..10b8373b3 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -114,9 +114,9 @@ extern std::ostringstream output; #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_##CLASSNAME; } #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 -#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 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 9d9a2763a..7fec0bca2 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -7009,7 +7009,7 @@ private: Settings settingsWin64; settingsWin64.platformType = Settings::Win64; 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["xyz::x"] = u32; settingsWin64.library.mPodTypes["podtype2"] = podtype2;