From 53dbcb956fcd33efe7b51299494ff5f83faf1067 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sun, 29 Nov 2015 13:23:13 +0100 Subject: [PATCH] Small refactoring: use a single complete set for reserved for each C/C++. Replace NULL by nullptr --- lib/symboldatabase.cpp | 7 ++++++- lib/symboldatabase.h | 24 ++++++++++++------------ lib/utils.h | 10 ++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4d2e308af..9503bfd34 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3642,6 +3642,7 @@ namespace { "static" << "struct" << "switch" << "typedef" << "union" << "unsigned" << "void" << "volatile" << "while"; const std::set cpp_keywords = make_container< std::set >() << + c_keywords << "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" << @@ -3654,9 +3655,13 @@ namespace { "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())); + if (isCPP()) + return cpp_keywords.find(iName) != cpp_keywords.cend(); + else + return c_keywords.find(iName) != c_keywords.cend(); } static const Token * parsedecl(const Token *type, ValueType * const valuetype); diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index fe77afadd..2c65013eb 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -49,7 +49,7 @@ enum AccessControl { Public, Protected, Private, Global, Namespace, Argument, Lo * @brief Array dimension information. */ struct Dimension { - Dimension() : start(NULL), end(NULL), num(0), known(true) { } + Dimension() : start(nullptr), end(nullptr), num(0), known(true) { } const Token *start; // size start token const Token *end; // size end token @@ -70,7 +70,7 @@ public: class BaseInfo { public: BaseInfo() : - type(NULL), nameTok(NULL), access(Public), isVirtual(false) { + type(nullptr), nameTok(nullptr), access(Public), isVirtual(false) { } std::string name; @@ -86,7 +86,7 @@ public: struct FriendInfo { FriendInfo() : - nameStart(NULL), nameEnd(NULL), type(NULL) { + nameStart(nullptr), nameEnd(nullptr), type(nullptr) { } const Token* nameStart; @@ -632,14 +632,14 @@ public: enum Type { eConstructor, eCopyConstructor, eMoveConstructor, eOperatorEqual, eDestructor, eFunction }; Function() - : tokenDef(NULL), - argDef(NULL), - token(NULL), - arg(NULL), - retDef(NULL), - retType(NULL), - functionScope(NULL), - nestedIn(NULL), + : tokenDef(nullptr), + argDef(nullptr), + token(nullptr), + arg(nullptr), + retDef(nullptr), + retType(nullptr), + functionScope(nullptr), + nestedIn(nullptr), initArgCount(0), type(eFunction), access(Public), @@ -1001,7 +1001,7 @@ public: */ void debugMessage(const Token *tok, const std::string &msg) const; - void printOut(const char * title = NULL) const; + void printOut(const char * title = nullptr) const; void printVariable(const Variable *var, const char *indent) const; void printXml(std::ostream &out) const; diff --git a/lib/utils.h b/lib/utils.h index db520292e..acd77e828 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -21,15 +21,25 @@ #define utilsH //--------------------------------------------------------------------------- +#include + +/*! Helper class to aid in the initializing global const data */ template < typename Cont > class make_container { public: typedef make_container< Cont > my_type; typedef typename Cont::value_type T; + my_type& operator<< (const T& val) { data_.insert(data_.end(), val); return *this; } + my_type& operator<< (const Cont& other_container) { + for (typename Cont::const_iterator it=other_container.begin(); it!=other_container.end(); ++it) { + data_.insert(data_.end(), *it); + } + return *this; + } my_type& operator<< (T&& val) { data_.insert(data_.end(), val); return *this;