diff --git a/lib/token.cpp b/lib/token.cpp index c21d8ee8c..3e856b7a9 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -381,7 +381,7 @@ const std::string &Token::strAt(int index) const return tok ? tok->mStr : emptyString; } -static int multiComparePercent(const Token *tok, const char*& haystack, unsigned int varid) +static int multiComparePercent(const Token *tok, const char*& haystack, int varid) { ++haystack; // Compare only the first character of the string for optimization reasons @@ -521,7 +521,7 @@ static int multiComparePercent(const Token *tok, const char*& haystack, unsigned return 0xFFFF; } -int Token::multiCompare(const Token *tok, const char *haystack, unsigned int varid) +int Token::multiCompare(const Token *tok, const char *haystack, int varid) { const char *needle = tok->str().c_str(); const char *needlePointer = needle; @@ -626,7 +626,7 @@ const char *Token::chrInFirstWord(const char *str, char c) } } -bool Token::Match(const Token *tok, const char pattern[], unsigned int varid) +bool Token::Match(const Token *tok, const char pattern[], int varid) { const char *p = pattern; while (*p) { @@ -655,7 +655,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid) const char *temp = p+1; bool chrFound = false; - unsigned int count = 0; + int count = 0; while (*temp && *temp != ' ') { if (*temp == ']') { ++count; @@ -713,12 +713,12 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid) return true; } -std::size_t Token::getStrLength(const Token *tok) +int Token::getStrLength(const Token *tok) { assert(tok != nullptr); assert(tok->mTokType == eString); - std::size_t len = 0; + int len = 0; std::string::const_iterator it = tok->str().begin() + 1U; const std::string::const_iterator end = tok->str().end() - 1U; @@ -741,13 +741,13 @@ std::size_t Token::getStrLength(const Token *tok) return len; } -std::size_t Token::getStrSize(const Token *tok) +int Token::getStrSize(const Token *tok) { assert(tok != nullptr); assert(tok->tokType() == eString); const std::string &str = tok->str(); - unsigned int sizeofstring = 1U; - for (unsigned int i = 1U; i < str.size() - 1U; i++) { + int sizeofstring = 1; + for (int i = 1; i < (int)str.size() - 1; i++) { if (str[i] == '\\') ++i; ++sizeofstring; @@ -755,7 +755,7 @@ std::size_t Token::getStrSize(const Token *tok) return sizeofstring; } -std::string Token::getCharAt(const Token *tok, std::size_t index) +std::string Token::getCharAt(const Token *tok, MathLib::bigint index) { assert(tok != nullptr); @@ -937,7 +937,7 @@ const Token *Token::findsimplematch(const Token * const startTok, const char pat return nullptr; } -const Token *Token::findmatch(const Token * const startTok, const char pattern[], const unsigned int varId) +const Token *Token::findmatch(const Token * const startTok, const char pattern[], const int varId) { for (const Token* tok = startTok; tok; tok = tok->next()) { if (Token::Match(tok, pattern, varId)) @@ -946,7 +946,7 @@ const Token *Token::findmatch(const Token * const startTok, const char pattern[] return nullptr; } -const Token *Token::findmatch(const Token * const startTok, const char pattern[], const Token * const end, const unsigned int varId) +const Token *Token::findmatch(const Token * const startTok, const char pattern[], const Token * const end, const int varId) { for (const Token* tok = startTok; tok && tok != end; tok = tok->next()) { if (Token::Match(tok, pattern, varId)) @@ -1333,7 +1333,7 @@ std::string Token::expressionString() const return stringFromTokenRange(tokens.first, tokens.second); } -static void astStringXml(const Token *tok, std::size_t indent, std::ostream &out) +static void astStringXml(const Token *tok, int indent, std::ostream &out) { const std::string strindent(indent, ' '); @@ -1387,15 +1387,15 @@ void Token::printAst(bool verbose, bool xml, std::ostream &out) const } } -static void indent(std::string &str, const unsigned int indent1, const unsigned int indent2) +static void indent(std::string &str, const int indent1, const int indent2) { - for (unsigned int i = 0; i < indent1; ++i) + for (int i = 0; i < indent1; ++i) str += ' '; - for (unsigned int i = indent1; i < indent2; i += 2) + for (int i = indent1; i < indent2; i += 2) str += "| "; } -void Token::astStringVerboseRecursive(std::string& ret, const unsigned int indent1, const unsigned int indent2) const +void Token::astStringVerboseRecursive(std::string& ret, const int indent1, const int indent2) const { if (isExpandedMacro()) ret += '$'; @@ -1405,7 +1405,7 @@ void Token::astStringVerboseRecursive(std::string& ret, const unsigned int inden ret += '\n'; if (mImpl->mAstOperand1) { - unsigned int i1 = indent1, i2 = indent2 + 2; + int i1 = indent1, i2 = indent2 + 2; if (indent1 == indent2 && !mImpl->mAstOperand2) i1 += 2; indent(ret, indent1, indent2); @@ -1413,7 +1413,7 @@ void Token::astStringVerboseRecursive(std::string& ret, const unsigned int inden mImpl->mAstOperand1->astStringVerboseRecursive(ret, i1, i2); } if (mImpl->mAstOperand2) { - unsigned int i1 = indent1, i2 = indent2 + 2; + int i1 = indent1, i2 = indent2 + 2; if (indent1 == indent2) i1 += 2; indent(ret, indent1, indent2); @@ -1432,7 +1432,7 @@ std::string Token::astStringVerbose() const void Token::printValueFlow(bool xml, std::ostream &out) const { - unsigned int line = 0; + int line = 0; if (xml) out << " " << std::endl; else @@ -1582,7 +1582,7 @@ const ValueFlow::Value * Token::getValueGE(const MathLib::bigint val, const Sett return ret; } -const ValueFlow::Value * Token::getInvalidValue(const Token *ftok, unsigned int argnr, const Settings *settings) const +const ValueFlow::Value * Token::getInvalidValue(const Token *ftok, int argnr, const Settings *settings) const { if (!mImpl->mValues || !settings) return nullptr; @@ -1611,11 +1611,11 @@ const Token *Token::getValueTokenMinStrSize() const if (!mImpl->mValues) return nullptr; const Token *ret = nullptr; - std::size_t minsize = ~0U; + int minsize = INT_MAX; std::list::const_iterator it; for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { if (it->isTokValue() && it->tokvalue && it->tokvalue->tokType() == Token::eString) { - const std::size_t size = getStrSize(it->tokvalue); + const int size = getStrSize(it->tokvalue); if (!ret || size < minsize) { minsize = size; ret = it->tokvalue; @@ -1630,11 +1630,11 @@ const Token *Token::getValueTokenMaxStrLength() const if (!mImpl->mValues) return nullptr; const Token *ret = nullptr; - std::size_t maxlength = 0U; + int maxlength = 0; std::list::const_iterator it; for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { if (it->isTokValue() && it->tokvalue && it->tokvalue->tokType() == Token::eString) { - const std::size_t length = getStrLength(it->tokvalue); + const int length = getStrLength(it->tokvalue); if (!ret || length > maxlength) { maxlength = length; ret = it->tokvalue; @@ -1746,17 +1746,17 @@ bool Token::addValue(const ValueFlow::Value &value) void Token::assignProgressValues(Token *tok) { - unsigned int total_count = 0; + int total_count = 0; for (Token *tok2 = tok; tok2; tok2 = tok2->next()) ++total_count; - unsigned int count = 0; + int count = 0; for (Token *tok2 = tok; tok2; tok2 = tok2->next()) tok2->mImpl->mProgressValue = count++ * 100 / total_count; } void Token::assignIndexes() { - unsigned int index = (mPrevious ? mPrevious->mImpl->mIndex : 0) + 1; + int index = (mPrevious ? mPrevious->mImpl->mIndex : 0) + 1; for (Token *tok = this; tok; tok = tok->next()) tok->mImpl->mIndex = index++; } diff --git a/lib/token.h b/lib/token.h index c934c001b..2a0acf374 100644 --- a/lib/token.h +++ b/lib/token.h @@ -51,10 +51,10 @@ struct TokensFrontBack { }; struct TokenImpl { - unsigned int mVarId; - unsigned int mFileIndex; - unsigned int mLineNumber; - unsigned int mColumn; + int mVarId; + int mFileIndex; + int mLineNumber; + int mColumn; // AST.. Token *mAstOperand1; @@ -74,12 +74,12 @@ struct TokenImpl { * A value from 0-100 that provides a rough idea about where in the token * list this token is located. */ - unsigned int mProgressValue; + int mProgressValue; /** * Token index. Position in token list */ - unsigned int mIndex; + int mIndex; // original name like size_t std::string* mOriginalName; @@ -288,7 +288,7 @@ public: * @return true if given token matches with given pattern * false if given token does not match with given pattern */ - static bool Match(const Token *tok, const char pattern[], unsigned int varid = 0); + static bool Match(const Token *tok, const char pattern[], int varid = 0); /** * @return length of C-string. @@ -297,7 +297,7 @@ public: * * @param tok token with C-string **/ - static std::size_t getStrLength(const Token *tok); + static int getStrLength(const Token *tok); /** * @return sizeof of C-string. @@ -306,7 +306,7 @@ public: * * @param tok token with C-string **/ - static std::size_t getStrSize(const Token *tok); + static int getStrSize(const Token *tok); /** * @return char of C-string at index (possible escaped "\\n") @@ -316,7 +316,7 @@ public: * @param tok token with C-string * @param index position of character **/ - static std::string getCharAt(const Token *tok, std::size_t index); + static std::string getCharAt(const Token *tok, MathLib::bigint index); const ValueType *valueType() const { return mImpl->mValueType; @@ -586,18 +586,18 @@ public: static const Token *findsimplematch(const Token * const startTok, const char pattern[]); static const Token *findsimplematch(const Token * const startTok, const char pattern[], const Token * const end); - static const Token *findmatch(const Token * const startTok, const char pattern[], const unsigned int varId = 0U); - static const Token *findmatch(const Token * const startTok, const char pattern[], const Token * const end, const unsigned int varId = 0U); + static const Token *findmatch(const Token * const startTok, const char pattern[], const int varId = 0); + static const Token *findmatch(const Token * const startTok, const char pattern[], const Token * const end, const int varId = 0); static Token *findsimplematch(Token * const startTok, const char pattern[]) { return const_cast(findsimplematch(const_cast(startTok), pattern)); } static Token *findsimplematch(Token * const startTok, const char pattern[], const Token * const end) { return const_cast(findsimplematch(const_cast(startTok), pattern, end)); } - static Token *findmatch(Token * const startTok, const char pattern[], const unsigned int varId = 0U) { + static Token *findmatch(Token * const startTok, const char pattern[], const int varId = 0) { return const_cast(findmatch(const_cast(startTok), pattern, varId)); } - static Token *findmatch(Token * const startTok, const char pattern[], const Token * const end, const unsigned int varId = 0U) { + static Token *findmatch(Token * const startTok, const char pattern[], const Token * const end, const int varId = 0) { return const_cast(findmatch(const_cast(startTok), pattern, end, varId)); } @@ -615,26 +615,26 @@ public: * 0 if needle was empty string * -1 if needle was not found */ - static int multiCompare(const Token *tok, const char *haystack, unsigned int varid); + static int multiCompare(const Token *tok, const char *haystack, int varid); - unsigned int fileIndex() const { + int fileIndex() const { return mImpl->mFileIndex; } - void fileIndex(unsigned int indexOfFile) { + void fileIndex(int indexOfFile) { mImpl->mFileIndex = indexOfFile; } - unsigned int linenr() const { + int linenr() const { return mImpl->mLineNumber; } - void linenr(unsigned int lineNumber) { + void linenr(int lineNumber) { mImpl->mLineNumber = lineNumber; } - unsigned int col() const { + int col() const { return mImpl->mColumn; } - void col(unsigned int c) { + void col(int c) { mImpl->mColumn = c; } @@ -667,10 +667,10 @@ public: } - unsigned int varId() const { + int varId() const { return mImpl->mVarId; } - void varId(unsigned int id) { + void varId(int id) { mImpl->mVarId = id; if (id != 0) { tokType(eVariable); @@ -873,7 +873,7 @@ public: static void move(Token *srcStart, Token *srcEnd, Token *newLocation); /** Get progressValue (0 - 100) */ - unsigned int progressValue() const { + int progressValue() const { return mImpl->mProgressValue; } @@ -981,7 +981,7 @@ public: const ValueFlow::Value * getValueLE(const MathLib::bigint val, const Settings *settings) const; const ValueFlow::Value * getValueGE(const MathLib::bigint val, const Settings *settings) const; - const ValueFlow::Value * getInvalidValue(const Token *ftok, unsigned int argnr, const Settings *settings) const; + const ValueFlow::Value * getInvalidValue(const Token *ftok, int argnr, const Settings *settings) const; const ValueFlow::Value * getContainerSizeValue(const MathLib::bigint val) const { if (!mImpl->mValues) @@ -1006,7 +1006,7 @@ public: mImpl->mValues->remove_if(pred); } - unsigned int index() const { + int index() const { return mImpl->mIndex; } @@ -1107,7 +1107,7 @@ private: void update_property_char_string_literal(); /** Internal helper function to avoid excessive string allocations */ - void astStringVerboseRecursive(std::string& ret, const unsigned int indent1 = 0U, const unsigned int indent2 = 0U) const; + void astStringVerboseRecursive(std::string& ret, const int indent1 = 0, const int indent2 = 0) const; public: void astOperand1(Token *tok);