[cfe-commits] [cfe-dev] Get location of #pragma

Daniel Powell divot.powell at googlemail.com
Tue Nov 6 11:18:19 PST 2012


Hi,

Original Context:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-June/022120.html

I found an issue with the PragmaHandler class where those wishing to modify
a pragma statement did not have any access to the "#pragma" keyword. Doug
asked that a SourceRange parameter be added to the HandlePragma method
specifying the range for the "#pragma" keyword.

I have made this change, along with handling for _pragma and __pragma
introducers. FInally I have also updated all of the existing PragmaHandlers
to receive this new SourceRange.

My apologies, I have been sat on this for longer than I should.

Cheers,

Dan


On 19 June 2012 18:04, Douglas Gregor <dgregor at apple.com> wrote:

>
> On Jun 16, 2012, at 6:54 AM, Daniel Powell wrote:
>
> Hi,
>
> HandlePragma should take a SourceRange that covers the '#pragma' or
>> '_Pragma', so that this information is available to the pragma handlers. It
>> should be a fairly simple change to Clang; would you like to contribute a
>> patch for it?
>>
>
> Happy to. Just to check, you are suggesting I modify the current
> HandlePragma method to have the following prototype?
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind
> Introducer, Token &FirstToken, SourceLocation IntroducerLoc) = 0;
>
>
> With the SourceRange change from your follow-up e-mail, yes.
>
> With the three types of pragma supported (#pragma, _Pragma and __Pragma)
> their locations only appear available when the preprocessor first discovers
> the token (HandleDirective, Handle_Pragma and HandleMicrosoft__pragma
> respectively), and is lost by the time HandlePragmaDirective is called so
> it's probably best to pass the location from those places to
> HandlePragmaDirective and onwards.
>
> _Pragma and __Pragma are easy, they each have PragmaLoc pointing to the
> keyword. However, by the time #pragma is fully discovered it only has a
> location pointing to "pragma" not "#pragma". I could use the
> getLocWithOffset(-1) method, or catch it at the start of the
> HandleDirective method, which do you think is best?
>
>
> Please catch it at the start of HandleDirective and pass it down.
>
> I'll have to update the existing PragmaHandlers too.
>
>
> Yes, please!
>
> Does all this sound sane? First time someone's asked me to contribute
> something specific back to open source. :-D
>
>
> Yes, this sounds perfectly reasonable. Thanks for looking into it!
>
> - Doug
>
>


-- 
--------
Daniel Powell
divot.powell at googlemail.com
http://tinyurl.com/powelld

The University of Edinburgh
Institute for Computer Systems Architecture
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121106/b4051927/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PragmaLocation.patch
Type: application/octet-stream
Size: 20448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121106/b4051927/attachment.obj>


More information about the cfe-commits mailing list