SymbolDatabase: Update some properties for auto variables

This commit is contained in:
Daniel Marjamäki 2017-02-27 23:04:25 +01:00
parent 994f6b684d
commit beaf29c158
3 changed files with 32 additions and 0 deletions

View File

@ -2418,6 +2418,15 @@ bool Variable::arrayDimensions(const Library* lib)
return arr; 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) static std::ostream & operator << (std::ostream & s, Scope::ScopeType type)
{ {
s << (type == Scope::eGlobal ? "Global" : 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) static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, ValueType::Sign defaultSignedness, const Settings* settings)
{ {
tok->setValueType(new ValueType(valuetype)); tok->setValueType(new ValueType(valuetype));
@ -4434,8 +4450,10 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
autoTok = var1Tok->tokAt(-2); autoTok = var1Tok->tokAt(-2);
if (autoTok) { if (autoTok) {
setValueType(autoTok, *vt2, cpp, defaultSignedness, settings); setValueType(autoTok, *vt2, cpp, defaultSignedness, settings);
setAutoTokenProperties(autoTok);
setValueType(var1Tok, *vt2, cpp, defaultSignedness, settings); setValueType(var1Tok, *vt2, cpp, defaultSignedness, settings);
setValueType(parent->previous(), *vt2, cpp, defaultSignedness, settings); setValueType(parent->previous(), *vt2, cpp, defaultSignedness, settings);
const_cast<Variable *>(parent->previous()->variable())->setFlags(*vt2);
} }
} }
return; return;
@ -4500,7 +4518,9 @@ static void setValueType(Token *tok, const ValueType &valuetype, bool cpp, Value
if (isconst) if (isconst)
vt.constness |= 1; vt.constness |= 1;
setValueType(autoToken, vt, cpp, defaultSignedness, settings); setValueType(autoToken, vt, cpp, defaultSignedness, settings);
setAutoTokenProperties(autoToken);
setValueType(parent->previous(), vt, cpp, defaultSignedness, settings); setValueType(parent->previous(), vt, cpp, defaultSignedness, settings);
const_cast<Variable *>(parent->previous()->variable())->setFlags(vt);
} }
} }

View File

@ -580,6 +580,8 @@ public:
return type() && type()->isEnumType(); return type() && type()->isEnumType();
} }
void setFlags(const ValueType &valuetype);
private: private:
// only symbol database can change the type // only symbol database can change the type
friend class SymbolDatabase; friend class SymbolDatabase;

View File

@ -315,6 +315,8 @@ private:
TEST_CASE(variadic3); // #7387 TEST_CASE(variadic3); // #7387
TEST_CASE(noReturnType); TEST_CASE(noReturnType);
TEST_CASE(auto1);
} }
void array() { 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) REGISTER_TEST(TestSymbolDatabase)