Added ErrorLogger::reportProgress and removed ErrorLogger::ReportProgress. This will make it easier for GUI and other clients to display progress information.
This commit is contained in:
parent
6700351ede
commit
9edecd4a3f
|
@ -980,7 +980,9 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
||||||
if (tok->previous() && (!tok->previous()->isName() && !Token::Match(tok->previous(), "[;{}]")))
|
if (tok->previous() && (!tok->previous()->isName() && !Token::Match(tok->previous(), "[;{}]")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_errorLogger->ReportProgress("CheckBufferOverrun::checkGlobalAndLocalVariable");
|
_errorLogger->reportProgress(_tokenizer->getFiles()->front(),
|
||||||
|
"Check (BufferOverrun::checkGlobalAndLocalVariable)",
|
||||||
|
tok->progressValue());
|
||||||
|
|
||||||
ArrayInfo arrayInfo;
|
ArrayInfo arrayInfo;
|
||||||
if (arrayInfo.declare(tok, *_tokenizer))
|
if (arrayInfo.declare(tok, *_tokenizer))
|
||||||
|
|
|
@ -171,6 +171,7 @@ CppCheck::CppCheck(ErrorLogger &errorLogger)
|
||||||
: _errorLogger(errorLogger)
|
: _errorLogger(errorLogger)
|
||||||
{
|
{
|
||||||
exitcode = 0;
|
exitcode = 0;
|
||||||
|
time1 = std::time(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCheck::~CppCheck()
|
CppCheck::~CppCheck()
|
||||||
|
@ -930,6 +931,32 @@ void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppCheck::reportProgress(const std::string &filename, const char stage[], const unsigned char value)
|
||||||
|
{
|
||||||
|
(void)filename;
|
||||||
|
|
||||||
|
// Report progress messages every 10 seconds
|
||||||
|
const std::time_t time2 = std::time(NULL);
|
||||||
|
if (time2 >= (time1 + 10))
|
||||||
|
{
|
||||||
|
time1 = time2;
|
||||||
|
|
||||||
|
// current time in the format "Www Mmm dd hh:mm:ss yyyy"
|
||||||
|
const std::string str(ctime(&time2));
|
||||||
|
|
||||||
|
// format a progress message
|
||||||
|
std::ostringstream ostr;
|
||||||
|
ostr << "progress: "
|
||||||
|
<< stage
|
||||||
|
<< " " << int(value) << "%";
|
||||||
|
if (_settings._verbose)
|
||||||
|
ostr << " time=" << str.substr(11, 8);
|
||||||
|
|
||||||
|
// Report progress message
|
||||||
|
reportOut(ostr.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CppCheck::getErrorMessages()
|
void CppCheck::getErrorMessages()
|
||||||
{
|
{
|
||||||
// call all "getErrorMessages" in all registered Check classes
|
// call all "getErrorMessages" in all registered Check classes
|
||||||
|
|
|
@ -19,14 +19,16 @@
|
||||||
#ifndef CPPCHECK_H
|
#ifndef CPPCHECK_H
|
||||||
#define CPPCHECK_H
|
#define CPPCHECK_H
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
|
#include "errorlogger.h"
|
||||||
|
#include "checkunusedfunctions.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "settings.h"
|
#include <ctime>
|
||||||
#include "errorlogger.h"
|
|
||||||
#include "checkunusedfunctions.h"
|
|
||||||
|
|
||||||
/// @addtogroup Core
|
/// @addtogroup Core
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -155,6 +157,8 @@ private:
|
||||||
*/
|
*/
|
||||||
virtual void reportOut(const std::string &outmsg);
|
virtual void reportOut(const std::string &outmsg);
|
||||||
|
|
||||||
|
void reportProgress(const std::string &filename, const char stage[], const unsigned char value);
|
||||||
|
|
||||||
unsigned int exitcode;
|
unsigned int exitcode;
|
||||||
std::list<std::string> _errorList;
|
std::list<std::string> _errorList;
|
||||||
std::ostringstream _errout;
|
std::ostringstream _errout;
|
||||||
|
@ -169,6 +173,8 @@ private:
|
||||||
|
|
||||||
/** @brief Current preprocessor configuration */
|
/** @brief Current preprocessor configuration */
|
||||||
std::string cfg;
|
std::string cfg;
|
||||||
|
|
||||||
|
std::time_t time1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -230,31 +230,3 @@ void ErrorLogger::ErrorMessage::FileLocation::setfile(const std::string &file)
|
||||||
_file = file;
|
_file = file;
|
||||||
_file = Path::fromNativeSeparators(_file);
|
_file = Path::fromNativeSeparators(_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ErrorLogger::ReportProgress(const char func[])
|
|
||||||
{
|
|
||||||
if (!func)
|
|
||||||
{
|
|
||||||
time1 = std::time(NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::time_t time2 = std::time(NULL);
|
|
||||||
if (time2 >= (time1 + 10))
|
|
||||||
{
|
|
||||||
time1 = time2;
|
|
||||||
|
|
||||||
// current time in the format "Www Mmm dd hh:mm:ss yyyy"
|
|
||||||
const std::string str(ctime(&time2));
|
|
||||||
|
|
||||||
// format a progress message
|
|
||||||
std::ostringstream ostr;
|
|
||||||
ostr << "progress:"
|
|
||||||
<< " time=" << str.substr(11, 8)
|
|
||||||
<< " function=" << func;
|
|
||||||
|
|
||||||
// Report progress message
|
|
||||||
reportOut(ostr.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#ifndef errorloggerH
|
#ifndef errorloggerH
|
||||||
#define errorloggerH
|
#define errorloggerH
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -141,10 +140,7 @@ public:
|
||||||
std::string _id;
|
std::string _id;
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorLogger()
|
ErrorLogger() { }
|
||||||
{
|
|
||||||
time1 = 0;
|
|
||||||
}
|
|
||||||
virtual ~ErrorLogger() { }
|
virtual ~ErrorLogger() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,17 +169,19 @@ public:
|
||||||
virtual void reportStatus(unsigned int index, unsigned int max) = 0;
|
virtual void reportStatus(unsigned int index, unsigned int max) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report progress.
|
* Report progress to client
|
||||||
*
|
* @param filename main file that is checked
|
||||||
* @param func function name (NULL = start command)
|
* @param stage for example preprocess / tokenize / simplify / check
|
||||||
|
* @param value progress value (0-100)
|
||||||
*/
|
*/
|
||||||
void ReportProgress(const char func[]);
|
virtual void reportProgress(const std::string &filename, const char stage[], const unsigned char value)
|
||||||
|
{
|
||||||
|
(void)filename;
|
||||||
|
(void)stage;
|
||||||
|
(void)value;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);
|
static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);
|
||||||
|
|
||||||
private:
|
|
||||||
/** time variable for the 'ReportProgress' */
|
|
||||||
std::time_t time1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -677,9 +677,6 @@ std::string Preprocessor::getdef(std::string line, bool def)
|
||||||
|
|
||||||
std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const std::string &filename)
|
std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const std::string &filename)
|
||||||
{
|
{
|
||||||
if (_errorLogger)
|
|
||||||
_errorLogger->ReportProgress(0);
|
|
||||||
|
|
||||||
std::list<std::string> ret;
|
std::list<std::string> ret;
|
||||||
ret.push_back("");
|
ret.push_back("");
|
||||||
|
|
||||||
|
@ -702,7 +699,8 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
||||||
++linenr;
|
++linenr;
|
||||||
|
|
||||||
if (_errorLogger)
|
if (_errorLogger)
|
||||||
_errorLogger->ReportProgress("Preprocessor::getcfgs");
|
_errorLogger->reportProgress(filename, "Preprocessing (get configurations 1)", 0);
|
||||||
|
|
||||||
|
|
||||||
if (line.compare(0, 6, "#file ") == 0)
|
if (line.compare(0, 6, "#file ") == 0)
|
||||||
{
|
{
|
||||||
|
@ -856,10 +854,11 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove defined constants from ifdef configurations..
|
// Remove defined constants from ifdef configurations..
|
||||||
|
unsigned int count = 0;
|
||||||
for (std::list<std::string>::iterator it = ret.begin(); it != ret.end(); ++it)
|
for (std::list<std::string>::iterator it = ret.begin(); it != ret.end(); ++it)
|
||||||
{
|
{
|
||||||
if (_errorLogger)
|
if (_errorLogger)
|
||||||
_errorLogger->ReportProgress("Preprocessor::getcfgs");
|
_errorLogger->reportProgress(filename, "Preprocessing (get configurations 2)", (100 * count++) / ret.size());
|
||||||
|
|
||||||
std::string cfg(*it);
|
std::string cfg(*it);
|
||||||
for (std::set<std::string>::const_iterator it2 = defines.begin(); it2 != defines.end(); ++it2)
|
for (std::set<std::string>::const_iterator it2 = defines.begin(); it2 != defines.end(); ++it2)
|
||||||
|
|
|
@ -43,7 +43,8 @@ Token::Token(Token **t) :
|
||||||
_previous(0),
|
_previous(0),
|
||||||
_link(0),
|
_link(0),
|
||||||
_fileIndex(0),
|
_fileIndex(0),
|
||||||
_linenr(0)
|
_linenr(0),
|
||||||
|
_progressValue(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,6 +590,10 @@ void Token::move(Token *srcStart, Token *srcEnd, Token *newLocation)
|
||||||
// Fix the tokens at newLocation
|
// Fix the tokens at newLocation
|
||||||
newLocation->next()->previous(srcEnd);
|
newLocation->next()->previous(srcEnd);
|
||||||
newLocation->next(srcStart);
|
newLocation->next(srcStart);
|
||||||
|
|
||||||
|
// Update _progressValue
|
||||||
|
for (Token *tok = srcStart; tok && tok != srcEnd; tok = tok->next())
|
||||||
|
tok->_progressValue = newLocation->_progressValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -619,6 +624,7 @@ void Token::insertToken(const std::string &tokenStr)
|
||||||
newToken->str(tokenStr);
|
newToken->str(tokenStr);
|
||||||
newToken->_linenr = _linenr;
|
newToken->_linenr = _linenr;
|
||||||
newToken->_fileIndex = _fileIndex;
|
newToken->_fileIndex = _fileIndex;
|
||||||
|
newToken->_progressValue = _progressValue;
|
||||||
if (this->next())
|
if (this->next())
|
||||||
{
|
{
|
||||||
newToken->next(this->next());
|
newToken->next(this->next());
|
||||||
|
|
18
lib/token.h
18
lib/token.h
|
@ -338,6 +338,23 @@ public:
|
||||||
*/
|
*/
|
||||||
static void move(Token *srcStart, Token *srcEnd, Token *newLocation);
|
static void move(Token *srcStart, Token *srcEnd, Token *newLocation);
|
||||||
|
|
||||||
|
/** Get progressValue */
|
||||||
|
unsigned char progressValue() const
|
||||||
|
{
|
||||||
|
return _progressValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Calculate progress values for all tokens */
|
||||||
|
void assignProgressValues()
|
||||||
|
{
|
||||||
|
unsigned int total_count = 0;
|
||||||
|
for (Token *tok = this; tok; tok = tok->next())
|
||||||
|
++total_count;
|
||||||
|
unsigned int count = 0;
|
||||||
|
for (Token *tok = this; tok; tok = tok->next())
|
||||||
|
tok->_progressValue = count++ * 100 / total_count;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void next(Token *nextToken)
|
void next(Token *nextToken)
|
||||||
{
|
{
|
||||||
|
@ -384,6 +401,7 @@ private:
|
||||||
Token *_link;
|
Token *_link;
|
||||||
unsigned int _fileIndex;
|
unsigned int _fileIndex;
|
||||||
unsigned int _linenr;
|
unsigned int _linenr;
|
||||||
|
unsigned char _progressValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -400,6 +400,7 @@ void Tokenizer::createTokens(std::istream &code)
|
||||||
CurrentToken += ch;
|
CurrentToken += ch;
|
||||||
}
|
}
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
addtoken(CurrentToken.c_str(), lineno, FileIndex, true);
|
||||||
|
_tokens->assignProgressValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, const std::string &type)
|
void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, const std::string &type)
|
||||||
|
@ -650,8 +651,8 @@ void Tokenizer::simplifyTypedef()
|
||||||
bool hasClass = false;
|
bool hasClass = false;
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (_errorLogger)
|
if (_errorLogger && !_files.empty())
|
||||||
_errorLogger->ReportProgress("Tokenizer::simplifyTypedef");
|
_errorLogger->reportProgress(_files[0], "Tokenize (typedef)", tok->progressValue());
|
||||||
|
|
||||||
if (Token::Match(tok, "class|struct|namespace %any%"))
|
if (Token::Match(tok, "class|struct|namespace %any%"))
|
||||||
{
|
{
|
||||||
|
@ -1651,9 +1652,6 @@ void Tokenizer::simplifyTypedef()
|
||||||
|
|
||||||
bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::string &configuration)
|
bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::string &configuration)
|
||||||
{
|
{
|
||||||
if (_errorLogger)
|
|
||||||
_errorLogger->ReportProgress(0);
|
|
||||||
|
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
|
||||||
// The "_files" vector remembers what files have been tokenized..
|
// The "_files" vector remembers what files have been tokenized..
|
||||||
|
@ -1829,10 +1827,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
||||||
//updateClassList();
|
//updateClassList();
|
||||||
setVarId();
|
setVarId();
|
||||||
|
|
||||||
if (!validate())
|
_tokens->assignProgressValues();
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return validate();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -2684,7 +2681,7 @@ void Tokenizer::setVarId()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (_errorLogger)
|
if (_errorLogger)
|
||||||
_errorLogger->ReportProgress("Tokenizer::setVarId");
|
_errorLogger->reportProgress(_files[0], "Tokenize (set variable id)", tok->progressValue());
|
||||||
|
|
||||||
// If pattern is "( %type% *|& %var% )" then check if it's a
|
// If pattern is "( %type% *|& %var% )" then check if it's a
|
||||||
// variable declaration or a multiplication / mask
|
// variable declaration or a multiplication / mask
|
||||||
|
@ -3693,6 +3690,8 @@ bool Tokenizer::simplifyTokenList()
|
||||||
_tokens->printOut(0, _files);
|
_tokens->printOut(0, _files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tokens->assignProgressValues();
|
||||||
|
|
||||||
return validate();
|
return validate();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue