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

Function findExpressionChangedImpl

lib/astutils.cpp:3084–3133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3082
3083template<class Find>
3084static const Token* findExpressionChangedImpl(const Token* expr,
3085 const Token* start,
3086 const Token* end,
3087 const Settings& settings,
3088 int depth,
3089 Find find)
3090{
3091 if (depth < 0)
3092 return start;
3093 if (!precedes(start, end))
3094 return nullptr;
3095 const Token* result = nullptr;
3096 findAstNode(expr, [&](const Token* tok) {
3097 if (exprDependsOnThis(tok)) {
3098 result = findThisChanged(start, end, /*indirect*/ 0, settings);
3099 if (result)
3100 return true;
3101 }
3102 bool global = false;
3103 if (tok->variable()) {
3104 global = !tok->variable()->isLocal() && !tok->variable()->isArgument();
3105 } else if (tok->isIncompleteVar() && !tok->isIncompleteConstant()) {
3106 global = true;
3107 }
3108
3109 if (tok->exprId() > 0 || global) {
3110 const Token* modifedTok = find(start, end, [&](const Token* tok2) {
3111 int indirect = 0;
3112 if (const ValueType* vt = tok->valueType()) {
3113 indirect = vt->pointer;
3114 if (vt->type == ValueType::ITERATOR)
3115 ++indirect;
3116 }
3117 if (indirect == 0 && tok2->astParent() && tok2->astParent()->isUnaryOp("*"))
3118 ++indirect;
3119 for (int i = 0; i <= indirect; ++i) {
3120 if (isExpressionChangedAt(tok, tok2, i, global, settings, depth))
3121 return true;
3122 }
3123 return false;
3124 });
3125 if (modifedTok) {
3126 result = modifedTok;
3127 return true;
3128 }
3129 }
3130 return false;
3131 });
3132 return result;
3133}
3134
3135namespace {
3136 struct ExpressionChangedSimpleFind {

Callers 2

findExpressionChangedFunction · 0.85

Calls 8

precedesFunction · 0.85
findAstNodeFunction · 0.85
exprDependsOnThisFunction · 0.85
findThisChangedFunction · 0.85
isExpressionChangedAtFunction · 0.85
variableMethod · 0.80
astParentMethod · 0.80
isUnaryOpMethod · 0.80

Tested by

no test coverage detected