@@ -595,6 +595,38 @@ static T* getCondTokFromEndImpl(T* endBlock)
595595 return nullptr ;
596596}
597597
598+ template <class T , REQUIRES(" T must be a Token class" , std::is_convertible<T*, const Token*> )>
599+ static T* getInitTokImpl (T* tok)
600+ {
601+ if (!tok)
602+ return nullptr ;
603+ if (Token::Match (tok, " %name% (" ))
604+ return getInitTokImpl (tok->next ());
605+ if (tok->str () != " (" )
606+ return nullptr ;
607+ if (!Token::simpleMatch (tok->astOperand2 (), " ;" ))
608+ return nullptr ;
609+ if (Token::simpleMatch (tok->astOperand2 ()->astOperand1 (), " ;" ))
610+ return nullptr ;
611+ return tok->astOperand2 ()->astOperand1 ();
612+ }
613+
614+ template <class T , REQUIRES(" T must be a Token class" , std::is_convertible<T*, const Token*> )>
615+ static T* getStepTokImpl (T* tok)
616+ {
617+ if (!tok)
618+ return nullptr ;
619+ if (Token::Match (tok, " %name% (" ))
620+ return getStepTokImpl (tok->next ());
621+ if (tok->str () != " (" )
622+ return nullptr ;
623+ if (!Token::simpleMatch (tok->astOperand2 (), " ;" ))
624+ return nullptr ;
625+ if (!Token::simpleMatch (tok->astOperand2 ()->astOperand2 (), " ;" ))
626+ return nullptr ;
627+ return tok->astOperand2 ()->astOperand2 ()->astOperand2 ();
628+ }
629+
598630Token* getCondTok (Token* tok)
599631{
600632 return getCondTokImpl (tok);
@@ -613,6 +645,20 @@ const Token* getCondTokFromEnd(const Token* endBlock)
613645 return getCondTokFromEndImpl (endBlock);
614646}
615647
648+ Token* getInitTok (Token* tok) {
649+ return getInitTokImpl (tok);
650+ }
651+ const Token* getInitTok (const Token* tok) {
652+ return getInitTokImpl (tok);
653+ }
654+
655+ Token* getStepTok (Token* tok) {
656+ return getStepTokImpl (tok);
657+ }
658+ const Token* getStepTok (const Token* tok) {
659+ return getStepTokImpl (tok);
660+ }
661+
616662const Token *findNextTokenFromBreak (const Token *breakToken)
617663{
618664 const Scope *scope = breakToken->scope ();
0 commit comments