[cfe-dev] Problem with retrieving the BinaryOperator RHS end location

Stephen Kelly via cfe-dev cfe-dev at lists.llvm.org
Sat May 4 05:28:20 PDT 2019


On 03/05/2019 14:28, Nat! via cfe-dev wrote:
> It turns out the fix suggestion - at least as I implemented it - works 
> for simple cases, but not in general.
> 
> ```
> endBuf  = SM->getCharacterData( Stmt->getRHS()->getEndLoc());
> endBuf += Lexer::MeasureTokenLength( Stmt->getEndLoc(), *SM, 
> TheRewriter.getLangOpts());
> ```
> 
> I believe the problem is that the SourceManager I am using
> to "measure" the length is looking at the unmodified sourcecode. But
> the RewriteBuffer may already contain changes.
> 
> So in my example if I am looking at `x = yyy` at the source but
> in the rewrite buffer its now `x=yyy_renamed` it will not take the
> extra characters into account.
> 
> I should be measuring the contents of the RewriteBuffer instead,
> with likely another SourceManager, but I lack the expertise to set
> this up.

Can you post a more-complete sscce example of what you are trying to do?

Thanks,

Stephen




More information about the cfe-dev mailing list