typedef: delete unhandled typedefs. ticket: #2348
This commit is contained in:
parent
a782d3ddf7
commit
63208e87d3
|
@ -691,6 +691,28 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
|
|||
Check::reportError(errmsg);
|
||||
}
|
||||
|
||||
Token * Tokenizer::deleteInvalidTypedef(Token *typeDef)
|
||||
{
|
||||
Token *tok = NULL;
|
||||
|
||||
// remove typedef but leave ;
|
||||
while (typeDef->next() && typeDef->next()->str() != ";")
|
||||
typeDef->deleteNext();
|
||||
|
||||
if (typeDef != _tokens)
|
||||
{
|
||||
tok = typeDef->previous();
|
||||
tok->deleteNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
_tokens->deleteThis();
|
||||
tok = _tokens;
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
struct SpaceInfo
|
||||
{
|
||||
bool isNamespace;
|
||||
|
@ -957,12 +979,11 @@ void Tokenizer::simplifyTypedef()
|
|||
// or a function typedef
|
||||
else if (Token::Match(tok->tokAt(offset), "("))
|
||||
{
|
||||
// unhandled typedef, skip it and continue
|
||||
if (typeName->str() == "void")
|
||||
{
|
||||
unsupportedTypedef(typeDef);
|
||||
|
||||
// unhandled typedef, skip it and continue
|
||||
tok = tok->tokAt(offset);
|
||||
tok = deleteInvalidTypedef(typeDef);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -979,12 +1000,12 @@ void Tokenizer::simplifyTypedef()
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// unhandled typedef, skip it and continue
|
||||
else
|
||||
{
|
||||
unsupportedTypedef(typeDef);
|
||||
|
||||
// unhandled typedef, skip it and continue
|
||||
tok = tok->tokAt(offset);
|
||||
tok = deleteInvalidTypedef(typeDef);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -1111,7 +1132,7 @@ void Tokenizer::simplifyTypedef()
|
|||
else
|
||||
{
|
||||
unsupportedTypedef(typeDef);
|
||||
|
||||
tok = deleteInvalidTypedef(typeDef);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -574,6 +574,8 @@ public:
|
|||
|
||||
SymbolDatabase * getSymbolDatabase() const;
|
||||
|
||||
Token * deleteInvalidTypedef(Token *typeDef);
|
||||
|
||||
private:
|
||||
/** Disable copy constructor, no implementation */
|
||||
Tokenizer(const Tokenizer &);
|
||||
|
|
|
@ -4646,7 +4646,7 @@ private:
|
|||
const char code[] = "typedef FMAC1 void (* a) ();\n"
|
||||
"void *(*b) ();\n";
|
||||
const std::string actual(sizeof_(code));
|
||||
ASSERT_EQUALS("typedef FMAC1 void ( * a ) ( ) ; void * * b ;", actual);
|
||||
ASSERT_EQUALS("; void * * b ;", actual);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue