2008-12-18 22:28:57 +01:00
|
|
|
/*
|
2009-01-21 21:04:20 +01:00
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2011-01-09 20:33:36 +01:00
|
|
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
2008-12-18 22:28:57 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-18 22:28:57 +01:00
|
|
|
*/
|
|
|
|
|
2009-01-03 21:29:20 +01:00
|
|
|
#ifndef TokenH
|
|
|
|
#define TokenH
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
#include <string>
|
2009-11-27 23:04:04 +01:00
|
|
|
#include <vector>
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
2009-07-13 13:35:33 +02:00
|
|
|
/**
|
|
|
|
* @brief The token list that the Tokenizer generates is a linked-list of this class.
|
|
|
|
*
|
|
|
|
* Tokens are stored as strings. The "if", "while", etc are stored in plain text.
|
|
|
|
* The reason the Token class is needed (instead of using the string class) is that some extra functionality is also needed for tokens:
|
|
|
|
* - location of the token is stored (linenr, fileIndex)
|
|
|
|
* - functions for classifying the token (isName, isNumber, isBoolean, isStandardType)
|
|
|
|
*
|
|
|
|
* The Token class also has other functions for management of token list, matching tokens, etc.
|
|
|
|
*/
|
2011-10-13 20:53:06 +02:00
|
|
|
class Token {
|
2010-01-06 20:19:27 +01:00
|
|
|
private:
|
|
|
|
Token **tokensBack;
|
|
|
|
|
|
|
|
// Not implemented..
|
2009-01-03 21:29:20 +01:00
|
|
|
Token();
|
2010-01-06 20:19:27 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Token(Token **tokensBack);
|
2009-01-03 21:29:20 +01:00
|
|
|
~Token();
|
2009-06-14 08:55:23 +02:00
|
|
|
|
|
|
|
void str(const std::string &s);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2011-10-23 21:21:42 +02:00
|
|
|
/**
|
2011-10-23 22:46:55 +02:00
|
|
|
* Concatenate two (quoted) strings. Automatically cuts of the last/first character.
|
|
|
|
* Example: "hello ""world" -> "hello world". Used by the token simplifier.
|
2011-10-23 21:21:42 +02:00
|
|
|
*/
|
2009-03-28 20:33:55 +01:00
|
|
|
void concatStr(std::string const& b);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
const std::string &str() const {
|
2009-01-05 16:49:57 +01:00
|
|
|
return _str;
|
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlink and delete next token.
|
|
|
|
*/
|
|
|
|
void deleteNext();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns token in given index, related to this token.
|
|
|
|
* For example index 1 would return next token, and 2
|
|
|
|
* would return next from that one.
|
|
|
|
*/
|
2009-01-03 21:29:20 +01:00
|
|
|
const Token *tokAt(int index) const;
|
2009-01-20 07:20:55 +01:00
|
|
|
Token *tokAt(int index);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2010-02-14 19:58:17 +01:00
|
|
|
std::string strAt(int index) const;
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2008-12-23 22:51:54 +01:00
|
|
|
/**
|
|
|
|
* Match given token (or list of tokens) to a pattern list.
|
|
|
|
*
|
|
|
|
* Possible patterns
|
|
|
|
* "someRandomText" If token contains "someRandomText".
|
|
|
|
* @note Use Match() if you want to use flags in patterns
|
|
|
|
*
|
|
|
|
* The patterns can be also combined to compare to multiple tokens at once
|
|
|
|
* by separating tokens with a space, e.g.
|
|
|
|
* ") void {" will return true if first token is ')' next token
|
|
|
|
* is "void" and token after that is '{'. If even one of the tokens does
|
|
|
|
* not match its pattern, false is returned.
|
|
|
|
*
|
|
|
|
* @param tok List of tokens to be compared to the pattern
|
|
|
|
* @param pattern The pattern against which the tokens are compared,
|
|
|
|
* e.g. "const" or ") void {".
|
|
|
|
* @return true if given token matches with given pattern
|
|
|
|
* false if given token does not match with given pattern
|
|
|
|
*/
|
2009-01-03 21:29:20 +01:00
|
|
|
static bool simpleMatch(const Token *tok, const char pattern[]);
|
2008-12-22 00:28:09 +01:00
|
|
|
|
2008-12-18 22:28:57 +01:00
|
|
|
/**
|
|
|
|
* Match given token (or list of tokens) to a pattern list.
|
|
|
|
*
|
|
|
|
* Possible patterns
|
2010-03-13 22:16:06 +01:00
|
|
|
* - "%any%" any token
|
|
|
|
* - "%var%" any token which is a name or type e.g. "hello" or "int"
|
|
|
|
* - "%type%" Anything that can be a variable type, e.g. "int", but not "delete".
|
|
|
|
* - "%num%" Any numeric token, e.g. "23"
|
|
|
|
* - "%bool%" true or false
|
|
|
|
* - "%str%" Any token starting with "-character (C-string).
|
|
|
|
* - "%varid%" Match with parameter varid
|
2010-10-25 03:14:21 +02:00
|
|
|
* - "%or%" A bitwise-or operator '|'
|
|
|
|
* - "%oror%" A logical-or operator '||'
|
2010-03-13 22:16:06 +01:00
|
|
|
* - "[abc]" Any of the characters 'a' or 'b' or 'c'
|
|
|
|
* - "int|void|char" Any of the strings, int, void or char
|
|
|
|
* - "int|void|char|" Any of the strings, int, void or char or empty string
|
|
|
|
* - "!!else" No tokens or any token that is not "else".
|
|
|
|
* - "someRandomText" If token contains "someRandomText".
|
2008-12-18 22:28:57 +01:00
|
|
|
*
|
|
|
|
* The patterns can be also combined to compare to multiple tokens at once
|
|
|
|
* by separating tokens with a space, e.g.
|
|
|
|
* ") const|void {" will return true if first token is ')' next token is either
|
|
|
|
* "const" or "void" and token after that is '{'. If even one of the tokens does not
|
|
|
|
* match its pattern, false is returned.
|
|
|
|
*
|
2010-03-14 19:11:03 +01:00
|
|
|
* @todo pattern "%type%|%num%" should mean either a type or a num.
|
|
|
|
*
|
2008-12-18 22:28:57 +01:00
|
|
|
* @param tok List of tokens to be compared to the pattern
|
2008-12-23 22:51:54 +01:00
|
|
|
* @param pattern The pattern against which the tokens are compared,
|
|
|
|
* e.g. "const" or ") const|volatile| {".
|
2010-03-13 22:16:06 +01:00
|
|
|
* @param varid if %varid% is given in the pattern the Token::varId will be matched against this argument
|
2008-12-18 22:28:57 +01:00
|
|
|
* @return true if given token matches with given pattern
|
|
|
|
* false if given token does not match with given pattern
|
|
|
|
*/
|
2009-01-06 00:06:51 +01:00
|
|
|
static bool Match(const Token *tok, const char pattern[], unsigned int varid = 0);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2009-08-30 13:07:10 +02:00
|
|
|
/**
|
|
|
|
* Return length of C-string.
|
|
|
|
*
|
|
|
|
* Should be called for %str% tokens only.
|
|
|
|
*
|
|
|
|
* @param tok token with C-string
|
|
|
|
**/
|
|
|
|
static size_t getStrLength(const Token *tok);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isName() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _isName;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isName(bool name) {
|
2011-03-08 02:04:25 +01:00
|
|
|
_isName = name;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isNumber() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _isNumber;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isNumber(bool number) {
|
2011-03-08 02:04:25 +01:00
|
|
|
_isNumber = number;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isArithmeticalOp() const {
|
2011-04-09 15:54:36 +02:00
|
|
|
return (this && (_str=="<<" || _str==">>" || (_str.size()==1 && _str.find_first_of("+-*/%") != std::string::npos)));
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isOp() const {
|
2011-04-08 19:40:22 +02:00
|
|
|
if (!this)
|
|
|
|
return false;
|
|
|
|
|
2011-04-09 15:54:36 +02:00
|
|
|
return (isArithmeticalOp() ||
|
|
|
|
_str == "&&" ||
|
2011-04-08 19:40:22 +02:00
|
|
|
_str == "||" ||
|
|
|
|
_str == "==" ||
|
|
|
|
_str == "!=" ||
|
|
|
|
_str == "<" ||
|
|
|
|
_str == "<=" ||
|
|
|
|
_str == ">" ||
|
|
|
|
_str == ">=" ||
|
2011-04-09 15:54:36 +02:00
|
|
|
(_str.size() == 1 && _str.find_first_of("&|^~!") != std::string::npos));
|
2011-04-08 19:40:22 +02:00
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isExtendedOp() const {
|
2011-04-09 16:22:47 +02:00
|
|
|
return isOp() ||
|
2011-04-09 15:54:36 +02:00
|
|
|
(this && _str.size() == 1 && _str.find_first_of(",[]()?:") != std::string::npos);
|
2011-04-08 19:40:22 +02:00
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isAssignmentOp() const {
|
2011-04-09 20:36:05 +02:00
|
|
|
if (!this)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (_str == "=" ||
|
|
|
|
_str == "+=" ||
|
|
|
|
_str == "-=" ||
|
|
|
|
_str == "*=" ||
|
|
|
|
_str == "/=" ||
|
|
|
|
_str == "%=" ||
|
|
|
|
_str == "&=" ||
|
|
|
|
_str == "^=" ||
|
|
|
|
_str == "|=" ||
|
|
|
|
_str == "<<=" ||
|
|
|
|
_str == ">>=");
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isBoolean() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _isBoolean;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isBoolean(bool boolean) {
|
2011-03-08 02:04:25 +01:00
|
|
|
_isBoolean = boolean;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isUnsigned() const {
|
2010-03-28 15:56:13 +02:00
|
|
|
return _isUnsigned;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isUnsigned(bool sign) {
|
2010-03-28 15:56:13 +02:00
|
|
|
_isUnsigned = sign;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isSigned() const {
|
2010-03-28 15:56:13 +02:00
|
|
|
return _isSigned;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isSigned(bool sign) {
|
2010-03-28 15:56:13 +02:00
|
|
|
_isSigned = sign;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isPointerCompare() const {
|
2011-07-07 15:14:33 +02:00
|
|
|
return _isPointerCompare;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isPointerCompare(bool b) {
|
2011-07-07 15:14:33 +02:00
|
|
|
_isPointerCompare = b;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isLong() const {
|
2010-03-28 15:56:13 +02:00
|
|
|
return _isLong;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isLong(bool size) {
|
2010-03-28 15:56:13 +02:00
|
|
|
_isLong = size;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
bool isUnused() const {
|
2010-06-14 15:46:57 +02:00
|
|
|
return _isUnused;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void isUnused(bool used) {
|
2010-06-14 15:46:57 +02:00
|
|
|
_isUnused = used;
|
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
bool isStandardType() const;
|
2009-06-10 23:12:26 +02:00
|
|
|
|
2011-10-27 10:54:50 +02:00
|
|
|
static const Token *findsimplematch(const Token *tok, const char pattern[]);
|
|
|
|
static const Token *findsimplematch(const Token *tok, const char pattern[], const Token *end);
|
2009-01-06 00:06:51 +01:00
|
|
|
static const Token *findmatch(const Token *tok, const char pattern[], unsigned int varId = 0);
|
2010-07-26 16:46:37 +02:00
|
|
|
static const Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Needle is build from multiple alternatives. If one of
|
|
|
|
* them is equal to haystack, return value is 1. If there
|
|
|
|
* are no matches, but one alternative to needle is empty
|
|
|
|
* string, return value is 0. If needle was not found, return
|
|
|
|
* value is -1.
|
|
|
|
*
|
2009-01-27 20:30:01 +01:00
|
|
|
* @param haystack e.g. "one|two" or "|one|two"
|
|
|
|
* @param needle e.g. "one", "two" or "invalid"
|
2008-12-18 22:28:57 +01:00
|
|
|
* @return 1 if needle is found from the haystack
|
|
|
|
* 0 if needle was empty string
|
|
|
|
* -1 if needle was not found
|
|
|
|
*/
|
2009-01-27 20:30:01 +01:00
|
|
|
static int multiCompare(const char *haystack, const char *needle);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
unsigned int linenr() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _linenr;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void linenr(unsigned int lineNumber) {
|
2010-04-06 21:53:05 +02:00
|
|
|
_linenr = lineNumber;
|
2009-08-23 17:17:57 +02:00
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
unsigned int fileIndex() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _fileIndex;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void fileIndex(unsigned int indexOfFile) {
|
2010-04-06 21:53:05 +02:00
|
|
|
_fileIndex = indexOfFile;
|
2009-08-23 17:17:57 +02:00
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
Token *next() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _next;
|
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete tokens between begin and end. E.g. if begin = 1
|
|
|
|
* and end = 5, tokens 2,3 and 4 would be erased.
|
|
|
|
*
|
|
|
|
* @param begin Tokens after this will be erased.
|
|
|
|
* @param end Tokens before this will be erased.
|
|
|
|
*/
|
2009-01-05 16:49:57 +01:00
|
|
|
static void eraseTokens(Token *begin, const Token *end);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert new token after this token. This function will handle
|
|
|
|
* relations between next and previous token also.
|
2010-04-09 21:40:37 +02:00
|
|
|
* @param tokenStr String for the new token.
|
2008-12-18 22:28:57 +01:00
|
|
|
*/
|
2010-04-09 21:40:37 +02:00
|
|
|
void insertToken(const std::string &tokenStr);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
Token *previous() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _previous;
|
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
unsigned int varId() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _varId;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void varId(unsigned int id) {
|
2009-08-23 17:17:57 +02:00
|
|
|
_varId = id;
|
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For debugging purposes, prints token and all tokens
|
|
|
|
* followed by it.
|
|
|
|
* @param title Title for the printout or use default parameter or 0
|
|
|
|
* for no title.
|
|
|
|
*/
|
2009-01-05 16:49:57 +01:00
|
|
|
void printOut(const char *title = 0) const;
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2009-11-27 23:04:04 +01:00
|
|
|
/**
|
|
|
|
* For debugging purposes, prints token and all tokens
|
|
|
|
* followed by it.
|
|
|
|
* @param title Title for the printout or use default parameter or 0
|
|
|
|
* for no title.
|
|
|
|
* @param fileNames Prints out file name instead of file index.
|
|
|
|
* File index should match the index of the string in this vector.
|
|
|
|
*/
|
|
|
|
void printOut(const char *title, const std::vector<std::string> &fileNames) const;
|
|
|
|
|
2009-01-26 23:26:50 +01:00
|
|
|
/**
|
|
|
|
* Replace token replaceThis with tokens between start and end,
|
|
|
|
* including start and end. The replaceThis token is deleted.
|
2009-06-20 11:54:49 +02:00
|
|
|
* @param replaceThis This token will be deleted.
|
2009-01-26 23:26:50 +01:00
|
|
|
* @param start This will be in the place of replaceThis
|
|
|
|
* @param end This is also in the place of replaceThis
|
|
|
|
*/
|
|
|
|
static void replace(Token *replaceThis, Token *start, Token *end);
|
|
|
|
|
2009-02-13 07:25:29 +01:00
|
|
|
/** Stringify a token list (with or without varId) */
|
2010-07-25 18:17:44 +02:00
|
|
|
std::string stringifyList(bool varid = false, const char *title = 0) const;
|
2009-11-27 23:04:04 +01:00
|
|
|
std::string stringifyList(bool varid, const char *title, const std::vector<std::string> &fileNames) const;
|
2009-02-13 07:25:29 +01:00
|
|
|
|
2009-03-13 00:07:05 +01:00
|
|
|
/**
|
2011-10-16 08:25:11 +02:00
|
|
|
* Remove the contents for this token from the token list.
|
|
|
|
*
|
|
|
|
* The contents are replaced with the contents of the next token and
|
|
|
|
* the next token is unlinked and deleted from the token list.
|
|
|
|
*
|
|
|
|
* So this token will still be valid after the 'deleteThis()'.
|
2009-03-13 00:07:05 +01:00
|
|
|
*/
|
|
|
|
void deleteThis();
|
|
|
|
|
2009-03-13 22:25:56 +01:00
|
|
|
/**
|
|
|
|
* Create link to given token
|
2010-06-14 07:54:41 +02:00
|
|
|
* @param linkToToken The token where this token should link
|
2009-03-13 22:25:56 +01:00
|
|
|
* to.
|
|
|
|
*/
|
2011-10-13 20:53:06 +02:00
|
|
|
void link(Token *linkToToken) {
|
2010-04-06 21:53:05 +02:00
|
|
|
_link = linkToToken;
|
2009-08-23 17:17:57 +02:00
|
|
|
}
|
2009-03-13 22:25:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return token where this token links to.
|
|
|
|
* Supported links are:
|
|
|
|
* "{" <-> "}"
|
2011-10-16 08:25:11 +02:00
|
|
|
* "(" <-> ")"
|
|
|
|
* "[" <-> "]"
|
2009-03-13 22:25:56 +01:00
|
|
|
*
|
|
|
|
* @return The token where this token links to.
|
|
|
|
*/
|
2011-10-13 20:53:06 +02:00
|
|
|
Token *link() const {
|
2009-08-23 17:17:57 +02:00
|
|
|
return _link;
|
|
|
|
}
|
2009-03-13 22:25:56 +01:00
|
|
|
|
2009-08-22 16:22:50 +02:00
|
|
|
/**
|
|
|
|
* Links two elements against each other.
|
|
|
|
**/
|
|
|
|
static void createMutualLinks(Token *begin, Token *end);
|
|
|
|
|
2009-09-12 22:54:47 +02:00
|
|
|
/**
|
|
|
|
* This can be called only for tokens that are strings, else
|
|
|
|
* the assert() is called. If Token is e.g. '"hello"', this will return
|
|
|
|
* 'hello' (removing the double quotes).
|
|
|
|
* @return String value
|
|
|
|
*/
|
2009-09-13 10:02:23 +02:00
|
|
|
std::string strValue() const;
|
2009-09-12 22:54:47 +02:00
|
|
|
|
2009-11-27 22:21:13 +01:00
|
|
|
/**
|
|
|
|
* Move srcStart and srcEnd tokens and all tokens between then
|
|
|
|
* into new a location. Only links between tokens are changed.
|
|
|
|
* @param srcStart This is the first token to be moved
|
|
|
|
* @param srcEnd The last token to be moved
|
|
|
|
* @param newLocation srcStart will be placed after this token.
|
|
|
|
*/
|
|
|
|
static void move(Token *srcStart, Token *srcEnd, Token *newLocation);
|
|
|
|
|
2010-08-03 16:36:21 +02:00
|
|
|
/** Get progressValue */
|
2011-10-13 20:53:06 +02:00
|
|
|
unsigned int progressValue() const {
|
2010-08-03 16:36:21 +02:00
|
|
|
return _progressValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Calculate progress values for all tokens */
|
2011-10-13 20:53:06 +02:00
|
|
|
void assignProgressValues() {
|
2010-08-03 16:36:21 +02:00
|
|
|
unsigned int total_count = 0;
|
|
|
|
for (Token *tok = this; tok; tok = tok->next())
|
|
|
|
++total_count;
|
|
|
|
unsigned int count = 0;
|
|
|
|
for (Token *tok = this; tok; tok = tok->next())
|
|
|
|
tok->_progressValue = count++ * 100 / total_count;
|
|
|
|
}
|
|
|
|
|
2011-10-23 11:23:48 +02:00
|
|
|
/**
|
|
|
|
* Returns the first token of the next argument. Does only work on argument
|
|
|
|
* lists. Returns 0, if there is no next argument
|
|
|
|
*/
|
|
|
|
const Token* nextArgument() const;
|
|
|
|
|
2008-12-18 22:28:57 +01:00
|
|
|
private:
|
2011-10-13 20:53:06 +02:00
|
|
|
void next(Token *nextToken) {
|
2010-04-06 21:53:05 +02:00
|
|
|
_next = nextToken;
|
2009-08-23 17:17:57 +02:00
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
void previous(Token *previousToken) {
|
2010-04-06 21:53:05 +02:00
|
|
|
_previous = previousToken;
|
2009-08-23 17:17:57 +02:00
|
|
|
}
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2009-08-16 22:28:17 +02:00
|
|
|
/**
|
|
|
|
* Works almost like strcmp() except returns only 0 or 1 and
|
2010-03-13 22:16:06 +01:00
|
|
|
* if str has empty space ' ' character, that character is handled
|
|
|
|
* as if it were '\\0'
|
2009-08-16 22:28:17 +02:00
|
|
|
*/
|
|
|
|
static int firstWordEquals(const char *str, const char *word);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Works almost like strchr() except
|
2010-03-13 22:16:06 +01:00
|
|
|
* if str has empty space ' ' character, that character is handled
|
|
|
|
* as if it were '\\0'
|
2009-08-16 22:28:17 +02:00
|
|
|
*/
|
|
|
|
static const char *chrInFirstWord(const char *str, char c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Works almost like strlen() except
|
2010-03-13 22:16:06 +01:00
|
|
|
* if str has empty space ' ' character, that character is handled
|
|
|
|
* as if it were '\\0'
|
2009-08-16 22:28:17 +02:00
|
|
|
*/
|
|
|
|
static int firstWordLen(const char *str);
|
|
|
|
|
|
|
|
|
2011-10-24 02:52:55 +02:00
|
|
|
Token *_next;
|
|
|
|
Token *_previous;
|
|
|
|
Token *_link;
|
|
|
|
|
2008-12-18 22:28:57 +01:00
|
|
|
bool _isName;
|
|
|
|
bool _isNumber;
|
2008-12-21 14:58:56 +01:00
|
|
|
bool _isBoolean;
|
2010-03-28 15:56:13 +02:00
|
|
|
bool _isUnsigned;
|
|
|
|
bool _isSigned;
|
2011-07-07 15:14:33 +02:00
|
|
|
bool _isPointerCompare;
|
2010-03-28 15:56:13 +02:00
|
|
|
bool _isLong;
|
2010-06-14 15:46:57 +02:00
|
|
|
bool _isUnused;
|
2008-12-18 22:28:57 +01:00
|
|
|
unsigned int _varId;
|
|
|
|
unsigned int _fileIndex;
|
|
|
|
unsigned int _linenr;
|
2010-08-05 21:40:04 +02:00
|
|
|
|
2011-10-23 20:38:03 +02:00
|
|
|
/** Updates internal property cache like _isName or _isBoolean.
|
|
|
|
Called after any _str() modification. */
|
|
|
|
void update_property_info();
|
|
|
|
|
2010-08-05 21:40:04 +02:00
|
|
|
/**
|
|
|
|
* A value from 0-100 that provides a rough idea about where in the token
|
|
|
|
* list this token is located.
|
|
|
|
*/
|
|
|
|
unsigned int _progressValue;
|
2011-10-24 02:52:55 +02:00
|
|
|
|
|
|
|
std::string _str;
|
2008-12-18 22:28:57 +01:00
|
|
|
};
|
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @}
|
|
|
|
|
2009-01-03 21:29:20 +01:00
|
|
|
#endif // TokenH
|