File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed
Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -1451,7 +1451,9 @@ void Token::astOperand1(Token *tok)
14511451 mImpl ->mAstOperand1 ->astParent (nullptr );
14521452 // goto parent operator
14531453 if (tok) {
1454- tok = tok->astTop ();
1454+ while (tok->mImpl ->mAstParent ) {
1455+ tok = tok->mImpl ->mAstParent ;
1456+ }
14551457 tok->astParent (this );
14561458 }
14571459 mImpl ->mAstOperand1 = tok;
@@ -1463,7 +1465,9 @@ void Token::astOperand2(Token *tok)
14631465 mImpl ->mAstOperand2 ->astParent (nullptr );
14641466 // goto parent operator
14651467 if (tok) {
1466- tok = tok->astTop ();
1468+ while (tok->mImpl ->mAstParent ) {
1469+ tok = tok->mImpl ->mAstParent ;
1470+ }
14671471 tok->astParent (this );
14681472 }
14691473 mImpl ->mAstOperand2 = tok;
Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ class CPPCHECKLIB Token {
117117 Token* mAstOperand1 {};
118118 Token* mAstOperand2 {};
119119 Token* mAstParent {};
120+ Token* mAstTop {};
120121
121122 // symbol database information
122123 const Scope* mScope {};
@@ -1598,15 +1599,23 @@ class CPPCHECKLIB Token {
15981599 }
15991600 RET_NONNULL Token *astTop () {
16001601 Token *ret = this ;
1602+ if (mImpl ->mAstTop ) {
1603+ return mImpl ->mAstTop ;
1604+ }
16011605 while (ret->mImpl ->mAstParent )
16021606 ret = ret->mImpl ->mAstParent ;
1607+ mImpl ->mAstTop = ret;
16031608 return ret;
16041609 }
16051610
16061611 RET_NONNULL const Token *astTop () const {
16071612 const Token *ret = this ;
1613+ if (mImpl ->mAstTop ) {
1614+ return mImpl ->mAstTop ;
1615+ }
16081616 while (ret->mImpl ->mAstParent )
16091617 ret = ret->mImpl ->mAstParent ;
1618+ mImpl ->mAstTop = const_cast <Token *>(ret);
16101619 return ret;
16111620 }
16121621
Original file line number Diff line number Diff line change @@ -1743,8 +1743,13 @@ static Token * createAstAtToken(Token *tok)
17431743 semicolon1->astOperand2 (state2.op .top ());
17441744 }
17451745
1746- if (init != semicolon1)
1747- semicolon1->astOperand1 (init->astTop ());
1746+ if (init != semicolon1) {
1747+ Token * top = init;
1748+ while (top->astParent ()) {
1749+ top = top->astParent ();
1750+ }
1751+ semicolon1->astOperand1 (top);
1752+ }
17481753 tok->next ()->astOperand1 (tok);
17491754 tok->next ()->astOperand2 (semicolon1);
17501755
You can’t perform that action at this time.
0 commit comments