Thread safety: changed local static variable 'count' to member variable
This commit is contained in:
parent
08ee5709ed
commit
2c3cd402ba
|
@ -147,8 +147,9 @@ Tokenizer::Tokenizer() :
|
||||||
_errorLogger(nullptr),
|
_errorLogger(nullptr),
|
||||||
_symbolDatabase(nullptr),
|
_symbolDatabase(nullptr),
|
||||||
_varId(0),
|
_varId(0),
|
||||||
|
_unnamedCount(0),
|
||||||
_codeWithTemplates(false), //is there any templates?
|
_codeWithTemplates(false), //is there any templates?
|
||||||
m_timerResults(nullptr)
|
_timerResults(nullptr)
|
||||||
#ifdef MAXTIME
|
#ifdef MAXTIME
|
||||||
,maxtime(std::time(0) + MAXTIME)
|
,maxtime(std::time(0) + MAXTIME)
|
||||||
#endif
|
#endif
|
||||||
|
@ -161,8 +162,9 @@ Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
|
||||||
_errorLogger(errorLogger),
|
_errorLogger(errorLogger),
|
||||||
_symbolDatabase(nullptr),
|
_symbolDatabase(nullptr),
|
||||||
_varId(0),
|
_varId(0),
|
||||||
|
_unnamedCount(0),
|
||||||
_codeWithTemplates(false), //is there any templates?
|
_codeWithTemplates(false), //is there any templates?
|
||||||
m_timerResults(nullptr)
|
_timerResults(nullptr)
|
||||||
#ifdef MAXTIME
|
#ifdef MAXTIME
|
||||||
,maxtime(std::time(0) + MAXTIME)
|
,maxtime(std::time(0) + MAXTIME)
|
||||||
#endif
|
#endif
|
||||||
|
@ -402,7 +404,7 @@ namespace {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Token *splitDefinitionFromTypedef(Token *tok)
|
static Token *splitDefinitionFromTypedef(Token *tok, unsigned int *unnamedCount)
|
||||||
{
|
{
|
||||||
Token *tok1;
|
Token *tok1;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -420,10 +422,8 @@ static Token *splitDefinitionFromTypedef(Token *tok)
|
||||||
// use typedef name if available
|
// use typedef name if available
|
||||||
if (Token::Match(tok1->next(), "%type%"))
|
if (Token::Match(tok1->next(), "%type%"))
|
||||||
name = tok1->next()->str();
|
name = tok1->next()->str();
|
||||||
else { // create a unique name
|
else // create a unique name
|
||||||
static unsigned int count = 0;
|
name = "Unnamed" + MathLib::toString((*unnamedCount)++);
|
||||||
name = "Unnamed" + MathLib::toString(count++);
|
|
||||||
}
|
|
||||||
tok->next()->insertToken(name);
|
tok->next()->insertToken(name);
|
||||||
} else
|
} else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -587,7 +587,7 @@ void Tokenizer::simplifyTypedef()
|
||||||
// pull struct, union, enum or class definition out of typedef
|
// pull struct, union, enum or class definition out of typedef
|
||||||
// use typedef name for unnamed struct, union, enum or class
|
// use typedef name for unnamed struct, union, enum or class
|
||||||
if (Token::Match(tok->next(), "const| struct|enum|union|class %type%| {")) {
|
if (Token::Match(tok->next(), "const| struct|enum|union|class %type%| {")) {
|
||||||
Token *tok1 = splitDefinitionFromTypedef(tok);
|
Token *tok1 = splitDefinitionFromTypedef(tok, &_unnamedCount);
|
||||||
if (!tok1)
|
if (!tok1)
|
||||||
continue;
|
continue;
|
||||||
tok = tok1;
|
tok = tok1;
|
||||||
|
@ -596,7 +596,7 @@ void Tokenizer::simplifyTypedef()
|
||||||
while (tok1 && tok1->str() != ";" && tok1->str() != "{")
|
while (tok1 && tok1->str() != ";" && tok1->str() != "{")
|
||||||
tok1 = tok1->next();
|
tok1 = tok1->next();
|
||||||
if (tok1 && tok1->str() == "{") {
|
if (tok1 && tok1->str() == "{") {
|
||||||
tok1 = splitDefinitionFromTypedef(tok);
|
tok1 = splitDefinitionFromTypedef(tok, &_unnamedCount);
|
||||||
if (!tok1)
|
if (!tok1)
|
||||||
continue;
|
continue;
|
||||||
tok = tok1;
|
tok = tok1;
|
||||||
|
@ -3559,8 +3559,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
simplifyAsm();
|
simplifyAsm();
|
||||||
|
|
||||||
// Bail out if code is garbage
|
// Bail out if code is garbage
|
||||||
if (m_timerResults) {
|
if (_timerResults) {
|
||||||
Timer t("Tokenizer::tokenize::findGarbageCode", _settings->showtime, m_timerResults);
|
Timer t("Tokenizer::tokenize::findGarbageCode", _settings->showtime, _timerResults);
|
||||||
findGarbageCode();
|
findGarbageCode();
|
||||||
} else {
|
} else {
|
||||||
findGarbageCode();
|
findGarbageCode();
|
||||||
|
@ -3723,8 +3723,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
simplifyVarDecl(false);
|
simplifyVarDecl(false);
|
||||||
|
|
||||||
// typedef..
|
// typedef..
|
||||||
if (m_timerResults) {
|
if (_timerResults) {
|
||||||
Timer t("Tokenizer::tokenize::simplifyTypedef", _settings->showtime, m_timerResults);
|
Timer t("Tokenizer::tokenize::simplifyTypedef", _settings->showtime, _timerResults);
|
||||||
simplifyTypedef();
|
simplifyTypedef();
|
||||||
} else {
|
} else {
|
||||||
simplifyTypedef();
|
simplifyTypedef();
|
||||||
|
@ -3841,8 +3841,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
|
|
||||||
validate(); // #6772 "segmentation fault (invalid code) in Tokenizer::setVarId"
|
validate(); // #6772 "segmentation fault (invalid code) in Tokenizer::setVarId"
|
||||||
|
|
||||||
if (m_timerResults) {
|
if (_timerResults) {
|
||||||
Timer t("Tokenizer::tokenize::setVarId", _settings->showtime, m_timerResults);
|
Timer t("Tokenizer::tokenize::setVarId", _settings->showtime, _timerResults);
|
||||||
setVarId();
|
setVarId();
|
||||||
} else {
|
} else {
|
||||||
setVarId();
|
setVarId();
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
~Tokenizer();
|
~Tokenizer();
|
||||||
|
|
||||||
void setTimerResults(TimerResults *tr) {
|
void setTimerResults(TimerResults *tr) {
|
||||||
m_timerResults = tr;
|
_timerResults = tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Is the code C. Used for bailouts */
|
/** Is the code C. Used for bailouts */
|
||||||
|
@ -845,6 +845,9 @@ private:
|
||||||
/** variable count */
|
/** variable count */
|
||||||
unsigned int _varId;
|
unsigned int _varId;
|
||||||
|
|
||||||
|
/** unnamed count "Unnamed0", "Unnamed1", "Unnamed2", .. */
|
||||||
|
unsigned int _unnamedCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* was there any templates? templates that are "unused" are
|
* was there any templates? templates that are "unused" are
|
||||||
* removed from the token list
|
* removed from the token list
|
||||||
|
@ -854,7 +857,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* TimerResults
|
* TimerResults
|
||||||
*/
|
*/
|
||||||
TimerResults *m_timerResults;
|
TimerResults *_timerResults;
|
||||||
|
|
||||||
#ifdef MAXTIME
|
#ifdef MAXTIME
|
||||||
/** Tokenizer maxtime */
|
/** Tokenizer maxtime */
|
||||||
|
|
Loading…
Reference in New Issue