Replace Tokenizer::simplifyBuiltinExpect by a suitable addition to gnu.cfg

This commit is contained in:
Alexander Mai 2015-08-10 20:21:30 +02:00
parent 57aec12f34
commit a5aba110a4
3 changed files with 77 additions and 105 deletions

View File

@ -296,6 +296,9 @@
</arg> </arg>
<leak-ignore/> <leak-ignore/>
</function> </function>
<!-- see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html -->
<define name="__builtin_expect(X,Y)" value="(X)"/>
<!-- see http://kernelnewbies.org/FAQ/LikelyUnlikely -->
<define name="likely(X)" value="(X)"/> <define name="likely(X)" value="(X)"/>
<define name="unlikely(X)" value="(X)"/> <define name="unlikely(X)" value="(X)"/>
</def> </def>

View File

@ -3452,9 +3452,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// remove Borland stuff.. // remove Borland stuff..
simplifyBorland(); simplifyBorland();
// Remove __builtin_expect
simplifyBuiltinExpect();
if (hasEnumsWithTypedef()) { if (hasEnumsWithTypedef()) {
// #2449: syntax error: enum with typedef in it // #2449: syntax error: enum with typedef in it
list.deallocateTokens(); list.deallocateTokens();
@ -6038,7 +6035,7 @@ void Tokenizer::simplifyIfSameInnerCondition()
// Binary operators simplification map // Binary operators simplification map
namespace { namespace {
static const std::map<std::string, std::string> cAlternativeTokens = make_container< std::map<std::string, std::string> >() const std::map<std::string, std::string> cAlternativeTokens = make_container< std::map<std::string, std::string> >()
<< std::make_pair("and", "&&") << std::make_pair("and", "&&")
<< std::make_pair("and_eq", "&=") << std::make_pair("and_eq", "&=")
<< std::make_pair("bitand", "&") << std::make_pair("bitand", "&")
@ -7909,14 +7906,14 @@ void Tokenizer::simplifyEnum()
} }
namespace { namespace {
static const std::set<std::string> f = make_container< std::set<std::string> > () << const std::set<std::string> f = make_container< std::set<std::string> > () <<
"strcat" << "strcat" <<
"strcpy" << "strcpy" <<
"strncat" << "strncat" <<
"strncpy" << "strncpy" <<
"free" << "free" <<
"malloc" << "malloc" <<
"strdup"; "strdup";
} }
void Tokenizer::simplifyStd() void Tokenizer::simplifyStd()
@ -9199,15 +9196,15 @@ void Tokenizer::simplifyAttribute()
} }
namespace { namespace {
static const std::set<std::string> keywords = make_container< std::set<std::string> >() const std::set<std::string> keywords = make_container< std::set<std::string> >()
<< "volatile" << "volatile"
<< "inline" << "inline"
<< "_inline" << "_inline"
<< "__inline" << "__inline"
<< "__forceinline" << "__forceinline"
<< "register" << "register"
<< "__restrict" << "__restrict"
<< "__restrict__" ; << "__restrict__" ;
} }
// Remove "volatile", "inline", "register", "restrict", "override", "final", "static" and "constexpr" // Remove "volatile", "inline", "register", "restrict", "override", "final", "static" and "constexpr"
// "restrict" keyword // "restrict" keyword
@ -9533,59 +9530,36 @@ void Tokenizer::simplifyBitfields()
} }
// Remove __builtin_expect(...)
void Tokenizer::simplifyBuiltinExpect()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (!Token::simpleMatch(tok->next(), "__builtin_expect ("))
continue;
// Count parentheses for tok2
const Token* end = tok->linkAt(2);
for (Token *tok2 = tok->tokAt(3); tok2 != end; tok2 = tok2->next()) {
if (tok2->str() == "(") {
tok2 = tok2->link();
} else if (tok2->str() == ",") {
if (Token::Match(tok2, ", %num% )")) {
tok->deleteNext();
tok2->deleteNext();
tok2->deleteThis();
}
break;
}
}
}
}
namespace { namespace {
// Types and objects in std namespace that are neither functions nor templates // Types and objects in std namespace that are neither functions nor templates
static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() << const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
"string"<< "wstring"<< "u16string"<< "u32string" << "string"<< "wstring"<< "u16string"<< "u32string" <<
"iostream"<< "ostream"<< "ofstream"<< "ostringstream" << "iostream"<< "ostream"<< "ofstream"<< "ostringstream" <<
"istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" << "istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" <<
"wstringstream"<< "wistringstream"<< "wostringstream"<< "wstringbuf" << "wstringstream"<< "wistringstream"<< "wostringstream"<< "wstringbuf" <<
"stringbuf"<< "streambuf"<< "ios"<< "filebuf"<< "ios_base" << "stringbuf"<< "streambuf"<< "ios"<< "filebuf"<< "ios_base" <<
"exception"<< "bad_exception"<< "bad_alloc" << "exception"<< "bad_exception"<< "bad_alloc" <<
"logic_error"<< "domain_error"<< "invalid_argument_"<< "length_error" << "logic_error"<< "domain_error"<< "invalid_argument_"<< "length_error" <<
"out_of_range"<< "runtime_error"<< "range_error"<< "overflow_error"<< "underflow_error" << "out_of_range"<< "runtime_error"<< "range_error"<< "overflow_error"<< "underflow_error" <<
"locale" << "locale" <<
"cout"<< "cerr"<< "clog"<< "cin" << "cout"<< "cerr"<< "clog"<< "cin" <<
"wcerr"<< "wcin"<< "wclog"<< "wcout" << "wcerr"<< "wcin"<< "wclog"<< "wcout" <<
"endl"<< "ends"<< "flush" << "endl"<< "ends"<< "flush" <<
"boolalpha"<< "noboolalpha"<< "showbase"<< "noshowbase" << "boolalpha"<< "noboolalpha"<< "showbase"<< "noshowbase" <<
"showpoint"<< "noshowpoint"<< "showpos"<< "noshowpos" << "showpoint"<< "noshowpoint"<< "showpos"<< "noshowpos" <<
"skipws"<< "noskipws"<< "unitbuf"<< "nounitbuf"<< "uppercase"<< "nouppercase" << "skipws"<< "noskipws"<< "unitbuf"<< "nounitbuf"<< "uppercase"<< "nouppercase" <<
"dec"<< "hex"<< "oct" << "dec"<< "hex"<< "oct" <<
"fixed"<< "scientific" << "fixed"<< "scientific" <<
"internal"<< "left"<< "right" << "internal"<< "left"<< "right" <<
"fpos"<< "streamoff"<< "streampos"<< "streamsize"; "fpos"<< "streamoff"<< "streampos"<< "streamsize";
static const std::set<std::string> stdTemplates = make_container<std::set<std::string> >() << const std::set<std::string> stdTemplates = make_container<std::set<std::string> >() <<
"array"<< "basic_string"<< "bitset"<< "deque"<< "list"<< "map"<< "multimap" << "array"<< "basic_string"<< "bitset"<< "deque"<< "list"<< "map"<< "multimap" <<
"priority_queue"<< "queue"<< "set"<< "multiset"<< "stack"<< "vector"<< "pair" << "priority_queue"<< "queue"<< "set"<< "multiset"<< "stack"<< "vector"<< "pair" <<
"iterator"<< "iterator_traits" << "iterator"<< "iterator_traits" <<
"unordered_map"<< "unordered_multimap"<< "unordered_set"<< "unordered_multiset" << "unordered_map"<< "unordered_multimap"<< "unordered_set"<< "unordered_multiset" <<
"tuple"<< "function"; "tuple"<< "function";
static const std::set<std::string> stdFunctions = make_container<std::set<std::string> >() << const std::set<std::string> stdFunctions = make_container<std::set<std::string> >() <<
"getline" << "getline" <<
"for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" << "for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" <<
"adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" << "adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" <<
@ -9721,40 +9695,40 @@ namespace {
std::string tchar, mbcs, unicode; std::string tchar, mbcs, unicode;
}; };
static const std::set<triplet> apis = make_container< std::set<triplet> >() << const std::set<triplet> apis = make_container< std::set<triplet> >() <<
triplet("_topen", "open", "_wopen") << triplet("_topen", "open", "_wopen") <<
triplet("_tsopen_s", "_sopen_s", "_wsopen_s") << triplet("_tsopen_s", "_sopen_s", "_wsopen_s") <<
triplet("_tfopen", "fopen", "_wfopen") << triplet("_tfopen", "fopen", "_wfopen") <<
triplet("_tfopen_s", "fopen_s", "_wfopen_s") << triplet("_tfopen_s", "fopen_s", "_wfopen_s") <<
triplet("_tfreopen", "freopen", "_wfreopen") << triplet("_tfreopen", "freopen", "_wfreopen") <<
triplet("_tfreopen_s", "freopen_s", "_wfreopen_s") << triplet("_tfreopen_s", "freopen_s", "_wfreopen_s") <<
triplet("_tcscat", "strcat", "wcscat") << triplet("_tcscat", "strcat", "wcscat") <<
triplet("_tcschr", "strchr", "wcschr") << triplet("_tcschr", "strchr", "wcschr") <<
triplet("_tcscmp", "strcmp", "wcscmp") << triplet("_tcscmp", "strcmp", "wcscmp") <<
triplet("_tcsdup", "strdup", "wcsdup") << triplet("_tcsdup", "strdup", "wcsdup") <<
triplet("_tcscpy", "strcpy", "wcscpy") << triplet("_tcscpy", "strcpy", "wcscpy") <<
triplet("_tcslen", "strlen", "wcslen") << triplet("_tcslen", "strlen", "wcslen") <<
triplet("_tcsncat", "strncat", "wcsncat") << triplet("_tcsncat", "strncat", "wcsncat") <<
triplet("_tcsncpy", "strncpy", "wcsncpy") << triplet("_tcsncpy", "strncpy", "wcsncpy") <<
triplet("_tcsnlen", "strnlen", "wcsnlen") << triplet("_tcsnlen", "strnlen", "wcsnlen") <<
triplet("_tcsrchr", "strrchr", "wcsrchr") << triplet("_tcsrchr", "strrchr", "wcsrchr") <<
triplet("_tcsstr", "strstr", "wcsstr") << triplet("_tcsstr", "strstr", "wcsstr") <<
triplet("_tcstok", "strtok", "wcstok") << triplet("_tcstok", "strtok", "wcstok") <<
triplet("_ftprintf", "fprintf", "fwprintf") << triplet("_ftprintf", "fprintf", "fwprintf") <<
triplet("_tprintf", "printf", "wprintf") << triplet("_tprintf", "printf", "wprintf") <<
triplet("_stprintf", "sprintf", "swprintf") << triplet("_stprintf", "sprintf", "swprintf") <<
triplet("_sntprintf", "_snprintf", "_snwprintf") << triplet("_sntprintf", "_snprintf", "_snwprintf") <<
triplet("_ftscanf", "fscanf", "fwscanf") << triplet("_ftscanf", "fscanf", "fwscanf") <<
triplet("_tscanf", "scanf", "wscanf") << triplet("_tscanf", "scanf", "wscanf") <<
triplet("_stscanf", "sscanf", "swscanf") << triplet("_stscanf", "sscanf", "swscanf") <<
triplet("_ftprintf_s", "fprintf_s", "fwprintf_s") << triplet("_ftprintf_s", "fprintf_s", "fwprintf_s") <<
triplet("_tprintf_s", "printf_s", "wprintf_s") << triplet("_tprintf_s", "printf_s", "wprintf_s") <<
triplet("_stprintf_s", "sprintf_s", "swprintf_s") << triplet("_stprintf_s", "sprintf_s", "swprintf_s") <<
triplet("_sntprintf_s", "_snprintf_s", "_snwprintf_s") << triplet("_sntprintf_s", "_snprintf_s", "_snwprintf_s") <<
triplet("_ftscanf_s", "fscanf_s", "fwscanf_s") << triplet("_ftscanf_s", "fscanf_s", "fwscanf_s") <<
triplet("_tscanf_s", "scanf_s", "wscanf_s") << triplet("_tscanf_s", "scanf_s", "wscanf_s") <<
triplet("_stscanf_s", "sscanf_s", "swscanf_s") triplet("_stscanf_s", "sscanf_s", "swscanf_s")
; ;
} }
void Tokenizer::simplifyMicrosoftStringFunctions() void Tokenizer::simplifyMicrosoftStringFunctions()

View File

@ -649,11 +649,6 @@ private:
*/ */
void simplifyBitfields(); void simplifyBitfields();
/**
* Remove __builtin_expect(...)
*/
void simplifyBuiltinExpect();
/** /**
* Remove unnecessary member qualification * Remove unnecessary member qualification
*/ */