tokenizer improvements: remove calling convention (#1619)

This commit is contained in:
Robert Reif 2010-04-24 09:40:05 +02:00 committed by Daniel Marjamäki
parent 5835b2665b
commit 99a7755218
4 changed files with 40 additions and 12 deletions

View File

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

View File

@ -428,6 +428,11 @@ public:
*/
bool simplifyDoWhileAddBracesHelper(Token *tok);
/**
* Remove __declspec()
*/
void simplifyDeclspec();
/**
* Remove calling convention
*/

View File

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

View File

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