diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b4622ee42..013a6ea3b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1274,15 +1274,8 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s } } - // Remove __declspec(dllexport) - for (Token *tok = _tokens; tok; tok = tok->next()) - { - if (Token::simpleMatch(tok, "__declspec ( dllexport )")) - { - Token::eraseTokens(tok, tok->tokAt(4)); - tok->deleteThis(); - } - } + // Remove __declspec() + simplifyDeclspec(); // remove calling conventions __cdecl, __stdcall.. simplifyCallingConvention(); @@ -7080,7 +7073,7 @@ void Tokenizer::simplifyStructDecl() void Tokenizer::simplifyCallingConvention() { - const char * pattern = "__cdecl|__stdcall|__fastcall|__pascal|__thiscall|__fortran|__clrcall|WINAPI|APIENTRY|CALLBACK"; + const char * pattern = "__cdecl|__stdcall|__fastcall|__thiscall|__clrcall|__syscall|__pascal|__fortran|__far|__near|WINAPI|APIENTRY|CALLBACK"; while (Token::Match(_tokens, pattern)) { _tokens->deleteThis(); @@ -7094,3 +7087,20 @@ void Tokenizer::simplifyCallingConvention() } } +void Tokenizer::simplifyDeclspec() +{ + while (Token::simpleMatch(_tokens, "__declspec (") && _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, "__declspec (") && 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 964f688b1..6b79b0064 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -428,6 +428,11 @@ public: */ bool simplifyDoWhileAddBracesHelper(Token *tok); + /** + * Remove __declspec() + */ + void simplifyDeclspec(); + /** * Remove calling convention */ diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 5a2d51d2f..f0777fe2b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4637,10 +4637,19 @@ private: ASSERT_EQUALS("int f ( ) ;", tok("int __cdecl f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int __stdcall f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int __fastcall f();", true)); - ASSERT_EQUALS("int f ( ) ;", tok("int __pascal f();", true)); - ASSERT_EQUALS("int f ( ) ;", tok("int __fortran f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int __clrcall f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int __thiscall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __syscall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __pascal f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __fortran f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __cdecl f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __stdcall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __fastcall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __clrcall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __thiscall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __syscall f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __pascal f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("int __far __fortran f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int WINAPI f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int APIENTRY f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", true)); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 78ad3d1ea..efc78ea3b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3091,6 +3091,10 @@ private: void removedeclspec() { ASSERT_EQUALS("a b", tokenizeAndStringify("a __declspec ( dllexport ) b")); + ASSERT_EQUALS("int a ;", tokenizeAndStringify("__declspec(thread) __declspec(align(32)) int a;")); + ASSERT_EQUALS("int i ;", tokenizeAndStringify("__declspec(allocate(\"mycode\")) int i;")); + ASSERT_EQUALS("struct IUnknown ;", tokenizeAndStringify("struct __declspec(uuid(\"00000000-0000-0000-c000-000000000046\")) IUnknown;")); + ASSERT_EQUALS("int x [ ] ;", tokenizeAndStringify("__declspec(property(get=GetX, put=PutX)) int x[];")); } void cpp0xtemplate()