| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dfd2291 commit 6739995
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,7 +73,7 @@ class CheckThread : public QThread { | |||
| 73 | 73 | * @brief method that is run in a thread | |
| 74 | 74 | * | |
| 75 | 75 | */ | |
| 76 | - void run(); | ||
| 76 | + void run() override; | ||
| 77 | 77 | ||
| 78 | 78 | void stop(); | |
| 79 | 79 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,7 +68,7 @@ class CPPCHECKLIB Library { | |||
| 68 | 68 | Error load(const char exename[], const char path[]); | |
| 69 | 69 | Error load(const tinyxml2::XMLDocument &doc); | |
| 70 | 70 | ||
| 71 | - /** this is primarily meant for unit tests. it only returns true/false */ | ||
| 71 | + /** this is used for unit tests */ | ||
| 72 | 72 | bool loadxmldata(const char xmldata[], std::size_t len); | |
| 73 | 73 | ||
| 74 | 74 | struct AllocFunc { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -357,105 +357,6 @@ unsigned int MathLib::encodeMultiChar(const std::string& str) | |||
| 357 | 357 | return retval; | |
| 358 | 358 | } | |
| 359 | 359 | ||
| 360 | - std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral) | ||
| 361 | - { | ||
| 362 | - std::string normalizedLiteral; | ||
| 363 | - const std::string::size_type iLiteralLen = iLiteral.size(); | ||
| 364 | - for (std::string::size_type idx = 0; idx < iLiteralLen; ++idx) { | ||
| 365 | - if (iLiteral[idx] != '\\') { | ||
| 366 | - normalizedLiteral.push_back(iLiteral[idx]); | ||
| 367 | - continue; | ||
| 368 | - } | ||
| 369 | - ++idx; | ||
| 370 | - if (idx == iLiteralLen) { | ||
| 371 | - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); | ||
| 372 | - } | ||
| 373 | - switch (iLiteral[idx]) { | ||
| 374 | - case 'x': | ||
| 375 | - // Hexa-decimal number: skip \x and interpret the next two characters | ||
| 376 | - { | ||
| 377 | - if (++idx == iLiteralLen) | ||
| 378 | - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); | ||
| 379 | - std::string tempBuf; | ||
| 380 | - tempBuf.push_back(iLiteral[idx]); | ||
| 381 | - if (++idx != iLiteralLen) | ||
| 382 | - tempBuf.push_back(iLiteral[idx]); | ||
| 383 | - normalizedLiteral.push_back(static_cast<char>(MathLib::toULongNumber("0x" + tempBuf))); | ||
| 384 | - continue; | ||
| 385 | - } | ||
| 386 | - case 'u': | ||
| 387 | - case 'U': | ||
| 388 | - // Unicode string; just skip the \u or \U | ||
| 389 | - if (idx + 1 == iLiteralLen) | ||
| 390 | - throw InternalError(nullptr, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + iLiteral + "'."); | ||
| 391 | - continue; | ||
| 392 | - } | ||
| 393 | - // Single digit octal number | ||
| 394 | - if (1 == iLiteralLen - idx) { | ||
| 395 | - switch (iLiteral[idx]) { | ||
| 396 | - case '0': | ||
| 397 | - case '1': | ||
| 398 | - case '2': | ||
| 399 | - case '3': | ||
| 400 | - case '4': | ||
| 401 | - case '5': | ||
| 402 | - case '6': | ||
| 403 | - case '7': | ||
| 404 | - normalizedLiteral.push_back(iLiteral[idx]-'0'); | ||
| 405 | - break; | ||
| 406 | - case 'a': | ||
| 407 | - normalizedLiteral.push_back('\a'); | ||
| 408 | - break; | ||
| 409 | - case 'b': | ||
| 410 | - normalizedLiteral.push_back('\b'); | ||
| 411 | - break; | ||
| 412 | - case 'e': | ||
| 413 | - normalizedLiteral.push_back(0x1B); // clang, gcc, tcc interpnormalizedLiteral this as 0x1B - escape character | ||
| 414 | - break; | ||
| 415 | - case 'f': | ||
| 416 | - normalizedLiteral.push_back('\f'); | ||
| 417 | - break; | ||
| 418 | - case 'n': | ||
| 419 | - normalizedLiteral.push_back('\n'); | ||
| 420 | - break; | ||
| 421 | - case 'r': | ||
| 422 | - normalizedLiteral.push_back('\r'); | ||
| 423 | - break; | ||
| 424 | - case 't': | ||
| 425 | - normalizedLiteral.push_back('\t'); | ||
| 426 | - break; | ||
| 427 | - case 'v': | ||
| 428 | - normalizedLiteral.push_back('\v'); | ||
| 429 | - break; | ||
| 430 | - case '\\': | ||
| 431 | - case '\?': | ||
| 432 | - case '\'': | ||
| 433 | - case '\"': | ||
| 434 | - normalizedLiteral.push_back(iLiteral[idx]); | ||
| 435 | - break; | ||
| 436 | - default: | ||
| 437 | - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); | ||
| 438 | - } | ||
| 439 | - continue; | ||
| 440 | - } | ||
| 441 | - // 2-3 digit octal number | ||
| 442 | - if (!MathLib::isOctalDigit(iLiteral[idx])) | ||
| 443 | - throw InternalError(nullptr, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'."); | ||
| 444 | - std::string tempBuf; | ||
| 445 | - tempBuf.push_back(iLiteral[idx]); | ||
| 446 | - ++idx; | ||
| 447 | - if (MathLib::isOctalDigit(iLiteral[idx])) { | ||
| 448 | - tempBuf.push_back(iLiteral[idx]); | ||
| 449 | - ++idx; | ||
| 450 | - if (MathLib::isOctalDigit(iLiteral[idx])) { | ||
| 451 | - tempBuf.push_back(iLiteral[idx]); | ||
| 452 | - } | ||
| 453 | - } | ||
| 454 | - normalizedLiteral.push_back(static_cast<char>(MathLib::toLongNumber("0" + tempBuf))); | ||
| 455 | - } | ||
| 456 | - return normalizedLiteral; | ||
| 457 | - } | ||
| 458 | - | ||
| 459 | 360 | MathLib::bigint MathLib::toLongNumber(const std::string & str) | |
| 460 | 361 | { | |
| 461 | 362 | // hexadecimal numbers: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,8 @@ class CPPCHECKLIB MathLib { | |||
| 93 | 93 | ||
| 94 | 94 | static std::string getSuffix(const std::string& value); | |
| 95 | 95 | /** | |
| 96 | + * Only used in unit tests | ||
| 97 | + * | ||
| 96 | 98 | * \param[in] str string | |
| 97 | 99 | * \param[in] supportMicrosoftExtensions support Microsoft extension: i64 | |
| 98 | 100 | * \return true if str is a non-empty valid integer suffix | |
@@ -133,13 +135,6 @@ class CPPCHECKLIB MathLib { | |||
| 133 | 135 | * \return Whether iCode[iPos] is a C++14 digit separator | |
| 134 | 136 | */ | |
| 135 | 137 | static bool isDigitSeparator(const std::string& iCode, std::string::size_type iPos); | |
| 136 | - | ||
| 137 | - private: | ||
| 138 | - /* | ||
| 139 | - * \param iLiteral A character literal | ||
| 140 | - * \return The equivalent character literal with all escapes interpreted | ||
| 141 | - */ | ||
| 142 | - static std::string normalizeCharacterLiteral(const std::string& iLiteral); | ||
| 143 | 138 | }; | |
| 144 | 139 | ||
| 145 | 140 | MathLib::value operator+(const MathLib::value &v1, const MathLib::value &v2); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1375,6 +1375,7 @@ class CPPCHECKLIB SymbolDatabase { | |||
| 1375 | 1375 | */ | |
| 1376 | 1376 | const Function *findFunction(const Token *tok) const; | |
| 1377 | 1377 | ||
| 1378 | + /** For unit testing only */ | ||
| 1378 | 1379 | const Scope *findScopeByName(const std::string& name) const; | |
| 1379 | 1380 | ||
| 1380 | 1381 | const Type* findType(const Token *startTok, const Scope *startScope) const; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9187,85 +9187,6 @@ void Tokenizer::simplifyNestedStrcat() | |||
| 9187 | 9187 | } | |
| 9188 | 9188 | } | |
| 9189 | 9189 | ||
| 9190 | - // Check if this statement is a duplicate definition. A duplicate | ||
| 9191 | - // definition will hide the enumerator within it's scope so just | ||
| 9192 | - // skip the entire scope of the duplicate. | ||
| 9193 | - bool Tokenizer::duplicateDefinition(Token ** tokPtr) | ||
| 9194 | - { | ||
| 9195 | - // check for an end of definition | ||
| 9196 | - const Token * tok = *tokPtr; | ||
| 9197 | - if (tok && Token::Match(tok->next(), ";|,|[|=|)|>")) { | ||
| 9198 | - const Token * end = tok->next(); | ||
| 9199 | - | ||
| 9200 | - if (end->str() == "[") { | ||
| 9201 | - end = end->link()->next(); | ||
| 9202 | - } else if (end->str() == ",") { | ||
| 9203 | - // check for function argument | ||
| 9204 | - if (Token::Match(tok->previous(), "(|,")) | ||
| 9205 | - return false; | ||
| 9206 | - | ||
| 9207 | - // find end of definition | ||
| 9208 | - int level = 0; | ||
| 9209 | - while (end->next() && (!Token::Match(end->next(), ";|)|>") || | ||
| 9210 | - (end->next()->str() == ")" && level == 0))) { | ||
| 9211 | - if (end->next()->str() == "(") | ||
| 9212 | - ++level; | ||
| 9213 | - else if (end->next()->str() == ")") | ||
| 9214 | - --level; | ||
| 9215 | - | ||
| 9216 | - end = end->next(); | ||
| 9217 | - } | ||
| 9218 | - } else if (end->str() == ")") { | ||
| 9219 | - // check for function argument | ||
| 9220 | - if (tok->previous()->str() == ",") | ||
| 9221 | - return false; | ||
| 9222 | - } | ||
| 9223 | - | ||
| 9224 | - if (end) { | ||
| 9225 | - if (Token::simpleMatch(end, ") {")) { // function parameter ? | ||
| 9226 | - // make sure it's not a conditional | ||
| 9227 | - if (Token::Match(end->link()->previous(), "if|for|while|switch|BOOST_FOREACH") || Token::Match(end->link()->tokAt(-2), ":|,")) | ||
| 9228 | - return false; | ||
| 9229 | - | ||
| 9230 | - // look backwards | ||
| 9231 | - if (tok->previous()->str() == "enum" || | ||
| 9232 | - (Token::Match(tok->previous(), "%type%") && | ||
| 9233 | - tok->previous()->str() != "return") || | ||
| 9234 | - Token::Match(tok->tokAt(-2), "%type% &|*")) { | ||
| 9235 | - // duplicate definition so skip entire function | ||
| 9236 | - *tokPtr = end->next()->link(); | ||
| 9237 | - return true; | ||
| 9238 | - } | ||
| 9239 | - } else if (end->str() == ">") { // template parameter ? | ||
| 9240 | - // look backwards | ||
| 9241 | - if (tok->previous()->str() == "enum" || | ||
| 9242 | - (Token::Match(tok->previous(), "%type%") && | ||
| 9243 | - tok->previous()->str() != "return")) { | ||
| 9244 | - // duplicate definition so skip entire template | ||
| 9245 | - while (end && end->str() != "{") | ||
| 9246 | - end = end->next(); | ||
| 9247 | - if (end) { | ||
| 9248 | - *tokPtr = end->link(); | ||
| 9249 | - return true; | ||
| 9250 | - } | ||
| 9251 | - } | ||
| 9252 | - } else { | ||
| 9253 | - if (Token::Match(tok->previous(), "enum|,")) | ||
| 9254 | - return true; | ||
| 9255 | - else if (Token::Match(tok->previous(), "%type%")) { | ||
| 9256 | - // look backwards | ||
| 9257 | - const Token *back = tok; | ||
| 9258 | - while (back && back->isName()) | ||
| 9259 | - back = back->previous(); | ||
| 9260 | - if (!back || (Token::Match(back, "[(,;{}]") && !Token::Match(back->next(),"return|throw"))) | ||
| 9261 | - return true; | ||
| 9262 | - } | ||
| 9263 | - } | ||
| 9264 | - } | ||
| 9265 | - } | ||
| 9266 | - return false; | ||
| 9267 | - } | ||
| 9268 | - | ||
| 9269 | 9190 | static const std::set<std::string> stdFunctionsPresentInC = { | |
| 9270 | 9191 | "strcat", | |
| 9271 | 9192 | "strcpy", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -810,11 +810,6 @@ class CPPCHECKLIB Tokenizer { | |||
| 810 | 810 | * */ | |
| 811 | 811 | void prepareTernaryOpForAST(); | |
| 812 | 812 | ||
| 813 | - /** | ||
| 814 | - * check for duplicate enum definition | ||
| 815 | - */ | ||
| 816 | - static bool duplicateDefinition(Token **tokPtr); | ||
| 817 | - | ||
| 818 | 813 | /** | |
| 819 | 814 | * report error message | |
| 820 | 815 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,6 @@ class TestMathLib : public TestFixture { | |||
| 62 | 62 | TEST_CASE(tan); | |
| 63 | 63 | TEST_CASE(abs); | |
| 64 | 64 | TEST_CASE(toString); | |
| 65 | - TEST_CASE(characterLiteralsNormalization); | ||
| 66 | 65 | TEST_CASE(CPP14DigitSeparators); | |
| 67 | 66 | } | |
| 68 | 67 | ||
@@ -1246,27 +1245,6 @@ class TestMathLib : public TestFixture { | |||
| 1246 | 1245 | ASSERT_EQUALS("-0", MathLib::toString(-0.0L)); | |
| 1247 | 1246 | } | |
| 1248 | 1247 | ||
| 1249 | - void characterLiteralsNormalization() const { | ||
| 1250 | - // `A` is 0x41 and 0101 | ||
| 1251 | - ASSERT_EQUALS("A", MathLib::normalizeCharacterLiteral("\\x41")); | ||
| 1252 | - ASSERT_EQUALS("A", MathLib::normalizeCharacterLiteral("\\101")); | ||
| 1253 | - // Hexa and octal numbers should not only be interpreted in byte 1 | ||
| 1254 | - ASSERT_EQUALS("TESTATEST", MathLib::normalizeCharacterLiteral("TEST\\x41TEST")); | ||
| 1255 | - ASSERT_EQUALS("TESTATEST", MathLib::normalizeCharacterLiteral("TEST\\101TEST")); | ||
| 1256 | - ASSERT_EQUALS("TESTTESTA", MathLib::normalizeCharacterLiteral("TESTTEST\\x41")); | ||
| 1257 | - ASSERT_EQUALS("TESTTESTA", MathLib::normalizeCharacterLiteral("TESTTEST\\101")); | ||
| 1258 | - // Single escape sequences | ||
| 1259 | - ASSERT_EQUALS("\?", MathLib::normalizeCharacterLiteral("\\?")); | ||
| 1260 | - ASSERT_EQUALS("\'", MathLib::normalizeCharacterLiteral("\\'")); | ||
| 1261 | - // Incomplete hexa and octal sequences | ||
| 1262 | - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\"), InternalError); | ||
| 1263 | - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\x"), InternalError); | ||
| 1264 | - // No octal digit in an octal sequence | ||
| 1265 | - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\9"), InternalError); | ||
| 1266 | - // Unsupported single escape sequence | ||
| 1267 | - ASSERT_THROW(MathLib::normalizeCharacterLiteral("\\c"), InternalError); | ||
| 1268 | - } | ||
| 1269 | - | ||
| 1270 | 1248 | void CPP14DigitSeparators() const { // Ticket #7137, #7565 | |
| 1271 | 1249 | ASSERT(MathLib::isDigitSeparator("'", 0) == false); | |
| 1272 | 1250 | ASSERT(MathLib::isDigitSeparator("123'0;", 3)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,8 +205,6 @@ class TestSimplifyTokens : public TestFixture { | |||
| 205 | 205 | // ticket #3140 | |
| 206 | 206 | TEST_CASE(while0for); | |
| 207 | 207 | ||
| 208 | - TEST_CASE(duplicateDefinition); // ticket #3565 | ||
| 209 | - | ||
| 210 | 208 | // remove "std::" on some standard functions | |
| 211 | 209 | TEST_CASE(removestd); | |
| 212 | 210 | ||
@@ -4451,14 +4449,6 @@ class TestSimplifyTokens : public TestFixture { | |||
| 4451 | 4449 | 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; }")); | |
| 4452 | 4450 | } | |
| 4453 | 4451 | ||
| 4454 | - void duplicateDefinition() { // #3565 - wrongly detects duplicate definition | ||
| 4455 | - Tokenizer tokenizer(&settings0, this); | ||
| 4456 | - std::istringstream istr("{ x ; return a not_eq x; }"); | ||
| 4457 | - ASSERT(tokenizer.tokenize(istr, "test.c")); | ||
| 4458 | - Token *x_token = tokenizer.list.front()->tokAt(5); | ||
| 4459 | - ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token)); | ||
| 4460 | - } | ||
| 4461 | - | ||
| 4462 | 4452 | void removestd() { | |
| 4463 | 4453 | ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);")); | |
| 4464 | 4454 | ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);")); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments