End location of DeclStmt

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

End location of DeclStmt

Oleg Smolsky via cfe-dev
Hi all,

My goal is to remove a DeclStmt from the beginning to end (including the semicolon) using the Rewriter.
However, calling getEnd() on a DeclStmt does not give the correct location. Is there a way to get the end location properly?

Best,
Pardis

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: End location of DeclStmt

Oleg Smolsky via cfe-dev

Hi Pardis,

which location does the `getEnd()` return?
I assume it's one byte to early: You can do offset-calculations with `SourceLocation`, therefore `YourStmt->getEnd().getLocWithOffset(1)` returns one element past the end-location.
Be careful with corner-cases as the new Location might be invalid, in a Macro-Range (isMarcoID()) and so on. Please note, that the `DeclStmt` might not always have a semicolon after itself.
E.g. `int my_variable = 42 /* This is my variable */;` could be such a case. You might want to take a look  `clang-tidy/utils/LexerUtils.{h,cpp}` as it has some functionality to deal with such situations.

Best, Jonas


Am 02.12.18 um 02:50 schrieb Pardis Pashakhanloo via cfe-dev:
Hi all,

My goal is to remove a DeclStmt from the beginning to end (including the semicolon) using the Rewriter.
However, calling getEnd() on a DeclStmt does not give the correct location. Is there a way to get the end location properly?

Best,
Pardis

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev