From eacf74be8dc8463a6c5ace9514bbb744512194b5 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Mon, 14 May 2012 20:46:23 +0200 Subject: [PATCH] Changed the order of some structures in order to improve, even if for a bit, their padding. --- cli/cmdlineparser.h | 4 ++-- cli/cppcheckexecutor.h | 10 +++++----- cli/threadexecutor.h | 2 +- lib/checkbufferoverrun.h | 6 +++--- lib/checkunusedvar.cpp | 9 +++++---- lib/cppcheck.cpp | 2 +- lib/cppcheck.h | 6 ++++-- lib/errorlogger.cpp | 4 ++-- lib/errorlogger.h | 5 +++-- lib/preprocessor.cpp | 6 +++--- lib/symboldatabase.cpp | 2 +- lib/symboldatabase.h | 20 ++++++++++---------- lib/timer.cpp | 6 +++--- lib/timer.h | 6 +++--- lib/token.cpp | 12 ++++++------ lib/token.h | 21 ++++++++++----------- test/options.cpp | 2 +- test/options.h | 2 +- 18 files changed, 64 insertions(+), 61 deletions(-) diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 533ebd2a9..181ba836b 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -106,13 +106,13 @@ protected: void PrintMessage(const std::string &message) const; private: + std::vector _pathnames; + std::vector _ignoredPaths; Settings *_settings; bool _showHelp; bool _showVersion; bool _showErrorMessages; bool _exitAfterPrint; - std::vector _pathnames; - std::vector _ignoredPaths; }; /// @} diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index c65da6fe4..bc5ac8ab0 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -112,6 +112,11 @@ private: */ std::set _errorList; + /** + * Filename associated with size of file + */ + std::map _files; + /** * Report progress time */ @@ -121,11 +126,6 @@ private: * Has --errorlist been given? */ bool errorlist; - - /** - * Filename associated with size of file - */ - std::map _files; }; #endif // CPPCHECKEXECUTOR_H diff --git a/cli/threadexecutor.h b/cli/threadexecutor.h index bcb3afff1..abe57513c 100644 --- a/cli/threadexecutor.h +++ b/cli/threadexecutor.h @@ -79,8 +79,8 @@ private: * Write end of status pipe, different for each child. * Not used in master process. */ - int _wpipe; std::list _errorList; + int _wpipe; public: /** diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 13f511eae..f58e565e3 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -114,15 +114,15 @@ public: /** number of elements of array */ std::vector _num; + /** full name of variable as pattern */ + std::string _varname; + /** size of each element in array */ MathLib::bigint _element_size; /** variable id */ unsigned int _varid; - /** full name of variable as pattern */ - std::string _varname; - public: ArrayInfo(); ArrayInfo(const ArrayInfo &); diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index d7dbb3976..e7ab82e3e 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -46,8 +46,8 @@ public: bool modified = false, bool allocateMemory = false) : _name(name), - _type(type), _scope(scope), + _type(type), _read(read), _write(write), _modified(modified), @@ -65,15 +65,16 @@ public: return (_read == false && _write == false); } + std::set _aliases; + std::set _assignments; + const Token *_name; - VariableType _type; const Scope *_scope; + VariableType _type; bool _read; bool _write; bool _modified; // read/modify/write bool _allocateMemory; - std::set _aliases; - std::set _assignments; }; typedef std::map VariableMap; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a6f1606c6..55b9e63ba 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -40,7 +40,7 @@ static const char ExtraVersion[] = ""; static TimerResults S_timerResults; CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions) - : exitcode(0), _useGlobalSuppressions(useGlobalSuppressions), _errorLogger(errorLogger) + : _errorLogger(errorLogger), exitcode(0), _useGlobalSuppressions(useGlobalSuppressions) { } diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 16564d119..0ea07cd6e 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -167,10 +167,8 @@ private: */ static void replaceAll(std::string& code, const std::string &from, const std::string &to); - unsigned int exitcode; std::list _errorList; Settings _settings; - bool _useGlobalSuppressions; std::string _fileContent; std::set _dependencies; @@ -181,6 +179,10 @@ private: /** @brief Current preprocessor configuration */ std::string cfg; + + unsigned int exitcode; + + bool _useGlobalSuppressions; }; /// @} diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 8e5d90abd..aa9f14a4c 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -37,8 +37,8 @@ ErrorLogger::ErrorMessage::ErrorMessage() ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) : _callStack(callStack), // locations for this error message - _severity(severity), // severity for this error message _id(id), // set the message id + _severity(severity), // severity for this error message _inconclusive(inconclusive) { // set the summary and verbose messages @@ -46,7 +46,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack } ErrorLogger::ErrorMessage::ErrorMessage(const std::list& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) - : _severity(severity), _id(id), _inconclusive(inconclusive) + : _id(id), _severity(severity), _inconclusive(inconclusive) { // Format callstack for (std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 15365bcae..21cc536bc 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -213,13 +213,14 @@ public: bool deserialize(const std::string &data); std::list _callStack; - Severity::SeverityType _severity; std::string _id; - bool _inconclusive; /** source file (not header) */ std::string file0; + Severity::SeverityType _severity; + bool _inconclusive; + /** set short and verbose messages */ void setmsg(const std::string &msg); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e886572c7..f43044360 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2200,12 +2200,12 @@ private: /** macro definition in plain text */ const std::string _macro; - /** does this macro take a variable number of parameters? */ - bool _variadic; - /** prefix that is used by cppcheck to separate macro parameters. Always "__cppcheck__" */ const std::string _prefix; + /** does this macro take a variable number of parameters? */ + bool _variadic; + /** The macro has parentheses but no parameters.. "AAA()" */ bool _nopar; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 71b4c6814..b00efefa9 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1685,13 +1685,13 @@ const Variable* Function::getArgumentVar(unsigned int num) const Scope::Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_, ScopeType type_, const Token *start_) : check(check_), - type(type_), classDef(classDef_), classStart(start_), classEnd(start_->link()), nestedIn(nestedIn_), numConstructors(0), needInitialization(Scope::Unknown), + type(type_), functionOf(NULL), function(NULL) { diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 8509c90e7..849e37d4f 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -367,6 +367,8 @@ public: token(NULL), arg(NULL), start(NULL), + functionScope(NULL), + type(eFunction), access(Public), hasBody(false), isInline(false), @@ -377,9 +379,7 @@ public: isFriend(false), isExplicit(false), isOperator(false), - retFuncPtr(false), - type(eFunction), - functionScope(NULL) { + retFuncPtr(false) { } std::size_t argCount() const { @@ -396,6 +396,9 @@ public: const Token *token; // function name token in implementation const Token *arg; // function argument start '(' const Token *start; // function start '{' + Scope *functionScope; // scope of function body + std::list argumentList; // argument list + Type type; // constructor, destructor, ... AccessControl access; // public/protected/private bool hasBody; // has implementation bool isInline; // implementation in class definition @@ -407,9 +410,6 @@ public: bool isExplicit; // is explicit bool isOperator; // is operator bool retFuncPtr; // returns function pointer - Type type; // constructor, destructor, ... - Scope *functionScope; // scope of function body - std::list argumentList; // argument list static bool argsMatch(const Scope *info, const Token *first, const Token *second, const std::string &path, unsigned int depth); @@ -423,10 +423,10 @@ class Scope { public: struct BaseInfo { - AccessControl access; // public/protected/private - bool isVirtual; std::string name; Scope *scope; + AccessControl access; // public/protected/private + bool isVirtual; }; struct FriendInfo { @@ -441,7 +441,6 @@ public: Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_, ScopeType type_, const Token *start_); SymbolDatabase *check; - ScopeType type; std::string className; const Token *classDef; // class/struct/union/namespace token const Token *classStart; // '{' token @@ -453,8 +452,9 @@ public: Scope *nestedIn; std::list nestedList; unsigned int numConstructors; - NeedInitialization needInitialization; std::list usingList; + NeedInitialization needInitialization; + ScopeType type; // function specific fields Scope *functionOf; // scope this function belongs to diff --git a/lib/timer.cpp b/lib/timer.cpp index 2e928a2db..a989cf39f 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -60,10 +60,10 @@ void TimerResults::AddResults(const std::string& str, std::clock_t clocks) Timer::Timer(const std::string& str, unsigned int showtimeMode, TimerResultsIntf* timerResults) : _str(str) - , _showtimeMode(showtimeMode) - , _start(0) - , _stopped(false) , _timerResults(timerResults) + , _start(0) + , _showtimeMode(showtimeMode) + , _stopped(false) { if (showtimeMode != SHOWTIME_NONE) _start = std::clock(); diff --git a/lib/timer.h b/lib/timer.h index fcee0d74d..057c7d67d 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -69,10 +69,10 @@ private: Timer& operator=(const Timer&); // disallow assignments const std::string _str; - const unsigned int _showtimeMode; - std::clock_t _start; - bool _stopped; TimerResultsIntf* _timerResults; + std::clock_t _start; + const unsigned int _showtimeMode; + bool _stopped; }; diff --git a/lib/token.cpp b/lib/token.cpp index 5dfedadf8..ec79d0203 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -33,6 +33,11 @@ Token::Token(Token **t) : _next(0), _previous(0), _link(0), + _str(""), + _varId(0), + _fileIndex(0), + _linenr(0), + _progressValue(0), _type(eNone), _isUnsigned(false), _isSigned(false), @@ -40,12 +45,7 @@ Token::Token(Token **t) : _isLong(false), _isUnused(false), _isStandardType(false), - _isExpandedMacro(false), - _varId(0), - _fileIndex(0), - _linenr(0), - _progressValue(0), - _str("") + _isExpandedMacro(false) { } diff --git a/lib/token.h b/lib/token.h index eb96ae455..d029bd564 100644 --- a/lib/token.h +++ b/lib/token.h @@ -472,6 +472,16 @@ private: Token *_next; Token *_previous; Token *_link; + std::string _str; + unsigned int _varId; + unsigned int _fileIndex; + unsigned int _linenr; + + /** + * A value from 0-100 that provides a rough idea about where in the token + * list this token is located. + */ + unsigned int _progressValue; Type _type; bool _isUnsigned; @@ -481,9 +491,6 @@ private: bool _isUnused; bool _isStandardType; bool _isExpandedMacro; - unsigned int _varId; - unsigned int _fileIndex; - unsigned int _linenr; /** Updates internal property cache like _isName or _isBoolean. Called after any _str() modification. */ @@ -491,14 +498,6 @@ private: /** Update internal property cache about isStandardType() */ void update_property_isStandardType(); - - /** - * A value from 0-100 that provides a rough idea about where in the token - * list this token is located. - */ - unsigned int _progressValue; - - std::string _str; }; /// @} diff --git a/test/options.cpp b/test/options.cpp index 14ac51977..fc45f1761 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -18,9 +18,9 @@ options::options(int argc, const char* argv[]) :_options(&argv[1], &argv[0] + argc) + ,_which_test("") ,_gcc_style_errors(_options.count("-g") != 0) ,_quiet(_options.count("-q") != 0) - ,_which_test("") { _options.erase("-g"); _options.erase("-q"); diff --git a/test/options.h b/test/options.h index 3fec644f7..8be234396 100644 --- a/test/options.h +++ b/test/options.h @@ -44,9 +44,9 @@ private: private: std::set _options; + std::string _which_test; const bool _gcc_style_errors; const bool _quiet; - std::string _which_test; }; #endif