MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / simplifyTemplateArgs

Method simplifyTemplateArgs

lib/templatesimplifier.cpp:2520–2686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2518}
2519
2520void TemplateSimplifier::simplifyTemplateArgs(Token *start, const Token *end, std::vector<newInstantiation>* newInst)
2521{
2522 // start could be erased so use the token before start if available
2523 Token * first = (start && start->previous()) ? start->previous() : mTokenList.front();
2524 bool again = true;
2525
2526 while (again) {
2527 again = false;
2528
2529 for (Token *tok = first->next(); tok && tok != end; tok = tok->next()) {
2530 if (tok->str() == "sizeof") {
2531 // sizeof('x')
2532 if (Token::Match(tok->next(), "( %char% )")) {
2533 tok->deleteNext();
2534 tok->deleteThis();
2535 tok->deleteNext();
2536 tok->str(std::to_string(1));
2537 again = true;
2538 }
2539
2540 // sizeof ("text")
2541 else if (Token::Match(tok->next(), "( %str% )")) {
2542 tok->deleteNext();
2543 tok->deleteThis();
2544 tok->deleteNext();
2545 tok->str(std::to_string(Token::getStrLength(tok) + 1));
2546 again = true;
2547 }
2548
2549 else if (Token::Match(tok->next(), "( %type% * )")) {
2550 tok->str(std::to_string(mTokenizer.sizeOfType(tok->tokAt(3))));
2551 tok->deleteNext(4);
2552 again = true;
2553 } else if (Token::simpleMatch(tok->next(), "( * )")) {
2554 tok->str(std::to_string(mTokenizer.sizeOfType(tok->tokAt(2))));
2555 tok->deleteNext(3);
2556 again = true;
2557 } else if (Token::Match(tok->next(), "( %type% )")) {
2558 const unsigned int size = mTokenizer.sizeOfType(tok->tokAt(2));
2559 if (size > 0) {
2560 tok->str(std::to_string(size));
2561 tok->deleteNext(3);
2562 again = true;
2563 }
2564 } else if (tok->strAt(1) == "(") {
2565 tok = tok->linkAt(1);
2566 }
2567 } else if (Token::Match(tok, "%num% %comp% %num%") &&
2568 MathLib::isInt(tok->str()) &&
2569 MathLib::isInt(tok->strAt(2))) {
2570 if ((Token::Match(tok->previous(), "(|&&|%oror%|,") || tok == start) &&
2571 (Token::Match(tok->tokAt(3), ")|&&|%oror%|?") || tok->tokAt(3) == end)) {
2572 const MathLib::bigint op1(MathLib::toBigNumber(tok));
2573 const std::string &cmp(tok->strAt(1));
2574 const MathLib::bigint op2(MathLib::toBigNumber(tok->tokAt(2)));
2575
2576 std::string result;
2577

Callers

nothing calls this directly

Calls 15

bool_to_stringFunction · 0.85
invalidateInstFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
deleteNextMethod · 0.80
deleteThisMethod · 0.80
linkAtMethod · 0.80
insertTokenMethod · 0.80
simpleMatchFunction · 0.70
skipTernaryOpFunction · 0.70
endsWithFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected