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

Function isUniqueExpression

lib/astutils.cpp:2165–2213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2163}
2164
2165bool isUniqueExpression(const Token* tok)
2166{
2167 if (!tok)
2168 return true;
2169 if (tok->function()) {
2170 const Function * fun = tok->function();
2171 const Scope * scope = fun->nestedIn;
2172 if (!scope)
2173 return true;
2174 const std::string returnType = fun->retType ? fun->retType->name() : fun->retDef->stringifyList(fun->tokenDef);
2175 if (!std::all_of(scope->functionList.begin(), scope->functionList.end(), [&](const Function& f) {
2176 if (f.type != FunctionType::eFunction)
2177 return true;
2178
2179 const std::string freturnType = f.retType ? f.retType->name() : f.retDef->stringifyList(f.returnDefEnd());
2180 return f.argumentList.size() != fun->argumentList.size() || returnType != freturnType || f.name() == fun->name();
2181 }))
2182 return false;
2183 } else if (tok->variable()) {
2184 const Variable * var = tok->variable();
2185 const Scope * scope = var->scope();
2186 if (!scope)
2187 return true;
2188 const Type * varType = var->type();
2189 // Iterate over the variables in scope and the parameters of the function if possible
2190 const Function * fun = scope->function;
2191
2192 auto pred = [=](const Variable& v) {
2193 if (varType)
2194 return v.type() && v.type()->name() == varType->name() && v.name() != var->name();
2195 return v.isFloatingType() == var->isFloatingType() &&
2196 v.isEnumType() == var->isEnumType() &&
2197 v.isClass() == var->isClass() &&
2198 v.isArray() == var->isArray() &&
2199 v.isPointer() == var->isPointer() &&
2200 v.name() != var->name();
2201 };
2202 if (std::any_of(scope->varlist.cbegin(), scope->varlist.cend(), pred))
2203 return false;
2204 if (fun) {
2205 if (std::any_of(fun->argumentList.cbegin(), fun->argumentList.cend(), pred))
2206 return false;
2207 }
2208 } else if (!isUniqueExpression(tok->astOperand1())) {
2209 return false;
2210 }
2211
2212 return isUniqueExpression(tok->astOperand2());
2213}
2214
2215static bool isEscaped(const Token* tok, bool functionsScope, const Library& library)
2216{

Callers 1

Calls 14

stringifyListMethod · 0.80
variableMethod · 0.80
scopeMethod · 0.80
typeMethod · 0.80
isEnumTypeMethod · 0.80
isClassMethod · 0.80
isArrayMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
functionMethod · 0.45
nameMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected