<html><body bgcolor="#FFFFFF"><div>We should probably add this to a FAQ of some sort that documents how to do X with Clang.<br></div><div><br>On Dec 30, 2010, at 12:02 PM, Sam <<a href="mailto:sam@cs.jhu.edu">sam@cs.jhu.edu</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div>John, <div><br></div><div>That works perfectly. Thank you so much for your help!<div><br></div><div>Sam<br><br><div class="gmail_quote">On Wed, Dec 29, 2010 at 4:20 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com"><a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a></a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Dec 29, 2010, at 12:53 PM, Sam wrote:<br>
> 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.<br>
<br>
</div>We should probably make some API for this.<br>
<br>
What you can do for now is something like the following:<br>
<br>
SourceRange range = expr->getSourceRange();<br>
if (range.getBegin().isMacroID() || range.getEnd().isMacroID()) {<br>
// handle this case<br>
} else if (!sourceManager.isFromSameFile(range.getBegin(), range.getEnd())) {<br>
// handle this case<br>
} else {<br>
range.setEnd(preprocessor.getLocForEndOfToken(range.getEnd()));<br>
const char *begin = sourceManager.getCharacterData(range.getBegin());<br>
const char *end = sourceManager.getCharacterData(range.getEnd());<br>
llvm::StringRef string(begin, end - begin);<br>
// now you can do whatever you want<br>
}<br>
<font color="#888888"><br>
John.</font></blockquote></div><br></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>cfe-dev mailing list</span><br><span><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a></span><br><span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></span><br></div></blockquote></body></html>