Refactoring Tokenizer::simplifyAttribute
This commit is contained in:
parent
fb3f5a159d
commit
06803ee333
109
lib/tokenize.cpp
109
lib/tokenize.cpp
|
@ -9279,96 +9279,55 @@ void Tokenizer::simplifyAttribute()
|
||||||
tok->next()->link()->next()->isAttributeDestructor(true);
|
tok->next()->link()->next()->isAttributeDestructor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( unused|__unused__ )")) {
|
else if (Token::Match(tok->tokAt(2), "( unused|__unused__|used|__used__ )")) {
|
||||||
|
const std::string &attribute(tok->strAt(3));
|
||||||
|
Token *vartok = nullptr;
|
||||||
|
|
||||||
// check if after variable name
|
// check if after variable name
|
||||||
if (Token::Match(tok->next()->link()->next(), ";|=")) {
|
if (Token::Match(tok->next()->link()->next(), ";|=")) {
|
||||||
if (Token::Match(tok->previous(), "%type%"))
|
if (Token::Match(tok->previous(), "%type%"))
|
||||||
tok->previous()->isAttributeUnused(true);
|
vartok = tok->previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if before variable name
|
// check if before variable name
|
||||||
else if (Token::Match(tok->next()->link()->next(), "%type%"))
|
else if (Token::Match(tok->next()->link()->next(), "%type%"))
|
||||||
tok->next()->link()->next()->isAttributeUnused(true);
|
vartok = tok->next()->link()->next();
|
||||||
|
|
||||||
|
if (vartok) {
|
||||||
|
if (attribute.find("unused") != std::string::npos)
|
||||||
|
vartok->isAttributeUnused(true);
|
||||||
|
else
|
||||||
|
vartok->isAttributeUsed(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( used|__used__ )")) {
|
else if (Token::Match(tok->tokAt(2), "( pure|__pure__|const|__const__|noreturn|__noreturn__|nothrow|__nothrow__ )")) {
|
||||||
// check if after variable name
|
const std::string &attribute(tok->strAt(3));
|
||||||
if (Token::Match(tok->next()->link()->next(), ";|=")) {
|
Token *functok = nullptr;
|
||||||
if (Token::Match(tok->previous(), "%type%"))
|
|
||||||
tok->previous()->isAttributeUsed(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if before variable name
|
// type func(...) __attribute__((attribute));
|
||||||
else if (Token::Match(tok->next()->link()->next(), "%type%"))
|
|
||||||
tok->next()->link()->next()->isAttributeUsed(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( pure|__pure__ )")) {
|
|
||||||
// type func(...) __attribute__((pure));
|
|
||||||
if (tok->previous() && tok->previous()->link() && Token::Match(tok->previous()->link()->previous(), "%var% ("))
|
if (tok->previous() && tok->previous()->link() && Token::Match(tok->previous()->link()->previous(), "%var% ("))
|
||||||
tok->previous()->link()->previous()->isAttributePure(true);
|
functok = tok->previous()->link()->previous();
|
||||||
|
|
||||||
// type __attribute__((pure)) func() { }
|
// type __attribute__((attribute)) func() { }
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
else {
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") __attribute__|__attribute (") &&
|
Token *tok2 = tok->next()->link();
|
||||||
Token::Match(tok->next()->link()->linkAt(2)->linkAt(2), ") %var% ("))
|
while (Token::Match(tok2, ") __attribute__|__attribute ("))
|
||||||
tok->next()->link()->linkAt(2)->linkAt(2)->next()->isAttributePure(true);
|
tok2 = tok2->linkAt(2);
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
if (Token::Match(tok2, ") %var% ("))
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") %var% ("))
|
functok = tok2->next();
|
||||||
tok->next()->link()->linkAt(2)->next()->isAttributePure(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") %var% ("))
|
|
||||||
tok->next()->link()->next()->isAttributePure(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( const|__const__ )")) {
|
if (functok) {
|
||||||
// type func(...) __attribute__((const));
|
if (attribute.find("pure") != std::string::npos)
|
||||||
if (tok->previous() && tok->previous()->link() && Token::Match(tok->previous()->link()->previous(), "%var% ("))
|
functok->isAttributePure(true);
|
||||||
tok->previous()->link()->previous()->isAttributeConst(true);
|
else if (attribute.find("const") != std::string::npos)
|
||||||
|
functok->isAttributeConst(true);
|
||||||
// type __attribute__((const)) func() { }
|
else if (attribute.find("noreturn") != std::string::npos)
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
functok->isAttributeNoreturn(true);
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") __attribute__|__attribute (") &&
|
else if (attribute.find("nothrow") != std::string::npos)
|
||||||
Token::Match(tok->next()->link()->linkAt(2)->linkAt(2), ") %var% ("))
|
functok->isAttributeNothrow(true);
|
||||||
tok->next()->link()->linkAt(2)->linkAt(2)->next()->isAttributeConst(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") %var% ("))
|
|
||||||
tok->next()->link()->linkAt(2)->next()->isAttributeConst(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") %var% ("))
|
|
||||||
tok->next()->link()->next()->isAttributeConst(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( noreturn|__noreturn__")) {
|
|
||||||
// type func(...) __attribute__((noreturn));
|
|
||||||
if (tok->previous() && tok->previous()->link() && Token::Match(tok->previous()->link()->previous(), "%var% ("))
|
|
||||||
tok->previous()->link()->previous()->isAttributeNoreturn(true);
|
|
||||||
|
|
||||||
// type __attribute__((noreturn)) func() { }
|
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2)->linkAt(2), ") %var% ("))
|
|
||||||
tok->next()->link()->linkAt(2)->linkAt(2)->next()->isAttributeNoreturn(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") %var% ("))
|
|
||||||
tok->next()->link()->linkAt(2)->next()->isAttributeNoreturn(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") %var% ("))
|
|
||||||
tok->next()->link()->next()->isAttributeNoreturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( nothrow|__nothrow__")) {
|
|
||||||
// type func(...) __attribute__((nothrow));
|
|
||||||
if (tok->previous() && tok->previous()->link() && Token::Match(tok->previous()->link()->previous(), "%var% ("))
|
|
||||||
tok->previous()->link()->previous()->isAttributeNothrow(true);
|
|
||||||
|
|
||||||
// type __attribute__((nothrow)) func() { }
|
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2)->linkAt(2), ") %var% ("))
|
|
||||||
tok->next()->link()->linkAt(2)->linkAt(2)->next()->isAttributeNothrow(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") __attribute__|__attribute (") &&
|
|
||||||
Token::Match(tok->next()->link()->linkAt(2), ") %var% ("))
|
|
||||||
tok->next()->link()->linkAt(2)->next()->isAttributeNothrow(true);
|
|
||||||
else if (Token::Match(tok->next()->link(), ") %var% ("))
|
|
||||||
tok->next()->link()->next()->isAttributeNothrow(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::eraseTokens(tok, tok->next()->link()->next());
|
Token::eraseTokens(tok, tok->next()->link()->next());
|
||||||
|
|
Loading…
Reference in New Issue