Tokenizer: some cleanup of std::
This commit is contained in:
parent
913ede45aa
commit
2358c51694
|
@ -2160,6 +2160,8 @@ bool Tokenizer::simplifyTokenList()
|
|||
tok->deleteNext();
|
||||
}
|
||||
|
||||
simplifyStd();
|
||||
|
||||
simplifyNamespaces();
|
||||
|
||||
simplifyGoto();
|
||||
|
@ -4543,6 +4545,32 @@ void Tokenizer::simplifyEnum()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Tokenizer::simplifyStd()
|
||||
{
|
||||
std::set<std::string> f;
|
||||
f.insert("strcat");
|
||||
f.insert("strcpy");
|
||||
f.insert("strncat");
|
||||
f.insert("strncpy");
|
||||
f.insert("free");
|
||||
f.insert("malloc");
|
||||
f.insert("strdup");
|
||||
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() != "std")
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok->previous(), "[(,{};] std :: %var% (") &&
|
||||
f.find(tok->strAt(2)) != f.end())
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok->deleteThis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Helper functions for handling the tokens list
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -331,6 +331,11 @@ private:
|
|||
*/
|
||||
void simplifyEnum();
|
||||
|
||||
/**
|
||||
* Remove "std::" before some function names
|
||||
*/
|
||||
void simplifyStd();
|
||||
|
||||
/**
|
||||
* Remove exception specifications. This function calls itself recursively.
|
||||
* @param tok First token in scope to cleanup
|
||||
|
|
|
@ -164,6 +164,9 @@ private:
|
|||
|
||||
TEST_CASE(enum1);
|
||||
TEST_CASE(enum2);
|
||||
|
||||
// remove "std::" on some standard functions
|
||||
TEST_CASE(removestd);
|
||||
}
|
||||
|
||||
std::string tok(const char code[], bool simplify = true)
|
||||
|
@ -2719,6 +2722,16 @@ private:
|
|||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
|
||||
void removestd()
|
||||
{
|
||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));
|
||||
ASSERT_EQUALS("; strncpy ( a , b , 10 ) ;", tok("; std::strncpy(a,b,10);"));
|
||||
ASSERT_EQUALS("; strncat ( a , b , 10 ) ;", tok("; std::strncat(a,b,10);"));
|
||||
ASSERT_EQUALS("; free ( p ) ;", tok("; std::free(p);"));
|
||||
ASSERT_EQUALS("; malloc ( 10 ) ;", tok("; std::malloc(10);"));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSimplifyTokens)
|
||||
|
|
Loading…
Reference in New Issue