From df5d26901cabc0b64c96082dce39020ce5bc3617 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Mon, 24 Oct 2011 02:52:55 +0200 Subject: [PATCH] Add new warning option to check for dead code and change the order of some struct members to reduce structure padding. --- Makefile | 2 +- lib/token.cpp | 10 +++++----- lib/token.h | 10 ++++++---- lib/tokenize.cpp | 47 +++++++++++++++++------------------------------ lib/tokenize.h | 24 ++++++++++++------------ tools/dmake.cpp | 21 +++++++++++---------- 6 files changed, 52 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index e04b0acdb..0772a2724 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ifndef HAVE_RULES endif ifndef CXXFLAGS - CXXFLAGS=-Wall -Wextra -Wshadow -pedantic -Wno-long-long -Wfloat-equal -Wcast-qual -Woverloaded-virtual -Wsign-promo -Wabi -Winline -Wredundant-decls -Wpacked -Wmissing-format-attribute -Wmissing-declarations -D_GLIBCXX_DEBUG -g + CXXFLAGS=-pedantic -Wall -Wextra -Wabi -Wcast-qual -Wfloat-equal -Winline -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Woverloaded-virtual -Wpacked -Wredundant-decls -Wshadow -Wsign-promo -Wunreachable-code -D_GLIBCXX_DEBUG -g endif ifeq ($(HAVE_RULES),yes) diff --git a/lib/token.cpp b/lib/token.cpp index 5bcba4de0..fd42abb6a 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -30,7 +30,9 @@ Token::Token(Token **t) : tokensBack(t), - _str(""), + _next(0), + _previous(0), + _link(0), _isName(false), _isNumber(false), _isBoolean(false), @@ -40,12 +42,10 @@ Token::Token(Token **t) : _isLong(false), _isUnused(false), _varId(0), - _next(0), - _previous(0), - _link(0), _fileIndex(0), _linenr(0), - _progressValue(0) + _progressValue(0), + _str("") { } diff --git a/lib/token.h b/lib/token.h index 37d8a3979..581911b27 100644 --- a/lib/token.h +++ b/lib/token.h @@ -428,7 +428,10 @@ private: static int firstWordLen(const char *str); - std::string _str; + Token *_next; + Token *_previous; + Token *_link; + bool _isName; bool _isNumber; bool _isBoolean; @@ -438,9 +441,6 @@ private: bool _isLong; bool _isUnused; unsigned int _varId; - Token *_next; - Token *_previous; - Token *_link; unsigned int _fileIndex; unsigned int _linenr; @@ -453,6 +453,8 @@ private: * list this token is located. */ unsigned int _progressValue; + + std::string _str; }; /// @} diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 92cfca2ae..779dde147 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -42,41 +42,28 @@ //--------------------------------------------------------------------------- -Tokenizer::Tokenizer() - : _settings(0), _errorLogger(0) +Tokenizer::Tokenizer() : + _tokens(0), //no tokens to start with + _tokensBack(0), + _settings(0), + _errorLogger(0), + _symbolDatabase(0), + _varId(0), + _codeWithTemplates(false) //is there any templates? { - // No tokens to start with - _tokens = 0; - _tokensBack = 0; - - // is there any templates? - _codeWithTemplates = false; - - // symbol database - _symbolDatabase = NULL; - - // variable count - _varId = 0; } -Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) - : _settings(settings), _errorLogger(errorLogger) +Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) : + _tokens(0), //no tokens to start with + _tokensBack(0), + _settings(settings), + _errorLogger(errorLogger), + _symbolDatabase(0), + _varId(0), + _codeWithTemplates(false) //is there any templates? { // make sure settings are specified assert(_settings); - - // No tokens to start with - _tokens = 0; - _tokensBack = 0; - - // is there any templates? - _codeWithTemplates = false; - - // symbol database - _symbolDatabase = NULL; - - // variable count - _varId = 0; } Tokenizer::~Tokenizer() @@ -738,9 +725,9 @@ Token * Tokenizer::deleteInvalidTypedef(Token *typeDef) } struct Space { - bool isNamespace; std::string className; const Token * classEnd; + bool isNamespace; }; static Token *splitDefinitionFromTypedef(Token *tok) diff --git a/lib/tokenize.h b/lib/tokenize.h index f7dad0fe1..389302580 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -728,33 +728,33 @@ private: /** Token list */ Token *_tokens, *_tokensBack; - /** sizeof information for known types */ - std::map _typeSize; - - /** filenames for the tokenized source code (source + included) */ - std::vector _files; - /** settings */ const Settings * _settings; /** errorlogger */ ErrorLogger * const _errorLogger; + /** Symbol database that all checks etc can use */ + mutable SymbolDatabase *_symbolDatabase; + /** E.g. "A" for code where "#ifdef A" is true. This is used to print additional information in error situations. */ std::string _configuration; + /** sizeof information for known types */ + std::map _typeSize; + + /** filenames for the tokenized source code (source + included) */ + std::vector _files; + + /** variable count */ + unsigned int _varId; + /** * was there any templates? templates that are "unused" are * removed from the token list */ bool _codeWithTemplates; - - /** Symbol database that all checks etc can use */ - mutable SymbolDatabase *_symbolDatabase; - - /** variable count */ - unsigned int _varId; }; /// @} diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 96512250b..0fde96654 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -216,21 +216,22 @@ int main(int argc, char **argv) // The _GLIBCXX_DEBUG doesn't work in cygwin makeConditionalVariable(fout, "CXXFLAGS", + "-pedantic " "-Wall " "-Wextra " - "-Wshadow " - "-pedantic " - "-Wno-long-long " - "-Wfloat-equal " - "-Wcast-qual " - "-Woverloaded-virtual " - "-Wsign-promo " "-Wabi " + "-Wcast-qual " + "-Wfloat-equal " "-Winline " - "-Wredundant-decls " - "-Wpacked " - "-Wmissing-format-attribute " "-Wmissing-declarations " + "-Wmissing-format-attribute " + "-Wno-long-long " + "-Woverloaded-virtual " + "-Wpacked " + "-Wredundant-decls " + "-Wshadow " + "-Wsign-promo " + "-Wunreachable-code " // "-Wsign-conversion " // "-Wconversion " "-D_GLIBCXX_DEBUG "