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

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


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/62bc50c4/attachment.html>


More information about the cfe-dev mailing list