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

Function findLambdaEndTokenGeneric

lib/astutils.cpp:3288–3324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3286}
3287
3288template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
3289static T* findLambdaEndTokenGeneric(T* first)
3290{
3291 auto maybeLambda = [](T* tok) -> bool {
3292 while (Token::Match(tok, "*|%name%|::|>")) {
3293 if (tok->link())
3294 tok = tok->link()->previous();
3295 else {
3296 if (tok->str() == ">")
3297 return true;
3298 if (tok->str() == "new")
3299 return false;
3300 tok = tok->previous();
3301 }
3302 }
3303 return true;
3304 };
3305
3306 if (!first || !first->isCpp() || first->str() != "[")
3307 return nullptr;
3308 if (!maybeLambda(first->previous()))
3309 return nullptr;
3310 if (!Token::Match(first->link(), "] (|{|<"))
3311 return nullptr;
3312 const Token* roundOrCurly = first->link()->next();
3313 if (roundOrCurly->link() && roundOrCurly->str() == "<")
3314 roundOrCurly = roundOrCurly->link()->next();
3315 if (first->astOperand1() != roundOrCurly)
3316 return nullptr;
3317 T * tok = first;
3318
3319 if (tok->astOperand1() && tok->astOperand1()->str() == "(")
3320 tok = tok->astOperand1();
3321 if (tok->astOperand1() && tok->astOperand1()->str() == "{")
3322 return tok->astOperand1()->link();
3323 return nullptr;
3324}
3325
3326const Token* findLambdaEndToken(const Token* first)
3327{

Callers 1

findLambdaEndTokenFunction · 0.85

Calls 3

nextMethod · 0.80
astOperand1Method · 0.80
strMethod · 0.45

Tested by

no test coverage detected