diff --git a/gui/checkthread.h b/gui/checkthread.h index d6e78af00..50a0685a5 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -73,7 +73,7 @@ public: * @brief method that is run in a thread * */ - void run(); + void run() override; void stop(); diff --git a/lib/library.h b/lib/library.h index 5aed161c8..f85d38658 100644 --- a/lib/library.h +++ b/lib/library.h @@ -68,7 +68,7 @@ public: Error load(const char exename[], const char path[]); Error load(const tinyxml2::XMLDocument &doc); - /** this is primarily meant for unit tests. it only returns true/false */ + /** this is used for unit tests */ bool loadxmldata(const char xmldata[], std::size_t len); struct AllocFunc { diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 1b6cb1550..cd9f8b556 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -357,105 +357,6 @@ unsigned int MathLib::encodeMultiChar(const std::string& str) return retval; } -std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral) -{ - std::string normalizedLiteral; - const std::string::size_type iLiteralLen = iLiteral.size(); - for (std::string::size_type idx = 0; idx < iLiteralLen; ++idx) { - if (iLiteral[idx] != '\\') { - normalizedLiteral.push_back(iLiteral[idx]); - continue; - } - ++idx; - if (idx == iLiteralLen) { - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); - } - switch (iLiteral[idx]) { - case 'x': - // Hexa-decimal number: skip \x and interpret the next two characters - { - if (++idx == iLiteralLen) - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); - std::string tempBuf; - tempBuf.push_back(iLiteral[idx]); - if (++idx != iLiteralLen) - tempBuf.push_back(iLiteral[idx]); - normalizedLiteral.push_back(static_cast(MathLib::toULongNumber("0x" + tempBuf))); - continue; - } - case 'u': - case 'U': - // Unicode string; just skip the \u or \U - if (idx + 1 == iLiteralLen) - throw InternalError(nullptr, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + iLiteral + "'."); - continue; - } - // Single digit octal number - if (1 == iLiteralLen - idx) { - switch (iLiteral[idx]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - normalizedLiteral.push_back(iLiteral[idx]-'0'); - break; - case 'a': - normalizedLiteral.push_back('\a'); - break; - case 'b': - normalizedLiteral.push_back('\b'); - break; - case 'e': - normalizedLiteral.push_back(0x1B); // clang, gcc, tcc interpnormalizedLiteral this as 0x1B - escape character - break; - case 'f': - normalizedLiteral.push_back('\f'); - break; - case 'n': - normalizedLiteral.push_back('\n'); - break; - case 'r': - normalizedLiteral.push_back('\r'); - break; - case 't': - normalizedLiteral.push_back('\t'); - break; - case 'v': - normalizedLiteral.push_back('\v'); - break; - case '\\': - case '\?': - case '\'': - case '\"': - normalizedLiteral.push_back(iLiteral[idx]); - break; - default: - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); - } - continue; - } - // 2-3 digit octal number - if (!MathLib::isOctalDigit(iLiteral[idx])) - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); - std::string tempBuf; - tempBuf.push_back(iLiteral[idx]); - ++idx; - if (MathLib::isOctalDigit(iLiteral[idx])) { - tempBuf.push_back(iLiteral[idx]); - ++idx; - if (MathLib::isOctalDigit(iLiteral[idx])) { - tempBuf.push_back(iLiteral[idx]); - } - } - normalizedLiteral.push_back(static_cast(MathLib::toLongNumber("0" + tempBuf))); - } - return normalizedLiteral; -} - MathLib::bigint MathLib::toLongNumber(const std::string & str) { // hexadecimal numbers: diff --git a/lib/mathlib.h b/lib/mathlib.h index e37ac3819..895e8531d 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -93,6 +93,8 @@ public: static std::string getSuffix(const std::string& value); /** + * Only used in unit tests + * * \param[in] str string * \param[in] supportMicrosoftExtensions support Microsoft extension: i64 * \return true if str is a non-empty valid integer suffix @@ -133,13 +135,6 @@ public: * \return Whether iCode[iPos] is a C++14 digit separator */ static bool isDigitSeparator(const std::string& iCode, std::string::size_type iPos); - -private: - /* - * \param iLiteral A character literal - * \return The equivalent character literal with all escapes interpreted - */ - static std::string normalizeCharacterLiteral(const std::string& iLiteral); }; MathLib::value operator+(const MathLib::value &v1, const MathLib::value &v2); diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index e46b38c8c..ad02e15b3 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1375,6 +1375,7 @@ public: */ const Function *findFunction(const Token *tok) const; + /** For unit testing only */ const Scope *findScopeByName(const std::string& name) const; const Type* findType(const Token *startTok, const Scope *startScope) const; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8bded705e..2c1bdf8cf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9187,85 +9187,6 @@ void Tokenizer::simplifyNestedStrcat() } } -// Check if this statement is a duplicate definition. A duplicate -// definition will hide the enumerator within it's scope so just -// skip the entire scope of the duplicate. -bool Tokenizer::duplicateDefinition(Token ** tokPtr) -{ - // check for an end of definition - const Token * tok = *tokPtr; - if (tok && Token::Match(tok->next(), ";|,|[|=|)|>")) { - const Token * end = tok->next(); - - if (end->str() == "[") { - end = end->link()->next(); - } else if (end->str() == ",") { - // check for function argument - if (Token::Match(tok->previous(), "(|,")) - return false; - - // find end of definition - int level = 0; - while (end->next() && (!Token::Match(end->next(), ";|)|>") || - (end->next()->str() == ")" && level == 0))) { - if (end->next()->str() == "(") - ++level; - else if (end->next()->str() == ")") - --level; - - end = end->next(); - } - } else if (end->str() == ")") { - // check for function argument - if (tok->previous()->str() == ",") - return false; - } - - if (end) { - if (Token::simpleMatch(end, ") {")) { // function parameter ? - // make sure it's not a conditional - if (Token::Match(end->link()->previous(), "if|for|while|switch|BOOST_FOREACH") || Token::Match(end->link()->tokAt(-2), ":|,")) - return false; - - // look backwards - if (tok->previous()->str() == "enum" || - (Token::Match(tok->previous(), "%type%") && - tok->previous()->str() != "return") || - Token::Match(tok->tokAt(-2), "%type% &|*")) { - // duplicate definition so skip entire function - *tokPtr = end->next()->link(); - return true; - } - } else if (end->str() == ">") { // template parameter ? - // look backwards - if (tok->previous()->str() == "enum" || - (Token::Match(tok->previous(), "%type%") && - tok->previous()->str() != "return")) { - // duplicate definition so skip entire template - while (end && end->str() != "{") - end = end->next(); - if (end) { - *tokPtr = end->link(); - return true; - } - } - } else { - if (Token::Match(tok->previous(), "enum|,")) - return true; - else if (Token::Match(tok->previous(), "%type%")) { - // look backwards - const Token *back = tok; - while (back && back->isName()) - back = back->previous(); - if (!back || (Token::Match(back, "[(,;{}]") && !Token::Match(back->next(),"return|throw"))) - return true; - } - } - } - } - return false; -} - static const std::set stdFunctionsPresentInC = { "strcat", "strcpy", diff --git a/lib/tokenize.h b/lib/tokenize.h index 945c58601..13de2cc70 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -810,11 +810,6 @@ private: * */ void prepareTernaryOpForAST(); - /** - * check for duplicate enum definition - */ - static bool duplicateDefinition(Token **tokPtr); - /** * report error message */ diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index de7e91612..c1b2d7640 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -62,7 +62,6 @@ private: TEST_CASE(tan); TEST_CASE(abs); TEST_CASE(toString); - TEST_CASE(characterLiteralsNormalization); TEST_CASE(CPP14DigitSeparators); } @@ -1246,27 +1245,6 @@ private: ASSERT_EQUALS("-0", MathLib::toString(-0.0L)); } - void characterLiteralsNormalization() const { - // `A` is 0x41 and 0101 - ASSERT_EQUALS("A", MathLib::normalizeCharacterLiteral("\\x41")); - ASSERT_EQUALS("A", MathLib::normalizeCharacterLiteral("\\101")); - // Hexa and octal numbers should not only be interpreted in byte 1 - ASSERT_EQUALS("TESTATEST", MathLib::normalizeCharacterLiteral("TEST\\x41TEST")); - ASSERT_EQUALS("TESTATEST", MathLib::normalizeCharacterLiteral("TEST\\101TEST")); - ASSERT_EQUALS("TESTTESTA", MathLib::normalizeCharacterLiteral("TESTTEST\\x41")); - ASSERT_EQUALS("TESTTESTA", MathLib::normalizeCharacterLiteral("TESTTEST\\101")); - // Single escape sequences - ASSERT_EQUALS("\?", MathLib::normalizeCharacterLiteral("\\?")); - ASSERT_EQUALS("\'", MathLib::normalizeCharacterLiteral("\\'")); - // Incomplete hexa and octal sequences - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\"), InternalError); - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\x"), InternalError); - // No octal digit in an octal sequence - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\9"), InternalError); - // Unsupported single escape sequence - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\c"), InternalError); - } - void CPP14DigitSeparators() const { // Ticket #7137, #7565 ASSERT(MathLib::isDigitSeparator("'", 0) == false); ASSERT(MathLib::isDigitSeparator("123'0;", 3)); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 245ee2522..0a5ca78d8 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -205,8 +205,6 @@ private: // ticket #3140 TEST_CASE(while0for); - TEST_CASE(duplicateDefinition); // ticket #3565 - // remove "std::" on some standard functions TEST_CASE(removestd); @@ -4451,14 +4449,6 @@ private: ASSERT_EQUALS("void f ( ) { int i ; for ( i = 0 ; i < 0 ; ++ i ) { } return i ; }", tok("void f() { int i; for (i=0;i<0;++i){ dostuff(); } return i; }")); } - void duplicateDefinition() { // #3565 - wrongly detects duplicate definition - Tokenizer tokenizer(&settings0, this); - std::istringstream istr("{ x ; return a not_eq x; }"); - ASSERT(tokenizer.tokenize(istr, "test.c")); - Token *x_token = tokenizer.list.front()->tokAt(5); - ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token)); - } - void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);")); ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));