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

Function getArgumentVars

lib/astutils.cpp:2446–2486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2444}
2445
2446std::vector<const Variable*> getArgumentVars(const Token* tok, int argnr)
2447{
2448 if (!tok)
2449 return {};
2450 if (tok->function()) {
2451 const Variable* argvar = tok->function()->getArgumentVar(argnr);
2452 if (argvar)
2453 return {argvar};
2454 return {};
2455 }
2456 if (tok->variable() || Token::simpleMatch(tok, "{") || Token::Match(tok->previous(), "%type% (|{")) {
2457 const Type* type = Token::typeOf(tok);
2458 if (!type)
2459 return {};
2460 const Scope* typeScope = type->classScope;
2461 if (!typeScope)
2462 return {};
2463 const bool tokIsBrace = Token::simpleMatch(tok, "{");
2464 // Aggregate constructor
2465 if (tokIsBrace && typeScope->numConstructors == 0 && argnr < typeScope->varlist.size()) {
2466 auto it = std::next(typeScope->varlist.cbegin(), argnr);
2467 return {&*it};
2468 }
2469 std::vector<const Variable*> result;
2470 const int argCount = numberOfArguments(tok);
2471 const bool constructor = tokIsBrace || (tok->variable() && tok->variable()->nameToken() == tok);
2472 for (const Function &function : typeScope->functionList) {
2473 if (function.argCount() < argCount)
2474 continue;
2475 if (constructor && !function.isConstructor())
2476 continue;
2477 if (!constructor && !Token::simpleMatch(function.token, "operator()"))
2478 continue;
2479 const Variable* argvar = function.getArgumentVar(argnr);
2480 if (argvar)
2481 result.push_back(argvar);
2482 }
2483 return result;
2484 }
2485 return {};
2486}
2487
2488static bool isCPPCastKeyword(const Token* tok)
2489{

Callers 4

typeOfMethod · 0.85
getParentValueTypesFunction · 0.85
getFunctionUsageFunction · 0.85

Calls 9

nextFunction · 0.85
numberOfArgumentsFunction · 0.85
getArgumentVarMethod · 0.80
variableMethod · 0.80
simpleMatchFunction · 0.70
functionMethod · 0.45
sizeMethod · 0.45
nameTokenMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected