Fixed #1619 (tokenizer: remove calling convention)
This commit is contained in:
parent
f378b382a0
commit
90541386da
|
@ -477,12 +477,12 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c
|
|||
total_size["strncpy"] = 3;
|
||||
total_size["memset"] = 3;
|
||||
}
|
||||
|
||||
|
||||
if (par == 2)
|
||||
{
|
||||
total_size["read"] = 3;
|
||||
total_size["write"] = 3;
|
||||
}
|
||||
total_size["write"] = 3;
|
||||
}
|
||||
|
||||
std::map<std::string, unsigned int>::const_iterator it = total_size.find(tok.str());
|
||||
if (it != total_size.end())
|
||||
|
|
|
@ -1284,6 +1284,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
|||
}
|
||||
}
|
||||
|
||||
// remove calling conventions __cdecl, __stdcall..
|
||||
simplifyCallingConvention();
|
||||
|
||||
// typedef..
|
||||
simplifyTypedef();
|
||||
|
||||
|
@ -7073,3 +7076,20 @@ void Tokenizer::simplifyStructDecl()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyCallingConvention()
|
||||
{
|
||||
const char * pattern = "__cdecl|__stdcall|__fastcall|__pascal|__thiscall|__fortran|__clrcall|WINAPI|APIENTRY|CALLBACK";
|
||||
while (Token::Match(_tokens, pattern))
|
||||
{
|
||||
_tokens->deleteThis();
|
||||
}
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
while (Token::Match(tok->next(), pattern))
|
||||
{
|
||||
tok->deleteNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -428,6 +428,11 @@ public:
|
|||
*/
|
||||
bool simplifyDoWhileAddBracesHelper(Token *tok);
|
||||
|
||||
/**
|
||||
* Remove calling convention
|
||||
*/
|
||||
void simplifyCallingConvention();
|
||||
|
||||
/**
|
||||
* This will return a short name describing function parameters
|
||||
* e.g. parameters: (int a, char b) should get name "int,char,".
|
||||
|
|
|
@ -237,6 +237,9 @@ private:
|
|||
// register int var; => int var;
|
||||
// inline int foo() {} => int foo() {}
|
||||
TEST_CASE(removeUnwantedKeywords);
|
||||
|
||||
// remove calling convention __cdecl, __stdcall, ...
|
||||
TEST_CASE(simplifyCallingConvention);
|
||||
}
|
||||
|
||||
std::string tok(const char code[], bool simplify = true)
|
||||
|
@ -4612,6 +4615,20 @@ private:
|
|||
ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true));
|
||||
ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true));
|
||||
}
|
||||
|
||||
void simplifyCallingConvention()
|
||||
{
|
||||
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 WINAPI f();", true));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int APIENTRY f();", true));
|
||||
ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", true));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSimplifyTokens)
|
||||
|
|
Loading…
Reference in New Issue