[cfe-dev] source-code representation of an Expr
Sam
sam at cs.jhu.edu
Thu Dec 30 12:02:04 PST 2010
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101230/ccb6c464/attachment.html>
More information about the cfe-dev
mailing list