[cfe-dev] source-code representation of an Expr
Ted Kremenek
kremenek at apple.com
Sat Jan 1 14:40:02 PST 2011
We should probably add this to a FAQ of some sort that documents how to do X with Clang.
On Dec 30, 2010, at 12:02 PM, Sam <sam at cs.jhu.edu> wrote:
> John,
>
> That works perfectly. Thank you so much for your help!
>
> Sam
>
> On Wed, Dec 29, 2010 at 4:20 PM, John McCall <rjmccall at apple.com> wrote:
> On Dec 29, 2010, at 12:53 PM, Sam wrote:
> > Yes, I just don't know what to *do* with it ;-) In other words, I don't see a clear use of the SourceManager API once I have the SourceRange to extract the Expr's source-code. I don't see any API calls that use SourceRange or beginning and ending SourceLocations for source-code extraction.
>
> We should probably make some API for this.
>
> What you can do for now is something like the following:
>
> SourceRange range = expr->getSourceRange();
> if (range.getBegin().isMacroID() || range.getEnd().isMacroID()) {
> // handle this case
> } else if (!sourceManager.isFromSameFile(range.getBegin(), range.getEnd())) {
> // handle this case
> } else {
> range.setEnd(preprocessor.getLocForEndOfToken(range.getEnd()));
> const char *begin = sourceManager.getCharacterData(range.getBegin());
> const char *end = sourceManager.getCharacterData(range.getEnd());
> llvm::StringRef string(begin, end - begin);
> // now you can do whatever you want
> }
>
> John.
>
> _______________________________________________
> 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/20110101/cb4782dd/attachment.html>
More information about the cfe-dev
mailing list