@@ -242,7 +242,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
242242 new_scope->definedType = &typeList.back ();
243243 scope->definedTypes .push_back (&typeList.back ());
244244
245- scope->addVariable (varNameTok, tok, tok, access[scope], new_scope->definedType , scope);
245+ scope->addVariable (varNameTok, tok, tok, access[scope], new_scope->definedType , scope, &settings-> library );
246246
247247 const Token *tok2 = tok->next ();
248248
@@ -800,9 +800,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
800800 scope->nestedList .push_back (&scopeList.back ());
801801 scope = &scopeList.back ();
802802 if (scope->type == Scope::eFor)
803- scope->checkVariable (tok->tokAt (2 ), Local); // check for variable declaration and add it to new scope if found
803+ scope->checkVariable (tok->tokAt (2 ), Local, &settings-> library ); // check for variable declaration and add it to new scope if found
804804 else if (scope->type == Scope::eCatch)
805- scope->checkVariable (tok->tokAt (2 ), Throw); // check for variable declaration and add it to new scope if found
805+ scope->checkVariable (tok->tokAt (2 ), Throw, &settings-> library ); // check for variable declaration and add it to new scope if found
806806 tok = tok1;
807807 } else if (tok->str () == " {" && !tok->previous ()->varId ()) {
808808 if (tok->strAt (-1 ) == " )" && tok->linkAt (-1 )->strAt (-1 ) == " ]" ) {
@@ -856,7 +856,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
856856 // fill in variable info
857857 for (std::list<Scope>::iterator it = scopeList.begin (); it != scopeList.end (); ++it) {
858858 // find variables
859- it->getVariableList ();
859+ it->getVariableList (&settings-> library );
860860 }
861861
862862 // fill in function arguments
@@ -1342,7 +1342,7 @@ const Token * Variable::declEndToken() const
13421342 return declEnd;
13431343}
13441344
1345- void Variable::evaluate ()
1345+ void Variable::evaluate (const Library* lib )
13461346{
13471347 const Token* tok = _start;
13481348 while (tok && tok->previous () && tok->previous ()->isName ())
@@ -1380,7 +1380,7 @@ void Variable::evaluate()
13801380 _end = _end->previous ();
13811381
13821382 if (_name)
1383- setFlag (fIsArray , arrayDimensions (_dimensions, _name-> next () ));
1383+ setFlag (fIsArray , arrayDimensions (lib ));
13841384 if (_start) {
13851385 setFlag (fIsClass , !_start->isStandardType () && !isPointer () && !isReference ());
13861386 setFlag (fIsStlType , Token::simpleMatch (_start, " std ::" ));
@@ -1396,7 +1396,7 @@ void Variable::evaluate()
13961396 tok = tok->link ()->previous ();
13971397 // add array dimensions if present
13981398 if (tok && tok->next ()->str () == " [" )
1399- setFlag (fIsArray , arrayDimensions (_dimensions, tok-> next () ));
1399+ setFlag (fIsArray , arrayDimensions (lib ));
14001400 }
14011401 if (!tok)
14021402 return ;
@@ -1951,12 +1951,42 @@ bool Type::hasCircularDependencies(std::set<BaseInfo>* anchestors) const
19511951 return false ;
19521952}
19531953
1954- bool Variable::arrayDimensions (std::vector<Dimension> &dimensions, const Token *tok )
1954+ bool Variable::arrayDimensions (const Library* lib )
19551955{
1956- bool isArray = false ;
1956+ const Library::Container* container = lib->detectContainer (_start);
1957+ if (container && container->arrayLike_indexOp && container->size_templateArgNo > 0 ) {
1958+ Dimension dimension;
1959+ const Token* tok = Token::findsimplematch (_start, " <" );
1960+ if (tok) {
1961+ tok = tok->next ();
1962+ for (int i = 0 ; i < container->size_templateArgNo && tok; i++) {
1963+ tok = tok->nextTemplateArgument ();
1964+ }
1965+ if (tok) {
1966+ dimension.start = tok;
1967+ dimension.end = Token::findmatch (tok, " ,|>" );
1968+ if (dimension.end )
1969+ dimension.end = dimension.end ->previous ();
1970+ if (dimension.start == dimension.end )
1971+ dimension.num = MathLib::toLongNumber (dimension.start ->str ());
1972+ }
1973+ _dimensions.push_back (dimension);
1974+ return true ;
1975+ }
1976+ }
19571977
1958- const Token *dim = tok;
1978+ const Token *dim = _name;
1979+ if (!dim) {
1980+ // Argument without name
1981+ dim = _end;
1982+ // back up to start of array dimensions
1983+ while (dim && dim->str () == " ]" )
1984+ dim = dim->link ()->previous ();
1985+ }
1986+ if (dim)
1987+ dim = dim->next ();
19591988
1989+ bool isArray = false ;
19601990 while (dim && dim->next () && dim->str () == " [" ) {
19611991 Dimension dimension;
19621992 // check for empty array dimension []
@@ -1966,7 +1996,7 @@ bool Variable::arrayDimensions(std::vector<Dimension> &dimensions, const Token *
19661996 if (dimension.start == dimension.end && dimension.start ->isNumber ())
19671997 dimension.num = MathLib::toLongNumber (dimension.start ->str ());
19681998 }
1969- dimensions .push_back (dimension);
1999+ _dimensions .push_back (dimension);
19702000 dim = dim->link ()->next ();
19712001 isArray = true ;
19722002 }
@@ -2452,7 +2482,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
24522482 }
24532483 }
24542484
2455- argumentList.push_back (Variable (nameTok, startTok, endTok, count++, Argument, argType, functionScope));
2485+ argumentList.push_back (Variable (nameTok, startTok, endTok, count++, Argument, argType, functionScope, &symbolDatabase-> _settings -> library ));
24562486
24572487 if (tok->str () == " )" )
24582488 break ;
@@ -2634,7 +2664,7 @@ AccessControl Scope::defaultAccess() const
26342664}
26352665
26362666// Get variable list..
2637- void Scope::getVariableList ()
2667+ void Scope::getVariableList (const Library* lib )
26382668{
26392669 const Token *start;
26402670
@@ -2748,14 +2778,14 @@ void Scope::getVariableList()
27482778 continue ;
27492779 }
27502780
2751- tok = checkVariable (tok, varaccess);
2781+ tok = checkVariable (tok, varaccess, lib );
27522782
27532783 if (!tok)
27542784 break ;
27552785 }
27562786}
27572787
2758- const Token *Scope::checkVariable (const Token *tok, AccessControl varaccess)
2788+ const Token *Scope::checkVariable (const Token *tok, AccessControl varaccess, const Library* lib )
27592789{
27602790 // Is it a throw..?
27612791 if (Token::Match (tok, " throw %any% (" ) &&
@@ -2823,7 +2853,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
28232853 }
28242854 }
28252855
2826- addVariable (vartok, typestart, vartok->previous (), varaccess, vType, this );
2856+ addVariable (vartok, typestart, vartok->previous (), varaccess, vType, this , lib );
28272857 }
28282858
28292859 return tok;
0 commit comments