@@ -365,7 +365,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
365365 scope->definedTypesMap [new_type->name ()] = new_type;
366366 }
367367
368- scope->addVariable (varNameTok, tok, tok, access[scope], new_scope->definedType , scope, & mSettings -> library );
368+ scope->addVariable (varNameTok, tok, tok, access[scope], new_scope->definedType , scope, mSettings );
369369
370370 const Token *tok2 = tok->next ();
371371
@@ -637,9 +637,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
637637 scope->nestedList .push_back (&scopeList.back ());
638638 scope = &scopeList.back ();
639639 if (scope->type == Scope::eFor)
640- scope->checkVariable (tok->tokAt (2 ), Local, & mSettings -> library ); // check for variable declaration and add it to new scope if found
640+ scope->checkVariable (tok->tokAt (2 ), Local, mSettings ); // check for variable declaration and add it to new scope if found
641641 else if (scope->type == Scope::eCatch)
642- scope->checkVariable (tok->tokAt (2 ), Throw, & mSettings -> library ); // check for variable declaration and add it to new scope if found
642+ scope->checkVariable (tok->tokAt (2 ), Throw, mSettings ); // check for variable declaration and add it to new scope if found
643643 tok = scopeStartTok;
644644 } else if (tok->str () == " {" ) {
645645 if (tok->previous ()->varId ())
@@ -717,7 +717,7 @@ void SymbolDatabase::createSymbolDatabaseVariableInfo()
717717 // fill in variable info
718718 for (std::list<Scope>::iterator it = scopeList.begin (); it != scopeList.end (); ++it) {
719719 // find variables
720- it->getVariableList (& mSettings -> library );
720+ it->getVariableList (mSettings );
721721 }
722722
723723 // fill in function arguments
@@ -1598,6 +1598,11 @@ void SymbolDatabase::validate() const
15981598 // validateVariables();
15991599}
16001600
1601+ Variable::~Variable ()
1602+ {
1603+ delete mValueType ;
1604+ }
1605+
16011606bool Variable::isPointerArray () const
16021607{
16031608 return isArray () && nameToken () && nameToken ()->previous () && (nameToken ()->previous ()->str () == " *" );
@@ -1614,14 +1619,16 @@ const Token * Variable::declEndToken() const
16141619 return declEnd;
16151620}
16161621
1617- void Variable::evaluate (const Library* lib )
1622+ void Variable::evaluate (const Settings* settings )
16181623{
1619- unsigned int pointer = 0 ;
1620- mConstness = 0 ;
1624+ const Library * const lib = settings ? &settings->library : nullptr ;
16211625
16221626 if (mNameToken )
16231627 setFlag (fIsArray , arrayDimensions (lib));
16241628
1629+ if (mTypeStartToken )
1630+ setValueType (ValueType::parseDecl (mTypeStartToken ,settings));
1631+
16251632 const Token* tok = mTypeStartToken ;
16261633 while (tok && tok->previous () && tok->previous ()->isName ())
16271634 tok = tok->previous ();
@@ -1637,13 +1644,11 @@ void Variable::evaluate(const Library* lib)
16371644 setFlag (fIsVolatile , true );
16381645 else if (tok->str () == " mutable" )
16391646 setFlag (fIsMutable , true );
1640- else if (tok->str () == " const" ) {
1647+ else if (tok->str () == " const" )
16411648 setFlag (fIsConst , true );
1642- mConstness |= 1 << pointer;
1643- } else if (tok->str () == " *" ) {
1649+ else if (tok->str () == " *" ) {
16441650 setFlag (fIsPointer , !isArray () || Token::Match (tok->previous (), " ( * %name% )" ));
16451651 setFlag (fIsConst , false ); // Points to const, isn't necessarily const itself
1646- ++pointer;
16471652 } else if (tok->str () == " &" ) {
16481653 if (isReference ())
16491654 setFlag (fIsRValueRef , true );
@@ -1708,6 +1713,15 @@ void Variable::evaluate(const Library* lib)
17081713 }
17091714}
17101715
1716+ void Variable::setValueType (const ValueType &valueType)
1717+ {
1718+ delete mValueType ;
1719+ mValueType = new ValueType (valueType);
1720+ if ((mValueType ->pointer > 0 ) && (!isArray () || Token::Match (mNameToken ->previous (), " ( * %name% )" )))
1721+ setFlag (fIsPointer , true );
1722+ setFlag (fIsConst , mValueType ->constness & (1U << mValueType ->pointer ));
1723+ }
1724+
17111725Function::Function (const Tokenizer *mTokenizer , const Token *tok, const Scope *scope, const Token *tokDef, const Token *tokArgDef)
17121726 : tokenDef(tokDef),
17131727 argDef(tokArgDef),
@@ -2503,15 +2517,6 @@ bool Variable::arrayDimensions(const Library* lib)
25032517 return arr;
25042518}
25052519
2506- void Variable::setFlags (const ValueType &valuetype)
2507- {
2508- if (valuetype.constness )
2509- setFlag (fIsConst ,true );
2510- if (valuetype.pointer )
2511- setFlag (fIsPointer ,true );
2512- }
2513-
2514-
25152520static std::ostream & operator << (std::ostream & s, Scope::ScopeType type)
25162521{
25172522 s << (type == Scope::eGlobal ? " Global" :
@@ -3006,7 +3011,6 @@ void SymbolDatabase::printXml(std::ostream &out) const
30063011 out << " isPointer=\" " << var->isPointer () << ' \" ' ;
30073012 out << " isReference=\" " << var->isReference () << ' \" ' ;
30083013 out << " isStatic=\" " << var->isStatic () << ' \" ' ;
3009- out << " constness=\" " << var->constness () << ' \" ' ;
30103014 out << " />" << std::endl;
30113015 }
30123016 out << " </variables>" << std::endl;
@@ -3123,7 +3127,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
31233127 while (Token::Match (startTok, " enum|struct|const|volatile" ))
31243128 startTok = startTok->next ();
31253129
3126- argumentList.emplace_back (nameTok, startTok, endTok, count++, Argument, argType, functionScope, & symbolDatabase->mSettings -> library );
3130+ argumentList.emplace_back (nameTok, startTok, endTok, count++, Argument, argType, functionScope, symbolDatabase->mSettings );
31273131
31283132 if (tok->str () == " )" ) {
31293133 // check for a variadic function
@@ -3325,7 +3329,7 @@ AccessControl Scope::defaultAccess() const
33253329}
33263330
33273331// Get variable list..
3328- void Scope::getVariableList (const Library* lib )
3332+ void Scope::getVariableList (const Settings* settings )
33293333{
33303334 const Token *start;
33313335
@@ -3426,14 +3430,14 @@ void Scope::getVariableList(const Library* lib)
34263430 else if (tok->str () == " ;" )
34273431 continue ;
34283432
3429- tok = checkVariable (tok, varaccess, lib );
3433+ tok = checkVariable (tok, varaccess, settings );
34303434
34313435 if (!tok)
34323436 break ;
34333437 }
34343438}
34353439
3436- const Token *Scope::checkVariable (const Token *tok, AccessControl varaccess, const Library* lib )
3440+ const Token *Scope::checkVariable (const Token *tok, AccessControl varaccess, const Settings* settings )
34373441{
34383442 // Is it a throw..?
34393443 if (Token::Match (tok, " throw %any% (" ) &&
@@ -3494,7 +3498,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con
34943498 if (Token::Match (typestart, " enum|struct" ))
34953499 typestart = typestart->next ();
34963500
3497- addVariable (vartok, typestart, vartok->previous (), varaccess, vType, this , lib );
3501+ addVariable (vartok, typestart, vartok->previous (), varaccess, vType, this , settings );
34983502 }
34993503
35003504 return tok;
@@ -4872,7 +4876,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
48724876 setValueType (parent->previous (), *vt2);
48734877 Variable *var = const_cast <Variable *>(parent->previous ()->variable ());
48744878 if (var) {
4875- var->setFlags (*vt2);
4879+ var->setValueType (*vt2);
48764880 if (vt2->typeScope && vt2->typeScope ->definedType ) {
48774881 var->type (vt2->typeScope ->definedType );
48784882 if (autoTok->valueType ()->pointer == 0 )
@@ -4956,7 +4960,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
49564960 setValueType (parent->previous (), varvt);
49574961 Variable *var = const_cast <Variable *>(parent->previous ()->variable ());
49584962 if (var) {
4959- var->setFlags (varvt);
4963+ var->setValueType (varvt);
49604964 if (vt2->typeScope && vt2->typeScope ->definedType ) {
49614965 var->type (vt2->typeScope ->definedType );
49624966 autoToken->type (vt2->typeScope ->definedType );
@@ -4985,7 +4989,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
49854989 setValueType (parent->previous (), varvt);
49864990 Variable * var = const_cast <Variable *>(parent->previous ()->variable ());
49874991 if (var) {
4988- var->setFlags (varvt);
4992+ var->setValueType (varvt);
49894993 const Type * type = typeStart->tokAt (4 )->type ();
49904994 if (type && type->classScope && type->classScope ->definedType ) {
49914995 autoToken->type (type->classScope ->definedType );
0 commit comments