use nullptr in lib/tokenize.cpp

This commit is contained in:
Daniel Marjamäki 2014-02-15 08:04:54 +01:00
parent 91340d4043
commit 384ffb4173
1 changed files with 51 additions and 51 deletions

View File

@ -42,7 +42,7 @@ Tokenizer::Tokenizer() :
_symbolDatabase(0), _symbolDatabase(0),
_varId(0), _varId(0),
_codeWithTemplates(false), //is there any templates? _codeWithTemplates(false), //is there any templates?
m_timerResults(NULL) m_timerResults(nullptr)
#ifdef MAXTIME #ifdef MAXTIME
,maxtime(std::time(0) + MAXTIME) ,maxtime(std::time(0) + MAXTIME)
#endif #endif
@ -56,7 +56,7 @@ Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) :
_symbolDatabase(0), _symbolDatabase(0),
_varId(0), _varId(0),
_codeWithTemplates(false), //is there any templates? _codeWithTemplates(false), //is there any templates?
m_timerResults(NULL) m_timerResults(nullptr)
#ifdef MAXTIME #ifdef MAXTIME
,maxtime(std::time(0) + MAXTIME) ,maxtime(std::time(0) + MAXTIME)
#endif #endif
@ -344,7 +344,7 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
Token * Tokenizer::deleteInvalidTypedef(Token *typeDef) Token * Tokenizer::deleteInvalidTypedef(Token *typeDef)
{ {
Token *tok = NULL; Token *tok = nullptr;
// remove typedef but leave ; // remove typedef but leave ;
while (typeDef->next()) { while (typeDef->next()) {
@ -370,7 +370,7 @@ Token * Tokenizer::deleteInvalidTypedef(Token *typeDef)
} }
struct Space { struct Space {
Space() : classEnd(NULL), isNamespace(false) { } Space() : classEnd(nullptr), isNamespace(false) { }
std::string className; std::string className;
const Token * classEnd; const Token * classEnd;
bool isNamespace; bool isNamespace;
@ -400,13 +400,13 @@ static Token *splitDefinitionFromTypedef(Token *tok)
} }
tok->next()->insertToken(name); tok->next()->insertToken(name);
} else } else
return NULL; return nullptr;
} else if (tok->strAt(3) == ":") { } else if (tok->strAt(3) == ":") {
tok1 = tok->tokAt(4); tok1 = tok->tokAt(4);
while (tok1 && tok1->str() != "{") while (tok1 && tok1->str() != "{")
tok1 = tok1->next(); tok1 = tok1->next();
if (!tok1) if (!tok1)
return NULL; return nullptr;
tok1 = tok1->link(); tok1 = tok1->link();
@ -415,7 +415,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
tok1 = tok->linkAt(3); tok1 = tok->linkAt(3);
if (!tok1) if (!tok1)
return NULL; return nullptr;
name = tok->strAt(2); name = tok->strAt(2);
} }
@ -426,7 +426,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
if (tok1->next() && tok1->next()->str() == ";" && tok1->previous()->str() == "}") { if (tok1->next() && tok1->next()->str() == ";" && tok1->previous()->str() == "}") {
tok->deleteThis(); tok->deleteThis();
tok1->deleteThis(); tok1->deleteThis();
return NULL; return nullptr;
} else { } else {
tok1->insertToken("typedef"); tok1->insertToken("typedef");
tok1 = tok1->next(); tok1 = tok1->next();
@ -484,7 +484,7 @@ static Token *processFunc(Token *tok2, bool inOperator)
tok2 = tok2->tokAt(2); tok2 = tok2->tokAt(2);
if (!tok2) if (!tok2)
return NULL; return nullptr;
if (tok2->str() == "(" && if (tok2->str() == "(" &&
tok2->link()->next()->str() == "(") { tok2->link()->next()->str() == "(") {
@ -1661,7 +1661,7 @@ bool Tokenizer::tokenizeCondition(const std::string &code)
concatenateNegativeNumberAndAnyPositive(); concatenateNegativeNumberAndAnyPositive();
// simplify simple calculations // simplify simple calculations
for (Token *tok = list.front() ? list.front()->next() : NULL; for (Token *tok = list.front() ? list.front()->next() : nullptr;
tok; tok;
tok = tok->next()) { tok = tok->next()) {
if (tok->isNumber()) if (tok->isNumber())
@ -2065,7 +2065,7 @@ static Token *skipTernaryOp(Token *tok)
if (!tok || tok->str() != "?") if (!tok || tok->str() != "?")
return tok; return tok;
unsigned int colonlevel = 1; unsigned int colonlevel = 1;
while (NULL != (tok = tok->next())) { while (nullptr != (tok = tok->next())) {
if (tok->str() == "?") { if (tok->str() == "?") {
++colonlevel; ++colonlevel;
} else if (tok->str() == ":") { } else if (tok->str() == ":") {
@ -2116,7 +2116,7 @@ bool Tokenizer::simplifyLabelsCaseDefault()
tok = tok->link(); tok = tok->link();
if (Token::Match(tok, "[;{}] case")) { if (Token::Match(tok, "[;{}] case")) {
while (NULL != (tok = tok->next())) { while (nullptr != (tok = tok->next())) {
if (tok->str() == "(" || tok->str() == "[") { if (tok->str() == "(" || tok->str() == "[") {
tok = tok->link(); tok = tok->link();
} else if (tok->str() == "?") { } else if (tok->str() == "?") {
@ -3081,7 +3081,7 @@ bool Tokenizer::simplifyTokenList1()
concatenateNegativeNumberAndAnyPositive(); concatenateNegativeNumberAndAnyPositive();
// simplify simple calculations // simplify simple calculations
for (Token *tok = list.front() ? list.front()->next() : NULL; tok; tok = tok->next()) { for (Token *tok = list.front() ? list.front()->next() : nullptr; tok; tok = tok->next()) {
if (tok->isNumber()) if (tok->isNumber())
TemplateSimplifier::simplifyNumericCalculations(tok->previous()); TemplateSimplifier::simplifyNumericCalculations(tok->previous());
} }
@ -3267,7 +3267,7 @@ bool Tokenizer::simplifyTokenList1()
start->insertToken("\"" + asmcode + "\""); start->insertToken("\"" + asmcode + "\"");
start->insertToken("("); start->insertToken("(");
start->str("asm"); start->str("asm");
start->link(NULL); start->link(nullptr);
start->next()->link(start->tokAt(3)); start->next()->link(start->tokAt(3));
start->tokAt(3)->link(start->next()); start->tokAt(3)->link(start->next());
tok = start->tokAt(4); tok = start->tokAt(4);
@ -3759,7 +3759,7 @@ void Tokenizer::removeMacroInVarDecl()
} }
tok2 = tok2->next(); tok2 = tok2->next();
} }
tok2 = tok2 ? tok2->next() : NULL; tok2 = tok2 ? tok2->next() : nullptr;
// check if this is a variable declaration.. // check if this is a variable declaration..
const Token *tok3 = tok2; const Token *tok3 = tok2;
@ -3875,7 +3875,7 @@ void Tokenizer::simplifyEmptyNamespaces()
return; return;
bool goback = false; bool goback = false;
for (Token *tok = list.front(); tok; tok = tok ? tok->next() : NULL) { for (Token *tok = list.front(); tok; tok = tok ? tok->next() : nullptr) {
if (goback) { if (goback) {
tok = tok->previous(); tok = tok->previous();
goback = false; goback = false;
@ -4171,14 +4171,14 @@ Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
if (!tokEnd) { if (!tokEnd) {
// no while return input token // no while return input token
syntaxError(tok); syntaxError(tok);
return NULL; return nullptr;
} }
} }
} }
} else if (tok->str()=="if") { } else if (tok->str()=="if") {
tokEnd=simplifyAddBracesPair(tok,true); tokEnd=simplifyAddBracesPair(tok,true);
if (!tokEnd) if (!tokEnd)
return NULL; return nullptr;
Token * tokEndNext=tokEnd->next(); Token * tokEndNext=tokEnd->next();
if (tokEndNext && tokEndNext->str()=="else") { if (tokEndNext && tokEndNext->str()=="else") {
Token * tokEndNextNext=tokEndNext->next(); Token * tokEndNextNext=tokEndNext->next();
@ -4187,7 +4187,7 @@ Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
tokEnd=simplifyAddBracesToCommand(tokEndNextNext); tokEnd=simplifyAddBracesToCommand(tokEndNextNext);
} else if (Token::simpleMatch(tokEndNext, "else }")) { } else if (Token::simpleMatch(tokEndNext, "else }")) {
syntaxError(tokEndNext); syntaxError(tokEndNext);
return NULL; return nullptr;
} else } else
tokEnd=simplifyAddBracesPair(tokEndNext,false); tokEnd=simplifyAddBracesPair(tokEndNext,false);
} }
@ -4208,11 +4208,11 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
if (tokCondition->str()=="(") if (tokCondition->str()=="(")
tokAfterCondition=tokCondition->link(); tokAfterCondition=tokCondition->link();
else else
tokAfterCondition=NULL; tokAfterCondition=nullptr;
if (!tokAfterCondition) { if (!tokAfterCondition) {
// Bad condition // Bad condition
syntaxError(tok); syntaxError(tok);
return NULL; return nullptr;
} }
tokAfterCondition=tokAfterCondition->next(); tokAfterCondition=tokAfterCondition->next();
} }
@ -4223,7 +4223,7 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
// No tokens left where to add braces around // No tokens left where to add braces around
return tok; return tok;
} }
Token * tokBracesEnd=NULL; Token * tokBracesEnd=nullptr;
if (tokAfterCondition->str()=="{") { if (tokAfterCondition->str()=="{") {
// already surrounded by braces // already surrounded by braces
tokBracesEnd=tokAfterCondition->link(); tokBracesEnd=tokAfterCondition->link();
@ -4855,7 +4855,7 @@ bool Tokenizer::simplifyFunctionParameters()
// First step: Get list of argument names in parentheses // First step: Get list of argument names in parentheses
std::map<std::string, Token *> argumentNames; std::map<std::string, Token *> argumentNames;
bool bailOut = false; bool bailOut = false;
Token * tokparam = NULL; Token * tokparam = nullptr;
//take count of the function name.. //take count of the function name..
const std::string& funcName(tok->str()); const std::string& funcName(tok->str());
@ -4863,7 +4863,7 @@ bool Tokenizer::simplifyFunctionParameters()
//floating token used to check for parameters //floating token used to check for parameters
Token *tok1 = tok; Token *tok1 = tok;
while (NULL != (tok1 = tok1->tokAt(2))) { while (nullptr != (tok1 = tok1->tokAt(2))) {
if (!Token::Match(tok1, "%var% [,)]")) { if (!Token::Match(tok1, "%var% [,)]")) {
bailOut = true; bailOut = true;
break; break;
@ -5137,7 +5137,7 @@ static void incdec(std::string &value, const std::string &op)
void Tokenizer::simplifyVarDecl(bool only_k_r_fpar) void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
{ {
simplifyVarDecl(list.front(), NULL, only_k_r_fpar); simplifyVarDecl(list.front(), nullptr, only_k_r_fpar);
} }
void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_fpar) void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_fpar)
@ -5241,7 +5241,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
//skip combinations of templates and namespaces //skip combinations of templates and namespaces
while (Token::Match(tok2, "%type% <") || Token::Match(tok2, "%type% ::")) { while (Token::Match(tok2, "%type% <") || Token::Match(tok2, "%type% ::")) {
if (tok2->next()->str() == "<" && !TemplateSimplifier::templateParameters(tok2->next())) { if (tok2->next()->str() == "<" && !TemplateSimplifier::templateParameters(tok2->next())) {
tok2 = NULL; tok2 = nullptr;
break; break;
} }
typelen += 2; typelen += 2;
@ -5272,7 +5272,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
++parens; ++parens;
} else if (tok3->str() == ")") { } else if (tok3->str() == ")") {
if (!parens) { if (!parens) {
tok2 = NULL; tok2 = nullptr;
break; break;
} }
--parens; --parens;
@ -5323,10 +5323,10 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
tok2 = tok2->next(); tok2 = tok2->next();
} }
if (tok2 && tok2->str() == ";") if (tok2 && tok2->str() == ";")
tok2 = NULL; tok2 = nullptr;
} }
} else } else
tok2 = NULL; tok2 = nullptr;
} }
//VLA case //VLA case
@ -5336,7 +5336,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
while (Token::Match(tok2->link(), "] ,|=|[")) while (Token::Match(tok2->link(), "] ,|=|["))
tok2 = tok2->link()->next(); tok2 = tok2->link()->next();
if (!Token::Match(tok2, "=|,")) if (!Token::Match(tok2, "=|,"))
tok2 = NULL; tok2 = nullptr;
if (tok2 && tok2->str() == "=") { if (tok2 && tok2->str() == "=") {
while (tok2 && tok2->str() != "," && tok2->str() != ";") { while (tok2 && tok2->str() != "," && tok2->str() != ";") {
if (tok2->str() == "{" || tok2->str() == "(" || tok2->str() == "[") if (tok2->str() == "{" || tok2->str() == "(" || tok2->str() == "[")
@ -5344,12 +5344,12 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
tok2 = tok2->next(); tok2 = tok2->next();
} }
if (tok2 && tok2->str() == ";") if (tok2 && tok2->str() == ";")
tok2 = NULL; tok2 = nullptr;
} }
} else } else
tok2 = NULL; tok2 = nullptr;
} else { } else {
tok2 = NULL; tok2 = nullptr;
} }
if (!tok2) { if (!tok2) {
@ -5938,7 +5938,7 @@ void Tokenizer::simplifyIfNot()
void Tokenizer::simplifyIfNotNull() void Tokenizer::simplifyIfNotNull()
{ {
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {
Token *deleteFrom = NULL; Token *deleteFrom = nullptr;
// Remove 'x = (x != 0)' // Remove 'x = (x != 0)'
if (Token::simpleMatch(tok, "= (")) { if (Token::simpleMatch(tok, "= (")) {
@ -6046,7 +6046,7 @@ bool Tokenizer::simplifyLogicalOperators()
continue; continue;
const Token *tok2 = tok; const Token *tok2 = tok;
while (NULL != (tok2 = tok2->previous())) { while (nullptr != (tok2 = tok2->previous())) {
if (tok2->str() == ")") if (tok2->str() == ")")
tok2 = tok2->link(); tok2 = tok2->link();
else if (Token::Match(tok2, "(|;|{|}")) else if (Token::Match(tok2, "(|;|{|}"))
@ -6315,7 +6315,7 @@ bool Tokenizer::simplifyKnownVariables()
std::string value; std::string value;
unsigned int valueVarId = 0; unsigned int valueVarId = 0;
Token *tok3 = NULL; Token *tok3 = nullptr;
bool valueIsPointer = false; bool valueIsPointer = false;
// there could be a hang here if tok2 is moved back by the function calls below for some reason // there could be a hang here if tok2 is moved back by the function calls below for some reason
@ -6394,7 +6394,7 @@ bool Tokenizer::simplifyKnownVariables()
bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar) bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar)
{ {
Token *tok2 = *_tok2; Token *tok2 = *_tok2;
Token *tok3 = NULL; Token *tok3 = nullptr;
if (Token::simpleMatch(tok2->tokAt(-2), "for (")) { if (Token::simpleMatch(tok2->tokAt(-2), "for (")) {
// only specific for loops is handled // only specific for loops is handled
@ -7259,10 +7259,10 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const
class EnumValue { class EnumValue {
public: public:
EnumValue() : EnumValue() :
name(NULL), name(nullptr),
value(NULL), value(nullptr),
start(NULL), start(nullptr),
end(NULL) { end(nullptr) {
} }
EnumValue(const EnumValue &ev) : EnumValue(const EnumValue &ev) :
name(ev.name), name(ev.name),
@ -7281,7 +7281,7 @@ public:
for (Token *tok = start; tok; tok = tok->next()) { for (Token *tok = start; tok; tok = tok->next()) {
if (enumValues.find(tok->str()) != enumValues.end()) { if (enumValues.find(tok->str()) != enumValues.end()) {
const EnumValue &other = enumValues.find(tok->str())->second; const EnumValue &other = enumValues.find(tok->str())->second;
if (other.value != NULL) if (other.value != nullptr)
tok->str(other.value->str()); tok->str(other.value->str());
else { else {
bool islast = (tok == end); bool islast = (tok == end);
@ -7304,7 +7304,7 @@ public:
if (Token::Match(start, "%num% [,}]")) { if (Token::Match(start, "%num% [,}]")) {
value = start; value = start;
start = end = NULL; start = end = nullptr;
} }
} }
@ -7503,7 +7503,7 @@ void Tokenizer::simplifyEnum()
enumValues[enumName->str()] = ev; enumValues[enumName->str()] = ev;
lastEnumValueStart = ev.start; lastEnumValueStart = ev.start;
lastEnumValueEnd = ev.end; lastEnumValueEnd = ev.end;
if (ev.start == NULL) if (ev.start == nullptr)
lastValue = MathLib::toLongNumber(ev.value->str()); lastValue = MathLib::toLongNumber(ev.value->str());
tok1 = ev.end ? ev.end : ev.value; tok1 = ev.end ? ev.end : ev.value;
} }
@ -7523,7 +7523,7 @@ void Tokenizer::simplifyEnum()
std::stack<std::set<std::string> > shadowId; // duplicate ids in inner scope std::stack<std::set<std::string> > shadowId; // duplicate ids in inner scope
bool simplify = false; bool simplify = false;
bool hasClass = false; bool hasClass = false;
EnumValue *ev = NULL; EnumValue *ev = nullptr;
if (!tok1) if (!tok1)
return; return;
@ -8543,8 +8543,8 @@ void Tokenizer::simplifyComma()
} }
bool inReturn = false; bool inReturn = false;
Token *startFrom = NULL; // "[;{}]" token before "return" Token *startFrom = nullptr; // "[;{}]" token before "return"
Token *endAt = NULL; // first ";" token after "[;{}] return" Token *endAt = nullptr; // first ";" token after "[;{}] return"
// find "; return" pattern before comma // find "; return" pattern before comma
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) { for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {
@ -8833,7 +8833,7 @@ void Tokenizer::simplifyWhile0()
Token *tok2 = tok->previous()->link(); Token *tok2 = tok->previous()->link();
tok2 = tok2->previous(); tok2 = tok2->previous();
if (tok2 && tok2->str() == "do") { if (tok2 && tok2->str() == "do") {
bool flowmatch = Token::findmatch(tok2, "continue|break", tok) != NULL; bool flowmatch = Token::findmatch(tok2, "continue|break", tok) != nullptr;
// delete "do ({)" // delete "do ({)"
tok2->deleteThis(); tok2->deleteThis();
if (!flowmatch) if (!flowmatch)
@ -9203,7 +9203,7 @@ void Tokenizer::simplifyAssignmentBlock()
// goto the "} )" // goto the "} )"
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
Token *tok2 = tok; Token *tok2 = tok;
while (NULL != (tok2 = tok2->next())) { while (nullptr != (tok2 = tok2->next())) {
if (tok2->str() == "(" || tok2->str() == "{") if (tok2->str() == "(" || tok2->str() == "{")
++indentlevel; ++indentlevel;
else if (tok2->str() == ")" || tok2->str() == "}") { else if (tok2->str() == ")" || tok2->str() == "}") {
@ -9851,7 +9851,7 @@ void Tokenizer::createSymbolDatabase()
// Set Token::variable pointer for array member variable // Set Token::variable pointer for array member variable
// Since it doesn't point at a fixed location it doesn't have varid // Since it doesn't point at a fixed location it doesn't have varid
if (tok->variable() != NULL && if (tok->variable() != nullptr &&
tok->variable()->typeScope() && tok->variable()->typeScope() &&
Token::Match(tok, "%var% [|.")) { Token::Match(tok, "%var% [|.")) {
@ -9862,7 +9862,7 @@ void Tokenizer::createSymbolDatabase()
tok2 = tok2->link()->next(); tok2 = tok2->link()->next();
} }
Token *membertok = NULL; Token *membertok = nullptr;
if (Token::Match(tok2, ". %var%")) if (Token::Match(tok2, ". %var%"))
membertok = tok2->next(); membertok = tok2->next();
else if (Token::Match(tok2, ") . %var%") && tok->strAt(-1) == "(") else if (Token::Match(tok2, ") . %var%") && tok->strAt(-1) == "(")