| 9573 | } |
| 9574 | |
| 9575 | void Tokenizer::simplifyAttribute() |
| 9576 | { |
| 9577 | for (Token *tok = list.front(); tok; tok = tok->next()) { |
| 9578 | if (!tok->isKeyword() && Token::Match(tok, "%type% (") && !mSettings.library.isNotLibraryFunction(tok)) { |
| 9579 | if (mSettings.library.isFunctionConst(tok->str(), true)) |
| 9580 | tok->isAttributePure(true); |
| 9581 | if (mSettings.library.isFunctionConst(tok->str(), false)) |
| 9582 | tok->isAttributeConst(true); |
| 9583 | } |
| 9584 | while (isAttribute(tok, true)) { |
| 9585 | Token *functok = getAttributeFuncTok(tok, true); |
| 9586 | |
| 9587 | for (Token *attr = tok->tokAt(2); attr->str() != ")"; attr = attr->next()) { |
| 9588 | if (Token::Match(attr, "%name% (")) |
| 9589 | attr = attr->linkAt(1); |
| 9590 | |
| 9591 | if (Token::Match(attr, "[(,] constructor|__constructor__ [,()]")) { |
| 9592 | if (!functok) |
| 9593 | syntaxError(tok); |
| 9594 | functok->isAttributeConstructor(true); |
| 9595 | } |
| 9596 | |
| 9597 | else if (Token::Match(attr, "[(,] destructor|__destructor__ [,()]")) { |
| 9598 | if (!functok) |
| 9599 | syntaxError(tok); |
| 9600 | functok->isAttributeDestructor(true); |
| 9601 | } |
| 9602 | |
| 9603 | else if (Token::Match(attr, "[(,] unused|__unused__|used|__used__ [,)]")) { |
| 9604 | Token *vartok = getVariableTokenAfterAttributes(tok); |
| 9605 | if (!vartok) |
| 9606 | vartok = functok; |
| 9607 | if (vartok) { |
| 9608 | const std::string &attribute(attr->strAt(1)); |
| 9609 | if (attribute.find("unused") != std::string::npos) |
| 9610 | vartok->isAttributeUnused(true); |
| 9611 | else |
| 9612 | vartok->isAttributeUsed(true); |
| 9613 | } |
| 9614 | } |
| 9615 | |
| 9616 | else if (Token::Match(attr, "[(,] pure|__pure__|const|__const__|noreturn|__noreturn__|nothrow|__nothrow__|warn_unused_result [,)]")) { |
| 9617 | if (!functok) |
| 9618 | syntaxError(tok); |
| 9619 | |
| 9620 | const std::string &attribute(attr->strAt(1)); |
| 9621 | if (attribute.find("pure") != std::string::npos) |
| 9622 | functok->isAttributePure(true); |
| 9623 | else if (attribute.find("const") != std::string::npos) |
| 9624 | functok->isAttributeConst(true); |
| 9625 | else if (attribute.find("noreturn") != std::string::npos) |
| 9626 | functok->isAttributeNoreturn(true); |
| 9627 | else if (attribute.find("nothrow") != std::string::npos) |
| 9628 | functok->isAttributeNothrow(true); |
| 9629 | else if (attribute.find("warn_unused_result") != std::string::npos) |
| 9630 | functok->isAttributeNodiscard(true); |
| 9631 | } |
| 9632 |
nothing calls this directly
no test coverage detected