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

Method simplifyTypedefLHS

lib/tokenize.cpp:506–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

504}
505
506void Tokenizer::simplifyTypedefLHS()
507{
508 if (!list.front())
509 return;
510
511 for (Token* tok = list.front()->next(); tok; tok = tok->next()) {
512 if (tok->str() == "typedef") {
513 bool doSimplify = !Token::Match(tok->previous(), ";|{|}|:|public:|private:|protected:");
514 if (doSimplify && Token::simpleMatch(tok->previous(), ")") && Token::Match(tok->linkAt(-1)->previous(), "if|for|while"))
515 doSimplify = false;
516 bool haveStart = false;
517 Token* start{};
518 if (!doSimplify && Token::simpleMatch(tok->previous(), "}")) {
519 start = tok->linkAt(-1)->previous();
520 while (Token::Match(start, "%name%")) {
521 if (Token::Match(start, "class|struct|union|enum")) {
522 start = start->previous();
523 doSimplify = true;
524 haveStart = true;
525 break;
526 }
527 start = start->previous();
528 }
529 }
530 if (doSimplify) {
531 if (!haveStart) {
532 start = tok;
533 while (start && !Token::Match(start, "[;{}]"))
534 start = start->previous();
535 }
536 if (start)
537 start = start->next();
538 else
539 start = list.front();
540 start->insertTokenBefore(tok->str());
541 tok->deleteThis();
542 }
543 }
544 }
545}
546
547namespace {
548 class TypedefSimplifier {

Callers

nothing calls this directly

Calls 6

frontMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
deleteThisMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected