<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Apr 7, 2014, at 2:22 AM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">+argyrios<div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 5, 2014 at 1:40 AM, Michael Bolin <span dir="ltr"><<a href="mailto:bolinfest@gmail.com" target="_blank">bolinfest@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr">Also, I just tried the following on the FunctionDecl that corresponds to `extern NSString *someFunction1(void) NS_RETURNS_NOT_RETAINED;`:<br>
<br>// const FunctionDecl *decl;<br>CharSourceRange range = CharSourceRange::getCharRange(decl->getSourceRange());<br>
LangOptions *opts = new LangOptions();<br>StringRef sourceText = Lexer::getSourceText(range, *sourceManager, *opts);<br><br>The sourceText that I get back is an empty string. For other, non-macro FunctionDecl nodes that I tried (specifically ones with bodies), I seem to get the right thing, though the closing curly braces often appears to be missing.<br>
</div></blockquote><div><br></div><div>I think if that's true, that's a bug in getSourceText() / makeFileCharRange.</div><div>Argyrios, any ideas?</div></div></div></div></blockquote><div><br></div><div>It should be:</div><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div dir="ltr"><br></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">       </span>CharSourceRange range = CharSourceRange::<b>getTokenRange</b>(decl->getSourceRange());</div></div></div></div><br></div><div>Also note that I think we don’t keep track of the semicolon at the end of the FunctionDecl.</div><div><br></div>-Argyrios</div><div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Cheers,</div><div>/Manuel</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 4, 2014 at 3:28 PM, Michael Bolin <span dir="ltr"><<a href="mailto:bolinfest@gmail.com" target="_blank">bolinfest@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr">Here is a better example:<div><br></div><div><a href="https://gist.github.com/bolinfest/9984257" target="_blank">https://gist.github.com/bolinfest/9984257</a><br>

</div><div><br></div><div>Here are the key lines in the output:<br>
<br><pre style="line-height:16.799999237060547px;width:1155px;font-size:12px;margin-bottom:0px;font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;padding:0px"><div>
|-FunctionDecl 0x10450ca90 <./example.h:15:1, /System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:137:72> someFunction1 'NSString *(void)' extern</div><div>
|-FunctionDecl 0x10450cc00 <./example.h:16:1, /System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:137:72> someFunction2 'NSString *(void)' extern</div><div><br></div></pre>Ideally, I would like to be able to get the following instead:<br>


<br><pre style="line-height:16.799999237060547px;width:1155px;font-size:12px;margin-bottom:0px;font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;padding:0px"><div>
|-FunctionDecl 0x10450ca90 <./example.h:15:1, ./example.h:15:61> someFunction1 'NSString *(void)' extern</div><div>|-FunctionDecl 0x10450cc00 <./example.h:16:1, ./example.h:16:61> someFunction2 'NSString *(void)' extern</div>


<div><br></div></pre>That is, I would like to be able to extract a SourceRange from a single file that I could delete (or comment out) to remove the definition or someFunction1 or someFunction2. Obviously the existing SourceRange that I get from the AST makes that hard to do.<br>


<br>Is it possible to get my desired SourceRange?</div><div><br></div><div>Thank you,</div><div>Michael</div><div><br></div></div><div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Apr 2, 2014 at 1:51 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>On Wed, Apr 2, 2014 at 2:31 AM, Michael Bolin <span dir="ltr"><<a href="mailto:bolinfest@gmail.com" target="_blank">bolinfest@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi, I am traversing the AST for an obj-c file using a clang plugin. I have a code snippet like the following:<div>



<br></div><div><div>#define JK_ATTRIBUTES(attr, ...)        __attribute__((attr, ##__VA_ARGS__))</div>
<div>#define JK_STATIC_INLINE static __inline__ JK_ATTRIBUTES(always_inline)</div><div><br></div><div>JK_STATIC_INLINE int jk_parse_skip_newline();</div><div><br></div><div>@implementation Hello</div><div>- (void)say:(int)i {</div>




<div>  if (i > 0) {</div><div>    NSLog(@"Hello, world! (%d)", i);</div><div>  }</div><div><br></div><div>  // Example of selector with unknown method declaration.</div><div>  [(id)@"Anything" length];</div>




<div>}</div><div>@end</div><div><br></div><div>JK_STATIC_INLINE int jk_parse_skip_newline() {</div><div>  return 0;</div><div>}</div></div><div><br></div><div>so while traversing the AST, I am trying to find the SourceRange of the jk_parse_skip_newline() definition at the bottom of the file. For non-macro expanded functions, this is very straightforward. But due to the macro expansion, I get a SourceRange that spans from the start of the macro to the end of my code snippet.</div>



</div></blockquote><div><br></div></div><div>How do you get that? If you only use functions that handle SourceRanges (and never combine locations you get from getBegin() getEnd()) that should not be possible.</div><div>Take a look at Lexer::makeFileCharRange and Lexer::getSourceText for how to deal with macro-ized ranges.</div>



<div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="ltr"><div> That means that it also includes the Hello class, which has nothing to do with jk_parse_skip_newline(). This is a problem because I am trying to use the AST to determine where jk_parse_skip_newline is defined so I can comment it out of the source file.</div>




<div><br></div><div>Is it possible for me to get the necessary SourceRange from the clang API? Ideally, I would get a SourceRange that identifies only the last three lines of my code sample.</div><div><br></div><div>Thank you,</div>




<div>Michael</div></div>
<br></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div>
</div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>
</blockquote></div><br></body></html>