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

Method typeOf

lib/token.cpp:2344–2396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2342}
2343
2344const ::Type* Token::typeOf(const Token* tok, const Token** typeTok)
2345{
2346 if (!tok)
2347 return nullptr;
2348 if (typeTok != nullptr)
2349 *typeTok = tok;
2350 const Token* lhsVarTok{};
2351 if (tok->type())
2352 return tok->type();
2353 if (tok->variable())
2354 return tok->variable()->type();
2355 if (tok->function())
2356 return tok->function()->retType;
2357 if (tok->valueType() && tok->valueType()->typeScope && tok->valueType()->typeScope->definedType)
2358 return tok->valueType()->typeScope->definedType;
2359 if (Token::simpleMatch(tok, "return")) {
2360 const Scope *scope = tok->scope();
2361 if (!scope)
2362 return nullptr;
2363 const Function *function = scope->function;
2364 if (!function)
2365 return nullptr;
2366 return function->retType;
2367 }
2368 if (Token::Match(tok->previous(), "%type%|= (|{"))
2369 return typeOf(tok->previous(), typeTok);
2370 if (Token::simpleMatch(tok, "=") && (lhsVarTok = getLHSVariableToken(tok)) != tok->next())
2371 return Token::typeOf(lhsVarTok, typeTok);
2372 if (Token::simpleMatch(tok, "."))
2373 return Token::typeOf(tok->astOperand2(), typeTok);
2374 if (Token::simpleMatch(tok, "["))
2375 return Token::typeOf(tok->astOperand1(), typeTok);
2376 if (Token::simpleMatch(tok, "{")) {
2377 int argnr;
2378 const Token* ftok = getTokenArgumentFunction(tok, argnr);
2379 if (argnr < 0)
2380 return nullptr;
2381 if (!ftok)
2382 return nullptr;
2383 if (ftok == tok)
2384 return nullptr;
2385 std::vector<const Variable*> vars = getArgumentVars(ftok, argnr);
2386 if (vars.empty())
2387 return nullptr;
2388 if (std::all_of(
2389 vars.cbegin(), vars.cend(), [&](const Variable* var) {
2390 return var->type() == vars.front()->type();
2391 }))
2392 return vars.front()->type();
2393 }
2394
2395 return nullptr;
2396}
2397
2398std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool pointedToType)
2399{

Callers

nothing calls this directly

Calls 13

getLHSVariableTokenFunction · 0.85
getTokenArgumentFunctionFunction · 0.85
getArgumentVarsFunction · 0.85
typeMethod · 0.80
variableMethod · 0.80
scopeMethod · 0.80
nextMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
frontMethod · 0.80
simpleMatchFunction · 0.70
functionMethod · 0.45

Tested by

no test coverage detected