[cfe-dev] Source to source transformations questions in branches/tooling
Philip Dunstan
phil at philipdunstan.com
Wed Jun 27 16:36:30 PDT 2012
Daniel Jasper wrote
>
>> In my callback however I don't know how to find the right source location
>> to insert the override keyword. If there is no body I can use the end of
>> the function declaration. However if there is a body I don't know how to
>> get the end of the declaration section before the body. For example in
>> the
>> following example I want to insert the keyword before the comment. How do
>> I
>> get the source location of this point?
>> void f() const // overrides a base class virtual function
>> {
>> }
>>
>
> You could put the attribute to the location of the function's body
> (FunctionDecl::getBody()->getLocStart()). This only works if the function
> has a body but would be very similar to the end of a body-less
> FunctionDecl. It does not play nicely with code styles where you put the
> open brace on a new line, though. You could move back one character
> (SourceLocation::getLocWithOffset(-1)). That would effectively not add the
> attribute if you have trailing single line comments like the one above. It
> might be possible to use Lexer::GetBeginningOfToken() on to move to the
> front of such a single-line comment, but that would need some
> experimenting.
>
> It might be preferable to know the end of the function's parameter list
> (or
> the location of both parenthesis), but I think this information is
> currently not stored in the AST and cannot be easily calculated for
> functions without parameters :-(. We could open a bug for this.
>
I am not sure the end of the function's parameter list is sufficient as
there might be const specifiers and other attributes there that I need to
know about. Some of these ideas might be enough to work on the code base I
want to apply it to though. I will try a few of these ideas out on the
weekend.
Thanks for the help,
Phil
--
Philip Dunstan
phil at philipdunstan.com
http://philipdunstan.com
--
View this message in context: http://clang-developers.42468.n3.nabble.com/Source-to-source-transformations-questions-in-branches-tooling-tp4024920p4025006.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list