From dc34a1b3ffa42df3a7e0be71ccc538b0e8e9ebd4 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 27 May 2010 18:15:42 +0200 Subject: [PATCH] Fixed #1711 (Wrong typedef name shown when struct declared with __attribute__) --- lib/tokenize.cpp | 20 ++++++++++++++++++++ lib/tokenize.h | 5 +++++ test/testtokenize.cpp | 7 +++++++ 3 files changed, 32 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f12c7c542..6e71c14cb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); + } + } +} + diff --git a/lib/tokenize.h b/lib/tokenize.h index b9bf7a8cd..392e81d67 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -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,". diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b17ee2274..e25a2cea4 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 \n"