[cfe-dev] PPCallbacks - If function param SourceRange returns whole file

fdart via cfe-dev cfe-dev at lists.llvm.org
Mon Oct 7 09:30:33 PDT 2019


The source which I am compiling looking at does include a macro, which I
suspect might be part of the problem.

This is the file we are compiling.  PLATFORM_WINDOWS is a #define.
#if PLATFORM_WINDOWS
//...
#endif
// Other code.




On Mon, Oct 7, 2019 at 9:25 AM fdart <jfdart17 at gmail.com> wrote:

> Hi,
>
> In my libtooling project I have a class implementing the PPCallbacks
> interface to get that information.  When the "If" function is triggered, I
> am passed a condition range.  I expect that would be whatever followed "#if
> " on that line.
>
> To extract the raw source text information as a string, I followed the
> advice of the below thread and have the below implementation.  The string
> "source" I retrieve contains the entire source of the file, after the "#if
> " statement.  Why is that?  How can I get only the information for the text
> on the line following the "#if "?  I'm using Clang 8.0.0.
>
>
> http://clang-developers.42468.n3.nabble.com/source-code-string-from-SourceRange-td4032732.html
>
>
>  void PreprocessorInfoListener::If(SourceLocation sourceLoc, SourceRange
> conditionRange, PPCallbacks::ConditionValueKind conditionValue)
> {
>     LangOptions langOptions;
>     llvm::StringRef source =
> Lexer::getSourceText(CharSourceRange::getTokenRange(conditionRange),
> m_sourceManager, langOptions);
> }
>
> Thanks,
> Justin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191007/737a0a95/attachment.html>


More information about the cfe-dev mailing list