prevent double rewriting

Dear clang developers, greetings!
I would like to ask what is the best way to prevent double rewriting of the code; Please consider further example:


Where m_foundPixels is class member of “RedPixels” class; Here is the AST dump for it:

CXXMemberCallExpr 0x555557a11e40 ‘void’

-MemberExpr 0x555557a11e10 ‘’ .resize 0x555557597370
-MemberExpr 0x555557a11d60 'std::vector<PixelInfo>':'class std::vector<struct RedPixels::PixelInfoT, struct tinystl::allocator>' lvalue ->m_foundPixels 0x5555577db5a8 -CXXThisExpr 0x555557a11d50 ‘class RedPixels *’ implicit this
-ImplicitCastExpr 0x555557a11e68 'size_t':'unsigned long' <IntegralCast> -IntegerLiteral 0x555557a11df0 ‘int’

In my logic i have 2 different rewrites:

  1. VisitMemberExpr
  2. VisitCXXMemberCallExpr

The problems is that for this example VisitMemberExpr is called earlier than VisitCXXMemberCallExpr.
So if i rewrite the code inside VisitMemberExpr (“m_foundPixels”), my next rewrite in VisitCXXMemberCallExpr (which suppose to rewrite “m_foundPixels.resize(0)”) produce incorrect result.

I think I can come up with solutions for specific cases, but I would like to know if there is any good general way to prevent such situations.
For my program logic i suppose that if some upper level of the tree is to be rewritten, we definitely shouldn’t touch the lower levels anymore.

Many thanks!