From 60f5bd97dfefbb45caf0adc16c18305bd8423d6b Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Thu, 18 Jun 2015 19:07:51 +0200 Subject: [PATCH] Refactoring: missing include added, (potential) multi-threading issue fixed, expose static method to allow unit testing --- lib/checkcondition.cpp | 2 ++ lib/errorlogger.cpp | 6 ++---- lib/errorlogger.h | 2 ++ lib/symboldatabase.cpp | 10 ++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index aaa94850c..dc0c6d64a 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -24,6 +24,8 @@ #include "checkother.h" #include "symboldatabase.h" +#include + //--------------------------------------------------------------------------- // Register this check class (by creating a static instance of it) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index e216cecfa..03a2d93c1 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -29,8 +29,6 @@ #include #include -static std::string fixInvalidChars(const std::string& raw); - InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type type) : token(tok), errorMessage(errorMsg) { @@ -225,8 +223,8 @@ std::string ErrorLogger::ErrorMessage::getXMLFooter(int xml_version) } // There is no utf-8 support around but the strings should at least be safe for to tinyxml2. -// See #5300 "Invalid encoding in XML output" -static std::string fixInvalidChars(const std::string& raw) +// See #5300 "Invalid encoding in XML output" and #6431 "Invalid XML created - Invalid encoding of string literal " +std::string ErrorLogger::ErrorMessage::fixInvalidChars(const std::string& raw) { std::string result; result.reserve(raw.length()); diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 9c1feaecb..02210c24f 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -256,6 +256,8 @@ public: */ static void findAndReplace(std::string &source, const std::string &searchFor, const std::string &replaceWith); + static std::string fixInvalidChars(const std::string& raw); + /** Short message */ std::string _shortMessage; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5a8e23011..277254409 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3602,15 +3602,14 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n //--------------------------------------------------------------------------- -bool SymbolDatabase::isReservedName(const std::string& iName) const -{ - static const std::set c_keywords = make_container>() << +namespace { + const std::set c_keywords = make_container>() << "auto" << "break" << "case" << "char" << "const" << "continue" << "default" << "do" << "double" << "else" << "enum" << "extern" << "float" << "for" << "goto" << "if" << "inline" << "int" << "long" << "register" << "restrict" << "return" << "short" << "signed" << "sizeof" << "static" << "struct" << "switch" << "typedef" << "union" << "unsigned" << "void" << "volatile" << "while"; - static const std::set cpp_keywords = make_container>() << + const std::set cpp_keywords = make_container>() << "alignas" << "alignof" << "and" << "and_eq" << "asm" << "auto" << "bitand" << "bitor" << "bool" << "break" << "case" << "catch" << "char" << "char16_t" << "char32_t" << "class" << "compl" << "concept" << "const" << "constexpr" << "const_cast" << "continue" << "decltype" << "default" << @@ -3622,5 +3621,8 @@ bool SymbolDatabase::isReservedName(const std::string& iName) const "static_cast" << "struct" << "switch" << "template" << "this" << "thread_local" << "throw" << "true" << "try" << "typedef" << "typeid" << "typename" << "union" << "unsigned" << "using" << "virtual" << "void" << "volatile" << "wchar_t" << "while" << "xor" << "xor_eq"; +} +bool SymbolDatabase::isReservedName(const std::string& iName) const +{ return (c_keywords.find(iName) != c_keywords.cend()) || (isCPP() && (cpp_keywords.find(iName) != cpp_keywords.cend())); }