@@ -1069,10 +1069,12 @@ bool isAliasOf(const Token *tok, nonneg int varid, bool* inconclusive)
10691069
10701070bool isAliasOf (const Token* tok, const Token* expr, nonneg int * indirect)
10711071{
1072- const Token* r = nullptr ;
10731072 if (indirect)
10741073 *indirect = 1 ;
1075- for (const ReferenceToken& ref : followAllReferences (tok)) {
1074+ if (!tok)
1075+ return false ;
1076+ const Token* r = nullptr ;
1077+ for (const ReferenceToken& ref : tok->refs ()) {
10761078 const bool pointer = astIsPointer (ref.token );
10771079 r = findAstNode (expr, [&](const Token* childTok) {
10781080 if (childTok->exprId () == 0 )
@@ -1253,11 +1255,11 @@ static void followVariableExpressionError(const Token *tok1, const Token *tok2,
12531255 errors->push_back (std::move (item));
12541256}
12551257
1256- SmallVector<ReferenceToken> followAllReferences (const Token* tok,
1257- bool temporary,
1258- bool inconclusive,
1259- ErrorPath errors,
1260- int depth)
1258+ static SmallVector<ReferenceToken> followAllReferencesInternal (const Token* tok,
1259+ bool temporary = true ,
1260+ bool inconclusive = true ,
1261+ ErrorPath errors = ErrorPath{} ,
1262+ int depth = 20 )
12611263{
12621264 struct ReferenceTokenLess {
12631265 bool operator ()(const ReferenceToken& x, const ReferenceToken& y) const {
@@ -1303,16 +1305,16 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
13031305 return refs_result;
13041306 }
13051307 if (vartok)
1306- return followAllReferences (vartok, temporary, inconclusive, std::move (errors), depth - 1 );
1308+ return followAllReferencesInternal (vartok, temporary, inconclusive, std::move (errors), depth - 1 );
13071309 }
13081310 }
13091311 } else if (Token::simpleMatch (tok, " ?" ) && Token::simpleMatch (tok->astOperand2 (), " :" )) {
13101312 std::set<ReferenceToken, ReferenceTokenLess> result;
13111313 const Token* tok2 = tok->astOperand2 ();
13121314
1313- auto refs = followAllReferences (tok2->astOperand1 (), temporary, inconclusive, errors, depth - 1 );
1315+ auto refs = followAllReferencesInternal (tok2->astOperand1 (), temporary, inconclusive, errors, depth - 1 );
13141316 result.insert (refs.cbegin (), refs.cend ());
1315- refs = followAllReferences (tok2->astOperand2 (), temporary, inconclusive, errors, depth - 1 );
1317+ refs = followAllReferencesInternal (tok2->astOperand2 (), temporary, inconclusive, errors, depth - 1 );
13161318 result.insert (refs.cbegin (), refs.cend ());
13171319
13181320 if (!inconclusive && result.size () != 1 ) {
@@ -1340,7 +1342,7 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
13401342 if (returnTok == tok)
13411343 continue ;
13421344 for (const ReferenceToken& rt :
1343- followAllReferences (returnTok, temporary, inconclusive, errors, depth - returns.size ())) {
1345+ followAllReferencesInternal (returnTok, temporary, inconclusive, errors, depth - returns.size ())) {
13441346 const Variable* argvar = rt.token ->variable ();
13451347 if (!argvar) {
13461348 SmallVector<ReferenceToken> refs_result;
@@ -1365,7 +1367,7 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
13651367 er.emplace_back (returnTok, " Return reference." );
13661368 er.emplace_back (tok->previous (), " Called function passing '" + argTok->expressionString () + " '." );
13671369 auto refs =
1368- followAllReferences (argTok, temporary, inconclusive, std::move (er), depth - returns.size ());
1370+ followAllReferencesInternal (argTok, temporary, inconclusive, std::move (er), depth - returns.size ());
13691371 result.insert (refs.cbegin (), refs.cend ());
13701372 if (!inconclusive && result.size () > 1 ) {
13711373 SmallVector<ReferenceToken> refs_result;
@@ -1386,11 +1388,16 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
13861388 return refs_result;
13871389}
13881390
1391+ SmallVector<ReferenceToken> followAllReferences (const Token* tok, bool temporary)
1392+ {
1393+ return followAllReferencesInternal (tok, temporary);
1394+ }
1395+
13891396const Token* followReferences (const Token* tok, ErrorPath* errors)
13901397{
13911398 if (!tok)
13921399 return nullptr ;
1393- auto refs = followAllReferences (tok, true , false );
1400+ auto refs = followAllReferencesInternal (tok, true , false );
13941401 if (refs.size () == 1 ) {
13951402 if (errors)
13961403 *errors = std::move (refs.front ().errors );
0 commit comments