SymbolDatabase: add constness attribute for Variable

This commit is contained in:
Daniel Marjamäki 2018-04-12 20:23:34 +02:00
parent 9e623b15b1
commit f7d65cd735
2 changed files with 16 additions and 2 deletions

View File

@ -1791,6 +1791,9 @@ const Token * Variable::declEndToken() const
void Variable::evaluate(const Library* lib) void Variable::evaluate(const Library* lib)
{ {
unsigned int pointer = 0;
_constness = 0;
if (_name) if (_name)
setFlag(fIsArray, arrayDimensions(lib)); setFlag(fIsArray, arrayDimensions(lib));
@ -1809,11 +1812,13 @@ void Variable::evaluate(const Library* lib)
setFlag(fIsVolatile, true); setFlag(fIsVolatile, true);
else if (tok->str() == "mutable") else if (tok->str() == "mutable")
setFlag(fIsMutable, true); setFlag(fIsMutable, true);
else if (tok->str() == "const") else if (tok->str() == "const") {
setFlag(fIsConst, true); setFlag(fIsConst, true);
else if (tok->str() == "*") { _constness |= 1 << pointer;
} else if (tok->str() == "*") {
setFlag(fIsPointer, !isArray() || Token::Match(tok->previous(), "( * %name% )")); setFlag(fIsPointer, !isArray() || Token::Match(tok->previous(), "( * %name% )"));
setFlag(fIsConst, false); // Points to const, isn't necessarily const itself setFlag(fIsConst, false); // Points to const, isn't necessarily const itself
++pointer;
} else if (tok->str() == "&") { } else if (tok->str() == "&") {
if (isReference()) if (isReference())
setFlag(fIsRValueRef, true); setFlag(fIsRValueRef, true);
@ -3045,6 +3050,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
out << " isPointer=\"" << var->isPointer() << '\"'; out << " isPointer=\"" << var->isPointer() << '\"';
out << " isReference=\"" << var->isReference() << '\"'; out << " isReference=\"" << var->isReference() << '\"';
out << " isStatic=\"" << var->isStatic() << '\"'; out << " isStatic=\"" << var->isStatic() << '\"';
out << " constness=\"" << var->constness() << '\"';
out << " access=\"" << accessControlToString(var->_access) << '\"'; out << " access=\"" << accessControlToString(var->_access) << '\"';
out << "/>" << std::endl; out << "/>" << std::endl;
} }

View File

@ -229,6 +229,7 @@ public:
_index(index_), _index(index_),
_access(access_), _access(access_),
_flags(0), _flags(0),
_constness(0),
_type(type_), _type(type_),
_scope(scope_) { _scope(scope_) {
evaluate(lib); evaluate(lib);
@ -599,6 +600,10 @@ public:
void setFlags(const ValueType &valuetype); void setFlags(const ValueType &valuetype);
unsigned int constness() const {
return _constness;
}
private: private:
// only symbol database can change the type // only symbol database can change the type
friend class SymbolDatabase; friend class SymbolDatabase;
@ -629,6 +634,9 @@ private:
/** @brief flags */ /** @brief flags */
unsigned int _flags; unsigned int _flags;
/** @brief constness (same encoding as ValueType::constness) */
unsigned int _constness;
/** @brief pointer to user defined type info (for known types) */ /** @brief pointer to user defined type info (for known types) */
const Type *_type; const Type *_type;