[cfe-dev] Best way to determine if preprocessor directives live in a source range?

Alexander Kornienko alexfh at google.com
Thu May 28 06:20:08 PDT 2015


Nice, didn't know about
that. PreprocessingRecord::getPreprocessedEntitiesInRange() seems to be
what Richard is looking for.

On Thu, May 28, 2015 at 11:32 AM, Gabor Kozar <kozargabor at fastmail.fm>
wrote:

>  I think getting the PreprocessingRecord (
> http://clang.llvm.org/doxygen/classclang_1_1PreprocessingRecord.html
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__clang.llvm.org_doxygen_classclang-5F1-5F1PreprocessingRecord.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=gdAX48tJjBcP2806COIEPzLGexVNn0GK7k0ztqh2WPE&e=>)
> from the Preprocessor would also work; a PreprocessedEntity seems to
> contain source information that you can use:
> http://clang.llvm.org/doxygen/classclang_1_1PreprocessedEntity.html
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__clang.llvm.org_doxygen_classclang-5F1-5F1PreprocessedEntity.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=AGS_swi36AgPnFOd03NfpQz4FKz86QimsbYhDba4o0E&e=>
>
> ---
> Best regards,
>
> Gábor 'ShdNx' Kozár
> http://gaborkozar.me
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__gaborkozar.me&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=To6D6r6J4rN-RRMDez5SNHCWCaSiRkPNRwGQO1yaJ8A&e=>
>
>
> On Wed, May 27, 2015, at 18:31, Richard wrote:
>
>
> In article
> <CAOweq9+4kdBKeiKBg+SXzKs3SN-RNE7NQG7ysv4N4tsBCcWiCA at mail.gmail.com>,
>     Alexander Kornienko <alexfh at google.com> writes:
>
>
> This problem is relevant to comments as well.
>
> I'm not sure if there's an easy solution, but some hand-rolled options are
> available. One way is to re-lex the range and try to find preprocessor
> directives (and comments) by analyzing token sequences. Another approach
> would be to subscribe to PPCallbacks, gather all locations of #if/#else/...
> into a set and then look up any values in this set that fall between the
> bounds of your range.
>
>
> Yeah, I think with PPCallbacks you could build a function that would
> tell you something about preprocessor blocks based on source location.
>
> For comments, I thought there was something about sprinkling comment
> nodes into the AST?  Isn't this how the doxygen thing works?
> --
> "The Direct3D Graphics Pipeline" free book
> <http://tinyurl.com/d3d-pipeline
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__tinyurl.com_d3d-2Dpipeline&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=YXpM_NwFD-RVPg0HEFe-g1tvf2qaDER1W0PG48ttddQ&e=>
> >
>     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__ComputerGraphicsMuseum.org&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=ylNdlYjL1DoUeb1D4GyASw9xWrXXzshfyPPEMGruxjg&e=>
> >
>         The Terminals Wiki <http://terminals.classiccmp.org
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__terminals.classiccmp.org&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=12apur7YXWHhycuU59HXqZIgf_8MkKaguz3OTQkvo3s&e=>
> >
>   Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__LegalizeAdulthood.wordpress.com&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=jeMV2hAGYT4VtNUhol0Ohhr8Z2gbxuErge19Us3IgSE&s=Jg7QcSQ1vkfLyvCQqsnMKiXvPSfMJU_Hbm0OYNBFT3I&e=>
> >
> *_______________________________________________*
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150528/604da56b/attachment.html>


More information about the cfe-dev mailing list