This commit is contained in:
Martin Ettl 2015-05-24 10:04:04 +02:00
commit 227a73eb45
2 changed files with 116 additions and 164 deletions

View File

@ -118,8 +118,10 @@ void Token::update_property_isStandardType()
if (_str.size() < 3) if (_str.size() < 3)
return; return;
static const char * const stdtype[] = { "bool", "char", "char16_t", "char32_t", "double", "float", "int", "long", "short", "size_t", "void", "wchar_t"}; static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
if (std::binary_search(stdtype, stdtype + sizeof(stdtype) / sizeof(stdtype[0]), _str)) { "bool" << "char" << "char16_t" << "char32_t" << "double" << "float" << "int" << "long" << "short" << "size_t" << "void" << "wchar_t";
if (stdTypes.find(_str)!=stdTypes.end()) {
isStandardType(true); isStandardType(true);
_type = eType; _type = eType;
} }

View File

@ -9564,54 +9564,50 @@ void Tokenizer::simplifyNamespaceStd()
if (!isCPP()) if (!isCPP())
return; return;
static const char* stdTypes_[] = { // Types and objects in std namespace that are neither functions nor templates // Types and objects in std namespace that are neither functions nor templates
"string", "wstring", "u16string", "u32string", static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
"iostream", "ostream", "ofstream", "ostringstream", "string"<< "wstring"<< "u16string"<< "u32string" <<
"istream", "ifstream", "istringstream", "fstream", "stringstream", "iostream"<< "ostream"<< "ofstream"<< "ostringstream" <<
"wstringstream", "wistringstream", "wostringstream", "wstringbuf", "istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" <<
"stringbuf", "streambuf", "ios", "filebuf", "ios_base", "wstringstream"<< "wistringstream"<< "wostringstream"<< "wstringbuf" <<
"exception", "bad_exception", "bad_alloc", "stringbuf"<< "streambuf"<< "ios"<< "filebuf"<< "ios_base" <<
"logic_error", "domain_error", "invalid_argument_", "length_error", "exception"<< "bad_exception"<< "bad_alloc" <<
"out_of_range", "runtime_error", "range_error", "overflow_error", "underflow_error", "logic_error"<< "domain_error"<< "invalid_argument_"<< "length_error" <<
"locale", "out_of_range"<< "runtime_error"<< "range_error"<< "overflow_error"<< "underflow_error" <<
"cout", "cerr", "clog", "cin", "locale" <<
"wcerr", "wcin", "wclog", "wcout", "cout"<< "cerr"<< "clog"<< "cin" <<
"endl", "ends", "flush", "wcerr"<< "wcin"<< "wclog"<< "wcout" <<
"boolalpha", "noboolalpha", "showbase", "noshowbase", "endl"<< "ends"<< "flush" <<
"showpoint", "noshowpoint", "showpos", "noshowpos", "boolalpha"<< "noboolalpha"<< "showbase"<< "noshowbase" <<
"skipws", "noskipws", "unitbuf", "nounitbuf", "uppercase", "nouppercase", "showpoint"<< "noshowpoint"<< "showpos"<< "noshowpos" <<
"dec", "hex", "oct", "skipws"<< "noskipws"<< "unitbuf"<< "nounitbuf"<< "uppercase"<< "nouppercase" <<
"fixed", "scientific", "dec"<< "hex"<< "oct" <<
"internal", "left", "right", "fixed"<< "scientific" <<
"fpos", "streamoff", "streampos", "streamsize" "internal"<< "left"<< "right" <<
}; "fpos"<< "streamoff"<< "streampos"<< "streamsize";
static const std::set<std::string> stdTypes(stdTypes_, stdTypes_+sizeof(stdTypes_)/sizeof(*stdTypes_));
static const char* stdTemplates_[] = { static 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> >() <<
static const std::set<std::string> stdTemplates(stdTemplates_, stdTemplates_+sizeof(stdTemplates_)/sizeof(*stdTemplates_)); "getline" <<
static const char* stdFunctions_[] = { "for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" <<
"getline", "adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" <<
"for_each", "find", "find_if", "find_end", "find_first_of", "copy"<< "copy_backward"<< "swap"<< "swap_ranges"<< "iter_swap"<< "transform"<< "replace" <<
"adjacent_find", "count", "count_if", "mismatch", "equal", "search", "search_n", "replace_if"<< "replace_copy"<< "replace_copy_if"<< "fill"<< "fill_n"<< "generate"<< "generate_n"<< "remove" <<
"copy", "copy_backward", "swap", "swap_ranges", "iter_swap", "transform", "replace", "remove_if"<< "remove_copy"<< "remove_copy_if" <<
"replace_if", "replace_copy", "replace_copy_if", "fill", "fill_n", "generate", "generate_n", "remove", "unique"<< "unique_copy"<< "reverse"<< "reverse_copy" <<
"remove_if", "remove_copy", "remove_copy_if", "rotate"<< "rotate_copy"<< "random_shuffle"<< "partition"<< "stable_partition" <<
"unique", "unique_copy", "reverse", "reverse_copy", "sort"<< "stable_sort"<< "partial_sort"<< "partial_sort_copy"<< "nth_element" <<
"rotate", "rotate_copy", "random_shuffle", "partition", "stable_partition", "lower_bound"<< "upper_bound"<< "equal_range"<< "binary_search"<< "merge"<< "inplace_merge"<< "includes" <<
"sort", "stable_sort", "partial_sort", "partial_sort_copy", "nth_element", "set_union"<< "set_intersection"<< "set_difference" <<
"lower_bound", "upper_bound", "equal_range", "binary_search", "merge", "inplace_merge", "includes", "set_symmetric_difference"<< "push_heap"<< "pop_heap"<< "make_heap"<< "sort_heap" <<
"set_union", "set_intersection", "set_difference", "min"<< "max"<< "min_element"<< "max_element"<< "lexicographical_compare"<< "next_permutation"<< "prev_permutation" <<
"set_symmetric_difference", "push_heap", "pop_heap", "make_heap", "sort_heap", "advance"<< "back_inserter"<< "distance"<< "front_inserter"<< "inserter" <<
"min", "max", "min_element", "max_element", "lexicographical_compare", "next_permutation", "prev_permutation", "make_pair"<< "make_shared"<< "make_tuple";
"advance", "back_inserter", "distance", "front_inserter", "inserter",
"make_pair", "make_shared", "make_tuple"
};
static const std::set<std::string> stdFunctions(stdFunctions_, stdFunctions_+sizeof(stdFunctions_)/sizeof(*stdFunctions_));
const bool isCPP11 = _settings->standards.cpp == Standards::CPP11; const bool isCPP11 = _settings->standards.cpp == Standards::CPP11;
for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) { for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) {
@ -9715,108 +9711,63 @@ void Tokenizer::simplifyMicrosoftMemoryFunctions()
void Tokenizer::simplifyMicrosoftStringFunctions() void Tokenizer::simplifyMicrosoftStringFunctions()
{ {
// skip if not Windows // skip if not Windows
if (_settings->platformType == Settings::Win32A || if (_settings->platformType != Settings::Win32A &&
_settings->platformType == Settings::Win32W || _settings->platformType != Settings::Win32W &
_settings->platformType == Settings::Win64) { _settings->platformType != Settings::Win64)
return;
struct triplet {
triplet(const char* t, const char* m, const char* u) : tchar(t), mbcs(m), unicode(u) {}
triplet(const std::string& t) : tchar(t) {}
bool operator <(const triplet& rhs) const {
return tchar < rhs.tchar;
}
std::string tchar, mbcs, unicode;
};
const static std::set<triplet> apis = make_container< std::set<triplet> >() <<
triplet("_topen", "open", "_wopen") <<
triplet("_tsopen_s", "_sopen_s", "_wsopen_s") <<
triplet("_tfopen", "fopen", "_wfopen") <<
triplet("_tfopen_s", "fopen_s", "_wfopen_s") <<
triplet("_tfreopen", "freopen", "_wfreopen") <<
triplet("_tfreopen_s", "freopen_s", "_wfreopen_s") <<
triplet("_tcscat", "strcat", "wcscat") <<
triplet("_tcschr", "strchr", "wcschr") <<
triplet("_tcscmp", "strcmp", "wcscmp") <<
triplet("_tcsdup", "strdup", "wcsdup") <<
triplet("_tcscpy", "strcpy", "wcscpy") <<
triplet("_tcslen", "strlen", "wcslen") <<
triplet("_tcsncat", "strncat", "wcsncat") <<
triplet("_tcsncpy", "strncpy", "wcsncpy") <<
triplet("_tcsnlen", "strnlen", "wcsnlen") <<
triplet("_tcsrchr", "strrchr", "wcsrchr") <<
triplet("_tcsstr", "strstr", "wcsstr") <<
triplet("_tcstok", "strtok", "wcstok") <<
triplet("_ftprintf", "fprintf", "fwprintf") <<
triplet("_tprintf", "printf", "wprintf") <<
triplet("_stprintf", "sprintf", "swprintf") <<
triplet("_sntprintf", "_snprintf", "_snwprintf") <<
triplet("_ftscanf", "fscanf", "fwscanf") <<
triplet("_tscanf", "scanf", "wscanf") <<
triplet("_stscanf", "sscanf", "swscanf") <<
triplet("_ftprintf_s", "fprintf_s", "fwprintf_s") <<
triplet("_tprintf_s", "printf_s", "wprintf_s") <<
triplet("_stprintf_s", "sprintf_s", "swprintf_s") <<
triplet("_sntprintf_s", "_snprintf_s", "_snwprintf_s") <<
triplet("_ftscanf_s", "fscanf_s", "fwscanf_s") <<
triplet("_tscanf_s", "scanf_s", "wscanf_s") <<
triplet("_stscanf_s", "sscanf_s", "swscanf_s")
;
const bool ansi = _settings->platformType == Settings::Win32A; const bool ansi = _settings->platformType == Settings::Win32A;
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "_topen (")) { std::set<triplet>::const_iterator match = apis.find(tok->str());
tok->str(ansi ? "open" : "_wopen"); if (match!=apis.end()) {
tok->originalName("_topen"); const std::string pattern(match->tchar + " (");
} else if (Token::simpleMatch(tok, "_tsopen_s (")) { if (Token::simpleMatch(tok, pattern.c_str())) {
tok->str(ansi ? "_sopen_s" : "_wsopen_s"); tok->str(ansi ? match->mbcs : match->unicode);
tok->originalName("_tsopen_s"); tok->originalName(match->tchar);
} else if (Token::simpleMatch(tok, "_tfopen (")) { }
tok->str(ansi ? "fopen" : "_wfopen");
tok->originalName("_tfopen");
} else if (Token::simpleMatch(tok, "_tfopen_s (")) {
tok->str(ansi ? "fopen_s" : "_wfopen_s");
tok->originalName("_tfopen_s");
} else if (Token::simpleMatch(tok, "_tfreopen (")) {
tok->str(ansi ? "freopen" : "_wfreopen");
tok->originalName("_tfreopen");
} else if (Token::simpleMatch(tok, "_tfreopen_s (")) {
tok->str(ansi ? "freopen_s" : "_wfreopen_s");
tok->originalName("_tfreopen_s");
} else if (Token::simpleMatch(tok, "_tcscat (")) {
tok->str(ansi ? "strcat" : "wcscat");
tok->originalName("_tcscat");
} else if (Token::simpleMatch(tok, "_tcschr (")) {
tok->str(ansi ? "strchr" : "wcschr");
tok->originalName("_tcschr");
} else if (Token::simpleMatch(tok, "_tcscmp (")) {
tok->str(ansi ? "strcmp" : "wcscmp");
tok->originalName("_tcscmp");
} else if (Token::simpleMatch(tok, "_tcsdup (")) {
tok->str(ansi ? "strdup" : "wcsdup");
tok->originalName("_tcsdup");
} else if (Token::simpleMatch(tok, "_tcscpy (")) {
tok->str(ansi ? "strcpy" : "wcscpy");
tok->originalName("_tcscpy");
} else if (Token::simpleMatch(tok, "_tcslen (")) {
tok->str(ansi ? "strlen" : "wcslen");
tok->originalName("_tcslen");
} else if (Token::simpleMatch(tok, "_tcsncat (")) {
tok->str(ansi ? "strncat" : "wcsncat");
tok->originalName("_tcsncat");
} else if (Token::simpleMatch(tok, "_tcsncpy (")) {
tok->str(ansi ? "strncpy" : "wcsncpy");
tok->originalName("_tcsncpy");
} else if (Token::simpleMatch(tok, "_tcsnlen (")) {
tok->str(ansi ? "strnlen" : "wcsnlen");
tok->originalName("_tcsnlen");
} else if (Token::simpleMatch(tok, "_tcsrchr (")) {
tok->str(ansi ? "strrchr" : "wcsrchr");
tok->originalName("_tcsrchr");
} else if (Token::simpleMatch(tok, "_tcsstr (")) {
tok->str(ansi ? "strstr" : "wcsstr");
tok->originalName("_tcsstr");
} else if (Token::simpleMatch(tok, "_tcstok (")) {
tok->str(ansi ? "strtok" : "wcstok");
tok->originalName("_tcstok");
} else if (Token::simpleMatch(tok, "_ftprintf (")) {
tok->str(ansi ? "fprintf" : "fwprintf");
tok->originalName("_ftprintf");
} else if (Token::simpleMatch(tok, "_tprintf (")) {
tok->str(ansi ? "printf" : "wprintf");
tok->originalName("_tprintf");
} else if (Token::simpleMatch(tok, "_stprintf (")) {
tok->str(ansi ? "sprintf" : "swprintf");
tok->originalName("_stprintf");
} else if (Token::simpleMatch(tok, "_sntprintf (")) {
tok->str(ansi ? "_snprintf" : "_snwprintf");
tok->originalName("_sntprintf");
} else if (Token::simpleMatch(tok, "_ftscanf (")) {
tok->str(ansi ? "fscanf" : "fwscanf");
tok->originalName("_ftscanf");
} else if (Token::simpleMatch(tok, "_tscanf (")) {
tok->str(ansi ? "scanf" : "wscanf");
tok->originalName("_tscanf");
} else if (Token::simpleMatch(tok, "_stscanf (")) {
tok->str(ansi ? "sscanf" : "swscanf");
tok->originalName("_stscanf");
} else if (Token::simpleMatch(tok, "_ftprintf_s (")) {
tok->str(ansi ? "fprintf_s" : "fwprintf_s");
tok->originalName("_ftprintf_s");
} else if (Token::simpleMatch(tok, "_tprintf_s (")) {
tok->str(ansi ? "printf_s" : "wprintf_s");
tok->originalName("_tprintf_s");
} else if (Token::simpleMatch(tok, "_stprintf_s (")) {
tok->str(ansi ? "sprintf_s" : "swprintf_s");
tok->originalName("_stprintf_s");
} else if (Token::simpleMatch(tok, "_sntprintf_s (")) {
tok->str(ansi ? "_snprintf_s" : "_snwprintf_s");
tok->originalName("_sntprintf_s");
} else if (Token::simpleMatch(tok, "_ftscanf_s (")) {
tok->str(ansi ? "fscanf_s" : "fwscanf_s");
tok->originalName("_ftscanf_s");
} else if (Token::simpleMatch(tok, "_tscanf_s (")) {
tok->str(ansi ? "scanf_s" : "wscanf_s");
tok->originalName("_tscanf_s");
} else if (Token::simpleMatch(tok, "_stscanf_s (")) {
tok->str(ansi ? "sscanf_s" : "swscanf_s");
tok->originalName("_stscanf_s");
} else if (Token::Match(tok, "_T ( %char%|%str% )")) { } else if (Token::Match(tok, "_T ( %char%|%str% )")) {
tok->deleteNext(); tok->deleteNext();
tok->deleteThis(); tok->deleteThis();
@ -9832,7 +9783,6 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
} }
} }
} }
}
} }
// Remove Borland code // Remove Borland code
@ -10382,7 +10332,7 @@ void Tokenizer::reportError(const Token* tok, const Severity::SeverityType sever
void Tokenizer::reportError(const std::list<const Token*>& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const void Tokenizer::reportError(const std::list<const Token*>& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) const
{ {
ErrorLogger::ErrorMessage errmsg(callstack, &list, severity, id, msg, inconclusive); const ErrorLogger::ErrorMessage errmsg(callstack, &list, severity, id, msg, inconclusive);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
else else