typedef: delete unhandled typedefs. ticket: #2348

This commit is contained in:
Robert Reif 2011-01-04 07:43:40 +01:00 committed by Daniel Marjamäki
parent a782d3ddf7
commit 63208e87d3
3 changed files with 31 additions and 8 deletions

View File

@ -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;
}

View File

@ -574,6 +574,8 @@ public:
SymbolDatabase * getSymbolDatabase() const;
Token * deleteInvalidTypedef(Token *typeDef);
private:
/** Disable copy constructor, no implementation */
Tokenizer(const Tokenizer &);

View File

@ -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());
}