Replace 'unsigned' with 'nonneg'

This commit is contained in:
Daniel Marjamäki 2019-07-17 10:14:00 +02:00
parent 61ddda6252
commit e9b12b1fe0
2 changed files with 28 additions and 28 deletions

View File

@ -34,7 +34,7 @@
// How many compileExpression recursions are allowed? // How many compileExpression recursions are allowed?
// For practical code this could be endless. But in some special torture test // For practical code this could be endless. But in some special torture test
// there needs to be a limit. // there needs to be a limit.
static const unsigned int AST_MAX_DEPTH = 50U; static const int AST_MAX_DEPTH = 50;
TokenList::TokenList(const Settings* settings) : TokenList::TokenList(const Settings* settings) :
@ -71,12 +71,12 @@ void TokenList::deallocateTokens()
mFiles.clear(); mFiles.clear();
} }
unsigned int TokenList::appendFileIfNew(const std::string &fileName) int TokenList::appendFileIfNew(const std::string &fileName)
{ {
// Has this file been tokenized already? // Has this file been tokenized already?
for (std::size_t i = 0; i < mFiles.size(); ++i) for (int i = 0; i < mFiles.size(); ++i)
if (Path::sameFileName(mFiles[i], fileName)) if (Path::sameFileName(mFiles[i], fileName))
return (unsigned int)i; return i;
// The "mFiles" vector remembers what files have been tokenized.. // The "mFiles" vector remembers what files have been tokenized..
mFiles.push_back(fileName); mFiles.push_back(fileName);
@ -91,7 +91,7 @@ unsigned int TokenList::appendFileIfNew(const std::string &fileName)
mIsCpp = mSettings->enforcedLang == Settings::CPP || (mSettings->enforcedLang == Settings::None && Path::isCPP(getSourceFilePath())); mIsCpp = mSettings->enforcedLang == Settings::CPP || (mSettings->enforcedLang == Settings::None && Path::isCPP(getSourceFilePath()));
} }
} }
return mFiles.size() - 1U; return mFiles.size() - 1;
} }
void TokenList::deleteTokens(Token *tok) void TokenList::deleteTokens(Token *tok)
@ -107,7 +107,7 @@ void TokenList::deleteTokens(Token *tok)
// add a token. // add a token.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void TokenList::addtoken(std::string str, const unsigned int lineno, const unsigned int fileno, bool split) void TokenList::addtoken(std::string str, const nonneg int lineno, const nonneg int fileno, bool split)
{ {
if (str.empty()) if (str.empty())
return; return;
@ -155,7 +155,7 @@ void TokenList::addtoken(std::string str, const unsigned int lineno, const unsig
mTokensFrontBack.back->fileIndex(fileno); mTokensFrontBack.back->fileIndex(fileno);
} }
void TokenList::addtoken(const Token * tok, const unsigned int lineno, const unsigned int fileno) void TokenList::addtoken(const Token * tok, const nonneg int lineno, const nonneg int fileno)
{ {
if (tok == nullptr) if (tok == nullptr)
return; return;
@ -184,13 +184,13 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last,
{ {
std::stack<Token *> links; std::stack<Token *> links;
Token *tok2 = dest; Token *tok2 = dest;
unsigned int linenrs = dest->linenr(); int linenr = dest->linenr();
const unsigned int commonFileIndex = dest->fileIndex(); const int commonFileIndex = dest->fileIndex();
for (const Token *tok = first; tok != last->next(); tok = tok->next()) { for (const Token *tok = first; tok != last->next(); tok = tok->next()) {
tok2->insertToken(tok->str()); tok2->insertToken(tok->str());
tok2 = tok2->next(); tok2 = tok2->next();
tok2->fileIndex(commonFileIndex); tok2->fileIndex(commonFileIndex);
tok2->linenr(linenrs); tok2->linenr(linenr);
tok2->tokType(tok->tokType()); tok2->tokType(tok->tokType());
tok2->flags(tok->flags()); tok2->flags(tok->flags());
tok2->varId(tok->varId()); tok2->varId(tok->varId());
@ -210,7 +210,7 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last,
links.pop(); links.pop();
} }
if (!one_line && tok->next()) if (!one_line && tok->next())
linenrs += tok->next()->linenr() - tok->linenr(); linenr += tok->next()->linenr() - tok->linenr();
} }
return tok2; return tok2;
} }
@ -219,7 +219,7 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last,
// InsertTokens - Copy and insert tokens // InsertTokens - Copy and insert tokens
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void TokenList::insertTokens(Token *dest, const Token *src, unsigned int n) void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
{ {
std::stack<Token *> link; std::stack<Token *> link;
@ -358,12 +358,12 @@ unsigned long long TokenList::calculateChecksum() const
struct AST_state { struct AST_state {
std::stack<Token*> op; std::stack<Token*> op;
unsigned int depth; int depth;
unsigned int inArrayAssignment; int inArrayAssignment;
bool cpp; bool cpp;
unsigned int assign; int assign;
bool inCase; // true from case to : bool inCase; // true from case to :
explicit AST_state(bool cpp) : depth(0), inArrayAssignment(0), cpp(cpp), assign(0U), inCase(false) {} explicit AST_state(bool cpp) : depth(0), inArrayAssignment(0), cpp(cpp), assign(0), inCase(false) {}
}; };
static Token * skipDecl(Token *tok) static Token * skipDecl(Token *tok)
@ -589,8 +589,8 @@ static void compileTerm(Token *&tok, AST_state& state)
if (tok->str() == "<") if (tok->str() == "<")
tok = tok->link()->next(); tok = tok->link()->next();
if (Token::Match(tok, "{ . %name% =")) { if (Token::Match(tok, "{ . %name% =")) {
const bool inArrayAssignment = state.inArrayAssignment; const int inArrayAssignment = state.inArrayAssignment;
state.inArrayAssignment = true; state.inArrayAssignment = 1;
compileBinOp(tok, state, compileExpression); compileBinOp(tok, state, compileExpression);
state.inArrayAssignment = inArrayAssignment; state.inArrayAssignment = inArrayAssignment;
} }
@ -629,7 +629,7 @@ static void compileTerm(Token *&tok, AST_state& state)
if (tok->link() != tok->next()) { if (tok->link() != tok->next()) {
state.inArrayAssignment++; state.inArrayAssignment++;
compileUnaryOp(tok, state, compileExpression); compileUnaryOp(tok, state, compileExpression);
while (Token::Match(tok, "} [,};]") && state.inArrayAssignment > 0U) { while (Token::Match(tok, "} [,};]") && state.inArrayAssignment > 0) {
tok = tok->next(); tok = tok->next();
state.inArrayAssignment--; state.inArrayAssignment--;
} }
@ -965,7 +965,7 @@ static void compileAssignTernary(Token *&tok, AST_state& state)
if (tok->isAssignmentOp()) { if (tok->isAssignmentOp()) {
state.assign++; state.assign++;
compileBinOp(tok, state, compileAssignTernary); compileBinOp(tok, state, compileAssignTernary);
if (state.assign > 0U) if (state.assign > 0)
state.assign--; state.assign--;
} else if (tok->str() == "?") { } else if (tok->str() == "?") {
// http://en.cppreference.com/w/cpp/language/operator_precedence says about ternary operator: // http://en.cppreference.com/w/cpp/language/operator_precedence says about ternary operator:
@ -974,8 +974,8 @@ static void compileAssignTernary(Token *&tok, AST_state& state)
if (tok->strAt(1) == ":") { if (tok->strAt(1) == ":") {
state.op.push(nullptr); state.op.push(nullptr);
} }
const unsigned int assign = state.assign; const int assign = state.assign;
state.assign = 0U; state.assign = 0;
compileBinOp(tok, state, compileAssignTernary); compileBinOp(tok, state, compileAssignTernary);
state.assign = assign; state.assign = assign;
} else if (tok->str() == ":") { } else if (tok->str() == ":") {
@ -984,7 +984,7 @@ static void compileAssignTernary(Token *&tok, AST_state& state)
tok = tok->next(); tok = tok->next();
break; break;
} }
if (state.assign > 0U) if (state.assign > 0)
break; break;
compileBinOp(tok, state, compileAssignTernary); compileBinOp(tok, state, compileAssignTernary);
} else break; } else break;
@ -1456,7 +1456,7 @@ void TokenList::simplifyStdType()
bool isSigned = false; bool isSigned = false;
bool isUnsigned = false; bool isUnsigned = false;
bool isComplex = false; bool isComplex = false;
unsigned int countLong = 0; int countLong = 0;
Token* typeSpec = nullptr; Token* typeSpec = nullptr;
Token* tok2 = tok; Token* tok2 = tok;

View File

@ -69,10 +69,10 @@ public:
*/ */
static void deleteTokens(Token *tok); static void deleteTokens(Token *tok);
void addtoken(std::string str, const unsigned int lineno, const unsigned int fileno, bool split = false); void addtoken(std::string str, const nonneg int lineno, const nonneg int fileno, bool split = false);
void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno); void addtoken(const Token *tok, const nonneg int lineno, const nonneg int fileno);
static void insertTokens(Token *dest, const Token *src, unsigned int n); static void insertTokens(Token *dest, const Token *src, nonneg int n);
/** /**
* Copy tokens. * Copy tokens.
@ -101,7 +101,7 @@ public:
void deallocateTokens(); void deallocateTokens();
/** append file name if seen the first time; return its index in any case */ /** append file name if seen the first time; return its index in any case */
unsigned int appendFileIfNew(const std::string &fileName); int appendFileIfNew(const std::string &fileName);
/** get first token of list */ /** get first token of list */
const Token *front() const { const Token *front() const {