Report progress when checking a file takes a long time. Ticket: #1868

This commit is contained in:
Daniel Marjamäki 2010-07-24 18:58:52 +02:00
parent 05c4138b2f
commit b8146271a2
3 changed files with 54 additions and 1 deletions

View File

@ -231,3 +231,32 @@ void ErrorLogger::ErrorMessage::FileLocation::setfile(const std::string &file)
_file = file;
_file = Path::fromNativeSeparators(_file);
}
void ErrorLogger::ReportProgress(const char func[], const Token * const tok)
{
if (!func)
{
time1 = std::time(NULL);
return;
}
const std::time_t time2 = std::time(NULL);
if (time2 >= (time1 + 60))
{
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
<< " parsed-line=" << tok->linenr();
// Report progress message
reportOut(ostr.str());
}
}

View File

@ -20,6 +20,7 @@
#ifndef errorloggerH
#define errorloggerH
#include <ctime>
#include <list>
#include <string>
#include "settings.h"
@ -140,7 +141,10 @@ public:
std::string _id;
};
ErrorLogger() { }
ErrorLogger()
{
time1 = 0;
}
virtual ~ErrorLogger() { }
/**
@ -168,7 +172,19 @@ public:
*/
virtual void reportStatus(unsigned int index, unsigned int max) = 0;
/**
* Report progress.
*
* @param func function name (NULL = start command)
* @param tok current token
*/
void ReportProgress(const char func[], const Token * const tok);
static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);
private:
/** time variable for the 'ReportProgress' */
std::time_t time1;
};

View File

@ -1647,6 +1647,9 @@ void Tokenizer::simplifyTypedef()
bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::string &configuration)
{
if (_errorLogger)
_errorLogger->ReportProgress(0, 0);
_configuration = configuration;
// The "_files" vector remembers what files have been tokenized..
@ -2673,6 +2676,9 @@ void Tokenizer::setVarId()
if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%"))
continue;
if (_errorLogger)
_errorLogger->ReportProgress(__FUNCTION__, tok);
// If pattern is "( %type% *|& %var% )" then check if it's a
// variable declaration or a multiplication / mask
if (Token::Match(tok, "( %type% *|& %var% )") && !tok->next()->isStandardType())
@ -7851,3 +7857,5 @@ void Tokenizer::simplifyBuiltinExpect()
}
}