Tokenizer: Simplified the bitfields handling. This patch just looks for the bitfield signature but doesn't care about the type. I don't think any other code would have this same signature so it should be OK. We could add code to only look in structures and classes but I don't think that is necessary. Ticket: #1956
This commit is contained in:
parent
807269b5e9
commit
3b716dfcc9
|
@ -7988,54 +7988,27 @@ void Tokenizer::simplifyAsm()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simplify bitfields
|
// Simplify bitfields
|
||||||
static bool isAllUpper(const Token *type)
|
|
||||||
{
|
|
||||||
if (type->isName())
|
|
||||||
{
|
|
||||||
bool allupper = true;
|
|
||||||
const std::string s(type->str());
|
|
||||||
for (std::string::size_type pos = 0; pos < s.size(); ++pos)
|
|
||||||
{
|
|
||||||
const char ch = s[pos];
|
|
||||||
if (!(ch == '_' || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')))
|
|
||||||
{
|
|
||||||
allupper = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allupper;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isBitfieldType(const Token *type)
|
|
||||||
{
|
|
||||||
if (Token::Match(type, "bool|char|short|int|long") || isAllUpper(type))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tokenizer::simplifyBitfields()
|
void Tokenizer::simplifyBitfields()
|
||||||
{
|
{
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
Token *last = 0;
|
Token *last = 0;
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
if (Token::Match(tok, ";|{|public:|protected:|private: %type% %var% : %num% ;|,") && isBitfieldType(tok->next()))
|
if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% : %num% ;|,"))
|
||||||
{
|
{
|
||||||
last = tok->tokAt(5);
|
if (tok->next()->str() == "const")
|
||||||
Token::eraseTokens(tok->tokAt(2), tok->tokAt(5));
|
offset = 1;
|
||||||
|
|
||||||
|
last = tok->tokAt(5 + offset);
|
||||||
|
Token::eraseTokens(tok->tokAt(2 + offset), tok->tokAt(5 + offset));
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok, ";|{|public:|protected:|private: const %type% %var% : %num% ;|,") && isBitfieldType(tok->tokAt(2)))
|
else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %num% ;"))
|
||||||
{
|
{
|
||||||
last = tok->tokAt(6);
|
if (tok->next()->str() == "const")
|
||||||
Token::eraseTokens(tok->tokAt(3), tok->tokAt(6));
|
offset = 1;
|
||||||
}
|
|
||||||
else if (Token::Match(tok, ";|{|public:|protected:|private: %type% : %num% ;") && isBitfieldType(tok->next()))
|
Token::eraseTokens(tok->tokAt(0), tok->tokAt(5 + offset));
|
||||||
{
|
|
||||||
Token::eraseTokens(tok->tokAt(0), tok->tokAt(5));
|
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4450,6 +4450,9 @@ private:
|
||||||
|
|
||||||
const char code2[] = "struct A { int a : 3; int : 3; int c : 3; };";
|
const char code2[] = "struct A { int a : 3; int : 3; int c : 3; };";
|
||||||
ASSERT_EQUALS("struct A { int a ; int c ; } ;", tokenizeAndStringify(code2,false));
|
ASSERT_EQUALS("struct A { int a ; int c ; } ;", tokenizeAndStringify(code2,false));
|
||||||
|
|
||||||
|
const char code3[] = "struct A { virtual void f() {} int f1 : 1; };";
|
||||||
|
ASSERT_EQUALS("struct A { virtual void f ( ) { } int f1 ; } ;", tokenizeAndStringify(code3,false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void microsoftMFC()
|
void microsoftMFC()
|
||||||
|
|
Loading…
Reference in New Issue