diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7139cdf1b..edcbc293a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1791,6 +1791,9 @@ const Token * Variable::declEndToken() const void Variable::evaluate(const Library* lib) { + unsigned int pointer = 0; + _constness = 0; + if (_name) setFlag(fIsArray, arrayDimensions(lib)); @@ -1809,11 +1812,13 @@ void Variable::evaluate(const Library* lib) setFlag(fIsVolatile, true); else if (tok->str() == "mutable") setFlag(fIsMutable, true); - else if (tok->str() == "const") + else if (tok->str() == "const") { setFlag(fIsConst, true); - else if (tok->str() == "*") { + _constness |= 1 << pointer; + } else if (tok->str() == "*") { setFlag(fIsPointer, !isArray() || Token::Match(tok->previous(), "( * %name% )")); setFlag(fIsConst, false); // Points to const, isn't necessarily const itself + ++pointer; } else if (tok->str() == "&") { if (isReference()) setFlag(fIsRValueRef, true); @@ -3045,6 +3050,7 @@ void SymbolDatabase::printXml(std::ostream &out) const out << " isPointer=\"" << var->isPointer() << '\"'; out << " isReference=\"" << var->isReference() << '\"'; out << " isStatic=\"" << var->isStatic() << '\"'; + out << " constness=\"" << var->constness() << '\"'; out << " access=\"" << accessControlToString(var->_access) << '\"'; out << "/>" << std::endl; } diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index fd22a08c1..8a67e365a 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -229,6 +229,7 @@ public: _index(index_), _access(access_), _flags(0), + _constness(0), _type(type_), _scope(scope_) { evaluate(lib); @@ -599,6 +600,10 @@ public: void setFlags(const ValueType &valuetype); + unsigned int constness() const { + return _constness; + } + private: // only symbol database can change the type friend class SymbolDatabase; @@ -629,6 +634,9 @@ private: /** @brief flags */ unsigned int _flags; + /** @brief constness (same encoding as ValueType::constness) */ + unsigned int _constness; + /** @brief pointer to user defined type info (for known types) */ const Type *_type;