Skip to content

Commit

Permalink
Changed the order of some structures in order to improve, even if for…
Browse files Browse the repository at this point in the history
… a bit, their padding.
  • Loading branch information
Edoardo Prezioso committed May 14, 2012
1 parent fc7f782 commit eacf74b
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 59 deletions.
4 changes: 2 additions & 2 deletions cli/cmdlineparser.h
Expand Up @@ -106,13 +106,13 @@ class CmdLineParser {
void PrintMessage(const std::string &message) const;

private:
std::vector<std::string> _pathnames;
std::vector<std::string> _ignoredPaths;
Settings *_settings;
bool _showHelp;
bool _showVersion;
bool _showErrorMessages;
bool _exitAfterPrint;
std::vector<std::string> _pathnames;
std::vector<std::string> _ignoredPaths;
};

/// @}
Expand Down
10 changes: 5 additions & 5 deletions cli/cppcheckexecutor.h
Expand Up @@ -112,6 +112,11 @@ class CppCheckExecutor : public ErrorLogger {
*/
std::set<std::string> _errorList;

/**
* Filename associated with size of file
*/
std::map<std::string, size_t> _files;

/**
* Report progress time
*/
Expand All @@ -121,11 +126,6 @@ class CppCheckExecutor : public ErrorLogger {
* Has --errorlist been given?
*/
bool errorlist;

/**
* Filename associated with size of file
*/
std::map<std::string, size_t> _files;
};

#endif // CPPCHECKEXECUTOR_H
2 changes: 1 addition & 1 deletion cli/threadexecutor.h
Expand Up @@ -79,8 +79,8 @@ class ThreadExecutor : public ErrorLogger {
* Write end of status pipe, different for each child.
* Not used in master process.
*/
int _wpipe;
std::list<std::string> _errorList;
int _wpipe;

public:
/**
Expand Down
6 changes: 3 additions & 3 deletions lib/checkbufferoverrun.h
Expand Up @@ -114,15 +114,15 @@ class CheckBufferOverrun : public Check {
/** number of elements of array */
std::vector<MathLib::bigint> _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 &);
Expand Down
9 changes: 5 additions & 4 deletions lib/checkunusedvar.cpp
Expand Up @@ -46,8 +46,8 @@ class Variables {
bool modified = false,
bool allocateMemory = false) :
_name(name),
_type(type),
_scope(scope),
_type(type),
_read(read),
_write(write),
_modified(modified),
Expand All @@ -65,15 +65,16 @@ class Variables {
return (_read == false && _write == false);
}

std::set<unsigned int> _aliases;
std::set<const Scope*> _assignments;

const Token *_name;
VariableType _type;
const Scope *_scope;
VariableType _type;
bool _read;
bool _write;
bool _modified; // read/modify/write
bool _allocateMemory;
std::set<unsigned int> _aliases;
std::set<const Scope*> _assignments;
};

typedef std::map<unsigned int, VariableUsage> VariableMap;
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.cpp
Expand Up @@ -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)
{
}

Expand Down
6 changes: 4 additions & 2 deletions lib/cppcheck.h
Expand Up @@ -167,10 +167,8 @@ class CppCheck : ErrorLogger {
*/
static void replaceAll(std::string& code, const std::string &from, const std::string &to);

unsigned int exitcode;
std::list<std::string> _errorList;
Settings _settings;
bool _useGlobalSuppressions;
std::string _fileContent;
std::set<std::string> _dependencies;

Expand All @@ -181,6 +179,10 @@ class CppCheck : ErrorLogger {

/** @brief Current preprocessor configuration */
std::string cfg;

unsigned int exitcode;

bool _useGlobalSuppressions;
};

/// @}
Expand Down
4 changes: 2 additions & 2 deletions lib/errorlogger.cpp
Expand Up @@ -37,16 +37,16 @@ ErrorLogger::ErrorMessage::ErrorMessage()

ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &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
setmsg(msg);
}

ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& 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 Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) {
Expand Down
5 changes: 3 additions & 2 deletions lib/errorlogger.h
Expand Up @@ -213,13 +213,14 @@ class ErrorLogger {
bool deserialize(const std::string &data);

std::list<FileLocation> _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);

Expand Down
6 changes: 3 additions & 3 deletions lib/preprocessor.cpp
Expand Up @@ -2200,12 +2200,12 @@ class PreprocessorMacro {
/** 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;

Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Expand Up @@ -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)
{
Expand Down
20 changes: 10 additions & 10 deletions lib/symboldatabase.h
Expand Up @@ -367,6 +367,8 @@ class Function {
token(NULL),
arg(NULL),
start(NULL),
functionScope(NULL),
type(eFunction),
access(Public),
hasBody(false),
isInline(false),
Expand All @@ -377,9 +379,7 @@ class Function {
isFriend(false),
isExplicit(false),
isOperator(false),
retFuncPtr(false),
type(eFunction),
functionScope(NULL) {
retFuncPtr(false) {
}

std::size_t argCount() const {
Expand All @@ -396,6 +396,9 @@ class Function {
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<Variable> argumentList; // argument list
Type type; // constructor, destructor, ...
AccessControl access; // public/protected/private
bool hasBody; // has implementation
bool isInline; // implementation in class definition
Expand All @@ -407,9 +410,6 @@ class Function {
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<Variable> argumentList; // argument list

static bool argsMatch(const Scope *info, const Token *first, const Token *second, const std::string &path, unsigned int depth);

Expand All @@ -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 {
Expand All @@ -441,7 +441,6 @@ class Scope {
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
Expand All @@ -453,8 +452,9 @@ class Scope {
Scope *nestedIn;
std::list<Scope *> nestedList;
unsigned int numConstructors;
NeedInitialization needInitialization;
std::list<const Token *> usingList;
NeedInitialization needInitialization;
ScopeType type;

// function specific fields
Scope *functionOf; // scope this function belongs to
Expand Down
4 changes: 2 additions & 2 deletions lib/timer.cpp
Expand Up @@ -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)
, _timerResults(timerResults)
, _start(0)
, _showtimeMode(showtimeMode)
, _stopped(false)
, _timerResults(timerResults)
{
if (showtimeMode != SHOWTIME_NONE)
_start = std::clock();
Expand Down
4 changes: 2 additions & 2 deletions lib/timer.h
Expand Up @@ -69,10 +69,10 @@ class Timer {
Timer& operator=(const Timer&); // disallow assignments

const std::string _str;
const unsigned int _showtimeMode;
TimerResultsIntf* _timerResults;
std::clock_t _start;
const unsigned int _showtimeMode;
bool _stopped;
TimerResultsIntf* _timerResults;
};


Expand Down
12 changes: 6 additions & 6 deletions lib/token.cpp
Expand Up @@ -33,19 +33,19 @@ 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),
_isPointerCompare(false),
_isLong(false),
_isUnused(false),
_isStandardType(false),
_isExpandedMacro(false),
_varId(0),
_fileIndex(0),
_linenr(0),
_progressValue(0),
_str("")
_isExpandedMacro(false)
{
}

Expand Down
21 changes: 10 additions & 11 deletions lib/token.h
Expand Up @@ -472,6 +472,16 @@ class Token {
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;
Expand All @@ -481,24 +491,13 @@ class Token {
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. */
void update_property_info();

/** 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;
};

/// @}
Expand Down
2 changes: 1 addition & 1 deletion test/options.cpp
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion test/options.h
Expand Up @@ -44,9 +44,9 @@ class options {

private:
std::set<std::string> _options;
std::string _which_test;
const bool _gcc_style_errors;
const bool _quiet;
std::string _which_test;
};

#endif

0 comments on commit eacf74b

Please sign in to comment.