Fixed #5764 (Store Token flags in a single variable)
This commit is contained in:
parent
6e25280c90
commit
2d2847ddbd
|
@ -45,19 +45,7 @@ Token::Token(Token **t) :
|
|||
_linenr(0),
|
||||
_progressValue(0),
|
||||
_type(eNone),
|
||||
_isUnsigned(false),
|
||||
_isSigned(false),
|
||||
_isPointerCompare(false),
|
||||
_isLong(false),
|
||||
_isStandardType(false),
|
||||
_isExpandedMacro(false),
|
||||
_isAttributeConstructor(false),
|
||||
_isAttributeDestructor(false),
|
||||
_isAttributeUnused(false),
|
||||
_isAttributePure(false),
|
||||
_isAttributeConst(false),
|
||||
_isAttributeNothrow(false),
|
||||
_isDeclspecNothrow(false),
|
||||
_flags(0),
|
||||
_astOperand1(nullptr),
|
||||
_astOperand2(nullptr),
|
||||
_astParent(nullptr)
|
||||
|
@ -121,14 +109,14 @@ void Token::update_property_info()
|
|||
|
||||
void Token::update_property_isStandardType()
|
||||
{
|
||||
_isStandardType = false;
|
||||
isStandardType(false);
|
||||
|
||||
if (_str.size() < 3)
|
||||
return;
|
||||
|
||||
static const char * const stdtype[] = { "bool", "char", "char16_t", "char32_t", "double", "float", "int", "long", "short", "size_t", "void", "wchar_t"};
|
||||
if (std::binary_search(stdtype, stdtype + sizeof(stdtype) / sizeof(stdtype[0]), _str)) {
|
||||
_isStandardType = true;
|
||||
isStandardType(true);
|
||||
_type = eType;
|
||||
}
|
||||
}
|
||||
|
@ -178,19 +166,7 @@ void Token::deleteThis()
|
|||
if (_next) { // Copy next to this and delete next
|
||||
_str = _next->_str;
|
||||
_type = _next->_type;
|
||||
_isUnsigned = _next->_isUnsigned;
|
||||
_isSigned = _next->_isSigned;
|
||||
_isPointerCompare = _next->_isPointerCompare;
|
||||
_isLong = _next->_isLong;
|
||||
_isStandardType = _next->_isStandardType;
|
||||
_isExpandedMacro = _next->_isExpandedMacro;
|
||||
_isAttributeConstructor = _next->_isAttributeConstructor;
|
||||
_isAttributeDestructor = _next->_isAttributeDestructor;
|
||||
_isAttributeUnused = _next->_isAttributeUnused;
|
||||
_isAttributePure = _next->_isAttributePure;
|
||||
_isAttributeConst = _next->_isAttributeConst;
|
||||
_isAttributeNothrow = _next->_isAttributeNothrow;
|
||||
_isDeclspecNothrow = _next->_isDeclspecNothrow;
|
||||
_flags = _next->_flags;
|
||||
_varId = _next->_varId;
|
||||
_fileIndex = _next->_fileIndex;
|
||||
_linenr = _next->_linenr;
|
||||
|
@ -207,19 +183,7 @@ void Token::deleteThis()
|
|||
} else if (_previous && _previous->_previous) { // Copy previous to this and delete previous
|
||||
_str = _previous->_str;
|
||||
_type = _previous->_type;
|
||||
_isUnsigned = _previous->_isUnsigned;
|
||||
_isSigned = _previous->_isSigned;
|
||||
_isPointerCompare = _previous->_isPointerCompare;
|
||||
_isLong = _previous->_isLong;
|
||||
_isStandardType = _previous->_isStandardType;
|
||||
_isExpandedMacro = _previous->_isExpandedMacro;
|
||||
_isAttributeConstructor = _previous->_isAttributeConstructor;
|
||||
_isAttributeDestructor = _previous->_isAttributeDestructor;
|
||||
_isAttributeUnused = _previous->_isAttributeUnused;
|
||||
_isAttributePure = _previous->_isAttributePure;
|
||||
_isAttributeConst = _previous->_isAttributeConst;
|
||||
_isAttributeNothrow = _previous->_isAttributeNothrow;
|
||||
_isDeclspecNothrow = _previous->_isDeclspecNothrow;
|
||||
_flags = _previous->_flags;
|
||||
_varId = _previous->_varId;
|
||||
_fileIndex = _previous->_fileIndex;
|
||||
_linenr = _previous->_linenr;
|
||||
|
|
108
lib/token.h
108
lib/token.h
|
@ -253,80 +253,89 @@ public:
|
|||
return _type == eBoolean;
|
||||
}
|
||||
|
||||
unsigned int flags() const {
|
||||
return _flags;
|
||||
}
|
||||
void flags(unsigned int flags_) {
|
||||
_flags = flags_;
|
||||
}
|
||||
bool isUnsigned() const {
|
||||
return _isUnsigned;
|
||||
return getFlag(fIsUnsigned);
|
||||
}
|
||||
void isUnsigned(bool sign) {
|
||||
_isUnsigned = sign;
|
||||
setFlag(fIsUnsigned, sign);
|
||||
}
|
||||
bool isSigned() const {
|
||||
return _isSigned;
|
||||
return getFlag(fIsSigned);
|
||||
}
|
||||
void isSigned(bool sign) {
|
||||
_isSigned = sign;
|
||||
setFlag(fIsSigned, sign);
|
||||
}
|
||||
bool isPointerCompare() const {
|
||||
return _isPointerCompare;
|
||||
return getFlag(fIsPointerCompare);
|
||||
}
|
||||
void isPointerCompare(bool b) {
|
||||
_isPointerCompare = b;
|
||||
setFlag(fIsPointerCompare, b);
|
||||
}
|
||||
bool isLong() const {
|
||||
return _isLong;
|
||||
return getFlag(fIsLong);
|
||||
}
|
||||
void isLong(bool size) {
|
||||
_isLong = size;
|
||||
setFlag(fIsLong, size);
|
||||
}
|
||||
bool isStandardType() const {
|
||||
return _isStandardType;
|
||||
return getFlag(fIsStandardType);
|
||||
}
|
||||
void isStandardType(bool b) {
|
||||
setFlag(fIsStandardType, b);
|
||||
}
|
||||
bool isExpandedMacro() const {
|
||||
return _isExpandedMacro;
|
||||
return getFlag(fIsExpandedMacro);
|
||||
}
|
||||
void isExpandedMacro(bool m) {
|
||||
_isExpandedMacro = m;
|
||||
setFlag(fIsExpandedMacro, m);
|
||||
}
|
||||
bool isAttributeConstructor() const {
|
||||
return _isAttributeConstructor;
|
||||
return getFlag(fIsAttributeConstructor);
|
||||
}
|
||||
void isAttributeConstructor(bool ac) {
|
||||
_isAttributeConstructor = ac;
|
||||
setFlag(fIsAttributeConstructor, ac);
|
||||
}
|
||||
bool isAttributeDestructor() const {
|
||||
return _isAttributeDestructor;
|
||||
return getFlag(fIsAttributeDestructor);
|
||||
}
|
||||
void isAttributeDestructor(bool value) {
|
||||
_isAttributeDestructor = value;
|
||||
setFlag(fIsAttributeDestructor, value);
|
||||
}
|
||||
bool isAttributeUnused() const {
|
||||
return _isAttributeUnused;
|
||||
return getFlag(fIsAttributeUnused);
|
||||
}
|
||||
void isAttributeUnused(bool unused) {
|
||||
_isAttributeUnused = unused;
|
||||
setFlag(fIsAttributeUnused, unused);
|
||||
}
|
||||
bool isAttributePure() const {
|
||||
return _isAttributePure;
|
||||
return getFlag(fIsAttributePure);
|
||||
}
|
||||
void isAttributePure(bool value) {
|
||||
_isAttributePure = value;
|
||||
setFlag(fIsAttributePure, value);
|
||||
}
|
||||
bool isAttributeConst() const {
|
||||
return _isAttributeConst;
|
||||
return getFlag(fIsAttributeConst);
|
||||
}
|
||||
void isAttributeConst(bool value) {
|
||||
_isAttributeConst = value;
|
||||
setFlag(fIsAttributeConst, value);
|
||||
}
|
||||
bool isAttributeNothrow() const {
|
||||
return _isAttributeNothrow;
|
||||
return getFlag(fIsAttributeNothrow);
|
||||
}
|
||||
void isAttributeNothrow(bool value) {
|
||||
_isAttributeNothrow = value;
|
||||
setFlag(fIsAttributeNothrow, value);
|
||||
}
|
||||
bool isDeclspecNothrow() const {
|
||||
return _isDeclspecNothrow;
|
||||
return getFlag(fIsDeclspecNothrow);
|
||||
}
|
||||
void isDeclspecNothrow(bool value) {
|
||||
_isDeclspecNothrow = value;
|
||||
setFlag(fIsDeclspecNothrow, value);
|
||||
}
|
||||
|
||||
static const Token *findsimplematch(const Token *tok, const char pattern[]);
|
||||
|
@ -700,19 +709,42 @@ private:
|
|||
unsigned int _progressValue;
|
||||
|
||||
Type _type;
|
||||
bool _isUnsigned;
|
||||
bool _isSigned;
|
||||
bool _isPointerCompare;
|
||||
bool _isLong;
|
||||
bool _isStandardType;
|
||||
bool _isExpandedMacro;
|
||||
bool _isAttributeConstructor; // __attribute__((constructor)) __attribute__((constructor(priority)))
|
||||
bool _isAttributeDestructor; // __attribute__((destructor)) __attribute__((destructor(priority)))
|
||||
bool _isAttributeUnused; // __attribute__((unused))
|
||||
bool _isAttributePure; // __attribute__((pure))
|
||||
bool _isAttributeConst; // __attribute__((const))
|
||||
bool _isAttributeNothrow; // __attribute__((nothrow))
|
||||
bool _isDeclspecNothrow; // __declspec(nothrow)
|
||||
|
||||
enum {
|
||||
fIsUnsigned = (1 << 0),
|
||||
fIsSigned = (1 << 1),
|
||||
fIsPointerCompare = (1 << 2),
|
||||
fIsLong = (1 << 3),
|
||||
fIsStandardType = (1 << 4),
|
||||
fIsExpandedMacro = (1 << 5),
|
||||
fIsAttributeConstructor = (1 << 6), // __attribute__((constructor)) __attribute__((constructor(priority)))
|
||||
fIsAttributeDestructor = (1 << 7), // __attribute__((destructor)) __attribute__((destructor(priority)))
|
||||
fIsAttributeUnused = (1 << 8), // __attribute__((unused))
|
||||
fIsAttributePure = (1 << 9), // __attribute__((pure))
|
||||
fIsAttributeConst = (1 << 10), // __attribute__((const))
|
||||
fIsAttributeNothrow = (1 << 11), // __attribute__((nothrow))
|
||||
fIsDeclspecNothrow = (1 << 12) // __declspec(nothrow)
|
||||
};
|
||||
|
||||
unsigned int _flags;
|
||||
|
||||
/**
|
||||
* Get specified flag state.
|
||||
* @param flag_ flag to get state of
|
||||
* @return true if flag set or false in flag not set
|
||||
*/
|
||||
bool getFlag(int flag_) const {
|
||||
return bool((_flags & flag_) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set specified flag state.
|
||||
* @param flag_ flag to set state
|
||||
* @param state_ new state of flag
|
||||
*/
|
||||
void setFlag(int flag_, bool state_) {
|
||||
_flags = state_ ? _flags | flag_ : _flags & ~flag_;
|
||||
}
|
||||
|
||||
/** Updates internal property cache like _isName or _isBoolean.
|
||||
Called after any _str() modification. */
|
||||
|
|
|
@ -145,16 +145,7 @@ void TokenList::addtoken(const Token * tok, const unsigned int lineno, const uns
|
|||
|
||||
_back->linenr(lineno);
|
||||
_back->fileIndex(fileno);
|
||||
_back->isUnsigned(tok->isUnsigned());
|
||||
_back->isSigned(tok->isSigned());
|
||||
_back->isLong(tok->isLong());
|
||||
_back->isAttributeConstructor(tok->isAttributeConstructor());
|
||||
_back->isAttributeDestructor(tok->isAttributeDestructor());
|
||||
_back->isAttributeUnused(tok->isAttributeUnused());
|
||||
_back->isAttributePure(tok->isAttributePure());
|
||||
_back->isAttributeConst(tok->isAttributeConst());
|
||||
_back->isAttributeNothrow(tok->isAttributeNothrow());
|
||||
_back->isDeclspecNothrow(tok->isDeclspecNothrow());
|
||||
_back->flags(tok->flags());
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// InsertTokens - Copy and insert tokens
|
||||
|
@ -180,17 +171,7 @@ void TokenList::insertTokens(Token *dest, const Token *src, unsigned int n)
|
|||
dest->linenr(src->linenr());
|
||||
dest->varId(src->varId());
|
||||
dest->type(src->type());
|
||||
dest->isUnsigned(src->isUnsigned());
|
||||
dest->isSigned(src->isSigned());
|
||||
dest->isPointerCompare(src->isPointerCompare());
|
||||
dest->isLong(src->isLong());
|
||||
dest->isAttributeConstructor(src->isAttributeConstructor());
|
||||
dest->isAttributeDestructor(src->isAttributeDestructor());
|
||||
dest->isAttributeUnused(src->isAttributeUnused());
|
||||
dest->isAttributePure(src->isAttributePure());
|
||||
dest->isAttributeConst(src->isAttributeConst());
|
||||
dest->isAttributeNothrow(src->isAttributeNothrow());
|
||||
dest->isDeclspecNothrow(src->isDeclspecNothrow());
|
||||
dest->flags(src->flags());
|
||||
src = src->next();
|
||||
--n;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue