MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / setupExprVarIds

Method setupExprVarIds

lib/vf_analyzers.cpp:1272–1313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1270 }
1271
1272 void setupExprVarIds(const Token* start, int depth = 0) {
1273 if (depth > settings.vfOptions.maxExprVarIdDepth) {
1274 // TODO: add bailout message
1275 return;
1276 }
1277 visitAstNodes(start, [&](const Token* tok) {
1278 const bool top = depth == 0 && tok == start;
1279 const bool ispointer = astIsPointer(tok) || astIsSmartPointer(tok) || astIsIterator(tok);
1280 if (!top || !ispointer || value.indirect != 0) {
1281 for (const ValueFlow::Value& v : tok->values()) {
1282 if (!(v.isLocalLifetimeValue() || (ispointer && v.isSymbolicValue() && v.isKnown())))
1283 continue;
1284 if (!v.tokvalue)
1285 continue;
1286 if (v.tokvalue == tok)
1287 continue;
1288 setupExprVarIds(v.tokvalue, depth + 1);
1289 }
1290 }
1291 if (depth == 0 && tok->isIncompleteVar()) {
1292 // TODO: Treat incomplete var as global, but we need to update
1293 // the alias variables to just expr ids instead of requiring
1294 // Variable
1295 unknown = true;
1296 return ChildrenToVisit::none;
1297 }
1298 if (tok->varId() > 0) {
1299 varids[tok->varId()] = tok->variable();
1300 if (!Token::simpleMatch(tok->previous(), ".")) {
1301 const Variable* var = tok->variable();
1302 if (var && var->isReference() && var->isLocal() && Token::Match(var->nameToken(), "%var% [=(]") &&
1303 !isGlobalData(var->nameToken()->next()->astOperand2()))
1304 return ChildrenToVisit::none;
1305 const bool deref = tok->astParent() &&
1306 (tok->astParent()->isUnaryOp("*") ||
1307 (tok->astParent()->str() == "[" && tok == tok->astParent()->astOperand1()));
1308 local &= !nonLocal(tok->variable(), deref);
1309 }
1310 }
1311 return ChildrenToVisit::op1_and_op2;
1312 });
1313 }
1314
1315 virtual bool skipUniqueExprIds() const {
1316 return true;

Callers

nothing calls this directly

Calls 15

visitAstNodesFunction · 0.85
astIsPointerFunction · 0.85
astIsSmartPointerFunction · 0.85
astIsIteratorFunction · 0.85
isGlobalDataFunction · 0.85
nonLocalFunction · 0.85
isKnownMethod · 0.80
variableMethod · 0.80
astOperand2Method · 0.80
nextMethod · 0.80
astParentMethod · 0.80
isUnaryOpMethod · 0.80

Tested by

no test coverage detected