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

Method simplifyCppcheckAttribute

lib/tokenize.cpp:9654–9693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9652}
9653
9654void Tokenizer::simplifyCppcheckAttribute()
9655{
9656 for (Token *tok = list.front(); tok; tok = tok->next()) {
9657 if (tok->str() != "(")
9658 continue;
9659 if (!tok->previous())
9660 continue;
9661 const std::string &attr = tok->strAt(-1);
9662 if (!startsWith(attr, "__cppcheck_"))
9663 continue;
9664 if (attr.compare(attr.size()-2, 2, "__") != 0) // TODO: ends_with("__")
9665 continue;
9666
9667 Token *vartok = tok->link();
9668 while (Token::Match(vartok->next(), "%name%|*|&|::")) {
9669 vartok = vartok->next();
9670 if (Token::Match(vartok, "%name% (") && startsWith(vartok->str(),"__cppcheck_"))
9671 vartok = vartok->linkAt(1);
9672 }
9673
9674 if (vartok->isName()) {
9675 if (Token::Match(tok->previous(), "__cppcheck_low__ ( %num% )"))
9676 vartok->setCppcheckAttribute(Token::CppcheckAttributesType::LOW,
9677 MathLib::toBigNumber(tok->tokAt(1)));
9678 else if (Token::Match(tok->previous(), "__cppcheck_high__ ( %num% )"))
9679 vartok->setCppcheckAttribute(Token::CppcheckAttributesType::HIGH,
9680 MathLib::toBigNumber(tok->tokAt(1)));
9681 }
9682
9683 // Delete cppcheck attribute..
9684 if (tok->tokAt(-2)) {
9685 tok = tok->tokAt(-2);
9686 Token::eraseTokens(tok, tok->linkAt(2)->next());
9687 } else {
9688 tok = tok->previous();
9689 Token::eraseTokens(tok, tok->linkAt(1)->next());
9690 tok->str(";");
9691 }
9692 }
9693}
9694
9695void Tokenizer::simplifyCPPAttribute()
9696{

Callers

nothing calls this directly

Calls 9

frontMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
setCppcheckAttributeMethod · 0.80
startsWithFunction · 0.70
strMethod · 0.45
compareMethod · 0.45
sizeMethod · 0.45
tokAtMethod · 0.45

Tested by

no test coverage detected