From f7d65cd7352eb6902f0b771950a58908cd5ae13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 12 Apr 2018 20:23:34 +0200 Subject: [PATCH] SymbolDatabase: add constness attribute for Variable --- lib/symboldatabase.cpp | 10 ++++++++-- lib/symboldatabase.h | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) 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;