| 2342 | } |
| 2343 | |
| 2344 | const ::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 | |
| 2398 | std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool pointedToType) |
| 2399 | { |
nothing calls this directly
no test coverage detected