From beaf29c15867984aa3c2a15cf15bd7576ccde2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 27 Feb 2017 23:04:25 +0100 Subject: [PATCH] SymbolDatabase: Update some properties for auto variables --- lib/symboldatabase.cpp | 20 ++++++++++++++++++++ lib/symboldatabase.h | 2 ++ test/testsymboldatabase.cpp | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index def9f1e7f..d2318b353 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2418,6 +2418,15 @@ bool Variable::arrayDimensions(const Library* lib) return arr; } +void Variable::setFlags(const ValueType &valuetype) +{ + if (valuetype.constness) + setFlag(fIsConst,true); + if (valuetype.pointer) + setFlag(fIsPointer,true); +} + + static std::ostream & operator << (std::ostream & s, Scope::ScopeType type) { s << (type == Scope::eGlobal ? "Global" : @@ -4404,6 +4413,13 @@ static void setValueType(Token *tok, const Enumerator &enumerator, bool cpp, Val } } +static void setAutoTokenProperties(Token * const autoTok) +{ + const ValueType *valuetype = autoTok->valueType(); + if (valuetype->isIntegral() || valuetype->isFloat()) + autoTok->isStandardType(true); +} + static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, ValueType::Sign defaultSignedness, const Settings* settings) { tok->setValueType(new ValueType(valuetype)); @@ -4434,8 +4450,10 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value autoTok = var1Tok->tokAt(-2); if (autoTok) { setValueType(autoTok, *vt2, cpp, defaultSignedness, settings); + setAutoTokenProperties(autoTok); setValueType(var1Tok, *vt2, cpp, defaultSignedness, settings); setValueType(parent->previous(), *vt2, cpp, defaultSignedness, settings); + const_cast(parent->previous()->variable())->setFlags(*vt2); } } return; @@ -4500,7 +4518,9 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value if (isconst) vt.constness |= 1; setValueType(autoToken, vt, cpp, defaultSignedness, settings); + setAutoTokenProperties(autoToken); setValueType(parent->previous(), vt, cpp, defaultSignedness, settings); + const_cast(parent->previous()->variable())->setFlags(vt); } } diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 28dfe57df..fc7e8c47c 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -580,6 +580,8 @@ public: return type() && type()->isEnumType(); } + void setFlags(const ValueType &valuetype); + private: // only symbol database can change the type friend class SymbolDatabase; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index bf6a9a013..19843ba56 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -315,6 +315,8 @@ private: TEST_CASE(variadic3); // #7387 TEST_CASE(noReturnType); + + TEST_CASE(auto1); } void array() { @@ -4347,6 +4349,14 @@ private: } } } + + void auto1() { + GET_SYMBOL_DB("; auto x = \"abc\";"); + const Token *autotok = tokenizer.tokens()->next(); + ASSERT(autotok && autotok->isStandardType()); + const Variable *var = db ? db->getVariableFromVarId(1) : nullptr; + ASSERT(var && var->isPointer() && var->isConst()); + } }; REGISTER_TEST(TestSymbolDatabase)