From c760ccee13f66be037d2bed9349f9dece4bacc83 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Thu, 27 Aug 2015 17:14:33 +0300 Subject: [PATCH] Use const_cast to add const, better variable name --- lib/symboldatabase.h | 8 ++++---- lib/token.cpp | 16 ++++++++-------- lib/token.h | 28 ++++++++++++++-------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 0379cdd0a..8fda6d8d9 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -871,12 +871,12 @@ public: const Scope *findRecordInNestedList(const std::string & name) const; Scope *findRecordInNestedList(const std::string & name) { - return const_cast(static_cast(this)->findRecordInNestedList(name)); + return const_cast(const_cast(this)->findRecordInNestedList(name)); } const Type* findType(const std::string& name) const; Type* findType(const std::string& name) { - return const_cast(static_cast(this)->findType(name)); + return const_cast(const_cast(this)->findType(name)); } /** @@ -975,12 +975,12 @@ public: const Type* findType(const Token *tok, const Scope *startScope) const; Type* findType(const Token *tok, Scope *startScope) const { - return const_cast(this->findType(tok, static_cast(startScope))); + return const_cast(this->findType(tok, const_cast(startScope))); } const Scope *findScope(const Token *tok, const Scope *startScope) const; Scope *findScope(const Token *tok, Scope *startScope) const { - return const_cast(this->findScope(tok, static_cast(startScope))); + return const_cast(this->findScope(tok, const_cast(startScope))); } const Variable *getVariableFromVarId(std::size_t varId) const { diff --git a/lib/token.cpp b/lib/token.cpp index 845d6dacb..388490d37 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -853,36 +853,36 @@ Token * Token::findClosingBracket() //--------------------------------------------------------------------------- -const Token *Token::findsimplematch(const Token *tok, const char pattern[]) +const Token *Token::findsimplematch(const Token *startTok, const char pattern[]) { - for (; tok; tok = tok->next()) { + for (const Token* tok = startTok; tok; tok = tok->next()) { if (Token::simpleMatch(tok, pattern)) return tok; } return 0; } -const Token *Token::findsimplematch(const Token *tok, const char pattern[], const Token *end) +const Token *Token::findsimplematch(const Token *startTok, const char pattern[], const Token *end) { - for (; tok && tok != end; tok = tok->next()) { + for (const Token* tok = startTok; tok && tok != end; tok = tok->next()) { if (Token::simpleMatch(tok, pattern)) return tok; } return 0; } -const Token *Token::findmatch(const Token *tok, const char pattern[], unsigned int varId) +const Token *Token::findmatch(const Token *startTok, const char pattern[], unsigned int varId) { - for (; tok; tok = tok->next()) { + for (const Token* tok = startTok; tok; tok = tok->next()) { if (Token::Match(tok, pattern, varId)) return tok; } return 0; } -const Token *Token::findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId) +const Token *Token::findmatch(const Token *startTok, const char pattern[], const Token *end, unsigned int varId) { - for (; tok && tok != end; tok = tok->next()) { + for (const Token* tok = startTok; tok && tok != end; tok = tok->next()) { if (Token::Match(tok, pattern, varId)) return tok; } diff --git a/lib/token.h b/lib/token.h index 0c0c5ec64..c537db643 100644 --- a/lib/token.h +++ b/lib/token.h @@ -105,7 +105,7 @@ public: */ const Token *tokAt(int index) const; Token *tokAt(int index) { - return const_cast(static_cast(this)->tokAt(index)); + return const_cast(const_cast(this)->tokAt(index)); } /** @@ -114,7 +114,7 @@ public: */ const Token *linkAt(int index) const; Token *linkAt(int index) { - return const_cast(static_cast(this)->linkAt(index)); + return const_cast(const_cast(this)->linkAt(index)); } /** @@ -388,21 +388,21 @@ public: setFlag(fIsComplex, value); } - static const Token *findsimplematch(const Token *tok, const char pattern[]); - static const Token *findsimplematch(const Token *tok, const char pattern[], const Token *end); - static const Token *findmatch(const Token *tok, const char pattern[], unsigned int varId = 0); - static const Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0); - static Token *findsimplematch(Token *tok, const char pattern[]) { - return const_cast(findsimplematch(static_cast(tok), pattern)); + static const Token *findsimplematch(const Token *startTok, const char pattern[]); + static const Token *findsimplematch(const Token *startTok, const char pattern[], const Token *end); + static const Token *findmatch(const Token *startTok, const char pattern[], unsigned int varId = 0); + static const Token *findmatch(const Token *startTok, const char pattern[], const Token *end, unsigned int varId = 0); + static Token *findsimplematch(Token *startTok, const char pattern[]) { + return const_cast(findsimplematch(const_cast(startTok), pattern)); } - static Token *findsimplematch(Token *tok, const char pattern[], const Token *end) { - return const_cast(findsimplematch(static_cast(tok), pattern, end)); + static Token *findsimplematch(Token *startTok, const char pattern[], const Token *end) { + return const_cast(findsimplematch(const_cast(startTok), pattern, end)); } - static Token *findmatch(Token *tok, const char pattern[], unsigned int varId = 0) { - return const_cast(findmatch(static_cast(tok), pattern, varId)); + static Token *findmatch(Token *startTok, const char pattern[], unsigned int varId = 0) { + return const_cast(findmatch(const_cast(startTok), pattern, varId)); } - static Token *findmatch(Token *tok, const char pattern[], const Token *end, unsigned int varId = 0) { - return const_cast(findmatch(static_cast(tok), pattern, end, varId)); + static Token *findmatch(Token *startTok, const char pattern[], const Token *end, unsigned int varId = 0) { + return const_cast(findmatch(const_cast(startTok), pattern, end, varId)); } /**