Fixed #1711 (Wrong typedef name shown when struct declared with __attribute__)

This commit is contained in:
Robert Reif 2010-05-27 18:15:42 +02:00 committed by Daniel Marjamäki
parent 8881a0c361
commit dc34a1b3ff
3 changed files with 32 additions and 0 deletions

View File

@ -1582,6 +1582,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
// remove calling conventions __cdecl, __stdcall..
simplifyCallingConvention();
// remove __attribute__((?))
simplifyAttribute();
// typedef..
simplifyTypedef();
@ -7537,3 +7540,20 @@ void Tokenizer::simplifyDeclspec()
}
}
void Tokenizer::simplifyAttribute()
{
while (Token::simpleMatch(_tokens, "__attribute__ (") && _tokens->next()->link() && _tokens->next()->link()->next())
{
Token::eraseTokens(_tokens, _tokens->next()->link()->next());
_tokens->deleteThis();
}
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::simpleMatch(tok, "__attribute__ (") && tok->next()->link() && tok->next()->link()->next())
{
Token::eraseTokens(tok, tok->next()->link()->next());
tok->deleteThis();
}
}
}

View File

@ -438,6 +438,11 @@ public:
*/
void simplifyCallingConvention();
/**
* Remove __attribute__ ((?))
*/
void simplifyAttribute();
/**
* This will return a short name describing function parameters
* e.g. parameters: (int a, char b) should get name "int,char,".

View File

@ -208,6 +208,7 @@ private:
TEST_CASE(removeRedundantAssignment);
TEST_CASE(removedeclspec);
TEST_CASE(removeattribute);
TEST_CASE(cpp0xtemplate);
TEST_CASE(arraySize);
@ -3264,6 +3265,12 @@ private:
ASSERT_EQUALS("int x [ ] ;", tokenizeAndStringify("__declspec(property(get=GetX, put=PutX)) int x[];"));
}
void removeattribute()
{
ASSERT_EQUALS("short array [ 3 ] ;", tokenizeAndStringify("short array[3] __attribute__ ((aligned));"));
ASSERT_EQUALS("int x [ 2 ] ;", tokenizeAndStringify("int x[2] __attribute__ ((packed));"));
}
void cpp0xtemplate()
{
const char *code = "template <class T>\n"