@@ -53,10 +53,10 @@ void visitAstNodesGeneric(T *ast, std::function<ChildrenToVisit(T *)> visitor)
5353
5454 if (c == ChildrenToVisit::done)
5555 break ;
56- if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2)
57- tokens.push (tok->astOperand1 ());
5856 if (c == ChildrenToVisit::op2 || c == ChildrenToVisit::op1_and_op2)
5957 tokens.push (tok->astOperand2 ());
58+ if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2)
59+ tokens.push (tok->astOperand1 ());
6060 }
6161}
6262
@@ -734,13 +734,27 @@ static bool isInLoopCondition(const Token * tok)
734734// / If tok2 comes after tok1
735735bool precedes (const Token * tok1, const Token * tok2)
736736{
737+ if (tok1 == tok2)
738+ return false ;
737739 if (!tok1)
738740 return false ;
739741 if (!tok2)
740742 return true ;
741743 return tok1->index () < tok2->index ();
742744}
743745
746+ // / If tok1 comes after tok2
747+ bool succedes (const Token* tok1, const Token* tok2)
748+ {
749+ if (tok1 == tok2)
750+ return false ;
751+ if (!tok1)
752+ return false ;
753+ if (!tok2)
754+ return true ;
755+ return tok1->index () > tok2->index ();
756+ }
757+
744758bool isAliasOf (const Token *tok, nonneg int varid, bool * inconclusive)
745759{
746760 if (tok->varId () == varid)
@@ -1865,11 +1879,12 @@ bool isScopeBracket(const Token* tok)
18651879 return false ;
18661880}
18671881
1868- const Token * getTokenArgumentFunction (const Token * tok, int & argn)
1882+ template <class T , REQUIRES(" T must be a Token class" , std::is_convertible<T*, const Token*> )>
1883+ T* getTokenArgumentFunctionImpl (T* tok, int & argn)
18691884{
18701885 argn = -1 ;
18711886 {
1872- const Token * parent = tok->astParent ();
1887+ T* parent = tok->astParent ();
18731888 if (parent && parent->isUnaryOp (" &" ))
18741889 parent = parent->astParent ();
18751890 while (parent && parent->isCast ())
@@ -1891,7 +1906,7 @@ const Token * getTokenArgumentFunction(const Token * tok, int& argn)
18911906 return nullptr ;
18921907 }
18931908
1894- const Token * argtok = tok;
1909+ T * argtok = tok;
18951910 while (argtok && argtok->astParent () && (!Token::Match (argtok->astParent (), " ,|(|{" ) || argtok->astParent ()->isCast ())) {
18961911 argtok = argtok->astParent ();
18971912 }
@@ -1935,6 +1950,14 @@ const Token * getTokenArgumentFunction(const Token * tok, int& argn)
19351950 return tok;
19361951}
19371952
1953+ const Token* getTokenArgumentFunction (const Token* tok, int & argn) {
1954+ return getTokenArgumentFunctionImpl (tok, argn);
1955+ }
1956+
1957+ Token* getTokenArgumentFunction (Token* tok, int & argn) {
1958+ return getTokenArgumentFunctionImpl (tok, argn);
1959+ }
1960+
19381961std::vector<const Variable*> getArgumentVars (const Token* tok, int argnr)
19391962{
19401963 std::vector<const Variable*> result;
0 commit comments